01: /**
02: *
03: */package org.emforge.jbpm.assigner;
04:
05: import java.util.Collection;
06:
07: import org.apache.commons.lang.StringUtils;
08: import org.emforge.jbpm.BpmVariable;
09: import org.jbpm.context.def.VariableAccess;
10: import org.jbpm.graph.exe.ExecutionContext;
11: import org.jbpm.taskmgmt.def.AssignmentHandler;
12: import org.jbpm.taskmgmt.def.TaskController;
13: import org.jbpm.taskmgmt.exe.Assignable;
14:
15: /** Task Assigment Handler
16: *
17: * This class is responsible for task assigment.
18: * He get information about assigned persone from "assignTo" attribute.
19: */
20: public class ToDoTaskAssignmentHandler implements AssignmentHandler {
21: private static final long serialVersionUID = -2806706854629810246L;
22:
23: /** Assigns task according to variable ASSIGNTO_VARIABLE
24: *
25: * (non-Javadoc)
26: * @see org.jbpm.taskmgmt.def.AssignmentHandler#assign(org.jbpm.taskmgmt.exe.Assignable, org.jbpm.graph.exe.ExecutionContext)
27: */
28: @SuppressWarnings("unchecked")
29: public void assign(Assignable i_assignable,
30: ExecutionContext i_executionContext) throws Exception {
31: // first - we need to get the role name, we should use for assignment
32: String roleName = null;
33:
34: TaskController taskController = i_executionContext.getTask()
35: .getTaskController();
36: if (taskController != null) {
37: Collection<VariableAccess> variableAccesses = taskController
38: .getVariableAccesses();
39: for (VariableAccess va : variableAccesses) {
40: if (va.getVariableName().startsWith(
41: BpmVariable.ASSIGNEDTO.getVariable())) {
42: roleName = va.getVariableName()
43: .substring(
44: BpmVariable.ASSIGNTO.getVariable()
45: .length() + 1);
46: break;
47: }
48: }
49: }
50:
51: Object assignTo = null;
52: if (roleName == null) {
53: assignTo = i_executionContext
54: .getVariable(BpmVariable.ASSIGNTO.getVariable());
55: } else {
56: assignTo = i_executionContext
57: .getVariable(BpmVariable.ASSIGNTO.getVariable()
58: + "_" + roleName);
59: }
60:
61: assert (StringUtils.isNotEmpty((String) assignTo));
62: i_assignable.setActorId((String) assignTo);
63: }
64:
65: }
|