Search in sources :

Example 1 with UNIQUE_ID_ERROR_MESSAGE

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();
}
Also used : ParsedRecordUtil(org.folio.inventory.dataimport.util.ParsedRecordUtil) CREATE(org.folio.ActionProfile.Action.CREATE) Arrays(java.util.Arrays) EventHandler(org.folio.processing.events.services.handler.EventHandler) ItemUtil(org.folio.inventory.support.ItemUtil) JsonHelper(org.folio.inventory.support.JsonHelper) ZonedDateTime(java.time.ZonedDateTime) Item(org.folio.inventory.domain.items.Item) ACTION_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.ACTION_PROFILE) StringUtils(org.apache.commons.lang3.StringUtils) CirculationNote(org.folio.inventory.domain.items.CirculationNote) UNIQUE_ID_ERROR_MESSAGE(org.folio.inventory.dataimport.util.DataImportConstants.UNIQUE_ID_ERROR_MESSAGE) JsonObject(io.vertx.core.json.JsonObject) ItemCollection(org.folio.inventory.domain.items.ItemCollection) ZoneOffset(java.time.ZoneOffset) RecordToEntity(org.folio.inventory.domain.relationship.RecordToEntity) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) DuplicateEventException(org.folio.kafka.exception.DuplicateEventException) DataImportEventPayload(org.folio.DataImportEventPayload) UUID(java.util.UUID) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Storage(org.folio.inventory.storage.Storage) List(java.util.List) Logger(org.apache.logging.log4j.Logger) EventHandlingUtil(org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil) ITEM(org.folio.ActionProfile.FolioRecord.ITEM) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Json(io.vertx.core.json.Json) Context(org.folio.inventory.common.Context) MappingManager(org.folio.processing.mapping.MappingManager) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) DI_INVENTORY_ITEM_CREATED(org.folio.DataImportEventTypes.DI_INVENTORY_ITEM_CREATED) EntityType(org.folio.rest.jaxrs.model.EntityType) IdStorageService(org.folio.inventory.services.IdStorageService) ActionProfile(org.folio.ActionProfile) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) MappingContext(org.folio.processing.mapping.mapper.MappingContext) ItemStatusName(org.folio.inventory.domain.items.ItemStatusName) Record(org.folio.rest.jaxrs.model.Record) Promise(io.vertx.core.Promise) CqlHelper(org.folio.inventory.support.CqlHelper) StringUtils.isNotBlank(org.apache.commons.lang.StringUtils.isNotBlank) EventProcessingException(org.folio.processing.exceptions.EventProcessingException) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) DateTimeFormatter(java.time.format.DateTimeFormatter) LogManager(org.apache.logging.log4j.LogManager) MappingMetadataCache(org.folio.inventory.dataimport.cache.MappingMetadataCache) DuplicateEventException(org.folio.kafka.exception.DuplicateEventException) Item(org.folio.inventory.domain.items.Item) CirculationNote(org.folio.inventory.domain.items.CirculationNote)

Aggregations

Future (io.vertx.core.Future)1 Promise (io.vertx.core.Promise)1 Json (io.vertx.core.json.Json)1 JsonObject (io.vertx.core.json.JsonObject)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 String.format (java.lang.String.format)1 ZoneOffset (java.time.ZoneOffset)1 ZonedDateTime (java.time.ZonedDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors (java.util.stream.Collectors)1 StringUtils.isNotBlank (org.apache.commons.lang.StringUtils.isNotBlank)1 StringUtils (org.apache.commons.lang3.StringUtils)1 StringUtils.isBlank (org.apache.commons.lang3.StringUtils.isBlank)1 StringUtils.isEmpty (org.apache.commons.lang3.StringUtils.isEmpty)1 LogManager (org.apache.logging.log4j.LogManager)1