use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.
the class LogCheckInServiceTest method checkInProcessRecords.
private CheckInContext checkInProcessRecords() {
JsonObject requestRepresentation = new JsonObject().put("servicePointId", UUID.randomUUID().toString()).put("itemBarcode", "barcode").put("checkInDate", ClockUtil.getZonedDateTime().toString());
JsonObject itemRepresentation = new JsonObject().put("id", UUID.randomUUID().toString()).put("status", new JsonObject().put("name", "Available"));
return new CheckInContext(CheckInByBarcodeRequest.from(requestRepresentation).value()).withItem(Item.from(itemRepresentation)).withRequestQueue(new RequestQueue(Collections.emptyList())).withLoggedInUserId(UUID.randomUUID().toString());
}
use of org.folio.circulation.domain.RequestQueue 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.RequestQueue 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.RequestQueue in project mod-circulation by folio-org.
the class RenewalResource method unsetDueDateChangedByRecallIfNoOpenRecallsInQueue.
private RenewalContext unsetDueDateChangedByRecallIfNoOpenRecallsInQueue(RenewalContext renewalContext) {
Loan loan = renewalContext.getLoan();
RequestQueue queue = renewalContext.getRequestQueue();
if (loan.wasDueDateChangedByRecall() && !queue.hasOpenRecalls()) {
return renewalContext.withLoan(loan.unsetDueDateChangedByRecall());
} else {
return renewalContext;
}
}
use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.
the class RenewalResource method renew.
private Result<RenewalContext> renew(RenewalContext context, ZonedDateTime renewDate) {
final var loan = context.getLoan();
final var requestQueue = context.getRequestQueue();
final var loanPolicy = loan.getLoanPolicy();
final Result<ZonedDateTime> proposedDueDateResult = calculateNewDueDate(loan, requestQueue, renewDate);
final List<ValidationError> errors = new ArrayList<>();
addErrorsIfDueDateResultFailed(loan, errors, proposedDueDateResult);
if (errors.isEmpty()) {
final BlockOverrides blockOverrides = BlockOverrides.from(getObjectProperty(context.getRenewalRequest(), "overrideBlocks"));
if (!blockOverrides.getPatronBlockOverride().isRequested() && !blockOverrides.getRenewalBlockOverride().isRequested()) {
return proposedDueDateResult.map(dueDate -> loan.renew(dueDate, loanPolicy.getId())).map(l -> context);
}
return proposedDueDateResult.map(dueDate -> loan.overrideRenewal(dueDate, loanPolicy.getId(), blockOverrides.getComment())).map(l -> context);
}
return failedValidation(errors);
}
Aggregations