Search in sources :

Example 1 with CompositePoLine

use of org.folio.rest.acq.model.CompositePoLine in project mod-gobi by folio-org.

the class Mapper method mapPurchaseOrderLine.

private void mapPurchaseOrderLine(List<CompletableFuture<?>> futures, CompositePoLine pol, Document doc) {
    Optional.ofNullable(mappings.get(Mapping.Field.ALERTS)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> {
        Alert alert = new Alert();
        alert.setAlert((String) o);
        List<Alert> alerts = new ArrayList<>();
        alerts.add(alert);
        pol.setAlerts(alerts);
    }).exceptionally(Mapper::logException)));
    Optional.ofNullable(mappings.get(Mapping.Field.CANCELLATION_RESTRICTION)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> pol.setCancellationRestriction((Boolean) o)).exceptionally(Mapper::logException)));
    Optional.ofNullable(mappings.get(Mapping.Field.PO_LINE_ORDER_FORMAT)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> pol.setOrderFormat(CompositePoLine.OrderFormat.fromValue((String) o))).exceptionally(Mapper::logException)));
    Optional.ofNullable(mappings.get(Mapping.Field.COLLECTION)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> pol.setCollection((Boolean) o)).exceptionally(Mapper::logException)));
    Optional.ofNullable(mappings.get(Mapping.Field.PO_LINE_DESCRIPTION)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> pol.setPoLineDescription((String) o)).exceptionally(Mapper::logException)));
    Optional.ofNullable(mappings.get(Mapping.Field.PO_LINE_PAYMENT_STATUS)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> pol.setPaymentStatus(CompositePoLine.PaymentStatus.fromValue((String) o))).exceptionally(Mapper::logException)));
    Optional.ofNullable(mappings.get(Mapping.Field.PUBLICATION_DATE)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> pol.setPublicationDate((String) o)).exceptionally(Mapper::logException)));
    Optional.ofNullable(mappings.get(Mapping.Field.PUBLISHER)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> pol.setPublisher((String) o)).exceptionally(Mapper::logException)));
    Optional.ofNullable(mappings.get(Mapping.Field.PURCHASE_ORDER_ID)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> pol.setPurchaseOrderId((String) o)).exceptionally(Mapper::logException)));
    Optional.ofNullable(mappings.get(Mapping.Field.RECEIPT_DATE)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> pol.setReceiptDate((Date) o)).exceptionally(Mapper::logException)));
    Optional.ofNullable(mappings.get(Mapping.Field.RUSH)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> pol.setRush((Boolean) o)).exceptionally(Mapper::logException)));
    Optional.ofNullable(mappings.get(Mapping.Field.TAGS)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> {
        Tags tags = new Tags();
        List<String> tagList = new ArrayList<>();
        tagList.add((String) o);
        tags.setTagList(tagList);
        pol.setTags(tags);
    }).exceptionally(Mapper::logException)));
    Optional.ofNullable(mappings.get(Mapping.Field.PO_LINE_RECEIPT_STATUS)).ifPresent(field -> futures.add(field.resolve(doc).thenAccept(o -> pol.setReceiptStatus(CompositePoLine.ReceiptStatus.fromValue((String) o))).exceptionally(Mapper::logException)));
}
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) Alert(org.folio.rest.acq.model.Alert) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) Tags(org.folio.rest.acq.model.Tags)

Example 2 with CompositePoLine

use of org.folio.rest.acq.model.CompositePoLine in project mod-gobi by folio-org.

the class Mapper method map.

public CompletableFuture<CompositePurchaseOrder> map(Document doc, PostGobiOrdersHelper postGobiOrdersHelper) {
    CompletableFuture<CompositePurchaseOrder> future = new CompletableFuture<>();
    CompositePoLine pol = new CompositePoLine();
    CompositePurchaseOrder compPO = new CompositePurchaseOrder();
    List<CompletableFuture<?>> purchaseOrderFutures = new ArrayList<>();
    mapPurchaseOrder(purchaseOrderFutures, compPO, doc);
    mapPurchaseOrderLine(purchaseOrderFutures, pol, doc);
    mapPurchaseOrderLineStrings(purchaseOrderFutures, pol, doc);
    CompletableFuture.allOf(purchaseOrderFutures.toArray(new CompletableFuture<?>[0])).thenApply(v -> compPO.getCompositePoLines().add(pol)).thenCompose(v -> mapCompositePOLine(doc, compPO, postGobiOrdersHelper)).thenAccept(future::complete).exceptionally(t -> {
        logger.error("Exception Mapping Composite PO Line fields", 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) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) CompositePoLine(org.folio.rest.acq.model.CompositePoLine) CompositePurchaseOrder(org.folio.rest.acq.model.CompositePurchaseOrder)

Example 3 with CompositePoLine

use of org.folio.rest.acq.model.CompositePoLine 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)

Example 4 with CompositePoLine

use of org.folio.rest.acq.model.CompositePoLine in project mod-gobi by folio-org.

the class GOBIIntegrationServiceResourceImplTest method verifyRequiredFieldsAreMapped.

/**
 * Make sure all the required fields for creating an order are mapped
 * @param compPO CompositePurchaseOrder object to be verified
 */
private void verifyRequiredFieldsAreMapped(CompositePurchaseOrder compPO) {
    assertNotNull(compPO.getVendor());
    assertNotNull(compPO.getOrderType());
    CompositePoLine poLine = compPO.getCompositePoLines().get(0);
    assertNotNull(poLine.getAcquisitionMethod());
    assertNotNull(poLine.getCost());
    assertNotNull(poLine.getOrderFormat());
    assertNotNull(poLine.getSource());
    assertNotNull(poLine.getTitleOrPackage());
    if (!poLine.getContributors().isEmpty()) {
        poLine.getContributors().forEach(contributor -> {
            assertNotNull(contributor.getContributor());
            assertNotNull(contributor.getContributorNameTypeId());
        });
    }
}
Also used : CompositePoLine(org.folio.rest.acq.model.CompositePoLine)

Aggregations

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