Skip to main content

Overview

The CalendarService manages calendars and calendar events in Sakai LMS. Each site can have one or more calendars containing events that can be viewed, edited, and shared. Package: org.sakaiproject.calendar.api Source: /calendar/calendar-api/api/src/java/org/sakaiproject/calendar/api/CalendarService.java

Constants

Application Identifiers

Event Types

Security Permissions

View Types

Recurrence Modification Types

Calendar Management

addCalendar

Create a new calendar.
String
required
The new calendar reference
Returns: The newly created CalendarEdit object Throws:
  • IdUsedException - If the reference is already in use
  • IdInvalidException - If the reference contains invalid characters
  • PermissionException - If the user lacks permission to add calendars
Note: You must call commitCalendar() to finalize or cancelCalendar() to discard Example:

getCalendar

Retrieve a specific calendar.
String
required
The calendar reference
Returns: The Calendar with the specified reference Throws:
  • IdUnusedException - If the calendar doesn’t exist
  • PermissionException - If the user lacks permissions
Example:

editCalendar

Get a locked calendar for editing.
String
required
The calendar reference
Returns: A CalendarEdit object for editing Throws:
  • IdUnusedException - If the calendar doesn’t exist
  • PermissionException - If the user lacks permission
  • InUseException - If the calendar is locked by another user
Note: Must call commitCalendar(), cancelCalendar(), or removeCalendar() when done

commitCalendar

Commit changes to a calendar and release the lock.
CalendarEdit
required
The calendar edit object to commit
Note: The CalendarEdit is disabled after this call

cancelCalendar

Cancel changes to a calendar and release the lock.
CalendarEdit
required
The calendar edit object to cancel

removeCalendar

Remove a calendar that is locked for edit.
CalendarEdit
required
The calendar to remove
Throws: PermissionException if the user lacks permission

Event Management

getEvents

Merge events from multiple calendars within a time range.
List
required
List of calendar references
TimeRange
Time period to select events (null = one year before and after)
Returns: CalendarEventVector with the union of all events Example:

getFilteredEvents

Retrieve filtered events for the current user.
Map<EventFilterKey, Object>
required
Filter options (supports “limit” and “siteId”)
Returns: List of CalendarEvent objects matching the filter Example:

Recurrence

newRecurrence

Create a new recurrence rule.
String
required
The frequency description (“DAILY”, “WEEKLY”, “MONTHLY”, “YEARLY”)
int
The recurrence interval
int
Number of occurrences
Time
Time after which recurrences stop
Returns: A new RecurrenceRule object Example:

Reference Methods

calendarReference

Get the internal reference for a calendar.
String
required
The context (site ID)
String
required
The calendar ID
Returns: The internal reference string

eventReference

Get the internal reference for an event.
String
required
The context (site ID)
String
required
The calendar ID
String
required
The event ID
Returns: The internal reference string for the event

calendarICalReference

Get the iCal reference for a calendar.
Reference
required
The calendar reference
Returns: The iCal reference string

calendarPdfReference

Get the PDF reference for a calendar.
String
required
The context (site ID)
String
required
The calendar ID
int
required
The view type (DAY_VIEW, WEEK_VIEW, etc.)
String
required
Time range for the PDF
String
required
The user name for the PDF
boolean
required
Whether to reverse event order
Returns: The PDF reference string

Permission Checking

allowGetCalendar

Check if the user can get a calendar.
String
required
The calendar reference
Returns: true if the user is allowed to get the calendar

allowEditCalendar

Check if the user can edit a calendar.
String
required
The calendar reference
Returns: true if the user can edit the calendar

allowImportCalendar

Check if the user can import calendar events.
String
required
The calendar reference
Returns: true if the user can import events

allowSubscribeCalendar

Check if the user can subscribe to external calendars.
String
required
The calendar reference
Returns: true if the user can subscribe to external calendars

Export and Subscription

getExportEnabled

Check if public iCal export is enabled for a calendar.
String
required
The calendar reference
Returns: true if export is enabled

setExportEnabled

Enable or disable public iCal export for a calendar.
String
required
The calendar reference
boolean
required
True to enable, false to disable

Utility Methods

getCalendarReferences

Get all calendar references for a site.
String
required
The site ID
Returns: List of calendar reference strings

isCalendarToolInitialized

Check if the calendar tool has been initialized for a site.
String
required
The site ID
Returns: true if the calendar has been created

getUpcomingDaysLimit

Get the limit on upcoming days for filtered events.
Returns: The number of days (default 60, configurable via calendar.upcoming_days_limit)

Complete Example

See Also