Search in sources :

Example 26 with HoldingsRecord

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

the class ExternalStorageModuleHoldingsRecordCollectionExamples method shouldMapToRequest.

@Test
public void shouldMapToRequest() {
    String holdingId = UUID.randomUUID().toString();
    String instanceId = UUID.randomUUID().toString();
    String permanentLocationId = UUID.randomUUID().toString();
    HoldingsRecord holdingsrecord = new HoldingsRecord().withId(holdingId).withInstanceId(instanceId).withPermanentLocationId(permanentLocationId);
    JsonObject jsonObject = storage.mapToRequest(holdingsrecord);
    assertNotNull(jsonObject);
    assertEquals(holdingId, jsonObject.getString("id"));
    assertEquals(instanceId, jsonObject.getString("instanceId"));
    assertEquals(permanentLocationId, jsonObject.getString("permanentLocationId"));
}
Also used : HoldingsRecord(org.folio.HoldingsRecord) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 27 with HoldingsRecord

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

the class ExternalStorageModuleHoldingsRecordCollectionExamples method shouldMapFromJson.

@Test
public void shouldMapFromJson() {
    String holdingId = UUID.randomUUID().toString();
    String instanceId = UUID.randomUUID().toString();
    String permanentLocationId = UUID.randomUUID().toString();
    JsonObject holdingsRecord = new JsonObject().put("id", holdingId).put("instanceId", instanceId).put("permanentLocationId", permanentLocationId);
    HoldingsRecord holdingsrecord = storage.mapFromJson(holdingsRecord);
    assertNotNull(holdingsrecord);
    assertEquals(holdingId, holdingsrecord.getId());
    assertEquals(instanceId, holdingsrecord.getInstanceId());
    assertEquals(permanentLocationId, holdingsrecord.getPermanentLocationId());
}
Also used : HoldingsRecord(org.folio.HoldingsRecord) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 28 with HoldingsRecord

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

the class UpdateHoldingsQuickMarcEventHandlerTest method setUp.

@Before
public void setUp() throws IOException {
    existingHoldingsRecord = new JsonObject(TestUtil.readFileFromPath(INSTANCE_PATH)).mapTo(HoldingsRecord.class);
    holdingsUpdateDelegate = Mockito.spy(new HoldingsUpdateDelegate(storage));
    updateHoldingsQuickMarcEventHandler = new UpdateHoldingsQuickMarcEventHandler(holdingsUpdateDelegate, context);
    when(storage.getHoldingsRecordCollection(any())).thenReturn(holdingsRecordCollection);
    doAnswer(invocationOnMock -> {
        Consumer<Success<HoldingsRecord>> successHandler = invocationOnMock.getArgument(1);
        successHandler.accept(new Success<>(existingHoldingsRecord));
        return null;
    }).when(holdingsRecordCollection).findById(anyString(), any(), any());
    doAnswer(invocationOnMock -> {
        HoldingsRecord holdingsRecord = invocationOnMock.getArgument(0);
        Consumer<Success<HoldingsRecord>> successHandler = invocationOnMock.getArgument(1);
        successHandler.accept(new Success<>(holdingsRecord));
        return null;
    }).when(holdingsRecordCollection).update(any(), any(), any());
    when(context.getTenantId()).thenReturn("dummy");
    when(context.getToken()).thenReturn("token");
    when(context.getOkapiLocation()).thenReturn("http://localhost");
    mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH));
    record = new JsonObject(TestUtil.readFileFromPath(RECORD_PATH));
}
Also used : HoldingsRecord(org.folio.HoldingsRecord) UpdateHoldingsQuickMarcEventHandler(org.folio.inventory.dataimport.handlers.quickmarc.UpdateHoldingsQuickMarcEventHandler) JsonObject(io.vertx.core.json.JsonObject) HoldingsUpdateDelegate(org.folio.inventory.dataimport.handlers.actions.HoldingsUpdateDelegate) Success(org.folio.inventory.common.domain.Success) Before(org.junit.Before)

Example 29 with HoldingsRecord

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

the class CreateMarcHoldingsEventHandler method addHoldings.

private Future<HoldingsRecord> addHoldings(HoldingsRecord holdings, HoldingsRecordCollection holdingsRecordCollection) {
    Promise<HoldingsRecord> promise = Promise.promise();
    holdingsRecordCollection.add(holdings, success -> promise.complete(success.getResult()), failure -> {
        // This is temporary solution (verify by error message). It will be improved via another solution by https://issues.folio.org/browse/RMB-899.
        if (isNotBlank(failure.getReason()) && failure.getReason().contains(UNIQUE_ID_ERROR_MESSAGE)) {
            LOGGER.info("Duplicated event received by InstanceId: {}. Ignoring...", holdings.getId());
            promise.fail(new DuplicateEventException(format("Duplicated event by Holding id: %s", holdings.getId())));
        } else {
            LOGGER.error(format("Error posting Holdings cause %s, status code %s", failure.getReason(), failure.getStatusCode()));
            promise.fail(failure.getReason());
        }
    });
    return promise.future();
}
Also used : DuplicateEventException(org.folio.kafka.exception.DuplicateEventException) HoldingsRecord(org.folio.HoldingsRecord)

