Search in sources :

Example 1 with Physical

use of org.folio.rest.acq.model.Physical 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;
}
Also used : Tags(org.folio.rest.acq.model.Tags) Date(java.util.Date) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Contributor(org.folio.rest.acq.model.Contributor) StringUtils(org.apache.commons.lang3.StringUtils) Ongoing(org.folio.rest.acq.model.Ongoing) Location(org.folio.rest.acq.model.Location) Document(org.w3c.dom.Document) Map(java.util.Map) Claim(org.folio.rest.acq.model.Claim) ReferenceNumberItem(org.folio.rest.acq.model.ReferenceNumberItem) JsonObject(io.vertx.core.json.JsonObject) ZoneOffset(java.time.ZoneOffset) BigDecimal(scala.math.BigDecimal) ReportingCode(org.folio.rest.acq.model.ReportingCode) ProductIdentifier(org.folio.rest.acq.model.ProductIdentifier) Details(org.folio.rest.acq.model.Details) AcquisitionMethod(org.folio.rest.acq.model.AcquisitionMethod) Eresource(org.folio.rest.acq.model.Eresource) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) Organization(org.folio.rest.acq.model.Organization) Optional(java.util.Optional) HelperUtils.extractFundCode(org.folio.gobi.HelperUtils.extractFundCode) VendorDetail(org.folio.rest.acq.model.VendorDetail) LocalDateTime(java.time.LocalDateTime) CompletableFuture(java.util.concurrent.CompletableFuture) CompositePurchaseOrder(org.folio.rest.acq.model.CompositePurchaseOrder) CompositePoLine(org.folio.rest.acq.model.CompositePoLine) ArrayList(java.util.ArrayList) Alert(org.folio.rest.acq.model.Alert) HelperUtils.extractExpenseClassFromFundCode(org.folio.gobi.HelperUtils.extractExpenseClassFromFundCode) License(org.folio.rest.acq.model.License) PostGobiOrdersHelper(org.folio.rest.impl.PostGobiOrdersHelper) NodeList(org.w3c.dom.NodeList) INVALID_ISBN_PRODUCT_ID_TYPE(org.folio.gobi.HelperUtils.INVALID_ISBN_PRODUCT_ID_TYPE) DateTime(org.joda.time.DateTime) DiscountType(org.folio.rest.acq.model.Cost.DiscountType) Consumer(java.util.function.Consumer) IsbnUtil(org.folio.isbn.IsbnUtil) FundDistribution(org.folio.rest.acq.model.FundDistribution) Mapping(org.folio.rest.mappings.model.Mapping) Physical(org.folio.rest.acq.model.Physical) FUND_CODE_EXPENSE_CLASS_SEPARATOR(org.folio.gobi.HelperUtils.FUND_CODE_EXPENSE_CLASS_SEPARATOR) Cost(org.folio.rest.acq.model.Cost) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) AcquisitionMethod(org.folio.rest.acq.model.AcquisitionMethod) License(org.folio.rest.acq.model.License) ArrayList(java.util.ArrayList) Contributor(org.folio.rest.acq.model.Contributor) CompositePoLine(org.folio.rest.acq.model.CompositePoLine) CompositePurchaseOrder(org.folio.rest.acq.model.CompositePurchaseOrder) Cost(org.folio.rest.acq.model.Cost) Eresource(org.folio.rest.acq.model.Eresource) FundDistribution(org.folio.rest.acq.model.FundDistribution) VendorDetail(org.folio.rest.acq.model.VendorDetail) Physical(org.folio.rest.acq.model.Physical) CompletableFuture(java.util.concurrent.CompletableFuture) Details(org.folio.rest.acq.model.Details) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) Claim(org.folio.rest.acq.model.Claim) ReportingCode(org.folio.rest.acq.model.ReportingCode) Tags(org.folio.rest.acq.model.Tags) Location(org.folio.rest.acq.model.Location)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)1 LocalDateTime (java.time.LocalDateTime)1 ZoneOffset (java.time.ZoneOffset)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 StringUtils (org.apache.commons.lang3.StringUtils)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 FUND_CODE_EXPENSE_CLASS_SEPARATOR (org.folio.gobi.HelperUtils.FUND_CODE_EXPENSE_CLASS_SEPARATOR)1 INVALID_ISBN_PRODUCT_ID_TYPE (org.folio.gobi.HelperUtils.INVALID_ISBN_PRODUCT_ID_TYPE)1 HelperUtils.extractExpenseClassFromFundCode (org.folio.gobi.HelperUtils.extractExpenseClassFromFundCode)1