📄 workflowengine.java
字号:
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 { tm.resume(parentTrans); //Debug.logInfo("Resumed the parent transaction.", module); } catch (InvalidTransactionException ite) { throw new GenericServiceException("Cannot resume transaction", ite); } catch (SystemException se) { throw new GenericServiceException("Unexpected transaction error", se); } } } } private String getSplitPosition(String splitString, int position) { if (splitString.indexOf("::") == -1) { if (position == 0) return splitString; if (position == 1) return null; } List splitList = StringUtil.split(splitString, "::"); return (String) splitList.get(position); }}/** Workflow Runner class runs inside its own thread using the Scheduler API */class WorkflowRunner extends AbstractJob { GenericRequester requester; WfProcess process; String startActivityId; WorkflowRunner(WfProcess process, GenericRequester requester, String startActivityId) { super(process.toString() + "." + System.currentTimeMillis(), process.toString()); this.process = process; this.requester = requester; this.startActivityId = startActivityId; runtime = new Date().getTime(); } protected void finish() { runtime = -1; } public void exec() { try { if (startActivityId != null) process.start(startActivityId); else process.start(); } catch (Exception e) { Debug.logError(e, module); if (requester != null) requester.receiveResult(null); } finish(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -