-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MODSOURMAN-1020: Save incoming records for DI logs (#819)
* MODSOURMAN-1020: add IncomingRecord entity DAO and service layers; save IncomingRecords with JournalRecords after incoming records are parsed
- Loading branch information
1 parent
f6f6410
commit bb0745e
Showing
21 changed files
with
425 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
mod-source-record-manager-server/src/main/java/org/folio/dao/IncomingRecordDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.folio.dao; | ||
|
||
import io.vertx.core.Future; | ||
import io.vertx.sqlclient.Row; | ||
import io.vertx.sqlclient.RowSet; | ||
import org.folio.rest.jaxrs.model.IncomingRecord; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* DAO interface for the {@link IncomingRecord} entity | ||
*/ | ||
public interface IncomingRecordDao { | ||
|
||
/** | ||
* Saves {@link IncomingRecord} entities into DB | ||
* | ||
* @param incomingRecords {@link IncomingRecord} entities to save | ||
* @param tenantId tenant id | ||
* @return future with created incomingRecords entities represented as row set | ||
*/ | ||
Future<List<RowSet<Row>>> saveBatch(List<IncomingRecord> incomingRecords, String tenantId); | ||
} |
52 changes: 52 additions & 0 deletions
52
mod-source-record-manager-server/src/main/java/org/folio/dao/IncomingRecordDaoImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.folio.dao; | ||
|
||
import io.vertx.core.Future; | ||
import io.vertx.core.Promise; | ||
import io.vertx.core.json.JsonObject; | ||
import io.vertx.sqlclient.Row; | ||
import io.vertx.sqlclient.RowSet; | ||
import io.vertx.sqlclient.Tuple; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.folio.dao.util.PostgresClientFactory; | ||
import org.folio.rest.jaxrs.model.IncomingRecord; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static java.lang.String.format; | ||
import static org.folio.rest.persist.PostgresClient.convertToPsqlStandard; | ||
|
||
@Repository | ||
public class IncomingRecordDaoImpl implements IncomingRecordDao { | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(); | ||
public static final String INCOMING_RECORDS_TABLE = "incoming_records"; | ||
private static final String INSERT_SQL = "INSERT INTO %s.%s (id, job_execution_id, incoming_record) VALUES ($1, $2, $3)"; | ||
|
||
@Autowired | ||
private PostgresClientFactory pgClientFactory; | ||
|
||
@Override | ||
public Future<List<RowSet<Row>>> saveBatch(List<IncomingRecord> incomingRecords, String tenantId) { | ||
LOGGER.info("saveBatch:: Save IncomingRecord entity to the {} table", INCOMING_RECORDS_TABLE); | ||
Promise<List<RowSet<Row>>> promise = Promise.promise(); | ||
try { | ||
String query = format(INSERT_SQL, convertToPsqlStandard(tenantId), INCOMING_RECORDS_TABLE); | ||
List<Tuple> tuples = incomingRecords.stream().map(this::prepareInsertQueryParameters).toList(); | ||
LOGGER.debug("IncomingRecordDaoImpl:: Save query = {}; tuples = {}", query, tuples); | ||
pgClientFactory.createInstance(tenantId).execute(query, tuples, promise); | ||
} catch (Exception e) { | ||
LOGGER.warn("saveBatch:: Error saving IncomingRecord entity", e); | ||
promise.fail(e); | ||
} | ||
return promise.future().onFailure(e -> LOGGER.warn("saveBatch:: Error saving IncomingRecord entity", e)); | ||
} | ||
|
||
private Tuple prepareInsertQueryParameters(IncomingRecord incomingRecord) { | ||
return Tuple.of(UUID.fromString(incomingRecord.getId()), UUID.fromString(incomingRecord.getJobExecutionId()), | ||
JsonObject.mapFrom(incomingRecord)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
mod-source-record-manager-server/src/main/java/org/folio/services/IncomingRecordService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.folio.services; | ||
|
||
import org.folio.rest.jaxrs.model.IncomingRecord; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* {@link IncomingRecord} Service interface | ||
*/ | ||
public interface IncomingRecordService { | ||
|
||
/** | ||
* Saves {@link IncomingRecord}s into DB | ||
* | ||
* @param incomingRecords incoming records to be saved | ||
* @param tenantId tenant | ||
*/ | ||
void saveBatch(List<IncomingRecord> incomingRecords, String tenantId); | ||
} |
20 changes: 20 additions & 0 deletions
20
...rce-record-manager-server/src/main/java/org/folio/services/IncomingRecordServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.folio.services; | ||
|
||
import org.folio.dao.IncomingRecordDao; | ||
import org.folio.rest.jaxrs.model.IncomingRecord; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
public class IncomingRecordServiceImpl implements IncomingRecordService { | ||
|
||
@Autowired | ||
private IncomingRecordDao incomingRecordDao; | ||
|
||
@Override | ||
public void saveBatch(List<IncomingRecord> incomingRecords, String tenantId) { | ||
incomingRecordDao.saveBatch(incomingRecords, tenantId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...-manager-server/src/main/resources/templates/db_scripts/create_incoming_records_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE IF NOT EXISTS incoming_records ( | ||
id uuid NOT NULL, | ||
job_execution_id uuid NOT NULL, | ||
incoming_record jsonb NOT NULL, | ||
CONSTRAINT incoming_records_pkey PRIMARY KEY (id), | ||
CONSTRAINT incoming_records_jobexecutionid_fkey FOREIGN KEY (job_execution_id) | ||
REFERENCES job_execution (id) | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS incoming_records_jobexecutionid_index ON incoming_records USING BTREE (job_execution_id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.