Fórum

Get all Roles

Gaston Artemski, modificado 14 Anos atrás.

Get all Roles

Junior Member Postagens: 70 Data de Entrada: 27/04/09 Postagens Recentes
Hello,

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
thumbnail
Amos Fong, modificado 14 Anos atrás.

RE: Get all Roles

Liferay Legend Postagens: 2047 Data de Entrada: 07/10/08 Postagens Recentes
Hi Gaston,

I don't think there is one method that gets all roles. What are you trying to do?
thumbnail
Aarti Jain, modificado 14 Anos atrás.

RE: Get all Roles

Regular Member Postagens: 116 Data de Entrada: 02/09/08 Postagens Recentes
Hi,

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
Gaston Artemski, modificado 14 Anos atrás.

RE: Get all Roles

Junior Member Postagens: 70 Data de Entrada: 27/04/09 Postagens Recentes
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
thumbnail
Tanaji M. Londhe, modificado 11 Anos atrás.

RE: Get all Roles

Regular Member Postagens: 194 Data de Entrada: 25/04/12 Postagens Recentes
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.
thumbnail
Nishikant sapkal, modificado 11 Anos atrás.

RE: Get all Roles

Junior Member Postagens: 80 Data de Entrada: 16/02/10 Postagens Recentes
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
thumbnail
Tanaji M. Londhe, modificado 11 Anos atrás.

RE: Get all Roles

Regular Member Postagens: 194 Data de Entrada: 25/04/12 Postagens Recentes
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
Eric Smith, modificado 10 Anos atrás.

RE: Get all Roles

Junior Member Postagens: 66 Data de Entrada: 28/08/12 Postagens Recentes
I simply use:

List<Role> allRoles=RoleLocalServiceUtil.getRoles(0,RoleLocalServiceUtil.getRolesCount());

I'm not sure why others didn't suggest this. Then you can separate them by type (regular, site, etc...) using .getType() on each role
thumbnail
Sebastian Konkol, modificado 14 Anos atrás.

RE: Get all Roles

Junior Member Postagens: 34 Data de Entrada: 20/03/09 Postagens Recentes
I've been looking for answer to that for couple of hours. Thanks very much. It worked as a charm :-)
Mustafa Kemal Fedakar, modificado 9 Anos atrás.

RE: Get all Roles

New Member Postagens: 7 Data de Entrada: 01/10/14 Postagens Recentes
I need the same thing but I am using soap service.Role service doesn't contains a method like
getRoles(companyId);
.

So can i publish this method like a web service method?