Difference between revisions of "Workflow Course: Exercise 7"
From OpenKM Documentation
(Created page with '== Step 1 - How user can assign task to other == The idea of this exercise is one user assign a task to other For doing it you should: * Create two forms in one user will set t…') |
(→Resources) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | {{TOCright}} __TOC__ | ||
+ | |||
== Step 1 - How user can assign task to other == | == Step 1 - How user can assign task to other == | ||
+ | The idea of this exercise is one user assign a task to other. | ||
− | + | To do it you should: | |
− | |||
* Create two forms in one user will set the user who will execute the next task. | * Create two forms in one user will set the user who will execute the next task. | ||
− | * First task will be assigned to user okmAdmin. | + | * First task will be assigned to user ''okmAdmin''. |
− | * Create a class which implements AssignmentHandler and assign to taks2. | + | * Create a class which implements '''AssignmentHandler''' and assign to '''taks2'''. |
+ | |||
+ | == Diagram == | ||
+ | |||
+ | [[File:Wf assignment.png|center]] | ||
− | + | == Resources == | |
+ | Example of '''forms.xml''': | ||
− | |||
<source lang="xml"> | <source lang="xml"> | ||
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||
Line 16: | Line 22: | ||
"http://www.openkm.com/dtd/workflow-forms-2.1.dtd"> | "http://www.openkm.com/dtd/workflow-forms-2.1.dtd"> | ||
<workflow-forms> | <workflow-forms> | ||
− | <workflow-form task=" | + | <workflow-form task="task1"> |
− | + | <input label="username" name="username" /> | |
<button name="submit" label="Submit" /> | <button name="submit" label="Submit" /> | ||
</workflow-form> | </workflow-form> | ||
Line 26: | Line 32: | ||
</source> | </source> | ||
− | ''' | + | Example of '''ActorAssignment.java''': |
+ | |||
<source lang="java"> | <source lang="java"> | ||
− | package com.openkm.workflow.exercise. | + | package com.openkm.workflow.exercise.exercise6; |
import org.jbpm.graph.exe.ExecutionContext; | import org.jbpm.graph.exe.ExecutionContext; | ||
import org.jbpm.taskmgmt.def.AssignmentHandler; | import org.jbpm.taskmgmt.def.AssignmentHandler; | ||
import org.jbpm.taskmgmt.exe.Assignable; | import org.jbpm.taskmgmt.exe.Assignable; | ||
+ | import org.slf4j.Logger; | ||
+ | import org.slf4j.LoggerFactory; | ||
import com.openkm.bean.form.Input; | import com.openkm.bean.form.Input; | ||
public class ActorAssigment implements AssignmentHandler { | public class ActorAssigment implements AssignmentHandler { | ||
− | + | private static final long serialVersionUID = 1L; | |
− | + | private static Logger log = LoggerFactory.getLogger(ActorAssigment.class); | |
− | + | ||
− | + | @Override | |
− | + | public void assign(Assignable assignable, ExecutionContext executionContext) throws Exception { | |
− | + | log.info("Evaluating assigment"); | |
− | + | Input username = (Input) executionContext.getContextInstance().getVariable("username"); | |
− | + | ||
− | + | if (username != null) { | |
− | + | log.info("Task assigned to '{}'", username.getValue()); | |
− | + | assignable.setActorId(username.getValue()); | |
− | + | } else { | |
− | + | log.info("Task assigned to 'okmAdmin'"); | |
− | + | assignable.setActorId("okmAdmin"); | |
+ | } | ||
+ | } | ||
} | } | ||
</source> | </source> | ||
+ | [[Category: Workflow Guide]] | ||
[[Category: Workflow Course]] | [[Category: Workflow Course]] |
Latest revision as of 11:03, 20 February 2015
Step 1 - How user can assign task to other
The idea of this exercise is one user assign a task to other.
To do it you should:
- Create two forms in one user will set the user who will execute the next task.
- First task will be assigned to user okmAdmin.
- Create a class which implements AssignmentHandler and assign to taks2.
Diagram
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="task1">
<input label="username" name="username" />
<button name="submit" label="Submit" />
</workflow-form>
<workflow-form task="task2">
<button name="submit" label="Submit" />
</workflow-form>
</workflow-forms>
Example of ActorAssignment.java:
package com.openkm.workflow.exercise.exercise6;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.taskmgmt.def.AssignmentHandler;
import org.jbpm.taskmgmt.exe.Assignable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.openkm.bean.form.Input;
public class ActorAssigment implements AssignmentHandler {
private static final long serialVersionUID = 1L;
private static Logger log = LoggerFactory.getLogger(ActorAssigment.class);
@Override
public void assign(Assignable assignable, ExecutionContext executionContext) throws Exception {
log.info("Evaluating assigment");
Input username = (Input) executionContext.getContextInstance().getVariable("username");
if (username != null) {
log.info("Task assigned to '{}'", username.getValue());
assignable.setActorId(username.getValue());
} else {
log.info("Task assigned to 'okmAdmin'");
assignable.setActorId("okmAdmin");
}
}
}