use of org.folio.circulation.domain.RequestRepresentation 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);
}
use of org.folio.circulation.domain.RequestRepresentation in project mod-circulation by folio-org.
the class RequestCollectionResource method move.
void move(RoutingContext routingContext) {
final var context = new WebContext(routingContext);
final var clients = Clients.create(context, client);
final var representation = routingContext.getBodyAsJson();
final var id = getRequestId(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 requestQueueRepository = new RequestQueueRepository(requestRepository);
final var loanPolicyRepository = new LoanPolicyRepository(clients);
final var configurationRepository = new ConfigurationRepository(clients);
final var updateUponRequest = new UpdateUponRequest(new UpdateItem(itemRepository), new UpdateLoan(clients, loanRepository, loanPolicyRepository), UpdateRequestQueue.using(clients, requestRepository, requestQueueRepository));
final var moveRequestProcessAdapter = new MoveRequestProcessAdapter(itemRepository, loanRepository, requestRepository);
final var eventPublisher = new EventPublisher(routingContext);
final var moveRequestService = new MoveRequestService(requestRepository, new RequestPolicyRepository(clients), updateUponRequest, moveRequestProcessAdapter, new RequestLoanValidator(new ItemByInstanceIdFinder(clients.holdingsStorage(), itemRepository), loanRepository), RequestNoticeSender.using(clients), configurationRepository, eventPublisher, requestQueueRepository);
fromFutureResult(requestRepository.getById(id)).map(RequestAndRelatedRecords::new).map(request -> asMove(request, representation)).flatMapFuture(move -> moveRequestService.moveRequest(move, move.getOriginalRequest())).onSuccess(records -> eventPublisher.publishDueDateChangedEvent(records, loanRepository)).map(RequestAndRelatedRecords::getRequest).map(new RequestRepresentation()::extendedRepresentation).map(JsonHttpResponse::ok).onComplete(context::write, context::write);
}
use of org.folio.circulation.domain.RequestRepresentation in project mod-circulation by folio-org.
the class RequestQueueResource method getQueue.
private void getQueue(RoutingContext routingContext, RequestQueueType requestQueueType) {
final var context = new WebContext(routingContext);
final var clients = Clients.create(context, client);
final var itemRepository = new ItemRepository(clients);
final var userRepository = new UserRepository(clients);
final var loanRepository = new LoanRepository(clients, itemRepository, userRepository);
final var requestQueueRepository = new RequestQueueRepository(RequestRepository.using(clients, itemRepository, userRepository, loanRepository));
final RequestRepresentation requestRepresentation = new RequestRepresentation();
CompletableFuture<Result<RequestQueue>> requestQueue = getRequestQueueByType(routingContext, requestQueueType, requestQueueRepository);
requestQueue.thenApply(r -> r.map(queue -> new MultipleRecords<>(queue.getRequests(), queue.size()))).thenApply(r -> r.map(requests -> requests.asJson(requestRepresentation::extendedRepresentation, "requests"))).thenApply(r -> r.map(JsonHttpResponse::ok)).thenAccept(context::writeResultToHttpResponse);
}
use of org.folio.circulation.domain.RequestRepresentation in project mod-circulation by folio-org.
the class RequestByInstanceIdResource method createInstanceLevelRequests.
private void createInstanceLevelRequests(RoutingContext routingContext) {
final WebContext context = new WebContext(routingContext);
final Clients clients = Clients.create(context, client);
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 requestQueueRepository = new RequestQueueRepository(requestRepository);
final var itemFinder = new ItemByInstanceIdFinder(clients.holdingsStorage(), itemRepository);
final var eventPublisher = new EventPublisher(routingContext);
final var requestBody = routingContext.getBodyAsJson();
new ConfigurationRepository(clients).lookupTlrSettings().thenCompose(r -> r.after(config -> buildAndPlaceRequests(clients, eventPublisher, itemRepository, loanRepository, requestRepository, requestQueueRepository, userRepository, itemFinder, config, requestBody))).thenApply(r -> r.map(RequestAndRelatedRecords::getRequest)).thenApply(r -> r.map(new RequestRepresentation()::extendedRepresentation)).thenApply(r -> r.map(JsonHttpResponse::created)).thenAccept(context::writeResultToHttpResponse).exceptionally(err -> {
String reason = "Error processing instance-level request";
log.error(reason, err);
ServerErrorResponse.internalError(routingContext.response(), reason);
return null;
});
}
Aggregations