Difference between revisions of "Workflow Course: Exercise 6"

From OpenKM Documentation
Jump to: navigation, search
(Created page with 'Create your own decision nodes workflow test File:Wf6.png File:Wf6_1.png')
 
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Create your own decision nodes workflow test
+
{{TOCright}} __TOC__
  
[[File:Wf6.png]]
+
== Step 1 - Use decision nodes ==
 +
The idea of this exercise is user put some number value at starting workflow and then in next form try to guess the number.
  
[[File:Wf6_1.png]]
+
To do it you should:
 +
 
 +
* Create two forms with inputs value, one to put the value and other to guess the number.
 +
* Create a task where to guess the number and assign task to actor ''okmAdmin''.
 +
* Create a decision node where to decide if user ''okmAdmin'' has guessed the number.
 +
 
 +
== Diagram ==
 +
 
 +
[[File:Wf decission.png|center]]
 +
 
 +
== Resources ==
 +
Example of '''forms.xml''':
 +
 
 +
<source lang="xml">
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
<!DOCTYPE workflow-forms PUBLIC "-//OpenKM//DTD Workflow Forms 2.1//EN"
 +
                                "http://www.openkm.com/dtd/workflow-forms-2.1.dtd">
 +
<workflow-forms>
 +
  <workflow-form task="run_config">
 +
    <input label="number" name="number" />
 +
    <button name="submit" label="Submit" />
 +
  </workflow-form>
 +
  <workflow-form task="task">
 +
  <input label="suggested" name="suggested" />
 +
    <button name="submit" label="Submit" />
 +
  </workflow-form>
 +
</workflow-forms>
 +
</source>
 +
 
 +
Example of '''Decision.java''':
 +
 
 +
<source lang="java">
 +
package com.openkm.workflow.exercise.exercise5;
 +
 
 +
import org.jbpm.graph.exe.ExecutionContext;
 +
import org.jbpm.graph.node.DecisionHandler;
 +
import org.slf4j.Logger;
 +
import org.slf4j.LoggerFactory;
 +
 
 +
import com.openkm.bean.form.Input;
 +
 
 +
public class Decision implements DecisionHandler {
 +
    private static final long serialVersionUID = 1L;
 +
    private static Logger log = LoggerFactory.getLogger(Decision.class);
 +
 
 +
    @Override
 +
    public String decide(ExecutionContext executionContext) throws Exception {
 +
        log.info("Decision being evaluated");
 +
        Input number = (Input) executionContext.getContextInstance().getVariable("number");
 +
        Input suggested = (Input) executionContext.getContextInstance().getVariable("suggested");
 +
       
 +
        if (number != null && suggested != null && number.getValue().equals(suggested.getValue())) {
 +
            log.info("Go to 'good'");
 +
            return "good";
 +
        } else {
 +
            log.info("Go to 'bad'");
 +
            return "bad";
 +
        }
 +
    }
 +
}
 +
</source>
 +
 
 +
[[Category: Workflow Guide]]
 +
[[Category: Workflow Course]]

Latest revision as of 08:54, 18 June 2013

Step 1 - Use decision nodes

The idea of this exercise is user put some number value at starting workflow and then in next form try to guess the number.

To do it you should:

  • Create two forms with inputs value, one to put the value and other to guess the number.
  • Create a task where to guess the number and assign task to actor okmAdmin.
  • Create a decision node where to decide if user okmAdmin has guessed the number.

Diagram

Wf decission.png

Resources

Example of forms.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE workflow-forms PUBLIC "-//OpenKM//DTD Workflow Forms 2.1//EN"
                                "http://www.openkm.com/dtd/workflow-forms-2.1.dtd">
<workflow-forms>
  <workflow-form task="run_config">
    <input label="number" name="number" />
    <button name="submit" label="Submit" />
  </workflow-form>
  <workflow-form task="task">
  	<input label="suggested" name="suggested" />
    <button name="submit" label="Submit" />
  </workflow-form>
</workflow-forms>

Example of Decision.java:

package com.openkm.workflow.exercise.exercise5;

import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.node.DecisionHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.openkm.bean.form.Input;

public class Decision implements DecisionHandler {
    private static final long serialVersionUID = 1L;
    private static Logger log = LoggerFactory.getLogger(Decision.class);

    @Override
    public String decide(ExecutionContext executionContext) throws Exception {
        log.info("Decision being evaluated");
        Input number = (Input) executionContext.getContextInstance().getVariable("number");
        Input suggested = (Input) executionContext.getContextInstance().getVariable("suggested");
        
        if (number != null && suggested != null && number.getValue().equals(suggested.getValue())) {
            log.info("Go to 'good'");
            return "good";
        } else {
            log.info("Go to 'bad'");
            return "bad";
        }
    }
}