组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
Paul Robinson
Bulk assignment of members to organisations and bulk role assignement
2011年9月13日 上午5:45
答复

Paul Robinson

等级: Junior Member

帖子: 46

加入日期: 2008年12月29日

最近的帖子

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
2011年9月22日 下午5:55
答复

Hitoshi Ozawa

等级: Liferay Legend

帖子: 7949

加入日期: 2010年3月23日

最近的帖子

Thanks for the information.
Marcos Laurito
RE: Bulk assignment of members to organisations and bulk role assignement
2014年4月22日 上午6:34
答复

Marcos Laurito

等级: Junior Member

帖子: 99

加入日期: 2013年4月18日

最近的帖子

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.

Participate in the State of Liferay Community 2017. Help the community and even win some prizes!