Search in sources :

Example 21 with Item

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"));
}
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)

Example 22 with Item

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());
}
Also used : Item(org.folio.circulation.domain.Item) RequestByInstanceIdRequest(org.folio.circulation.domain.representations.RequestByInstanceIdRequest) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) InstanceRequestRelatedRecords(org.folio.circulation.domain.InstanceRequestRelatedRecords) UUID(java.util.UUID) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 23 with Item

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;
}
Also used : Item(org.folio.circulation.domain.Item)

Example 24 with Item

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;
}
Also used : Item(org.folio.circulation.domain.Item)

Example 25 with Item

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);
    });
}
Also used : UpdateItem(org.folio.circulation.domain.UpdateItem) Item(org.folio.circulation.domain.Item) CompletableFuture(java.util.concurrent.CompletableFuture) HashMap(java.util.HashMap) UpdateRequestQueue(org.folio.circulation.domain.UpdateRequestQueue) RequestQueue(org.folio.circulation.domain.RequestQueue) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Item (org.folio.circulation.domain.Item)29 JsonObject (io.vertx.core.json.JsonObject)17 Loan (org.folio.circulation.domain.Loan)13 UUID (java.util.UUID)12 Result (org.folio.circulation.support.results.Result)12 CompletableFuture (java.util.concurrent.CompletableFuture)11 Map (java.util.Map)10 Request (org.folio.circulation.domain.Request)10 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)10 HashMap (java.util.HashMap)9 ZonedDateTime (java.time.ZonedDateTime)8 ArrayList (java.util.ArrayList)8 RequestQueue (org.folio.circulation.domain.RequestQueue)8 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)8 Result.succeeded (org.folio.circulation.support.results.Result.succeeded)8 List (java.util.List)7 UpdateItem (org.folio.circulation.domain.UpdateItem)7 RequestByInstanceIdRequest (org.folio.circulation.domain.representations.RequestByInstanceIdRequest)7 ItemRepository (org.folio.circulation.infrastructure.storage.inventory.ItemRepository)7 Test (org.junit.jupiter.api.Test)7