Search in sources :

Example 11 with DataImportEventPayload

use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.

the class AbstractMatchEventHandler method handle.

@Override
public CompletableFuture<DataImportEventPayload> handle(DataImportEventPayload dataImportEventPayload) {
    CompletableFuture<DataImportEventPayload> future = new CompletableFuture<>();
    dataImportEventPayload.getEventsChain().add(dataImportEventPayload.getEventType());
    Context context = constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl());
    mappingMetadataCache.get(dataImportEventPayload.getJobExecutionId(), context).toCompletionStage().thenCompose(metadataOptional -> metadataOptional.map(mappingMetadataDto -> doMatching(dataImportEventPayload, mappingMetadataDto, new MatchingParametersRelations())).orElse(CompletableFuture.failedFuture(new EventProcessingException(MAPPING_METADATA_NOT_FOUND_MSG)))).whenComplete((matched, throwable) -> {
        if (throwable != null) {
            future.completeExceptionally(throwable);
        } else {
            if (Boolean.TRUE.equals(matched)) {
                dataImportEventPayload.setEventType(getMatchedEventType());
            } else {
                dataImportEventPayload.setEventType(getNotMatchedEventType());
            }
            future.complete(dataImportEventPayload);
        }
    });
    return future;
}
Also used : Context(org.folio.inventory.common.Context) EventHandlingUtil.constructContext(org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.constructContext) Json(io.vertx.core.json.Json) Context(org.folio.inventory.common.Context) MappingMetadataDto(org.folio.MappingMetadataDto) EventHandler(org.folio.processing.events.services.handler.EventHandler) DataImportEventPayload(org.folio.DataImportEventPayload) CompletableFuture(java.util.concurrent.CompletableFuture) MATCH_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MATCH_PROFILE) EventHandlingUtil.constructContext(org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.constructContext) EventProcessingException(org.folio.processing.exceptions.EventProcessingException) EntityType(org.folio.rest.jaxrs.model.EntityType) JsonObject(io.vertx.core.json.JsonObject) MatchProfile(org.folio.MatchProfile) MappingMetadataCache(org.folio.inventory.dataimport.cache.MappingMetadataCache) MatchingParametersRelations(org.folio.inventory.dataimport.handlers.matching.util.MatchingParametersRelations) MatchingManager(org.folio.processing.matching.MatchingManager) CompletableFuture(java.util.concurrent.CompletableFuture) MatchingParametersRelations(org.folio.inventory.dataimport.handlers.matching.util.MatchingParametersRelations) DataImportEventPayload(org.folio.DataImportEventPayload) EventProcessingException(org.folio.processing.exceptions.EventProcessingException)

Example 12 with DataImportEventPayload

use of org.folio.DataImportEventPayload 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 13 with DataImportEventPayload

use of org.folio.DataImportEventPayload 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 14 with DataImportEventPayload

use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.

the class MatchInstanceEventHandlerUnitTest method shouldReturnTrueOnIsEligibleForInstanceMatchProfile.

@Test
public void shouldReturnTrueOnIsEligibleForInstanceMatchProfile() {
    EventHandler eventHandler = new MatchInstanceEventHandler(mappingMetadataCache);
    DataImportEventPayload eventPayload = new DataImportEventPayload().withCurrentNode(new ProfileSnapshotWrapper().withContentType(MATCH_PROFILE).withContent(JsonObject.mapFrom(new MatchProfile().withExistingRecordType(INSTANCE))));
    assertTrue(eventHandler.isEligible(eventPayload));
}
Also used : MatchProfile(org.folio.MatchProfile) MatchInstanceEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchInstanceEventHandler) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchInstanceEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchInstanceEventHandler) DataImportEventPayload(org.folio.DataImportEventPayload) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) Test(org.junit.Test)

Example 15 with DataImportEventPayload

use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.

the class MatchInstanceEventHandlerUnitTest method shouldNotMatchOnHandleEventPayload.

@Test
public void shouldNotMatchOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
    Async async = testContext.async();
    doAnswer(ans -> {
        Consumer<Success<MultipleRecords<Instance>>> callback = ans.getArgument(2);
        Success<MultipleRecords<Instance>> result = new Success<>(new MultipleRecords<>(new ArrayList<>(), 0));
        callback.accept(result);
        return null;
    }).when(instanceCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
    EventHandler eventHandler = new MatchInstanceEventHandler(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_INSTANCE_NOT_MATCHED.value(), updatedEventPayload.getEventType());
        async.complete();
    });
}
Also used : PagingParameters(org.folio.inventory.common.api.request.PagingParameters) Instance(org.folio.inventory.domain.instances.Instance) MatchInstanceEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchInstanceEventHandler) ArrayList(java.util.ArrayList) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchInstanceEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchInstanceEventHandler) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) Consumer(java.util.function.Consumer) Async(io.vertx.ext.unit.Async) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) Test(org.junit.Test)

Aggregations

DataImportEventPayload (org.folio.DataImportEventPayload)371 Test (org.junit.Test)319 HashMap (java.util.HashMap)230 JsonObject (io.vertx.core.json.JsonObject)135 Record (org.folio.rest.jaxrs.model.Record)118 ProfileSnapshotWrapper (org.folio.rest.jaxrs.model.ProfileSnapshotWrapper)115 Async (io.vertx.ext.unit.Async)107 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)107 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)102 EventHandler (org.folio.processing.events.services.handler.EventHandler)81 PagingParameters (org.folio.inventory.common.api.request.PagingParameters)55 Consumer (java.util.function.Consumer)53 HoldingsRecord (org.folio.HoldingsRecord)50 ActionProfile (org.folio.ActionProfile)47 Success (org.folio.inventory.common.domain.Success)45 MappingRule (org.folio.rest.jaxrs.model.MappingRule)44 MultipleRecords (org.folio.inventory.common.domain.MultipleRecords)43 Json (io.vertx.core.json.Json)40 CompletableFuture (java.util.concurrent.CompletableFuture)36 Reader (org.folio.processing.mapping.mapper.reader.Reader)36