Search in sources :

Example 1 with MarcValueReaderImpl

use of org.folio.processing.matching.reader.MarcValueReaderImpl in project mod-inventory by folio-org.

the class DataImportKafkaHandler method registerDataImportProcessingHandlers.

private void registerDataImportProcessingHandlers(Storage storage, HttpClient client) {
    MatchValueLoaderFactory.register(new InstanceLoader(storage, vertx));
    MatchValueLoaderFactory.register(new ItemLoader(storage, vertx));
    MatchValueLoaderFactory.register(new HoldingLoader(storage, vertx));
    MatchValueLoaderFactory.register(new AuthorityLoader(storage, vertx));
    MatchValueReaderFactory.register(new MarcValueReaderImpl());
    MatchValueReaderFactory.register(new StaticValueReaderImpl());
    MappingManager.registerReaderFactory(new MarcBibReaderFactory());
    MappingManager.registerReaderFactory(new MarcHoldingsReaderFactory());
    MappingManager.registerWriterFactory(new ItemWriterFactory());
    MappingManager.registerWriterFactory(new HoldingWriterFactory());
    MappingManager.registerWriterFactory(new InstanceWriterFactory());
    PrecedingSucceedingTitlesHelper precedingSucceedingTitlesHelper = new PrecedingSucceedingTitlesHelper(WebClient.wrap(client));
    EventManager.registerEventHandler(new MatchInstanceEventHandler(mappingMetadataCache));
    EventManager.registerEventHandler(new MatchItemEventHandler(mappingMetadataCache));
    EventManager.registerEventHandler(new MatchHoldingEventHandler(mappingMetadataCache));
    EventManager.registerEventHandler(new MatchAuthorityEventHandler(mappingMetadataCache));
    EventManager.registerEventHandler(new CreateItemEventHandler(storage, mappingMetadataCache, new ItemIdStorageService(new EntityIdStorageDaoImpl(new PostgresClientFactory(vertx)))));
    EventManager.registerEventHandler(new CreateHoldingEventHandler(storage, mappingMetadataCache, new HoldingsIdStorageService(new EntityIdStorageDaoImpl(new PostgresClientFactory(vertx)))));
    EventManager.registerEventHandler(new CreateInstanceEventHandler(storage, precedingSucceedingTitlesHelper, mappingMetadataCache, new InstanceIdStorageService(new EntityIdStorageDaoImpl(new PostgresClientFactory(vertx)))));
    EventManager.registerEventHandler(new CreateMarcHoldingsEventHandler(storage, mappingMetadataCache, new HoldingsIdStorageService(new EntityIdStorageDaoImpl(new PostgresClientFactory(vertx)))));
    EventManager.registerEventHandler(new CreateAuthorityEventHandler(storage, mappingMetadataCache, new AuthorityIdStorageService(new EntityIdStorageDaoImpl(new PostgresClientFactory(vertx)))));
    EventManager.registerEventHandler(new UpdateAuthorityEventHandler(storage, mappingMetadataCache, new KafkaEventPublisher(kafkaConfig, vertx, 100)));
    EventManager.registerEventHandler(new DeleteAuthorityEventHandler(storage));
    EventManager.registerEventHandler(new UpdateItemEventHandler(storage, mappingMetadataCache));
    EventManager.registerEventHandler(new UpdateHoldingEventHandler(storage, mappingMetadataCache));
    EventManager.registerEventHandler(new ReplaceInstanceEventHandler(storage, precedingSucceedingTitlesHelper, mappingMetadataCache));
    EventManager.registerEventHandler(new MarcBibModifiedPostProcessingEventHandler(new InstanceUpdateDelegate(storage), precedingSucceedingTitlesHelper, mappingMetadataCache));
    EventManager.registerEventHandler(new MarcBibMatchedPostProcessingEventHandler(storage));
}
Also used : MatchHoldingEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler) StaticValueReaderImpl(org.folio.processing.matching.reader.StaticValueReaderImpl) MatchInstanceEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchInstanceEventHandler) EntityIdStorageDaoImpl(org.folio.inventory.common.dao.EntityIdStorageDaoImpl) CreateMarcHoldingsEventHandler(org.folio.inventory.dataimport.handlers.actions.CreateMarcHoldingsEventHandler) UpdateItemEventHandler(org.folio.inventory.dataimport.handlers.actions.UpdateItemEventHandler) ItemWriterFactory(org.folio.inventory.dataimport.ItemWriterFactory) ReplaceInstanceEventHandler(org.folio.inventory.dataimport.handlers.actions.ReplaceInstanceEventHandler) CreateAuthorityEventHandler(org.folio.inventory.dataimport.handlers.actions.CreateAuthorityEventHandler) CreateItemEventHandler(org.folio.inventory.dataimport.handlers.actions.CreateItemEventHandler) HoldingsIdStorageService(org.folio.inventory.services.HoldingsIdStorageService) PostgresClientFactory(org.folio.inventory.common.dao.PostgresClientFactory) CreateInstanceEventHandler(org.folio.inventory.dataimport.handlers.actions.CreateInstanceEventHandler) PrecedingSucceedingTitlesHelper(org.folio.inventory.dataimport.handlers.actions.PrecedingSucceedingTitlesHelper) ItemIdStorageService(org.folio.inventory.services.ItemIdStorageService) MarcBibMatchedPostProcessingEventHandler(org.folio.inventory.dataimport.handlers.actions.MarcBibMatchedPostProcessingEventHandler) MarcValueReaderImpl(org.folio.processing.matching.reader.MarcValueReaderImpl) MarcBibReaderFactory(org.folio.processing.mapping.mapper.reader.record.marc.MarcBibReaderFactory) MatchAuthorityEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchAuthorityEventHandler) KafkaEventPublisher(org.folio.processing.events.services.publisher.KafkaEventPublisher) HoldingLoader(org.folio.inventory.dataimport.handlers.matching.loaders.HoldingLoader) AuthorityIdStorageService(org.folio.inventory.services.AuthorityIdStorageService) ItemLoader(org.folio.inventory.dataimport.handlers.matching.loaders.ItemLoader) DeleteAuthorityEventHandler(org.folio.inventory.dataimport.handlers.actions.DeleteAuthorityEventHandler) InstanceLoader(org.folio.inventory.dataimport.handlers.matching.loaders.InstanceLoader) InstanceWriterFactory(org.folio.inventory.dataimport.InstanceWriterFactory) MarcBibModifiedPostProcessingEventHandler(org.folio.inventory.dataimport.handlers.actions.MarcBibModifiedPostProcessingEventHandler) UpdateHoldingEventHandler(org.folio.inventory.dataimport.handlers.actions.UpdateHoldingEventHandler) MatchItemEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler) AuthorityLoader(org.folio.inventory.dataimport.handlers.matching.loaders.AuthorityLoader) HoldingWriterFactory(org.folio.inventory.dataimport.HoldingWriterFactory) InstanceIdStorageService(org.folio.inventory.services.InstanceIdStorageService) InstanceUpdateDelegate(org.folio.inventory.dataimport.handlers.actions.InstanceUpdateDelegate) UpdateAuthorityEventHandler(org.folio.inventory.dataimport.handlers.actions.UpdateAuthorityEventHandler) MarcHoldingsReaderFactory(org.folio.processing.mapping.mapper.reader.record.marc.MarcHoldingsReaderFactory) CreateHoldingEventHandler(org.folio.inventory.dataimport.handlers.actions.CreateHoldingEventHandler)