Example 30 with HoldingsRecord

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

the class UpdateHoldingEventHandler method processOLError.

private void processOLError(DataImportEventPayload dataImportEventPayload, CompletableFuture<DataImportEventPayload> future, HoldingsRecordCollection holdingsRecords, HoldingsRecord holding, Failure failure) {
    int currentRetryNumber = dataImportEventPayload.getContext().get(CURRENT_RETRY_NUMBER) == null ? 0 : Integer.parseInt(dataImportEventPayload.getContext().get(CURRENT_RETRY_NUMBER));
    if (currentRetryNumber < MAX_RETRIES_COUNT) {
        dataImportEventPayload.getContext().put(CURRENT_RETRY_NUMBER, String.valueOf(currentRetryNumber + 1));
        LOGGER.warn("Error updating Holding by id '{}' - '{}', status code '{}'. Retry UpdateHoldingEventHandler handler...", holding.getId(), failure.getReason(), failure.getStatusCode());
        holdingsRecords.findById(holding.getId()).thenAccept(actualInstance -> prepareDataAndReInvokeCurrentHandler(dataImportEventPayload, future, actualInstance)).exceptionally(e -> {
            dataImportEventPayload.getContext().remove(CURRENT_RETRY_NUMBER);
            String errMessage = format("Cannot get actual Holding by id: '%s' for jobExecutionId '%s'. Error: %s ", holding.getId(), dataImportEventPayload.getJobExecutionId(), e.getCause());
            LOGGER.error(errMessage);
            future.completeExceptionally(new EventProcessingException(errMessage));
            return null;
        });
    } else {
        dataImportEventPayload.getContext().remove(CURRENT_RETRY_NUMBER);
        String errMessage = format("Current retry number %s exceeded or equal given number %s for the Holding update for jobExecutionId '%s' ", MAX_RETRIES_COUNT, currentRetryNumber, dataImportEventPayload.getJobExecutionId());
        LOGGER.error(errMessage);
        future.completeExceptionally(new EventProcessingException(errMessage));
    }
}
Also used : Json(io.vertx.core.json.Json) Context(org.folio.inventory.common.Context) EventHandler(org.folio.processing.events.services.handler.EventHandler) 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) ACTION_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.ACTION_PROFILE) StringUtils(org.apache.commons.lang3.StringUtils) EventHandlingUtil.constructContext(org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.constructContext) HOLDINGS(org.folio.ActionProfile.FolioRecord.HOLDINGS) HoldingsRecordCollection(org.folio.inventory.domain.HoldingsRecordCollection) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) ObjectMapperTool(org.folio.dbschema.ObjectMapperTool) JsonObject(io.vertx.core.json.JsonObject) Objects.isNull(java.util.Objects.isNull) 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) DataImportEventPayload(org.folio.DataImportEventPayload) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) HoldingsRecord(org.folio.HoldingsRecord) String.format(java.lang.String.format) DI_INVENTORY_HOLDING_UPDATED(org.folio.DataImportEventTypes.DI_INVENTORY_HOLDING_UPDATED) Storage(org.folio.inventory.storage.Storage) UPDATE(org.folio.ActionProfile.Action.UPDATE) Logger(org.apache.logging.log4j.Logger) EventProcessingException(org.folio.processing.exceptions.EventProcessingException) LogManager(org.apache.logging.log4j.LogManager) MappingMetadataCache(org.folio.inventory.dataimport.cache.MappingMetadataCache) EventProcessingException(org.folio.processing.exceptions.EventProcessingException)

Aggregations

HoldingsRecord (org.folio.HoldingsRecord)44 JsonObject (io.vertx.core.json.JsonObject)27 Test (org.junit.Test)26 DataImportEventPayload (org.folio.DataImportEventPayload)24 HashMap (java.util.HashMap)23 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)22 Record (org.folio.rest.jaxrs.model.Record)18 Success (org.folio.inventory.common.domain.Success)17 Consumer (java.util.function.Consumer)14 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)14 PagingParameters (org.folio.inventory.common.api.request.PagingParameters)13 Context (org.folio.inventory.common.Context)12 MultipleRecords (org.folio.inventory.common.domain.MultipleRecords)12 EventHandler (org.folio.processing.events.services.handler.EventHandler)11 MappingParameters (org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters)11 Async (io.vertx.ext.unit.Async)8 MappingMetadataDto (org.folio.MappingMetadataDto)8 MatchItemEventHandler (org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler)8 HoldingsRecordCollection (org.folio.inventory.domain.HoldingsRecordCollection)8 Before (org.junit.Before)8