use of org.folio.dao.util.MatchField in project mod-source-record-storage by folio-org.
the class AbstractMarcMatchEventHandler method handle.
@Override
public CompletableFuture<DataImportEventPayload> handle(DataImportEventPayload payload) {
CompletableFuture<DataImportEventPayload> future = new CompletableFuture<>();
HashMap<String, String> context = payload.getContext();
if (context == null || context.isEmpty() || isEmpty(payload.getContext().get(typeConnection.getMarcType().value())) || Objects.isNull(payload.getCurrentNode()) || Objects.isNull(payload.getEventsChain())) {
LOG.error(PAYLOAD_HAS_NO_DATA_MSG);
future.completeExceptionally(new EventProcessingException(PAYLOAD_HAS_NO_DATA_MSG));
return future;
}
payload.getEventsChain().add(payload.getEventType());
String record = context.get(typeConnection.getMarcType().value());
MatchDetail matchDetail = retrieveMatchDetail(payload);
if (isValidMatchDetail(matchDetail)) {
MatchField matchField = prepareMatchField(record, matchDetail);
if (matchField.isDefaultField()) {
processDefaultMatchField(matchField, payload.getTenant()).onSuccess(recordCollection -> processSucceededResult(recordCollection.getRecords(), payload, future)).onFailure(throwable -> future.completeExceptionally(new MatchingException(throwable)));
} else {
recordDao.getMatchedRecords(matchField, typeConnection, 0, 2, payload.getTenant()).onSuccess(recordList -> processSucceededResult(recordList, payload, future)).onFailure(throwable -> future.completeExceptionally(new MatchingException(throwable)));
}
} else {
constructError(payload, format(MATCH_DETAIL_IS_NOT_VALID, matchDetail));
future.complete(payload);
}
return future;
}
use of org.folio.dao.util.MatchField in project mod-source-record-storage by folio-org.
the class RecordDaoImpl method getMatchedRecords.
public Future<List<Record>> getMatchedRecords(MatchField matchedField, TypeConnection typeConnection, int offset, int limit, String tenantId) {
Name prt = name(typeConnection.getDbType().getTableName());
Table marcIndexersPartitionTable = table(name("marc_indexers_" + matchedField.getTag()));
return getQueryExecutor(tenantId).transaction(txQE -> txQE.query(dsl -> dsl.select(getAllRecordFields(prt)).from(RECORDS_LB).leftJoin(table(prt)).on(RECORDS_LB.ID.eq(field(TABLE_FIELD_TEMPLATE, UUID.class, prt, name(ID)))).leftJoin(RAW_RECORDS_LB).on(RECORDS_LB.ID.eq(RAW_RECORDS_LB.ID)).leftJoin(ERROR_RECORDS_LB).on(RECORDS_LB.ID.eq(ERROR_RECORDS_LB.ID)).innerJoin(marcIndexersPartitionTable).on(RECORDS_LB.ID.eq(field(TABLE_FIELD_TEMPLATE, UUID.class, marcIndexersPartitionTable, name(MARC_ID)))).where(filterRecordByType(typeConnection.getRecordType().value()).and(filterRecordByState(Record.State.ACTUAL.value())).and(getMatchedFieldCondition(matchedField, marcIndexersPartitionTable.getName()))).offset(offset).limit(limit > 0 ? limit : DEFAULT_LIMIT_FOR_GET_RECORDS))).map(queryResult -> queryResult.stream().map(res -> asRow(res.unwrap())).map(this::toRecord).collect(Collectors.toList()));
}
Aggregations