Foros de discusión

[Resolved]How to find organization admin and owner??

thumbnail
Sandeep Nair, modificado hace 14 años.

[Resolved]How to find organization admin and owner??

Liferay Legend Mensajes: 1744 Fecha de incorporación: 6/11/08 Mensajes recientes
Hi,

I am using liferay 5.1.2. I have a requirement to find all the organization admins and organization owner. How can i achieve that??

Regards,
Sandeep
thumbnail
Auditya manikanta Vadrevu, modificado hace 14 años.

RE: How to find organization admin and owner??

Liferay Master Mensajes: 621 Fecha de incorporación: 6/05/08 Mensajes recientes
hi sandeep,

see in enterprise admin portlet , you will get the solution.

i think this will help you.

for organisation owner :

 permissionChecker.isCommunityOwner(organizationGroupId)


for organisation administrator :

portletName.equals(PortletKeys.ORGANIZATION_ADMIN)



With Regards,
V.Auditya
thumbnail
Sandeep Nair, modificado hace 14 años.

RE: How to find organization admin and owner??

Liferay Legend Mensajes: 1744 Fecha de incorporación: 6/11/08 Mensajes recientes
Auditya sorry for not making my question clear enough.

I need all the users who are organization admin or organization owner for a given organization id. The above snippet tells me whether the portlet is organization admin or not.

Regards,
Sandeep
thumbnail
Auditya manikanta Vadrevu, modificado hace 14 años.

RE: How to find organization admin and owner??

Liferay Master Mensajes: 621 Fecha de incorporación: 6/05/08 Mensajes recientes
hi sandeep,

i understood from your first post that you need to display users who are organisation owners and who are organisation administrators.

i think the first statement to find whether the user is owner or not will work. and for the second statement my intention was to just to highlight that there will be for users also in enterprise admin portlet.

With Regards,
V.Auditya
thumbnail
Sandeep Nair, modificado hace 14 años.

RE: How to find organization admin and owner??

Liferay Legend Mensajes: 1744 Fecha de incorporación: 6/11/08 Mensajes recientes
Hi Auditya,

Actually i was looking for a straightforward method in which i just have to pass an organizationid and that would retrieve me all the users who are the admin or owner for that org.

Regards,
Sandeep
thumbnail
Auditya manikanta Vadrevu, modificado hace 14 años.

RE: How to find organization admin and owner??

Liferay Master Mensajes: 621 Fecha de incorporación: 6/05/08 Mensajes recientes
hi sandeep,

Using searchContainer, long back i have done this type of coding. but it is working for only regular roles.

long orgid = 12912;
String org1 = "12912";     // organisation id
String r1 = "10107";                   // role id for administrator
UserSearchTerms searchTerms = (UserSearchTerms)searchContainer.getSearchTerms();
LinkedHashMap userParams = new LinkedHashMap();
if(orgid == 12912)                    // just a simple condition which always satisfies
{
userParams.put("usersOrgs", Long.parseLong(org1));   // inserting condition of organisation
userParams.put("usersRoles", Long.parseLong(r1));     // inserting condition of role
}
int nbrUser= UserLocalServiceUtil.searchCount(company.getCompanyId(),null,null,userParams);
LIST<user> results = UserLocalServiceUtil.search(company.getCompanyId(),null,null,userParams,searchContainer.getStart(),searchContainer.getEnd(),searchContainer.getOrderByComparator());</user>


if i keep organisation roles it is not getting results.
so, you need to write your own method.
first we must bring all the users of organisation and then we can check the roles of each user. This will work .

long orgid = 12912;
String org1 = "12912";     // organisation id
UserSearchTerms searchTerms = (UserSearchTerms)searchContainer.getSearchTerms();
LinkedHashMap userParams = new LinkedHashMap();
if(orgid == 12912)                    // just a simple condition which always satisfies
{
userParams.put("usersOrgs", Long.parseLong(org1));   // inserting condition of organisation
}
int nbrUser= UserLocalServiceUtil.searchCount(company.getCompanyId(),null,null,userParams);
LIST<user> results = UserLocalServiceUtil.search(company.getCompanyId(),null,null,userParams,searchContainer.getStart(),searchContainer.getEnd(),searchContainer.getOrderByComparator());
searchContainer.setTotal(nbrUser);
searchContainer.setResults(results);</user>


Now you can get all users of that organisation.

for (int i = 0; i &lt; results.size(); i++)
{
                User user2 = (User)results.get(i);
                List<role> roles = RoleServiceUtil.getUserRoles(user2.getUserId());
                for (Role role : roles) {
                if (role.getName().equalsIgnoreCase("Organization Administrator"))  
                   {
                    // print username ;         
                   }
}            </role>


With Regards,
V.Auditya
thumbnail
Sandeep Nair, modificado hace 14 años.

RE: How to find organization admin and owner??

Liferay Legend Mensajes: 1744 Fecha de incorporación: 6/11/08 Mensajes recientes
Thanks Auditya,

I modified the code little bit.
long orgId = ParamUtil.getLong(request, "organizationId");
		List<user> users = OrganizationUtil.getUsers(orgId);
                 Group organizationGroup = OrganizationServiceUtil.getOrganization(orgId).getGroup();
                  for(User user: users){
				
				long organizationGroupId = organizationGroup.getGroupId();

				if (UserGroupRoleLocalServiceUtil.hasUserGroupRole(
						user.getUserId(), organizationGroupId,
						RoleConstants.ORGANIZATION_ADMINISTRATOR)) {
					System.out.println("User Name: "+ user.getFullName());
					adminUsers.add(user);
				}
			}</user>


Thanks and Regards,
Sandeep