use of org.folio.circulation.domain.Item in project mod-circulation by folio-org.
the class PickSlipsTests method responseContainsPickSlipWithAllAvailableTokens.
@Test
void responseContainsPickSlipWithAllAvailableTokens() {
IndividualResource servicePoint = servicePointsFixture.cd1();
UUID servicePointId = servicePoint.getId();
IndividualResource locationResource = locationsFixture.thirdFloor();
IndividualResource addressTypeResource = addressTypesFixture.home();
Address address = AddressExamples.mainStreet();
IndividualResource requesterResource = usersFixture.steve(builder -> builder.withAddress(address));
ZonedDateTime requestDate = ZonedDateTime.of(2019, 7, 22, 10, 22, 54, 0, UTC);
final var requestExpiration = LocalDate.of(2019, 7, 30);
final var holdShelfExpiration = LocalDate.of(2019, 8, 31);
IndividualResource materialTypeResource = materialTypesFixture.book();
IndividualResource loanTypeResource = loanTypesFixture.canCirculate();
ItemResource itemResource = itemsFixture.basedUponSmallAngryPlanet(builder -> builder.withEnumeration("v.70:no.7-12").withVolume("vol.1").withChronology("1984:July-Dec.").withYearCaption(Arrays.asList("1984", "1985")).withCopyNumber("cp.2").withNumberOfPieces("3").withDescriptionOfPieces("Description of three pieces").withPermanentLocation(locationResource).withMaterialType(materialTypeResource.getId()).withPermanentLoanType(loanTypeResource.getId()));
ZonedDateTime now = ClockUtil.getZonedDateTime();
checkOutFixture.checkOutByBarcode(itemResource, requesterResource);
checkInFixture.checkInByBarcode(itemResource, now, servicePointId);
JsonObject lastCheckIn = itemsClient.get(itemResource.getId()).getJson().getJsonObject("lastCheckIn");
ZonedDateTime actualCheckinDateTime = getDateTimeProperty(lastCheckIn, "dateTime");
IndividualResource requestResource = requestsFixture.place(new RequestBuilder().withStatus(RequestStatus.OPEN_NOT_YET_FILLED.getValue()).open().page().withRequestDate(requestDate).withRequestExpiration(requestExpiration).withHoldShelfExpiration(holdShelfExpiration).withPickupServicePointId(servicePointId).withDeliveryAddressType(addressTypeResource.getId()).forItem(itemResource).withPatronComments("I need the book").by(requesterResource));
Response response = ResourceClient.forPickSlips().getById(servicePointId);
assertThat(response.getStatusCode(), is(HTTP_OK));
assertResponseHasItems(response, 1);
JsonObject pickSlip = getPickSlipsList(response).get(0);
JsonObject itemContext = pickSlip.getJsonObject(ITEM_KEY);
Item item = Item.from(itemResource.getJson()).withInstance(new InstanceMapper().toDomain(itemResource.getInstance().getJson()));
String contributorNames = item.getContributorNames().collect(joining("; "));
String yearCaptionsToken = String.join("; ", item.getYearCaption());
String copyNumber = item.getCopyNumber() != null ? item.getCopyNumber() : "";
String materialTypeName = getName(materialTypeResource.getJson());
String loanTypeName = getName(loanTypeResource.getJson());
Location location = Location.from(locationResource.getJson());
assertEquals(item.getTitle(), itemContext.getString("title"));
assertEquals(item.getBarcode(), itemContext.getString("barcode"));
assertEquals(ItemStatus.PAGED.getValue(), itemContext.getString("status"));
assertEquals(item.getPrimaryContributorName(), itemContext.getString("primaryContributor"));
assertEquals(contributorNames, itemContext.getString("allContributors"));
assertEquals(item.getEnumeration(), itemContext.getString("enumeration"));
assertEquals(item.getVolume(), itemContext.getString("volume"));
assertEquals(item.getChronology(), itemContext.getString("chronology"));
assertEquals(yearCaptionsToken, itemContext.getString("yearCaption"));
assertEquals(materialTypeName, itemContext.getString("materialType"));
assertEquals(loanTypeName, itemContext.getString("loanType"));
assertEquals(copyNumber, itemContext.getString("copy"));
assertEquals(item.getNumberOfPieces(), itemContext.getString("numberOfPieces"));
assertEquals(item.getDescriptionOfPieces(), itemContext.getString("descriptionOfPieces"));
assertEquals(actualCheckinDateTime.toString(), itemContext.getString("lastCheckedInDateTime"));
assertEquals(location.getName(), itemContext.getString("effectiveLocationSpecific"));
CallNumberComponents callNumberComponents = item.getCallNumberComponents();
assertEquals(callNumberComponents.getCallNumber(), itemContext.getString("callNumber"));
assertEquals(callNumberComponents.getPrefix(), itemContext.getString("callNumberPrefix"));
assertEquals(callNumberComponents.getSuffix(), itemContext.getString("callNumberSuffix"));
User requester = new User(requesterResource.getJson());
JsonObject requesterContext = pickSlip.getJsonObject("requester");
assertThat(requesterContext.getString("firstName"), is(requester.getFirstName()));
assertThat(requesterContext.getString("lastName"), is(requester.getLastName()));
assertThat(requesterContext.getString("middleName"), is(requester.getMiddleName()));
assertThat(requesterContext.getString("barcode"), is(requester.getBarcode()));
assertThat(requesterContext.getString("addressLine1"), is(address.getAddressLineOne()));
assertThat(requesterContext.getString("addressLine2"), is(address.getAddressLineTwo()));
assertThat(requesterContext.getString("city"), is(address.getCity()));
assertThat(requesterContext.getString("region"), is(address.getRegion()));
assertThat(requesterContext.getString("postalCode"), is(address.getPostalCode()));
assertThat(requesterContext.getString("countryId"), is(address.getCountryId()));
JsonObject requestContext = pickSlip.getJsonObject("request");
assertThat(requestContext.getString("deliveryAddressType"), is(addressTypeResource.getJson().getString("addressType")));
assertThat(requestContext.getString("requestExpirationDate"), isEquivalentTo(requestExpiration.atTime(23, 59, 59).atZone(UTC)));
assertThat(requestContext.getString("holdShelfExpirationDate"), isEquivalentTo(ZonedDateTime.of(holdShelfExpiration.atStartOfDay(), ZoneOffset.UTC)));
assertThat(requestContext.getString("requestID"), UUIDMatcher.is(requestResource.getId()));
assertThat(requestContext.getString("servicePointPickup"), is(servicePoint.getJson().getString("name")));
assertThat(requestContext.getString("patronComments"), is("I need the book"));
}
use of org.folio.circulation.domain.Item in project mod-circulation by folio-org.
the class RequestByInstanceIdResourceTests method canGetOrderedAvailableItemsList.
@Test
void canGetOrderedAvailableItemsList() {
UUID primaryServicePointId = servicePointsFixture.cd2().getId();
UUID secondaryServicePointId = UUID.randomUUID();
UUID institutionId = UUID.randomUUID();
HashSet<UUID> servicePoints1 = new HashSet<>();
servicePoints1.add(secondaryServicePointId);
JsonObject location1 = getLocationWithServicePoints(servicePoints1, secondaryServicePointId, institutionId);
// Matching item and servicePoints
HashSet<UUID> servicePoints2 = new HashSet<>();
servicePoints2.add(primaryServicePointId);
servicePoints2.add(secondaryServicePointId);
JsonObject location2 = getLocationWithServicePoints(servicePoints2, primaryServicePointId, institutionId);
JsonObject location3 = getLocationWithServicePoints(emptySet(), null, institutionId);
// Matching item and servicePoints
HashSet<UUID> servicePoints4 = new HashSet<>();
servicePoints4.add(primaryServicePointId);
JsonObject location4 = getLocationWithServicePoints(servicePoints4, primaryServicePointId, institutionId);
UUID bookMaterialTypeId = UUID.randomUUID();
UUID loanTypeId = UUID.randomUUID();
Item item1 = Item.from(ItemExamples.basedUponSmallAngryPlanet(bookMaterialTypeId, loanTypeId).withTemporaryLocation(UUID.fromString(location1.getString("id"))).create()).withLocation(Location.from(location1));
Item item2 = Item.from(ItemExamples.basedUponSmallAngryPlanet(bookMaterialTypeId, loanTypeId).withTemporaryLocation(UUID.fromString(location2.getString("id"))).create()).withLocation(Location.from(location2));
Item item3 = Item.from(ItemExamples.basedUponSmallAngryPlanet(bookMaterialTypeId, loanTypeId).withTemporaryLocation(UUID.fromString(location3.getString("id"))).create()).withLocation(Location.from(location3));
Item item4 = Item.from(ItemExamples.basedUponSmallAngryPlanet(bookMaterialTypeId, loanTypeId).withTemporaryLocation(UUID.fromString(location4.getString("id"))).create()).withLocation(Location.from(location4));
final ArrayList<Item> items = new ArrayList<>();
items.add(item2);
items.add(item3);
items.add(item4);
items.add(item1);
InstanceRequestRelatedRecords records = new InstanceRequestRelatedRecords();
JsonObject requestJson = getJsonInstanceRequest(primaryServicePointId);
Result<RequestByInstanceIdRequest> request = RequestByInstanceIdRequest.from(requestJson);
records.setUnsortedAvailableItems(items);
records.setInstanceLevelRequest(request.value());
Result<InstanceRequestRelatedRecords> rankResult = rankItemsByMatchingServicePoint(records);
final List<Item> orderedItems = rankResult.value().getCombinedSortedItemsList();
assertEquals(4, orderedItems.size());
assertEquals(item2.getItemId(), orderedItems.get(0).getItemId());
assertEquals(item4.getItemId(), orderedItems.get(1).getItemId());
assertEquals(item3.getItemId(), orderedItems.get(2).getItemId());
assertEquals(item1.getItemId(), orderedItems.get(3).getItemId());
}
use of org.folio.circulation.domain.Item in project mod-circulation by folio-org.
the class NoticeLogContextItem method from.
public static NoticeLogContextItem from(Request request) {
Item item = request.getItem();
NoticeLogContextItem logContextItem = new NoticeLogContextItem();
if (item != null) {
logContextItem = logContextItem.withItemId(item.getItemId()).withItemBarcode(item.getBarcode()).withInstanceId(item.getInstanceId()).withHoldingsRecordId(item.getHoldingsRecordId());
}
if (Objects.nonNull(request.getPickupServicePointId())) {
logContextItem = logContextItem.withServicePointId(request.getPickupServicePointId());
}
return logContextItem;
}
use of org.folio.circulation.domain.Item in project mod-circulation by folio-org.
the class NoticeLogContextItem method from.
public static NoticeLogContextItem from(Loan loan) {
NoticeLogContextItem noticeLogContextItem = new NoticeLogContextItem();
if (loan != null) {
noticeLogContextItem = noticeLogContextItem.withItemId(loan.getItemId()).withLoanId(loan.getId()).withServicePointId(loan.getCheckoutServicePointId());
Item item = loan.getItem();
if (item != null) {
noticeLogContextItem = noticeLogContextItem.withItemBarcode(item.getBarcode()).withInstanceId(item.getInstanceId()).withHoldingsRecordId(item.getHoldingsRecordId());
}
}
return noticeLogContextItem;
}
use of org.folio.circulation.domain.Item in project mod-circulation by folio-org.
the class RequestByInstanceIdResource method getRequestQueues.
private CompletableFuture<Result<Map<Item, RequestQueue>>> getRequestQueues(Collection<Item> items, InstanceRequestRelatedRecords instanceRequestPackage, RequestQueueRepository requestQueueRepository) {
Map<Item, CompletableFuture<Result<RequestQueue>>> itemRequestQueueMap = new HashMap<>();
instanceRequestPackage.setAllUnsortedItems(items);
for (Item item : items) {
itemRequestQueueMap.put(item, requestQueueRepository.getRequestQueueWithoutItemLookup(item.getItemId()));
}
final Collection<CompletableFuture<Result<RequestQueue>>> requestQueuesFutures = itemRequestQueueMap.values();
// Collect the RequestQueue objects once they come back
return CompletableFuture.allOf(requestQueuesFutures.toArray(new CompletableFuture[0])).thenApply(x -> {
Map<Item, RequestQueue> itemQueueMap = new HashMap<>();
List<Item> itemsWithoutRequestQueues = new ArrayList<>();
for (Map.Entry<Item, CompletableFuture<Result<RequestQueue>>> entry : itemRequestQueueMap.entrySet()) {
Result<RequestQueue> requestQueueResult = entry.getValue().join();
if (requestQueueResult.succeeded()) {
itemQueueMap.put(entry.getKey(), requestQueueResult.value());
} else {
itemsWithoutRequestQueues.add(entry.getKey());
}
}
if (itemsWithoutRequestQueues.size() == requestQueuesFutures.size() && (instanceRequestPackage.getSortedAvailableItems() == null || instanceRequestPackage.getSortedAvailableItems().isEmpty())) {
// fail the requests when there are no items to make requests from.
log.error("Failed to find request queues for all items of instanceId {}", instanceRequestPackage.getInstanceLevelRequest().getInstanceId());
return failedDueToServerError("Unable to find an item to place a request");
}
instanceRequestPackage.setItemsWithoutRequests(itemsWithoutRequestQueues);
instanceRequestPackage.setItemRequestQueueMap(itemQueueMap);
return succeeded(itemQueueMap);
});
}
Aggregations