Skip to main content
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
REFERENCE_ROOT
String
default:"/site"
Root path for site resource references
ADMIN_SITE_ID
String
default:"!admin"
The site ID for the admin workspace
SITE_TEMPLATE
String
default:"!worksite"
Template site for non-user sites
USER_SITE_TEMPLATE
String
default:"!user"
Template site for user sites

Security Functions

SECURE_ADD_SITE
String
default:"site.add"
Permission to add a site
SECURE_REMOVE_SITE
String
default:"site.del"
Permission to remove a site
SECURE_UPDATE_SITE
String
default:"site.upd"
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.
id
String
required
The site ID string
Site
Site
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.
id
String
required
The site ID string
Optional<Site>
Optional<Site>
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.
id
String
required
The site ID string
Site
Site
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.
id
String
The site ID string (returns false if null)
boolean
boolean
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.
id
String
required
The site ID
type
String
required
The site type (e.g., “course”, “project”)
Site
Site
The new Site object
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.
id
String
required
The new site ID
other
Site
required
The site to copy structure from
Site
Site
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.
site
Site
required
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.
site
Site
required
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.
id
String
required
The site ID to update
description
String
required
The updated description
infoUrl
String
required
The updated info URL

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.
site
Site
required
The site to remove
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.
requireDescription
boolean
default:"true"
When true, full descriptions included; when false, may be omitted
includeUnpublishedSites
boolean
default:"false"
When true, include unpublished sites
List<Site>
List<Site>
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.
type
SelectionType
required
Selection type (ACCESS, UPDATE, JOINABLE, PUBVIEW, ANY, etc.)
ofType
Object
Site type criteria: null for any; String for single type; String[]/List/Set for multiple
criteria
String
Match string in site id, title, description, or skin
propertyCriteria
Map<String,String>
Property name-value pairs to match
sort
SortType
required
Sort order (TITLE_ASC, TITLE_DESC, CREATED_ON_ASC, etc.)
page
PagingPosition
Subset of items to return
List<Site>
List<Site>
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.
type
SelectionType
required
Selection type
List<String>
List<String>
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.
int
int
Count of sites matching criteria

Selection Types

The SelectionType class defines filtering criteria:
ACCESS
SelectionType
Sites the current user has read access to (non-special, non-myWorkspace)
UPDATE
SelectionType
Sites the current user has write access to
JOINABLE
SelectionType
Sites the current user can join but doesn’t have read access to
PUBVIEW
SelectionType
Sites marked for public view
ANY
SelectionType
Any sites
MEMBER
SelectionType
Sites the current user is a member of (regardless of published status)
DELETED
SelectionType
Soft-deleted sites for current user

Sort Types

The SortType class defines sorting options:
TITLE_ASC
SortType
Sort by title ascending
TITLE_DESC
SortType
Sort by title descending
CREATED_ON_ASC
SortType
Sort by creation time ascending
CREATED_ON_DESC
SortType
Sort by creation time descending
MODIFIED_ON_ASC
SortType
Sort by modification time ascending
PUBLISHED_ASC
SortType
Sort by published status ascending

Site Membership

join

void join(String id) throws IdUnusedException, PermissionException
Cause the current user to join a site.
id
String
required
The site ID
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.
id
String
required
The site ID

isCurrentUserMemberOfSite

boolean isCurrentUserMemberOfSite(String id)
Determine if the current user is a member of the site.
id
String
required
The site ID
boolean
boolean
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.
id
String
The site ID (returns false if null)
boolean
boolean
true if allowed, false otherwise

allowUpdateSite

boolean allowUpdateSite(String id)
Check if the current user is allowed to update a site.
id
String
required
The site ID
boolean
boolean
true if allowed, false otherwise

allowAddSite

boolean allowAddSite(String id)
Check if the current user is allowed to add a site.
id
String
required
The site ID
boolean
boolean
true if allowed, false otherwise

Tool and Page Access

findTool

ToolConfiguration findTool(String id)
Access a ToolConfiguration by ID from any site.
id
String
required
The tool ID
ToolConfiguration
ToolConfiguration
The ToolConfiguration, or null if not found

findPage

SitePage findPage(String id)
Access a Page by ID from any site.
id
String
required
The page ID
SitePage
SitePage
The SitePage, or null if not found

Utility Methods

siteReference

String siteReference(String id)
Get the internal reference for accessing a site.
id
String
required
The site ID
String
String
The internal reference (e.g., “/site/“)

isUserSite

boolean isUserSite(String site)
Check if this site ID or reference is a user site (My Workspace).
site
String
required
The site ID or reference
boolean
boolean
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 ’!’).
site
String
required
The site ID or reference
boolean
boolean
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

Build docs developers (and LLMs) love