Difference between revisions of "Use of decision node"

From OpenKM Documentation
Jump to: navigation, search
(Created page with '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 cond…')
 
Line 21: Line 21:
  
 
<source lang="java">
 
<source lang="java">
public class Decisor implements DecisionHandler {
+
public class MyDecision implements DecisionHandler {
     public Decisor(String info) {
+
     public MyDecision(String info) {
 
         super();
 
         super();
 
     }
 
     }
Line 35: Line 35:
 
             return "trans_2";
 
             return "trans_2";
 
         }
 
         }
 +
    }
 +
}
 +
</source>
 +
 +
<source lang="java">
 +
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());
 
     }
 
     }
 
}
 
}

Revision as of 20:11, 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.


public class ValorAction implements ActionHandler {
    public String value;

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


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 "trans_1";
        } else {
            return "trans_2";
        }
    }
}
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());
    }
}