use of org.folio.circulation.storage.mappers.InstanceMapper in project mod-circulation by folio-org.
the class InstanceRepository method findInstancesForRequests.
public CompletableFuture<Result<MultipleRecords<Request>>> findInstancesForRequests(MultipleRecords<Request> multipleRequests) {
Collection<Request> requests = multipleRequests.getRecords();
final List<String> instanceIdsToFetch = requests.stream().filter(Objects::nonNull).map(Request::getInstanceId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
if (instanceIdsToFetch.isEmpty()) {
log.info("No instance ids to query");
return completedFuture(succeeded(multipleRequests));
}
InstanceMapper mapper = new InstanceMapper();
return findWithMultipleCqlIndexValues(instancesClient, "instances", mapper::toDomain).findByIds(instanceIdsToFetch).thenApply(multipleInstancesResult -> multipleInstancesResult.next(multipleInstances -> {
List<Request> newRequestList = requests.stream().map(getRequestMapper(multipleInstances)).collect(Collectors.toList());
return succeeded(new MultipleRecords<>(newRequestList, multipleRequests.getTotalRecords()));
}));
}
use of org.folio.circulation.storage.mappers.InstanceMapper in project mod-circulation by folio-org.
the class RequestRepresentationTests method createMockRequest.
private Request createMockRequest() {
final UserBuilder userBuilder = new UserBuilder().withName("Test", "User").withBarcode("764523186496").withAddress(new Address(ADDRESS_ID, "Fake first address line", "Fake second address line", "Fake city", "Fake region", "Fake postal code", "Fake country code"));
final User requester = new User(userBuilder.create());
final UUID requesterId = UUID.fromString(requester.getId());
final ZonedDateTime requestDate = ZonedDateTime.of(2017, 7, 22, 10, 22, 54, 0, UTC);
final var servicePoint = new ServicePoint(SERVICE_POINT_ID.toString(), "Circ Desk", "cd1", true, "Circulation Desk", null, null, null);
JsonObject instanceRepresentation = new JsonObject();
write(instanceRepresentation, EDITIONS, new JsonArray().add("First American Edition"));
write(instanceRepresentation, IDENTIFIERS, new JsonArray().add(new JsonObject().put("identifierTypeId", IDENTIFIER_ID).put("value", IDENTIFIER_VALUE)));
JsonObject publication = new JsonObject();
publication.put("publisher", "fake publisher");
publication.put("place", "fake place");
publication.put("dateOfPublication", "2016");
write(instanceRepresentation, PUBLICATION, new JsonArray().add(publication));
write(instanceRepresentation, ID, UUID.randomUUID().toString());
Instance instance = new InstanceMapper().toDomain(instanceRepresentation);
final Item item = Item.from(new JsonObject()).withInstance(instance);
JsonObject requestJsonObject = new RequestBuilder().recall().withId(REQUEST_ID).withInstanceId(INSTANCE_ID).withRequestDate(requestDate).itemRequestLevel().withItemId(ITEM_ID).withRequesterId(requesterId).fulfilToHoldShelf().withPickupServicePointId(SERVICE_POINT_ID).withRequestExpiration(LocalDate.of(2017, 7, 30)).deliverToAddress(ADDRESS_ID).create();
return Request.from(requestJsonObject).withInstance(instance).withRequester(requester).withPickupServicePoint(servicePoint).withItem(item);
}
use of org.folio.circulation.storage.mappers.InstanceMapper 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"));
}
Aggregations