Search in sources :

Example 11 with Request

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

the class RequestScheduledNoticeService method rescheduleRequestNotices.

public Result<RequestAndRelatedRecords> rescheduleRequestNotices(RequestAndRelatedRecords relatedRecords) {
    Request request = relatedRecords.getRequest();
    scheduledNoticesRepository.deleteByRequestId(request.getId()).thenAccept(r -> r.next(resp -> scheduleRequestNotices(request)));
    return succeeded(relatedRecords);
}
Also used : Clients(org.folio.circulation.support.Clients) ZonedDateTime(java.time.ZonedDateTime) Request(org.folio.circulation.domain.Request) ITEM(org.folio.circulation.domain.RequestLevel.ITEM) CheckInContext(org.folio.circulation.domain.CheckInContext) TlrSettingsConfiguration(org.folio.circulation.domain.configuration.TlrSettingsConfiguration) NoticeEventType(org.folio.circulation.domain.notice.NoticeEventType) TITLE_LEVEL_REQUEST_EXPIRATION(org.folio.circulation.domain.notice.schedule.TriggeringEvent.TITLE_LEVEL_REQUEST_EXPIRATION) RequestAndRelatedRecords(org.folio.circulation.domain.RequestAndRelatedRecords) NoticeConfigurationBuilder(org.folio.circulation.domain.notice.NoticeConfigurationBuilder) PatronNoticePolicyRepository(org.folio.circulation.infrastructure.storage.notices.PatronNoticePolicyRepository) NoticeFormat(org.folio.circulation.domain.notice.NoticeFormat) ScheduledNoticesRepository(org.folio.circulation.infrastructure.storage.notices.ScheduledNoticesRepository) NoticeConfiguration(org.folio.circulation.domain.notice.NoticeConfiguration) REQUEST_EXPIRATION(org.folio.circulation.domain.notice.schedule.TriggeringEvent.REQUEST_EXPIRATION) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) MethodHandles(java.lang.invoke.MethodHandles) UUID(java.util.UUID) PatronNoticePolicy(org.folio.circulation.domain.notice.PatronNoticePolicy) Result(org.folio.circulation.support.results.Result) TITLE(org.folio.circulation.domain.RequestLevel.TITLE) Logger(org.apache.logging.log4j.Logger) RequestLevel(org.folio.circulation.domain.RequestLevel) UPON_AT(org.folio.circulation.domain.notice.NoticeTiming.UPON_AT) Optional(java.util.Optional) LogManager(org.apache.logging.log4j.LogManager) Request(org.folio.circulation.domain.Request)

Example 12 with Request

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

the class TemplateContextUtil method createCheckInContext.

public static JsonObject createCheckInContext(CheckInContext context) {
    Item item = context.getItem();
    Request firstRequest = context.getHighestPriorityFulfillableRequest();
    JsonObject staffSlipContext = createStaffSlipContext(item, firstRequest);
    JsonObject itemContext = staffSlipContext.getJsonObject(ITEM);
    if (ObjectUtils.allNotNull(item, itemContext)) {
        write(itemContext, "lastCheckedInDateTime", ClockUtil.getZonedDateTime());
        if (item.getInTransitDestinationServicePoint() != null) {
            itemContext.put("fromServicePoint", context.getCheckInServicePoint().getName());
            itemContext.put("toServicePoint", item.getInTransitDestinationServicePoint().getName());
        }
    }
    return staffSlipContext;
}
Also used : Item(org.folio.circulation.domain.Item) Request(org.folio.circulation.domain.Request) JsonObject(io.vertx.core.json.JsonObject)

Example 13 with Request

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

the class RollingLoanPolicyCheckOutDueDateCalculationTests method shouldApplyAlternateScheduleWhenQueuedRequestIsHoldAndRolling.

