-
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.
MODDATAIMP-957: remove initial saving of records in SRS (#845)
* MODSOURMAN-1021: add endpoint to get IncomingRecord by id with DAO and service layers functionality (#823) * MODSOURMAN-1022: remove step of initial saving of incoming records to SRS (#826) * MODSOURMAN-1070: Fill in Journal Records for created MARC when INSTANCE_CREATED event received (#834) * MODSOURMAN-1070: Filled in two journals records for Instance and Marc bib during INSTANCE_CREATED event type * MODSOURMAN-1063: remove entity type set for journal records to not fetch them with get_job_log_entries (#844) * MODSOURMAN-1063: Update RecordProcessingLogDto to contain incoming record id --------- Co-authored-by: Yaroslav_Kiriak <[email protected]> Co-authored-by: Maksat <[email protected]> Co-authored-by: Volodymyr Rohach <[email protected]>
- Loading branch information
1 parent
073fb3b
commit 84315dc
Showing
37 changed files
with
3,095 additions
and
1,121 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
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
32 changes: 32 additions & 0 deletions
32
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,32 @@ | ||
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; | ||
import java.util.Optional; | ||
|
||
/** | ||
* DAO interface for the {@link IncomingRecord} entity | ||
*/ | ||
public interface IncomingRecordDao { | ||
|
||
/** | ||
* Searches for {@link IncomingRecord} by id | ||
* | ||
* @param id incomingRecord id | ||
* @return optional of incomingRecord | ||
*/ | ||
Future<Optional<IncomingRecord>> getById(String id, String tenantId); | ||
|
||
/** | ||
* 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); | ||
} |
79 changes: 79 additions & 0 deletions
79
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,79 @@ | ||
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.Optional; | ||
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 GET_BY_ID_SQL = "SELECT * FROM %s.%s WHERE id = $1"; | ||
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<Optional<IncomingRecord>> getById(String id, String tenantId) { | ||
LOGGER.debug("getById:: Get IncomingRecord by id = {} from the {} table", id, INCOMING_RECORDS_TABLE); | ||
Promise<RowSet<Row>> promise = Promise.promise(); | ||
try { | ||
String query = format(GET_BY_ID_SQL, convertToPsqlStandard(tenantId), INCOMING_RECORDS_TABLE); | ||
pgClientFactory.createInstance(tenantId).selectRead(query, Tuple.of(UUID.fromString(id)), promise); | ||
} catch (Exception e) { | ||
LOGGER.warn("getById:: Error getting IncomingRecord by id", e); | ||
promise.fail(e); | ||
} | ||
return promise.future().map(rowSet -> rowSet.rowCount() == 0 ? Optional.empty() | ||
: Optional.of(mapRowToIncomingRecord(rowSet.iterator().next()))); | ||
} | ||
|
||
@Override | ||
public Future<List<RowSet<Row>>> saveBatch(List<IncomingRecord> incomingRecords, String tenantId) { | ||
LOGGER.debug("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 IncomingRecord mapRowToIncomingRecord(Row row) { | ||
JsonObject jsonObject = row.getJsonObject("incoming_record"); | ||
return new IncomingRecord().withId(String.valueOf(row.getUUID("id"))) | ||
.withJobExecutionId(String.valueOf(row.getUUID("job_execution_id"))) | ||
.withRecordType(IncomingRecord.RecordType.fromValue(jsonObject.getString("recordType"))) | ||
.withOrder(jsonObject.getInteger("order")) | ||
.withRawRecordContent(jsonObject.getString("rawRecordContent")) | ||
.withParsedRecordContent(jsonObject.getString("parsedRecordContent")); | ||
} | ||
|
||
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
Oops, something went wrong.