Search in sources :

Example 1 with CallNumberComponents

use of org.folio.circulation.domain.CallNumberComponents in project mod-circulation by folio-org.

the class TemplateContextUtil method createItemContext.

private static JsonObject createItemContext(Item item) {
    String contributorNamesToken = item.getContributorNames().collect(joining("; "));
    String yearCaptionsToken = String.join("; ", item.getYearCaption());
    String copyNumber = item.getCopyNumber() != null ? item.getCopyNumber() : "";
    JsonObject itemContext = new JsonObject().put("title", item.getTitle()).put("barcode", item.getBarcode()).put("status", item.getStatus().getValue()).put("primaryContributor", item.getPrimaryContributorName()).put("allContributors", contributorNamesToken).put("enumeration", item.getEnumeration()).put("volume", item.getVolume()).put("chronology", item.getChronology()).put("yearCaption", yearCaptionsToken).put("materialType", item.getMaterialTypeName()).put("loanType", item.getLoanTypeName()).put("copy", copyNumber).put("numberOfPieces", item.getNumberOfPieces()).put("descriptionOfPieces", item.getDescriptionOfPieces());
    Location location = item.getLocation();
    if (location != null) {
        itemContext.put("effectiveLocationSpecific", location.getName()).put("effectiveLocationLibrary", location.getLibraryName()).put("effectiveLocationCampus", location.getCampusName()).put("effectiveLocationInstitution", location.getInstitutionName());
    }
    CallNumberComponents callNumberComponents = item.getCallNumberComponents();
    if (callNumberComponents != null) {
        itemContext.put("callNumber", callNumberComponents.getCallNumber()).put("callNumberPrefix", callNumberComponents.getPrefix()).put("callNumberSuffix", callNumberComponents.getSuffix());
    }
    return itemContext;
}
Also used : JsonObject(io.vertx.core.json.JsonObject) CallNumberComponents(org.folio.circulation.domain.CallNumberComponents) Location(org.folio.circulation.domain.Location)

Example 2 with CallNumberComponents

use of org.folio.circulation.domain.CallNumberComponents 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

JsonObject (io.vertx.core.json.JsonObject)2 CallNumberComponents (org.folio.circulation.domain.CallNumberComponents)2 Location (org.folio.circulation.domain.Location)2 Address (api.support.builders.Address)1 RequestBuilder (api.support.builders.RequestBuilder)1 IndividualResource (api.support.http.IndividualResource)1 ItemResource (api.support.http.ItemResource)1 ZonedDateTime (java.time.ZonedDateTime)1 UUID (java.util.UUID)1 Item (org.folio.circulation.domain.Item)1 User (org.folio.circulation.domain.User)1 InstanceMapper (org.folio.circulation.storage.mappers.InstanceMapper)1 Response (org.folio.circulation.support.http.client.Response)1 Test (org.junit.jupiter.api.Test)1