/* (non-Javadoc) * @see org.jbpm.graph.def.ActionHandler#execute(org.jbpm.graph.exe.ExecutionContext) */ @Override public void execute(ExecutionContext executionContext) throws Exception { /* * 通过总经理审批 */ ContextInstance ci = executionContext.getContextInstance(); String user = (String) ci.getVariable("initiator"); Integer money = (Integer) ci.getVariable("money"); System.out.println(new Date() + " 员工 " + user + " 借款 " + money + " 元, 通过总经理审批"); }
/* (non-Javadoc) * @see org.jbpm.taskmgmt.def.AssignmentHandler#assign(org.jbpm.taskmgmt.exe.Assignable, org.jbpm.graph.exe.ExecutionContext) */ @Override public void assign(Assignable assignable, ExecutionContext executionContext) throws Exception { /* * 将审批任务分配给流程发起人的部门领导 */ ContextInstance ci = executionContext.getContextInstance(); String user = (String) ci.getVariable("initiator"); String manager = getDepartmentManagerByUser(user); ci.setVariable("manager", manager); assignable.setActorId(manager); }
public Object resolveVariable(String name) throws ELException { ExecutionContext executionContext = ExecutionContext.currentExecutionContext(); Object value = null; if ("taskInstance".equals(name)) { value = executionContext.getTaskInstance(); } else if ("processInstance".equals(name)) { value = executionContext.getProcessInstance(); } else if ("processDefinition".equals(name)) { value = executionContext.getProcessDefinition(); } else if ("token".equals(name)) { value = executionContext.getToken(); } else if ("taskMgmtInstance".equals(name)) { value = executionContext.getTaskMgmtInstance(); } else if ("contextInstance".equals(name)) { value = executionContext.getContextInstance(); } else if ((executionContext.getTaskInstance() != null) && (executionContext.getTaskInstance().hasVariableLocally(name))) { value = executionContext.getTaskInstance().getVariable(name); } else { ContextInstance contextInstance = executionContext.getContextInstance(); TaskMgmtInstance taskMgmtInstance = executionContext.getTaskMgmtInstance(); Token token = executionContext.getToken(); if ((contextInstance != null) && (contextInstance.hasVariable(name))) { value = contextInstance.getVariable(name, token); } else if ((contextInstance != null) && (contextInstance.hasTransientVariable(name))) { value = contextInstance.getTransientVariable(name); } else if ((taskMgmtInstance != null) && (taskMgmtInstance.getSwimlaneInstances() != null) && (taskMgmtInstance.getSwimlaneInstances().containsKey(name))) { SwimlaneInstance swimlaneInstance = taskMgmtInstance.getSwimlaneInstance(name); value = (swimlaneInstance != null ? swimlaneInstance.getActorId() : null); } else if ((contextInstance != null) && (contextInstance.hasTransientVariable(name))) { value = contextInstance.getTransientVariable(name); } else if (JbpmConfiguration.Configs.hasObject(name)) { value = JbpmConfiguration.Configs.getObject(name); } } return value; }
protected List<TaskInstance> getTasksInstancesBySubmittingUser( long companyId, long userId, Boolean completed, int start, int end, OrderByComparator orderByComparator) { List<TaskInstance> taskInstances = new ArrayList<TaskInstance>(); try { Criteria criteria = _session.createCriteria(TaskInstance.class); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); if (completed != null) { if (completed.booleanValue()) { criteria.add(Restrictions.isNotNull("end")); } else { criteria.add(Restrictions.isNull("end")); } } addOrder(criteria, orderByComparator); for (TaskInstance taskInstance : (List<TaskInstance>) criteria.list()) { ProcessInstance processInstance = taskInstance.getProcessInstance(); ContextInstance contextInstance = processInstance.getContextInstance(); long taskInstanceUserId = GetterUtil.getLong((String) contextInstance.getVariable("userId")); if (userId == taskInstanceUserId) { taskInstances.add(taskInstance); } } } catch (Exception e) { throw new JbpmException(e); } if ((end != QueryUtil.ALL_POS) && (taskInstances.size() > end)) { taskInstances = ListUtil.subList(taskInstances, start, end); } return taskInstances; }
/** * extract the list of information from the process variables and make them available locally. * Note that if no task instance variables are specified, the full process variables scope will be * visible (that means that the user did not specify a special task instance scope). */ public void initializeVariables(TaskInstance taskInstance) { ClassLoader surroundingClassLoader = Thread.currentThread().getContextClassLoader(); try { // set context class loader correctly for delegation class // (https://jira.jboss.org/jira/browse/JBPM-1448) Thread.currentThread() .setContextClassLoader( JbpmConfiguration.getProcessClassLoader( taskInstance.getTask().getProcessDefinition())); if (taskControllerDelegation != null) { TaskControllerHandler taskControllerHandler = (TaskControllerHandler) taskControllerDelegation.instantiate(); ProcessInstance processInstance = taskInstance.getTaskMgmtInstance().getProcessInstance(); ContextInstance contextInstance = (processInstance != null ? processInstance.getContextInstance() : null); Token token = taskInstance.getToken(); if (UserCodeInterceptorConfig.userCodeInterceptor != null) { UserCodeInterceptorConfig.userCodeInterceptor.executeTaskControllerInitialization( taskControllerHandler, taskInstance, contextInstance, token); } else { taskControllerHandler.initializeTaskVariables(taskInstance, contextInstance, token); } } else { Token token = taskInstance.getToken(); ProcessInstance processInstance = token.getProcessInstance(); ContextInstance contextInstance = processInstance.getContextInstance(); if (variableAccesses != null) { Iterator iter = variableAccesses.iterator(); while (iter.hasNext()) { VariableAccess variableAccess = (VariableAccess) iter.next(); String mappedName = variableAccess.getMappedName(); if (variableAccess.isReadable()) { String variableName = variableAccess.getVariableName(); Object value = contextInstance.getVariable(variableName, token); log.debug( "creating task instance variable '" + mappedName + "' from process variable '" + variableName + "', value '" + value + "'"); taskInstance.setVariableLocally(mappedName, value); } else { log.debug( "creating task instance local variable '" + mappedName + "'. initializing with null value."); taskInstance.setVariableLocally(mappedName, null); } } } } } finally { Thread.currentThread().setContextClassLoader(surroundingClassLoader); } }
public void testTimerInCombinationWithAsyncNode() throws Throwable { ProcessDefinition subDefinition = ProcessDefinition.parseXmlString( "<process-definition name='sub'>" + " <start-state name='start'>" + " <transition to='decision'/>" + " </start-state>" + " <decision name='decision'>" + " <handler class='org.jbpm.scenarios.AsyncTimerAndSubProcessDbTest$ToTimedDecisionHandler' />" + " <transition name='default' to='task' />" + " </decision>" + " <task-node name='task'>" + " <task name='do stuff'>" + " <controller>" + " <variable name='a' access='read' />" + " </controller>" + " <assignment actor-id='victim' />" + " </task>" + " <transition to='end'/>" + " </task-node>" + " <end-state name='end' />" + "</process-definition>"); jbpmContext.deployProcessDefinition(subDefinition); newTransaction(); ProcessDefinition superDefinition = ProcessDefinition.parseXmlString( "<process-definition name='super'>" + " <start-state name='start'>" + " <transition to='decision'/>" + " </start-state>" + " <decision name='decision'>" + " <handler class='org.jbpm.scenarios.AsyncTimerAndSubProcessDbTest$ToTimedDecisionHandler' />" + " <transition name='default' to='timed' />" + " </decision>" + " <state name='timed'>" + " <timer name='reminder' " + " duedate='0 seconds' " + " transition='timer fires' />" + " <transition name='timer fires' to='async'/>" + " <transition name='normal continuation' to='end'/>" + " </state>" + " <node name='async' async='true'>" + " <transition to='subprocess'/>" + " </node>" + " <process-state name='subprocess'>" + " <sub-process name='sub' />" + " <variable name='a'/>" + " <variable name='b'/>" + " <transition to='decision' />" + " </process-state>" + " <end-state name='end' />" + "</process-definition>"); jbpmContext.deployProcessDefinition(superDefinition); newTransaction(); ProcessInstance superInstance = jbpmContext.newProcessInstanceForUpdate("super"); ContextInstance superContext = superInstance.getContextInstance(); superContext.setVariable("a", "value a"); superContext.setVariable("b", "value b"); superInstance.signal(); processJobs(5000); superInstance = jbpmContext.loadProcessInstance(superInstance.getId()); assertEquals("subprocess", superInstance.getRootToken().getNode().getName()); List taskInstances = taskMgmtSession.findTaskInstances("victim"); assertEquals(1, taskInstances.size()); TaskInstance taskInstance = (TaskInstance) taskInstances.get(0); taskInstance.setVariable("a", "value a updated"); taskInstance.setVariable("b", "value b updated"); taskInstance.end(); jbpmContext.save(taskInstance); long taskInstanceId = taskInstance.getId(); long tokenId = taskInstance.getToken().getId(); newTransaction(); taskInstance = jbpmContext.loadTaskInstance(taskInstanceId); assertEquals("value a updated", taskInstance.getVariable("a")); assertEquals("value b updated", taskInstance.getVariable("b")); Token token = jbpmContext.loadToken(tokenId); ContextInstance subContextInstance = token.getProcessInstance().getContextInstance(); assertEquals("value a", subContextInstance.getVariable("a")); assertEquals("value b updated", subContextInstance.getVariable("b")); }