Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Stardust/Knowledge Base/API/JavaAPICookbook/CheckingUserSpecificRole"

(Created page with "== Purpose<br> == There are instances where you need to find if a particular user is assigned under a specific role.You don't have to iterate over a list of grants to achiev...")
 
(Solution)
Line 3: Line 3:
 
There are instances where you need to find if a particular user is assigned under a specific role.You don't have to iterate over a list of grants to achieve this.
 
There are instances where you need to find if a particular user is assigned under a specific role.You don't have to iterate over a list of grants to achieve this.
  
==== Solution<br>  ====
+
==== <br>  ====
  
 
<source lang="java">
 
<source lang="java">
 
 
QueryService qs = sf.getQueryService();
 
QueryService qs = sf.getQueryService();
 
 
UserQuery userQuery = new UserQuery();
 
UserQuery userQuery = new UserQuery();
 
 
userQuery.getFilter().add(UserQuery.ACCOUNT.isEqual("Bang")); //User
 
userQuery.getFilter().add(UserQuery.ACCOUNT.isEqual("Bang")); //User
 
 
ParticipantInfo pInfo = qs.getParticipant("Administrator"); //Role
 
ParticipantInfo pInfo = qs.getParticipant("Administrator"); //Role
 
 
userQuery.where(ParticipantAssociationFilter.forParticipant(pInfo));
 
userQuery.where(ParticipantAssociationFilter.forParticipant(pInfo));
 
 
User retUser = qs.findFirstUser(userQuery);
 
User retUser = qs.findFirstUser(userQuery);
 
 
System.out.println("retUser:::::::::" + retUser);
 
System.out.println("retUser:::::::::" + retUser);
 
 
</source>
 
</source>

Revision as of 06:35, 19 March 2014

Purpose

There are instances where you need to find if a particular user is assigned under a specific role.You don't have to iterate over a list of grants to achieve this.


QueryService qs = sf.getQueryService();
UserQuery userQuery = new UserQuery();
userQuery.getFilter().add(UserQuery.ACCOUNT.isEqual("Bang")); //User
ParticipantInfo pInfo = qs.getParticipant("Administrator"); //Role
userQuery.where(ParticipantAssociationFilter.forParticipant(pInfo));
User retUser = qs.findFirstUser(userQuery);
System.out.println("retUser:::::::::" + retUser);

Back to the top