use of org.jivesoftware.openfire.crowd.jaxb.Groups in project Openfire by igniterealtime.
the class CrowdManager method getUserGroups.
/**
* Get all the groups of a given username
* @param username
* @return a List of groups name
* @throws RemoteException
*/
public List<String> getUserGroups(String username) throws RemoteException {
username = JID.unescapeNode(username);
if (LOG.isDebugEnabled())
LOG.debug("fetch all crowd groups for user:" + username);
int maxResults = 100;
int startIndex = 0;
List<String> results = new ArrayList<>();
StringBuilder request = new StringBuilder("user/group/nested?username=").append(urlEncode(username)).append("&max-results=").append(maxResults).append("&start-index=");
try {
while (true) {
GetMethod get = createGetMethodXmlResponse(crowdServer.resolve(request.toString() + startIndex));
Groups groups = null;
try {
int httpCode = client.executeMethod(get);
if (httpCode != 200) {
handleHTTPError(get);
}
groups = JAXB.unmarshal(get.getResponseBodyAsStream(), Groups.class);
} finally {
get.releaseConnection();
}
if (groups != null && groups.group != null) {
for (Group group : groups.group) {
results.add(group.name);
}
if (groups.group.size() != maxResults) {
break;
} else {
startIndex += maxResults;
}
} else {
break;
}
}
} catch (IOException ioe) {
handleError(ioe);
}
return results;
}
use of org.jivesoftware.openfire.crowd.jaxb.Groups in project Openfire by igniterealtime.
the class CrowdManager method getAllGroupNames.
/**
* Get all the crowd groups
* @return a List of group names
* @throws RemoteException
*/
public List<String> getAllGroupNames() throws RemoteException {
if (LOG.isDebugEnabled())
LOG.debug("fetch all crowd groups");
int maxResults = 100;
int startIndex = 0;
List<String> results = new ArrayList<>();
StringBuilder request = new StringBuilder("search?entity-type=group&restriction=active%3dtrue").append("&max-results=").append(maxResults).append("&start-index=");
try {
while (true) {
GetMethod get = createGetMethodXmlResponse(crowdServer.resolve(request.toString() + startIndex));
Groups groups = null;
try {
int httpCode = client.executeMethod(get);
if (httpCode != 200) {
handleHTTPError(get);
}
groups = JAXB.unmarshal(get.getResponseBodyAsStream(), Groups.class);
} finally {
get.releaseConnection();
}
if (groups != null && groups.group != null) {
for (Group group : groups.group) {
results.add(group.name);
}
if (groups.group.size() != maxResults) {
break;
} else {
startIndex += maxResults;
}
} else {
break;
}
}
} catch (IOException ioe) {
handleError(ioe);
}
return results;
}
Aggregations