use of org.folio.circulation.domain.User in project mod-circulation by folio-org.
the class InactiveUserValidatorTests method allowActiveUser.
@Test
void allowActiveUser() {
final User steve = new User(basedUponStevenJones().create());
final InactiveUserValidator validator = forUser(steve.getBarcode());
final Result<LoanAndRelatedRecords> result = validator.refuseWhenUserIsInactive(steve, null);
assertThat(result.succeeded(), is(true));
}
use of org.folio.circulation.domain.User in project mod-circulation by folio-org.
the class FeeFineFacadeTest method shouldForwardFailureIfAnAccountIsNotRefunded.
@Test
void shouldForwardFailureIfAnAccountIsNotRefunded() throws Exception {
final String expectedError = "Fee fine account failed to be refunded";
when(accountRefundClient.post(any(JsonObject.class), anyString())).thenAnswer(postRespondWithRequestAndFail(expectedError));
User user = User.from(new JsonObject().put("personal", new JsonObject().put("firstName", "Folio").put("lastName", "Tester")));
final Result<AccountActionResponse> result = feeFineFacade.refundAccountIfNeeded(refundCommand(), user).get(5, TimeUnit.SECONDS);
assertThat(result, notNullValue());
assertThat(result.failed(), is(true));
assertThat(result.cause(), instanceOf(ServerErrorFailure.class));
assertThat(((ServerErrorFailure) result.cause()).getReason(), is(expectedError));
}
use of org.folio.circulation.domain.User 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"));
}
use of org.folio.circulation.domain.User in project mod-circulation by folio-org.
the class ItemsInTransitReport method buildEntry.
private JsonObject buildEntry(Item item) {
if (item == null || item.isNotFound()) {
return new JsonObject();
}
item = ofNullable(item.getHoldingsRecordId()).map(reportContext.getHoldingsRecords()::get).map(Holdings::getInstanceId).map(reportContext.getInstances()::get).map(item::withInstance).orElse(item);
Loan loan = reportContext.getLoans().get(item.getItemId());
Request request = reportContext.getRequests().get(item.getItemId());
Location location = reportContext.getLocations().get(item.getLocationId());
if (location != null) {
ServicePoint primaryServicePoint = reportContext.getServicePoints().get(location.getPrimaryServicePointId().toString());
item = item.withLocation(location.withPrimaryServicePoint(primaryServicePoint));
}
ServicePoint inTransitDestinationServicePoint = reportContext.getServicePoints().get(item.getInTransitDestinationServicePointId());
ServicePoint lastCheckInServicePoint = reportContext.getServicePoints().get(item.getLastCheckInServicePointId().toString());
item = item.updateLastCheckInServicePoint(lastCheckInServicePoint).updateDestinationServicePoint(inTransitDestinationServicePoint);
final JsonObject entry = new JsonObject();
write(entry, "id", item.getItemId());
write(entry, "title", item.getTitle());
write(entry, "barcode", item.getBarcode());
write(entry, "contributors", mapContributorNamesToJson(item));
write(entry, "callNumber", item.getCallNumber());
write(entry, "enumeration", item.getEnumeration());
write(entry, "volume", item.getVolume());
write(entry, "yearCaption", new JsonArray(item.getYearCaption()));
writeNamedObject(entry, "status", ofNullable(item.getStatus()).map(ItemStatus::getValue).orElse(null));
write(entry, "inTransitDestinationServicePointId", item.getInTransitDestinationServicePointId());
write(entry, "copyNumber", item.getCopyNumber());
write(entry, "effectiveCallNumberComponents", createCallNumberComponents(item.getCallNumberComponents()));
if (inTransitDestinationServicePoint != null) {
writeServicePoint(entry, inTransitDestinationServicePoint, "inTransitDestinationServicePoint");
}
if (location != null) {
writeLocation(entry, location);
}
if (request != null) {
User requester = reportContext.getUsers().get(request.getRequesterId());
PatronGroup requesterPatronGroup = requester == null ? null : reportContext.getPatronGroups().get(requester.getPatronGroupId());
if (requesterPatronGroup != null) {
request = request.withRequester(requester.withPatronGroup(requesterPatronGroup));
}
ServicePoint pickupServicePoint = reportContext.getServicePoints().get(request.getPickupServicePointId());
request = request.withPickupServicePoint(pickupServicePoint);
writeRequest(request, entry);
}
if (loan != null) {
ServicePoint checkoutServicePoint = reportContext.getServicePoints().get(loan.getCheckoutServicePointId());
ServicePoint checkInServicePoint = reportContext.getServicePoints().get(loan.getCheckInServicePointId());
loan = loan.withCheckinServicePoint(checkInServicePoint).withCheckoutServicePoint(checkoutServicePoint);
writeLoan(entry, loan);
}
final LastCheckIn lastCheckIn = item.getLastCheckIn();
if (lastCheckIn != null) {
writeLastCheckIn(entry, lastCheckIn);
}
return entry;
}
use of org.folio.circulation.domain.User in project mod-circulation by folio-org.
the class PatronActionSessionService method sendNotice.
// all sessions must be for the same patron
private CompletableFuture<Result<List<PatronSessionRecord>>> sendNotice(List<PatronSessionRecord> sessions) {
if (sessions.isEmpty()) {
log.info("No patron action sessions to process");
return ofAsync(() -> null);
}
// The user is the same for all sessions
User user = sessions.get(0).getLoan().getUser();
log.info("Attempting to send a notice for a group of {} action sessions to user {}", sessions.size(), user.getId());
return patronNoticeService.acceptNoticeEvents(buildNoticeEvents(sessions)).thenApply(mapResult(v -> sessions));
}
Aggregations