01: package org.emforge.jbpm.event;
02:
03: import org.emforge.jbpm.BpmVariable;
04: import org.emforge.jbpm.BpmServiceImpl;
05: import org.emforge.jbpm.ProcessTransformer;
06: import org.jbpm.context.exe.ContextInstance;
07: import org.jbpm.graph.def.ActionHandler;
08: import org.jbpm.graph.exe.ExecutionContext;
09: import org.jbpm.graph.exe.ProcessInstance;
10: import org.jbpm.graph.exe.Token;
11:
12: /** Event-Handler for propagating some values from parent process to subprocess
13: *
14: * For current moment it moves owner variable from parent process to subprocess
15: * and moves name of node to the description of subprocess
16: */
17: public class SubProcessCreatedEvent implements ActionHandler {
18: private static final long serialVersionUID = -7971904573310132853L;
19:
20: public void execute(ExecutionContext i_context) throws Exception {
21: Token token = i_context.getToken();
22: assert token != null;
23:
24: // first, get created subprocess
25: ProcessInstance subProcess = token.getSubProcessInstance();
26: //ProcessInstance subProcess = i_context.getSubProcessInstance();
27: assert subProcess != null;
28:
29: ContextInstance subContext = subProcess.getContextInstance();
30: assert subContext != null;
31:
32: /*
33: // get process owner
34: Object owner = i_context.getVariable(JbpmProcessDefImpl.OWNER_VARIABLE);
35: assert owner != null;
36:
37: subContext.setVariable(JbpmProcessDefImpl.OWNER_VARIABLE, owner);
38: */
39: // we will set current user as owner of new process
40: subContext.setVariable(BpmVariable.OWNER.getVariable(),
41: i_context.getJbpmContext().getActorId());
42:
43: // now, copy name of parent node to the description
44: subContext.setVariable(BpmVariable.TITLE.getVariable(),
45: i_context.getNode().getName());
46:
47: // propagate priority and process due date
48: BpmServiceImpl.setDueDate(subProcess, ProcessTransformer
49: .getDueDate(i_context.getProcessInstance()));
50: BpmServiceImpl.setPriority(subProcess, ProcessTransformer
51: .getPriority(i_context.getProcessInstance()));
52:
53: // and copy project
54: BpmServiceImpl.setProject(subProcess, ProcessTransformer
55: .getProject(i_context.getProcessInstance()));
56:
57: // I do not found any event logs related to creating this subprocess
58: // so, we will add one
59: }
60:
61: }
|