...
This explains basic usage of the Sakai SiteService. This service is used to find out things about Sakai Sites (courses) and look them up by references or contexts. The Site provides access to memberships in the site and allows retrieval and manipulation.
- Trunk javadocs:
- Trunk source location: https://source.sakaiproject.org/svn/site/trunk/
...
Code Block | ||||
---|---|---|---|---|
| ||||
Site site = null;
try {
site = siteService.getSite(siteId);
Set<Member> members = site.getMembers();
for (Member member : members) {
// do something here
log.info("Check it out: " + member.getUserEid());
}
} catch (Exception e) {
// assume we are not in a site or something died and do something about it
}
|
Adding memberships to a Site
Use the SiteService to get the Site and then use the methods on Site to add a membership (it can also update and remove memberships)
Code Block | ||||
---|---|---|---|---|
| ||||
String userId = getCurrentUserId(); // or some other way of getting the userId
Site site;
try {
site = siteService.getSite(siteId);
} catch (IdUnusedException e) {
throw new IllegalArgumentException("Cannot find site by siteId: " + siteId +":"+e, e);
}
String roleId = site.getJoinerRole(); // or some other role
site.addMember(userId, roleId, true, false);
try {
siteService.saveSiteMembership(site);
} catch (IdUnusedException e) {
throw new IllegalArgumentException("Invalid site: " + site.getId() + ":" + e, e);
} catch (PermissionException e) {
throw new SecurityException("Current user not allowed to update site memberships in site: " + site.getId() + " :"+e, e);
}
|
Getting the workspace Site for a user (using the userId)
...