Example 2 with MarcValueReaderImpl

use of org.folio.processing.matching.reader.MarcValueReaderImpl 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();
    });
}
Also used : MarcValueReaderImpl(org.folio.processing.matching.reader.MarcValueReaderImpl) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) Authority(org.folio.Authority) MatchAuthorityEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchAuthorityEventHandler) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchAuthorityEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchAuthorityEventHandler) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) Field(org.folio.rest.jaxrs.model.Field) Consumer(java.util.function.Consumer) Async(io.vertx.ext.unit.Async) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) MatchDetail(org.folio.MatchDetail) Test(org.junit.Test)

Example 3 with MarcValueReaderImpl

use of org.folio.processing.matching.reader.MarcValueReaderImpl 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();
    });
}
Also used : MarcValueReaderImpl(org.folio.processing.matching.reader.MarcValueReaderImpl) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) Authority(org.folio.Authority) MatchAuthorityEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchAuthorityEventHandler) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchAuthorityEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchAuthorityEventHandler) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) Field(org.folio.rest.jaxrs.model.Field) Consumer(java.util.function.Consumer) Async(io.vertx.ext.unit.Async) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) MatchDetail(org.folio.MatchDetail) Test(org.junit.Test)

Aggregations

MatchAuthorityEventHandler (org.folio.inventory.dataimport.handlers.matching.MatchAuthorityEventHandler)3 MarcValueReaderImpl (org.folio.processing.matching.reader.MarcValueReaderImpl)3 Async (io.vertx.ext.unit.Async)2 Consumer (java.util.function.Consumer)2 Authority (org.folio.Authority)2 DataImportEventPayload (org.folio.DataImportEventPayload)2 MatchDetail (org.folio.MatchDetail)2 PagingParameters (org.folio.inventory.common.api.request.PagingParameters)2 MultipleRecords (org.folio.inventory.common.domain.MultipleRecords)2 Success (org.folio.inventory.common.domain.Success)2 EventHandler (org.folio.processing.events.services.handler.EventHandler)2 Field (org.folio.rest.jaxrs.model.Field)2 MatchExpression (org.folio.rest.jaxrs.model.MatchExpression)2 Test (org.junit.Test)2 EntityIdStorageDaoImpl (org.folio.inventory.common.dao.EntityIdStorageDaoImpl)1 PostgresClientFactory (org.folio.inventory.common.dao.PostgresClientFactory)1 HoldingWriterFactory (org.folio.inventory.dataimport.HoldingWriterFactory)1 InstanceWriterFactory (org.folio.inventory.dataimport.InstanceWriterFactory)1 ItemWriterFactory (org.folio.inventory.dataimport.ItemWriterFactory)1 CreateAuthorityEventHandler (org.folio.inventory.dataimport.handlers.actions.CreateAuthorityEventHandler)1