I can't find any documentation on how to dinamically create a task instance at
runtime. So the code below (and in previous post) is fruit of hours spend in trying ... I
achieved something that (seems to) works. And this is the result.
Maybe this is not the correct way, so any help needed!!
<?xml version="1.0" encoding="UTF-8"?>
|
| <process-definition
| xmlns="urn:jbpm.org:jpdl-3.1" name="Interpello">
| <swimlane name="startingUser">
| <assignment expression="user(admin)"></assignment>
| </swimlane>
| <start-state name="start">
| <transition name=""
to="inizioInterpello"></transition>
| </start-state>
| <end-state name="end1"></end-state>
| <task-node name="verificaFinale">
| <task name="verifica finale"
swimlane="startingUser"></task>
| <transition name="finito"
to="end1"></transition>
| <transition name="ripeti"
to="inizioInterpello"></transition>
| </task-node>
| <task-node name="inizioInterpello">
| <task name="inizio interpello"
swimlane="startingUser"></task>
| <event type="node-leave">
| <action name="actionIstruttoriaInterpello"
class="it.unict.interpello.IstruttoriaInterpello"></action>
| </event>
| <transition name="Convoca Interpello"
to="chiusuraInterpello"></transition>
| </task-node>
| <task-node name="tCompDoc">
| </task-node>
| <task-node name="chiusuraInterpello">
| <task name="Chiusura interpello"
swimlane="startingUser"></task>
| <event type="node-leave">
| <action name="actionChiudiInterpello"
class="it.unict.interpello.IstruttoriaInterpello"></action>
| </event>
| <transition name="procedi alla verifica finale"
to="verificaFinale"></transition>
| </task-node>
| <process-state name="process1"></process-state>
| <super-state name="super1"></super-state>
| </process-definition>
as you can see in the xml, I created a node-leave action handler, and I call the same
class (for testing purpose only) on leaving InizioInterpello and on leaving
ChiusuraInterpello.
Below you can read the code of the action handler.
When I execute the InizioInterpello task the code is executed: I can see the output
(System.out) and when I show the task list
(context.getProcessInstance(processInstanceId).getTaskMgmtInstance().getTaskInstances())
of the process instance I see a task for every user.
But If I execute ChiusuraInterpello I can't see no output, no new task instance were
created ... it seems that my action is ignored at all. But the task is closed correctly.
package it.unict.interpello;
|
|
| import it.unict.consulta.ManagerBeansProxy;
| import it.unict.consulta.driver.data.IDocente;
| import it.unict.consulta.driver.manager.IEducationManager;
|
| import java.util.Collection;
|
| import org.jbpm.graph.exe.ExecutionContext;
| import org.jbpm.graph.exe.Token;
| import org.jbpm.graph.node.TaskNode;
| import org.jbpm.taskmgmt.def.Task;
| import org.jbpm.taskmgmt.exe.TaskInstance;
| import org.jbpm.taskmgmt.exe.TaskMgmtInstance;
|
| public class IstruttoriaInterpello implements org.jbpm.graph.def.ActionHandler
| {
| ManagerBeansProxy mbProxy = null;
|
| public void execute(ExecutionContext executionContext) throws Exception
| {
|
System.out.println("qqqqq***********************************************************************");
| System.out.println("*** I can see this only when leaving InizioInterpello, but
nothing is shown when executing ChiusuraInterpello ***");
|
System.out.println("***********************************************************************");
|
System.out.println("***********************************************************************");
|
System.out.println("***********************************************************************");
|
System.out.println("***********************************************************************");
|
| mbProxy = new ManagerBeansProxy();
| IEducationManager edu = mbProxy.getMEducation();
|
| if (edu == null)
| throw new RuntimeException("EducationManager non disponibile");
|
| try
| {
| // determine the sets of users
| Collection<IDocente> lDoc = edu.listaDocenti();
|
| if (lDoc == null || lDoc.size() == 0)
| throw new RuntimeException("Nessun docente");
|
| // for each user creates a personal task instance
| for (IDocente d : lDoc)
| {
| String uname = d.getUsername();
| createAndAssignTask(uname, executionContext);
| }
| }
| catch (Exception ex)
| {
| System.out.println(ex);
| createAndAssignTask("admin", executionContext);
| }
| }
|
| public void createAndAssignTask(String user, ExecutionContext executionContext)
| {
| Token token = null;
| TaskMgmtInstance tmi = null;
| TaskNode taskNode = null;
|
| try
| {
| token = executionContext.getToken();
| tmi = executionContext.getTaskMgmtInstance();
| taskNode = (TaskNode) executionContext.getNode();
|
| // create the new task instance, a clone of tCompDoc
| Task doCompilaDocumento = taskNode.getTask("tCompDoc");
| TaskInstance tCompDoc = tmi.createTaskInstance(doCompilaDocumento, token);
|
| // set the name of the task, the actor that this task is assigned to, and set the
creation date
| tCompDoc.setName("consulta: convocazione " + user);
| tCompDoc.setActorId(user);
| tCompDoc.setCreate(token.getEnd());
|
| // build a variable
| tCompDoc.setVariableLocally("XXX"+user, "");
| // bind the newly created task instance to the task.
| tmi.addTaskInstance(tCompDoc);
| // print some outputs
|
System.out.println("***********************************************************************");
| System.out.println("creato: " + tCompDoc);
|
System.out.println("***********************************************************************");
| } catch (Exception ex)
| {
| ex.printStackTrace();
| }
| }
|
| }
|
What you say about the fork is correct, I think. But Actually I don't know how to bind
the newly created task instance to the rest of the process.
Infact the code that create the task doesn't do this.
Any idea on this?
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4138781#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...