use of org.folio.circulation.support.results.Result 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.support.results.Result 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.support.results.Result in project mod-circulation by folio-org.
the class CirculationRulesResource method proceedWithUpdate.
private void proceedWithUpdate(Map<String, Set<String>> existingPoliciesIds, RoutingContext routingContext, Clients clients) {
final WebContext webContext = new WebContext(routingContext);
JsonObject rulesInput;
try {
// try to convert, do not safe if conversion fails
rulesInput = routingContext.getBodyAsJson();
Text2Drools.convert(rulesInput.getString("rulesAsText"), (policyType, policies, token) -> validatePolicy(existingPoliciesIds, policyType, policies, token));
} catch (CirculationRulesException e) {
processingError(routingContext.response(), e);
return;
} catch (DecodeException e) {
decodingError(routingContext.response(), e);
return;
} catch (Exception e) {
internalError(routingContext.response(), getStackTrace(e));
return;
}
clients.circulationRulesStorage().put(rulesInput.copy()).thenApply(this::failWhenResponseOtherThanNoContent).thenApply(result -> result.map(response -> noContent())).thenAccept(webContext::writeResultToHttpResponse);
CirculationRulesCache.getInstance().clearCache(webContext.getTenantId());
}
use of org.folio.circulation.support.results.Result in project mod-circulation by folio-org.
the class CirculationRulesResource method getPolicyIdsByType.
private CompletableFuture<Result<Map<String, Set<String>>>> getPolicyIdsByType(Clients clients) {
CollectionResourceClient loanPolicyClient = clients.loanPoliciesStorage();
CollectionResourceClient noticePolicyClient = clients.patronNoticePolicesStorageClient();
CollectionResourceClient requestPolicyClient = clients.requestPoliciesStorage();
CollectionResourceClient overdueFinePolicyClient = clients.overdueFinesPoliciesStorage();
CollectionResourceClient lostItemFeePolicyClient = clients.lostItemPoliciesStorage();
Map<String, Set<String>> ids = new HashMap<>();
return Result.ofAsync(() -> ids).thenCombineAsync(getPolicyIdsByType(loanPolicyClient, "loanPolicies", "l"), (resultTotalIds, resultNewIds) -> resultTotalIds.combine(resultNewIds, this::getTotalMap)).thenCombineAsync(getPolicyIdsByType(noticePolicyClient, "patronNoticePolicies", "n"), (resultTotalIds, resultNewIds) -> resultTotalIds.combine(resultNewIds, this::getTotalMap)).thenCombineAsync(getPolicyIdsByType(requestPolicyClient, "requestPolicies", "r"), (resultTotalIds, resultNewIds) -> resultTotalIds.combine(resultNewIds, this::getTotalMap)).thenCombineAsync(getPolicyIdsByType(overdueFinePolicyClient, "overdueFinePolicies", "o"), (resultTotalIds, resultNewIds) -> resultTotalIds.combine(resultNewIds, this::getTotalMap)).thenCombineAsync(getPolicyIdsByType(lostItemFeePolicyClient, "lostItemFeePolicies", "i"), (resultTotalIds, resultNewIds) -> resultTotalIds.combine(resultNewIds, this::getTotalMap));
}
use of org.folio.circulation.support.results.Result in project mod-circulation by folio-org.
the class DeclareLostResource method declareItemLostWhenClaimedReturned.
private CompletableFuture<Result<Loan>> declareItemLostWhenClaimedReturned(Loan loan, DeclareItemLostRequest request, Clients clients) {
final NotesRepository notesRepository = NotesRepository.createUsing(clients);
final NoteCreator creator = new NoteCreator(notesRepository);
return ofAsync(() -> declareItemLost(loan, request)).thenCompose(r -> r.after(l -> creator.createGeneralUserNote(loan.getUserId(), "Claimed returned item marked declared lost"))).thenCompose(r -> r.after(note -> completedFuture(succeeded(loan))));
}
Aggregations