Search in sources :

Example 1 with MatchHoldingEventHandler

use of org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler 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 MatchHoldingEventHandler

use of org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler in project mod-inventory by folio-org.

the class MatchHoldingEventHandlerUnitTest method shouldMatchWithSubConditionBasedOnMultiMatchResultOnHandleEventPayload.

@Test
public void shouldMatchWithSubConditionBasedOnMultiMatchResultOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
    Async async = testContext.async();
    List<String> multiMatchResult = List.of(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    HoldingsRecord expectedHolding = createHolding();
    doAnswer(invocation -> {
        Consumer<Success<MultipleRecords<HoldingsRecord>>> successHandler = invocation.getArgument(2);
        Success<MultipleRecords<HoldingsRecord>> result = new Success<>(new MultipleRecords<>(singletonList(expectedHolding), 1));
        successHandler.accept(result);
        return null;
    }).when(holdingCollection).findByCql(eq(format("hrid == \"%s\" AND id == (%s OR %s)", HOLDING_HRID, multiMatchResult.get(0), multiMatchResult.get(1))), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
    EventHandler eventHandler = new MatchHoldingEventHandler(mappingMetadataCache);
    HashMap<String, String> context = new HashMap<>();
    context.put(MULTI_MATCH_IDS, Json.encode(multiMatchResult));
    context.put(MAPPING_PARAMS, LOCATIONS_PARAMS);
    context.put(RELATIONS, MATCHING_RELATIONS);
    DataImportEventPayload eventPayload = createEventPayload().withContext(context);
    eventHandler.handle(eventPayload).whenComplete((processedPayload, throwable) -> {
        testContext.assertNull(throwable);
        testContext.assertEquals(1, processedPayload.getEventsChain().size());
        testContext.assertEquals(processedPayload.getEventsChain(), singletonList(DI_SRS_MARC_BIB_RECORD_CREATED.value()));
        testContext.assertEquals(DI_INVENTORY_HOLDING_MATCHED.value(), processedPayload.getEventType());
        testContext.assertEquals(Json.decodeValue(processedPayload.getContext().get(HOLDINGS.value()), HoldingsRecord.class).getId(), expectedHolding.getId());
        async.complete();
    });
}
Also used : MatchHoldingEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) HashMap(java.util.HashMap) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchItemEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler) MatchHoldingEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) HoldingsRecord(org.folio.HoldingsRecord) Consumer(java.util.function.Consumer) Async(io.vertx.ext.unit.Async) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) Test(org.junit.Test)

Example 3 with MatchHoldingEventHandler

use of org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler in project mod-inventory by folio-org.

the class MatchHoldingEventHandlerUnitTest method shouldMatchWithSubMatchByHoldingOnHandleEventPayload.

@Test
public void shouldMatchWithSubMatchByHoldingOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
    Async async = testContext.async();
    doAnswer(ans -> {
        Consumer<Success<MultipleRecords<HoldingsRecord>>> callback = ans.getArgument(2);
        Success<MultipleRecords<HoldingsRecord>> result = new Success<>(new MultipleRecords<>(singletonList(createHolding()), 1));
        callback.accept(result);
        return null;
    }).when(holdingCollection).findByCql(eq(format("hrid == \"%s\" AND id == \"%s\"", HOLDING_HRID, HOLDING_ID)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
    EventHandler eventHandler = new MatchHoldingEventHandler(mappingMetadataCache);
    HashMap<String, String> context = new HashMap<>();
    context.put(EntityType.HOLDINGS.value(), JsonObject.mapFrom(new HoldingsRecord().withId(HOLDING_ID)).encode());
    context.put(MAPPING_PARAMS, LOCATIONS_PARAMS);
    context.put(RELATIONS, MATCHING_RELATIONS);
    DataImportEventPayload eventPayload = createEventPayload().withContext(context);
    eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
        testContext.assertNull(throwable);
        testContext.assertEquals(1, updatedEventPayload.getEventsChain().size());
        testContext.assertEquals(updatedEventPayload.getEventsChain(), singletonList(DI_SRS_MARC_BIB_RECORD_CREATED.value()));
        testContext.assertEquals(DI_INVENTORY_HOLDING_MATCHED.value(), updatedEventPayload.getEventType());
        async.complete();
    });
}
Also used : MatchHoldingEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) HashMap(java.util.HashMap) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchItemEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler) MatchHoldingEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) HoldingsRecord(org.folio.HoldingsRecord) Consumer(java.util.function.Consumer) Async(io.vertx.ext.unit.Async) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) Test(org.junit.Test)

