use of org.folio.circulation.support.Clients 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.Clients 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.Clients in project mod-circulation by folio-org.
the class CirculationRulesResource method put.
// Cannot combine exception catching as cannot resolve overloaded method for error
@SuppressWarnings("squid:S2147")
private void put(RoutingContext routingContext) {
final Clients clients = Clients.create(new WebContext(routingContext), client);
CollectionResourceClient loansRulesClient = clients.circulationRulesStorage();
if (loansRulesClient == null) {
internalError(routingContext.response(), "Cannot initialise client to storage interface");
return;
}
getPolicyIdsByType(clients).thenAccept(result -> proceedWithUpdate(result.value(), routingContext, clients));
}
use of org.folio.circulation.support.Clients in project mod-circulation by folio-org.
the class DeclareLostResource method declareLost.
private void declareLost(RoutingContext routingContext) {
final WebContext context = new WebContext(routingContext);
final Clients clients = Clients.create(context, client);
final EventPublisher eventPublisher = new EventPublisher(routingContext);
validateDeclaredLostRequest(routingContext).after(request -> declareItemLost(request, clients, context)).thenComposeAsync(r -> r.after(loan -> publishEvent(loan, eventPublisher))).thenApply(r -> r.map(toFixedValue(NoContentResponse::noContent))).thenAccept(context::writeResultToHttpResponse);
}
use of org.folio.circulation.support.Clients 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