[jboss-user] [JBoss jBPM] - Re: how to use Decision nodes??????

minam97531 do-not-reply at jboss.com
Tue Jul 22 03:31:52 EDT 2008


i could make the process definition work. (the one that i put above with name "mytest"). it's problem was swimlanes that i assigned! 
but i still have the same problem, using handler class in decision nodes! :( 
when i make new instance of websale process definition, in "check-for-another-web-order" task, if i select either "yes" or "no",i get the following error: 

Entering node evaluate-another-web-order 
ERROR [com.liferay.jbpm.WorkflowComponentImpl] Task has already ended 

i made some changes to the original websale example to make it easier to check.
this is the first time i write a unit test, so i hope it's correct. 
here's the unit test: 


  | import java.util.Collection;
  | 
  | import junit.framework.TestCase;
  | 
  | import org.jbpm.graph.def.ProcessDefinition;
  | import org.jbpm.graph.exe.ProcessInstance;
  | import org.jbpm.taskmgmt.exe.TaskInstance;
  | 
  | public class DecisionTest {
  | 
  | 	private static final String TEST_PROCESS = 
  | 	 "<?xml version=\"1.0\" >" 
  | 	 +"<process-definition name=\"websale\">"
  | 	 +"<!--  Event Logging  -->" 
  | 	 +"<event type=\"node-enter\">"
  | 	 +"<script>System.out.println(\"Entering node \" + node.getName());</script>" 
  | 	 +" </event>"
  | 	 +"<event type=\"node-leave\">"
  | 	 +"<script>System.out.println(\"Leaving node \" + node.getName());</script>" 
  | 	 +"</event>"
  | 	 +"<!--  Swimlanes -->" 
  | 	 +"<swimlane name=\"user\" />" 
  | 	 +"<!--  Nodes -->" 
  | 	 +"<start-state name=\"initiate-process\">"
  | 	 +"<task swimlane=\"user\">"
  | 	 +"<controller>"
  | 	 +"<variable name=\"textarea:description\" />" 
  | 	 +"</controller>"
  | 	 +"</task>"
  | 	 +"<transition name=\"save\" to=\"create-new-web-sale-order\" />" 
  | 	 +"</start-state>"
  | 	 +"<task-node name=\"create-new-web-sale-order\">"
  | 	 +"<task swimlane=\"user\">"
  | 	 +"<controller>"
  | 	 +"<variable name=\"text:item\" access=\"read,write,required\" />" 
  | 	 +"</controller>"
  | 	 +"</task>"
  | 	 +"<transition name=\"submit\" to=\"check-for-another-web-order\" />" 
  | 	 +"</task-node>"
  | 	 +"<task-node name=\"check-for-another-web-order\">"
  | 	 +"<task swimlane=\"user\">"
  | 	 +"<controller>"
  | 	 +"<variable name=\"radio:perform-another-order:yes,no\" />" 
  | 	 +"</controller>"
  | 	 +"</task>"
  | 	 +"<transition name=\"submit\" to=\"decision\">" 
  | 	 +"</transition>"
  | 	 +"</task-node>"
  | 	 +"<decision name=\"decision\">"
  | 	 +"<handler class=\"com.liferay.jbpm.handler.WebOrderDecisionHandler\" />" 
  | 	 +"<transition name=\"finished\" to=\"disagree\" />" 
  | 	 +"<transition name=\"another\" to=\"agree\" />" 
  | 	 +"</decision>"
  |                  +"<task-node name=\"agree\">"
  | 	 +"<task swimlane=\"user\">"
  | 	 +"<controller>"
  | 	 +"<variable name=\"text:hello\" />" 
  | 	 +"</controller>"
  | 	 +"</task>"
  | 	 +"<transition name=\"submit\" to=\"end\">" 
  | 	 +"</transition>"
  | 	 +"</task-node>"
  | 	 +"<task-node name=\"disagree\">"
  | 	 +"<task swimlane=\"user\">"
  | 	 +"<controller>"
  | 	 +"<variable name=\"text:goodbye\" />" 
  | 	 +"</controller>"
  | 	 +"</task>"
  | 	 +"<transition name=\"submit\" to=\"end\">" 
  | 	 +"</transition>"
  | 	 +"</task-node>"
  | 	 +"<end-state name=\"end\" />" 
  | 	 +"</process-definition>";
  | 	
  | 	public void testExpression() {
  | 		ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(TEST_PROCESS);
  | 		ProcessInstance processInstance = processDefinition.createProcessInstance();
  | 		processInstance.getContextInstance().setVariable("textarea:description", "something"); 
  | 		processInstance.signal(); 
  | 		processInstance.getContextInstance().setVariable("text:item", "book");
  | 		processInstance.signal();
  | 		processInstance.getContextInstance().setVariable("radio:perform-another-order:yes,no", "yes");
  | 		processInstance.signal();
  | 		assertEquals(processDefinition.getNode("agree"), processInstance.getRootToken().getNode()); 
  | 	}
  | 	
  | }
  | 

and this is WebOrderDecisionHandler.java:


  | import org.jbpm.context.exe.ContextInstance;
  | import org.jbpm.graph.exe.ExecutionContext;
  | import org.jbpm.graph.node.DecisionHandler;
  | 
  | /**
  |  * <a href="WebOrderDecisionHandler.java.html"><b><i>View Source</i></b></a>
  |  *
  |  * @author Charles May
  |  *
  |  */
  | public class WebOrderDecisionHandler implements DecisionHandler {
  | 
  | 	public String decide(ExecutionContext executionContext) throws Exception {
  | 		ContextInstance contextInstance = executionContext.getContextInstance();
  | 
  | 		String decision = null;
  | 
  | 		String buyerResponse = (String)contextInstance.getVariable(
  | 			"radio:perform-another-order:yes,no");
  | 
  | 		if (buyerResponse.equals("yes")) {
  | 			decision = "another";
  | 		}
  | 		else {
  | 			decision = "finished";
  | 		}
  | 
  | 		return decision;
  | 	}
  | 
  | }
  | 

one another question: where should i put WebOrderDecisionHandler.class?? maybe i put it in wrong path. 

thanks again. 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4165800#4165800

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4165800



More information about the jboss-user mailing list