- //your crowd server settings
- String url = "http://auth.staging.company.com/crowd/";//crowd base url
- String applicationName = "appincrowd";
- String applicationPass = "apppassword";
- String groupName = "usergroup";//a user group under the app
- CrowdClient client = new RestCrowdClientFactory().newInstance(url, applicationName, applicationPass);
- //initialze crowd client
- //a single user can be more than one group,so let's remove duplicate users by using Set
- Set<CrowdUser> allCrowdUsers = new HashSet<>();
- List<String> newGroupList = client.searchGroupNames(NullRestrictionImpl.INSTANCE, 0, maxGroupSearchResult);
- //get all users in a single list
- for (String currGroupName : newGroupList) {
- List<User> currGroupUsers = client.getUsersOfGroup(currGroupName, 0, maxUserSearchResult);
- for (User grpUser : currGroupUsers) {
- allCrowdUsers.add(new CrowdUser(grpUser));
- }
- }
- //traverse the all users list
- for (User usr : allCrowdUsers) {
- System.out.println(usr.getName() + " " + usr.getFirstName() + " " + usr.getLastName() + " (" + usr.getEmailAddress() + ")");
- }
Output:
- //john cooper (cooper@company.com)
- //sam peters (sam@company.com)
- //...............................
- //Istiak Ahmad (iask@company.com)
Extended crowd user class:
CrowdUser.java:
- import com.atlassian.crowd.model.user.User;
- import com.atlassian.crowd.model.user.UserTemplate;
- /**
- *Extend user with overridden equals() and hashCode() method according to user email address so that we can build a collection(Set<>) with no different users with same email address
- *
- */
- public class CrowdUser extends UserTemplate {
- public CrowdUser(User user) {
- super(user);
- }
- /**
- compare only user email address
- */
- @Override
- public boolean equals(Object object) {
- boolean result = false;
- if (object == null || object.getClass() != getClass()) {
- result = false;
- } else {
- CrowdUser muser = (CrowdUser) object;
- if (this.getEmailAddress().compareTo(muser.getEmailAddress()) == 0) {
- result = true;
- }
- }
- return result;
- }
- // only email address
- @Override
- public int hashCode() {
- return this.getEmailAddress().hashCode();
- }
- }
No comments:
Post a Comment