Search in sources :

Example 1 with OrderWorkflowType

use of org.folio.service.orders.OrderWorkflowType in project mod-orders by folio-org.

the class PurchaseOrderLineHelper method processPoLineEncumbrances.

private CompletableFuture<Void> processPoLineEncumbrances(CompositePurchaseOrder compOrder, CompositePoLine compositePoLine, JsonObject lineFromStorage, RequestContext requestContext) {
    PoLine storagePoLine = lineFromStorage.mapTo(PoLine.class);
    List<String> storageFundIds = storagePoLine.getFundDistribution().stream().map(FundDistribution::getFundId).collect(Collectors.toList());
    compositePoLine.getFundDistribution().stream().filter(fundDistribution -> storageFundIds.contains(fundDistribution.getFundId()) && fundDistribution.getEncumbrance() == null).forEach(fundDistribution -> storagePoLine.getFundDistribution().stream().filter(storageFundDistribution -> storageFundDistribution.getFundId().equals(fundDistribution.getFundId())).findFirst().ifPresent(storageFundDistribution -> fundDistribution.setEncumbrance(storageFundDistribution.getEncumbrance())));
    if (isEncumbranceUpdateNeeded(compOrder, compositePoLine, storagePoLine)) {
        OrderWorkflowType workflowType = compOrder.getWorkflowStatus() == PENDING ? OrderWorkflowType.PENDING_TO_PENDING : OrderWorkflowType.PENDING_TO_OPEN;
        EncumbranceWorkflowStrategy strategy = encumbranceWorkflowStrategyFactory.getStrategy(workflowType);
        CompositePurchaseOrder poFromStorage = JsonObject.mapFrom(compOrder).mapTo(CompositePurchaseOrder.class);
        return strategy.processEncumbrances(compOrder.withCompositePoLines(Collections.singletonList(compositePoLine)), poFromStorage, requestContext);
    }
    return completedFuture(null);
}
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) EncumbranceWorkflowStrategy(org.folio.service.finance.transaction.EncumbranceWorkflowStrategy) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) PoLine(org.folio.rest.jaxrs.model.PoLine) HelperUtils.deletePoLine(org.folio.orders.utils.HelperUtils.deletePoLine) OrderWorkflowType(org.folio.service.orders.OrderWorkflowType) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder)

Aggregations

HttpMethod (io.vertx.core.http.HttpMethod)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 JsonObject.mapFrom (io.vertx.core.json.JsonObject.mapFrom)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.allOf (java.util.concurrent.CompletableFuture.allOf)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 CompletionException (java.util.concurrent.CompletionException)1 CompletionStage (java.util.concurrent.CompletionStage)1 Predicate (java.util.function.Predicate)1 Matcher (java.util.regex.Matcher)1