Search in sources :

Example 1 with MatchingParametersRelations

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

Aggregations

Json (io.vertx.core.json.Json)1 JsonObject (io.vertx.core.json.JsonObject)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 DataImportEventPayload (org.folio.DataImportEventPayload)1 MappingMetadataDto (org.folio.MappingMetadataDto)1 MatchProfile (org.folio.MatchProfile)1 Context (org.folio.inventory.common.Context)1 MappingMetadataCache (org.folio.inventory.dataimport.cache.MappingMetadataCache)1 EventHandlingUtil.constructContext (org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.constructContext)1 MatchingParametersRelations (org.folio.inventory.dataimport.handlers.matching.util.MatchingParametersRelations)1 EventHandler (org.folio.processing.events.services.handler.EventHandler)1 EventProcessingException (org.folio.processing.exceptions.EventProcessingException)1 MatchingManager (org.folio.processing.matching.MatchingManager)1 EntityType (org.folio.rest.jaxrs.model.EntityType)1 MATCH_PROFILE (org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MATCH_PROFILE)1