Difference between revisions of "Examples: Advanced"

From OpenKM Documentation
Jump to: navigation, search
 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{TOCright}} __TOC__
 
{{TOCright}} __TOC__
 +
 +
Download and test this process definition: [[File:Advanced.par]].
 +
 +
{{Note|The taks will be assigned to an user called "monkiki" so you need to create this user and log as him to see the task assignment. Also you can assing this task to another user from the process instance workflow administration.}}
  
 
== Process image ==
 
== Process image ==
Line 11: Line 15:
 
     <transition to="task-node"></transition>
 
     <transition to="task-node"></transition>
 
   </start-state>
 
   </start-state>
 
+
 
   <task-node name="task-node">
 
   <task-node name="task-node">
 
     <task name="guess_a_number">
 
     <task name="guess_a_number">
Line 21: Line 25:
 
     <transition to="decision"></transition>
 
     <transition to="decision"></transition>
 
   </task-node>
 
   </task-node>
 
+
 
   <decision name="decision">
 
   <decision name="decision">
     <handler class="com.openkm.VerifyNumber"></handler>
+
     <handler class="com.openkm.sample.VerifyNumber"></handler>
 
       <transition to="task-node" name="no"></transition>
 
       <transition to="task-node" name="no"></transition>
 
       <transition to="end" name="yes"></transition>
 
       <transition to="end" name="yes"></transition>
 
     </decision>
 
     </decision>
 
+
 
   <end-state name="end"></end-state>
 
   <end-state name="end"></end-state>
 
</process-definition>
 
</process-definition>
Line 34: Line 38:
 
== Process handlers ==
 
== Process handlers ==
 
<source lang="java">
 
<source lang="java">
package com.openkm;
+
package com.openkm.sample;
  
 +
import com.openkm.bean.form.Input;
 +
 +
import org.jbpm.graph.exe.Comment;
 
import org.jbpm.graph.exe.ExecutionContext;
 
import org.jbpm.graph.exe.ExecutionContext;
 
import org.jbpm.graph.node.DecisionHandler;
 
