Search in sources :

Example 1 with REPORTING_CODES

use of org.folio.orders.utils.ResourcePathResolver.REPORTING_CODES in project mod-orders by folio-org.

the class PurchaseOrderLineHelper method createReportingCodes.

private CompletableFuture<Void> createReportingCodes(CompositePoLine compPOL, JsonObject line, RequestContext requestContext) {
    List<CompletableFuture<String>> futures = new ArrayList<>();
    List<ReportingCode> reportingCodes = compPOL.getReportingCodes();
    if (null != reportingCodes) {
        RequestEntry rqEntry = new RequestEntry(resourcesPath(REPORTING_CODES));
        reportingCodes.forEach(reportingObject -> {
            futures.add(restClient.post(rqEntry, reportingObject, requestContext, ReportingCode.class).thenApply(ReportingCode::getId));
        });
    }
    return collectResultsOnSuccess(futures).thenAccept(reportingIds -> line.put(REPORTING_CODES, reportingIds)).exceptionally(t -> {
        logger.error("failed to create Reporting Codes", t);
        throw new CompletionException(t.getCause());
    });
}
Also used : OrderInvoiceRelationService(org.folio.service.orders.OrderInvoiceRelationService) EN(org.folio.rest.RestConstants.EN) URL_WITH_LANG_PARAM(org.folio.orders.utils.HelperUtils.URL_WITH_LANG_PARAM) StringUtils(org.apache.commons.lang3.StringUtils) PoLineCommonUtil(org.folio.orders.utils.PoLineCommonUtil) Matcher(java.util.regex.Matcher) HelperUtils.verifyProtectedFieldsChanged(org.folio.orders.utils.HelperUtils.verifyProtectedFieldsChanged) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) ORDER_CONFIG_MODULE_NAME(org.folio.orders.utils.HelperUtils.ORDER_CONFIG_MODULE_NAME) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) Errors(org.folio.rest.jaxrs.model.Errors) Alert(org.folio.rest.jaxrs.model.Alert) ErrorCodes(org.folio.rest.core.exceptions.ErrorCodes) ConfigurationEntriesService(org.folio.service.configuration.ConfigurationEntriesService) REPORTING_CODES(org.folio.orders.utils.ResourcePathResolver.REPORTING_CODES) OPEN(org.folio.rest.jaxrs.model.CompositePurchaseOrder.WorkflowStatus.OPEN) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) Eresource(org.folio.rest.jaxrs.model.Eresource) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) HttpClientInterface(org.folio.rest.tools.client.interfaces.HttpClientInterface) PO_LINES_STORAGE(org.folio.orders.utils.ResourcePathResolver.PO_LINES_STORAGE) ExpenseClassValidationService(org.folio.service.finance.expenceclass.ExpenseClassValidationService) RestClient(org.folio.rest.core.RestClient) UPDATE(org.folio.orders.utils.ProtectedOperationType.UPDATE) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) FolioVertxCompletableFuture(org.folio.completablefuture.FolioVertxCompletableFuture) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) OrderFormat(org.folio.rest.jaxrs.model.CompositePoLine.OrderFormat) ResourcePathResolver.resourcesPath(org.folio.orders.utils.ResourcePathResolver.resourcesPath) SequenceNumbers(org.folio.rest.acq.model.SequenceNumbers) Physical(org.folio.rest.jaxrs.model.Physical) ALERTS(org.folio.orders.utils.ResourcePathResolver.ALERTS) PO_LINE_NUMBER(org.folio.orders.utils.ResourcePathResolver.PO_LINE_NUMBER) HelperUtils(org.folio.orders.utils.HelperUtils) RequestEntry(org.folio.rest.core.models.RequestEntry) PostResponseType(org.folio.rest.core.PostResponseType) HelperUtils.combineCqlExpressions(org.folio.orders.utils.HelperUtils.combineCqlExpressions) JsonArray(io.vertx.core.json.JsonArray) ResourcePathResolver.resourceByIdPath(org.folio.orders.utils.ResourcePathResolver.resourceByIdPath) PoLineCollection(org.folio.rest.jaxrs.model.PoLineCollection) OrderWorkflowType(org.folio.service.orders.OrderWorkflowType) EVENT_PAYLOAD(org.folio.helper.AbstractHelper.EVENT_PAYLOAD) Cost(org.folio.rest.jaxrs.model.Cost) JsonObject.mapFrom(io.vertx.core.json.JsonObject.mapFrom) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) PurchaseOrderStorageService(org.folio.service.orders.PurchaseOrderStorageService) PoNumberHelper.buildPoLineNumber(org.folio.helper.PoNumberHelper.buildPoLineNumber) HelperUtils.collectResultsOnSuccess(org.folio.orders.utils.HelperUtils.collectResultsOnSuccess) PoLine(org.folio.rest.jaxrs.model.PoLine) ProtectionService(org.folio.service.ProtectionService) CollectionUtils.isEqualCollection(org.apache.commons.collections4.CollectionUtils.isEqualCollection) LOCATION_CAN_NOT_BE_MODIFIER_AFTER_OPEN(org.folio.rest.core.exceptions.ErrorCodes.LOCATION_CAN_NOT_BE_MODIFIER_AFTER_OPEN) HelperUtils.operateOnObject(org.folio.orders.utils.HelperUtils.operateOnObject) HelperUtils.deletePoLine(org.folio.orders.utils.HelperUtils.deletePoLine) Predicate(java.util.function.Predicate) CompletionException(java.util.concurrent.CompletionException) UUID(java.util.UUID) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ID(org.folio.helper.AbstractHelper.ID) List(java.util.List) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) Response(javax.ws.rs.core.Response) CompositePoLineValidationService(org.folio.service.orders.CompositePoLineValidationService) ReportingCode(org.folio.rest.jaxrs.model.ReportingCode) EncumbranceService(org.folio.service.finance.transaction.EncumbranceService) Optional(java.util.Optional) Parameter(org.folio.rest.jaxrs.model.Parameter) ORDER_ID(org.folio.helper.AbstractHelper.ORDER_ID) Pattern(java.util.regex.Pattern) AcquisitionsUnitsService(org.folio.service.AcquisitionsUnitsService) ProtectedOperationType(org.folio.orders.utils.ProtectedOperationType) HttpException(org.folio.rest.core.exceptions.HttpException) ProductId(org.folio.rest.jaxrs.model.ProductId) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) PENDING(org.folio.rest.jaxrs.model.CompositePurchaseOrder.WorkflowStatus.PENDING) POLineProtectedFieldsUtil(org.folio.orders.utils.POLineProtectedFieldsUtil) Title(org.folio.rest.jaxrs.model.Title) TitlesService(org.folio.service.titles.TitlesService) CompletableFuture.allOf(java.util.concurrent.CompletableFuture.allOf) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) RequestContext(org.folio.rest.core.models.RequestContext) HelperUtils.getPoLineLimit(org.folio.orders.utils.HelperUtils.getPoLineLimit) DELETE(org.folio.orders.utils.ProtectedOperationType.DELETE) EncumbranceWorkflowStrategyFactory(org.folio.service.finance.transaction.EncumbranceWorkflowStrategyFactory) InventoryManager(org.folio.service.inventory.InventoryManager) RestConstants(org.folio.rest.RestConstants) EncumbranceWorkflowStrategy(org.folio.service.finance.transaction.EncumbranceWorkflowStrategy) Iterator(java.util.Iterator) MessageAddress(org.folio.orders.events.handlers.MessageAddress) CLOSED(org.folio.rest.jaxrs.model.CompositePurchaseOrder.WorkflowStatus.CLOSED) Error(org.folio.rest.jaxrs.model.Error) Collectors.toList(java.util.stream.Collectors.toList) HelperUtils.calculateEstimatedPrice(org.folio.orders.utils.HelperUtils.calculateEstimatedPrice) HttpMethod(io.vertx.core.http.HttpMethod) PurchaseOrderLineService(org.folio.service.orders.PurchaseOrderLineService) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) FolioVertxCompletableFuture(org.folio.completablefuture.FolioVertxCompletableFuture) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) ArrayList(java.util.ArrayList) RequestEntry(org.folio.rest.core.models.RequestEntry) ReportingCode(org.folio.rest.jaxrs.model.ReportingCode)

