4 Replies Latest reply on Dec 20, 2005 4:22 AM by rafa perez

    asign swimlanes in execution time

    rafa perez Newbie

      hi again,
      i need to asign diferents activities to diferents swimlanes in execution time. That is, in some activity i want to do a role assigment of the next activity to some role (swimlane).

      Thas's posible??

      A lot of thanks friends!

      Rafael.

        • 1. Re: asign swimlanes in execution time
          brittm Novice

          I'm not sure that I understand your question; however, if you mean that at runtime you want to determine to which swimlane a task belongs, I would think that that violates the concept of a swimlane.

          Never the less, what you could do to make things work, is define swimlanes in the process definition but don't associated tasks with them. When you begin execution on an instance, assign actors to the swimlanes and as execution continues, you could:
          1. programatically determine which "role" you need to associated to a given task,
          2. read the actor from the appropriate swimlane that represents that role,
          3. and assign that actor to the task.

          While I can't say that this would never be a valid scenario, if I found myself needing to do something like this I would first go back and re-evaluate the way I've concieved of my process before continuing.

          -Britt

          • 2. Re: asign swimlanes in execution time
            rafa perez Newbie

            Hi,
            yes brittm it's my question.

            I need to assign swimlanes to activities in runtime.

            The scenario:

            Is a process to process complaints from cityzens. The citycounting receive the complaints from a cityzen and send it to one departament, them the next activity is procecesed to the departament implicated. If i have a lot of departaments i need to do this asociation between activities and swimlanes at runtime.

            Now i know that it's posible, but how can i do this?

            Thnks,
            Rafael.

            • 3. Re: asign swimlanes in execution time
              brittm Novice

              From your description, it sounds like you just need to wait to assign an actor to your swimlane until you know which department it will be.

              1) If you know which department should handle the complaint when the complaint is first received (the citizen specified which one), then your assignment handler could simply set the appropriate department.

              2) However, if you won't know which department should handle the complaint until a worker analyzes the complaint, then try creating a "department" swimlane with no default actor assignment, and allow the worker to effect a jBPM API call that sets the "department" swimlane's ownership once the department has been determined.

              Ok, that all sounds great, except...By default, Swimlanes are not initialized and available for reassignment until a Task that is associated with the swimlane is instantiated. So, to have some one assign the swimlane prior to the to process being passed on to a department (and a "department" task being instantiated), you may need to initialize your swimlanes manually when your process is first initialized. This is a method I use to instantiate all my processes; take from it what you need:

              public Long instantiate(String processDefinitionName, String userId) {
               Long instanceId = null;
              
               JbpmSessionFactory jbpmSessionFactory = JbpmSessionFactory.getInstance();
               JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSession();
               GraphSession graphSession = jbpmSession.getGraphSession();
               TaskMgmtSession taskMgmtSession = jbpmSession.getTaskMgmtSession();
              
               ProcessDefinition pd = graphSession.findLatestProcessDefinition(processDefinitionName);
               jbpmSession.beginTransaction();
               ProcessInstance pi = new ProcessInstance(pd);
              
               //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());
               SwimlaneInstance swi = pi.getTaskMgmtInstance().getInitializedSwimlaneInstance(new ExecutionContext(pi.getRootToken()), swimlane);
               //We have to do this cause it doesn't automatically happen when we
               // call swimlaneInstance.setPooledActors()
               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();
              
               TaskInstance startTask = pi.getTaskMgmtInstance().createStartTaskInstance();
              
               //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.
               startTask.setActorId(userId);
              
               if(startTask.getSwimlaneInstance() != null) {
               log.debug("Swimlane assigned actor: " + startTask.getSwimlaneInstance().getActorId());
               startTask.getSwimlaneInstance().setActorId(userId);
              
               //Currently, no pooledActors are being set
              
               //swi.setPooledActors(originalPooledActors);
               //startTask.getSwimlaneInstance().setPooledActors(originalPooledActors);
               if (startTask.getSwimlaneInstance().getPooledActors() != null) {
               log.debug("Swimlane assigned pooled actor: " + ( (PooledActor)(startTask.getSwimlaneInstance().getPooledActors().iterator().next()) ).getActorId() );
               }
               //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();
               }
              
               graphSession.saveProcessInstance(pi);
               jbpmSession.commitTransaction();
              
               instanceId = Long.valueOf(pi.getId());
               jbpmSession.close();
               return instanceId;
               }


              • 4. Re: asign swimlanes in execution time
                rafa perez Newbie

                Thanks brittm,
                i'm going to try it!!