cancel
Showing results for 
Search instead for 
Did you mean: 

Get all tasks for a given user

gant
Champ in-the-making
Champ in-the-making
Hi all,

I try to get a list of all tasks I can perform actions on, that means:
- tasks assigned to me
- tasks where I'm a candidate-user
- tasks where I'm a member of a candidate-group

Tried to use TaskQuery.taskInvolvedUser(myUserName) with , but the list I recieve is always empty. Even for tasks, where I'm the assignee (check this on the database). So I think, I completly missunderstand the meaning of taskInvolvedUser().

Can I get this list with on single call to the TaskService?

Thanks in advance,
michael

P.S.: Have custom UserManager and GroupManager loaded, so this might also cause the problem. But there are no Exceptions at all.
8 REPLIES 8

gant
Champ in-the-making
Champ in-the-making
Hi,

Any ideas on this? Found out in the meantime, that I can get all Tasks assigned to me and all unassigned tasks, so I completely have no idea, why taskInvolvedUser() returns a empty list. I saw, there are the expected IdentityLinks in the database.

Thanks,
michael

trademak
Star Contributor
Star Contributor
Hi,

The taskInvolvedUser method works fine for me.
You said you implemented a custom UserManager and GroupManager. Could you elaborate a bit more on that.
Also, are you using other custom functionality?

Best regards,

gant
Champ in-the-making
Champ in-the-making
Hi,

The custom UserManager and GroupManager are the only custom things I use with Activiti.

I need custom IdentityManagers, because I have to use the Liferay User Management forActiviti, but can not use the Liferay integration for Activiti. At this time, I only have implemented the following methods on the two Managers:

public GroupEntity findGroupById(String groupId)

public List<Group> findGroupsByUser(String userId)
and
public UserEntity findUserById(String userId)

public List<Group> findGroupsByUser(String userId)

All other methods throw an UnsupportedOperationException.

My factories are like this:

package my.company.taskmanagement.activiti.identity;

import org.activiti.engine.impl.interceptor.Session;
import org.activiti.engine.impl.interceptor.SessionFactory;
import org.activiti.engine.impl.persistence.entity.GroupManager;

public class LiferayGroupManagerFactory implements SessionFactory {

public Class<?> getSessionType() {
  return GroupManager.class;
}
public Session openSession() {
  return new LiferayGroupManager();
}

}

The methods
taskService.createTaskQuery().taskUnnassigned().orderByTaskCreateTime().desc().list()
taskService.createTaskQuery().taskAssignee(liferayUsername).orderByTaskCreateTime().desc().list()
taskService.claim(taskToProcess.getId(), liferayUserame)
taskService.setAssignee(taskToProcess.getId(), null)
taskService.complete(taskToProcess.getId(), vars)
work as expected, but the taskInvolvedUser() always returns an empty list. Not even the tasks directly assigned to the liferayUser are returned. There is no thrown UnsupportedOperationException thrown at any time.

Regards
michael

frederikherema1
Star Contributor
Star Contributor
What did you exactly modify? Because the taskQuery.involved uses the Identity-link table:

<if test="involvedUser != null">
        and I.USER_ID_ = #{involvedUser}
      </if>

gant
Champ in-the-making
Champ in-the-making
Hi,

Below the code of my current UserManager implementation (GroupManager implementation is similar). I have absolutely no plan, if this is the right way to do what I want. The goal of all that is to make activiti use the user and group information from Liferay.

package my.conpany.taskmanagement.activiti.identity;

import java.util.ArrayList;

public class LiferayUserManager extends UserManager {

public User createNewUser(String userId) {
  throw new UnsupportedOperationException("Use Liferay User Management to create User.");
}

public void insertUser(User user) {
  throw new UnsupportedOperationException("Use Liferay User Management to insert User.");
}

public void updateUser(User updatedUser) {
  throw new UnsupportedOperationException("Use Liferay User Management to update User.");
}

public UserEntity findUserById(String userId) {
  com.liferay.portal.model.impl.UserImpl lrUser = null;
  try {
   lrUser = (com.liferay.portal.model.impl.UserImpl) UserLocalServiceUtil.getUserById(Long.valueOf(userId));

  } catch (Exception e) {
   // TODO Exception Handling
   e.printStackTrace();
  }

  return liferayToActivitiUser(lrUser);
}

public void deleteUser(String userId) {
  throw new UnsupportedOperationException("Use Liferay User Management to delete User.");
}

public List<User> findUserByQueryCriteria(Object query, Page page) {
  throw new UnsupportedOperationException("UserQuery is not yet supported.");
}

public long findUserCountByQueryCriteria(Object query) {
  throw new UnsupportedOperationException("UserQuery is not yet supported.");
}


public List<Group> findGroupsByUser(String userId) {
  List<com.liferay.portal.model.Group> lrUserGroups = null;
  try {
   
  lrUserGroups = GroupLocalServiceUtil.getUserGroups(Long.valueOf(userId));  
      
  } catch (Exception e) {
   //TODO Exception Handling
   e.printStackTrace();
  }
  return liferayToActivitiGroupList(lrUserGroups);

}

public UserQuery createNewUserQuery() {
  throw new UnsupportedOperationException("UserQuery is not yet supported.");
}

public IdentityInfoEntity findUserInfoByUserIdAndKey(String userId, String key) {
  throw new UnsupportedOperationException("Keys are not yet supported.");
}

public List<String> findUserInfoKeysByUserIdAndType(String userId, String type) {
  throw new UnsupportedOperationException("Keys are not yet supported.");
}

private UserEntity liferayToActivitiUser(com.liferay.portal.model.User lrUser) {
  UserEntity ue = new UserEntity();
  ue.setId(Long.toString(lrUser.getUserId()));
  ue.setEmail(lrUser.getEmailAddress());
  ue.setFirstName(lrUser.getFirstName());
  ue.setLastName(lrUser.getLastName());
  ue.setPassword(lrUser.getPassword());
 
  return ue;
}

private Group liferayToActivitiGroup(com.liferay.portal.model.Group lrGroup) {
  GroupEntity actGroup = new GroupEntity();
  actGroup.setId(Long.toString(lrGroup.getGroupId()));
  //actGroup.setId(lrGroup.getName());
  actGroup.setType(Integer.toString(lrGroup.getType()));
  actGroup.setName(lrGroup.getName());
  return actGroup;
}

private List<Group> liferayToActivitiGroupList(List<com.liferay.portal.model.Group> lrUserGroups) {

  List<Group> actGroups = new ArrayList<Group>();
  for (int i = 0; i < lrUserGroups.size(); i++) {
   actGroups.add(liferayToActivitiGroup(lrUserGroups.get(i)));
  }

  return actGroups;
}

}

Regards

frederikherema1
Star Contributor
Star Contributor
Can you double-check that the identity-link table contains a record, combining the task and the ID of the user in liferay?

gant
Champ in-the-making
Champ in-the-making
Hi,

I have the following information stored in the database:



mysql> select * from act_ru_task;
+—–+——+—————+—————+———————–+—————————-+—————–+————–+————————–+——–+———–+————-+———–+————–
——-+———–+
| ID_ | REV_ | EXECUTION_ID_ | PROC_INST_ID_ | PROC_DEF_ID_          | NAME_                      | PARENT_TASK_ID_ | DESCRIPTION_ | TASK_DEF_KEY_            | OWNER_ | ASSIGNEE_ | DELEGATION_ | PRIORITY_ | CREATE_TIME_
       | DUE_DATE_ |
+—–+——+—————+—————+———————–+—————————-+—————–+————–+————————–+——–+———–+————-+———–+————–
——-+———–+
| 305 |    2 | 301           | 301           | InvestmentRequest:1:4 | Approve Investment Request | NULL            | NULL         | ApproveInvestmentRequest | NULL   | 10950     | NULL        |        50 | 2011-05-26 07
:35:18 | NULL      |
| 405 |    1 | 401           | 401           | InvestmentRequest:1:4 | Approve Investment Request | NULL            | NULL         | ApproveInvestmentRequest | NULL   | NULL      | NULL        |        50 | 2011-05-26 11
:53:31 | NULL      |
+—–+——+—————+—————+———————–+—————————-+—————–+————–+————————–+——–+———–+————-+———–+————–
——-+———–+
2 rows in set (0.00 sec)

and in act_ru_identitylink
mysql> select * from act_ru_identitylink;
+—–+——+————+———–+———-+———-+
| ID_ | REV_ | GROUP_ID_  | TYPE_     | USER_ID_ | TASK_ID_ |
+—–+——+————+———–+———-+———-+
| 306 |    1 | management | candidate | NULL     | 305      |
| 406 |    1 | management | candidate | NULL     | 405      |
+—–+——+————+———–+———-+———-+
2 rows in set (0.00 sec)

User 10950 is in group 'management' (btw. changed GroupManager.liferayToActivitiGroup() so that the groupname of liferay, which is management is mapped to the id of the activiti group object)

…getTaskInvolvedUser('10950') returns an empty list, and …taskAssignee('10950') returns the task with id 305.

I would expect:
taskAssignedUser() returns task 305, taskInvolvedUser returns 305 and 405.

Thanks

frederikherema1
Star Contributor
Star Contributor
As I quoted before:
<if test="involvedUser != null">
        and I.USER_ID_ = #{involvedUser}
</if>

.. the involvedUser(…) only checks for identitylinks pointing the the user, not the group. So if the user is a candidate for a task, the query will not return those tasks. This is the case in your db (2 times candidate, user_id_ is null):

nd in act_ru_identitylink
mysql> select * from act_ru_identitylink;
+—–+——+————+———–+———-+———-+
| ID_ | REV_ | GROUP_ID_  | TYPE_     | USER_ID_ | TASK_ID_ |
+—–+——+————+———–+———-+———-+
| 306 |    1 | management | candidate | NULL     | 305      |
| 406 |    1 | management | candidate | NULL     | 405      |
+—–+——+————+———–+———-+———-+