use of org.folio.inventory.dataimport.util.DataImportConstants.UNIQUE_ID_ERROR_MESSAGE in project mod-inventory by folio-org.
the class CreateItemEventHandler method addItem.
private Future<Item> addItem(Item item, ItemCollection itemCollection) {
Promise<Item> promise = Promise.promise();
List<CirculationNote> notes = item.getCirculationNotes().stream().map(note -> note.withId(UUID.randomUUID().toString())).map(note -> note.withSource(null)).map(note -> note.withDate(dateTimeFormatter.format(ZonedDateTime.now()))).collect(Collectors.toList());
itemCollection.add(item.withCirculationNotes(notes), 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)) {
LOG.info("Duplicated event received by ItemId: {}. Ignoring...", item.getId());
promise.fail(new DuplicateEventException(format("Duplicated event by Item id: %s", item.getId())));
} else {
LOG.error(format("Error posting Item cause %s, status code %s", failure.getReason(), failure.getStatusCode()));
promise.fail(failure.getReason());
}
});
return promise.future();
}
Aggregations