use of org.folio.orders.utils.ResourcePathResolver.ALERTS in project mod-orders by folio-org.
the class PurchaseOrderLineHelper method createAlerts.
private CompletableFuture<Void> createAlerts(CompositePoLine compPOL, JsonObject line, RequestContext requestContext) {
List<CompletableFuture<String>> futures = new ArrayList<>();
List<Alert> alerts = compPOL.getAlerts();
if (null != alerts) {
RequestEntry rqEntry = new RequestEntry(resourcesPath(ALERTS));
alerts.forEach(alertObject -> {
futures.add(restClient.post(rqEntry, alertObject, requestContext, Alert.class).thenApply(Alert::getId));
});
}
return collectResultsOnSuccess(futures).thenAccept(ids -> line.put(ALERTS, ids)).exceptionally(t -> {
logger.error("failed to create Alerts", t);
throw new CompletionException(t.getCause());
});
}
use of org.folio.orders.utils.ResourcePathResolver.ALERTS in project mod-orders by folio-org.
the class HelperUtils method operateOnPoLine.
public static CompletableFuture<CompositePoLine> operateOnPoLine(HttpMethod operation, JsonObject line, Map<String, String> okapiHeaders, Logger logger) {
CompletableFuture<CompositePoLine> future = new CompletableFuture<>();
if (logger.isDebugEnabled()) {
logger.debug("The PO line prior to {} operation: {}", operation, line.encodePrettily());
}
List<CompletableFuture<Void>> futures = new ArrayList<>();
HttpClientInterface httpClient = AbstractHelper.getHttpClient(okapiHeaders, true);
futures.addAll(operateOnSubObjsIfPresent(operation, line, ALERTS, httpClient, okapiHeaders, logger));
futures.addAll(operateOnSubObjsIfPresent(operation, line, REPORTING_CODES, httpClient, okapiHeaders, logger));
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).thenAccept(v -> {
if (logger.isDebugEnabled()) {
logger.debug("The PO line after {} operation on sub-objects: {}", operation, line.encodePrettily());
}
httpClient.closeClient();
future.complete(line.mapTo(CompositePoLine.class));
}).exceptionally(t -> {
httpClient.closeClient();
logger.error("Exception resolving one or more poLine sub-object(s) on {} operation", operation, t);
future.completeExceptionally(t);
return null;
});
return future;
}
Aggregations