Search in sources :

Example 1 with Mapping

use of org.folio.rest.mappings.model.Mapping 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 2 with Mapping

use of org.folio.rest.mappings.model.Mapping in project mod-gobi by folio-org.

the class MappingHelper method getDefaultMappingForOrderType.

public static Map<Mapping.Field, DataSourceResolver> getDefaultMappingForOrderType(PostGobiOrdersHelper postGobiOrdersHelper, OrderType orderType) {
    Map<Mapping.Field, org.folio.gobi.DataSourceResolver> fieldDataSourceMapping = new EnumMap<>(Mapping.Field.class);
    List<Mapping> mappingsList = defaultMappings.get(orderType).getMappings();
    for (Mapping mapping : mappingsList) {
        Mapping.Field field = mapping.getField();
        org.folio.gobi.DataSourceResolver dataSource = getDS(mapping, fieldDataSourceMapping, postGobiOrdersHelper);
        fieldDataSourceMapping.put(field, dataSource);
    }
    return fieldDataSourceMapping;
}
Also used : Field(org.folio.rest.mappings.model.Mapping.Field) Mapping(org.folio.rest.mappings.model.Mapping) EnumMap(java.util.EnumMap) Field(org.folio.rest.mappings.model.Mapping.Field)

Example 3 with Mapping

use of org.folio.rest.mappings.model.Mapping in project mod-gobi by folio-org.

the class MappingHelperTest method setUp.

@Before
public void setUp() {
    logger.info("Begin: SetUp by initializing a default mapping");
    JsonObject expectedListedPrintMonographJsonObj = new JsonObject();
    expectedListedPrintMonographJsonObj.put("orderType", "ListedPrintMonograph");
    JsonObject accessProvider = new JsonObject().put("field", ACCESS_PROVIDER.value()).put("dataSource", new JsonObject().put("from", "//PurchaseOption/VendorPOCode").put("translation", "lookupOrganization"));
    JsonObject expenseClass = new JsonObject().put("field", EXPENSE_CLASS.value()).put("dataSource", new JsonObject().put("from", "//LocalData[Description='LocalData5']/Value").put("translation", "lookupExpenseClassId"));
    ;
    expectedListedPrintMonographJsonObj.put("mappings", new JsonArray().add(accessProvider).add(expenseClass));
    JsonObject combinatorTitle = new JsonObject().put("field", TITLE.value()).put("dataSource", new JsonObject().put("from", "//datafield[@tag='245']/*").put("combinator", "concat"));
    ;
    expectedListedPrintMonographJsonObj.put("mappings", new JsonArray().add(accessProvider).add(expenseClass).add(combinatorTitle));
    String expectedListedPrintMonographJson = expectedListedPrintMonographJsonObj.toString();
    JsonObject expectedUnListedPrintMonographJsonObj = new JsonObject();
    expectedUnListedPrintMonographJsonObj.put("orderType", "UnlistedPrintMonograph");
    expectedUnListedPrintMonographJsonObj.put("mappings", new JsonArray().add(new JsonObject().put("field", "PRODUCT_ID").put("dataSource", new JsonObject().put("from", "//datafield[@tag='020']/subfield[@code='a']"))).add(new JsonObject().put("field", "CONTRIBUTOR").put("dataSource", new JsonObject().put("from", "//datafield[@tag='100']/*").put("combinator", "concat"))));
    String expectedUnListedPrintMonographJson = expectedUnListedPrintMonographJsonObj.toString();
    actualListedPrintJson = MappingHelper.readMappingsFile(LISTED_PRINT_PATH);
    assertEquals(expectedListedPrintMonographJson, actualListedPrintJson.replaceAll("\\s", ""));
    actuallistedPrintMappings = Json.decodeValue(actualListedPrintJson, OrderMappings.class);
    actualUnlistedPrintJson = MappingHelper.readMappingsFile(UNLISTED_PRINT_PATH);
    assertEquals(expectedUnListedPrintMonographJson, actualUnlistedPrintJson.replaceAll("\\s", ""));
    actualUnlistedPrintMappings = Json.decodeValue(actualUnlistedPrintJson, OrderMappings.class);
    OrderType orderType1 = actuallistedPrintMappings.getOrderType();
    OrderType orderType2 = actualUnlistedPrintMappings.getOrderType();
    assertEquals(EXPECTEDORDERTYPE1, orderType1.toString());
    assertEquals(EXPECTEDORDERTYPE2, orderType2.toString());
    List<Mapping> mappingsList1 = actuallistedPrintMappings.getMappings();
    List<Mapping> mappingsList2 = actualUnlistedPrintMappings.getMappings();
    mappingAccessProvider = mappingsList1.get(0);
    mappingExpenseClass = mappingsList1.get(1);
    mappingCombinatorNotExist = mappingsList1.get(2);
    mappingCombinatorNotExist.getDataSource().setCombinator(null);
    mapping2 = mappingsList2.get(0);
    assertEquals(3, mappingsList1.size());
    assertEquals(2, mappingsList2.size());
    assertEquals(Mapping.Field.ACCESS_PROVIDER.value(), mappingAccessProvider.getField().toString());
    assertEquals(EXPENSE_CLASS.value(), mappingExpenseClass.getField().toString());
    assertEquals("PRODUCT_ID", mapping2.getField().toString());
}
Also used : JsonArray(io.vertx.core.json.JsonArray) OrderType(org.folio.rest.mappings.model.OrderMappings.OrderType) OrderMappings(org.folio.rest.mappings.model.OrderMappings) JsonObject(io.vertx.core.json.JsonObject) Mapping(org.folio.rest.mappings.model.Mapping) Before(org.junit.Before)

Example 4 with Mapping

use of org.folio.rest.mappings.model.Mapping in project mod-gobi by folio-org.

the class MappingHelper method extractOrderMappings.

public static Map<Mapping.Field, DataSourceResolver> extractOrderMappings(OrderMappings.OrderType orderType, JsonObject jo, PostGobiOrdersHelper postGobiOrdersHelper) {
    final Map<Mapping.Field, DataSourceResolver> map = new EnumMap<>(Mapping.Field.class);
    final JsonArray configs = jo.getJsonArray("configs");
    if (!configs.isEmpty()) {
        final String mappingsString = configs.getJsonObject(0).getString("value");
        final OrderMappings orderMapping = Json.decodeValue(mappingsString, OrderMappings.class);
        final List<Mapping> orderMappingList = orderMapping.getMappings();
        if (orderMappingList != null) {
            for (Mapping mapping : orderMappingList) {
                logger.info("Mapping exists for type: {} , field: {}", orderType, mapping.getField());
                map.put(mapping.getField(), getDS(mapping, map, postGobiOrdersHelper));
            }
        }
    }
    return map;
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Field(org.folio.rest.mappings.model.Mapping.Field) OrderMappings(org.folio.rest.mappings.model.OrderMappings) Mapping(org.folio.rest.mappings.model.Mapping) EnumMap(java.util.EnumMap)

Aggregations

Mapping (org.folio.rest.mappings.model.Mapping)3 JsonArray (io.vertx.core.json.JsonArray)2 JsonObject (io.vertx.core.json.JsonObject)2 EnumMap (java.util.EnumMap)2 Field (org.folio.rest.mappings.model.Mapping.Field)2 OrderMappings (org.folio.rest.mappings.model.OrderMappings)2 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