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 [EMAIL PROTECTED]
#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 ...
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3909763#3909763
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3909763
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user