Difference between revisions of "Workflow Course: Exercise 5"

From OpenKM Documentation
Jump to: navigation, search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
{{TOCright}} __TOC__
 +
 
== Step 1 - Use process instance objects between tasks ==
 
== Step 1 - Use process instance objects between tasks ==
 
 
The idea of this exercise is user put some number value at starting workflow and then in next form will be showed the introduced number multiplied by 3.
 
The idea of this exercise is user put some number value at starting workflow and then in next form will be showed the introduced number multiplied by 3.
  
Line 8: Line 9:
 
* Create a node where get the value introduced, multiply by 3 and store in new object.
 
* Create a node where get the value introduced, multiply by 3 and store in new object.
 
* Create a task where to show the number.
 
* Create a task where to show the number.
* Assign task to actor okmAdmin
+
* Assign task to actor ''okmAdmin''.
 +
 
 +
To store some object in workflow variable map, you should use:
 +
 
 +
<source lang="java">
 +
executionContext.getContextInstance().setVariable("modified", modified);
 +
</source>
  
To store some object in workflow variable map, you should use executionContext.getContextInstance().setVariable("modified", modified);
+
Remember that objects used in forms should extend '''FormElement'''. Take a look at [http://doxygen.openkm.com/5.1.x/d5/d89/namespacecom_1_1openkm_1_1bean_1_1form.html Doxygen documentation].
 +
 +
== Diagram ==
  
Remember objects used in forms should extend FormElement. Take a look here http://doxygen.openkm.com/5.1.x/d5/d89/namespacecom_1_1openkm_1_1bean_1_1form.html
+
[[File:Wf proc instances.png|center]]
  
[[File:Wf5.png]]
+
== Resources ==
 +
Example of '''forms.xml''':
  
'''forms.xml'''
 
 
<source lang="xml">
 
<source lang="xml">
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
Line 33: Line 42:
 
</source>
 
</source>
  
'''NodeAction.java'''
+
Example of '''NodeAction.java''':
 +
 
 
<source lang="java">
 
<source lang="java">
package com.openkm.workflow.exercise.exercise5;
+
package com.openkm.workflow.exercise.exercise4;
  
 
import org.jbpm.graph.def.ActionHandler;
 
import org.jbpm.graph.def.ActionHandler;
 
import org.jbpm.graph.exe.ExecutionContext;
 
import org.jbpm.graph.exe.ExecutionContext;
 +
import org.slf4j.Logger;
 +
import org.slf4j.LoggerFactory;
  
 
import com.openkm.bean.form.Input;
 
import com.openkm.bean.form.Input;
  
 
public class NodeAction implements ActionHandler {
 
public class NodeAction implements ActionHandler {
private static final long serialVersionUID = 1L;
+
    private static final long serialVersionUID = 1L;
 
+
    private static Logger log = LoggerFactory.getLogger(NodeAction.class);
@Override
+
   
public void execute(ExecutionContext executionContext) throws Exception {
+
    @Override
Input number = (Input) executionContext.getContextInstance().getVariable("number");
+
    public void execute(ExecutionContext executionContext) throws Exception {
int value = 0;
+
        log.info("Executing action");
if (number!=null) {
+
        Input number = (Input) executionContext.getContextInstance().getVariable("number");
value = Integer.valueOf(number.getValue());
+
        int value = 0;
} else {
+
       
value = 0;
+
        if (number != null) {
}
+
            value = Integer.valueOf(number.getValue());
value = value * 3;
+
        } else {
Input modified = new Input();
+
            value = 0;
modified.setName("modified");
+
        }
modified.setLabel("modified");
+
       
modified.setValue(String.valueOf(value*3));
+
        value = value * 3;
executionContext.getContextInstance().setVariable("modified", modified);
+
        Input modified = new Input();
}
+
        modified.setName("modified");
 +
        modified.setLabel("modified");
 +
        modified.setValue(String.valueOf(value * 3));
 +
        executionContext.getContextInstance().setVariable("modified", modified);
 +
    }
 
}
 
}
 
</source>
 
</source>
  
 +
[[Category: Workflow Guide]]
 
[[Category: Workflow Course]]
 
[[Category: Workflow Course]]

Latest revision as of 08:53, 18 June 2013

Step 1 - Use process instance objects between tasks

The idea of this exercise is user put some number value at starting workflow and then in next form will be showed the introduced number multiplied by 3.

For doing it you should:

  • Create two forms with inputs value, one to put the value and other to show the value multiplied by 3.
  • Create a node where get the value introduced, multiply by 3 and store in new object.
  • Create a task where to show the number.
  • Assign task to actor okmAdmin.

To store some object in workflow variable map, you should use:

executionContext.getContextInstance().setVariable("modified", modified);

Remember that objects used in forms should extend FormElement. Take a look at Doxygen documentation.

Diagram

Wf proc instances.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="number" name="number" data="modified" />
    <button name="submit" label="Submit" />
  </workflow-form>
</workflow-forms>

Example of NodeAction.java:

package com.openkm.workflow.exercise.exercise4;

import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.openkm.bean.form.Input;

public class NodeAction implements ActionHandler {
    private static final long serialVersionUID = 1L;
    private static Logger log = LoggerFactory.getLogger(NodeAction.class);
    
    @Override
    public void execute(ExecutionContext executionContext) throws Exception {
        log.info("Executing action");
        Input number = (Input) executionContext.getContextInstance().getVariable("number");
        int value = 0;
        
        if (number != null) {
            value = Integer.valueOf(number.getValue());
        } else {
            value = 0;
        }
        
        value = value * 3;
        Input modified = new Input();
        modified.setName("modified");
        modified.setLabel("modified");
        modified.setValue(String.valueOf(value * 3));
        executionContext.getContextInstance().setVariable("modified", modified);
    }
}