Example 4 with MatchHoldingEventHandler

use of org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler in project mod-inventory by folio-org.

the class MatchHoldingEventHandlerUnitTest method shouldNotMatchOnHandleEventPayload.

@Test
public void shouldNotMatchOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
    Async async = testContext.async();
    doAnswer(ans -> {
        Consumer<Success<MultipleRecords<HoldingsRecord>>> callback = ans.getArgument(2);
        Success<MultipleRecords<HoldingsRecord>> result = new Success<>(new MultipleRecords<>(new ArrayList<>(), 0));
        callback.accept(result);
        return null;
    }).when(holdingCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
    EventHandler eventHandler = new MatchHoldingEventHandler(mappingMetadataCache);
    DataImportEventPayload eventPayload = createEventPayload();
    eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
        testContext.assertNull(throwable);
        testContext.assertEquals(1, updatedEventPayload.getEventsChain().size());
        testContext.assertEquals(updatedEventPayload.getEventsChain(), singletonList(DI_SRS_MARC_BIB_RECORD_CREATED.value()));
        testContext.assertEquals(DI_INVENTORY_HOLDING_NOT_MATCHED.value(), updatedEventPayload.getEventType());
        async.complete();
    });
}
Also used : MatchHoldingEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) ArrayList(java.util.ArrayList) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchItemEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler) MatchHoldingEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) HoldingsRecord(org.folio.HoldingsRecord) Consumer(java.util.function.Consumer) Async(io.vertx.ext.unit.Async) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) Test(org.junit.Test)

Example 5 with MatchHoldingEventHandler

use of org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler in project mod-inventory by folio-org.

the class MatchHoldingEventHandlerUnitTest method shouldFailOnHandleEventPayloadIfMatchedMultipleHoldings.

@Test
public void shouldFailOnHandleEventPayloadIfMatchedMultipleHoldings(TestContext testContext) throws UnsupportedEncodingException {
    Async async = testContext.async();
    doAnswer(ans -> {
        Consumer<Success<MultipleRecords<HoldingsRecord>>> callback = ans.getArgument(2);
        Success<MultipleRecords<HoldingsRecord>> result = new Success<>(new MultipleRecords<>(asList(createHolding(), createHolding()), 2));
        callback.accept(result);
        return null;
    }).when(holdingCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
    EventHandler eventHandler = new MatchHoldingEventHandler(mappingMetadataCache);
    DataImportEventPayload eventPayload = createEventPayload();
    eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
        testContext.assertNotNull(throwable);
        async.complete();
    });
}
Also used : MatchHoldingEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler) HoldingsRecord(org.folio.HoldingsRecord) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) Consumer(java.util.function.Consumer) Async(io.vertx.ext.unit.Async) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchItemEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler) MatchHoldingEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Aggregations

MatchHoldingEventHandler (org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler)11 MatchItemEventHandler (org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler)11 Async (io.vertx.ext.unit.Async)10 DataImportEventPayload (org.folio.DataImportEventPayload)10 EventHandler (org.folio.processing.events.services.handler.EventHandler)10 Test (org.junit.Test)10 Consumer (java.util.function.Consumer)9 PagingParameters (org.folio.inventory.common.api.request.PagingParameters)9 HoldingsRecord (org.folio.HoldingsRecord)7 MultipleRecords (org.folio.inventory.common.domain.MultipleRecords)7 Success (org.folio.inventory.common.domain.Success)7 HashMap (java.util.HashMap)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 JsonObject (io.vertx.core.json.JsonObject)2 TestContext (io.vertx.ext.unit.TestContext)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 Instance (org.folio.Instance)2 MappingMetadataDto (org.folio.MappingMetadataDto)2 MatchDetail (org.folio.MatchDetail)2