use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.
the class ItemApiExamples method CanGetAllItemsWithDifferentTemporaryLoanType.
@Test
public void CanGetAllItemsWithDifferentTemporaryLoanType() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
JsonObject smallAngryInstance = createInstance(smallAngryPlanet(UUID.randomUUID()));
UUID smallAngryHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(smallAngryInstance.getString("id")))).getId();
itemsClient.create(new ItemRequestBuilder().forHolding(smallAngryHoldingId).book().canCirculate().withBarcode("645398607547"));
itemsClient.create(new ItemRequestBuilder().forHolding(smallAngryHoldingId).book().canCirculate().temporarilyCourseReserves().withBarcode("175848607547"));
final var getAllCompleted = okapiClient.get(ApiRoot.items());
Response getAllResponse = getAllCompleted.toCompletableFuture().get(5, SECONDS);
assertThat(getAllResponse.getStatusCode(), is(200));
List<JsonObject> items = JsonArrayHelper.toList(getAllResponse.getJson().getJsonArray("items"));
assertThat(items.size(), is(2));
assertThat(getAllResponse.getJson().getInteger("totalRecords"), is(2));
assertThat(items.stream().filter(item -> StringUtils.equals(item.getString("barcode"), "645398607547")).findFirst().orElse(new JsonObject()).getJsonObject("permanentLoanType").getString("id"), is(ApiTestSuite.getCanCirculateLoanType()));
assertThat(items.stream().filter(item -> StringUtils.equals(item.getString("barcode"), "645398607547")).findFirst().orElse(new JsonObject()).containsKey("temporaryLoanType"), is(false));
assertThat(items.stream().filter(item -> StringUtils.equals(item.getString("barcode"), "175848607547")).findFirst().orElse(new JsonObject()).getJsonObject("permanentLoanType").getString("id"), is(ApiTestSuite.getCanCirculateLoanType()));
assertThat(items.stream().filter(item -> StringUtils.equals(item.getString("barcode"), "175848607547")).findFirst().orElse(new JsonObject()).getJsonObject("temporaryLoanType").getString("id"), is(ApiTestSuite.getCourseReserveLoanType()));
items.forEach(ItemApiExamples::hasConsistentPermanentLoanType);
items.forEach(ItemApiExamples::hasConsistentTemporaryLoanType);
items.forEach(ItemApiExamples::hasConsistentPermanentLocation);
items.forEach(ItemApiExamples::hasConsistentTemporaryLocation);
}
use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.
the class MoveApi method updateItems.
private void updateItems(RoutingContext routingContext, WebContext context, List<String> idsToUpdate, List<Item> itemsToUpdate) {
ItemCollection storageItemCollection = storage.getItemCollection(context);
List<CompletableFuture<Item>> updates = itemsToUpdate.stream().map(storageItemCollection::update).collect(Collectors.toList());
CompletableFuture.allOf(updates.toArray(new CompletableFuture[0])).handle((vVoid, throwable) -> updates.stream().filter(future -> !future.isCompletedExceptionally()).map(CompletableFuture::join).map(Item::getId).collect(toList())).thenAccept(updatedIds -> respond(routingContext, idsToUpdate, updatedIds));
}
use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.
the class MoveApi method moveItems.
private void moveItems(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);
JsonObject itemsMoveJsonRequest = routingContext.getBodyAsJson();
Optional<ValidationError> validationError = itemsMoveHasRequiredFields(itemsMoveJsonRequest);
if (validationError.isPresent()) {
unprocessableEntity(routingContext.response(), validationError.get());
return;
}
String toHoldingsRecordId = itemsMoveJsonRequest.getString(TO_HOLDINGS_RECORD_ID);
List<String> itemIdsToUpdate = toListOfStrings(itemsMoveJsonRequest.getJsonArray(ITEM_IDS));
storage.getHoldingCollection(context).findById(toHoldingsRecordId).thenAccept(holding -> {
if (Objects.nonNull(holding)) {
try {
CollectionResourceClient itemsStorageClient = createItemStorageClient(createHttpClient(routingContext, context), context);
MultipleRecordsFetchClient itemsFetchClient = createItemsFetchClient(itemsStorageClient);
itemsFetchClient.find(itemIdsToUpdate, this::fetchByIdCql).thenAccept(jsons -> {
List<Item> itemsToUpdate = updateHoldingsRecordIdForItems(toHoldingsRecordId, jsons);
updateItems(routingContext, context, itemIdsToUpdate, itemsToUpdate);
}).exceptionally(e -> {
ServerErrorResponse.internalError(routingContext.response(), e);
return null;
});
} catch (Exception e) {
ServerErrorResponse.internalError(routingContext.response(), e);
}
} else {
JsonResponse.unprocessableEntity(routingContext.response(), String.format("Holding with id=%s not found", toHoldingsRecordId));
}
}).exceptionally(e -> {
ServerErrorResponse.internalError(routingContext.response(), e);
return null;
});
}
use of org.folio.inventory.domain.items.Item 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.Item in project mod-inventory by folio-org.
the class MatchItemEventHandlerUnitTest method shouldNotMatchOnHandleEventPayload.
@Test
public void shouldNotMatchOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
doAnswer(ans -> {
Consumer<Success<MultipleRecords<Item>>> callback = ans.getArgument(2);
Success<MultipleRecords<Item>> result = new Success<>(new MultipleRecords<>(new ArrayList<>(), 0));
callback.accept(result);
return null;
}).when(itemCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchItemEventHandler(mappingMetadataCache);
DataImportEventPayload eventPayload = createEventPayload();
eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
testContext.assertNull(throwable);
testContext.assertEquals(1, updatedEventPayload.getEventsChain().size());
testContext.assertEquals(updatedEventPayload.getEventsChain(), singletonList(DI_SRS_MARC_BIB_RECORD_CREATED.value()));
testContext.assertEquals(DI_INVENTORY_ITEM_NOT_MATCHED.value(), updatedEventPayload.getEventType());
async.complete();
});
}
Aggregations