Foros de discusión
RE: Bulk assignment of members to organisations and bulk role assignement
Paul Robinson, modificado hace 12 años.
Bulk assignment of members to organisations and bulk role assignement
Junior Member Mensajes: 46 Fecha de incorporación: 30/12/08 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.
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.
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.service.OrganizationLocalServiceUtil;
import com.liferay.portal.service.RoleLocalServiceUtil;
import com.liferay.portal.service.UserGroupRoleLocalServiceUtil;
companyId = COMPANYID;
studentOrgRoleName = "ROLENAME";
userToGrps = new String[] { "ORGNAME,SCREENNAME","ORGNAME,SCREENNAME",};
studentOrgRole = RoleLocalServiceUtil.getRole(companyId, studentOrgRoleName);
for(int i=0; i<usertogrps.length; i++) { usertogrp="userToGrps[i];" usergrpdetail="userToGrp.split(",");" out.println("user: " + usergrpdetail[0] ", grp: usergrpdetail[1]); try user org usergrpdetail[0]); add as member to if(!userlocalserviceutil.hasorganizationuser(org.getorganizationid(), user.getuserid())) userlocalserviceutil.addorganizationusers(org.getorganizationid(), new long[] {user.getuserid()}); out.println("adding user: } role if(!usergrouprolelocalserviceutil.hasusergrouprole(user.getuserid(), org.getgroup().getgroupid(), studentorgrole.getroleid())) usergrouprolelocalserviceutil.addusergrouproles(user.getuserid(), {studentorgrole.getroleid(),}); role: +studentorgrolename+ catch(exception e) out.println(e.getmessage()); < code></usertogrps.length;>
Hitoshi Ozawa, modificado hace 12 años.
RE: Bulk assignment of members to organisations and bulk role assignement
Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
Thanks for the information.
Marcos Laurito, modificado hace 10 años.
RE: Bulk assignment of members to organisations and bulk role assignement
Junior Member Mensajes: 99 Fecha de incorporación: 18/04/13 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.
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.