Example 2 with REPORTING_CODES

use of org.folio.orders.utils.ResourcePathResolver.REPORTING_CODES in project mod-orders by folio-org.

the class HelperUtils method operateOnPoLine.

public static CompletableFuture<CompositePoLine> operateOnPoLine(HttpMethod operation, JsonObject line, Map<String, String> okapiHeaders, Logger logger) {
    CompletableFuture<CompositePoLine> future = new CompletableFuture<>();
    if (logger.isDebugEnabled()) {
        logger.debug("The PO line prior to {} operation: {}", operation, line.encodePrettily());
    }
    List<CompletableFuture<Void>> futures = new ArrayList<>();
    HttpClientInterface httpClient = AbstractHelper.getHttpClient(okapiHeaders, true);
    futures.addAll(operateOnSubObjsIfPresent(operation, line, ALERTS, httpClient, okapiHeaders, logger));
    futures.addAll(operateOnSubObjsIfPresent(operation, line, REPORTING_CODES, httpClient, okapiHeaders, logger));
    CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).thenAccept(v -> {
        if (logger.isDebugEnabled()) {
            logger.debug("The PO line after {} operation on sub-objects: {}", operation, line.encodePrettily());
        }
        httpClient.closeClient();
        future.complete(line.mapTo(CompositePoLine.class));
    }).exceptionally(t -> {
        httpClient.closeClient();
        logger.error("Exception resolving one or more poLine sub-object(s) on {} operation", operation, t);
        future.completeExceptionally(t);
        return null;
    });
    return future;
}
Also used : GENERIC_ERROR_CODE(org.folio.rest.core.exceptions.ErrorCodes.GENERIC_ERROR_CODE) AbstractHelper(org.folio.helper.AbstractHelper) Cost(org.folio.rest.jaxrs.model.Cost) Date(java.util.Date) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) CurrencyUnit(javax.money.CurrencyUnit) Path(javax.ws.rs.Path) EN(org.folio.rest.RestConstants.EN) PoLine(org.folio.rest.jaxrs.model.PoLine) StringUtils(org.apache.commons.lang3.StringUtils) Matcher(java.util.regex.Matcher) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) FULLY_RECEIVED(org.folio.rest.jaxrs.model.PoLine.ReceiptStatus.FULLY_RECEIVED) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) ReceiptStatus(org.folio.rest.jaxrs.model.PoLine.ReceiptStatus) ExchangeRateProviderResolver(org.folio.service.exchange.ExchangeRateProviderResolver) Alert(org.folio.rest.jaxrs.model.Alert) Location(org.folio.rest.jaxrs.model.Location) EnumMap(java.util.EnumMap) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) Collection(java.util.Collection) Money(org.javamoney.moneta.Money) ConversionQuery(javax.money.convert.ConversionQuery) Set(java.util.Set) Message(io.vertx.core.eventbus.Message) CompletionException(java.util.concurrent.CompletionException) PAYMENT_NOT_REQUIRED(org.folio.rest.jaxrs.model.PoLine.PaymentStatus.PAYMENT_NOT_REQUIRED) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) MonetaryOperators(org.javamoney.moneta.function.MonetaryOperators) List(java.util.List) REPORTING_CODES(org.folio.orders.utils.ResourcePathResolver.REPORTING_CODES) Logger(org.apache.logging.log4j.Logger) TITLE_NOT_FOUND(org.folio.rest.core.exceptions.ErrorCodes.TITLE_NOT_FOUND) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) PROHIBITED_FIELD_CHANGING(org.folio.rest.core.exceptions.ErrorCodes.PROHIBITED_FIELD_CHANGING) Response(org.folio.rest.tools.client.Response) HttpClientInterface(org.folio.rest.tools.client.interfaces.HttpClientInterface) StreamEx(one.util.streamex.StreamEx) PO_LINES_STORAGE(org.folio.orders.utils.ResourcePathResolver.PO_LINES_STORAGE) FULLY_PAID(org.folio.rest.jaxrs.model.PoLine.PaymentStatus.FULLY_PAID) ReportingCode(org.folio.rest.jaxrs.model.ReportingCode) Optional(java.util.Optional) IntStreamEx(one.util.streamex.IntStreamEx) Pattern(java.util.regex.Pattern) Objects.nonNull(java.util.Objects.nonNull) RATE_KEY(org.folio.service.exchange.ExchangeRateProviderResolver.RATE_KEY) MonetaryAmount(javax.money.MonetaryAmount) Future.succeededFuture(io.vertx.core.Future.succeededFuture) DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions) ERROR_MESSAGE(org.folio.rest.RestConstants.ERROR_MESSAGE) HttpException(org.folio.rest.core.exceptions.HttpException) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayUtils(org.apache.commons.lang3.ArrayUtils) LOCATION(javax.ws.rs.core.HttpHeaders.LOCATION) ObjectUtils.defaultIfNull(org.apache.commons.lang3.ObjectUtils.defaultIfNull) CollectionUtils(org.apache.commons.collections4.CollectionUtils) CaseInsensitiveMap(org.apache.commons.collections4.map.CaseInsensitiveMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Title(org.folio.rest.jaxrs.model.Title) ResourcePathResolver.resourcesPath(org.folio.orders.utils.ResourcePathResolver.resourcesPath) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) ObjectUtils(org.apache.commons.lang3.ObjectUtils) RequestContext(org.folio.rest.core.models.RequestContext) EMPTY(org.apache.commons.lang3.StringUtils.EMPTY) AsyncResult(io.vertx.core.AsyncResult) ALERTS(org.folio.orders.utils.ResourcePathResolver.ALERTS) Monetary(javax.money.Monetary) PURCHASE_ORDER_STORAGE(org.folio.orders.utils.ResourcePathResolver.PURCHASE_ORDER_STORAGE) MessageAddress(org.folio.orders.events.handlers.MessageAddress) MULTIPLE_NONPACKAGE_TITLES(org.folio.rest.core.exceptions.ErrorCodes.MULTIPLE_NONPACKAGE_TITLES) Piece(org.folio.rest.jaxrs.model.Piece) CloseReason(org.folio.rest.jaxrs.model.CloseReason) JsonPathParser(org.folio.rest.tools.parser.JsonPathParser) InventoryException(org.folio.rest.core.exceptions.InventoryException) Error(org.folio.rest.jaxrs.model.Error) JsonArray(io.vertx.core.json.JsonArray) Collectors.toList(java.util.stream.Collectors.toList) URLEncoder(java.net.URLEncoder) ResourcePathResolver.resourceByIdPath(org.folio.orders.utils.ResourcePathResolver.resourceByIdPath) HttpMethod(io.vertx.core.http.HttpMethod) RECEIPT_NOT_REQUIRED(org.folio.rest.jaxrs.model.PoLine.ReceiptStatus.RECEIPT_NOT_REQUIRED) Handler(io.vertx.core.Handler) Collections(java.util.Collections) PaymentStatus(org.folio.rest.jaxrs.model.PoLine.PaymentStatus) ConversionQueryBuilder(javax.money.convert.ConversionQueryBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) HttpClientInterface(org.folio.rest.tools.client.interfaces.HttpClientInterface) ArrayList(java.util.ArrayList) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine)

Aggregations

HttpMethod (io.vertx.core.http.HttpMethod)2 JsonArray (io.vertx.core.json.JsonArray)2 JsonObject (io.vertx.core.json.JsonObject)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)2 CompletionException (java.util.concurrent.CompletionException)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Collectors.toList (java.util.stream.Collectors.toList)2 CollectionUtils (org.apache.commons.collections4.CollectionUtils)2 StringUtils (org.apache.commons.lang3.StringUtils)2 StringUtils.isEmpty (org.apache.commons.lang3.StringUtils.isEmpty)2 Logger (org.apache.logging.log4j.Logger)2 MessageAddress (org.folio.orders.events.handlers.MessageAddress)2