GenericValue userLogin = (GenericValue) context.get("userLogin");
// Mandatory input fields
String facilityId = (String)context.get("facilityId");
// Optional input fields
String configId = (String)context.get("configId");
ProductConfigWrapper config = (ProductConfigWrapper)context.get("config");
BigDecimal quantity = (BigDecimal)context.get("quantity");
String orderId = (String)context.get("orderId");
String orderItemSeqId = (String)context.get("orderItemSeqId");
if (config == null && configId == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingConfigurationNotAvailable", locale));
}
if (config == null && configId != null) {
// TODO: load the configuration
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunFromConfigurationNotYetImplemented", locale));
}
if (!config.isCompleted()) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunFromConfigurationNotValid", locale));
}
if (quantity == null) {
quantity = BigDecimal.ONE;
}
String instanceProductId = null;
try {
instanceProductId = ProductWorker.getAggregatedInstanceId(delegator, config.getProduct().getString("productId"), config.getConfigId());
} catch (Exception e) {
return ServiceUtil.returnError(e.getMessage());
}
Map<String, Object> serviceContext = FastMap.newInstance();
serviceContext.clear();
serviceContext.put("productId", instanceProductId);
serviceContext.put("pRQuantity", quantity);
serviceContext.put("startDate", UtilDateTime.nowTimestamp());
serviceContext.put("facilityId", facilityId);
//serviceContext.put("workEffortName", "");
serviceContext.put("userLogin", userLogin);
Map<String, Object> resultService = null;
try {
resultService = dispatcher.runSync("createProductionRun", serviceContext);
} catch (GenericServiceException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotCreated", locale));
}
String productionRunId = (String)resultService.get("productionRunId");
result.put("productionRunId", productionRunId);
Map<String, BigDecimal> components = FastMap.newInstance();
for(ConfigOption co : config.getSelectedOptions()) {
//components.addAll(co.getComponents());
for(GenericValue selComponent : co.getComponents()) {
BigDecimal componentQuantity = null;
if (selComponent.get("quantity") != null) {
componentQuantity = selComponent.getBigDecimal("quantity");