Search in sources :

Example 1 with CirculationNote

use of org.folio.inventory.domain.items.CirculationNote in project mod-inventory by folio-org.

the class ItemUtil method jsonToItem.

public static Item jsonToItem(JsonObject itemRequest) {
    List<String> formerIds = toListOfStrings(itemRequest.getJsonArray(Item.FORMER_IDS_KEY));
    List<String> statisticalCodeIds = toListOfStrings(itemRequest.getJsonArray(Item.STATISTICAL_CODE_IDS_KEY));
    List<String> yearCaption = toListOfStrings(itemRequest.getJsonArray(Item.YEAR_CAPTION_KEY));
    Status status = converterForClass(Status.class).fromJson(itemRequest.getJsonObject(Item.STATUS_KEY));
    List<String> administrativeNotes = toListOfStrings(itemRequest.getJsonArray(Item.ADMINISTRATIVE_NOTES_KEY));
    List<Note> notes = itemRequest.containsKey(Item.NOTES_KEY) ? JsonArrayHelper.toList(itemRequest.getJsonArray(Item.NOTES_KEY)).stream().map(Note::new).collect(Collectors.toList()) : new ArrayList<>();
    List<CirculationNote> circulationNotes = itemRequest.containsKey(Item.CIRCULATION_NOTES_KEY) ? JsonArrayHelper.toList(itemRequest.getJsonArray(Item.CIRCULATION_NOTES_KEY)).stream().map(CirculationNote::new).collect(Collectors.toList()) : new ArrayList<>();
    List<ElectronicAccess> electronicAccess = itemRequest.containsKey(Item.ELECTRONIC_ACCESS_KEY) ? JsonArrayHelper.toList(itemRequest.getJsonArray(Item.ELECTRONIC_ACCESS_KEY)).stream().map(ElectronicAccess::new).collect(Collectors.toList()) : new ArrayList<>();
    List<String> tags = itemRequest.containsKey(Item.TAGS_KEY) ? getTags(itemRequest) : new ArrayList<>();
    String materialTypeId = getNestedProperty(itemRequest, MATERIAL_TYPE, ID);
    String permanentLocationId = getNestedProperty(itemRequest, PERMANENT_LOCATION, ID);
    String temporaryLocationId = getNestedProperty(itemRequest, TEMPORARY_LOCATION, ID);
    String permanentLoanTypeId = getNestedProperty(itemRequest, PERMANENT_LOAN_TYPE, ID);
    String temporaryLoanTypeId = getNestedProperty(itemRequest, TEMPORARY_LOAN_TYPE, ID);
    return new Item(itemRequest.getString(ID), itemRequest.getString(Item.VERSION_KEY), itemRequest.getString(HOLDINGS_RECORD_ID), itemRequest.getString(Item.TRANSIT_DESTINATION_SERVICE_POINT_ID_KEY), status, materialTypeId, permanentLoanTypeId, null).withHrid(itemRequest.getString(Item.HRID_KEY)).withFormerIds(formerIds).withDiscoverySuppress(itemRequest.getBoolean(Item.DISCOVERY_SUPPRESS_KEY)).withBarcode(itemRequest.getString(BARCODE)).withItemLevelCallNumber(itemRequest.getString(Item.ITEM_LEVEL_CALL_NUMBER_KEY)).withEffectiveShelvingOrder(itemRequest.getString(Item.EFFECTIVE_SHELVING_ORDER_KEY)).withItemLevelCallNumberPrefix(itemRequest.getString(Item.ITEM_LEVEL_CALL_NUMBER_PREFIX_KEY)).withItemLevelCallNumberSuffix(itemRequest.getString(Item.ITEM_LEVEL_CALL_NUMBER_SUFFIX_KEY)).withItemLevelCallNumberTypeId(itemRequest.getString(Item.ITEM_LEVEL_CALL_NUMBER_TYPE_ID_KEY)).withVolume(itemRequest.getString(Item.VOLUME_KEY)).withEnumeration(itemRequest.getString(ENUMERATION)).withChronology(itemRequest.getString(CHRONOLOGY)).withNumberOfPieces(itemRequest.getString(NUMBER_OF_PIECES)).withDescriptionOfPieces(itemRequest.getString(Item.DESCRIPTION_OF_PIECES_KEY)).withNumberOfMissingPieces(itemRequest.getString(Item.NUMBER_OF_MISSING_PIECES_KEY)).withMissingPieces(itemRequest.getString(Item.MISSING_PIECES_KEY)).withMissingPiecesDate(itemRequest.getString(Item.MISSING_PIECES_DATE_KEY)).withItemDamagedStatusId(itemRequest.getString(Item.ITEM_DAMAGED_STATUS_ID_KEY)).withItemDamagedStatusDate(itemRequest.getString(Item.ITEM_DAMAGED_STATUS_DATE_KEY)).withPermanentLocationId(permanentLocationId).withTemporaryLocationId(temporaryLocationId).withTemporaryLoanTypeId(temporaryLoanTypeId).withCopyNumber(itemRequest.getString(Item.COPY_NUMBER_KEY)).withAdministrativeNotes(administrativeNotes).withNotes(notes).withCirculationNotes(circulationNotes).withAccessionNumber(itemRequest.getString(Item.ACCESSION_NUMBER_KEY)).withItemIdentifier(itemRequest.getString(Item.ITEM_IDENTIFIER_KEY)).withYearCaption(yearCaption).withElectronicAccess(electronicAccess).withStatisticalCodeIds(statisticalCodeIds).withPurchaseOrderLineIdentifier(itemRequest.getString(Item.PURCHASE_ORDER_LINE_IDENTIFIER)).withLastCheckIn(LastCheckIn.from(itemRequest.getJsonObject(Item.LAST_CHECK_IN))).withTags(tags);
}
Also used : Status(org.folio.inventory.domain.items.Status) Item(org.folio.inventory.domain.items.Item) ElectronicAccess(org.folio.inventory.domain.sharedproperties.ElectronicAccess) Note(org.folio.inventory.domain.items.Note) CirculationNote(org.folio.inventory.domain.items.CirculationNote) CirculationNote(org.folio.inventory.domain.items.CirculationNote)

