Search in sources :

Example 1 with OverridingErrorHandler

use of org.folio.circulation.resources.handlers.error.OverridingErrorHandler in project mod-circulation by folio-org.

the class RegularRenewalTest method cannotRenewWhenHoldRequestedAndFixedPolicyHasAlternativeRenewPeriod.

@Test
void cannotRenewWhenHoldRequestedAndFixedPolicyHasAlternativeRenewPeriod() {
    final var request = new RequestBuilder().hold().asDomainObject();
    final var loanPolicy = new LoanPolicyBuilder().fixed(UUID.randomUUID()).withHolds(null, true, days(1)).asDomainObject();
    CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
    renew(loanPolicy, request, errorHandler);
    assertTrue(matchErrorReason(errorHandler, ALTERNATIVE_RENEWAL_PERIOD_FOR_HOLDS_IS_SPECIFIED));
}
Also used : RequestBuilder(api.support.builders.RequestBuilder) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with OverridingErrorHandler

use of org.folio.circulation.resources.handlers.error.OverridingErrorHandler in project mod-circulation by folio-org.

the class RegularRenewalTest method cannotRenewWhenHoldRequestedAndFixedPolicyHasRenewPeriod.

@Test
void cannotRenewWhenHoldRequestedAndFixedPolicyHasRenewPeriod() {
    final var request = new RequestBuilder().hold().asDomainObject();
    final var loanPolicy = new LoanPolicyBuilder().fixed(UUID.randomUUID()).renewWith(days(10)).withHolds(null, true, null).asDomainObject();
    CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
    renew(loanPolicy, request, errorHandler);
    assertTrue(matchErrorReason(errorHandler, POLICY_HAS_FIXED_PROFILE_BUT_RENEWAL_PERIOD_IS_SPECIFIED));
}
Also used : RequestBuilder(api.support.builders.RequestBuilder) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with OverridingErrorHandler

use of org.folio.circulation.resources.handlers.error.OverridingErrorHandler in project mod-circulation by folio-org.

the class RegularRenewalTest method shouldNotAttemptToCalculateDueDateWhenPolicyIsNotRenewable.

@Test
void shouldNotAttemptToCalculateDueDateWhenPolicyIsNotRenewable() {
    final var loanPolicy = spy(new LoanPolicyBuilder().rolling(days(1)).notRenewable().asDomainObject());
    CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
    renew(loanPolicy, errorHandler);
    assertTrue(matchErrorReason(errorHandler, LOAN_IS_NOT_RENEWABLE));
}
Also used : CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with OverridingErrorHandler

use of org.folio.circulation.resources.handlers.error.OverridingErrorHandler in project mod-circulation by folio-org.

the class RegularRenewalTest method cannotRenewWhenHoldRequestIsNotRenewable.

@Test
void cannotRenewWhenHoldRequestIsNotRenewable() {
    final var request = new RequestBuilder().hold().asDomainObject();
    final var loanPolicy = new LoanPolicyBuilder().withHolds(null, false, null).asDomainObject();
    CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
    renew(loanPolicy, request, errorHandler);
    assertTrue(matchErrorReason(errorHandler, ITEMS_CANNOT_BE_RENEWED_ACTIVE_PENDING_HOLD_REQUEST));
}
Also used : RequestBuilder(api.support.builders.RequestBuilder) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with OverridingErrorHandler

use of org.folio.circulation.resources.handlers.error.OverridingErrorHandler in project mod-circulation by folio-org.

the class RequestCollectionResource method create.

