use of org.folio.rest.acq.model.Location in project mod-gobi by folio-org.
the class Mapper method mapCompositePOLine.
private CompletableFuture<CompositePurchaseOrder> mapCompositePOLine(Document doc, CompositePurchaseOrder compPO, PostGobiOrdersHelper postGobiOrdersHelper) {
CompletableFuture<CompositePurchaseOrder> future = new CompletableFuture<>();
Details detail = new Details();
Cost cost = new Cost();
Location location = new Location();
Eresource eresource = new Eresource();
FundDistribution fundDistribution = new FundDistribution();
VendorDetail vendorDetail = new VendorDetail();
Claim claim = new Claim();
Physical physical = new Physical();
Contributor contributor = new Contributor();
ReportingCode reportingCode = new ReportingCode();
License license = new License();
Tags tags = new Tags();
AcquisitionMethod acquisitionMethod = new AcquisitionMethod();
List<CompletableFuture<?>> futures = new ArrayList<>();
mapCost(futures, cost, doc);
mapDetail(futures, detail, doc, postGobiOrdersHelper);
mapFundDistribution(futures, fundDistribution, doc, postGobiOrdersHelper);
mapLocation(futures, location, doc);
mapVendorDetail(futures, vendorDetail, doc);
mapClaims(futures, claim, doc);
mapContributor(futures, contributor, doc);
mapReportingCodes(futures, reportingCode, doc);
mapVendorDependentFields(futures, eresource, physical, compPO, claim, doc);
mapLicense(futures, license, doc);
mapTags(futures, tags, doc);
mapAcquisitionMethod(futures, acquisitionMethod, doc, postGobiOrdersHelper);
CompositePoLine pol = compPO.getCompositePoLines().get(0);
if (pol.getOrderFormat().equals(CompositePoLine.OrderFormat.ELECTRONIC_RESOURCE)) {
mapEresource(futures, eresource, doc);
} else {
mapPhysical(futures, physical, doc);
}
CompletableFuture.allOf(futures.toArray(new CompletableFuture<?>[0])).thenAccept(v -> {
compPO.setTotalItems(location.getQuantity());
setObjectIfPresent(detail, o -> pol.setDetails((Details) o));
setObjectIfPresent(cost, o -> pol.setCost((Cost) o));
setObjectIfPresent(license, o -> eresource.setLicense((License) o));
if (pol.getOrderFormat().equals(CompositePoLine.OrderFormat.ELECTRONIC_RESOURCE)) {
setObjectIfPresent(eresource, o -> pol.setEresource((Eresource) o));
} else {
setObjectIfPresent(physical, o -> pol.setPhysical((Physical) o));
}
setObjectIfPresent(vendorDetail, o -> pol.setVendorDetail((VendorDetail) o));
setObjectIfPresent(location, o -> {
List<Location> locations = new ArrayList<>();
locations.add(location);
pol.setLocations(locations);
});
setObjectIfPresent(contributor, o -> {
List<Contributor> contributors = new ArrayList<>();
contributors.add(contributor);
pol.setContributors(contributors);
});
setObjectIfPresent(reportingCode, o -> {
List<ReportingCode> reportingCodes = new ArrayList<>();
reportingCodes.add(reportingCode);
pol.setReportingCodes(reportingCodes);
});
setObjectIfPresent(claim, o -> {
List<Claim> claims = new ArrayList<>();
claims.add(claim);
pol.setClaims(claims);
});
setObjectIfPresent(fundDistribution, o -> {
if (StringUtils.isNotEmpty(fundDistribution.getFundId())) {
pol.setFundDistribution(Collections.singletonList(fundDistribution));
}
});
setObjectIfPresent(tags, o -> pol.setTags(tags));
setObjectIfPresent(acquisitionMethod, o -> pol.setAcquisitionMethod(acquisitionMethod.getId()));
future.complete(compPO);
}).exceptionally(t -> {
logger.error("Exception creating Composite PO", t);
future.completeExceptionally(t);
return null;
});
return future;
}
Aggregations