try {
TransactionUtil.rollback(beganTransaction, "Error getting Workflow Requester", e);
} catch (GenericTransactionException gte) {
Debug.logError(gte, "Unable to rollback nested exception.", module);
}
throw new GenericServiceException(e.getMessage(), e);
}
// Get the package and process ID::VERSION
String location = this.getLocation(modelService);
String invoke = modelService.invoke;
String packageId = this.getSplitPosition(location, 0);
String packageVersion = this.getSplitPosition(location, 1);
String processId = this.getSplitPosition(invoke, 0);
String processVersion = this.getSplitPosition(invoke, 1);
// Build the process manager
WfProcessMgr mgr = null;
try {
mgr = WfFactory.getWfProcessMgr(dispatcher.getDelegator(), packageId, packageVersion, processId, processVersion);
} catch (WfException e) {
String errMsg = "Process manager error";
Debug.logError(e, errMsg, module);
try {
TransactionUtil.rollback(beganTransaction, errMsg, e);
} catch (GenericTransactionException gte) {
Debug.logError(gte, "Unable to rollback nested exception.", module);
}
throw new GenericServiceException(e.getMessage(), e);
} catch (Exception e) {
Debug.logError(e, "Un-handled process manager error", module);
throw new GenericServiceException(e.getMessage(), e);
}
// Create the process
WfProcess process = null;
try {
process = mgr.createProcess(req);
} catch (NotEnabled ne) {
try {
TransactionUtil.rollback(beganTransaction, "Error in create workflow process: Not Enabled", ne);
} catch (GenericTransactionException gte) {
Debug.logError(gte, "Unable to rollback nested exception.", module);
}
throw new GenericServiceException(ne.getMessage(), ne);
} catch (InvalidRequester ir) {
try {
TransactionUtil.rollback(beganTransaction, "Error in create workflow process: Invalid Requester", ir);
} catch (GenericTransactionException gte) {
Debug.logError(gte, "Unable to rollback nested exception.", module);
}
throw new GenericServiceException(ir.getMessage(), ir);
} catch (RequesterRequired rr) {
try {
TransactionUtil.rollback(beganTransaction, "Error in create workflow process: Requester Required", rr);
} catch (GenericTransactionException gte) {
Debug.logError(gte, "Unable to rollback nested exception.", module);
}
throw new GenericServiceException(rr.getMessage(), rr);
} catch (WfException wfe) {
try {
TransactionUtil.rollback(beganTransaction, "Error in create workflow process: general workflow error error", wfe);
} catch (GenericTransactionException gte) {
Debug.logError(gte, "Unable to rollback nested exception.", module);
}
throw new GenericServiceException(wfe.getMessage(), wfe);
} catch (Exception e) {
Debug.logError(e, "Un-handled process exception", module);
throw new GenericServiceException(e.getMessage(), e);
}
// Assign the owner of the process
GenericValue userLogin = null;
if (context.containsKey("userLogin")) {
userLogin = (GenericValue) context.remove("userLogin");
try {
Map fields = UtilMisc.toMap("partyId", userLogin.getString("partyId"),
"roleTypeId", "WF_OWNER", "workEffortId", process.runtimeKey(),
"fromDate", UtilDateTime.nowTimestamp());
try {
GenericValue wepa = dispatcher.getDelegator().makeValue("WorkEffortPartyAssignment", fields);
dispatcher.getDelegator().create(wepa);
} catch (GenericEntityException e) {
String errMsg = "Cannot set ownership of workflow";
try {
TransactionUtil.rollback(beganTransaction, errMsg, e);
} catch (GenericTransactionException gte) {
Debug.logError(gte, "Unable to rollback nested exception.", module);
}
throw new GenericServiceException(errMsg, e);
}
} catch (WfException we) {
String errMsg = "Cannot get the workflow process runtime key";
try {
TransactionUtil.rollback(beganTransaction, errMsg, we);
} catch (GenericTransactionException gte) {
Debug.logError(gte, "Unable to rollback nested exception.", module);
}
throw new GenericServiceException(errMsg);
}
}
// Grab the locale from the context
Locale locale = (Locale) context.remove("locale");
// Grab the starting activityId from the context
String startActivityId = (String) context.remove("startWithActivityId");
// Register the process and set the workflow owner
try {
req.registerProcess(process, context, requester);
if (userLogin != null) {
Map pContext = process.processContext();
pContext.put("workflowOwnerId", userLogin.getString("userLoginId"));
process.setProcessContext(pContext);
}
} catch (WfException wfe) {
try {
TransactionUtil.rollback(beganTransaction, wfe.getMessage(), wfe);
} catch (GenericTransactionException gte) {
Debug.logError(gte, "Unable to rollback nested exception.", module);
}
throw new GenericServiceException(wfe.getMessage(), wfe);
}
// Set the initial locale - (in context)
if (locale != null) {
try {
Map pContext = process.processContext();
pContext.put("initialLocale", locale);
process.setProcessContext(pContext);
} catch (WfException wfe) {
try {
TransactionUtil.rollback(beganTransaction, wfe.getMessage(), wfe);
} catch (GenericTransactionException gte) {
Debug.logError(gte, "Unable to rollback nested exception.", module);
}
throw new GenericServiceException(wfe.getMessage(), wfe);
}
}
// Use the WorkflowRunner to start the workflow in a new thread
try {
Job job = new WorkflowRunner(process, requester, startActivityId);
if (Debug.verboseOn()) Debug.logVerbose("Created WorkflowRunner: " + job, module);
dispatcher.getJobManager().runJob(job);
} catch (JobManagerException je) {
try {
TransactionUtil.rollback(beganTransaction, je.getMessage(), je);
} catch (GenericTransactionException gte) {
Debug.logError(gte, "Unable to rollback nested exception.", module);
}
throw new GenericServiceException(je.getMessage(), je);
}
try {
TransactionUtil.commit(beganTransaction);
} catch (GenericTransactionException e) {
Debug.logError(e, "Cannot commit nested transaction: " + e.getMessage(), module);
}
} finally {
// Resume the parent transaction
if (parentTrans != null) {
try {
TransactionUtil.resume(parentTrans);
//Debug.logInfo("Resumed the parent transaction.", module);
} catch (GenericTransactionException e) {
throw new GenericServiceException("Could not resume transaction: " + e.toString(), e);
}
}
}
}