Search in sources :

Example 21 with MatchProfile

use of org.folio.MatchProfile in project mod-source-record-storage by folio-org.

the class MarcAuthorityMatchEventHandlerTest method shouldMatchBy999ffsField.

@Test
public void shouldMatchBy999ffsField(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("999"), new Field().withLabel("indicator1").withValue("f"), new Field().withLabel("indicator2").withValue("f"), new Field().withLabel("recordSubfield").withValue("s")))).withIncomingRecordType(EntityType.MARC_AUTHORITY).withIncomingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(Lists.newArrayList(new Field().withLabel("field").withValue("999"), new Field().withLabel("indicator1").withValue("f"), new Field().withLabel("indicator2").withValue("f"), new Field().withLabel("recordSubfield").withValue("s"))))))));
    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();
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) EventHandler(org.folio.processing.events.services.handler.EventHandler) RecordDaoImpl(org.folio.dao.RecordDaoImpl) BeforeClass(org.junit.BeforeClass) MarcAuthorityMatchEventHandler(org.folio.services.handlers.match.MarcAuthorityMatchEventHandler) Date(java.util.Date) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) EXACTLY_MATCHES(org.folio.MatchDetail.MatchCriterion.EXACTLY_MATCHES) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) MockitoAnnotations(org.mockito.MockitoAnnotations) MARC_AUTHORITY(org.folio.rest.jaxrs.model.Record.RecordType.MARC_AUTHORITY) Lists(com.google.common.collect.Lists) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) TestUtil(org.folio.TestUtil) After(org.junit.After) EntityType(org.folio.rest.jaxrs.model.EntityType) MAPPING_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MAPPING_PROFILE) DI_SRS_MARC_AUTHORITY_RECORD_CREATED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_CREATED) JsonObject(io.vertx.core.json.JsonObject) MatchProfile(org.folio.MatchProfile) MappingProfile(org.folio.MappingProfile) Before(org.junit.Before) MatchDetail(org.folio.MatchDetail) DI_SRS_MARC_AUTHORITY_RECORD_NOT_MATCHED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_NOT_MATCHED) RecordDao(org.folio.dao.RecordDao) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test) IOException(java.io.IOException) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) UUID(java.util.UUID) DI_SRS_MARC_AUTHORITY_RECORD_MATCHED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_MATCHED) VALUE_FROM_RECORD(org.folio.rest.jaxrs.model.MatchExpression.DataValueType.VALUE_FROM_RECORD) MATCH_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MATCH_PROFILE) List(java.util.List) Field(org.folio.rest.jaxrs.model.Field) Assert(org.junit.Assert) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Field(org.folio.rest.jaxrs.model.Field) MatchProfile(org.folio.MatchProfile) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) JsonObject(io.vertx.core.json.JsonObject) MatchDetail(org.folio.MatchDetail) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) DataImportEventPayload(org.folio.DataImportEventPayload) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) Test(org.junit.Test)

Example 22 with MatchProfile

use of org.folio.MatchProfile in project mod-source-record-storage by folio-org.

the class MarcAuthorityMatchEventHandlerTest method shouldMatchBy001Field.

@Test
public void shouldMatchBy001Field(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"), new Field().withLabel("indicator1").withValue(""), new Field().withLabel("indicator2").withValue(""), new Field().withLabel("recordSubfield").withValue("")))).withExistingRecordType(EntityType.MARC_AUTHORITY).withIncomingRecordType(EntityType.MARC_AUTHORITY).withIncomingMatchExpression(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(""))))))));
    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();
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) EventHandler(org.folio.processing.events.services.handler.EventHandler) RecordDaoImpl(org.folio.dao.RecordDaoImpl) BeforeClass(org.junit.BeforeClass) MarcAuthorityMatchEventHandler(org.folio.services.handlers.match.MarcAuthorityMatchEventHandler) Date(java.util.Date) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) EXACTLY_MATCHES(org.folio.MatchDetail.MatchCriterion.EXACTLY_MATCHES) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) MockitoAnnotations(org.mockito.MockitoAnnotations) MARC_AUTHORITY(org.folio.rest.jaxrs.model.Record.RecordType.MARC_AUTHORITY) Lists(com.google.common.collect.Lists) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) TestUtil(org.folio.TestUtil) After(org.junit.After) EntityType(org.folio.rest.jaxrs.model.EntityType) MAPPING_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MAPPING_PROFILE) DI_SRS_MARC_AUTHORITY_RECORD_CREATED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_CREATED) JsonObject(io.vertx.core.json.JsonObject) MatchProfile(org.folio.MatchProfile) MappingProfile(org.folio.MappingProfile) Before(org.junit.Before) MatchDetail(org.folio.MatchDetail) DI_SRS_MARC_AUTHORITY_RECORD_NOT_MATCHED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_NOT_MATCHED) RecordDao(org.folio.dao.RecordDao) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test) IOException(java.io.IOException) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) UUID(java.util.UUID) DI_SRS_MARC_AUTHORITY_RECORD_MATCHED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_MATCHED) VALUE_FROM_RECORD(org.folio.rest.jaxrs.model.MatchExpression.DataValueType.VALUE_FROM_RECORD) MATCH_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MATCH_PROFILE) List(java.util.List) Field(org.folio.rest.jaxrs.model.Field) Assert(org.junit.Assert) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Field(org.folio.rest.jaxrs.model.Field) MatchProfile(org.folio.MatchProfile) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) JsonObject(io.vertx.core.json.JsonObject) MatchDetail(org.folio.MatchDetail) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) DataImportEventPayload(org.folio.DataImportEventPayload) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) Test(org.junit.Test)

Example 23 with MatchProfile

use of org.folio.MatchProfile in project mod-source-record-storage by folio-org.

