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"));
}
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());
}
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));
}
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();
}
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));
}
}
Aggregations