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));
}
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));
}
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));
}
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));
}
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);
}
Aggregations