-
1. Re: task-create event
twiceknightly Feb 11, 2008 12:02 PM (in response to twiceknightly)A bit more information. It is actually calling my action from the task-create event, I was initially mistaken. Within that action I am setting the variables with something like that below.
ContextInstance instance = executionContext.getContextInstance() ; instance.setVariable("id",id) ; instance.setVariable("transaction value",value) ; instance.setVariable("account number",accountNumber) ; instance.setVariable("notes",notes) ; instance.setVariable("transaction status",status) ; etc ...
The returned task instance from the initial codeprocessInstance.getTaskMgmtInstance().createStartTaskInstance()
is returning NullInstance for the values of the variable instances. That I set above in the action tied to the task-create event. -
2. Re: task-create event
kukeltje Feb 11, 2008 12:35 PM (in response to twiceknightly)can you make a unittest that demonstrates the problem? Easier to reproduce then...
-
3. Re: task-create event
twiceknightly Feb 12, 2008 11:11 AM (in response to twiceknightly)Below is a simple unit test. What I am trying to do is set some values in the context on creation of the task in the start state. The event is firing and my action "SetupSuspiciousTransaction" is being run. This action sets variables in the context. Later on I try to retrieve the variables and there values in the method "retrieveVariables". When I step through this method "mappedName" has the right variable name but "value" has null as the value. I was expecting to get back the values I had put in earlier.
import java.io.InputStream; import java.util.Iterator; import java.util.List; import org.jbpm.JbpmConfiguration; import org.jbpm.JbpmContext; import org.jbpm.context.def.VariableAccess; import org.jbpm.graph.def.ProcessDefinition; import org.jbpm.graph.exe.ProcessInstance; import org.jbpm.taskmgmt.def.TaskController; import org.jbpm.taskmgmt.exe.TaskInstance; import junit.framework.TestCase; public class TaskEventTestCase extends TestCase { static JbpmConfiguration jbpmConfiguration = null ; public TaskEventTestCase(){ super("TaskEventTestCase") ; } static { InputStream is = ClassLoader.getSystemResourceAsStream("default.jbpm.cfg.xml"); jbpmConfiguration = JbpmConfiguration.parseInputStream(is) ; } public void testSimplePersistence(){ deployProcessDefinition() ; createStartTask() ; } public static void main(String[] args){ new TaskEventTestCase().testSimplePersistence() ; } public void createStartTask(){ JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext() ; try{ jbpmContext.setActorId("Fraud Investigator"); ProcessInstance processInstance = null; processInstance = jbpmContext.newProcessInstance("test"); TaskInstance result = null; result = processInstance.getTaskMgmtInstance().createStartTaskInstance(); jbpmContext.save(processInstance) ; retrieveVariables(result) ; } catch (Exception e){ throw new RuntimeException(e.getMessage()) ; } finally { jbpmContext.close() ; } } protected void retrieveVariables(TaskInstance ti){ TaskController taskController = ti.getTask().getTaskController(); if (taskController!=null) { List variableAccesses = taskController.getVariableAccesses(); Iterator iter = variableAccesses.iterator(); while (iter.hasNext()) { VariableAccess variableAccess = (VariableAccess) iter.next(); String mappedName = variableAccess.getMappedName(); String value = (String)ti.getVariable(mappedName); } } } public void deployProcessDefinition(){ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( "<process-definition name='test'>" + "<start-state name='state1'>" + "<task name='Investigate Transaction' swimlane='Fraud Investigator'>" + "<controller>" + "<variable name='transaction value' access='read,write,required'></variable>" + "<variable name='account number' access='read,write,required'></variable>" + "<variable name='transaction status' access='read,write,required'></variable>" + "</controller>" + "<event type='task-create'>" + " <action class='com.nr.tms.workflow.objectservices.actionhandlers.SetupSuspiciousTransaction'/>" + "</event>" + "</task>" + "<transition name='default' to='end1'></transition>" + "</start-state>" + "<end-state name='end1'></end-state>" + "</process-definition>" ) ; JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext() ; try{ jbpmContext.deployProcessDefinition(processDefinition) ; } finally { jbpmContext.close() ; } } }
-
4. Re: task-create event
twiceknightly Feb 12, 2008 11:19 AM (in response to twiceknightly)Sorry here is the code for the action ...
public class SetupSuspiciousTransaction implements ActionHandler{ public void execute(ExecutionContext executionContext){ ContextInstance instance = executionContext.getContextInstance() ; instance.setVariable("id","1") ; instance.setVariable("transaction value","test transaction value") ; instance.setVariable("account number","test account number") ; instance.setVariable("notes","test notes") ; instance.setVariable("transaction status","test transaction status") ; } }