Search in sources :

Example 1 with InstanceMapper

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()));
    }));
}
Also used : Clients(org.folio.circulation.support.Clients) RecordFetching.findWithMultipleCqlIndexValues(org.folio.circulation.support.fetching.RecordFetching.findWithMultipleCqlIndexValues) MultipleRecords(org.folio.circulation.domain.MultipleRecords) InstanceMapper(org.folio.circulation.storage.mappers.InstanceMapper) SingleRecordFetcher(org.folio.circulation.support.SingleRecordFetcher) Predicate(java.util.function.Predicate) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) Request(org.folio.circulation.domain.Request) CompletableFuture(java.util.concurrent.CompletableFuture) CollectionResourceClient(org.folio.circulation.support.CollectionResourceClient) Result(org.folio.circulation.support.results.Result) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Instance(org.folio.circulation.domain.Instance) LogManager(org.apache.logging.log4j.LogManager) MultipleRecords(org.folio.circulation.domain.MultipleRecords) Request(org.folio.circulation.domain.Request) Objects(java.util.Objects) InstanceMapper(org.folio.circulation.storage.mappers.InstanceMapper) List(java.util.List)

Example 2 with InstanceMapper

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);
}
Also used : Address(api.support.builders.Address) RequestBuilder(api.support.builders.RequestBuilder) JsonObject(io.vertx.core.json.JsonObject) JsonArray(io.vertx.core.json.JsonArray) ZonedDateTime(java.time.ZonedDateTime) InstanceMapper(org.folio.circulation.storage.mappers.InstanceMapper) UUID(java.util.UUID) UserBuilder(api.support.builders.UserBuilder)

Example 3 with InstanceMapper

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"));
}
Also used : User(org.folio.circulation.domain.User) Address(api.support.builders.Address) RequestBuilder(api.support.builders.RequestBuilder) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Response(org.folio.circulation.support.http.client.Response) Item(org.folio.circulation.domain.Item) ZonedDateTime(java.time.ZonedDateTime) InstanceMapper(org.folio.circulation.storage.mappers.InstanceMapper) UUID(java.util.UUID) CallNumberComponents(org.folio.circulation.domain.CallNumberComponents) Location(org.folio.circulation.domain.Location) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceMapper (org.folio.circulation.storage.mappers.InstanceMapper)3 Address (api.support.builders.Address)2 RequestBuilder (api.support.builders.RequestBuilder)2 JsonObject (io.vertx.core.json.JsonObject)2 ZonedDateTime (java.time.ZonedDateTime)2 UUID (java.util.UUID)2 UserBuilder (api.support.builders.UserBuilder)1 IndividualResource (api.support.http.IndividualResource)1 ItemResource (api.support.http.ItemResource)1 JsonArray (io.vertx.core.json.JsonArray)1 MethodHandles (java.lang.invoke.MethodHandles)1 Collection (java.util.Collection)1 List (java.util.List)1 Objects (java.util.Objects)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 LogManager (org.apache.logging.log4j.LogManager)1