AnsweredAssumed Answered

requirement for config assignee mode

Question asked by woodfox on Jul 16, 2014
Latest reply on Jul 22, 2014 by jbarrez
I am a new developer for Activiti, I have a requirement for some kind of assignee  configuration:

suppose customer has a group “GM" which has three user : gm0, gm1, gm2

when we design process, we have a user task for the GM Audit node, our customer want to control a flag so that they can control the audit behaviors :

if flag is true :

the audit task can be completed by all users in GM group that completed their task instances,

in this case, we create a multi instance use task and it create the task instances according to the assigneeList


if flag is false :

the audit task can be completed by one of the users in GM group that completed his task instance,

in this case, we can set candidate groups value to "GM".


they all work fine, however the problem is : we can't use a process define for both of them !

I have try the following way :

set a collection of User bean for the multi instance :



public class User {
   
    private String assignee;
    private String groups;

   ….
}



then set value ${user.assignee} for "assignee" property and value ${assignee.groups} for "candidate groups" property

and


   if(flag){
      assigneeList.add(new User("gm0"));
      assigneeList.add(new User("gm1"));
      assigneeList.add(new User("gm2"));
   }else{
      User u = new User();
      u.setGroups("GM");
      assigneeList.add(u);
   }



well… this code does't work because I found the code in handleAssignments() method at org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior


   if (!taskDefinition.getCandidateGroupIdExpressions().isEmpty()) {
      for (Expression groupIdExpr : taskDefinition.getCandidateGroupIdExpressions()) {
        Object value = groupIdExpr.getValue(execution);
        if (value instanceof String) {
          List<String> candiates = extractCandidates((String) value);
          task.addCandidateGroups(candiates);
        } else if (value instanceof Collection) {
          task.addCandidateGroups((Collection) value);
        } else {
          throw new ActivitiIllegalArgumentException("Expression did not resolve to a string or collection of strings");
        }
      }
    }

    if (!taskDefinition.getCandidateUserIdExpressions().isEmpty()) {
      for (Expression userIdExpr : taskDefinition.getCandidateUserIdExpressions()) {
        Object value = userIdExpr.getValue(execution);
        if (value instanceof String) {
          List<String> candiates = extractCandidates((String) value);
          task.addCandidateUsers(candiates);
        } else if (value instanceof Collection) {
          task.addCandidateUsers((Collection) value);
        } else {
          throw new ActivitiException("Expression did not resolve to a string or collection of strings");
        }
      }
    }


if one of the expressions return null, it will throw an Exception,


and the following code is my hoped logic :



     if (!taskDefinition.getCandidateGroupIdExpressions().isEmpty()) {
      for (Expression groupIdExpr : taskDefinition.getCandidateGroupIdExpressions()) {
        Object value = groupIdExpr.getValue(execution);
         if(value == null){
            //do nothing, just ignore
         }else if (value instanceof String) {
      …..


     if (!taskDefinition.getCandidateUserIdExpressions().isEmpty()) {
      for (Expression userIdExpr : taskDefinition.getCandidateUserIdExpressions()) {
        Object value = userIdExpr.getValue(execution);
       if(value == null){
            //do nothing, just ignore
         }else if (value instanceof String) {




I hope the code can just ignore the null value returned by expression.


any help is appreciated !

Outcomes