Search in sources :

Example 1 with InstanceCollection

use of org.folio.inventory.domain.instances.InstanceCollection in project mod-inventory by folio-org.

the class CreateInstanceEventHandler method handle.

@Override
public CompletableFuture<DataImportEventPayload> handle(DataImportEventPayload dataImportEventPayload) {
    CompletableFuture<DataImportEventPayload> future = new CompletableFuture<>();
    try {
        dataImportEventPayload.setEventType(DI_INVENTORY_INSTANCE_CREATED.value());
        HashMap<String, String> payloadContext = dataImportEventPayload.getContext();
        if (payloadContext == null || payloadContext.isEmpty() || isEmpty(dataImportEventPayload.getContext().get(MARC_BIBLIOGRAPHIC.value()))) {
            LOGGER.error(PAYLOAD_HAS_NO_DATA_MSG);
            return CompletableFuture.failedFuture(new EventProcessingException(PAYLOAD_HAS_NO_DATA_MSG));
        }
        String jobExecutionId = dataImportEventPayload.getJobExecutionId();
        String recordId = dataImportEventPayload.getContext().get(RECORD_ID_HEADER);
        if (dataImportEventPayload.getCurrentNode().getChildSnapshotWrappers().isEmpty()) {
            LOGGER.error(ACTION_HAS_NO_MAPPING_MSG);
            return CompletableFuture.failedFuture(new EventProcessingException(format(ACTION_HAS_NO_MAPPING_MSG, jobExecutionId, recordId)));
        }
        Context context = EventHandlingUtil.constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl());
        Record targetRecord = Json.decodeValue(payloadContext.get(EntityType.MARC_BIBLIOGRAPHIC.value()), Record.class);
        String chunkId = dataImportEventPayload.getContext().get(CHUNK_ID_HEADER);
        Future<RecordToEntity> recordToInstanceFuture = idStorageService.store(targetRecord.getId(), UUID.randomUUID().toString(), dataImportEventPayload.getTenant());
        recordToInstanceFuture.onSuccess(res -> {
            String instanceId = res.getEntityId();
            mappingMetadataCache.get(jobExecutionId, context).compose(parametersOptional -> parametersOptional.map(mappingMetadata -> prepareAndExecuteMapping(dataImportEventPayload, new JsonObject(mappingMetadata.getMappingRules()), Json.decodeValue(mappingMetadata.getMappingParams(), MappingParameters.class))).orElseGet(() -> Future.failedFuture(format(MAPPING_PARAMETERS_NOT_FOUND_MSG, jobExecutionId, recordId, chunkId)))).compose(v -> {
                InstanceCollection instanceCollection = storage.getInstanceCollection(context);
                JsonObject instanceAsJson = prepareInstance(dataImportEventPayload, instanceId, jobExecutionId);
                List<String> errors = EventHandlingUtil.validateJsonByRequiredFields(instanceAsJson, requiredFields);
                if (!errors.isEmpty()) {
                    String msg = format("Mapped Instance is invalid: %s, by jobExecutionId: '%s' and recordId: '%s' and chunkId: '%s' ", errors, jobExecutionId, recordId, chunkId);
                    LOGGER.warn(msg);
                    return Future.failedFuture(msg);
                }
                Instance mappedInstance = Instance.fromJson(instanceAsJson);
                return addInstance(mappedInstance, instanceCollection).compose(createdInstance -> precedingSucceedingTitlesHelper.createPrecedingSucceedingTitles(mappedInstance, context).map(createdInstance));
            }).onSuccess(ar -> {
                dataImportEventPayload.getContext().put(INSTANCE.value(), Json.encode(ar));
                future.complete(dataImportEventPayload);
            }).onFailure(e -> {
                if (!(e instanceof DuplicateEventException)) {
                    LOGGER.error("Error creating inventory Instance by jobExecutionId: '{}' and recordId: '{}' and chunkId: '{}' ", jobExecutionId, recordId, chunkId, e);
                }
                future.completeExceptionally(e);
            });
        }).onFailure(failure -> {
            LOGGER.error("Error creating inventory recordId and instanceId relationship by jobExecutionId: '{}' and recordId: '{}' and chunkId: '{}' ", jobExecutionId, recordId, chunkId, failure);
            future.completeExceptionally(failure);
        });
    } catch (Exception e) {
        LOGGER.error("Error creating inventory Instance", e);
        future.completeExceptionally(e);
    }
    return future;
}
Also used : Context(org.folio.inventory.common.Context) MappingContext(org.folio.processing.mapping.mapper.MappingContext) CREATE(org.folio.ActionProfile.Action.CREATE) Json(io.vertx.core.json.Json) Context(org.folio.inventory.common.Context) DI_INVENTORY_INSTANCE_CREATED_READY_FOR_POST_PROCESSING(org.folio.DataImportEventTypes.DI_INVENTORY_INSTANCE_CREATED_READY_FOR_POST_PROCESSING) MappingManager(org.folio.processing.mapping.MappingManager) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) InstanceCollection(org.folio.inventory.domain.instances.InstanceCollection) ACTION_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.ACTION_PROFILE) UNIQUE_ID_ERROR_MESSAGE(org.folio.inventory.dataimport.util.DataImportConstants.UNIQUE_ID_ERROR_MESSAGE) EntityType(org.folio.rest.jaxrs.model.EntityType) JsonObject(io.vertx.core.json.JsonObject) IdStorageService(org.folio.inventory.services.IdStorageService) ActionProfile(org.folio.ActionProfile) RecordToEntity(org.folio.inventory.domain.relationship.RecordToEntity) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) MARC_BIBLIOGRAPHIC(org.folio.ActionProfile.FolioRecord.MARC_BIBLIOGRAPHIC) MappingContext(org.folio.processing.mapping.mapper.MappingContext) DuplicateEventException(org.folio.kafka.exception.DuplicateEventException) Record(org.folio.rest.jaxrs.model.Record) HRID_KEY(org.folio.inventory.domain.instances.Instance.HRID_KEY) Promise(io.vertx.core.Promise) DataImportEventPayload(org.folio.DataImportEventPayload) UUID(java.util.UUID) Future(io.vertx.core.Future) String.format(java.lang.String.format) StringUtils.isNotBlank(org.apache.commons.lang.StringUtils.isNotBlank) Storage(org.folio.inventory.storage.Storage) List(java.util.List) Logger(org.apache.logging.log4j.Logger) EventProcessingException(org.folio.processing.exceptions.EventProcessingException) DI_INVENTORY_INSTANCE_CREATED(org.folio.DataImportEventTypes.DI_INVENTORY_INSTANCE_CREATED) EventHandlingUtil(org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil) INSTANCE(org.folio.ActionProfile.FolioRecord.INSTANCE) Instance(org.folio.inventory.domain.instances.Instance) SOURCE_KEY(org.folio.inventory.domain.instances.Instance.SOURCE_KEY) LogManager(org.apache.logging.log4j.LogManager) MappingMetadataCache(org.folio.inventory.dataimport.cache.MappingMetadataCache) DuplicateEventException(org.folio.kafka.exception.DuplicateEventException) Instance(org.folio.inventory.domain.instances.Instance) InstanceCollection(org.folio.inventory.domain.instances.InstanceCollection) JsonObject(io.vertx.core.json.JsonObject) RecordToEntity(org.folio.inventory.domain.relationship.RecordToEntity) DuplicateEventException(org.folio.kafka.exception.DuplicateEventException) EventProcessingException(org.folio.processing.exceptions.EventProcessingException) DataImportEventPayload(org.folio.DataImportEventPayload) CompletableFuture(java.util.concurrent.CompletableFuture) Record(org.folio.rest.jaxrs.model.Record) List(java.util.List) EventProcessingException(org.folio.processing.exceptions.EventProcessingException)

