Assigning a task exercise to another user.

 

The purpose of this exercise is to explain how one user assigns a task to another.

To do this, you should:

  • Create two forms, in one of them the user will setup the task that will be executed by the other user.
  • First task will be assigned to user "okmAdmin".
  • Create a class which implements AssignmentHandler and assign to taks2.

Diagram

Resources

File 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>

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