Example 2 with CirculationNote

use of org.folio.inventory.domain.items.CirculationNote in project mod-inventory by folio-org.

the class Items method addItem.

private void addItem(RoutingContext routingContext, WebContext webContext, Item newItem, User user, ItemCollection itemCollection) {
    List<CirculationNote> notes = newItem.getCirculationNotes().stream().map(note -> note.withId(UUID.randomUUID().toString())).map(note -> note.withSource(user)).map(note -> note.withDate(dateTimeFormatter.format(ZonedDateTime.now()))).collect(Collectors.toList());
    itemCollection.add(newItem.withCirculationNotes(notes), success -> {
        Item item = success.getResult();
        respondWithItemRepresentation(item, STATUS_CREATED, routingContext, webContext);
    }, FailureResponseConsumer.serverError(routingContext.response()));
}
Also used : ItemUtil(org.folio.inventory.support.ItemUtil) URL(java.net.URL) FailureResponseConsumer(org.folio.inventory.support.http.server.FailureResponseConsumer) ZonedDateTime(java.time.ZonedDateTime) MoveItemIntoStatusService(org.folio.inventory.services.MoveItemIntoStatusService) JsonArrayHelper(org.folio.inventory.support.JsonArrayHelper) Router(io.vertx.ext.web.Router) FutureAssistance.allOf(org.folio.inventory.common.FutureAssistance.allOf) Item(org.folio.inventory.domain.items.Item) RoutingContext(io.vertx.ext.web.RoutingContext) BodyHandler(io.vertx.ext.web.handler.BodyHandler) CirculationNote(org.folio.inventory.domain.items.CirculationNote) ServerErrorResponse(org.folio.inventory.support.http.server.ServerErrorResponse) CollectionResourceClient(org.folio.inventory.storage.external.CollectionResourceClient) ItemCollection(org.folio.inventory.domain.items.ItemCollection) JsonObject(io.vertx.core.json.JsonObject) ZoneOffset(java.time.ZoneOffset) ForwardResponse(org.folio.inventory.support.http.server.ForwardResponse) EndpointFailureHandler.doExceptionally(org.folio.inventory.support.EndpointFailureHandler.doExceptionally) UserCollection(org.folio.inventory.domain.user.UserCollection) MethodHandles(java.lang.invoke.MethodHandles) OkapiHttpClient(org.folio.inventory.support.http.client.OkapiHttpClient) Collectors(java.util.stream.Collectors) Storage(org.folio.inventory.storage.Storage) HTTP_OK(org.folio.HttpStatus.HTTP_OK) ItemsValidator(org.folio.inventory.validation.ItemsValidator) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) ValidationError(org.folio.inventory.support.http.server.ValidationError) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) HttpClient(io.vertx.core.http.HttpClient) CqlHelper.multipleRecordsCqlQuery(org.folio.inventory.support.CqlHelper.multipleRecordsCqlQuery) java.util(java.util) WebContext(org.folio.inventory.common.WebContext) ItemsValidator.claimedReturnedMarkedAsMissing(org.folio.inventory.validation.ItemsValidator.claimedReturnedMarkedAsMissing) WebClient(io.vertx.ext.web.client.WebClient) ClientErrorResponse(org.folio.inventory.support.http.server.ClientErrorResponse) ItemsValidator.hridChanged(org.folio.inventory.validation.ItemsValidator.hridChanged) ItemStatusValidator.itemHasCorrectStatus(org.folio.inventory.validation.ItemStatusValidator.itemHasCorrectStatus) CompletableFuture(java.util.concurrent.CompletableFuture) Response(org.folio.inventory.support.http.client.Response) Function(java.util.function.Function) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) JsonResponse(org.folio.inventory.support.http.server.JsonResponse) Clients(org.folio.inventory.storage.external.Clients) MalformedURLException(java.net.MalformedURLException) ItemStatusName(org.folio.inventory.domain.items.ItemStatusName) CqlHelper(org.folio.inventory.support.CqlHelper) User(org.folio.inventory.domain.user.User) JsonResponse.unprocessableEntity(org.folio.inventory.support.http.server.JsonResponse.unprocessableEntity) JsonArray(io.vertx.core.json.JsonArray) DateTimeFormatter(java.time.format.DateTimeFormatter) Success(org.folio.inventory.common.domain.Success) SuccessResponse(org.folio.inventory.support.http.server.SuccessResponse) LogManager(org.apache.logging.log4j.LogManager) Item(org.folio.inventory.domain.items.Item) CirculationNote(org.folio.inventory.domain.items.CirculationNote)

Example 3 with CirculationNote

use of org.folio.inventory.domain.items.CirculationNote 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

CirculationNote (org.folio.inventory.domain.items.CirculationNote)3 Item (org.folio.inventory.domain.items.Item)3 JsonObject (io.vertx.core.json.JsonObject)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ZoneOffset (java.time.ZoneOffset)2 ZonedDateTime (java.time.ZonedDateTime)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Collectors (java.util.stream.Collectors)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 PagingParameters (org.folio.inventory.common.api.request.PagingParameters)2 ItemCollection (org.folio.inventory.domain.items.ItemCollection)2 ItemStatusName (org.folio.inventory.domain.items.ItemStatusName)2 Storage (org.folio.inventory.storage.Storage)2 Future (io.vertx.core.Future)1 Promise (io.vertx.core.Promise)1 HttpClient (io.vertx.core.http.HttpClient)1 Json (io.vertx.core.json.Json)1 JsonArray (io.vertx.core.json.JsonArray)1