I need to get the list of Organization roles and Site roles that are present in my Liferay.
I have used the following below code to get Site Roles and Organization Roles
List<UserGroupRole> list =UserGroupRoleLocalServiceUtil.getUserGroupRoles(0,UserGroupRoleLocalServiceUtil.getUserGroupRolesCount());
System.out.println("UserGroupRole list size "+list.size());
System.out.println("getUserGroupRolesCount "+UserGroupRoleLocalServiceUtil.getUserGroupRolesCount());
for (UserGroupRole roleObj : list) {
if(roleObj != null && roleObj.getRole() != null ){
if (RoleConstants.TYPE_ORGANIZATION==roleObj.getRole().getType() && RoleConstants.ORGANIZATION_ADMINISTRATOR.equals(roleObj.getRole().getName())) {
System.out.println("Role Name " + roleObj.getRole().getName() + " Role Id "+ roleObj.getRole().getRoleId() + " Role type " + roleObj.getRole().getType());
session.setAttribute(LoginConstants.ORGANIZATION_ADMINISTRATOR_ROLE_ID, roleObj.getRole().getRoleId(),PortletSession.APPLICATION_SCOPE);
} else
if (RoleConstants.TYPE_ORGANIZATION==roleObj.getRole().getType() && RoleConstants.ORGANIZATION_OWNER.equals(roleObj.getRole().getName())) {
System.out.println("Role Name " + roleObj.getRole().getName() + " Role Id "+ roleObj.getRole().getRoleId() + " Role type " + roleObj.getRole().getType());
session.setAttribute(LoginConstants.ORGANIZATION_OWNER_ROLE_ID, roleObj.getRole().getRoleId(),PortletSession.APPLICATION_SCOPE);
} else
if (RoleConstants.TYPE_SITE==roleObj.getRole().getType() && RoleConstants.SITE_ADMINISTRATOR.equals(roleObj.getRole().getName())) {
System.out.println("Role Name " + roleObj.getRole().getName() + " Role Id "+ roleObj.getRole().getRoleId() + " Role type " + roleObj.getRole().getType());
session.setAttribute(LoginConstants.SITE_ADMINISTRATOR_ROLE_ID, roleObj.getRole().getRoleId(),PortletSession.APPLICATION_SCOPE);
} else
if (RoleConstants.TYPE_SITE==roleObj.getRole().getType() && RoleConstants.SITE_OWNER.equals(roleObj.getRole().getName())) {
System.out.println("Role Name " + roleObj.getRole().getName() + " Role Id "+ roleObj.getRole().getRoleId() + " Role type " + roleObj.getRole().getType());
session.setAttribute(LoginConstants.SITE_OWNER_ROLE_ID, roleObj.getRole().getRoleId(),PortletSession.APPLICATION_SCOPE);
}
}
}
I was expecting the following 4 roles details (Role Id) - Organization Administrator - Organization Owner - Site Administrator - Site Owner
But I did not got "Site Administrator" role details ,the reason I did not got was this role was not assigned to any user , hence there was no "UserGroupRole" mapping present for the same. The UserGroupRole list size was 2776.
When I assigned a user the "Site Administrator" role , I was able to get it from the above code and the size of the UserGroupRole list was 2777.
Is there any other way so that I can get the List of all Organization roles and Site roles. Please help me and thanks for the same.