@Override
void create(RoutingContext routingContext) {
    final var context = new WebContext(routingContext);
    final var clients = Clients.create(context, client);
    final var representation = routingContext.getBodyAsJson();
    final var eventPublisher = new EventPublisher(routingContext);
    final var itemRepository = new ItemRepository(clients);
    final var userRepository = new UserRepository(clients);
    final var loanRepository = new LoanRepository(clients, itemRepository, userRepository);
    final var requestRepository = RequestRepository.using(clients, itemRepository, userRepository, loanRepository);
    final var loanPolicyRepository = new LoanPolicyRepository(clients);
    final var requestNoticeSender = createRequestNoticeSender(clients, representation);
    final var configurationRepository = new ConfigurationRepository(clients);
    final var updateUponRequest = new UpdateUponRequest(new UpdateItem(itemRepository), new UpdateLoan(clients, loanRepository, loanPolicyRepository), UpdateRequestQueue.using(clients, requestRepository, new RequestQueueRepository(requestRepository)));
    final var okapiPermissions = OkapiPermissions.from(context.getHeaders());
    final var blockOverrides = BlockOverrides.fromRequest(representation);
    final var errorHandler = new OverridingErrorHandler(okapiPermissions);
    final var requestBlocksValidators = new RequestBlockValidators(blockOverrides, okapiPermissions, clients);
    final var requestLoanValidator = new RequestLoanValidator(new ItemByInstanceIdFinder(clients.holdingsStorage(), itemRepository), loanRepository);
    final var createRequestService = new CreateRequestService(new CreateRequestRepositories(requestRepository, new RequestPolicyRepository(clients), configurationRepository), updateUponRequest, requestLoanValidator, requestNoticeSender, requestBlocksValidators, eventPublisher, errorHandler);
    final var requestFromRepresentationService = new RequestFromRepresentationService(new InstanceRepository(clients), itemRepository, new RequestQueueRepository(requestRepository), userRepository, loanRepository, new ServicePointRepository(clients), configurationRepository, createProxyRelationshipValidator(representation, clients), new ServicePointPickupLocationValidator(), errorHandler, new ItemByInstanceIdFinder(clients.holdingsStorage(), itemRepository));
    final var scheduledNoticeService = RequestScheduledNoticeService.using(clients);
    fromFutureResult(requestFromRepresentationService.getRequestFrom(Request.Operation.CREATE, representation)).flatMapFuture(createRequestService::createRequest).onSuccess(scheduledNoticeService::scheduleRequestNotices).onSuccess(records -> eventPublisher.publishDueDateChangedEvent(records, loanRepository)).map(RequestAndRelatedRecords::getRequest).map(new RequestRepresentation()::extendedRepresentation).map(JsonHttpResponse::created).onComplete(context::write, context::write);
}
Also used : WebContext(org.folio.circulation.support.http.server.WebContext) CreateRequestRepositories(org.folio.circulation.domain.CreateRequestRepositories) ItemByInstanceIdFinder(org.folio.circulation.storage.ItemByInstanceIdFinder) ServicePointRepository(org.folio.circulation.infrastructure.storage.ServicePointRepository) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) UpdateLoan(org.folio.circulation.domain.UpdateLoan) CreateRequestService(org.folio.circulation.domain.CreateRequestService) LoanPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LoanPolicyRepository) ServicePointPickupLocationValidator(org.folio.circulation.domain.validation.ServicePointPickupLocationValidator) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) EventPublisher(org.folio.circulation.services.EventPublisher) RequestRepresentation(org.folio.circulation.domain.RequestRepresentation) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) RequestPolicyRepository(org.folio.circulation.infrastructure.storage.requests.RequestPolicyRepository) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) RequestLoanValidator(org.folio.circulation.domain.validation.RequestLoanValidator) UpdateItem(org.folio.circulation.domain.UpdateItem) RequestBlockValidators.regularRequestBlockValidators(org.folio.circulation.resources.RequestBlockValidators.regularRequestBlockValidators) InstanceRepository(org.folio.circulation.infrastructure.storage.inventory.InstanceRepository) UpdateUponRequest(org.folio.circulation.domain.UpdateUponRequest) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository)

Aggregations

OverridingErrorHandler (org.folio.circulation.resources.handlers.error.OverridingErrorHandler)52 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)49 Test (org.junit.jupiter.api.Test)42 CirculationErrorHandler (org.folio.circulation.resources.handlers.error.CirculationErrorHandler)40 ZonedDateTime (java.time.ZonedDateTime)37 Loan (org.folio.circulation.domain.Loan)37 RequestQueue (org.folio.circulation.domain.RequestQueue)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)31 FixedDueDateSchedulesBuilder (api.support.builders.FixedDueDateSchedulesBuilder)21 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)17 LoanBuilder (api.support.builders.LoanBuilder)13 JsonObject (io.vertx.core.json.JsonObject)9 ValueSource (org.junit.jupiter.params.provider.ValueSource)7 RequestBuilder (api.support.builders.RequestBuilder)5 FixedDueDateSchedule (api.support.builders.FixedDueDateSchedule)4 Result (org.folio.circulation.support.results.Result)4 FailureMatcher.hasValidationFailure (api.support.matchers.FailureMatcher.hasValidationFailure)2 HttpClient (io.vertx.core.http.HttpClient)2 Router (io.vertx.ext.web.Router)2 RoutingContext (io.vertx.ext.web.RoutingContext)2