Modified: ofbiz/ofbiz-framework/trunk/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java?rev=1819730&r1=1819729&r2=1819730&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java Sun Dec 31 11:11:46 2017 @@ -31,6 +31,7 @@ import java.util.SortedMap; import java.util.TreeMap; import org.apache.ofbiz.base.util.Debug; +import org.apache.ofbiz.base.util.GeneralException; import org.apache.ofbiz.base.util.UtilDateTime; import org.apache.ofbiz.base.util.UtilGenerics; import org.apache.ofbiz.base.util.UtilMisc; @@ -57,7 +58,6 @@ import org.apache.ofbiz.service.GenericS import org.apache.ofbiz.service.LocalDispatcher; import org.apache.ofbiz.service.ModelService; import org.apache.ofbiz.service.ServiceUtil; - /** * Services for Production Run maintenance * @@ -93,7 +93,7 @@ public class ProductionRunServices { LocalDispatcher dispatcher = ctx.getDispatcher(); Locale locale = (Locale) context.get("locale"); GenericValue userLogin = (GenericValue) context.get("userLogin"); - + Map<String, Object> serviceResult = new HashMap<String, Object>(); String productionRunId = (String) context.get("productionRunId"); ProductionRun productionRun = new ProductionRun(productionRunId, delegator, dispatcher); @@ -119,7 +119,10 @@ public class ProductionRunServices { serviceContext.put("workEffortId", productionRunId); serviceContext.put("currentStatusId", "PRUN_CANCELLED"); serviceContext.put("userLogin", userLogin); - dispatcher.runSync("updateWorkEffort", serviceContext); + serviceResult = dispatcher.runSync("updateWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } // Cancel the product promised List<GenericValue> products = EntityQuery.use(delegator).from("WorkEffortGoodStandard") .where("workEffortId", productionRunId, @@ -142,7 +145,10 @@ public class ProductionRunServices { serviceContext.put("workEffortId", taskId); serviceContext.put("currentStatusId", "PRUN_CANCELLED"); serviceContext.put("userLogin", userLogin); - dispatcher.runSync("updateWorkEffort", serviceContext); + serviceResult = dispatcher.runSync("updateWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } // cancel all the components List<GenericValue> components = EntityQuery.use(delegator).from("WorkEffortGoodStandard") .where("workEffortId", taskId, @@ -230,6 +236,9 @@ public class ProductionRunServices { routingInMap.put("workEffortId", workEffortId); } Map<String, Object> routingOutMap = dispatcher.runSync("getProductRouting", routingInMap); + if (ServiceUtil.isError(routingOutMap)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(routingOutMap)); + } routing = (GenericValue)routingOutMap.get("routing"); routingTaskAssocs = UtilGenerics.checkList(routingOutMap.get("tasks")); } catch (GenericServiceException gse) { @@ -252,10 +261,13 @@ public class ProductionRunServices { serviceContext.put("productId", productId); // the product that we want to manufacture serviceContext.put("quantity", pRQuantity); // the quantity that we want to manufacture serviceContext.put("userLogin", userLogin); - Map<String, Object> resultService = null; + Map<String, Object> serviceResult = null; try { - resultService = dispatcher.runSync("getManufacturingComponents", serviceContext); - components = UtilGenerics.checkList(resultService.get("components")); // a list of objects representing the product's components + serviceResult = dispatcher.runSync("getManufacturingComponents", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } + components = UtilGenerics.checkList(serviceResult.get("components")); // a list of objects representing the product's components } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the getManufacturingComponents service", module); return ServiceUtil.returnError(e.getMessage()); @@ -279,12 +291,15 @@ public class ProductionRunServices { serviceContext.put("quantityToProduce", pRQuantity); serviceContext.put("userLogin", userLogin); try { - resultService = dispatcher.runSync("createWorkEffort", serviceContext); + serviceResult = dispatcher.runSync("createWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the createWorkEffort service", module); return ServiceUtil.returnError(e.getMessage()); } - String productionRunId = (String) resultService.get("workEffortId"); + String productionRunId = (String) serviceResult.get("workEffortId"); if (Debug.infoOn()) { Debug.logInfo("ProductionRun created: " + productionRunId, module); } @@ -299,7 +314,10 @@ public class ProductionRunServices { serviceContext.put("fromDate", startDate); serviceContext.put("userLogin", userLogin); try { - resultService = dispatcher.runSync("createWorkEffortGoodStandard", serviceContext); + serviceResult = dispatcher.runSync("createWorkEffortGoodStandard", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the createWorkEffortGoodStandard service", module); return ServiceUtil.returnError(e.getMessage()); @@ -336,13 +354,16 @@ public class ProductionRunServices { serviceContext.put("estimatedMilliSeconds", routingTask.get("estimatedMilliSeconds")); serviceContext.put("quantityToProduce", pRQuantity); serviceContext.put("userLogin", userLogin); - resultService = null; + serviceResult = null; try { - resultService = dispatcher.runSync("createWorkEffort", serviceContext); + serviceResult = dispatcher.runSync("createWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the createWorkEffort service", module); } - String productionRunTaskId = (String) resultService.get("workEffortId"); + String productionRunTaskId = (String) serviceResult.get("workEffortId"); if (Debug.infoOn()) Debug.logInfo("ProductionRunTaskId created: " + productionRunTaskId, module); // The newly created production run task is associated to the routing task @@ -353,16 +374,21 @@ public class ProductionRunServices { serviceContext.put("workEffortIdTo", productionRunTaskId); serviceContext.put("workEffortAssocTypeId", "WORK_EFF_TEMPLATE"); try { - resultService = dispatcher.runSync("createWorkEffortAssoc", serviceContext); + serviceResult = dispatcher.runSync("createWorkEffortAssoc", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the createWorkEffortAssoc service", module); } - // clone associated objects from the routing task to the run task String routingTaskId = routingTaskAssoc.getString("workEffortIdTo"); + try { cloneWorkEffortPartyAssignments(ctx, userLogin, routingTaskId, productionRunTaskId); cloneWorkEffortCostCalcs(ctx, userLogin, routingTaskId, productionRunTaskId); - + } catch (GeneralException e) { + return ServiceUtil.returnError(e.getMessage()); + } // Now we iterate thru the components returned by the getManufacturingComponents service // TODO: if in the BOM a routingWorkEffortId is specified, but the task is not in the routing // the component is not added to the production run. @@ -384,9 +410,12 @@ public class ProductionRunServices { // computed by the getManufacturingComponents service serviceContext.put("estimatedQuantity", node.getQuantity()); serviceContext.put("userLogin", userLogin); - resultService = null; + serviceResult = null; try { - resultService = dispatcher.runSync("createWorkEffortGoodStandard", serviceContext); + serviceResult = dispatcher.runSync("createWorkEffortGoodStandard", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the createWorkEffortGoodStandard service", module); } @@ -403,9 +432,12 @@ public class ProductionRunServices { serviceContext.put("workEffortId",productionRunId); serviceContext.put("estimatedCompletionDate",startDate); serviceContext.put("userLogin", userLogin); - resultService = null; + serviceResult = null; try { - resultService = dispatcher.runSync("updateWorkEffort", serviceContext); + serviceResult = dispatcher.runSync("updateWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffort service", module); } @@ -419,7 +451,7 @@ public class ProductionRunServices { * Make a copy of the party assignments that were defined on the template routing task to the new production run task. */ private static void cloneWorkEffortPartyAssignments(DispatchContext dctx, GenericValue userLogin, - String routingTaskId, String productionRunTaskId) { + String routingTaskId, String productionRunTaskId) throws GeneralException { List<GenericValue> workEffortPartyAssignments = null; try { workEffortPartyAssignments = EntityUtil.filterByDate( @@ -439,7 +471,12 @@ public class ProductionRunServices { "userLogin", userLogin ); try { - dctx.getDispatcher().runSync("assignPartyToWorkEffort", partyToWorkEffort); + Map<String, Object> result = dctx.getDispatcher().runSync("assignPartyToWorkEffort", partyToWorkEffort); + if (ServiceUtil.isError(result)) { + String errorMessage = ServiceUtil.getErrorMessage(result); + Debug.logError(errorMessage, module); + throw new GeneralException(errorMessage); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the assignPartyToWorkEffort service", module); } @@ -451,7 +488,7 @@ public class ProductionRunServices { /** * Make a copy of the cost calc entities that were defined on the template routing task to the new production run task. */ - private static void cloneWorkEffortCostCalcs(DispatchContext dctx, GenericValue userLogin, String routingTaskId, String productionRunTaskId) { + private static void cloneWorkEffortCostCalcs(DispatchContext dctx, GenericValue userLogin, String routingTaskId, String productionRunTaskId) throws GeneralException { List<GenericValue> workEffortCostCalcs = null; try { workEffortCostCalcs = EntityUtil.filterByDate( @@ -472,7 +509,12 @@ public class ProductionRunServices { ); try { - dctx.getDispatcher().runSync("createWorkEffortCostCalc", createCostCalc); + Map<String, Object> result = dctx.getDispatcher().runSync("createWorkEffortCostCalc", createCostCalc); + if (ServiceUtil.isError(result)) { + String errorMessage = ServiceUtil.getErrorMessage(result); + Debug.logError(errorMessage, module); + throw new GeneralException(errorMessage); + } } catch (GenericServiceException gse) { Debug.logError(gse, "Problem calling the createWorkEffortCostCalc service", module); } @@ -539,8 +581,11 @@ public class ProductionRunServices { if (productionRun.store()) { if (updateEstimatedOrderDates && "PRUN_SCHEDULED".equals(productionRun.getGenericValue().getString("currentStatusId"))) { try { - dispatcher.runSync("setEstimatedDeliveryDates", + Map<String, Object> result = dispatcher.runSync("setEstimatedDeliveryDates", UtilMisc.toMap("userLogin", userLogin)); + if (ServiceUtil.isError(result)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the setEstimatedDeliveryDates service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotUpdated", locale)); @@ -565,7 +610,7 @@ public class ProductionRunServices { LocalDispatcher dispatcher = ctx.getDispatcher(); Locale locale = (Locale) context.get("locale"); GenericValue userLogin = (GenericValue) context.get("userLogin"); - + Map<String, Object> serviceResult = new HashMap<String, Object>(); String productionRunId = (String) context.get("productionRunId"); String statusId = (String) context.get("statusId"); @@ -590,7 +635,10 @@ public class ProductionRunServices { serviceContext.put("currentStatusId", statusId); serviceContext.put("userLogin", userLogin); try { - dispatcher.runSync("updateWorkEffort", serviceContext); + serviceResult = dispatcher.runSync("updateWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffort service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); @@ -602,7 +650,10 @@ public class ProductionRunServices { serviceContext.put("currentStatusId", statusId); serviceContext.put("userLogin", userLogin); try { - dispatcher.runSync("updateWorkEffort", serviceContext); + serviceResult = dispatcher.runSync("updateWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffort service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); @@ -622,7 +673,10 @@ public class ProductionRunServices { serviceContext.put("currentStatusId", "PRUN_DOC_PRINTED"); serviceContext.put("userLogin", userLogin); try { - dispatcher.runSync("updateWorkEffort", serviceContext); + serviceResult = dispatcher.runSync("updateWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffort service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); @@ -634,7 +688,10 @@ public class ProductionRunServices { serviceContext.put("currentStatusId", "PRUN_DOC_PRINTED"); serviceContext.put("userLogin", userLogin); try { - dispatcher.runSync("updateWorkEffort", serviceContext); + serviceResult = dispatcher.runSync("updateWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffort service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); @@ -675,7 +732,10 @@ public class ProductionRunServices { serviceContext.put("actualStartDate", UtilDateTime.nowTimestamp()); serviceContext.put("userLogin", userLogin); try { - dispatcher.runSync("updateWorkEffort", serviceContext); + serviceResult = dispatcher.runSync("updateWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffort service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); @@ -696,7 +756,10 @@ public class ProductionRunServices { serviceContext.put("actualCompletionDate", UtilDateTime.nowTimestamp()); serviceContext.put("userLogin", userLogin); try { - dispatcher.runSync("updateWorkEffort", serviceContext); + serviceResult = dispatcher.runSync("updateWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffort service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); @@ -715,7 +778,10 @@ public class ProductionRunServices { serviceContext.put("currentStatusId", "PRUN_CLOSED"); serviceContext.put("userLogin", userLogin); try { - dispatcher.runSync("updateWorkEffort", serviceContext); + serviceResult = dispatcher.runSync("updateWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffort service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); @@ -727,7 +793,10 @@ public class ProductionRunServices { serviceContext.put("currentStatusId", "PRUN_CLOSED"); serviceContext.put("userLogin", userLogin); try { - dispatcher.runSync("updateWorkEffort", serviceContext); + serviceResult = dispatcher.runSync("updateWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffort service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); @@ -751,6 +820,7 @@ public class ProductionRunServices { String productionRunId = (String) context.get("productionRunId"); String taskId = (String) context.get("workEffortId"); String statusId = (String) context.get("statusId"); + Map<String, Object> serviceResult = new HashMap<String, Object>(); Boolean issueAllComponents = (Boolean) context.get("issueAllComponents"); if (issueAllComponents == null) { issueAllComponents = Boolean.FALSE; @@ -810,7 +880,10 @@ public class ProductionRunServices { serviceContext.put("actualStartDate", UtilDateTime.nowTimestamp()); serviceContext.put("userLogin", userLogin); try { - dispatcher.runSync("updateWorkEffort", serviceContext); + serviceResult = dispatcher.runSync("updateWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffort service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); @@ -821,7 +894,10 @@ public class ProductionRunServices { serviceContext.put("statusId", "PRUN_RUNNING"); serviceContext.put("userLogin", userLogin); try { - dispatcher.runSync("changeProductionRunStatus", serviceContext); + serviceResult = dispatcher.runSync("changeProductionRunStatus", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the changeProductionRunStatus service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); @@ -847,7 +923,10 @@ public class ProductionRunServices { serviceContext.clear(); serviceContext.put("workEffortId", taskId); serviceContext.put("userLogin", userLogin); - dispatcher.runSync("issueProductionRunTask", serviceContext); + serviceResult = dispatcher.runSync("issueProductionRunTask", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); + } } } catch (GenericServiceException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); @@ -892,7 +971,10 @@ public class ProductionRunServices { } serviceContext.put("userLogin", userLogin); try { - dispatcher.runSync("updateWorkEffort", serviceContext); + serviceResult = dispatcher.runSync("updateWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffort service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); @@ -902,7 +984,10 @@ public class ProductionRunServices { serviceContext.put("productionRunTaskId", taskId); serviceContext.put("userLogin", userLogin); try { - dispatcher.runSync("createProductionRunTaskCosts", serviceContext); + serviceResult = dispatcher.runSync("createProductionRunTaskCosts", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the createProductionRunTaskCosts service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); @@ -914,7 +999,10 @@ public class ProductionRunServices { serviceContext.put("statusId", "PRUN_COMPLETED"); serviceContext.put("userLogin", userLogin); try { - dispatcher.runSync("changeProductionRunStatus", serviceContext); + serviceResult = dispatcher.runSync("changeProductionRunStatus", serviceContext); + if (ServiceUtil.isError(result)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffort service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); @@ -926,12 +1014,17 @@ public class ProductionRunServices { Map<String, Object> outputMap = dispatcher.runSync("getPartyAccountingPreferences", UtilMisc.<String, Object>toMap("userLogin", userLogin, "organizationPartyId", facility.getString("ownerPartyId"))); + if (ServiceUtil.isError(outputMap)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(outputMap)); + } GenericValue partyAccountingPreference = (GenericValue)outputMap.get("partyAccountingPreference"); if (partyAccountingPreference == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunUnableToFindCosts", locale)); } outputMap = dispatcher.runSync("getProductionRunCost", UtilMisc.<String, Object>toMap("userLogin", userLogin, "workEffortId", productionRunId)); - + if (ServiceUtil.isError(outputMap)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(outputMap)); + } BigDecimal totalCost = (BigDecimal)outputMap.get("totalCost"); if (totalCost == null) { totalCost = ZERO; @@ -955,6 +1048,9 @@ public class ProductionRunServices { "baseCost", totalCost, "currencyUomId", (String)partyAccountingPreference.get("baseCurrencyUomId"), "userLogin", userLogin)); + if (ServiceUtil.isError(costMethodResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(costMethodResult)); + } BigDecimal productCostAdjustment = (BigDecimal)costMethodResult.get("productCostAdjustment"); totalCost = totalCost.add(productCostAdjustment); Map<String, Object> inMap = UtilMisc.<String, Object>toMap("userLogin", userLogin, "workEffortId", productionRunId); @@ -962,7 +1058,10 @@ public class ProductionRunServices { inMap.put("costComponentTypeId", "ACTUAL_" + productCostComponentCalc.getString("costComponentTypeId")); inMap.put("costUomId", partyAccountingPreference.get("baseCurrencyUomId")); inMap.put("cost", productCostAdjustment); - dispatcher.runSync("createCostComponent", inMap); + serviceResult = dispatcher.runSync("createCostComponent", inMap); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } } } catch(GenericServiceException gse) { @@ -1032,11 +1131,17 @@ public class ProductionRunServices { BigDecimal totalCost = ZERO; Map<String, Object> outputMap = dispatcher.runSync("getWorkEffortCosts", UtilMisc.<String, Object>toMap("userLogin", userLogin, "workEffortId", workEffortId)); + if (ServiceUtil.isError(outputMap)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(outputMap)); + } BigDecimal productionRunHeaderCost = (BigDecimal)outputMap.get("totalCost"); totalCost = totalCost.add(productionRunHeaderCost); for (GenericValue task : tasks) { outputMap = dispatcher.runSync("getWorkEffortCosts", UtilMisc.<String, Object>toMap("userLogin", userLogin, "workEffortId", task.getString("workEffortId"))); + if (ServiceUtil.isError(outputMap)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(outputMap)); + } BigDecimal taskCost = (BigDecimal)outputMap.get("totalCost"); totalCost = totalCost.add(taskCost); } @@ -1056,7 +1161,7 @@ public class ProductionRunServices { LocalDispatcher dispatcher = ctx.getDispatcher(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Locale locale = (Locale) context.get("locale"); - + Map<String, Object> serviceResult = new HashMap<String, Object>(); // this is the id of the actual (real) production run task String productionRunTaskId = (String)context.get("productionRunTaskId"); try { @@ -1118,13 +1223,19 @@ public class ProductionRunServices { inMap.put("costComponentCalcId", costComponentCalc.getString("costComponentCalcId")); inMap.put("costUomId", costComponentCalc.getString("currencyUomId")); inMap.put("cost", totalCost); - dispatcher.runSync("createCostComponent", inMap); + serviceResult = dispatcher.runSync("createCostComponent", inMap); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } else { // use the custom method (aka formula) to compute the costs Map<String, Object> inMap = UtilMisc.<String, Object>toMap("userLogin", userLogin, "workEffort", workEffort); inMap.put("workEffortCostCalc", workEffortCostCalc); inMap.put("costComponentCalc", costComponentCalc); - dispatcher.runSync(customMethod.getString("customMethodName"), inMap); + serviceResult = dispatcher.runSync(customMethod.getString("customMethodName"), inMap); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } } @@ -1158,7 +1269,10 @@ public class ProductionRunServices { inMap.put("costUomId", currencyUomId); inMap.put("cost", fixedAssetCost); inMap.put("fixedAssetId", fixedAsset.get("fixedAssetId")); - dispatcher.runSync("createCostComponent", inMap); + serviceResult = dispatcher.runSync("createCostComponent", inMap); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } } } catch (GenericEntityException|GenericServiceException ge) { @@ -1191,7 +1305,10 @@ public class ProductionRunServices { inMap.put("costComponentTypeId", "ACTUAL_MAT_COST"); inMap.put("costUomId", currencyUomId); inMap.put("cost", materialsCost); - dispatcher.runSync("createCostComponent", inMap); + serviceResult = dispatcher.runSync("createCostComponent", inMap); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } } catch (GenericEntityException|GenericServiceException ge) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunUnableToCreateMaterialsCosts", UtilMisc.toMap("productionRunTaskId", productionRunTaskId, "errorString", ge.getMessage()), locale)); @@ -1219,7 +1336,7 @@ public class ProductionRunServices { LocalDispatcher dispatcher = ctx.getDispatcher(); Locale locale = (Locale) context.get("locale"); GenericValue userLogin = (GenericValue) context.get("userLogin"); - + Map<String, Object> serviceResult = new HashMap<String, Object>(); String productionRunId = (String) context.get("productionRunId"); String routingTaskId = (String) context.get("routingTaskId"); if (! UtilValidate.isEmpty(productionRunId) && ! UtilValidate.isEmpty(routingTaskId)) { @@ -1235,7 +1352,10 @@ public class ProductionRunServices { Timestamp pRestimatedStartDate = productionRun.getEstimatedStartDate(); if (pRestimatedStartDate.after(estimatedStartDate)) { try { - dispatcher.runSync("updateProductionRun", UtilMisc.toMap("productionRunId", productionRunId, "estimatedStartDate", estimatedStartDate, "userLogin", userLogin)); + serviceResult = dispatcher.runSync("updateProductionRun", UtilMisc.toMap("productionRunId", productionRunId, "estimatedStartDate", estimatedStartDate, "userLogin", userLogin)); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingRoutingTaskStartDateBeforePRun", locale)); } @@ -1346,7 +1466,10 @@ public class ProductionRunServices { serviceContext.put("estimatedQuantity", quantity); serviceContext.put("userLogin", userLogin); try { - dispatcher.runSync("createWorkEffortGoodStandard", serviceContext); + Map<String, Object> serviceResult = dispatcher.runSync("createWorkEffortGoodStandard", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the createWorkEffortGoodStandard service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunComponentNotAdded", locale)); @@ -1421,7 +1544,10 @@ public class ProductionRunServices { } serviceContext.put("userLogin", userLogin); try { - dispatcher.runSync("updateWorkEffortGoodStandard", serviceContext); + Map<String, Object> serviceResult = dispatcher.runSync("updateWorkEffortGoodStandard", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffortGoodStandard service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunComponentNotAdded", locale)); @@ -1524,14 +1650,17 @@ public class ProductionRunServices { serviceContext.put("estimatedMilliSeconds", estimatedMilliSeconds); serviceContext.put("quantityToProduce", pRQuantity); serviceContext.put("userLogin", userLogin); - Map<String, Object> resultService = null; + Map<String, Object> serviceResult = null; try { - resultService = dispatcher.runSync("createWorkEffort", serviceContext); + serviceResult = dispatcher.runSync("createWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the createWorkEffort service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingAddProductionRunRoutingTaskNotCreated", locale)); } - String productionRunTaskId = (String) resultService.get("workEffortId"); + String productionRunTaskId = (String) serviceResult.get("workEffortId"); if (Debug.infoOn()) Debug.logInfo("ProductionRunTaskId created: " + productionRunTaskId, module); @@ -1560,7 +1689,10 @@ public class ProductionRunServices { "userLogin", userLogin ); try { - resultService = dispatcher.runSync("assignPartyToWorkEffort", partyToWorkEffort); + serviceResult = dispatcher.runSync("assignPartyToWorkEffort", partyToWorkEffort); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the assignPartyToWorkEffort service", module); } @@ -1686,11 +1818,17 @@ public class ProductionRunServices { // get the currency facility = productionRun.getGenericValue().getRelatedOne("Facility", false); Map<String, Object> outputMap = dispatcher.runSync("getPartyAccountingPreferences", UtilMisc.<String, Object>toMap("userLogin", userLogin, "organizationPartyId", facility.getString("ownerPartyId"))); + if (ServiceUtil.isError(outputMap)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(outputMap)); + } GenericValue partyAccountingPreference = (GenericValue)outputMap.get("partyAccountingPreference"); if (partyAccountingPreference == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunUnableToFindCosts", locale)); } outputMap = dispatcher.runSync("getProductCost", UtilMisc.<String, Object>toMap("userLogin", userLogin, "productId", productionRun.getProductProduced().getString("productId"), "currencyUomId", (String)partyAccountingPreference.get("baseCurrencyUomId"), "costComponentTypePrefix", "EST_STD")); + if (ServiceUtil.isError(outputMap)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(outputMap)); + } unitCost = (BigDecimal)outputMap.get("productCost"); if (unitCost != null && unitCost.compareTo(BigDecimal.ZERO) == 0) { BigDecimal totalCost = ZERO; @@ -1722,7 +1860,10 @@ public class ProductionRunServices { createProductFacilityCtx.put("productId", productionRun.getProductProduced().getString("productId")); createProductFacilityCtx.put("facilityId", facility.get("facilityId")); createProductFacilityCtx.put("userLogin", userLogin); - dispatcher.runSync("createProductFacility", createProductFacilityCtx); + Map<String, Object> serviceResult = dispatcher.runSync("createProductFacility", createProductFacilityCtx); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } } catch (GenericServiceException gse) { @@ -1751,8 +1892,11 @@ public class ProductionRunServices { serviceContext.put("locationSeqId", locationSeqId); serviceContext.put("uomId",uomId); serviceContext.put("userLogin", userLogin); - Map<String, Object> resultService = dispatcher.runSync("createInventoryItem", serviceContext); - String inventoryItemId = (String)resultService.get("inventoryItemId"); + Map<String, Object> serviceResult = dispatcher.runSync("createInventoryItem", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } + String inventoryItemId = (String)serviceResult.get("inventoryItemId"); inventoryItemIds.add(inventoryItemId); serviceContext.clear(); serviceContext.put("inventoryItemId", inventoryItemId); @@ -1760,17 +1904,26 @@ public class ProductionRunServices { serviceContext.put("availableToPromiseDiff", BigDecimal.ONE); serviceContext.put("quantityOnHandDiff", BigDecimal.ONE); serviceContext.put("userLogin", userLogin); - resultService = dispatcher.runSync("createInventoryItemDetail", serviceContext); + serviceResult = dispatcher.runSync("createInventoryItemDetail", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } serviceContext.clear(); serviceContext.put("userLogin", userLogin); serviceContext.put("workEffortId", productionRunId); serviceContext.put("inventoryItemId", inventoryItemId); - resultService = dispatcher.runSync("createWorkEffortInventoryProduced", serviceContext); + serviceResult = dispatcher.runSync("createWorkEffortInventoryProduced", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } // Recompute reservations serviceContext = new HashMap<String, Object>(); serviceContext.put("inventoryItemId", inventoryItemId); serviceContext.put("userLogin", userLogin); - resultService = dispatcher.runSync("balanceInventoryItems", serviceContext); + serviceResult = dispatcher.runSync("balanceInventoryItems", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } } catch (GenericServiceException exc) { return ServiceUtil.returnError(exc.getMessage()); @@ -1792,8 +1945,11 @@ public class ProductionRunServices { serviceContext.put("unitCost", unitCost); } serviceContext.put("userLogin", userLogin); - Map<String, Object> resultService = dispatcher.runSync("createInventoryItem", serviceContext); - String inventoryItemId = (String)resultService.get("inventoryItemId"); + Map<String, Object> serviceResult = dispatcher.runSync("createInventoryItem", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } + String inventoryItemId = (String)serviceResult.get("inventoryItemId"); inventoryItemIds.add(inventoryItemId); serviceContext.clear(); serviceContext.put("inventoryItemId", inventoryItemId); @@ -1801,12 +1957,18 @@ public class ProductionRunServices { serviceContext.put("availableToPromiseDiff", quantity); serviceContext.put("quantityOnHandDiff", quantity); serviceContext.put("userLogin", userLogin); - resultService = dispatcher.runSync("createInventoryItemDetail", serviceContext); + serviceResult = dispatcher.runSync("createInventoryItemDetail", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } serviceContext.clear(); serviceContext.put("userLogin", userLogin); serviceContext.put("workEffortId", productionRunId); serviceContext.put("inventoryItemId", inventoryItemId); - resultService = dispatcher.runSync("createWorkEffortInventoryProduced", serviceContext); + serviceResult = dispatcher.runSync("createWorkEffortInventoryProduced", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } // Recompute reservations serviceContext = new HashMap<String, Object>(); serviceContext.put("inventoryItemId", inventoryItemId); @@ -1816,7 +1978,10 @@ public class ProductionRunServices { serviceContext.put("priorityOrderId", orderItem.getString("orderId")); serviceContext.put("priorityOrderItemSeqId", orderItem.getString("orderItemSeqId")); } - resultService = dispatcher.runSync("balanceInventoryItems", serviceContext); + serviceResult = dispatcher.runSync("balanceInventoryItems", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException exc) { return ServiceUtil.returnError(exc.getMessage()); } catch (Exception exc) { @@ -1829,7 +1994,10 @@ public class ProductionRunServices { serviceContext.put("actualCompletionDate", UtilDateTime.nowTimestamp()); serviceContext.put("userLogin", userLogin); try { - dispatcher.runSync("updateWorkEffort", serviceContext); + Map<String, Object> serviceResult = dispatcher.runSync("updateWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the updateWorkEffort service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); @@ -1885,9 +2053,9 @@ public class ProductionRunServices { serviceContext.put("issueRequiredComponents", Boolean.TRUE); serviceContext.put("componentsLocationMap", componentsLocationMap); serviceContext.put("userLogin", userLogin); - Map<String, Object> resultService = dispatcher.runSync("updateProductionRunTask", serviceContext); - if (ServiceUtil.isError(resultService)) { - return ServiceUtil.returnError(ServiceUtil.getErrorMessage(resultService)); + Map<String, Object> serviceResult = dispatcher.runSync("updateProductionRunTask", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the changeProductionRunTaskStatus service", module); @@ -1901,6 +2069,9 @@ public class ProductionRunServices { inputMap.putAll(context); inputMap.remove("componentsLocationMap"); result = dispatcher.runSync("productionRunProduce", inputMap); + if (ServiceUtil.isError(result)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the changeProductionRunTaskStatus service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); @@ -1957,26 +2128,38 @@ public class ProductionRunServices { serviceContext.put("uomId", uomId); serviceContext.put("userLogin", userLogin); serviceContext.put("isReturned", isReturned); - Map<String, Object> resultService = dispatcher.runSync("createInventoryItem", serviceContext); - String inventoryItemId = (String)resultService.get("inventoryItemId"); + Map<String, Object> serviceResult = dispatcher.runSync("createInventoryItem", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } + String inventoryItemId = (String)serviceResult.get("inventoryItemId"); serviceContext.clear(); serviceContext.put("inventoryItemId", inventoryItemId); serviceContext.put("workEffortId", productionRunTaskId); serviceContext.put("availableToPromiseDiff", BigDecimal.ONE); serviceContext.put("quantityOnHandDiff", BigDecimal.ONE); serviceContext.put("userLogin", userLogin); - resultService = dispatcher.runSync("createInventoryItemDetail", serviceContext); + serviceResult = dispatcher.runSync("createInventoryItemDetail", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } serviceContext.clear(); serviceContext.put("userLogin", userLogin); serviceContext.put("workEffortId", productionRunTaskId); serviceContext.put("inventoryItemId", inventoryItemId); - resultService = dispatcher.runSync("createWorkEffortInventoryProduced", serviceContext); + serviceResult = dispatcher.runSync("createWorkEffortInventoryProduced", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } inventoryItemIds.add(inventoryItemId); // Recompute reservations serviceContext = new HashMap<String, Object>(); serviceContext.put("inventoryItemId", inventoryItemId); serviceContext.put("userLogin", userLogin); - resultService = dispatcher.runSync("balanceInventoryItems", serviceContext); + serviceResult = dispatcher.runSync("balanceInventoryItems", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } } catch (GenericServiceException exc) { return ServiceUtil.returnError(exc.getMessage()); @@ -1999,8 +2182,11 @@ public class ProductionRunServices { serviceContext.put("uomId",uomId); serviceContext.put("userLogin", userLogin); serviceContext.put("isReturned", isReturned); - Map<String, Object> resultService = dispatcher.runSync("createInventoryItem", serviceContext); - String inventoryItemId = (String)resultService.get("inventoryItemId"); + Map<String, Object> serviceResult = dispatcher.runSync("createInventoryItem", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } + String inventoryItemId = (String)serviceResult.get("inventoryItemId"); serviceContext.clear(); serviceContext.put("inventoryItemId", inventoryItemId); @@ -2008,18 +2194,27 @@ public class ProductionRunServices { serviceContext.put("availableToPromiseDiff", quantity); serviceContext.put("quantityOnHandDiff", quantity); serviceContext.put("userLogin", userLogin); - resultService = dispatcher.runSync("createInventoryItemDetail", serviceContext); + serviceResult = dispatcher.runSync("createInventoryItemDetail", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } serviceContext.clear(); serviceContext.put("userLogin", userLogin); serviceContext.put("workEffortId", productionRunTaskId); serviceContext.put("inventoryItemId", inventoryItemId); - resultService = dispatcher.runSync("createWorkEffortInventoryProduced", serviceContext); + serviceResult = dispatcher.runSync("createWorkEffortInventoryProduced", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } inventoryItemIds.add(inventoryItemId); // Recompute reservations serviceContext = new HashMap<String, Object>(); serviceContext.put("inventoryItemId", inventoryItemId); serviceContext.put("userLogin", userLogin); - resultService = dispatcher.runSync("balanceInventoryItems", serviceContext); + serviceResult = dispatcher.runSync("balanceInventoryItems", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException exc) { return ServiceUtil.returnError(exc.getMessage()); } catch (Exception exc) { @@ -2213,10 +2408,10 @@ public class ProductionRunServices { serviceContext.put("failIfItemsAreNotAvailable", componentsLocation.get("failIfItemsAreNotAvailable")); } serviceContext.put("userLogin", userLogin); - Map<String, Object> resultService = dispatcher.runSync("issueProductionRunTaskComponent", + Map<String, Object> serviceResult = dispatcher.runSync("issueProductionRunTaskComponent", serviceContext); - if (ServiceUtil.isError(resultService)) { - return ServiceUtil.returnError(ServiceUtil.getErrorMessage(resultService)); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); } } } @@ -2250,7 +2445,10 @@ public class ProductionRunServices { serviceContext.put("quantityProduced", totalQuantityProduced); serviceContext.put("quantityRejected", totalQuantityRejected); serviceContext.put("userLogin", userLogin); - dispatcher.runSync("updateWorkEffort", serviceContext); + Map<String, Object> serviceResult = dispatcher.runSync("updateWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException exc) { return ServiceUtil.returnError(exc.getMessage()); } catch (Exception exc) { @@ -2280,10 +2478,13 @@ public class ProductionRunServices { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingRequirementNotExists", locale)); } try { - dispatcher.runSync("updateRequirement", + Map<String, Object> serviceResult = dispatcher.runSync("updateRequirement", UtilMisc.<String, Object>toMap("requirementId", requirementId, "statusId", "REQ_APPROVED", "requirementTypeId", requirement.getString("requirementTypeId"), "userLogin", userLogin)); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingRequirementNotUpdated", locale)); } @@ -2336,17 +2537,20 @@ public class ProductionRunServices { } serviceContext.put("workEffortName", workEffortName); serviceContext.put("userLogin", userLogin); - Map<String, Object> resultService = null; + Map<String, Object> serviceResult = null; try { - resultService = dispatcher.runSync("createProductionRunsForProductBom", serviceContext); + serviceResult = dispatcher.runSync("createProductionRunsForProductBom", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotCreated", locale) + ": " + ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotCreated", locale) + ": " + e.getMessage()); } - if (ServiceUtil.isError(resultService)) { - return ServiceUtil.returnError(ServiceUtil.getErrorMessage(resultService)); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); } - String productionRunId = (String)resultService.get("productionRunId"); + String productionRunId = (String)serviceResult.get("productionRunId"); result.put("productionRunId", productionRunId); result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "ManufacturingProductionRunCreated",UtilMisc.toMap("productionRunId", productionRunId), locale)); @@ -2395,13 +2599,16 @@ public class ProductionRunServices { serviceContext.put("startDate", UtilDateTime.nowTimestamp()); serviceContext.put("facilityId", facilityId); serviceContext.put("userLogin", userLogin); - Map<String, Object> resultService = null; + Map<String, Object> serviceResult = null; try { - resultService = dispatcher.runSync("createProductionRun", serviceContext); + serviceResult = dispatcher.runSync("createProductionRun", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotCreated", locale)); + } } catch (GenericServiceException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotCreated", locale)); } - String productionRunId = (String)resultService.get("productionRunId"); + String productionRunId = (String)serviceResult.get("productionRunId"); result.put("productionRunId", productionRunId); Map<String, BigDecimal> components = new HashMap<String, BigDecimal>(); @@ -2445,11 +2652,14 @@ public class ProductionRunServices { serviceContext.put("startDate", UtilDateTime.nowTimestamp()); serviceContext.put("facilityId", facilityId); serviceContext.put("userLogin", userLogin); - resultService = null; + serviceResult = null; try { - resultService = dispatcher.runSync("createProductionRunsForProductBom", serviceContext); + serviceResult = dispatcher.runSync("createProductionRunsForProductBom", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } GenericValue workEffortPreDecessor = delegator.makeValue("WorkEffortAssoc", UtilMisc.toMap( - "workEffortIdTo", productionRunId, "workEffortIdFrom", resultService.get("productionRunId"), + "workEffortIdTo", productionRunId, "workEffortIdFrom", serviceResult.get("productionRunId"), "workEffortAssocTypeId", "WORK_EFF_PRECEDENCY", "fromDate", UtilDateTime.nowTimestamp())); workEffortPreDecessor.create(); } catch (GenericServiceException e) { @@ -2465,7 +2675,7 @@ public class ProductionRunServices { // create production run notes from comments String comments = co.getComments(); if (UtilValidate.isNotEmpty(comments)) { - resultService.clear(); + serviceResult.clear(); serviceContext.clear(); serviceContext.put("workEffortId", productionRunId); serviceContext.put("internalNote", "Y"); @@ -2474,7 +2684,10 @@ public class ProductionRunServices { serviceContext.put("userLogin", userLogin); serviceContext.put("noteParty", userLogin.getString("partyId")); try { - resultService = dispatcher.runSync("createWorkEffortNote", serviceContext); + serviceResult = dispatcher.runSync("createWorkEffortNote", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException e) { Debug.logWarning(e.getMessage(), module); return ServiceUtil.returnError(e.getMessage()); @@ -2489,14 +2702,17 @@ public class ProductionRunServices { if (componentQuantity == null) { componentQuantity = BigDecimal.ONE; } - resultService = null; + serviceResult = null; serviceContext = new HashMap<String, Object>(); serviceContext.put("productionRunId", productionRunId); serviceContext.put("productId", productId); serviceContext.put("estimatedQuantity", componentQuantity); serviceContext.put("userLogin", userLogin); try { - resultService = dispatcher.runSync("addProductionRunComponent", serviceContext); + serviceResult = dispatcher.runSync("addProductionRunComponent", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotCreated", locale)); + } } catch (GenericServiceException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotCreated", locale)); } @@ -2555,6 +2771,9 @@ public class ProductionRunServices { Map<String, Object> tmpResults = dispatcher.runSync("getInventoryAvailableByFacility", UtilMisc.<String, Object>toMap("productId", orderItem.getString("productId"), "facilityId", facilityId, "userLogin", userLogin)); + if (ServiceUtil.isError(tmpResults)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(tmpResults)); + } if (tmpResults.get("availableToPromiseTotal") != null) { existingAtp = (BigDecimal) tmpResults.get("availableToPromiseTotal"); } @@ -2573,8 +2792,11 @@ public class ProductionRunServices { serviceContext.put("productId", orderItem.getString("productId")); serviceContext.put("facilityId", facilityId); serviceContext.put("userLogin", userLogin); - Map<String, Object> resultService = dispatcher.runSync("getMktgPackagesAvailable", serviceContext); - BigDecimal mktgPackagesAvailable = (BigDecimal) resultService.get("availableToPromiseTotal"); + Map<String, Object> serviceResult = dispatcher.runSync("getMktgPackagesAvailable", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } + BigDecimal mktgPackagesAvailable = (BigDecimal) serviceResult.get("availableToPromiseTotal"); BigDecimal qtyToProduce = qtyRequired.min(mktgPackagesAvailable); @@ -2583,9 +2805,11 @@ public class ProductionRunServices { serviceContext.put("pRQuantity", qtyToProduce); serviceContext.put("startDate", UtilDateTime.nowTimestamp()); - resultService = dispatcher.runSync("createProductionRun", serviceContext); - - String productionRunId = (String)resultService.get("productionRunId"); + serviceResult = dispatcher.runSync("createProductionRun", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } + String productionRunId = (String)serviceResult.get("productionRunId"); result.put("productionRunId", productionRunId); try { @@ -2599,11 +2823,17 @@ public class ProductionRunServices { serviceContext.put("productionRunId", productionRunId); serviceContext.put("statusId", "PRUN_COMPLETED"); serviceContext.put("userLogin", userLogin); - resultService = dispatcher.runSync("quickChangeProductionRunStatus", serviceContext); + serviceResult = dispatcher.runSync("quickChangeProductionRunStatus", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } serviceContext.clear(); serviceContext.put("workEffortId", productionRunId); serviceContext.put("userLogin", userLogin); - resultService = dispatcher.runSync("productionRunProduce", serviceContext); + serviceResult = dispatcher.runSync("productionRunProduce", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotCreated", locale)); } @@ -2804,7 +3034,7 @@ public class ProductionRunServices { try { Map<String, Object> serviceContext = new HashMap<String, Object>(); - Map<String, Object> resultService = null; + Map<String, Object> serviceResult = null; GenericValue task = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", taskId).queryOne(); String currentStatusId = task.getString("currentStatusId"); String prevStatusId = ""; @@ -2813,8 +3043,11 @@ public class ProductionRunServices { serviceContext.put("workEffortId", taskId); serviceContext.put("issueAllComponents", Boolean.TRUE); serviceContext.put("userLogin", userLogin); - resultService = dispatcher.runSync("changeProductionRunTaskStatus", serviceContext); - currentStatusId = (String)resultService.get("newStatusId"); + serviceResult = dispatcher.runSync("changeProductionRunTaskStatus", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } + currentStatusId = (String)serviceResult.get("newStatusId"); if (currentStatusId.equals(prevStatusId)) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunUnableToProgressTaskStatus", UtilMisc.toMap("prevStatusId", prevStatusId, "taskId", taskId), locale)); } else { @@ -2866,7 +3099,10 @@ public class ProductionRunServices { serviceContext.put("productionRunId", productionRunId); serviceContext.put("taskId", taskId); serviceContext.put("userLogin", userLogin); - dispatcher.runSync("quickRunProductionRunTask", serviceContext); + Map<String, Object> serviceResult = dispatcher.runSync("quickRunProductionRunTask", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the quickRunProductionRunTask service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); @@ -2903,7 +3139,10 @@ public class ProductionRunServices { serviceContext.put("statusId", "PRUN_RUNNING"); serviceContext.put("issueAllComponents", Boolean.FALSE); serviceContext.put("userLogin", userLogin); - dispatcher.runSync("changeProductionRunTaskStatus", serviceContext); + Map<String, Object> serviceResult = dispatcher.runSync("changeProductionRunTaskStatus", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the changeProductionRunTaskStatus service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunStatusNotChanged", locale)); @@ -2925,7 +3164,7 @@ public class ProductionRunServices { LocalDispatcher dispatcher = ctx.getDispatcher(); Locale locale = (Locale) context.get("locale"); GenericValue userLogin = (GenericValue) context.get("userLogin"); - + Map<String, Object> serviceResult = new HashMap<String, Object>(); String productionRunId = (String) context.get("productionRunId"); String statusId = (String) context.get("statusId"); String startAllTasks = (String) context.get("startAllTasks"); @@ -2941,37 +3180,55 @@ public class ProductionRunServices { serviceContext.put("productionRunId", productionRunId); serviceContext.put("statusId", "PRUN_DOC_PRINTED"); serviceContext.put("userLogin", userLogin); - dispatcher.runSync("changeProductionRunStatus", serviceContext); + serviceResult = dispatcher.runSync("changeProductionRunStatus", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } if ("PRUN_RUNNING".equals(statusId) && "Y".equals(startAllTasks)) { serviceContext.clear(); serviceContext.put("productionRunId", productionRunId); serviceContext.put("userLogin", userLogin); - dispatcher.runSync("quickStartAllProductionRunTasks", serviceContext); + serviceResult = dispatcher.runSync("quickStartAllProductionRunTasks", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } if ("PRUN_COMPLETED".equals(statusId) || "PRUN_CLOSED".equals(statusId)) { serviceContext.clear(); serviceContext.put("productionRunId", productionRunId); serviceContext.put("userLogin", userLogin); - dispatcher.runSync("quickRunAllProductionRunTasks", serviceContext); + serviceResult = dispatcher.runSync("quickRunAllProductionRunTasks", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } if ("PRUN_CLOSED".equals(statusId)) { // Put in warehouse the products manufactured serviceContext.clear(); serviceContext.put("workEffortId", productionRunId); serviceContext.put("userLogin", userLogin); - dispatcher.runSync("productionRunProduce", serviceContext); + serviceResult = dispatcher.runSync("productionRunProduce", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } serviceContext.clear(); serviceContext.put("productionRunId", productionRunId); serviceContext.put("statusId", "PRUN_CLOSED"); serviceContext.put("userLogin", userLogin); - dispatcher.runSync("changeProductionRunStatus", serviceContext); + serviceResult = dispatcher.runSync("changeProductionRunStatus", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } else { serviceContext.put("productionRunId", productionRunId); serviceContext.put("statusId", statusId); serviceContext.put("userLogin", userLogin); - dispatcher.runSync("changeProductionRunStatus", serviceContext); + serviceResult = dispatcher.runSync("changeProductionRunStatus", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } } catch (GenericServiceException e) { Debug.logError(e, "Problem calling the changeProductionRunStatus service", module); @@ -3038,6 +3295,7 @@ public class ProductionRunServices { GenericValue userLogin = (GenericValue) context.get("userLogin"); String inventoryItemId = (String)context.get("inventoryItemId"); Locale locale = (Locale) context.get("locale"); + Map<String, Object> serviceResult = new HashMap<String, Object>(); try { GenericValue inventoryItem = EntityQuery.use(delegator).from("InventoryItem").where("inventoryItemId", inventoryItemId).queryOne(); if (inventoryItem == null) { @@ -3053,7 +3311,10 @@ public class ProductionRunServices { if (EntityTypeUtil.hasParentType(delegator, "ProductType", "productTypeId", product.getString("productTypeId"), "parentTypeId", "MARKETING_PKG_AUTO")) { Map<String, Object> serviceContext = UtilMisc.toMap("inventoryItemId", inventoryItemId, "userLogin", userLogin); - dispatcher.runSync("decomposeInventoryItem", serviceContext); + serviceResult = dispatcher.runSync("decomposeInventoryItem", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } } } catch (GenericEntityException e) { Debug.logError(e, "Problem accessing the InventoryItem entity", module); @@ -3093,8 +3354,11 @@ public class ProductionRunServices { serviceContext.put("facilityId", inventoryItem.getString("facilityId")); serviceContext.put("estimatedStartDate", now); serviceContext.put("userLogin", userLogin); - Map<String, Object> resultService = dispatcher.runSync("createWorkEffort", serviceContext); - String workEffortId = (String)resultService.get("workEffortId"); + Map<String, Object> serviceResult = dispatcher.runSync("createWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } + String workEffortId = (String)serviceResult.get("workEffortId"); // the inventory (marketing package) is issued serviceContext.clear(); serviceContext = UtilMisc.toMap("inventoryItem", inventoryItem, @@ -3102,8 +3366,11 @@ public class ProductionRunServices { if (quantity != null) { serviceContext.put("quantity", quantity); } - resultService = dispatcher.runSync("issueInventoryItemToWorkEffort", serviceContext); - BigDecimal issuedQuantity = (BigDecimal)resultService.get("quantityIssued"); + serviceResult = dispatcher.runSync("issueInventoryItemToWorkEffort", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } + BigDecimal issuedQuantity = (BigDecimal)serviceResult.get("quantityIssued"); if (issuedQuantity.compareTo(ZERO) == 0) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunCannotDecomposingInventoryItemNoMarketingPackagesFound", UtilMisc.toMap("inventoryItemId", inventoryItem.getString("inventoryItemId")), locale)); } @@ -3114,8 +3381,11 @@ public class ProductionRunServices { "currencyUomId", inventoryItem.getString("currencyUomId"), "costComponentTypePrefix", "EST_STD", "userLogin", userLogin); - resultService = dispatcher.runSync("getProductCost", serviceContext); - BigDecimal packageCost = (BigDecimal)resultService.get("productCost"); + serviceResult = dispatcher.runSync("getProductCost", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } + BigDecimal packageCost = (BigDecimal)serviceResult.get("productCost"); BigDecimal inventoryItemCost = inventoryItem.getBigDecimal("unitCost"); BigDecimal costCoefficient = null; if (packageCost == null || packageCost.compareTo(ZERO) == 0 || inventoryItemCost == null) { @@ -3134,8 +3404,11 @@ public class ProductionRunServices { serviceContext = UtilMisc.toMap("productId", inventoryItem.getString("productId"), "quantity", issuedQuantity, "userLogin", userLogin); - resultService = dispatcher.runSync("getManufacturingComponents", serviceContext); - List<Map<String, Object>> components = UtilGenerics.checkList(resultService.get("componentsMap")); + serviceResult = dispatcher.runSync("getManufacturingComponents", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } + List<Map<String, Object>> components = UtilGenerics.checkList(serviceResult.get("componentsMap")); if (UtilValidate.isEmpty(components)) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunCannotDecomposingInventoryItemNoComponentsFound", UtilMisc.toMap("productId", inventoryItem.getString("productId")), locale)); } @@ -3146,8 +3419,11 @@ public class ProductionRunServices { "currencyUomId", inventoryItem.getString("currencyUomId"), "costComponentTypePrefix", "EST_STD", "userLogin", userLogin); - resultService = dispatcher.runSync("getProductCost", serviceContext); - BigDecimal componentCost = (BigDecimal)resultService.get("productCost"); + serviceResult = dispatcher.runSync("getProductCost", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } + BigDecimal componentCost = (BigDecimal)serviceResult.get("productCost"); // return the component to inventory at its standard cost multiplied by the cost coefficient from above BigDecimal componentInventoryItemCost = costCoefficient.multiply(componentCost); @@ -3158,8 +3434,11 @@ public class ProductionRunServices { "unitCost", componentInventoryItemCost, "userLogin", userLogin); serviceContext.put("workEffortId", workEffortId); - resultService = dispatcher.runSync("productionRunTaskProduce", serviceContext); - List<String> newInventoryItemIds = UtilGenerics.checkList(resultService.get("inventoryItemIds")); + serviceResult = dispatcher.runSync("productionRunTaskProduce", serviceContext); + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } + List<String> newInventoryItemIds = UtilGenerics.checkList(serviceResult.get("inventoryItemIds")); inventoryItemIds.addAll(newInventoryItemIds); } // the components are put in warehouse |
Free forum by Nabble | Edit this page |