the class MarcAuthorityMatchEventHandlerTest method shouldReturnFalseWhenHandlerIsNotEligibleForProfile.

@Test
public void shouldReturnFalseWhenHandlerIsNotEligibleForProfile() {
    MatchProfile matchProfile = new MatchProfile().withId(UUID.randomUUID().toString()).withName("MARC-MARC matching").withIncomingRecordType(EntityType.MARC_AUTHORITY).withExistingRecordType(EntityType.HOLDINGS);
    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_AUTHORITY_RECORD_CREATED.toString()).withContext(new HashMap<>()).withCurrentNode(profileSnapshotWrapper);
    boolean isEligible = handler.isEligible(dataImportEventPayload);
    Assert.assertFalse(isEligible);
}
Also used : MatchProfile(org.folio.MatchProfile) HashMap(java.util.HashMap) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Example 24 with MatchProfile

use of org.folio.MatchProfile in project mod-source-record-storage by folio-org.

the class MarcAuthorityMatchEventHandlerTest method shouldNotMatchBy999ffsField.

@Test
public void shouldNotMatchBy999ffsField(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("999"), new Field().withLabel("indicator1").withValue("f"), new Field().withLabel("indicator2").withValue("f"), new Field().withLabel("recordSubfield").withValue("s")))).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(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_NOT_MATCHED.value());
        context.assertNull(updatedEventPayload.getContext().get(MATCHED_MARC_KEY));
        async.complete();
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) EventHandler(org.folio.processing.events.services.handler.EventHandler) RecordDaoImpl(org.folio.dao.RecordDaoImpl) BeforeClass(org.junit.BeforeClass) MarcAuthorityMatchEventHandler(org.folio.services.handlers.match.MarcAuthorityMatchEventHandler) Date(java.util.Date) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) EXACTLY_MATCHES(org.folio.MatchDetail.MatchCriterion.EXACTLY_MATCHES) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) MockitoAnnotations(org.mockito.MockitoAnnotations) MARC_AUTHORITY(org.folio.rest.jaxrs.model.Record.RecordType.MARC_AUTHORITY) Lists(com.google.common.collect.Lists) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) TestUtil(org.folio.TestUtil) After(org.junit.After) EntityType(org.folio.rest.jaxrs.model.EntityType) MAPPING_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MAPPING_PROFILE) DI_SRS_MARC_AUTHORITY_RECORD_CREATED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_CREATED) JsonObject(io.vertx.core.json.JsonObject) MatchProfile(org.folio.MatchProfile) MappingProfile(org.folio.MappingProfile) Before(org.junit.Before) MatchDetail(org.folio.MatchDetail) DI_SRS_MARC_AUTHORITY_RECORD_NOT_MATCHED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_NOT_MATCHED) RecordDao(org.folio.dao.RecordDao) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test) IOException(java.io.IOException) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) UUID(java.util.UUID) DI_SRS_MARC_AUTHORITY_RECORD_MATCHED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_MATCHED) VALUE_FROM_RECORD(org.folio.rest.jaxrs.model.MatchExpression.DataValueType.VALUE_FROM_RECORD) MATCH_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MATCH_PROFILE) List(java.util.List) Field(org.folio.rest.jaxrs.model.Field) Assert(org.junit.Assert) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Field(org.folio.rest.jaxrs.model.Field) MatchProfile(org.folio.MatchProfile) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) MatchDetail(org.folio.MatchDetail) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) DataImportEventPayload(org.folio.DataImportEventPayload) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) Test(org.junit.Test)

Example 25 with MatchProfile

use of org.folio.MatchProfile in project mod-source-record-storage by folio-org.

the class MarcAuthorityMatchEventHandlerTest method shouldReturnTrueWhenHandlerIsEligibleForProfile.

@Test
public void shouldReturnTrueWhenHandlerIsEligibleForProfile() {
    MatchProfile matchProfile = new MatchProfile().withId(UUID.randomUUID().toString()).withName("MARC-MARC matching").withIncomingRecordType(EntityType.MARC_AUTHORITY).withExistingRecordType(EntityType.MARC_AUTHORITY);
    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_AUTHORITY_RECORD_CREATED.toString()).withContext(new HashMap<>()).withCurrentNode(profileSnapshotWrapper);
    boolean isEligible = handler.isEligible(dataImportEventPayload);
    Assert.assertTrue(isEligible);
}
Also used : MatchProfile(org.folio.MatchProfile) HashMap(java.util.HashMap) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Aggregations

MatchProfile (org.folio.MatchProfile)28 ProfileSnapshotWrapper (org.folio.rest.jaxrs.model.ProfileSnapshotWrapper)28 Test (org.junit.Test)27 DataImportEventPayload (org.folio.DataImportEventPayload)26 HashMap (java.util.HashMap)19 EventHandler (org.folio.processing.events.services.handler.EventHandler)17 JsonObject (io.vertx.core.json.JsonObject)15 Async (io.vertx.ext.unit.Async)15 Json (io.vertx.core.json.Json)14 TestContext (io.vertx.ext.unit.TestContext)14 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)14 ArrayList (java.util.ArrayList)14 Collections.singletonList (java.util.Collections.singletonList)14 List (java.util.List)14 UUID (java.util.UUID)14 MatchDetail (org.folio.MatchDetail)14 EXACTLY_MATCHES (org.folio.MatchDetail.MatchCriterion.EXACTLY_MATCHES)14 Field (org.folio.rest.jaxrs.model.Field)14 MatchExpression (org.folio.rest.jaxrs.model.MatchExpression)14 VALUE_FROM_RECORD (org.folio.rest.jaxrs.model.MatchExpression.DataValueType.VALUE_FROM_RECORD)14