📄 wfactivityimpl.java
字号:
// create a new assignment private WfAssignment assign(WfResource resource, boolean append) throws WfException { if (!append) { Iterator ai = getIteratorAssignment(); while (ai.hasNext()) { WfAssignment a = (WfAssignment) ai.next(); a.remove(); } } WfAssignment assign = WfFactory.getWfAssignment(this, resource, null, true); return assign; } // check the performer: dynamic; defined partyId/roleTypeId private GenericValue checkPerformer(GenericValue performer) throws WfException { GenericValue newPerformer = GenericValue.create(performer); Map context = processContext(); String performerType = performer.getString("participantTypeId"); String partyId = performer.getString("partyId"); String roleTypeId = performer.getString("roleTypeId"); // check for dynamic party if (partyId != null && partyId.trim().toLowerCase().startsWith("expr:")) { if (Debug.verboseOn()) Debug.logVerbose("Dynamic performer: Found a party expression", module); Object value = null; try { value = BshUtil.eval(partyId.trim().substring(5).trim(), context); } catch (bsh.EvalError e) { throw new WfException("Bsh evaluation error occurred.", e); } if (value != null) { if (value instanceof String) { newPerformer.set("partyId", value); } else { throw new WfException("Expression did not return a String"); } } } // check for dynamic role if (roleTypeId != null && roleTypeId.trim().toLowerCase().startsWith("expr:")) { if (Debug.verboseOn()) Debug.logVerbose("Dynamic performer: Found a role expression", module); Object value = null; try { value = BshUtil.eval(roleTypeId.trim().substring(5).trim(), context); } catch (bsh.EvalError e) { throw new WfException("Bsh evaluation error occurred.", e); } if (value != null) { if (value instanceof String) { newPerformer.set("roleTypeId", value); } else { throw new WfException("Expression did not return a String"); } } } // check for un-defined party if (performerType.equals("HUMAN") || performerType.equals("ORGANIZATIONAL_UNIT")) { if (partyId == null) { newPerformer.set("partyId", performer.getString("participantId")); } } // check for un-defined role if (performerType.equals("ROLE")) { if (roleTypeId == null) { newPerformer.set("roleTypeId", performer.getString("participantId")); } } return newPerformer; } /** * @see org.ofbiz.workflow.WfActivity#activate() */ public void activate() throws WfException, CannotStart, AlreadyRunning { // make sure we aren't already running if (this.state().equals("open.running")) throw new AlreadyRunning(); // check the start mode String mode = getDefinitionObject().getString("startModeEnumId"); if (mode == null) { throw new WfException("Start mode cannot be null"); } if (mode.equals("WAM_AUTOMATIC")) { Debug.logVerbose("Activity start mode is AUTO", module); Iterator i = getIteratorAssignment(); while (i.hasNext()) ((WfAssignment) i.next()).changeStatus("CAL_ACCEPTED"); // accept all assignments (AUTO) Debug.logVerbose("All assignments accepted, starting activity: " + this.runtimeKey(), module); startActivity(); } else if (howManyAssignment() > 0 && checkAssignStatus(CHECK_ASSIGN)) { Debug.logVerbose("Starting activity: " + this.runtimeKey(), module); startActivity(); } } /** * @see org.ofbiz.workflow.WfActivity#complete() */ public void complete() throws WfException, CannotComplete { // check to make sure all assignements are complete if (howManyAssignment() > 0 && !checkAssignStatus(CHECK_COMPLETE)) throw new CannotComplete("All assignments have not been completed"); try { container().receiveResults(this, result()); } catch (InvalidData e) { throw new WfException("Invalid result data was passed", e); } try { changeState("closed.completed"); GenericValue activityWe = getRuntimeObject(); activityWe.set("actualCompletionDate", UtilDateTime.nowTimestamp()); activityWe.store(); } catch (InvalidState is) { throw new WfException("Invalid WF State", is); } catch (TransitionNotAllowed tna) { throw new WfException(tna.getMessage(), tna); } catch (GenericEntityException gee) { throw new WfException(gee.getMessage(), gee); } container().activityComplete(this); } /** * @see org.ofbiz.workflow.WfExecutionObject#resume() */ public void resume() throws WfException, CannotResume, NotRunning, NotSuspended { super.resume(); try { Debug.logVerbose("Checking to see if we can complete the activity", module); this.checkComplete(); } catch (CannotComplete e) { throw new CannotResume("Attempt to complete activity failed", e); } } /** * @see org.ofbiz.workflow.WfExecutionObject#abort() */ public void abort() throws WfException, CannotStop, NotRunning { super.abort(); // cancel the active assignments Iterator assignments = this.getAssignments().iterator(); while (assignments.hasNext()) { WfAssignment assignment = (WfAssignment) assignments.next(); assignment.changeStatus("CAL_CANCELLED"); } } /** * @see org.ofbiz.workflow.WfActivity#isMemberOfAssignment(org.ofbiz.workflow.WfAssignment) */ public boolean isMemberOfAssignment(WfAssignment member) throws WfException { return getAssignments().contains(member); } /** * @see org.ofbiz.workflow.WfActivity#container() */ public WfProcess container() throws WfException { return WfFactory.getWfProcess(delegator, processId); } /** * @see org.ofbiz.workflow.WfActivity#setResult(java.util.Map) */ public void setResult(Map newResult) throws WfException, InvalidData { if (newResult != null && newResult.size() > 0) { if (Debug.verboseOn()) Debug.logVerbose( "[WfActivity.setResult]: putting (" + newResult.size() + ") keys into context.", module); Map context = processContext(); context.putAll(newResult); setSerializedData(context); } } /** * @see org.ofbiz.workflow.WfActivity#howManyAssignment() */ public int howManyAssignment() throws WfException { return getAssignments().size(); } /** * @see org.ofbiz.workflow.WfActivity#result() */ public Map result() throws WfException, ResultNotAvailable { // Get the results from the signature. Map resultSig = container().manager().resultSignature(); Map results = new HashMap(); Map context = processContext(); if (resultSig != null) { Set resultKeys = resultSig.keySet(); Iterator i = resultKeys.iterator(); while (i.hasNext()) { Object key = i.next(); if (context.containsKey(key)) results.put(key, context.get(key)); } } return results; } /** * @see org.ofbiz.workflow.WfActivity#getSequenceAssignment(int) */ public List getSequenceAssignment(int maxNumber) throws WfException { if (maxNumber > 0) return getAssignments().subList(0, (maxNumber - 1)); return getAssignments(); } /** * @see org.ofbiz.workflow.WfActivity#getIteratorAssignment() */ public Iterator getIteratorAssignment() throws WfException { return getAssignments().iterator(); } /** * @see org.ofbiz.workflow.impl.WfExecutionObjectImpl#executionObjectType() */ public String executionObjectType() { return "WfActivity"; } // Checks to see if we can complete private void checkComplete() throws WfException, CannotComplete { String mode = getDefinitionObject().getString("finishModeEnumId"); if (mode == null) throw new CannotComplete("Finish mode cannot be null"); // Default mode is MANUAL -- only finish if we are automatic if (mode.equals("WAM_AUTOMATIC")) { // check and make sure we are not suspended if (state().equals("open.running")) { // set the status of the assignments Iterator i = getIteratorAssignment(); while (i.hasNext()) ((WfAssignment) i.next()).changeStatus("CAL_COMPLETED"); this.complete(); } } } // Checks the staus of all assignments // type 1 -> accept status // type 2 -> complete status private boolean checkAssignStatus(int type) throws WfException { boolean acceptAll = false; boolean completeAll = false; GenericValue valueObject = getDefinitionObject(); if (valueObject.get("acceptAllAssignments") != null) acceptAll = valueObject.getBoolean("acceptAllAssignments").booleanValue(); if (valueObject.get("completeAllAssignments") != null) completeAll = valueObject.getBoolean("completeAllAssignments").booleanValue(); List validStatus = null; if (type == CHECK_ASSIGN) validStatus = UtilMisc.toList("CAL_ACCEPTED", "CAL_COMPLETED", "CAL_DELEGATED"); else if (type == CHECK_COMPLETE)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -