hi,

I post my java file, where I create my process and try to use the swimlane.


  | package com.opensymphony.webwork.portlet.tutorial;
  | 
  | import java.util.*;
  | import java.util.ArrayList;
  | 
  | 
  | import org.jbpm.graph.def.ProcessDefinition;
  | import org.jbpm.graph.exe.ProcessInstance;
  | import org.jbpm.db.*;
  | import org.jbpm.graph.exe.Token;
  | import org.jbpm.taskmgmt.exe.*; 
  | import org.jbpm.taskmgmt.log.TaskCreateLog;
  | import org.jbpm.graph.exe.*;
  | 
  | import com.opensymphony.xwork.ActionContext;
  | import com.opensymphony.xwork.ActionSupport;
  | import org.jbpm.*;
  | 
  | import org.jbpm.taskmgmt.def.*;
  | 
  | public class CreateProcessInstanceAction extends ActionSupport{
  |     
  |     private String nameProcess;
  |     private String currentNode;
  | 
  |     static JbpmConfiguration jbpmConfiguration = null;
  |     static ProcessDefinition processDefinition= null;
  |     ProcessInstance pi= null;
  |     JbpmContext     jbpmContext = 
JbpmConfiguration.getInstance().createJbpmContext();
  |     Map session = (Map) ActionContext.getContext().get("session");
  |     SwimlaneInstance si =null;
  |     ExecutionContext ec=null;
  |     
  |     public void setNameProcess(String nameProcess) {
  |             System.out.println("set NameProcess");
  |             this.nameProcess = nameProcess;
  |     }
  |     
  |     public String getNameProcess() {
  |             System.out.println("get NameProcess");
  |             return nameProcess;
  |     }
  |     
  |     public void setCurrentNode(String currentNode) {
  |             System.out.println("set currentNode");
  |             this.currentNode = currentNode;
  |     }
  |     
  |     public String getCurrentNode() {
  |             System.out.println("get currentNode");
  |             return currentNode;
  |     }
  |     
  |     public Long instantiate(ProcessDefinition pd, String userId) {
  |         Long instanceId = null;
  |         System.out.println("JBPM session factory");
  |         JbpmSessionFactory jbpmSessionFactory = 
JbpmSessionFactory.getInstance();
  |         System.out.println("JBPM session");
  |         JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSession(); 
  |         System.out.println("Graph session");
  |         GraphSession graphSession = jbpmSession.getGraphSession();
  |         System.out.println("Task management");
  |         TaskMgmtSession taskMgmtSession = jbpmSession.getTaskMgmtSession();
  |         System.out.println("instance des session ok");
  |         
  |         System.out.println("process definition instance");
  |         System.out.println("PROCESS NAME:"+ pd.getName());
  |         jbpmSession.beginTransaction();
  |         pi = new ProcessInstance(pd);
  |         System.out.println("PROCESS  INSTANCE ID:"+ pi.getId());
  |         //This ensures that all swimlanes are initialized and available for 
reporting and reassignment immediately.
  |         //If we don't initialize them up front, they won't be created until 
a task calls for them.
  |         
  |         Map swimlanes = pd.getTaskMgmtDefinition().getSwimlanes();
  |         Iterator itr = swimlanes.keySet().iterator();
  |         while(itr.hasNext()) {
  |             Swimlane swimlane = (Swimlane)swimlanes.get(itr.next());
  |             System.out.println("SWIMLANE CREE:"+ swimlane.getName());       
                
  |                     
  |                      swimlane.setPooledActorsExpression("ernie");
  |                      swimlane.setPooledActorsExpression("bert");
  |             
  |             
  |             System.out.println("ID porcess "+pi.toString());
  |             System.out.println(pi.getRootToken().toString());
  |             System.out.println(pi.getRootToken().getName());
  |             ec= new ExecutionContext(pi.getRootToken());
  |             System.out.println("execution context reussi");
  |             System.out.println("token lancer:"+ec.getToken().getName());
  |             
  |             
  |             SwimlaneInstance swi = 
pi.getTaskMgmtInstance().getInitializedSwimlaneInstance(ec, swimlane);
  |             
  |           
  |             System.out.println("swimlane instance good : "+swi.getName());
  |             //We have to do this cause it doesn't automatically happen when 
we
  |             // call swimlaneInstance.setPooledActors()
  |             System.out.println("pooled actors");
  |             Set pooledActors = swi.getPooledActors();
  |             if(pooledActors != null) {
  |                 Iterator paItr = pooledActors.iterator();
  |                 while(paItr.hasNext()) {
  |                     ( (PooledActor)paItr.next() ).setSwimlaneInstance(swi);
  |                 }
  |             }
  |         }
  | 
  |         //If this process definition defines a startTask in the StartState, 
we'll have to
  |         // explicitly create it--it won't be created otherwise...
  |         if (pd.getTaskMgmtDefinition().getStartTask() != null) {
  |             
  |             //When we create the startTaskInstance, the start task will be 
assigned
  |             // to the currently authenticated user (as understood by Jbpm), 
and that
  |             // data WILL overwrite any default swimlane assignments, as 
well as update
  |             // the actual swimlaneInstance itself.  The swimlaneInstance's 
pooledActors will be NULL
  | 
  |             // To preserve any original assignments to the 
swimlaneInstance, we'll have
  |             // to record that data now and re-set it in the 
swimlaneInstance after the
  |             // startTaskInstance has been created.
  |             org.jbpm.taskmgmt.def.Task task = 
pd.getTaskMgmtDefinition().getStartTask();
  |             String swimlaneName = task.getSwimlane().getName();
  |             SwimlaneInstance swi = 
pi.getTaskMgmtInstance().getSwimlaneInstance(swimlaneName);
  |             String originalActorId = swi.getActorId();
  |             Set originalPooledActors = swi.getPooledActors();
  |             System.out.println("taskinstance");
  |             TaskInstance startTask = 
pi.getTaskMgmtInstance().createStartTaskInstance();
  |             System.out.println("task instance name: "+startTask.getName());
  |             //Unless our application's authentication scheme has been tied 
into Jbpm's, we
  |             // should manually assign the startTask to a user as well as 
manually set the swimlane actors
  |             // referenced by this task, otherwise both will be null.
  |             System.out.println("set actor ID a task instance");
  |             startTask.setActorId(userId);
  |             
  |             if(startTask.getSwimlaneInstance() != null) {
  |                     System.out.println("startTask.getSwimlaneInstance() != 
null");
  |               System.out.println("Swimlane assigned actor: " + 
startTask.getSwimlaneInstance().getActorId());
  |              si = startTask.getSwimlaneInstance();
  |             System.out.println(si.getName());
  |              
  |               System.out.println("test pour voir");
  |                 startTask.getSwimlaneInstance().setActorId(userId);
  |                
  |                 
  |                 //Currently, no pooledActors are being set
  |                 
  |                 //swi.setPooledActors(originalPooledActors);
  |                 
//startTask.getSwimlaneInstance().setPooledActors(originalPooledActors);
  |                 if (startTask.getSwimlaneInstance().getPooledActors() != 
null) {
  |                     
System.out.println("startTask.getSwimlaneInstance().getPooledActors() != null");
  |                     System.out.println("Swimlane assigned pooled actor: " + 
( 
(PooledActor)(startTask.getSwimlaneInstance().getPooledActors().iterator().next())
 ).getActorId() );
  |                 }
  |                 System.out.println("NOM DE LA 
TACHE////::"+startTask.getName());
  |                 
  |                 //////////////////////////////
  |               //  jbpmSession.getSession().save(swi);
  |                 //////////////////////////////
  |             }
  |             
  |         }else {
  |             //If our new process doesn't have a startTask defined, we may 
want to get the new process rolling...
  |             // Although, some executions may want to set process variables, 
etc. before
  |             // continuing, in which case they should do such and signal for 
themselves.
  |             //pi.signal();
  |             
System.out.println("################################else#########################################");
  |         }
  |        
  |         System.out.println("graphsession enregistre le porcess instance");
  |       //graphSession.saveProcessInstance(pi);
  |        System.out.println("OK");
  |         jbpmSession.commitTransaction();
  |       
  |         instanceId = Long.valueOf(pi.getId());
  |         jbpmSession.close();
  |         
  |         return instanceId;
  |     }
  |     @Override
  |     public String execute() throws Exception {
  |             
  |             System.out.println("#### execute");
  |             System.out.println("Create process instance" );
  |               // This method shows a process definition and one execution
  |               // of the process definition.  The process definition has 
  |               // 3 nodes: an unnamed start-state, a state 's' and an 
  |               // end-state named 'end'.
  |               // The next line parses a piece of xml text into a
  |               // ProcessDefinition.  A ProcessDefinition is the formal 
  |               // description of a process represented as a java object.
  |              
  |             processDefinition = ProcessDefinition.parseXmlString(
  |             
  | 
  |                             "<process-definition   
name='DeclarationSinistre'>"+
  |                             "<swimlane name='F*' >"+
  |                                     "<assignment 
expression='user(ernie)'/>"+
  |                                     "</swimlane>"+
  |             
  |                                     "<swimlane name='A*' >"+
  |                                     "<assignment expression='user(bert)'/>"+
  |                                     "</swimlane>"+
  |                                     
  |                                     
  |                                "<start-state name='start'>"+
  |                                  "<task swimlane='F*'>"+
  |                                   "</task>"+
  |                                   "<transition name='' 
to='DeclarationSinistre'>"+"</transition>"+
  |                                "</start-state>"+
  |                                
  |                                "<end-state name='end'>"+"</end-state>"+
  |                                
  |                                "<task-node name='DeclarationSinistre'>"+
  |                                    "<task swimlane='F*'>"+
  |                                   "</task>"+
  |                                   "<transition name='' 
to='EnregistrementSinistre'>"+"</transition>"+
  |                                "</task-node>"+
  |                                
  |                                "<task-node name='EnregistrementSinistre'>"+
  |                                   "<task swimlane='A*'>"+
  |                                   "</task>"+
  |                                   "<transition name='' 
to='ControlePrime'>"+"</transition>"+
  |                                "</task-node>"+
  |                                
  |                                "<task-node name='ControlePrime'>"+
  |                                "<task swimlane='F*'>"+
  |                                   "</task>"+
  |                                   "<transition name='OK' 
to='fork1'>"+"</transition>"+
  |                                   "<transition name='SinistreHorsClause' 
to='HorsClause'>"+"</transition>"+
  |                                   "<transition name='PrimeNonPayee' 
to='RelancePaiement'>"+"</transition>"+
  |                                "</task-node>"+
  |                                
  |                                "<task-node name='RelancePaiement'>"+
  |                                "<task swimlane='A*'>"+
  |                                   "</task>"+
  |                                   "<transition name='' 
to='ControlePrime'>"+"</transition>"+
  |                                "</task-node>"+
  |                                
  |                                "<task-node name='HorsClause'>"+
  |                                "<task swimlane='F*'>"+
  |                                   "</task>"+
  |                                             "<transition name='' 
to='end'>"+"</transition>"+
  |                                "</task-node>"+
  |                                
  |                                "<task-node name='TraitementSinistre'>"+
  |                                "<task swimlane='A*'>"+
  |                                   "</task>"+
  |                                   "<transition name='' 
to='join1'>"+"</transition>"+
  |                                "</task-node>"+
  |                                
  |                                "<task-node name='ExtractionDonnées'>"+
  |                                "<task swimlane='F*'>"+
  |                                   "</task>"+
  |                                   "<transition name='' 
to='transfertDonnées'>"+"</transition>"+
  |                                "</task-node>"+
  |                                
  |                                "<task-node name='transfertDonnées'>"+
  |                                "<task swimlane='A*'>"+
  |                                   "</task>"+
  |                                   "<transition name='' 
to='join1'>"+"</transition>"+
  |                                "</task-node>"+
  |                                
  |                                "<fork name='fork1'>"+
  |                                   "<transition name='' 
to='TraitementSinistre'>"+"</transition>"+
  |                                   "<transition name='tr2' 
to='ExtractionDonnées'>"+"</transition>"+
  |                                "</fork>"+
  |                                
  |                                "<join name='join1'>"+
  |                                   "<transition name='' 
to='end'>"+"</transition>"+
  |                                "</join>"+
  |                                
  |                             "</process-definition>"
  |               );
  |             System.out.println("################## debut jbpm configuration 
#############"); 
  |             
  |             jbpmConfiguration = JbpmConfiguration.parseXmlString(
  |                   "<jbpm-configuration>" +
  |                   
  |                   // A jbpm-context mechanism separates the jbpm core 
  |                   // engine from the services that jbpm uses from 
  |                   // the environment.  
  |                   
  |                   "  <jbpm-context>" +
  |                   "    <service name='persistence' " +
  |                   "             
factory='org.jbpm.persistence.db.DbPersistenceServiceFactory' />" + 
  |                   "  </jbpm-context>" +
  |                   
  |                   // Also all the resource files that are used by jbpm are 
  |                   // referenced from the jbpm.cfg.xml
  |                   
  |                   "  <string name='resource.hibernate.cfg.xml' " +
  |                   "          value='hibernate.cfg.xml' />" +
  |                   "  <string name='resource.business.calendar' " +
  |                   "          
value='org/jbpm/calendar/jbpm.business.calendar.properties' />" +
  |                   "  <string name='resource.default.modules' " +
  |                   "          
value='org/jbpm/graph/def/jbpm.default.modules.properties' />" +
  |                   "  <string name='resource.converter' " +
  |                   "          
value='org/jbpm/db/hibernate/jbpm.converter.properties' />" +
  |                   "  <string name='resource.action.types' " +
  |                   "          value='org/jbpm/graph/action/action.types.xml' 
/>" +
  |                   "  <string name='resource.node.types' " +
  |                   "          value='org/jbpm/graph/node/node.types.xml' />" 
+
  |                   "  <string name='resource.varmapping' " +
  |                   "          
value='org/jbpm/context/exe/jbpm.varmapping.xml' />" +
  |                   "</jbpm-configuration>"
  |                 );
  | 
  |     
  |             
  |             Long longVariable = instantiate(processDefinition, "ernie");    
  |             try{
  |                     Token token = pi.getRootToken();
  |                     nameProcess=pi.getProcessDefinition().getName();
  |                    // System.out.println("avant affectation user");
  |                    // jbpmContext.setActorId("ernie");
  |                    // System.out.println("affectation user effectuer ok");
  |                    // System.out.println("nom de l'utilisateur est:"+ 
jbpmContext.getActorId());
  |                 this.setNameProcess(nameProcess);
  |                     token.signal();
  |                     
  |                 currentNode=token.getNode().getName();
  |                 this.setCurrentNode(currentNode);
  |                 System.out.println("noeud courant:"+currentNode);
  |                 jbpmContext.save(token);
  |                 System.out.println("############## save token good#######");
  |                 jbpmContext.save(pi);
  |                 System.out.println("############## save process 
good#######");
  |                     Map session = (Map) 
ActionContext.getContext().get("session");
  |                       session.put("process",pi);
  |                       session.put("jbpmContext",jbpmContext);
  |                       System.out.println("cuicuiactorid: 
"+jbpmContext.getActorId());
  |                       session.put("processName",nameProcess);
  |                       session.put("processDefiniton",processDefinition);
  |                       session.put("ec",ec);
  |                       session.put("si",si);
  |             }
  |             finally {
  |                     System.out.println("dans finally");
  |                 //jbpmContext.close();
  |                 System.out.println("fermeture du context");
  |             }
  |             
  |                       
  |               return SUCCESS;
  |     }
  | }

I hope you will see where my error or my missing. 

thank you very much for you help. I will try to see you way of problem of 
execution of the swimlane.

antitrust1982

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3967739#3967739

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3967739

_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to