Example 2 with InstanceCollection

use of org.folio.inventory.domain.instances.InstanceCollection in project mod-inventory by folio-org.

the class MarcBibMatchedPostProcessingEventHandler method handle.

@Override
public CompletableFuture<DataImportEventPayload> handle(DataImportEventPayload dataImportEventPayload) {
    CompletableFuture<DataImportEventPayload> future = new CompletableFuture<>();
    try {
        HashMap<String, String> payloadContext = dataImportEventPayload.getContext();
        if (isNull(payloadContext)) {
            LOGGER.error(PAYLOAD_HAS_NO_DATA_MSG);
            future.completeExceptionally(new EventProcessingException(PAYLOAD_HAS_NO_DATA_MSG));
            return future;
        }
        if (isBlank(payloadContext.get(MATCHED_MARC_BIB_KEY))) {
            LOGGER.info(MATCHED_RECORD_NOT_EXISTS_MSG);
            future.complete(dataImportEventPayload);
            return future;
        }
        Record matchedRecord = new JsonObject(payloadContext.get(MATCHED_MARC_BIB_KEY)).mapTo(Record.class);
        String instanceId = ParsedRecordUtil.getAdditionalSubfieldValue(matchedRecord.getParsedRecord(), ParsedRecordUtil.AdditionalSubfields.I);
        Context context = EventHandlingUtil.constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl());
        InstanceCollection instanceCollection = storage.getInstanceCollection(context);
        HoldingCollection holdingCollection = storage.getHoldingCollection(context);
        if (isBlank(instanceId)) {
            future.complete(dataImportEventPayload);
            return future;
        }
        instanceCollection.findById(instanceId).whenComplete((v, t) -> {
            if (t == null && v != null) {
                dataImportEventPayload.getContext().put(INSTANCE.value(), Json.encode(v));
                try {
                    holdingCollection.findByCql(format("instanceId=%s", v.getId()), PagingParameters.defaults(), findResult -> {
                        if (findResult.getResult() != null && findResult.getResult().totalRecords == 1) {
                            dataImportEventPayload.getContext().put(HOLDINGS.value(), Json.encode(findResult.getResult().records.get(0)));
                        }
                        future.complete(dataImportEventPayload);
                    }, failure -> {
                        LOGGER.error(ERROR_HOLDING_MSG + format(". StatusCode: %s. Message: %s", failure.getStatusCode(), failure.getReason()));
                        future.complete(dataImportEventPayload);
                    });
                } catch (UnsupportedEncodingException e) {
                    LOGGER.error(ERROR_HOLDING_MSG, e);
                    future.complete(dataImportEventPayload);
                }
            } else {
                LOGGER.error(ERROR_INSTANCE_MSG, t);
                future.complete(dataImportEventPayload);
            }
        });
    } catch (Exception e) {
        LOGGER.error(ERROR_INSTANCE_MSG, e);
        future.completeExceptionally(e);
    }
    return future;
}
Also used : Context(org.folio.inventory.common.Context) InstanceCollection(org.folio.inventory.domain.instances.InstanceCollection) JsonObject(io.vertx.core.json.JsonObject) UnsupportedEncodingException(java.io.UnsupportedEncodingException) EventProcessingException(org.folio.processing.exceptions.EventProcessingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DataImportEventPayload(org.folio.DataImportEventPayload) CompletableFuture(java.util.concurrent.CompletableFuture) HoldingCollection(org.folio.inventory.domain.HoldingCollection) Record(org.folio.rest.jaxrs.model.Record) EventProcessingException(org.folio.processing.exceptions.EventProcessingException)

Example 3 with InstanceCollection

use of org.folio.inventory.domain.instances.InstanceCollection in project mod-inventory by folio-org.

the class ReplaceInstanceEventHandler method handle.

@Override
public CompletableFuture<DataImportEventPayload> handle(DataImportEventPayload dataImportEventPayload) {
    // NOSONAR
    CompletableFuture<DataImportEventPayload> future = new CompletableFuture<>();
    try {
        dataImportEventPayload.setEventType(DI_INVENTORY_INSTANCE_UPDATED.value());
        HashMap<String, String> payloadContext = dataImportEventPayload.getContext();
        if (payloadContext == null || payloadContext.isEmpty() || isEmpty(dataImportEventPayload.getContext().get(MARC_BIBLIOGRAPHIC.value())) || isEmpty(dataImportEventPayload.getContext().get(INSTANCE.value()))) {
            LOGGER.error(PAYLOAD_HAS_NO_DATA_MSG);
            return CompletableFuture.failedFuture(new EventProcessingException(PAYLOAD_HAS_NO_DATA_MSG));
        }
        if (dataImportEventPayload.getCurrentNode().getChildSnapshotWrappers().isEmpty()) {
            LOGGER.error(ACTION_HAS_NO_MAPPING_MSG);
            return CompletableFuture.failedFuture(new EventProcessingException(ACTION_HAS_NO_MAPPING_MSG));
        }
        LOGGER.info("Processing ReplaceInstanceEventHandler starting with jobExecutionId: {}.", dataImportEventPayload.getJobExecutionId());
        Context context = EventHandlingUtil.constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl());
        Instance instanceToUpdate = Instance.fromJson(new JsonObject(dataImportEventPayload.getContext().get(INSTANCE.value())));
        prepareEvent(dataImportEventPayload);
        String jobExecutionId = dataImportEventPayload.getJobExecutionId();
        String recordId = dataImportEventPayload.getContext().get(RECORD_ID_HEADER);
        String chunkId = dataImportEventPayload.getContext().get(CHUNK_ID_HEADER);
        mappingMetadataCache.get(jobExecutionId, context).compose(parametersOptional -> parametersOptional.map(mappingMetadata -> prepareAndExecuteMapping(dataImportEventPayload, new JsonObject(mappingMetadata.getMappingRules()), new JsonObject(mappingMetadata.getMappingParams()).mapTo(MappingParameters.class), instanceToUpdate)).orElseGet(() -> Future.failedFuture(format(MAPPING_PARAMETERS_NOT_FOUND_MSG, jobExecutionId, recordId, chunkId)))).compose(e -> {
            JsonObject instanceAsJson = prepareTargetInstance(dataImportEventPayload, instanceToUpdate);
            InstanceCollection instanceCollection = storage.getInstanceCollection(context);
            List<String> errors = EventHandlingUtil.validateJsonByRequiredFields(instanceAsJson, requiredFields);
            if (!errors.isEmpty()) {
                String msg = format("Mapped Instance is invalid: %s, by jobExecutionId: '%s' and recordId: '%s' and chunkId: '%s' ", errors, jobExecutionId, recordId, chunkId);
                LOGGER.warn(msg);
                return Future.failedFuture(msg);
            }
            Instance mappedInstance = Instance.fromJson(instanceAsJson);
            return updateInstanceAndRetryIfOlExists(mappedInstance, instanceCollection, dataImportEventPayload).compose(updatedInstance -> precedingSucceedingTitlesHelper.getExistingPrecedingSucceedingTitles(mappedInstance, context)).map(precedingSucceedingTitles -> precedingSucceedingTitles.stream().map(titleJson -> titleJson.getString("id")).collect(Collectors.toSet())).compose(titlesIds -> precedingSucceedingTitlesHelper.deletePrecedingSucceedingTitles(titlesIds, context)).compose(ar -> precedingSucceedingTitlesHelper.createPrecedingSucceedingTitles(mappedInstance, context)).map(instanceAsJson);
        }).onComplete(ar -> {
            if (ar.succeeded()) {
                dataImportEventPayload.getContext().put(INSTANCE.value(), ar.result().encode());
                dataImportEventPayload.getContext().remove(CURRENT_RETRY_NUMBER);
                future.complete(dataImportEventPayload);
            } else {
                dataImportEventPayload.getContext().remove(CURRENT_RETRY_NUMBER);
                String errMessage = format("Error updating inventory Instance by jobExecutionId: '%s' and recordId: '%s' and chunkId: '%s': %s ", jobExecutionId, recordId, chunkId, ar.cause());
                LOGGER.error(errMessage);
                future.completeExceptionally(ar.cause());
            }
        });
    } catch (Exception e) {
        LOGGER.error("Error updating inventory Instance", e);
        future.completeExceptionally(e);
    }
    return future;
}
Also used : Context(org.folio.inventory.common.Context) MappingContext(org.folio.processing.mapping.mapper.MappingContext) Json(io.vertx.core.json.Json) Context(org.folio.inventory.common.Context) MappingManager(org.folio.processing.mapping.MappingManager) HttpStatus(org.apache.http.HttpStatus) Failure(org.folio.inventory.common.domain.Failure) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) InstanceCollection(org.folio.inventory.domain.instances.InstanceCollection) ACTION_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.ACTION_PROFILE) InstanceUtil(org.folio.inventory.support.InstanceUtil) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) HashSet(java.util.HashSet) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) ObjectMapperTool(org.folio.dbschema.ObjectMapperTool) JsonObject(io.vertx.core.json.JsonObject) ActionProfile(org.folio.ActionProfile) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) MARC_BIBLIOGRAPHIC(org.folio.ActionProfile.FolioRecord.MARC_BIBLIOGRAPHIC) MappingContext(org.folio.processing.mapping.mapper.MappingContext) HRID_KEY(org.folio.inventory.domain.instances.Instance.HRID_KEY) Promise(io.vertx.core.Promise) DataImportEventPayload(org.folio.DataImportEventPayload) DI_INVENTORY_INSTANCE_UPDATED(org.folio.DataImportEventTypes.DI_INVENTORY_INSTANCE_UPDATED) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Storage(org.folio.inventory.storage.Storage) DI_INVENTORY_INSTANCE_UPDATED_READY_FOR_POST_PROCESSING(org.folio.DataImportEventTypes.DI_INVENTORY_INSTANCE_UPDATED_READY_FOR_POST_PROCESSING) UPDATE(org.folio.ActionProfile.Action.UPDATE) List(java.util.List) EventProcessingException(org.folio.processing.exceptions.EventProcessingException) METADATA_KEY(org.folio.inventory.domain.instances.Instance.METADATA_KEY) EventHandlingUtil(org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil) INSTANCE(org.folio.ActionProfile.FolioRecord.INSTANCE) Instance(org.folio.inventory.domain.instances.Instance) SOURCE_KEY(org.folio.inventory.domain.instances.Instance.SOURCE_KEY) MappingMetadataCache(org.folio.inventory.dataimport.cache.MappingMetadataCache) Instance(org.folio.inventory.domain.instances.Instance) InstanceCollection(org.folio.inventory.domain.instances.InstanceCollection) JsonObject(io.vertx.core.json.JsonObject) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) EventProcessingException(org.folio.processing.exceptions.EventProcessingException) DataImportEventPayload(org.folio.DataImportEventPayload) CompletableFuture(java.util.concurrent.CompletableFuture) List(java.util.List) EventProcessingException(org.folio.processing.exceptions.EventProcessingException)

