留言板

Get all Roles

Gaston Artemski,修改在14 年前。

Get all Roles

Junior Member 帖子: 70 加入日期: 09-4-27 最近的帖子
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,修改在14 年前。

RE: Get all Roles

Liferay Legend 帖子: 2047 加入日期: 08-10-7 最近的帖子
Hi Gaston,

I don't think there is one method that gets all roles. What are you trying to do?
thumbnail
Aarti Jain,修改在14 年前。

RE: Get all Roles

Regular Member 帖子: 116 加入日期: 08-9-2 最近的帖子
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,修改在14 年前。

RE: Get all Roles

Junior Member 帖子: 70 加入日期: 09-4-27 最近的帖子
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,修改在11 年前。

RE: Get all Roles

Regular Member 帖子: 194 加入日期: 12-4-25 最近的帖子
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,修改在11 年前。

RE: Get all Roles

Junior Member 帖子: 80 加入日期: 10-2-16 最近的帖子
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,修改在11 年前。

RE: Get all Roles

Regular Member 帖子: 194 加入日期: 12-4-25 最近的帖子
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,修改在10 年前。

RE: Get all Roles

Junior Member 帖子: 66 加入日期: 12-8-28 最近的帖子
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,修改在14 年前。

RE: Get all Roles

Junior Member 帖子: 34 加入日期: 09-3-20 最近的帖子
I've been looking for answer to that for couple of hours. Thanks very much. It worked as a charm :-)
Mustafa Kemal Fedakar,修改在9 年前。

RE: Get all Roles

New Member 帖子: 7 加入日期: 14-10-1 最近的帖子
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?