@Test
void shouldApplyAlternateScheduleWhenQueuedRequestIsHoldAndRolling() {
    final Period alternateCheckoutLoanPeriod = Period.from(2, "Weeks");
    final ZonedDateTime systemTime = ZonedDateTime.of(2019, 6, 14, 11, 23, 43, 0, UTC);
    LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().rolling(Period.months(1)).withAlternateCheckoutLoanPeriod(alternateCheckoutLoanPeriod).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeYear(systemTime.getYear())).create());
    Item item = Item.from(new ItemBuilder().checkOut().withId(UUID.randomUUID()).create());
    Loan loan = Loan.from(new LoanBuilder().withItemId(UUID.fromString(item.getItemId())).withLoanDate(systemTime).create());
    Request requestOne = Request.from(new RequestBuilder().withId(UUID.randomUUID()).withPosition(1).create());
    Request requestTwo = Request.from(new RequestBuilder().withId(UUID.randomUUID()).withStatus(RequestStatus.OPEN_NOT_YET_FILLED.getValue()).hold().withItemId(UUID.fromString(loan.getItemId())).withPosition(2).create());
    RequestQueue requestQueue = new RequestQueue(asList(requestOne, requestTwo));
    ZonedDateTime calculatedDueDate = loanPolicy.calculateInitialDueDate(loan, requestQueue).value();
    String key = "alternateCheckoutLoanPeriod";
    ZonedDateTime expectedDueDate = alternateCheckoutLoanPeriod.addTo(systemTime, () -> errorForLoanPeriod(format("the \"%s\" is not recognized", key)), interval -> errorForLoanPeriod(format("the interval \"%s\" in \"%s\" is not recognized", interval, key)), dur -> errorForLoanPeriod(format("the duration \"%s\" in \"%s\" is invalid", dur, key))).value();
    assertThat(calculatedDueDate, is(expectedDueDate));
}
Also used : FailureMatcher.hasValidationFailure(api.support.matchers.FailureMatcher.hasValidationFailure) CoreMatchers.is(org.hamcrest.CoreMatchers.is) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) ZonedDateTime(java.time.ZonedDateTime) Request(org.folio.circulation.domain.Request) HashMap(java.util.HashMap) RequestBuilder(api.support.builders.RequestBuilder) Item(org.folio.circulation.domain.Item) ItemBuilder(api.support.builders.ItemBuilder) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) RequestQueue(org.folio.circulation.domain.RequestQueue) ValueSource(org.junit.jupiter.params.provider.ValueSource) Loan(org.folio.circulation.domain.Loan) LoanBuilder(api.support.builders.LoanBuilder) UUID(java.util.UUID) ValidationError(org.folio.circulation.support.http.server.ValidationError) Result(org.folio.circulation.support.results.Result) String.format(java.lang.String.format) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) FixedDueDateSchedule(api.support.builders.FixedDueDateSchedule) RequestStatus(org.folio.circulation.domain.RequestStatus) UTC(java.time.ZoneOffset.UTC) LoanBuilder(api.support.builders.LoanBuilder) RequestBuilder(api.support.builders.RequestBuilder) Request(org.folio.circulation.domain.Request) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Item(org.folio.circulation.domain.Item) ItemBuilder(api.support.builders.ItemBuilder) FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) Loan(org.folio.circulation.domain.Loan) ZonedDateTime(java.time.ZonedDateTime) RequestQueue(org.folio.circulation.domain.RequestQueue) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with Request

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

the class RequestRepository method batchUpdate.

CompletableFuture<Result<Collection<Request>>> batchUpdate(Collection<Request> requests) {
    if (requests == null || requests.isEmpty()) {
        return CompletableFuture.completedFuture(succeeded(requests));
    }
    ResponseInterpreter<Collection<Request>> interpreter = new ResponseInterpreter<Collection<Request>>().on(201, of(() -> requests)).otherwise(forwardOnFailure());
    RequestBatch requestBatch = new RequestBatch(requests);
    return requestsBatchStorageClient.post(requestBatch.toJson()).thenApply(interpreter::flatMap);
}
Also used : RequestBatch(org.folio.circulation.storage.RequestBatch) ResponseInterpreter(org.folio.circulation.support.http.client.ResponseInterpreter) Request(org.folio.circulation.domain.Request) Collection(java.util.Collection)

Example 15 with Request

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

the class RequestRepository method update.

public CompletableFuture<Result<Request>> update(Request request) {
    final JsonObject representation = new StoredRequestRepresentation().storedRequest(request);
    final ResponseInterpreter<Request> interpreter = new ResponseInterpreter<Request>().on(204, of(() -> request)).otherwise(forwardOnFailure());
    return requestsStorageClient.put(request.getId(), representation).thenApply(interpreter::flatMap);
}
Also used : StoredRequestRepresentation(org.folio.circulation.domain.StoredRequestRepresentation) ResponseInterpreter(org.folio.circulation.support.http.client.ResponseInterpreter) Request(org.folio.circulation.domain.Request) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

Request (org.folio.circulation.domain.Request)35 JsonObject (io.vertx.core.json.JsonObject)17 Loan (org.folio.circulation.domain.Loan)12 Result (org.folio.circulation.support.results.Result)11 Item (org.folio.circulation.domain.Item)10 ZonedDateTime (java.time.ZonedDateTime)9 List (java.util.List)9 Map (java.util.Map)9 ValidationError (org.folio.circulation.support.http.server.ValidationError)9 Result.succeeded (org.folio.circulation.support.results.Result.succeeded)9 HashMap (java.util.HashMap)8 UUID (java.util.UUID)8 CompletableFuture (java.util.concurrent.CompletableFuture)8 RequestAndRelatedRecords (org.folio.circulation.domain.RequestAndRelatedRecords)8 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)8 Clients (org.folio.circulation.support.Clients)8 Collection (java.util.Collection)7 Collectors (java.util.stream.Collectors)7 ItemRepository (org.folio.circulation.infrastructure.storage.inventory.ItemRepository)7 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)7