Example 4 with InstanceCollection

use of org.folio.inventory.domain.instances.InstanceCollection in project mod-inventory by folio-org.

the class MatchInstanceEventHandlerUnitTest method shouldPutMultipleMatchResultToPayloadOnHandleEventPayload.

@Test
public void shouldPutMultipleMatchResultToPayloadOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
    Async async = testContext.async();
    List<Instance> matchedInstances = List.of(new Instance(UUID.randomUUID().toString(), "1", "in1", "MARC", "Wonderful", "12334"), new Instance(UUID.randomUUID().toString(), "1", "in2", "MARC", "Wonderful", "12334"));
    doAnswer(invocation -> {
        Consumer<Success<MultipleRecords<Instance>>> successHandler = invocation.getArgument(2);
        Success<MultipleRecords<Instance>> result = new Success<>(new MultipleRecords<>(matchedInstances, 2));
        successHandler.accept(result);
        return null;
    }).when(instanceCollection).findByCql(eq(format("hrid == \"%s\"", INSTANCE_HRID)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
    MatchProfile subMatchProfile = new MatchProfile().withExistingRecordType(INSTANCE).withIncomingRecordType(MARC_BIBLIOGRAPHIC);
    EventHandler eventHandler = new MatchInstanceEventHandler(mappingMetadataCache);
    HashMap<String, String> context = new HashMap<>();
    context.put(MAPPING_PARAMS, LOCATIONS_PARAMS);
    context.put(RELATIONS, MATCHING_RELATIONS);
    DataImportEventPayload eventPayload = createEventPayload().withContext(context);
    eventPayload.getCurrentNode().setChildSnapshotWrappers(List.of(new ProfileSnapshotWrapper().withContent(subMatchProfile).withContentType(MATCH_PROFILE).withReactTo(MATCH)));
    eventHandler.handle(eventPayload).whenComplete((processedPayload, throwable) -> testContext.verify(v -> {
        testContext.assertNull(throwable);
        testContext.assertEquals(1, processedPayload.getEventsChain().size());
        testContext.assertEquals(DI_INVENTORY_INSTANCE_MATCHED.value(), processedPayload.getEventType());
        assertThat(new JsonArray(processedPayload.getContext().get(MULTI_MATCH_IDS)), hasItems(matchedInstances.get(0).getId(), matchedInstances.get(1).getId()));
        async.complete();
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) MappingMetadataDto(org.folio.MappingMetadataDto) EventHandler(org.folio.processing.events.services.handler.EventHandler) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Failure(org.folio.inventory.common.domain.Failure) DI_INVENTORY_INSTANCE_MATCHED(org.folio.DataImportEventTypes.DI_INVENTORY_INSTANCE_MATCHED) ACTION_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.ACTION_PROFILE) Matchers.hasItems(org.hamcrest.Matchers.hasItems) MarcValueReaderImpl(org.folio.processing.matching.reader.MarcValueReaderImpl) Collections.singletonList(java.util.Collections.singletonList) MockitoAnnotations(org.mockito.MockitoAnnotations) Mockito.doThrow(org.mockito.Mockito.doThrow) MULTI_MATCH_IDS(org.folio.inventory.dataimport.handlers.matching.loaders.AbstractLoader.MULTI_MATCH_IDS) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) Arrays.asList(java.util.Arrays.asList) Mockito.doAnswer(org.mockito.Mockito.doAnswer) JsonObject(io.vertx.core.json.JsonObject) MATCH(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ReactTo.MATCH) MatcherAssert.assertThat(org.hamcrest.junit.MatcherAssert.assertThat) MissingValue(org.folio.processing.value.MissingValue) INSTANCE(org.folio.rest.jaxrs.model.EntityType.INSTANCE) MatchInstanceEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchInstanceEventHandler) DataImportEventPayload(org.folio.DataImportEventPayload) UUID(java.util.UUID) Future(io.vertx.core.Future) String.format(java.lang.String.format) Storage(org.folio.inventory.storage.Storage) List(java.util.List) StringValue(org.folio.processing.value.StringValue) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) Instance(org.folio.inventory.domain.instances.Instance) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) Context(org.folio.inventory.common.Context) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) InstanceCollection(org.folio.inventory.domain.instances.InstanceCollection) EXACTLY_MATCHES(org.folio.MatchDetail.MatchCriterion.EXACTLY_MATCHES) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) ArrayList(java.util.ArrayList) DI_ERROR(org.folio.DataImportEventTypes.DI_ERROR) MARC_BIBLIOGRAPHIC(org.folio.rest.jaxrs.model.EntityType.MARC_BIBLIOGRAPHIC) EntityType(org.folio.rest.jaxrs.model.EntityType) MAPPING_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MAPPING_PROFILE) MatchProfile(org.folio.MatchProfile) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) MatchValueReaderFactory(org.folio.processing.matching.reader.MatchValueReaderFactory) MatchDetail(org.folio.MatchDetail) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) Vertx(io.vertx.core.Vertx) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Mockito.when(org.mockito.Mockito.when) DI_SRS_MARC_BIB_RECORD_CREATED(org.folio.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_CREATED) VALUE_FROM_RECORD(org.folio.rest.jaxrs.model.MatchExpression.DataValueType.VALUE_FROM_RECORD) MATCH_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MATCH_PROFILE) Consumer(java.util.function.Consumer) JsonArray(io.vertx.core.json.JsonArray) DI_INVENTORY_INSTANCE_NOT_MATCHED(org.folio.DataImportEventTypes.DI_INVENTORY_INSTANCE_NOT_MATCHED) Field(org.folio.rest.jaxrs.model.Field) Success(org.folio.inventory.common.domain.Success) MatchValueLoaderFactory(org.folio.processing.matching.loader.MatchValueLoaderFactory) MappingMetadataCache(org.folio.inventory.dataimport.cache.MappingMetadataCache) InstanceLoader(org.folio.inventory.dataimport.handlers.matching.loaders.InstanceLoader) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) Instance(org.folio.inventory.domain.instances.Instance) HashMap(java.util.HashMap) MatchInstanceEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchInstanceEventHandler) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchInstanceEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchInstanceEventHandler) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) JsonArray(io.vertx.core.json.JsonArray) MatchProfile(org.folio.MatchProfile) 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 InstanceCollection

