This content has been marked as final.
Show 5 replies
-
1. Re: Variables keep old values
kukeltje Dec 1, 2009 6:03 AM (in response to aroeder)please make a full unittest that demonstrates the problem.
And do you close the context? You should... according to the docs -
2. Re: Variables keep old values
tejjbpm Dec 1, 2009 3:41 PM (in response to aroeder)Are you using jbpm 3 version..i remember reading somewhere that only jbpm 4 replace the previously created values..worth checking the user guide again..
-
3. Re: Variables keep old values
kukeltje Dec 1, 2009 3:43 PM (in response to aroeder)3 should change them as well, but you have to close the context AND NOT set them as local variables
-
4. Re: Variables keep old values
aroeder Dec 2, 2009 4:10 AM (in response to aroeder)Would do you mean with local variables?
I also tried:currentTI.getProcessInstance().getContextInstance().addVariables(variables);
But that doesn't work neither. Still no value changed in JBPM_VARIABLEINSTANCE nor a new record was added. -
5. Re: Variables keep old values
aroeder Dec 2, 2009 9:08 AM (in response to aroeder)I wrote a JUnit test for showing my problem:
package de.firstdata.test; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Set; import org.jbpm.graph.def.ProcessDefinition; import org.jbpm.graph.exe.ProcessInstance; import org.jbpm.taskmgmt.exe.TaskInstance; import de.firstdata.config.TicketServiceConfigService; import de.firstdata.dm.JBPMContextWrapper; import de.firstdata.dm.TicketSystemDomainModelFacade; public class JbpmVariablesTest extends ATicketServiceTestA { private TicketSystemDomainModelFacade facade = null; @SuppressWarnings("unchecked") public void testVariables() throws IOException { JBPMContextWrapper ctx = getContextWrapper(); try { ProcessDefinition processDefinition = ProcessDefinition .parseXmlString("<process-definition xmlns='' name='ABR'>" + "<start-state name='start-state1'>" + "<transition to='edit'></transition>" + "</start-state>" + "<task-node name='edit'>" + "<task name='edit'>" + " <controller>" + " <variable access='read,write,required' name='inbox'></variable>" + " </controller>" + "</task>" + "<transition to='change' name='tochange'></transition>" + "<transition to='end-state1' name='done'></transition>" + "</task-node>" + "<task-node name='change'>" + "<task name='indexDataChange'>" + " <controller>" + " <variable access='read,write,required' name='inbox'></variable>" + " </controller>" + "</task>" + "<transition to='edit' name='back'></transition>" + "</task-node>" + "<end-state name='end-state1'></end-state>" + "</process-definition>"); Map<String, String> myMap = new HashMap<String, String>(); myMap.put("inbox", "COMPLAINTS_MANAGEMENT"); ctx.deployProcessDefinition(processDefinition); ProcessInstance processInstance = processDefinition.createProcessInstance(myMap); ctx.save(processInstance); processInstance.signal(); TaskInstance taskEdit = getTaskInstance(processInstance, "edit"); taskEdit.end("tochange"); ctx.save(taskEdit); TaskInstance taskChange = getTaskInstance(processInstance, "indexDataChange"); Map<String, String> variables = taskChange.getContextInstance().getVariables(); variables.put("inbox", "CS_ISO"); taskChange.getProcessInstance().getContextInstance().addVariables(variables); ctx.save(taskChange); ctx.close(); ctx = getContextWrapper(); taskChange.end("back"); taskEdit = getTaskInstance(processInstance, "edit"); Map<String, String> changedVariables = taskEdit.getProcessInstance().getContextInstance().getVariables(); String inbox = (String) changedVariables.get("inbox"); taskEdit.end("done"); processInstance.end(); ctx.deleteProcessDefinition(processDefinition); assertEquals("CS_ISO", inbox); } finally { ctx.close(); } } private JBPMContextWrapper getContextWrapper() { if (facade == null) { facade = (TicketSystemDomainModelFacade) TicketServiceConfigService.getConfig().getFacade(); } return JBPMContextWrapper.getInstance("jbpm.cfg.xml", facade); } @SuppressWarnings("unchecked") private TaskInstance getTaskInstance(final ProcessInstance processInstance, final String taskInstanceName) { TaskInstance returnInstance = null; Set<TaskInstance> tasks = (Set<TaskInstance>) processInstance.getTaskMgmtInstance().getTaskInstances(); for (TaskInstance ti : tasks) { if (ti.getName().equals(taskInstanceName) && !ti.hasEnded()) { returnInstance = ti; } } return returnInstance; } }