import org.jbpm.graph.node.DecisionHandler;
Line 44: Line 51:
 
   @Override
 
   @Override
 
   public String decide(ExecutionContext executionContext) throws Exception {
 
   public String decide(ExecutionContext executionContext) throws Exception {
     String numberStr = (String) executionContext.getContextInstance().getVariable("number");
+
     Input numberStr = (Input) executionContext.getContextInstance().getVariable("number");
     String guessStr = (String) executionContext.getContextInstance().getVariable("guess");
+
     Input guessStr = (Input) executionContext.getContextInstance().getVariable("guess");
 +
    System.out.println("numberStr: " + numberStr);
 +
    System.out.println("guessStr: " + numberStr);
 +
 
 +
    Integer guess = Integer.valueOf(guessStr.getValue());
 
     Integer number;
 
     Integer number;
  
     if (numberStr != null) number = Integer.valueOf(numberStr); else number = 10;
+
     if (numberStr != null && !numberStr.equals("")) {
     Integer guess = Integer.valueOf(guessStr);
+
      number = Integer.valueOf(numberStr.getValue());
+
    } else {
 +
      number = 10;
 +
     }
 +
 
     if (guess > number) {
 
     if (guess > number) {
 
       System.out.println("Too high!");
 
       System.out.println("Too high!");
 +
      executionContext.getToken().addComment(new Comment("system", guess + " is too high!"));
 
       return "no";
 
       return "no";
 
     } else if (guess < number) {
 
     } else if (guess < number) {
 
       System.out.println("Too low!");
 
       System.out.println("Too low!");
 +
      executionContext.getToken().addComment(new Comment("system", guess + " is too low!"));
 
       return "no";
 
       return "no";
 
     } else {
 
     } else {
 
       System.out.println("Great!");
 
       System.out.println("Great!");
 +
      executionContext.getToken().addComment(new Comment("system", guess + " is great!"));
 
       return "yes";
 
       return "yes";
 
     }
 
     }
Line 68: Line 85:
 
<source lang="xml">
 
<source lang="xml">
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
<forms xmlns="http://www.openkm.com/xsd/forms-1.0.xsd"
+
<!DOCTYPE workflow-forms PUBLIC "-//OpenKM//DTD Workflow Forms 2.1//EN"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
                                "http://www.openkm.com/dtd/workflow-forms-2.1.dtd">
      xsi:schemaLocation="http://www.openkm.com/xsd forms-1.0.xsd">
+
<workflow-forms>
   <form task="run_config">
+
   <workflow-form task="run_config">
 
     <input label="Number to guess" name="number" />
 
     <input label="Number to guess" name="number" />
     <button label="Submit" />
+
     <button name="submit" label="Submit" />
   </form>
+
   </workflow-form>
   <form task="guess_a_number">
+
   <workflow-form task="guess_a_number">
 
     <input label="Guess" name="guess" />
 
     <input label="Guess" name="guess" />
     <button label="Submit" />
+
     <button name="submit" label="Submit" />
   </form>
+
   </workflow-form>
</forms>
+
</workflow-forms>
 
</source>
 
</source>
  
 
[[Category: Workflow Guide]]
 
[[Category: Workflow Guide]]
[[Category:OKM Network]]
 

Latest revision as of 11:50, 3 December 2012

Download and test this process definition: File:Advanced.par.


Nota clasica.png The taks will be assigned to an user called "monkiki" so you need to create this user and log as him to see the task assignment. Also you can assing this task to another user from the process instance workflow administration.

Process image

Workflow example advanced.png

Process definition

<?xml version="1.0" encoding="UTF-8"?>
<process-definition  xmlns="urn:jbpm.org:jpdl-3.2"  name="advanced">
  <start-state name="start">
    <transition to="task-node"></transition>
  </start-state>
 
  <task-node name="task-node">
    <task name="guess_a_number">
      <assignment actor-id="monkiki"></assignment>
      <event type="task-create">
        <script>taskInstance.start();</script>
      </event>
    </task>
    <transition to="decision"></transition>
  </task-node>
 
  <decision name="decision">
    <handler class="com.openkm.sample.VerifyNumber"></handler>
      <transition to="task-node" name="no"></transition>
      <transition to="end" name="yes"></transition>
    </decision>
 
  <end-state name="end"></end-state>
</process-definition>

Process handlers

package com.openkm.sample;

import com.openkm.bean.form.Input;

import org.jbpm.graph.exe.Comment;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.node.DecisionHandler;

public class VerifyNumber implements DecisionHandler {
  private static final long serialVersionUID = 1L;

  @Override
  public String decide(ExecutionContext executionContext) throws Exception {
    Input numberStr = (Input) executionContext.getContextInstance().getVariable("number");
    Input guessStr = (Input) executionContext.getContextInstance().getVariable("guess");
    System.out.println("numberStr: " + numberStr);
    System.out.println("guessStr: " + numberStr);

    Integer guess = Integer.valueOf(guessStr.getValue());
    Integer number;

    if (numberStr != null && !numberStr.equals("")) {
      number = Integer.valueOf(numberStr.getValue());
    } else {
      number = 10;
    }
	
    if (guess > number) {
      System.out.println("Too high!");
      executionContext.getToken().addComment(new Comment("system", guess + " is too high!"));
      return "no";
    } else if (guess < number) {
      System.out.println("Too low!");
      executionContext.getToken().addComment(new Comment("system", guess + " is too low!"));
      return "no";
    } else {
      System.out.println("Great!");
      executionContext.getToken().addComment(new Comment("system", guess + " is great!"));
      return "yes";
    }
  }
}

Form definition

<?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 to guess" name="number" />
    <button name="submit" label="Submit" />
  </workflow-form>
  <workflow-form task="guess_a_number">
    <input label="Guess" name="guess" />
    <button name="submit" label="Submit" />
  </workflow-form>
</workflow-forms>