Search in sources :

Example 1 with OrderMappings

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

Example 2 with OrderMappings

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

the class PostGobiOrdersHelper method mapToPurchaseOrder.

public CompletableFuture<CompositePurchaseOrder> mapToPurchaseOrder(Document doc) {
    final OrderMappings.OrderType orderType = getOrderType(doc);
    VertxCompletableFuture<CompositePurchaseOrder> future = new VertxCompletableFuture<>(ctx);
    lookupOrderMappings(orderType).thenAccept(ordermappings -> {
        logger.info("Using Mappings {}", ordermappings);
        new Mapper(ordermappings).map(doc, this).thenAccept(future::complete);
    }).exceptionally(e -> {
        logger.error("Exception looking up Order mappings", e);
        future.completeExceptionally(e);
        return null;
    });
    return future;
}
Also used : DataSourceResolver(org.folio.gobi.DataSourceResolver) Json(io.vertx.core.json.Json) GobiPurchaseOrderParser(org.folio.gobi.GobiPurchaseOrderParser) HelperUtils.extractFundCode(org.folio.gobi.HelperUtils.extractFundCode) XPath(javax.xml.xpath.XPath) XPathConstants(javax.xml.xpath.XPathConstants) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) GobiPurchaseOrderParserException(org.folio.gobi.exceptions.GobiPurchaseOrderParserException) VertxCompletableFuture(me.escoffier.vertx.completablefuture.VertxCompletableFuture) CompletableFuture(java.util.concurrent.CompletableFuture) StringUtils(org.apache.commons.lang3.StringUtils) CompositePurchaseOrder(org.folio.rest.acq.model.CompositePurchaseOrder) Context(io.vertx.core.Context) OrderMappingCache(org.folio.gobi.OrderMappingCache) PostGobiOrdersResponse.respond500WithTextPlain(org.folio.rest.jaxrs.resource.Gobi.PostGobiOrdersResponse.respond500WithTextPlain) ResponseError(org.folio.rest.gobi.model.ResponseError) HttpException(org.folio.gobi.exceptions.HttpException) Collectors.toMap(java.util.stream.Collectors.toMap) HelperUtils(org.folio.gobi.HelperUtils) Document(org.w3c.dom.Document) Map(java.util.Map) Node(org.w3c.dom.Node) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) MappingHelper(org.folio.gobi.MappingHelper) Mapper(org.folio.gobi.Mapper) UUID(java.util.UUID) AcquisitionMethod(org.folio.rest.acq.model.AcquisitionMethod) GobiResponse(org.folio.rest.gobi.model.GobiResponse) Future(io.vertx.core.Future) XPathFactory(javax.xml.xpath.XPathFactory) PostGobiOrdersResponse.respond401WithTextPlain(org.folio.rest.jaxrs.resource.Gobi.PostGobiOrdersResponse.respond401WithTextPlain) Logger(org.apache.logging.log4j.Logger) Mapping(org.folio.rest.mappings.model.Mapping) OrderMappings(org.folio.rest.mappings.model.OrderMappings) HttpClientInterface(org.folio.rest.tools.client.interfaces.HttpClientInterface) HttpMethod(io.vertx.core.http.HttpMethod) Organization(org.folio.rest.acq.model.Organization) Function.identity(java.util.function.Function.identity) Optional(java.util.Optional) Objects.nonNull(java.util.Objects.nonNull) Handler(io.vertx.core.Handler) LogManager(org.apache.logging.log4j.LogManager) PostGobiOrdersResponse.respond400WithApplicationXml(org.folio.rest.jaxrs.resource.Gobi.PostGobiOrdersResponse.respond400WithApplicationXml) GobiResponseWriter(org.folio.gobi.GobiResponseWriter) Mapper(org.folio.gobi.Mapper) OrderMappings(org.folio.rest.mappings.model.OrderMappings) VertxCompletableFuture(me.escoffier.vertx.completablefuture.VertxCompletableFuture) CompositePurchaseOrder(org.folio.rest.acq.model.CompositePurchaseOrder)

Aggregations

Mapping (org.folio.rest.mappings.model.Mapping)2 OrderMappings (org.folio.rest.mappings.model.OrderMappings)2 AsyncResult (io.vertx.core.AsyncResult)1 Context (io.vertx.core.Context)1 Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1 HttpMethod (io.vertx.core.http.HttpMethod)1 Json (io.vertx.core.json.Json)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 EnumMap (java.util.EnumMap)1 Map (java.util.Map)1 Objects.nonNull (java.util.Objects.nonNull)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 Function.identity (java.util.function.Function.identity)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 XPath (javax.xml.xpath.XPath)1