Skip to content

Instantly share code, notes, and snippets.

@bmvakili
Created April 2, 2013 19:26
Show Gist options
  • Save bmvakili/5295400 to your computer and use it in GitHub Desktop.
Save bmvakili/5295400 to your computer and use it in GitHub Desktop.
Liferay Groovy Script Get all roles; list User Groups associated with each role.
import com.liferay.portlet.usergroupsadmin.search.*;
import java.util.*;
import com.liferay.portal.service.*;
import com.liferay.portal.model.*;
import com.liferay.portal.model.UserGroup;
List<Role> roles = RoleLocalServiceUtil.getRoles(0,999999999);
for (Role role : roles) {
long roleId = role.getRoleId();
List<Group> roleGroups = GroupLocalServiceUtil.getRoleGroups(roleId);
for (Group roleGroup : roleGroups) {
Map userGroupParams = new LinkedHashMap<String, Object>();
List userGroupsRoles = new ArrayList();
userGroupParams.put("userGroupsRoles", new Long(role.getRoleId()));
List t = UserGroupLocalServiceUtil.search(10153, "", userGroupParams, 0, 999999999, null);
List<String> added = new ArrayList<String>();
for (Object o : t) {
UserGroup ug = (UserGroup) o;
if (!added.contains(ug.getName())) {
added.add(ug.getName());
System.out.println(role.getName() + " " + ug.getName());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment