The SiteService manages Sites in Sakai. Sites are the primary organizational unit containing pages, tools, and user memberships.
Overview
Package: org.sakaiproject.site.api
The SiteService provides comprehensive site management capabilities including:
- Site creation, modification, and deletion
- Site membership and permissions
- Page and tool management within sites
- Site access control and visibility
- Site search and filtering
Constants
APPLICATION_ID
String
default:"sakai:site"
Application identifier for the site service
Root path for site resource references
The site ID for the admin workspace
SITE_TEMPLATE
String
default:"!worksite"
Template site for non-user sites
Template site for user sites
Security Functions
Permission to remove a site
Permission to update a site
SECURE_UPDATE_SITE_MEMBERSHIP
String
default:"site.upd.site.mbrshp"
Permission to update site membership
SECURE_UPDATE_GROUP_MEMBERSHIP
String
default:"site.upd.grp.mbrshp"
Permission to update group memberships
SECURE_VIEW_ROSTER
String
default:"site.viewRoster"
Permission to view project site participants
Events
SITE_VISIT
String
default:"site.visit"
Event for visiting a site
EVENT_SITE_PUBLISH
String
default:"site.publish"
Event for publishing a site
EVENT_SITE_UNPUBLISH
String
default:"site.unpublish"
Event for unpublishing a site
Core Methods
Site Access
getSite
Site getSite(String id) throws IdUnusedException
Access a site object. This method does not perform security/permission checks.
For permission-checked access when users visit a site, use getSiteVisit() instead.
Site object containing the site information
Throws:
IdUnusedException - if site not found
Example:
try {
Site site = siteService.getSite(siteId);
String title = site.getTitle();
List<SitePage> pages = site.getPages();
} catch (IdUnusedException e) {
// Handle site not found
}
getOptionalSite
Optional<Site> getOptionalSite(String id)
Access a site object as an Optional without throwing exceptions.
Optional containing the site if found
Example:
Optional<Site> optSite = siteService.getOptionalSite(siteId);
optSite.ifPresent(site -> {
log.info("Site title: " + site.getTitle());
});
getSiteVisit
Site getSiteVisit(String id) throws IdUnusedException, PermissionException
Access a site object with visitation permission checks.
Site object containing the site information
Throws:
IdUnusedException - if site not found
PermissionException - if current user lacks permission to visit
Example:
try {
Site site = siteService.getSiteVisit(siteId);
// User has permission to visit this site
} catch (PermissionException e) {
// User cannot access this site
}
siteExists
boolean siteExists(String id)
Check if a site with this ID exists.
The site ID string (returns false if null)
true if site exists, false otherwise
Site Creation
addSite (Simple)
Site addSite(String id, String type)
throws IdInvalidException, IdUsedException, PermissionException
Add a new site with the given ID and type.
The site type (e.g., “course”, “project”)
Throws:
IdInvalidException - if the site ID is invalid
IdUsedException - if the site ID is already in use
PermissionException - if current user lacks permission
Example:
try {
Site site = siteService.addSite("my-site", "project");
site.setTitle("My Project Site");
site.setDescription("A collaborative project space");
site.setPublished(true);
siteService.save(site);
} catch (IdUsedException e) {
// Site ID already exists
}
addSite (Copy)
Site addSite(String id, Site other)
throws IdInvalidException, IdUsedException, PermissionException
Add a new site structured like another site.
The site to copy structure from
The new Site object with structure copied from other
Site Modification
save
void save(Site site) throws IdUnusedException, PermissionException
Save updates to a site. Site must exist and user must have update permissions.
The modified site to save
Throws:
IdUnusedException - if the site’s ID is not defined
PermissionException - if current user lacks permission
Example:
try {
Site site = siteService.getSite(siteId);
site.setTitle("Updated Title");
site.setDescription("New description");
siteService.save(site);
} catch (PermissionException e) {
// User cannot update this site
}
saveSiteMembership
void saveSiteMembership(Site site) throws IdUnusedException, PermissionException
Save only site membership updates.
The site with modified membership
Throws:
IdUnusedException - if the site’s ID is not defined
PermissionException - if current user lacks permission to update membership
saveSiteInfo
void saveSiteInfo(String id, String description, String infoUrl)
throws IdUnusedException, PermissionException
Save a site’s display information fields only.
Site Removal
removeSite
void removeSite(Site site) throws PermissionException, IdUnusedException
Remove a site and all its content.
If site.soft.deletion=true in configuration, the site will be soft deleted first with a grace period before hard deletion.
Throws:
PermissionException - if current user lacks permission
IdUnusedException - if site does not exist
Site Search and Listing
getUserSites
List<Site> getUserSites()
List<Site> getUserSites(boolean requireDescription)
List<Site> getUserSites(boolean requireDescription, boolean includeUnpublishedSites)
Access a list of sites the current user can visit, sorted by title.
When true, full descriptions included; when false, may be omitted
When true, include unpublished sites
List of sites the current user can access
Example:
// Get all published sites for current user
List<Site> sites = siteService.getUserSites();
// Get all sites including unpublished
List<Site> allSites = siteService.getUserSites(true, true);
for (Site site : sites) {
System.out.println(site.getTitle() + " (" + site.getId() + ")");
}
getSites
List<Site> getSites(SelectionType type, Object ofType, String criteria,
Map<String, String> propertyCriteria, SortType sort,
PagingPosition page)
Access a list of Site objects meeting specified criteria.
Selection type (ACCESS, UPDATE, JOINABLE, PUBVIEW, ANY, etc.)
Site type criteria: null for any; String for single type; String[]/List/Set for multiple
Match string in site id, title, description, or skin
Property name-value pairs to match
Sort order (TITLE_ASC, TITLE_DESC, CREATED_ON_ASC, etc.)
Subset of items to return
List of Site objects matching criteria
Example:
// Get all course sites user can access, sorted by title
List<Site> courseSites = siteService.getSites(
SelectionType.ACCESS,
"course",
null,
null,
SortType.TITLE_ASC,
null
);
// Search for sites with "biology" in title/description
List<Site> bioSites = siteService.getSites(
SelectionType.ACCESS,
null,
"biology",
null,
SortType.TITLE_ASC,
null
);
getSiteIds
List<String> getSiteIds(SelectionType type, Object ofType, String criteria,
Map<String, String> propertyCriteria, SortType sort,
PagingPosition page)
Get site IDs matching criteria. More efficient than getSites() when you only need IDs.
List of site IDs matching criteria
countSites
int countSites(SelectionType type, Object ofType, String criteria,
Map<String, String> propertyCriteria)
Count Site objects meeting specified criteria.
Count of sites matching criteria
Selection Types
The SelectionType class defines filtering criteria:
Sites the current user has read access to (non-special, non-myWorkspace)
Sites the current user has write access to
Sites the current user can join but doesn’t have read access to
Sites marked for public view
Sites the current user is a member of (regardless of published status)
Soft-deleted sites for current user
Sort Types
The SortType class defines sorting options:
Sort by creation time ascending
Sort by creation time descending
Sort by modification time ascending
Sort by published status ascending
Site Membership
join
void join(String id) throws IdUnusedException, PermissionException
Cause the current user to join a site.
Throws:
IdUnusedException - if site not found
PermissionException - if current user cannot join this site
unjoin
void unjoin(String id) throws IdUnusedException, PermissionException
Cause the current user to unjoin a site.
isCurrentUserMemberOfSite
boolean isCurrentUserMemberOfSite(String id)
Determine if the current user is a member of the site.
true if current user is a member
Permission Checks
allowAccessSite
boolean allowAccessSite(String id)
Check if the current user is allowed to access (visit) a site.
The site ID (returns false if null)
true if allowed, false otherwise
allowUpdateSite
boolean allowUpdateSite(String id)
Check if the current user is allowed to update a site.
true if allowed, false otherwise
allowAddSite
boolean allowAddSite(String id)
Check if the current user is allowed to add a site.
true if allowed, false otherwise
Tool and Page Access
ToolConfiguration findTool(String id)
Access a ToolConfiguration by ID from any site.
The ToolConfiguration, or null if not found
findPage
SitePage findPage(String id)
Access a Page by ID from any site.
The SitePage, or null if not found
Utility Methods
siteReference
String siteReference(String id)
Get the internal reference for accessing a site.
The internal reference (e.g., “/site/“)
isUserSite
boolean isUserSite(String site)
Check if this site ID or reference is a user site (My Workspace).
true if this is a user site
isSpecialSite
boolean isSpecialSite(String site)
Check if this site ID or reference is a special site (starts with ’!’).
true if this is a special site
Site Object
The Site interface provides access to site properties and structure:
Site site = siteService.getSite(siteId);
// Basic Properties
String id = site.getId();
String title = site.getTitle();
String description = site.getDescription();
String type = site.getType();
// Status
boolean published = site.isPublished();
boolean joinable = site.isJoinable();
String joinerRole = site.getJoinerRole();
// Display
String skin = site.getSkin();
String iconUrl = site.getIconUrl();
String infoUrl = site.getInfoUrl();
// Structure
List<SitePage> pages = site.getPages();
List<SitePage> orderedPages = site.getOrderedPages();
Collection<Group> groups = site.getGroups();
// Membership (extends AuthzGroup)
Set<Member> members = site.getMembers();
Member member = site.getMember(userId);
Set<String> users = site.getUsers();
boolean hasRole = site.hasRole(userId, roleId);
// Metadata
User createdBy = site.getCreatedBy();
User modifiedBy = site.getModifiedBy();
Date createdDate = site.getCreatedDate();
Date modifiedDate = site.getModifiedDate();
See Also