use of org.folio.rest.acq.model.Details 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;
}
use of org.folio.rest.acq.model.Details in project mod-gobi by folio-org.
the class Mapper method mapDetail.
private void mapDetail(List<CompletableFuture<?>> futures, Details detail, Document doc, PostGobiOrdersHelper postGobiOrdersHelper) {
// Adding a new entry to product id only if the product ID and product id
// type are present
// as both of them are together are mandatory to create an inventory
// instance
Optional.ofNullable(mappings.get(Mapping.Field.PRODUCT_ID)).ifPresent(field -> futures.add(field.resolve(doc).thenCompose(o -> {
ProductIdentifier productId = new ProductIdentifier();
productId.setProductId(o.toString());
return Optional.ofNullable(mappings.get(Mapping.Field.PRODUCT_ID_TYPE)).map(prodIdType -> resolveProductIdType(prodIdType, doc, productId, postGobiOrdersHelper).thenAccept(typeId -> {
productId.setProductIdType((String) typeId);
Optional.ofNullable(mappings.get(Mapping.Field.PRODUCT_QUALIFIER)).ifPresent(qualifierField -> qualifierField.resolve(doc).thenAccept(qualifier -> productId.setQualifier((String) qualifier)));
detail.setProductIds(Collections.singletonList(productId));
}).exceptionally(Mapper::logException)).orElse(completedFuture(null));
}).exceptionally(Mapper::logException)));
Optional.ofNullable(mappings.get(Mapping.Field.RECEIVING_NOTE)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> detail.setReceivingNote((String) o)).exceptionally(Mapper::logException)));
Optional.ofNullable(mappings.get(Mapping.Field.SUBSCRIPTION_FROM)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> detail.setSubscriptionFrom((Date) o)).exceptionally(Mapper::logException)));
Optional.ofNullable(mappings.get(Mapping.Field.SUBSCRIPTION_INTERVAL)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> detail.setSubscriptionInterval((Integer) o)).exceptionally(Mapper::logException)));
Optional.ofNullable(mappings.get(Mapping.Field.SUBSCRIPTION_TO)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> detail.setSubscriptionTo((Date) o)).exceptionally(Mapper::logException)));
}
Aggregations