Difference between revisions of "Use of decision node"

From OpenKM Documentation
Jump to: navigation, search
Line 8: Line 8:
  
 
[[File:Jbpm sample decision.png|center]]
 
[[File:Jbpm sample decision.png|center]]
 +
 +
This process begins at the start node and go across the transition name '''initiate'''. This transition has an action called ''createvalue'' handler by the class ValueAction, who set the variable ''value'' in the execution context.
  
 
<source lang="java">
 
<source lang="java">
public class ValorAction implements ActionHandler {
+
public class ValueAction implements ActionHandler {
 
     public String value;
 
     public String value;
  
Line 20: Line 22:
 
</source>
 
</source>
  
 +
After that arrives to the decision node handled by the class Decission, who check the existence of the ''value'' variable in the execution context. If exists this variable leave the node across the transition ''trans1'', otherwise go across ''trans2''.
  
 
<source lang="java">
 
<source lang="java">
Line 32: Line 35:
  
 
         if(valor != null) {
 
         if(valor != null) {
             return "trans_1";
+
             return "trans1";
 
         } else {
 
         } else {
             return "trans_2";
+
             return "trans2";
 
         }
 
         }
 
     }
 
     }

Revision as of 21:29, 13 January 2012

A decision node is used to guide the process running path. This means you can tell the workflow which way should go. Decision criteria can be specified as follows:

  • Adding conditions to transitions or BeanShell script which returns a boolean. Nodes go across its transitions examining the conditions until found the first one which match a criteria.
  • Creating a class which implements the DecisionHandler interface. The decide method returns the transition to follow.

Below we are going to create a process containing a decision node which implements the DecisionHandler interface to decide the next node in the workflow.

Jbpm sample decision.png

This process begins at the start node and go across the transition name initiate. This transition has an action called createvalue handler by the class ValueAction, who set the variable value in the execution context.

public class ValueAction implements ActionHandler {
    public String value;

    @Override
    public void execute(ExecutionContext executionContext) throws Exception {
        executionContext.getContextInstance().setVariable("value", value);
    }
}

After that arrives to the decision node handled by the class Decission, who check the existence of the value variable in the execution context. If exists this variable leave the node across the transition trans1, otherwise go across trans2.

public class MyDecision implements DecisionHandler {
    public MyDecision(String info) {
        super();
    }

    @Override
    public String decide(ExecutionContext executionContext) throws Exception {
        String value = (String)executionContext.getContextInstance().getVariable("value");

        if(valor != null) {
            return "trans1";
        } else {
            return "trans2";
        }
    }
}
public class ShowMessageAction implements ActionHandler {
    public ShowMessageAction(String info) {
        super();
    }

    @Override
    public void execute(ExecutionContext executionContext) throws Exception {
        System.out.println("Flow go to node: " + executionContext.getNode().getName());
    }
}

If in the configuration you have set the "value" variable in the console you will see a message saying that has finished in node "end_1". In the other side, will end in node "end_2".