[Building Sakai] How to get a user's sites
Joshua Swink
joshua.swink at gmail.com
Fri Mar 9 10:27:32 PST 2012
This is a programming question. How can you get a list of a user's sites?
The catch: this is not a logged-in user.
When looking for examples of this in the current Sakai code, I come across
this (in UserPrefsTool.java):
SiteService.getSites(org.sakaiproject.site.api.SiteService.SelectionType.ACCESS,
null, null, null, org.sakaiproject.site.api.SiteService.SortType.TITLE_ASC,
null);
The above function relies on the user being logged in. I checked the code
of SiteService.getSites, and the assumption that it's searching for the
current user's sites is buried deeply within it.
The best I can could up with, using the current API, is this:
public List<String> getUserSites(String userId) {
List<String> userSites = new ArrayList<String>();
Map<String, String> userRoles =
authzGroupService.getUserRoles(userId, null);
for (String realmId: userRoles.keySet()) {
Reference r = entityManager.newReference(realmId);
if (siteService.SITE_SUBTYPE.equals(r.getSubType())) {
userSites.add(r.getId());
}
}
return userSites;
}
Is there a better way?
Another question. Would my function work properly for people who are
"provided", e.g. who are members of course sites due to being in a roster
that is associated with a site?
Josh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20120309/1afbaeb3/attachment.html
More information about the sakai-dev
mailing list