How to create an Actor Filter based on the Organization Group and use it in a process

Component: Bonita | Version: N/A

Question

We have a process that is used by all business units, where the approval task needs to be seen and completed by a separate group of users for each business unit.

Goal

Set candidates for a task based on the user groups in the organization and assign the same task to different groups, based on a Variable set in the process through a drop down select widget in the instantiation form.

Answer

The solution has 2 simple steps:

  1. Implement a custom actor filter to retrieve the group information
  2. Design your process to use this actor filter on your task and assign it to the group

1. Custom actor filter

You will need to implement a new custom actor filter to retrieve the Group information that was set in the organization as follow, this is a simple example (see attached .bos at the bottom of this page):

package org.bonitasoft.support.custom.actorfilter;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.bonitasoft.engine.connector.ConnectorValidationException;
import org.bonitasoft.engine.filter.UserFilterException;
import org.bonitasoft.engine.identity.User;
import org.bonitasoft.engine.identity.UserSearchDescriptor;
import org.bonitasoft.engine.search.SearchOptionsBuilder;
import org.bonitasoft.engine.search.SearchResult;
import org.bonitasoft.engine.api.IdentityAPI;

// The actor filter execution will follow the steps
// 1 - setInputParameters() --> the actor filter receives input parameters values
// 2 - validateInputParameters() --> the actor filter can validate input parameters values
// 3 - filter(final String actorName) --> execute the user filter
// 4 - shouldAutoAssignTaskIfSingleResult() --> auto-assign the task if filter returns a single result

public class listGroupPathImpl extends AbstractlistGroupPathImpl {
    Logger logger = Logger.getLogger(“org.bonitasoft.groupName”);
    
    @Override
    public void validateInputParameters() throws ConnectorValidationException {
        //TODO validate input parameters here
    }
    
    @Override
    public List < Long > filter(final String actorName) throws UserFilterException {
        //TODO execute the user filter here
        //The method must return a list of user id’s
        //you can use getApiAccessor() and getExecutionContext()
        @SuppressWarnings(“unchecked”)
        List<String> groupList = (List<String>) getListGroupPath();
        List<Long> users = new ArrayList<Long>();
        
        try {
            IdentityAPI identityApi = getAPIAccessor().getIdentityAPI();
            for (String groupPath: groupList) {
                SearchOptionsBuilder searchBuilder = new SearchOptionsBuilder(0, 100);
                searchBuilder.filter(UserSearchDescriptor.GROUP_ID, identityApi.getGroupByPath(groupPath).getId());
                SearchResult < User > searchusers = identityApi.searchUsers(searchBuilder.done());
                for (User userAux: searchusers.getResult()) {
                    users.add(userAux.getId());
                }
            }
        } catch (Exception e) {
            logger.severe(“ERROR during actor filter” + e.getMessage());
        }
        return users;
    }
    
    @Override
    public boolean shouldAutoAssignTaskIfSingleResult() {
        // If this method returns true, the step will be assigned to
        // the user if there is only one result returned by the filter method
        return super.shouldAutoAssignTaskIfSingleResult();
    }
}

 

2. Design your process

Then in your process design, you will use this actor filter and assign the task to the group, depending on the value of your variable.

In the .bos attached to this article, the variable is initialized in the instantiation form:

Here, you can find my process sample (created with Studio SP 7.9.4), containing the actor filter and demonstrating its usage in a simple diagram: actorfilterbyorganizationgroup-2.0.bos

Have fun with Bonita!