Workflow Course: Exercise 6

From OpenKM Documentation
(Redirected from Workflow Course: Exercice 6)
Jump to: navigation, search

Contents

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";
        }
    }
}