GroupEntityManager.findGroupsByUser() is invoked multiple times on taskQuery execution

cancel
Showing results for 
Search instead for 
Did you mean: 
sam_a
Member II

GroupEntityManager.findGroupsByUser() is invoked multiple times on taskQuery execution

The issue is pretty similar to the below one that was discussed many years ago and I'm unable to refer to the fixes provided to that issue.

GroupManager.findGroupsByUser called twice 

-----------------------------------------------------------------------------------------------------------------------------

GroupEntityManager.findGroupsByUser() is invoked 5 times on taskQuery execution. I'm using SpringBoot along with Activiti, I have provided the code snippets below. Please advise if I'm missing anything for the query to function correctly.

Query:

List<Task> tasks = taskQuery.taskCandidateOrAssigned(userId)
        .list();

Config:

@Override
public ProcessEngineFactoryBean processEngine(SpringProcessEngineConfiguration configuration) throws Exception{
    configuration.setIdGenerator(new StrongUuidGenerator());

    GroupManagerFactory groupManagerFactory = new GroupManagerFactory(customGroupEntityManager);
    configuration.setCustomSessionFactories(CollectionUtil.createListOfOne(groupManagerFactory));
    configuration.setGroupEntityManager(customGroupEntityManager);

    configuration.setDbIdentityUsed(false);
    return super.processEngine(configuration);
}

GroupEntityManager:

@Component
public class CustomGroupEntityManager implements GroupEntityManager, Session{

    @Override
    public List<Group> findGroupsByUser(String userId) {
        //ACTUAL IMPLEMENTATION AND THIS METHOD IS GETTING INVOKED "FIVE" TIMES
    }
    @Override
    public Group createNewGroup(String groupId) {
        return null;
    }

    @Override
    public GroupQuery createNewGroupQuery() {
        return null;
    }

    @Override
    public List<Group> findGroupByQueryCriteria(GroupQueryImpl query, Page page) {
        return null;
    }

    @Override
    public long findGroupCountByQueryCriteria(GroupQueryImpl query) {
        return 0;
    }


    @Override
    public List<Group> findGroupsByNativeQuery(Map<String, Object> parameterMap, int firstResult, int maxResults) {
        return null;
    }

    @Override
    public long findGroupCountByNativeQuery(Map<String, Object> parameterMap) {
        return 0;
    }

    @Override
    public boolean isNewGroup(Group group) {
        return false;
    }

    @Override
    public GroupEntity create() {
        return null;
    }

    @Override
    public GroupEntity findById(String entityId) {
        return null;
    }

    @Override
    public void insert(GroupEntity entity) {

    }

    @Override
    public void insert(GroupEntity entity, boolean fireCreateEvent) {

    }

    @Override
    public GroupEntity update(GroupEntity entity) {
        return null;
    }

    @Override
    public GroupEntity update(GroupEntity entity, boolean fireUpdateEvent) {
        return null;
    }

    @Override
    public void delete(String id) {

    }

    @Override
    public void delete(GroupEntity entity) {

    }

    @Override
    public void delete(GroupEntity entity, boolean fireDeleteEvent) {

    }

    @Override
    public void flush() {
    }

    @Override
    public void close() {
    }
    // CLOVER:ON
}
2 Replies
sam_a
Member II

Re: GroupEntityManager.findGroupsByUser() is invoked multiple times on taskQuery execution

Any input on this issue is appreciated.

bassam_al-saror
Alfresco Employee

Re: GroupEntityManager.findGroupsByUser() is invoked multiple times on taskQuery execution

This is being called by mybatis as mentioned in the other thread. Did you try setting the candidate groups in the query? If you provide the candidate groups in query GroupEntityManager.findGroupsByUser will not be invoked (see Activiti/TaskQueryImpl.java at 6.x · Activiti/Activiti · GitHub). Your query might look like this.

List<Task> tasks = taskQuery.taskCandidateOrAssigned(userId)
                  .or()
                     .taskCandidateGroupIn(groups)
                  .endOr()
                  .list();

Hope this helps.