4 Replies Latest reply on Nov 30, 2005 9:35 AM by babas1

    JDPL - Two roles performing same task

    brittm Novice

      You cannot assign two swimlanes to the same state/task--that would be conceptually contradictory. What you are doing is, in essence, defining a new and separate role/swimlane. If you don't want to define a new group across your systems, you may want to define the new swimlane in the process definition and handle who can see/access/complete states that are assigned to that swimlane in your user interface.

      -Britt

        • 1. Re: JDPL - Two roles performing same task
          Enrique Ruiz Newbie

          The new AssignmentHandler interface introduced in jBPM 3.0 gives you the control to assign tasks, you can develop your own assignment policy.

          • 3. Re: JDPL - Two roles performing same task
            babas1 Newbie

            As shown in http://www.jboss.com/index.html?module=bb&op=viewtopic&t=72818

            It is easy to use the delegation mechanism in Jbpm 3.0 to code our own AssignmentHandler :

            public class MyAssignmentClass implements AssignmentHandler {
            ...
             String myFieldA;
             String myFieldB;
            ...
            
             public void assign(Assignable assignable, ExecutionContext executionContext) {
            ...
             }


            But does anyone have a sample of the code in assign(..) method ?
            As for my problem, I would like to return a new group built from two real groups from the database. So that all the actor in the two groups can run the task calling the handler.
            Thank you ...


            • 4. Re: JDPL - Two roles performing same task
              babas1 Newbie

              Here is my example, it works for my purpose waiting that Jbpm includes its own feature "children group or nested groups".

              In your process definition :

              <swimlane name="start" >
               <assignment class="package.MergeGroupsAssignmentHandler">
               <groupList>aisi;businessTeam</groupList>
               </assignment>
              </swimlane>
              
              <start-state name="launch">
               <task swimlane="start"><controller/></task>
               <transition name="launch.ok" to="init" />
              </start-state>
              


              Here is the Handler code :

              package package;
              
              import org.apache.commons.logging.Log;
              import org.apache.commons.logging.LogFactory;
              import org.jbpm.db.JbpmSession;
              import org.jbpm.db.JbpmSessionFactory;
              import org.jbpm.graph.exe.ExecutionContext;
              import org.jbpm.identity.Group;
              import org.jbpm.identity.hibernate.IdentitySession;
              import org.jbpm.taskmgmt.def.AssignmentHandler;
              import org.jbpm.taskmgmt.exe.Assignable;
              
              /**
               * Specific handler to merge some groups, so that the task can be done by any member of the merged groups.
               *
               * @author Sébastien NOEL - Dexia BIL
               */
              public class MergeGroupsAssignmentHandler implements AssignmentHandler
              {
               /** Fully qualified class name. */
               static private final String FQCN = MergeGroupsAssignmentHandler.class.getName();
              
               /** Our logger. */
               static private Log log = LogFactory.getLog(MergeGroupsAssignmentHandler.class);
              
               /** Configuration given by the handler definition in the process definition. It must be a semi colon separated values like "group1;group2". */
               public String groupList = null;
              
               /** Required for serialization. */
               static private final long serialVersionUID = 1L;
              
              
               /**
               * Check the <code>groupsName</code> values. They should be a list of existing groups.
               * @exception Exception Thrown if check failed.
               */
               private void checkGroupList(String[] groupsName) throws Exception
               {
               if (groupsName == null) {
               throw new Exception("groupsName parameter is null");
               }
              
               JbpmSession jbpmSession = JbpmSessionFactory.getInstance().openJbpmSession();
               jbpmSession.beginTransaction(); // really needed in Read only mode ? But no overhead (even not 1 ms !)
               IdentitySession iSession = new IdentitySession(jbpmSession.getSession());
               for (int idx = 0; idx < groupsName.length; idx++) {
               Group group = iSession.getGroupByName(groupsName[idx]);
               if (group == null) {
               throw new Exception("Check your handler configuration : group called '"+ groupsName[idx]+"' can't be found in the system.");
               }
               }
               jbpmSession.commitTransaction();
               jbpmSession.close();
              
               }
              
               /** Basic constructor. It is called at each access to this handler mechanism. */
               public MergeGroupsAssignmentHandler() {
               }
              
               /**
               * Splits the configuration into an array of group name.
               *
               * @exception Exception Thrown on incorrect configuration.
               */
               private String[] analyseConfiguration() throws Exception
               {
               final String localMethodName = FQCN + ".analyseConfiguration()";
               if (this.groupList == null || "".equals(this.groupList.trim())) {
               throw new Exception("Handler configuration incorrect : expected group list for parameter groupList='"+ this.groupList +"' ("+ localMethodName +")");
               }
              
               String[] tokens = this.groupList.split(";");
               if (log.isDebugEnabled()) {
               StringBuffer sb = new StringBuffer();
               for (int idx=0; idx < tokens.length; idx++) {
               sb.append("'").append(tokens[idx]).append("', ");
               }
               log.debug(localMethodName + " Found from configuration : ["+ sb.toString() + "].");
               }
              
               return tokens;
               }
              
               /**
               * Concatenates all the groups name given by {@link #groupList} into the <code>assignable</code>.
               */
               public void assign(Assignable assignable, ExecutionContext executionContext) throws Exception
               {
               long start = System.currentTimeMillis();
               final String localMethodName = FQCN + ".assign(Assignable assignable, ExecutionContext executionContext)";
              
               String[] groupsName = analyseConfiguration();
               checkGroupList(groupsName);
               assignable.setPooledActors(groupsName);
              
               log.debug(localMethodName + "Time elapsed : "+ (System.currentTimeMillis() - start) +" ms.");
               }
              }
              


              I hope this could help ...