-
1. Re: How to take a decision in java code
kukeltje Sep 6, 2007 2:27 PM (in response to jean-luct)look at the testcases in the source.. clear examples of this.
-
2. Re: How to take a decision in java code
jean-luct Sep 6, 2007 3:30 PM (in response to jean-luct)Can you point to a specific example please, because I've seen this comment on some other topic about decision but I didn't find anything in the examples, docs or javadoc.
I've only seen so far samples with either rules our simple expression and I haven't been able to adapt it to java code.
Thanks -
3. Re: How to take a decision in java code
estaub Sep 6, 2007 4:08 PM (in response to jean-luct)You can't leave a node from the node-enter event.
Instead, use a instead of , and put the actionhandler in the "body" of the node.
You probably want to figure out how to use a Decision node without a ClassCastException, though - you don't want to write custom actionhandlers for every decision!
-Ed Staub -
4. Re: How to take a decision in java code
jean-luct Sep 7, 2007 3:37 AM (in response to jean-luct)Hello Ed, I've tryed moving it to the leave node. My new decision node XML is now :
<decision name="Client actif ?"> <event type="node-leave"> <action name="decisionWhenLeaving" class="fr.jl2tho.tutorialjbpm.action.DecideIfCustomer"></action> </event> <transition name="Oui" to="Enregistrer la Question"></transition> <transition name="Non" to="Prevenir le commercial"></transition> </decision>
Now, I got a java.lang.StackOverflowError when I use the Non transition (Non default one). It looks like as if it was looping on the instruction : node.leave(executionContext, "Non");
Any idea ? Am I using the correct instruction ? I'm lost with all this method that seems to be able to change a transition. -
5. Re: How to take a decision in java code
kukeltje Sep 7, 2007 5:18 AM (in response to jean-luct)you decide in a leave either.... and the TESTCASES are in the SOURCE
tip: use a handler, which IS described in the docs http://docs.jboss.com/jbpm/v3.2/userguide/html/processmodelling.html#nodetypedecision -
6. Re: How to take a decision in java code
jean-luct Sep 7, 2007 5:59 AM (in response to jean-luct)Sorry Ronald but I still don't get your point I went one more time on the Node decision without more understanding on the subject.
They talk about DecisionHandler but I've got ClassCastException when using it.
From documentation about graph flow, I've understood that event Node-Leave is triggered when doing a node.leave, thus now I understand why I've got a loop.
From my understanding about the javadoc for token.leaveNode, it is not possible to change process flow from an ActionHandler attached to an event.
I've noticed that when I add an action either Enter, Leave or Before Signal, my ActionHandler is always attached on an event.
I don't see any way to add an ActionHandler not attached to an event.
You're talking about testcase in Source, I've not seen any testcase in my directory C:\jbpm-jpdl-3.2.1\src. I'm sure I missed something, but you will be very helpful to me if you can provide me with the path of the testcase you are talking about.
Thanks -
7. Re: How to take a decision in java code
kukeltje Sep 7, 2007 6:52 AM (in response to jean-luct)The file is called DecisionHandlerTest.java
-
8. Re: How to take a decision in java code
jean-luct Sep 7, 2007 7:55 AM (in response to jean-luct)Sorry but I didn't find this file on my jbpm-jpdl-suite-3.2.1.zip file. I may have to look for another download.
But I made some progress : in fact I've now define my process like this :<decision name="Client actif ?"> <handler class="fr.jl2tho.tutorialjbpm.action.IsCustomer" /> <transition name="Oui" to="Enregistrer la Question"></transition> <transition name="Non" to="Prevenir le commercial"></transition> </decision>
There is no way in using the GUI to do so and the code assist doesn't provide any clue to add the handler tag.
My class is now a DecisionHandler :public class IsCustomer implements DecisionHandler { private static final Logger logger = Logger.getLogger(IsCustomer.class); public IsCustomer(){ super(); } public String decide(ExecutionContext executionContext) throws Exception { String maSortie="Oui"; ContextInstance contextInstance = executionContext.getContextInstance(); if (contextInstance.getVariable("Nom du contact").equals("Non")) { maSortie="Non"; } return maSortie; } public void setConfiguration(String Config){ } }
Im' now able to go either through the Non or Oui transition.
My last problem is that it seems to me that it goes twice through the Non transition. -
9. Solved
jean-luct Sep 7, 2007 8:16 AM (in response to jean-luct)It was the correct way (the transition Non was followed only once in fact). I've made a coding error later that made my trace be triggered twice.
So the correct way of doing a Decision in Java code is to code directly in the Source tab of your processdefinition.xml the following code :<decision name="Client actif ?"> <handler class="fr.jl2tho.tutorialjbpm.action.IsCustomer" /> <transition name="Oui" to="Enregistrer la Question"></transition> <transition name="Non" to="Prevenir le commercial"></transition> </decision>
Where IsCustomer implements org.jbpm.graph.node.DecisionHandler.
It seems to me impossible to do it through the GUI ProcessDesigner. -
10. Re: How to take a decision in java code
kukeltje Sep 10, 2007 7:26 PM (in response to jean-luct)no, this is possible... I wanted to try first, but should have trusted Koens words: "All jpdl language constructs are supported in the gui, no need to use the source tab anymore"
Select open the properties tab, select your decisionhandler, select handler in the left tab, choose delegation as configuration type and fill in your class. -
11. Re: How to take a decision in java code
jean-luct Sep 20, 2007 11:37 AM (in response to jean-luct)Ok I found a way using the Design mode.
When on my Decision Node, I can right click on it. I then select in the menu Add Child and then Handler.
i can then do on the added handler a Add Attribute -> class.
Then I can type my class.
Ronald, if you were talking about the Diagram mode : The only proprerties available to me just allow me to enter a new name to my Decision Node.
I don't understand what you call "Select open the properties tab" neither "select your decision handler". -
12. Re: How to take a decision in java code
dleerob Sep 26, 2007 4:36 AM (in response to jean-luct)Ronald,
What version of the GPD are you using to allow this functionality?
I'm using 3.0.13.1, and don't see the decision handler option. -
13. Re: How to take a decision in java code
dleerob Sep 26, 2007 4:48 AM (in response to jean-luct)Nevermind, I've read the notes on the 3.1 release, and busy downloading 3.1.0.sp1 now.