Vista combinada Visión Plana Vista de árbol
Discusiones [ Anterior | Siguiente ]
toggle
Paul Robinson
Bulk assignment of members to organisations and bulk role assignement
13 de septiembre de 2011 5:45
Respuesta

Paul Robinson

Ranking: Junior Member

Mensajes: 45

Fecha de incorporación: 29 de diciembre de 2008

Mensajes recientes

This may be of value to the community, I found this useful today for completing approximately 3000 member and role assignment transactions. In summary, We had some 300 users that needed to be assigned to approximately 6 organisations each e.g. students assigned as members to a class. Once they were members we needed to assign them a organisation role.

Obviously there are far better ways to do this level of integration e..g IDM, LDAP etc but in our current situation this is a work in progress. We created a simple beanshell script that took a CSV list of User and Organisation and completed the task for us rather than the manual assignment. The beanshell script was executed via the normal method in Control Panel, and I guess could be extended if required for additional role assignments.

 1
 2import com.liferay.portal.service.UserLocalServiceUtil;
 3import com.liferay.portal.service.OrganizationLocalServiceUtil;
 4import com.liferay.portal.service.RoleLocalServiceUtil;
 5import com.liferay.portal.service.UserGroupRoleLocalServiceUtil;
 6
 7companyId = COMPANYID;
 8studentOrgRoleName = "ROLENAME";
 9
10userToGrps = new String[] { "ORGNAME,SCREENNAME","ORGNAME,SCREENNAME",};
11studentOrgRole = RoleLocalServiceUtil.getRole(companyId, studentOrgRoleName);
12
13for(int i=0; i<userToGrps.length; i++) {
14userToGrp = userToGrps[i];
15userGrpDetail = userToGrp.split(",");
16
17out.println("user: " + userGrpDetail[0] + ", grp: " + userGrpDetail[1]);
18
19try {
20       user = UserLocalServiceUtil.getUserByScreenName(companyId, userGrpDetail[1]);
21       org = OrganizationLocalServiceUtil.getOrganization(companyId, userGrpDetail[0]);
22
23      //add user as member to org
24
25    if(!UserLocalServiceUtil.hasOrganizationUser(org.getOrganizationId(), user.getUserId())) {
26    UserLocalServiceUtil.addOrganizationUsers(org.getOrganizationId(), new long[] {user.getUserId()});
27    out.println("adding user: " + userGrpDetail[0] + " to grp: " + userGrpDetail[1]);
28}
29
30//add  org role to user
31
32if(!UserGroupRoleLocalServiceUtil.hasUserGroupRole(user.getUserId(), org.getGroup().getGroupId(), studentOrgRole.getRoleId())) {
33    UserGroupRoleLocalServiceUtil.addUserGroupRoles(user.getUserId(), org.getGroup().getGroupId(), new long[] {studentOrgRole.getRoleId(),});
34
35   out.println("adding org role: " +studentOrgRoleName+ " to user: " + userGrpDetail[1]);
36 }
37}
38  catch(Exception e) { out.println(e.getMessage()); }
39}
Hitoshi Ozawa
RE: Bulk assignment of members to organisations and bulk role assignement
22 de septiembre de 2011 17:55
Respuesta

Hitoshi Ozawa

Ranking: Liferay Legend

Mensajes: 7954

Fecha de incorporación: 23 de marzo de 2010

Mensajes recientes

Thanks for the information.
Marcos Laurito
RE: Bulk assignment of members to organisations and bulk role assignement
22 de abril de 2014 6:34
Respuesta

Marcos Laurito

Ranking: Junior Member

Mensajes: 79

Fecha de incorporación: 18 de abril de 2013

Mensajes recientes

I'm trying to use this script but is not working.
I've got a few questions.
Where is the CSV file used? Is any modification needed to make this work??

Sorry for my english and thanks.