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("Operation not yet implemented");
}
if (!config.isCompleted()) {
return ServiceUtil.returnError("ProductConfigurationNotValid");
}
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 serviceContext = new HashMap();
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 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);
Iterator options = config.getSelectedOptions().iterator();
HashMap components = new HashMap();
while (options.hasNext()) {
ConfigOption co = (ConfigOption)options.next();
//components.addAll(co.getComponents());
Iterator selComponents = co.getComponents().iterator();