use of org.folio.inventory.domain.instances.InstanceCollection in project mod-inventory by folio-org.

the class ExternalInstanceCollectionFailureExamples method serverErrorWhenGettingAllInstancesTriggersFailureCallback.

@Test
public void serverErrorWhenGettingAllInstancesTriggersFailureCallback() throws InterruptedException, ExecutionException, TimeoutException {
    InstanceCollection collection = createCollection();
    CompletableFuture<Failure> failureCalled = new CompletableFuture<>();
    collection.findAll(PagingParameters.defaults(), success -> fail("Completion callback should not be called"), failureCalled::complete);
    Failure failure = failureCalled.get(1000, TimeUnit.MILLISECONDS);
    check(failure);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) InstanceCollection(org.folio.inventory.domain.instances.InstanceCollection) Failure(org.folio.inventory.common.domain.Failure) Test(org.junit.Test)

Aggregations

InstanceCollection (org.folio.inventory.domain.instances.InstanceCollection)15 CompletableFuture (java.util.concurrent.CompletableFuture)11 Failure (org.folio.inventory.common.domain.Failure)9 Test (org.junit.Test)8 JsonObject (io.vertx.core.json.JsonObject)7 Instance (org.folio.inventory.domain.instances.Instance)6 Storage (org.folio.inventory.storage.Storage)6 String.format (java.lang.String.format)5 List (java.util.List)5 Future (io.vertx.core.Future)4 HashMap (java.util.HashMap)4 DataImportEventPayload (org.folio.DataImportEventPayload)4 Context (org.folio.inventory.common.Context)4 Promise (io.vertx.core.Promise)3 Json (io.vertx.core.json.Json)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 UUID (java.util.UUID)3 MappingMetadataCache (org.folio.inventory.dataimport.cache.MappingMetadataCache)3 EventProcessingException (org.folio.processing.exceptions.EventProcessingException)3 ACTION_PROFILE (org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.ACTION_PROFILE)3