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