use of org.folio.circulation.domain.Request in project mod-circulation by folio-org.
the class RequestByInstanceIdResource method validateRequester.
private Result<Collection<Item>> validateRequester(Map<Item, RequestQueue> itemRequestQueueMap, InstanceRequestRelatedRecords requestPackage) {
if (!itemRequestQueueMap.isEmpty()) {
Collection<RequestQueue> requestQueues = itemRequestQueueMap.values();
String requesterId = requestPackage.getInstanceLevelRequest().getRequesterId().toString();
for (RequestQueue queue : requestQueues) {
final Optional<Request> matchingRequest = queue.getRequests().stream().filter(request -> request.isOpen() && Objects.equals(request.getUserId(), requesterId)).findFirst();
if (matchingRequest.isPresent()) {
Map<String, String> parameters = new HashMap<>();
parameters.put(REQUESTER_ID, requesterId);
parameters.put(ITEM_ID, matchingRequest.get().getItemId());
parameters.put("instanceId", requestPackage.getInstanceLevelRequest().getInstanceId().toString());
String message = "This requester already has an open request for an item of this instance";
return failedValidation(new ValidationError(message, parameters));
}
}
}
return of(itemRequestQueueMap::keySet);
}
use of org.folio.circulation.domain.Request 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.Request in project mod-circulation by folio-org.
the class RequestFromRepresentationService method validateRequestLevel.
private Result<Request> validateRequestLevel(Request request) {
JsonObject representation = request.getRequestRepresentation();
String requestLevelRaw = representation.getString(REQUEST_LEVEL);
RequestLevel requestLevel = RequestLevel.from(requestLevelRaw);
boolean tlrEnabled = request.getTlrSettingsConfiguration().isTitleLevelRequestsFeatureEnabled();
List<RequestLevel> allowedStatuses = tlrEnabled ? List.of(ITEM, TITLE) : List.of(ITEM);
if (!allowedStatuses.contains(requestLevel)) {
String allowedStatusesJoined = allowedStatuses.stream().map(existingLevel -> StringUtils.wrap(existingLevel.getValue(), '"')).collect(Collectors.joining(", "));
return failedValidation("requestLevel must be one of the following: " + allowedStatusesJoined, "requestLevel", requestLevelRaw);
}
return succeeded(request);
}
use of org.folio.circulation.domain.Request in project mod-circulation by folio-org.
the class ItemLevelRequestNoticeSender method sendNoticeOnRequestCreated.
@Override
public Result<RequestAndRelatedRecords> sendNoticeOnRequestCreated(RequestAndRelatedRecords relatedRecords) {
Request request = relatedRecords.getRequest();
Item item = request.getItem();
NoticeEventType eventType = requestTypeToEventMap.getOrDefault(request.getRequestType(), NoticeEventType.UNKNOWN);
PatronNoticeEvent requestCreatedEvent = createPatronNoticeEvent(request, eventType).withItem(item);
patronNoticeService.acceptNoticeEvent(requestCreatedEvent);
Loan loan = request.getLoan();
if (request.getRequestType() == RequestType.RECALL && loan != null) {
sendNoticeOnItemRecalledEvent(loan);
sendLogEvent(loan);
}
return Result.succeeded(relatedRecords);
}
use of org.folio.circulation.domain.Request in project mod-circulation by folio-org.
the class TitleLevelRequestNoticeSender method sendNoticeOnRequestCreated.
@Override
public Result<RequestAndRelatedRecords> sendNoticeOnRequestCreated(RequestAndRelatedRecords relatedRecords) {
Request request = relatedRecords.getRequest();
TlrSettingsConfiguration tlrSettings = request.getTlrSettingsConfiguration();
NoticeEventType eventType = requestTypeToEventMap.getOrDefault(request.getRequestType(), NoticeEventType.UNKNOWN);
if (tlrSettings.isTitleLevelRequestsFeatureEnabled() && tlrSettings.getConfirmationPatronNoticeTemplateId() != null) {
PatronNoticeEvent requestCreatedEvent = createPatronNoticeEvent(request, eventType);
applyTlrConfirmationNotice(request.getTlrSettingsConfiguration(), requestCreatedEvent);
}
return Result.succeeded(relatedRecords);
}
Aggregations