Search in sources :

Example 6 with User

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));
}
Also used : User(org.folio.circulation.domain.User) InactiveUserValidator.forUser(org.folio.circulation.domain.validation.InactiveUserValidator.forUser) LoanAndRelatedRecords(org.folio.circulation.domain.LoanAndRelatedRecords) Test(org.junit.jupiter.api.Test)

Example 7 with User

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));
}
Also used : AccountActionResponse(org.folio.circulation.services.feefine.AccountActionResponse) User(org.folio.circulation.domain.User) ServerErrorFailure(org.folio.circulation.support.ServerErrorFailure) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 8 with User

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

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;
}
Also used : ServicePoint(org.folio.circulation.domain.ServicePoint) JsonArray(io.vertx.core.json.JsonArray) ItemStatus(org.folio.circulation.domain.ItemStatus) LastCheckIn(org.folio.circulation.domain.LastCheckIn) User(org.folio.circulation.domain.User) Loan(org.folio.circulation.domain.Loan) Holdings(org.folio.circulation.domain.Holdings) Request(org.folio.circulation.domain.Request) JsonObject(io.vertx.core.json.JsonObject) PatronGroup(org.folio.circulation.domain.PatronGroup) Location(org.folio.circulation.domain.Location)

Example 10 with User

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));
}
Also used : Clients(org.folio.circulation.support.Clients) ResultBinding.mapResult(org.folio.circulation.support.results.ResultBinding.mapResult) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) CompletableFuture(java.util.concurrent.CompletableFuture) TemplateContextUtil.createLoanNoticeContextWithoutUser(org.folio.circulation.domain.notice.TemplateContextUtil.createLoanNoticeContextWithoutUser) CheckInContext(org.folio.circulation.domain.CheckInContext) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) AsyncCoordinationUtil.allOf(org.folio.circulation.support.AsyncCoordinationUtil.allOf) NoticeEventType(org.folio.circulation.domain.notice.NoticeEventType) LoanAndRelatedRecords(org.folio.circulation.domain.LoanAndRelatedRecords) PageLimit(org.folio.circulation.support.http.client.PageLimit) PatronNoticeEvent(org.folio.circulation.domain.notice.PatronNoticeEvent) EnumMap(java.util.EnumMap) Result.of(org.folio.circulation.support.results.Result.of) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) MethodHandles(java.lang.invoke.MethodHandles) Loan(org.folio.circulation.domain.Loan) PatronActionSessionRepository(org.folio.circulation.infrastructure.storage.sessions.PatronActionSessionRepository) PageLimit.limit(org.folio.circulation.support.http.client.PageLimit.limit) UUID(java.util.UUID) ImmediatePatronNoticeService(org.folio.circulation.domain.notice.ImmediatePatronNoticeService) Result(org.folio.circulation.support.results.Result) Collectors(java.util.stream.Collectors) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) EventPublisher(org.folio.circulation.services.EventPublisher) User(org.folio.circulation.domain.User) PatronNoticeEventBuilder(org.folio.circulation.domain.notice.PatronNoticeEventBuilder) List(java.util.List) Logger(org.apache.logging.log4j.Logger) AsynchronousResultBindings.safelyInitialise(org.folio.circulation.support.results.AsynchronousResultBindings.safelyInitialise) NoticeLogContext(org.folio.circulation.domain.representations.logs.NoticeLogContext) AllArgsConstructor(lombok.AllArgsConstructor) LogManager(org.apache.logging.log4j.LogManager) LoanNoticeContextCombiner(org.folio.circulation.domain.notice.combiner.LoanNoticeContextCombiner) TemplateContextUtil.createLoanNoticeContextWithoutUser(org.folio.circulation.domain.notice.TemplateContextUtil.createLoanNoticeContextWithoutUser) User(org.folio.circulation.domain.User)

Aggregations

User (org.folio.circulation.domain.User)13 JsonObject (io.vertx.core.json.JsonObject)7 Test (org.junit.jupiter.api.Test)6 LoanAndRelatedRecords (org.folio.circulation.domain.LoanAndRelatedRecords)5 Loan (org.folio.circulation.domain.Loan)4 ZonedDateTime (java.time.ZonedDateTime)3 List (java.util.List)3 InactiveUserValidator.forUser (org.folio.circulation.domain.validation.InactiveUserValidator.forUser)3 Address (api.support.builders.Address)2 RequestBuilder (api.support.builders.RequestBuilder)2 IndividualResource (api.support.http.IndividualResource)2 ItemResource (api.support.http.ItemResource)2 JsonArray (io.vertx.core.json.JsonArray)2 MethodHandles (java.lang.invoke.MethodHandles)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)2 Collectors (java.util.stream.Collectors)2 CheckInContext (org.folio.circulation.domain.CheckInContext)2 Item (org.folio.circulation.domain.Item)2