use of org.folio.MatchProfile in project mod-source-record-storage by folio-org.
the class MarcBibliographicMatchEventHandlerTest method shouldReturnTrueWhenHandlerIsEligibleForProfile.
@Test
public void shouldReturnTrueWhenHandlerIsEligibleForProfile() {
MatchProfile matchProfile = new MatchProfile().withId(UUID.randomUUID().toString()).withName("MARC-MARC matching").withIncomingRecordType(EntityType.MARC_BIBLIOGRAPHIC).withExistingRecordType(EntityType.MARC_BIBLIOGRAPHIC);
ProfileSnapshotWrapper profileSnapshotWrapper = new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withProfileId(matchProfile.getId()).withContentType(MATCH_PROFILE).withContent(matchProfile);
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withTenant(TENANT_ID).withEventType("DI_SRS_MARC_BIB_RECORD_CREATED").withContext(new HashMap<>()).withCurrentNode(profileSnapshotWrapper);
boolean isEligible = handler.isEligible(dataImportEventPayload);
Assert.assertTrue(isEligible);
}
use of org.folio.MatchProfile in project mod-source-record-storage by folio-org.
the class MarcBibliographicMatchEventHandlerTest method shouldMatchByInstanceHridField.
@Test
public void shouldMatchByInstanceHridField(TestContext context) {
Async async = context.async();
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(EntityType.MARC_BIBLIOGRAPHIC.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_BIBLIOGRAPHIC).withIncomingRecordType(EntityType.MARC_BIBLIOGRAPHIC).withMatchDetails(singletonList(new MatchDetail().withMatchCriterion(EXACTLY_MATCHES).withExistingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(Lists.newArrayList(new Field().withLabel("field").withValue("001"), new Field().withLabel("indicator1").withValue(""), new Field().withLabel("indicator2").withValue(""), new Field().withLabel("recordSubfield").withValue("")))).withExistingRecordType(EntityType.MARC_BIBLIOGRAPHIC).withIncomingRecordType(EntityType.MARC_BIBLIOGRAPHIC).withIncomingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(Lists.newArrayList(new Field().withLabel("field").withValue("948"), new Field().withLabel("indicator1").withValue(""), new Field().withLabel("indicator2").withValue(""), new Field().withLabel("recordSubfield").withValue("d"))))))));
recordDao.saveRecord(existingRecord, TENANT_ID).onComplete(context.asyncAssertSuccess()).onSuccess(record -> handler.handle(dataImportEventPayload).whenComplete((updatedEventPayload, throwable) -> {
context.assertNull(throwable);
context.assertEquals(1, updatedEventPayload.getEventsChain().size());
context.assertEquals(updatedEventPayload.getEventType(), DI_SRS_MARC_BIB_RECORD_MATCHED.value());
context.assertEquals(new JsonObject(updatedEventPayload.getContext().get(MATCHED_MARC_BIB_KEY)).mapTo(Record.class), record);
async.complete();
}));
}
use of org.folio.MatchProfile in project mod-source-record-storage by folio-org.
the class MarcAuthorityMatchEventHandlerTest method shouldNotMatchBy001Field.
@Test
public void shouldNotMatchBy001Field(TestContext context) {
Async async = context.async();
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(EntityType.MARC_AUTHORITY.value(), Json.encode(existingRecord));
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).withExistingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(Lists.newArrayList(new Field().withLabel("field").withValue("001")))).withExistingRecordType(EntityType.MARC_AUTHORITY).withIncomingRecordType(EntityType.MARC_AUTHORITY).withIncomingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(Lists.newArrayList(new Field().withLabel("field").withValue("035"), 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(record -> handler.handle(dataImportEventPayload).whenComplete((updatedEventPayload, throwable) -> {
context.assertNull(throwable);
context.assertEquals(1, updatedEventPayload.getEventsChain().size());
context.assertEquals(updatedEventPayload.getEventType(), DI_SRS_MARC_AUTHORITY_RECORD_NOT_MATCHED.value());
context.assertNull(updatedEventPayload.getContext().get(MATCHED_MARC_KEY));
async.complete();
}));
}
use of org.folio.MatchProfile 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.MatchProfile in project mod-source-record-storage by folio-org.
the class AbstractMarcMatchEventHandler method retrieveMatchDetail.
/* Retrieves a {@link MatchDetail} from the given {@link DataImportEventPayload} */
private MatchDetail retrieveMatchDetail(DataImportEventPayload dataImportEventPayload) {
MatchProfile matchProfile;
ProfileSnapshotWrapper matchingProfileWrapper = dataImportEventPayload.getCurrentNode();
if (matchingProfileWrapper.getContent() instanceof Map) {
matchProfile = new JsonObject((Map) matchingProfileWrapper.getContent()).mapTo(MatchProfile.class);
} else {
matchProfile = (MatchProfile) matchingProfileWrapper.getContent();
}
return matchProfile.getMatchDetails().get(0);
}
Aggregations