use of org.folio.orders.utils.ResourcePathResolver.REPORTING_CODES in project mod-orders by folio-org.
the class PurchaseOrderLineHelper method createReportingCodes.
private CompletableFuture<Void> createReportingCodes(CompositePoLine compPOL, JsonObject line, RequestContext requestContext) {
List<CompletableFuture<String>> futures = new ArrayList<>();
List<ReportingCode> reportingCodes = compPOL.getReportingCodes();
if (null != reportingCodes) {
RequestEntry rqEntry = new RequestEntry(resourcesPath(REPORTING_CODES));
reportingCodes.forEach(reportingObject -> {
futures.add(restClient.post(rqEntry, reportingObject, requestContext, ReportingCode.class).thenApply(ReportingCode::getId));
});
}
return collectResultsOnSuccess(futures).thenAccept(reportingIds -> line.put(REPORTING_CODES, reportingIds)).exceptionally(t -> {
logger.error("failed to create Reporting Codes", t);
throw new CompletionException(t.getCause());
});
}
use of org.folio.orders.utils.ResourcePathResolver.REPORTING_CODES 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