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;
}
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;
}
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());
}
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;
}
Aggregations