use of org.folio.MatchDetail in project mod-source-record-storage by folio-org.
the class MarcAuthorityMatchEventHandlerTest method shouldMatchBy010aField.
@Test
public void shouldMatchBy010aField(TestContext context) {
Async async = context.async();
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(EntityType.MARC_AUTHORITY.value(), Json.encode(incomingRecord));
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withContext(payloadContext).withTenant(TENANT_ID).withCurrentNode(new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withContentType(MATCH_PROFILE).withContent(new MatchProfile().withExistingRecordType(EntityType.MARC_AUTHORITY).withIncomingRecordType(EntityType.MARC_AUTHORITY).withMatchDetails(singletonList(new MatchDetail().withMatchCriterion(EXACTLY_MATCHES).withExistingRecordType(EntityType.MARC_AUTHORITY).withExistingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(Lists.newArrayList(new Field().withLabel("field").withValue("010"), new Field().withLabel("indicator1").withValue(""), new Field().withLabel("indicator2").withValue(""), new Field().withLabel("recordSubfield").withValue("a")))).withIncomingRecordType(EntityType.MARC_AUTHORITY).withIncomingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(Lists.newArrayList(new Field().withLabel("field").withValue("010"), new Field().withLabel("indicator1").withValue(""), new Field().withLabel("indicator2").withValue(""), new Field().withLabel("recordSubfield").withValue("a"))))))));
recordDao.saveRecord(existingRecord, TENANT_ID).onComplete(context.asyncAssertSuccess()).onSuccess(existingSavedRecord -> handler.handle(dataImportEventPayload).whenComplete((updatedEventPayload, throwable) -> {
context.assertNull(throwable);
context.assertEquals(1, updatedEventPayload.getEventsChain().size());
context.assertEquals(updatedEventPayload.getEventType(), DI_SRS_MARC_AUTHORITY_RECORD_MATCHED.value());
context.assertEquals(new JsonObject(updatedEventPayload.getContext().get(MATCHED_MARC_KEY)).mapTo(Record.class), existingSavedRecord);
async.complete();
}));
}
use of org.folio.MatchDetail 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.MatchDetail in project mod-inventory by folio-org.
the class MatchAuthorityEventHandlerUnitTest method shouldMatchOnHandleEventPayloadFor999s.
@Test
public void shouldMatchOnHandleEventPayloadFor999s(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
MatchValueReaderFactory.clearReaderFactory();
MatchDetail matchDetail999s = new MatchDetail().withMatchCriterion(EXACTLY_MATCHES).withExistingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(singletonList(new Field().withLabel("idField").withValue("authority.id"))));
DataImportEventPayload eventPayload = createEventPayload(matchDetail999s);
MarcValueReaderImpl marcValueReaderMock = Mockito.mock(MarcValueReaderImpl.class);
when(marcValueReaderMock.isEligibleForEntityType(MARC_AUTHORITY)).thenReturn(true);
when(marcValueReaderMock.read(eventPayload, matchDetail999s)).thenReturn(StringValue.of(AUTHORITY_ID));
MatchValueReaderFactory.register(marcValueReaderMock);
doAnswer(ans -> {
Consumer<Success<MultipleRecords<Authority>>> callback = ans.getArgument(2);
Success<MultipleRecords<Authority>> result = new Success<>(new MultipleRecords<>(singletonList(createAuthority()), 1));
callback.accept(result);
return null;
}).when(collection).findByCql(eq(format("id == \"%s\"", AUTHORITY_ID)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchAuthorityEventHandler(mappingMetadataCache);
eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
testContext.assertNull(throwable);
testContext.assertEquals(1, updatedEventPayload.getEventsChain().size());
testContext.assertEquals(updatedEventPayload.getEventsChain(), singletonList(DI_SRS_MARC_AUTHORITY_RECORD_CREATED.value()));
testContext.assertEquals(DI_INVENTORY_AUTHORITY_MATCHED.value(), updatedEventPayload.getEventType());
async.complete();
});
}
use of org.folio.MatchDetail in project mod-inventory by folio-org.
the class MatchAuthorityEventHandlerUnitTest method shouldFailOnHandleEventPayloadIfExceptionThrown.
@Test
public void shouldFailOnHandleEventPayloadIfExceptionThrown(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
MatchDetail personalNameMatchDetail = new MatchDetail().withMatchCriterion(EXACTLY_MATCHES).withExistingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(singletonList(new Field().withLabel("personalName").withValue("authority.personalName"))));
DataImportEventPayload eventPayload = createEventPayload(personalNameMatchDetail);
doThrow(new UnsupportedEncodingException()).when(collection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchAuthorityEventHandler(mappingMetadataCache);
eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
testContext.assertNotNull(throwable);
async.complete();
});
}
use of org.folio.MatchDetail in project mod-inventory by folio-org.
the class MatchAuthorityEventHandlerUnitTest method shouldMatchOnHandleEventPayloadFor001.
@Test
public void shouldMatchOnHandleEventPayloadFor001(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
MatchValueReaderFactory.clearReaderFactory();
MatchDetail matchDetail001 = new MatchDetail().withMatchCriterion(EXACTLY_MATCHES).withExistingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(singletonList(new Field().withLabel("identifiersField").withValue("authority.identifiers[]"))));
DataImportEventPayload eventPayload = createEventPayload(matchDetail001);
MarcValueReaderImpl marcValueReaderMock = Mockito.mock(MarcValueReaderImpl.class);
when(marcValueReaderMock.isEligibleForEntityType(MARC_AUTHORITY)).thenReturn(true);
when(marcValueReaderMock.read(eventPayload, matchDetail001)).thenReturn(ListValue.of(singletonList(JsonObject.mapFrom(IDENTIFIER).toString())));
MatchValueReaderFactory.register(marcValueReaderMock);
doAnswer(ans -> {
Consumer<Success<MultipleRecords<Authority>>> callback = ans.getArgument(2);
Success<MultipleRecords<Authority>> result = new Success<>(new MultipleRecords<>(singletonList(createAuthority()), 1));
callback.accept(result);
return null;
}).when(collection).findByCql(eq("identifiers=\\\"[{\\\"value\\\":\\\"955335\\\",\\\"identifierTypeId\\\":\\\"11bf5f7c-30e1-4308-8170-1fbb5b817cf2\\\"}]\\\""), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchAuthorityEventHandler(mappingMetadataCache);
eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
testContext.assertNull(throwable);
testContext.assertEquals(1, updatedEventPayload.getEventsChain().size());
testContext.assertEquals(updatedEventPayload.getEventsChain(), singletonList(DI_SRS_MARC_AUTHORITY_RECORD_CREATED.value()));
testContext.assertEquals(DI_INVENTORY_AUTHORITY_MATCHED.value(), updatedEventPayload.getEventType());
async.complete();
});
}
Aggregations