Search in sources :

Example 1 with User

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

the class TemplateContextUtil method createStaffSlipContext.

public static JsonObject createStaffSlipContext(Item item, Request request) {
    JsonObject staffSlipContext = new JsonObject();
    if (item != null) {
        JsonObject itemContext = createItemContext(item);
        if (item.getLastCheckIn() != null) {
            write(itemContext, "lastCheckedInDateTime", item.getLastCheckIn().getDateTime());
        }
        staffSlipContext.put(ITEM, itemContext);
    }
    if (request != null) {
        staffSlipContext.put(REQUEST, createRequestContext(request));
        User requester = request.getRequester();
        if (requester != null) {
            staffSlipContext.put(REQUESTER, createUserContext(requester, request.getDeliveryAddressTypeId()));
        }
    }
    return staffSlipContext;
}
Also used : User(org.folio.circulation.domain.User) JsonObject(io.vertx.core.json.JsonObject)

Example 2 with User

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

the class GroupedLoanScheduledNoticeHandler method sendGroupedNotice.

private CompletableFuture<Result<List<ScheduledNoticeContext>>> sendGroupedNotice(List<ScheduledNoticeContext> contexts) {
    if (contexts.isEmpty()) {
        log.warn("No notices left in the group to process, skipping the group");
        return completedFuture(succeeded(contexts));
    }
    List<ScheduledNoticeContext> relevantContexts = contexts.stream().filter(not(loanScheduledNoticeHandler::isNoticeIrrelevant)).collect(toList());
    if (relevantContexts.isEmpty()) {
        log.warn("No relevant notices in the group, skipping the group");
        return completedFuture(succeeded(contexts));
    }
    // All the notices have the same properties so we can get any of them
    ScheduledNoticeContext contextSample = relevantContexts.get(0);
    User user = contextSample.getLoan().getUser();
    List<Loan> loans = relevantContexts.stream().map(ScheduledNoticeContext::getLoan).collect(toList());
    log.info("Attempting to send a grouped notice for {} scheduled notices", relevantContexts.size());
    return patronNoticeService.sendNotice(contextSample.getNotice().getConfiguration(), user.getId(), createMultiLoanNoticeContext(user, loans), buildNoticeLogContext(relevantContexts, user)).thenApply(mapResult(v -> contexts));
}
Also used : Clients(org.folio.circulation.support.Clients) ScheduledNoticeContext(org.folio.circulation.domain.notice.schedule.ScheduledNoticeHandler.ScheduledNoticeContext) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ResultBinding.mapResult(org.folio.circulation.support.results.ResultBinding.mapResult) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) AsyncCoordinationUtil.allOf(org.folio.circulation.support.AsyncCoordinationUtil.allOf) AsyncCoordinationUtil.allResultsOf(org.folio.circulation.support.AsyncCoordinationUtil.allResultsOf) HttpFailure(org.folio.circulation.support.HttpFailure) ScheduledPatronNoticeService(org.folio.circulation.domain.notice.ScheduledPatronNoticeService) Logger(org.slf4j.Logger) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) MethodHandles(java.lang.invoke.MethodHandles) Loan(org.folio.circulation.domain.Loan) Result(org.folio.circulation.support.results.Result) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) User(org.folio.circulation.domain.User) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) NoticeLogContextItem(org.folio.circulation.domain.representations.logs.NoticeLogContextItem) TemplateContextUtil.createMultiLoanNoticeContext(org.folio.circulation.domain.notice.TemplateContextUtil.createMultiLoanNoticeContext) Predicate.not(java.util.function.Predicate.not) NoticeLogContext(org.folio.circulation.domain.representations.logs.NoticeLogContext) User(org.folio.circulation.domain.User) Loan(org.folio.circulation.domain.Loan) ScheduledNoticeContext(org.folio.circulation.domain.notice.schedule.ScheduledNoticeHandler.ScheduledNoticeContext)

Example 3 with User

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

the class InactiveUserValidatorTests method refuseWhenUserIsNeitherActiveNorInactive.

@Test
void refuseWhenUserIsNeitherActiveNorInactive() {
    final User steve = new User(basedUponStevenJones().neitherActiveOrInactive().create());
    final InactiveUserValidator validator = forUser(steve.getBarcode());
    final Result<LoanAndRelatedRecords> result = validator.refuseWhenUserIsInactive(steve, null);
    assertThat(result.failed(), 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 4 with User

use of org.folio.circulation.domain.User 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 5 with User

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

the class InactiveUserValidatorTests method refuseInactiveUser.

@Test
void refuseInactiveUser() {
    final User steve = new User(basedUponStevenJones().inactive().create());
    final InactiveUserValidator validator = forUser(steve.getBarcode());
    final Result<LoanAndRelatedRecords> result = validator.refuseWhenUserIsInactive(steve, null);
    assertThat(result.failed(), 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)

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