Search in sources :

Example 1 with VertxCompletableFuture

use of me.escoffier.vertx.completablefuture.VertxCompletableFuture 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)

Example 2 with VertxCompletableFuture

use of me.escoffier.vertx.completablefuture.VertxCompletableFuture in project mod-gobi by folio-org.

the class PostGobiOrdersHelper method parse.

public CompletableFuture<Document> parse(String entity) {
    VertxCompletableFuture<Document> future = new VertxCompletableFuture<>(ctx);
    final GobiPurchaseOrderParser parser = GobiPurchaseOrderParser.getParser();
    try {
        future.complete(parser.parse(entity));
    } catch (GobiPurchaseOrderParserException e) {
        logger.error("Failed to parse GobiPurchaseOrder", e);
        future.completeExceptionally(e);
    }
    return future;
}
Also used : GobiPurchaseOrderParserException(org.folio.gobi.exceptions.GobiPurchaseOrderParserException) VertxCompletableFuture(me.escoffier.vertx.completablefuture.VertxCompletableFuture) Document(org.w3c.dom.Document) GobiPurchaseOrderParser(org.folio.gobi.GobiPurchaseOrderParser)

Aggregations

VertxCompletableFuture (me.escoffier.vertx.completablefuture.VertxCompletableFuture)2 GobiPurchaseOrderParser (org.folio.gobi.GobiPurchaseOrderParser)2 GobiPurchaseOrderParserException (org.folio.gobi.exceptions.GobiPurchaseOrderParserException)2 Document (org.w3c.dom.Document)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 JsonObject (io.vertx.core.json.JsonObject)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