留言板
Get all Roles
Hello,
is there a direct way to retrieve all available roles within a liferay portal?
Because RoleLocalServiceUtil delivers only roles for a certain company :
Ofcourse I can retrieve all companies with CompanyLocalServiceUtil
and get so all id's and roles....
But is there no direct was like getRolesForWholeSystem?
Greetings
Gaston
is there a direct way to retrieve all available roles within a liferay portal?
Because RoleLocalServiceUtil delivers only roles for a certain company :
public static java.util.List<com.liferay.portal.model.role> getRoles(
long companyId) throws com.liferay.portal.SystemException {
return getService().getRoles(companyId);
}
</com.liferay.portal.model.role>
Ofcourse I can retrieve all companies with CompanyLocalServiceUtil
public static java.util.List<com.liferay.portal.model.company> getCompanies()
throws com.liferay.portal.SystemException {
return getService().getCompanies();
}
</com.liferay.portal.model.company>
and get so all id's and roles....
But is there no direct was like getRolesForWholeSystem?
Greetings
Gaston
Hi,
You can try with the following code to retrieve all the roles within the portal:
Regards,
Aarti
You can try with the following code to retrieve all the roles within the portal:
List<role> roles=RoleLocalServiceUtil.getRoles(0,RoleLocalServiceUtil.getRolesCount());
</role>
Regards,
Aarti
Hi,
thanks for your effort.
I solved it in this way:
Greetings Gaston
thanks for your effort.
I solved it in this way:
public void listAllRoles()
{
try {
List<company> companies=CompanyLocalServiceUtil.getCompanies();
for(Company company:companies)
{
List<role> roles=RoleLocalServiceUtil.getRoles(company.getCompanyId());
for(Role role:roles)
{
System.out.println(role.getRoleId()+" "+role.getName());
}
}
} catch (SystemException e) {
e.printStackTrace();
}
}
</role></company>
Greetings Gaston
Gaston Artemski:
Hi,
thanks for your effort.
I solved it in this way:public void listAllRoles() { try { List<company> companies=CompanyLocalServiceUtil.getCompanies(); for(Company company:companies) { List<role> roles=RoleLocalServiceUtil.getRoles(company.getCompanyId()); for(Role role:roles) { System.out.println(role.getRoleId()+" "+role.getName()); } } } catch (SystemException e) { e.printStackTrace(); } } </role></company>
Greetings Gaston
Hi,
How can I use above code in vm (velocity) file?
Thanks,
Tanaji.
Tanaji M. Londhe:
Gaston Artemski:Hi,
thanks for your effort.
I solved it in this way:public void listAllRoles() { try { List<company> companies=CompanyLocalServiceUtil.getCompanies(); for(Company company:companies) { List<role> roles=RoleLocalServiceUtil.getRoles(company.getCompanyId()); for(Role role:roles) { System.out.println(role.getRoleId()+" "+role.getName()); } } } catch (SystemException e) { e.printStackTrace(); } } </role></company>
Greetings Gaston
Hi,
How can I use above code in vm (velocity) file?
Thanks,
Tanaji.
Try with below code snippet in your vm(velocity) file.
#set ($roleLocalService = $serviceLocator.findService("com.liferay.portal.service.RoleLocalService"))
#set ($companyLocalService = $serviceLocator.findService("com.liferay.portal.service.CompanyLocalService"))
#set ($comapnies =$companyLocalService.getCompanies())
#foreach($comapny in $comapnies)
#set($roles=$roleLocalService.getRoles($comapny.getCompanyId()))
#foreach($role in $roles)
role is ::$role.getName()
#end
#end
Regards,
Nishikant Sapkal
Nishikant sapkal:
Tanaji M. Londhe:Gaston Artemski:Hi,
thanks for your effort.
I solved it in this way:public void listAllRoles() { try { List<company> companies=CompanyLocalServiceUtil.getCompanies(); for(Company company:companies) { List<role> roles=RoleLocalServiceUtil.getRoles(company.getCompanyId()); for(Role role:roles) { System.out.println(role.getRoleId()+" "+role.getName()); } } } catch (SystemException e) { e.printStackTrace(); } } </role></company>
Greetings Gaston
Hi,
How can I use above code in vm (velocity) file?
Thanks,
Tanaji.
Try with below code snippet in your vm(velocity) file.
#set ($roleLocalService = $serviceLocator.findService("com.liferay.portal.service.RoleLocalService"))
#set ($companyLocalService = $serviceLocator.findService("com.liferay.portal.service.CompanyLocalService"))
#set ($comapnies =$companyLocalService.getCompanies())
#foreach($comapny in $comapnies)
#set($roles=$roleLocalService.getRoles($comapny.getCompanyId()))
#foreach($role in $roles)
role is ::$role.getName()
#end
#end
Regards,
Nishikant Sapkal
Hi Nishikant,
Thanks.
Your code snippet is working properly, but it gives me only regular roles of portal like "Administrator", "User" etc I want access my site roles("Site Administration", "Site Content Reviwer" etc) like that, So plz help me how can I access these site roles.
There are various types of role
1) Regular roles
2) Inherited Roles
3) Organisation roles
4) Site roles