📄 abstractworkflow.java
字号:
} public int getState() { return WorkflowEntry.CREATED; } }; // since no state change happens here, a memory instance is just fine PropertySet ps = PropertySetManager.getInstance("memory", null); Map transientVars = new HashMap(); if (inputs != null) { transientVars.putAll(inputs); } try { populateTransientMap(mockEntry, transientVars, Collections.EMPTY_LIST, new Integer(initialAction), Collections.EMPTY_LIST, ps); return canInitialize(workflowName, initialAction, transientVars, ps); } catch (InvalidActionException e) { log.error(e.getMessage()); return false; } catch (WorkflowException e) { log.error("Error checking canInitialize", e); return false; } } /** * @ejb.interface-method */ public boolean canModifyEntryState(long id, int newState) { try { WorkflowStore store = getPersistence(); WorkflowEntry entry = store.findEntry(id); int currentState = entry.getState(); boolean result = false; switch (newState) { case WorkflowEntry.COMPLETED: if (currentState == WorkflowEntry.ACTIVATED) { result = true; } break; case WorkflowEntry.CREATED: result = false; case WorkflowEntry.ACTIVATED: if ((currentState == WorkflowEntry.CREATED) || (currentState == WorkflowEntry.SUSPENDED)) { result = true; } break; case WorkflowEntry.SUSPENDED: if (currentState == WorkflowEntry.ACTIVATED) { result = true; } break; case WorkflowEntry.KILLED: if ((currentState == WorkflowEntry.CREATED) || (currentState == WorkflowEntry.ACTIVATED) || (currentState == WorkflowEntry.SUSPENDED)) { result = true; } break; default: result = false; break; } return result; } catch (StoreException e) { log.error("Error checking state modifiable for instance #" + id, e); } return false; } public void changeEntryState(long id, int newState) throws WorkflowException { WorkflowStore store = getPersistence(); WorkflowEntry entry = store.findEntry(id); if (entry.getState() == newState) { return; } if (canModifyEntryState(id, newState)) { if ((newState == WorkflowEntry.KILLED) || (newState == WorkflowEntry.COMPLETED)) { Collection currentSteps = getCurrentSteps(id); if (currentSteps.size() > 0) { completeEntry(null, id, currentSteps, newState); } } store.setEntryState(id, newState); } else { throw new InvalidEntryStateException("Can't transition workflow instance #" + id + ". Current state is " + entry.getState() + ", requested state is " + newState); } if (log.isDebugEnabled()) { log.debug(entry.getId() + " : State is now : " + entry.getState()); } } public void doAction(long id, int actionId, Map inputs) throws WorkflowException { WorkflowStore store = getPersistence(); WorkflowEntry entry = store.findEntry(id); if (entry.getState() != WorkflowEntry.ACTIVATED) { return; } WorkflowDescriptor wf = getConfiguration().getWorkflow(entry.getWorkflowName()); List currentSteps = store.findCurrentSteps(id); ActionDescriptor action = null; PropertySet ps = store.getPropertySet(id); Map transientVars = new HashMap(); if (inputs != null) { transientVars.putAll(inputs); } populateTransientMap(entry, transientVars, wf.getRegisters(), new Integer(actionId), currentSteps, ps); boolean validAction = false; //check global actions for (Iterator gIter = wf.getGlobalActions().iterator(); !validAction && gIter.hasNext();) { ActionDescriptor actionDesc = (ActionDescriptor) gIter.next(); if (actionDesc.getId() == actionId) { action = actionDesc; if (isActionAvailable(action, transientVars, ps, 0)) { validAction = true; } } } for (Iterator iter = currentSteps.iterator(); !validAction && iter.hasNext();) { Step step = (Step) iter.next(); StepDescriptor s = wf.getStep(step.getStepId()); for (Iterator iterator = s.getActions().iterator(); !validAction && iterator.hasNext();) { ActionDescriptor actionDesc = (ActionDescriptor) iterator.next(); if (actionDesc.getId() == actionId) { action = actionDesc; if (isActionAvailable(action, transientVars, ps, s.getId())) { validAction = true; } } } } if (!validAction) { throw new InvalidActionException("Action " + actionId + " is invalid"); } try { //transition the workflow, if it wasn't explicitly finished, check for an implicit finish if (!transitionWorkflow(entry, currentSteps, store, wf, action, transientVars, inputs, ps)) { checkImplicitFinish(action, id); } } catch (WorkflowException e) { context.setRollbackOnly(); throw e; } } public void executeTriggerFunction(long id, int triggerId) throws WorkflowException { WorkflowStore store = getPersistence(); WorkflowEntry entry = store.findEntry(id); if (entry == null) { log.warn("Cannot execute trigger #" + triggerId + " on non-existent workflow id#" + id); return; } WorkflowDescriptor wf = getConfiguration().getWorkflow(entry.getWorkflowName()); PropertySet ps = store.getPropertySet(id); Map transientVars = new HashMap(); populateTransientMap(entry, transientVars, wf.getRegisters(), null, store.findCurrentSteps(id), ps); executeFunction(wf.getTriggerFunction(triggerId), transientVars, ps); } public long initialize(String workflowName, int initialAction, Map inputs) throws InvalidRoleException, InvalidInputException, WorkflowException { WorkflowDescriptor wf = getConfiguration().getWorkflow(workflowName); WorkflowStore store = getPersistence(); WorkflowEntry entry = store.createEntry(workflowName); // start with a memory property set, but clone it after we have an ID PropertySet ps = store.getPropertySet(entry.getId()); Map transientVars = new HashMap(); if (inputs != null) { transientVars.putAll(inputs); } populateTransientMap(entry, transientVars, wf.getRegisters(), new Integer(initialAction), Collections.EMPTY_LIST, ps); if (!canInitialize(workflowName, initialAction, transientVars, ps)) { context.setRollbackOnly(); throw new InvalidRoleException("You are restricted from initializing this workflow"); } ActionDescriptor action = wf.getInitialAction(initialAction); try { transitionWorkflow(entry, Collections.EMPTY_LIST, store, wf, action, transientVars, inputs, ps); } catch (WorkflowException e) { context.setRollbackOnly(); throw e; } long entryId = entry.getId(); // now clone the memory PS to the real PS //PropertySetManager.clone(ps, store.getPropertySet(entryId)); return entryId; } /** * @ejb.interface-method */ public List query(WorkflowQuery query) throws StoreException { return getPersistence().query(query); } /** * @ejb.interface-method */ public List query(WorkflowExpressionQuery query) throws WorkflowException { return getPersistence().query(query); } /** * @ejb.interface-method */ public boolean removeWorkflowDescriptor(String workflowName) throws FactoryException { return getConfiguration().removeWorkflow(workflowName); } /** * @ejb.interface-method */ public boolean saveWorkflowDescriptor(String workflowName, WorkflowDescriptor descriptor, boolean replace) throws FactoryException { boolean success = getConfiguration().saveWorkflow(workflowName, descriptor, replace); return success; } protected List getAvailableActionsForStep(WorkflowDescriptor wf, Step step, Map transientVars, PropertySet ps) throws WorkflowException { List l = new ArrayList(); StepDescriptor s = wf.getStep(step.getStepId()); if (s == null) { log.warn("getAvailableActionsForStep called for non-existent step Id #" + step.getStepId()); return l; } List actions = s.getActions(); if ((actions == null) || (actions.size() == 0)) { return l; } for (Iterator iterator2 = actions.iterator(); iterator2.hasNext();) { ActionDescriptor action = (ActionDescriptor) iterator2.next(); RestrictionDescriptor restriction = action.getRestriction(); ConditionsDescriptor conditions = null; transientVars.put("actionId", new Integer(action.getId())); if (restriction != null) { conditions = restriction.getConditionsDescriptor(); } if (passesConditions(wf.getGlobalConditions(), new HashMap(transientVars), ps, s.getId()) && passesConditions(conditions, new HashMap(transientVars), ps, s.getId())) { l.add(new Integer(action.getId())); } } return l; } protected int[] getAvailableAutoActions(long id, Map inputs) { try { WorkflowStore store = getPersistence(); WorkflowEntry entry = store.findEntry(id); if (entry == null) { throw new IllegalArgumentException("No such workflow id " + id); } if (entry.getState() != WorkflowEntry.ACTIVATED) { log.debug("--> state is " + entry.getState()); return new int[0]; } WorkflowDescriptor wf = getConfiguration().getWorkflow(entry.getWorkflowName()); if (wf == null) { throw new IllegalArgumentException("No such workflow " + entry.getWorkflowName()); } List l = new ArrayList(); PropertySet ps = store.getPropertySet(id); Map transientVars = (inputs == null) ? new HashMap() : new HashMap(inputs); Collection currentSteps = store.findCurrentSteps(id); populateTransientMap(entry, transientVars, wf.getRegisters(), new Integer(0), currentSteps, ps); // get global actions List globalActions = wf.getGlobalActions(); for (Iterator iterator = globalActions.iterator(); iterator.hasNext();) { ActionDescriptor action = (ActionDescriptor) iterator.next(); transientVars.put("actionId", new Integer(action.getId())); if (action.getAutoExecute()) { if (isActionAvailable(action, transientVars, ps, 0)) { l.add(new Integer(action.getId())); } } } // get normal actions for (Iterator iterator = currentSteps.iterator(); iterator.hasNext();) { Step step = (Step) iterator.next(); l.addAll(getAvailableAutoActionsForStep(wf, step, transientVars, ps)); } int[] actions = new int[l.size()]; for (int i = 0; i < actions.length; i++) { actions[i] = ((Integer) l.get(i)).intValue(); } return actions; } catch (Exception e) { log.error("Error checking available actions", e); return new int[0]; } } /** * Get just auto action availables for a step */ protected List getAvailableAutoActionsForStep(WorkflowDescriptor wf, Step step, Map transientVars, PropertySet ps) throws WorkflowException { List l = new ArrayList(); StepDescriptor s = wf.getStep(step.getStepId()); if (s == null) { log.warn("getAvailableAutoActionsForStep called for non-existent step Id #" + step.getStepId()); return l; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -