Create an exclusive gateway according group

1
0
-1

Hi,

I need to create an exclusive gateway according group, i.e, if (the user belong to "production group") ==> get an specific way else ==> just get the default way.

I don't know how to get an attribute from the active user neither to take it and use it as a condition in a gateway.

Can someone help me please?

1 answer

1
+1
-1
This one is the BEST answer!

Hi.

I did this in a process to use the role of a user in a gateway.

First, I get the initiator id with this code in the Operations tab of a task :

return apiAccessor.getProcessAPI().getProcessInstance(processInstanceId).getStartedBy();

After that, I place my gateway. And for each flow, I use this code as condition : (I change the role name for each flow)

import org.bonitasoft.engine.identity.Role;
import org.bonitasoft.engine.identity.User;
import org.bonitasoft.engine.identity.UserCriterion;

Role role = apiAccessor.getIdentityAPI().getRoleByName("My role");
int nb = (int) apiAccessor.getIdentityAPI().getNumberOfUsersInRole(role.getId());
List<User> list = apiAccessor.getIdentityAPI().getUsersInRole(role.getId(), 0, nb, UserCriterion.USER_NAME_ASC);

User initiator = apiAccessor.getIdentityAPI().getUser(initiatorId);

if (list.contains(initiator)) return true;
return false;

You can do the same for groups by replacing the role by a group.

Comments

Submitted by hh.molina on Tue, 05/26/2015 - 13:47

Thank you so much, my solution was:

import org.bonitasoft.engine.identity.UserMembership; import org.bonitasoft.engine.identity.UserMembershipCriterion;

Boolean flag = false;

List listMemberships = apiAccessor.getIdentityAPI().getUserMemberships(BonitaUsers.getUser(apiAccessor,taskAssigneeId).getId(), 0, 100, UserMembershipCriterion.ASSIGNED_DATE_ASC); List listGroups = new ArrayList(); for (UserMembership userMembership : listMemberships){

if(userMembership.getGroupName().equals("Topografia") || userMembership.getGroupName().equals("Obra") || userMembership.getGroupName().equals("Presupuestos")){ flag=true; } } return flag;

Notifications