Search in sources :

Example 6 with Address

use of api.support.builders.Address in project mod-circulation by folio-org.

the class CheckInByBarcodeTests method canCreateStaffSlipContextOnCheckInByBarcode.

@Test
void canCreateStaffSlipContextOnCheckInByBarcode() {
    ItemResource item = itemsFixture.basedUponSmallAngryPlanet();
    ZonedDateTime requestDate = ZonedDateTime.of(2019, 7, 22, 10, 22, 54, 0, UTC);
    IndividualResource servicePoint = servicePointsFixture.cd1();
    Address address = SiriusBlack();
    IndividualResource requester = usersFixture.steve(builder -> builder.withAddress(address));
    final var requestExpiration = java.time.LocalDate.of(2019, 7, 30);
    final var holdShelfExpiration = java.time.LocalDate.of(2019, 8, 31);
    IndividualResource request = requestsFixture.place(new RequestBuilder().withId(UUID.randomUUID()).open().page().forItem(item).by(requester).withRequestDate(requestDate).fulfilToHoldShelf().withRequestExpiration(requestExpiration).withHoldShelfExpiration(holdShelfExpiration).withPickupServicePointId(servicePoint.getId()).withDeliveryAddressType(addressTypesFixture.home().getId()).withPatronComments("I need the book").withTags(new RequestBuilder.Tags(asList("new", "important"))));
    ZonedDateTime checkInDate = ZonedDateTime.of(2019, 7, 25, 14, 23, 41, 0, UTC);
    CheckInByBarcodeResponse response = checkInFixture.checkInByBarcode(item, checkInDate, servicePoint.getId());
    User requesterUser = new User(requester.getJson());
    JsonObject staffSlipContext = response.getStaffSlipContext();
    JsonObject userContext = staffSlipContext.getJsonObject("requester");
    JsonObject requestContext = staffSlipContext.getJsonObject("request");
    assertThat(userContext.getString("firstName"), is(requesterUser.getFirstName()));
    assertThat(userContext.getString("lastName"), is(requesterUser.getLastName()));
    assertThat(userContext.getString("middleName"), is(requesterUser.getMiddleName()));
    assertThat(userContext.getString("barcode"), is(requesterUser.getBarcode()));
    assertThat(userContext.getString("addressLine1"), is(address.getAddressLineOne()));
    assertThat(userContext.getString("addressLine2"), is(address.getAddressLineTwo()));
    assertThat(userContext.getString("city"), is(address.getCity()));
    assertThat(userContext.getString("region"), is(address.getRegion()));
    assertThat(userContext.getString("postalCode"), is(address.getPostalCode()));
    assertThat(userContext.getString("countryId"), is(address.getCountryId()));
    assertThat(requestContext.getString("deliveryAddressType"), is(addressTypesFixture.home().getJson().getString("addressType")));
    assertThat(requestContext.getString("requestExpirationDate"), isEquivalentTo(ZonedDateTime.of(requestExpiration.atTime(23, 59, 59), ZoneOffset.UTC)));
    assertThat(requestContext.getString("holdShelfExpirationDate"), isEquivalentTo(ZonedDateTime.of(holdShelfExpiration.atStartOfDay(), ZoneOffset.UTC)));
    assertThat(requestContext.getString("requestID"), is(request.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) CheckInByBarcodeRequestBuilder(api.support.builders.CheckInByBarcodeRequestBuilder) RequestBuilder(api.support.builders.RequestBuilder) ZonedDateTime(java.time.ZonedDateTime) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) CheckInByBarcodeResponse(api.support.CheckInByBarcodeResponse) Test(org.junit.jupiter.api.Test)

Example 7 with Address

use of api.support.builders.Address 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 8 with Address

use of api.support.builders.Address in project mod-circulation by folio-org.

the class UserAddressTests method noAddressFoundWhenOnlyAddressHasNoType.

@Test
void noAddressFoundWhenOnlyAddressHasNoType() {
    // TODO: Replace with address builder
    final User user = new User(new UserBuilder().withAddress(new Address(null, "Fake address", null, null, null, null, null)).create());
    JsonObject foundAddress = user.getAddressByType(WORK_ADDRESS_TYPE.toString());
    assertThat("Should not find an address", foundAddress, nullValue());
}
Also used : Address(api.support.builders.Address) JsonObject(io.vertx.core.json.JsonObject) UserBuilder(api.support.builders.UserBuilder) Test(org.junit.jupiter.api.Test)

Example 9 with Address

use of api.support.builders.Address 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

Address (api.support.builders.Address)9 JsonObject (io.vertx.core.json.JsonObject)9 RequestBuilder (api.support.builders.RequestBuilder)8 Test (org.junit.jupiter.api.Test)8 IndividualResource (api.support.http.IndividualResource)7 ZonedDateTime (java.time.ZonedDateTime)5 ItemResource (api.support.http.ItemResource)3 UUID (java.util.UUID)3 CheckInByBarcodeResponse (api.support.CheckInByBarcodeResponse)2 CheckInByBarcodeRequestBuilder (api.support.builders.CheckInByBarcodeRequestBuilder)2 ItemBuilder (api.support.builders.ItemBuilder)2 UserBuilder (api.support.builders.UserBuilder)2 User (org.folio.circulation.domain.User)2 InstanceMapper (org.folio.circulation.storage.mappers.InstanceMapper)2 Response (org.folio.circulation.support.http.client.Response)2 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)2 MultipleJsonRecords (api.support.MultipleJsonRecords)1 FeeFineBuilder (api.support.builders.FeeFineBuilder)1 FeeFineOwnerBuilder (api.support.builders.FeeFineOwnerBuilder)1 MoveRequestBuilder (api.support.builders.MoveRequestBuilder)1