org.sakaiproject.component.legacy.calendar
Class BaseCalendarService.BaseCalendarEdit

java.lang.Object
  extended byjava.util.Observable
      extended byorg.sakaiproject.component.legacy.calendar.BaseCalendarService.BaseCalendarEdit
All Implemented Interfaces:
Calendar, CalendarEdit, Edit, Entity, EventListener, SessionBindingListener
Enclosing class:
BaseCalendarService

public class BaseCalendarService.BaseCalendarEdit
extends Observable
implements CalendarEdit, SessionBindingListener

Calendar implementation


Field Summary
protected  boolean m_active
          Active flag.
protected  String m_context
          The context in which this calendar exists.
protected  String m_event
          The event code for this edit.
protected  String m_id
          Store the unique-in-context calendar id.
protected  boolean m_isRemoved
          When true, the calendar has been removed.
protected  ResourcePropertiesEdit m_properties
          The properties.
 
Fields inherited from interface org.sakaiproject.service.legacy.entity.Entity
SEPARATOR
 
Constructor Summary
BaseCalendarService.BaseCalendarEdit(Calendar other)
          Construct as a copy of another.
BaseCalendarService.BaseCalendarEdit(Element el)
          Construct from a calendar (and possibly events) already defined in XML in a DOM tree.
BaseCalendarService.BaseCalendarEdit(String ref)
          Construct with an id.
 
Method Summary
protected  void activate()
          Enable editing.
 CalendarEventEdit addEvent()
          Add a new event to this calendar.
 CalendarEvent addEvent(TimeRange range, String displayName, String description, String type, String location, List attachments)
          Add a new event to this calendar.
 boolean allowAddEvent()
          check permissions for addEvent().
 boolean allowEditEvent(String eventId)
          check permissions for editEvent()
 boolean allowGetEvents()
          check permissions for getEvents() and getEvent().
 boolean allowRemoveEvent(CalendarEvent event)
          check permissions for removeEvent().
 void cancelEvent(CalendarEventEdit edit)
          Cancel the changes made to a CalendarEventEdit object, and release the lock.
protected  void closeEdit()
          Close the edit object - it cannot be used after this.
 void commitEvent(CalendarEventEdit edit)
          Commit the changes made to a CalendarEventEdit object, and release the lock.
 void commitEvent(CalendarEventEdit edit, int intention)
          Commit the changes made to a CalendarEventEdit object, and release the lock.
 CalendarEventEdit editEvent(String eventId)
          Return a specific calendar event, as specified by event name, locked for update.
protected  List filterEvents(List events, TimeRange range)
          Filter the events to only those in the time range.
protected  void finalize()
          Clean up.
protected  CalendarEvent findEvent(String eventId)
          Find the event, in cache or info store - cache it if newly found.
 String getContext()
          Access the context of the resource.
protected  String getEvent()
          Access the event code for this edit.
 CalendarEvent getEvent(String eventId)
          Return a specific calendar event, as specified by event id.
 String getEventFields()
          Return the extra fields kept for each event in this calendar.
 List getEvents(TimeRange range, Filter filter)
          Return a List of all or filtered events in the calendar.
 String getId()
          Access the id of the resource.
 ResourceProperties getProperties()
          Access the collection's properties.
 ResourcePropertiesEdit getPropertiesEdit()
          Access the resource's properties for modification
 String getReference()
          Access the internal reference which can be used to access the resource from within the system.
 String getReference(String rootProperty)
          Access the alternate internal reference which can be used to access the entity from within the system.
 String getUrl()
          Access the URL which can be used to access the resource.
 String getUrl(String rootProperty)
          Access the alternate URL which can be used to access the entity.
 boolean isActiveEdit()
          Check to see if the edit is still active, or has already been closed.
 CalendarEventEdit mergeEvent(Element el)
          Merge in a new event as defined in the xml.
 void notify(Event event)
          Notify the calendar that it has changed
 void removeEvent(CalendarEventEdit edit)
          Remove an event from the calendar, one locked for edit.
 void removeEvent(CalendarEventEdit edit, int intention)
          Remove an event from the calendar, one locked for edit.
protected  void setEvent(String event)
          Set the event code for this edit.
 void setEventFields(String fields)
          Set the extra fields kept for each event in this calendar.
 void setRemoved(Event event)
          Set the calendar as removed.
 Element toXml(Document doc, Stack stack)
          Serialize the resource into XML, adding an element to the doc under the top of the stack element.
 void valueBound(SessionBindingEvent event)
          SessionBindingListener implementation
 void valueUnbound(SessionBindingEvent event)
          Notifies the object that it is being unbound from a session.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_context

protected String m_context
The context in which this calendar exists.


m_id

protected String m_id
Store the unique-in-context calendar id.


m_properties

protected ResourcePropertiesEdit m_properties
The properties.


m_isRemoved

protected boolean m_isRemoved
When true, the calendar has been removed.


m_event

protected String m_event
The event code for this edit.


m_active

protected boolean m_active
Active flag.

Constructor Detail

BaseCalendarService.BaseCalendarEdit

public BaseCalendarService.BaseCalendarEdit(String ref)
Construct with an id.

Parameters:
ref - The calendar reference.

BaseCalendarService.BaseCalendarEdit

public BaseCalendarService.BaseCalendarEdit(Calendar other)
Construct as a copy of another.


BaseCalendarService.BaseCalendarEdit

public BaseCalendarService.BaseCalendarEdit(Element el)
Construct from a calendar (and possibly events) already defined in XML in a DOM tree. The Calendar is added to storage.

Parameters:
el - The XML DOM element defining the calendar.
Method Detail

finalize

protected void finalize()
Clean up.


setRemoved

public void setRemoved(Event event)
Set the calendar as removed.

Parameters:
event - The tracking event associated with this action.

getContext

public String getContext()
Access the context of the resource.

Specified by:
getContext in interface Calendar
Returns:
The context.

getId

public String getId()
Access the id of the resource.

Specified by:
getId in interface Entity
Returns:
The id.

getUrl

public String getUrl()
Access the URL which can be used to access the resource.

Specified by:
getUrl in interface Entity
Returns:
The URL which can be used to access the resource.

getReference

public String getReference()
Access the internal reference which can be used to access the resource from within the system.

Specified by:
getReference in interface Entity
Returns:
The the internal reference which can be used to access the resource from within the system.

getReference

public String getReference(String rootProperty)
Description copied from interface: Entity
Access the alternate internal reference which can be used to access the entity from within the system.

Specified by:
getReference in interface Entity
Parameters:
rootProperty - The name of the entity property whose value controls which alternate reference is requested. If null, the native 'raw' reference is requested.
Returns:
The the alternate internal reference which can be used to access the entity from within the system.

getUrl

public String getUrl(String rootProperty)
Description copied from interface: Entity
Access the alternate URL which can be used to access the entity.

Specified by:
getUrl in interface Entity
Parameters:
rootProperty - The name of the entity property whose value controls which alternate reference URL is requested. If null, the native 'raw' URL is requested.
Returns:
The alternate URL which can be used to access the entity.

getProperties

public ResourceProperties getProperties()
Access the collection's properties.

Specified by:
getProperties in interface Entity
Returns:
The collection's properties.

allowGetEvents

public boolean allowGetEvents()
check permissions for getEvents() and getEvent().

Specified by:
allowGetEvents in interface Calendar
Returns:
true if the user is allowed to get events from the calendar, false if not.

getEvents

public List getEvents(TimeRange range,
                      Filter filter)
               throws PermissionException
Return a List of all or filtered events in the calendar. The order in which the events will be found in the iteration is by event start date.

Specified by:
getEvents in interface Calendar
Parameters:
range - A time range to limit the iterated events. May be null; all events will be returned.
filter - A filtering object to accept events into the iterator, or null if no filtering is desired.
Returns:
a List of all or filtered CalendarEvents in the calendar (may be empty).
Throws:
PermissionException - if the user does not have read permission to the calendar.

filterEvents

protected List filterEvents(List events,
                            TimeRange range)
Filter the events to only those in the time range.

Parameters:
events - The full list of events.
range - The time range.
Returns:
A list of events from the incoming list that overlap the given time range.

getEvent

public CalendarEvent getEvent(String eventId)
                       throws IdUnusedException,
                              PermissionException
Return a specific calendar event, as specified by event id.

Specified by:
getEvent in interface Calendar
Parameters:
eventId - The id of the event to get.
Returns:
the CalendarEvent that has the specified id.
Throws:
IdUnusedException - If this id is not a defined event in this calendar.
PermissionException - If the user does not have any permissions to read the calendar.

allowAddEvent

public boolean allowAddEvent()
check permissions for addEvent().

Specified by:
allowAddEvent in interface Calendar
Returns:
true if the user is allowed to addEvent(...), false if not.

addEvent

public CalendarEvent addEvent(TimeRange range,
                              String displayName,
                              String description,
                              String type,
                              String location,
                              List attachments)
                       throws PermissionException
Add a new event to this calendar.

Specified by:
addEvent in interface Calendar
Parameters:
range - The event's time range.
displayName - The event's display name (PROP_DISPLAY_NAME) property value.
description - The event's description as plain text (PROP_DESCRIPTION) property value.
type - The event's calendar event type (PROP_CALENDAR_TYPE) property value.
location - The event's calendar event location (PROP_CALENDAR_LOCATION) property value.
attachments - The event attachments, a vector of Reference objects.
Returns:
The newly added event.
Throws:
PermissionException - If the user does not have permission to modify the calendar.

addEvent

public CalendarEventEdit addEvent()
                           throws PermissionException
Add a new event to this calendar. Must commitEvent() to make official, or cancelEvent() when done!

Specified by:
addEvent in interface Calendar
Returns:
The newly added event, locked for update.
Throws:
PermissionException - If the user does not have write permission to the calendar.

mergeEvent

public CalendarEventEdit mergeEvent(Element el)
                             throws PermissionException,
                                    IdUsedException
Merge in a new event as defined in the xml.

Specified by:
mergeEvent in interface Calendar
Parameters:
el - The event information in XML in a DOM element.
Throws:
PermissionException - If the user does not have write permission to the calendar.
IdUsedException - if the user id is already used.

allowRemoveEvent

public boolean allowRemoveEvent(CalendarEvent event)
check permissions for removeEvent().

Specified by:
allowRemoveEvent in interface Calendar
Parameters:
event - The event from this calendar to remove.
Returns:
true if the user is allowed to removeEvent(event), false if not.

removeEvent

public void removeEvent(CalendarEventEdit edit)
Remove an event from the calendar, one locked for edit. Note: if the event is a recurring event, the entire sequence is modified by this commit (MOD_ALL).

Specified by:
removeEvent in interface Calendar
Parameters:
edit - The event from this calendar to remove.

removeEvent

public void removeEvent(CalendarEventEdit edit,
                        int intention)
Remove an event from the calendar, one locked for edit.

Specified by:
removeEvent in interface Calendar
Parameters:
intention - The recurring event modification intention, based on values in the CalendarService "MOD_*", used if the event is part of a recurring event sequence to determine how much of the sequence is removed.
edit - The event from this calendar to remove.

allowEditEvent

public boolean allowEditEvent(String eventId)
check permissions for editEvent()

Specified by:
allowEditEvent in interface Calendar
Returns:
true if the user is allowed to update the event, false if not.

editEvent

public CalendarEventEdit editEvent(String eventId)
                            throws IdUnusedException,
                                   PermissionException,
                                   InUseException
Return a specific calendar event, as specified by event name, locked for update. Must commitEvent() to make official, or cancelEvent(), or removeEvent() when done!

Specified by:
editEvent in interface Calendar
Parameters:
eventId - The id of the event to get.
Returns:
the Event that has the specified id.
Throws:
IdUnusedException - If this name is not a defined event in this calendar.
PermissionException - If the user does not have any permissions to edit the event.
InUseException - if the event is locked for edit by someone else.

commitEvent

public void commitEvent(CalendarEventEdit edit)
Commit the changes made to a CalendarEventEdit object, and release the lock. The CalendarEventEdit is disabled, and not to be used after this call. Note: if the event is a recurring event, the entire sequence is modified by this commit (MOD_ALL).

Specified by:
commitEvent in interface Calendar
Parameters:
edit - The CalendarEventEdit object to commit.

commitEvent

public void commitEvent(CalendarEventEdit edit,
                        int intention)
Commit the changes made to a CalendarEventEdit object, and release the lock. The CalendarEventEdit is disabled, and not to be used after this call.

Specified by:
commitEvent in interface Calendar
Parameters:
edit - The CalendarEventEdit object to commit.
intention - The recurring event modification intention, based on values in the CalendarService "MOD_*", used if the event is part of a recurring event sequence to determine how much of the sequence is changed by this commmit.

cancelEvent

public void cancelEvent(CalendarEventEdit edit)
Cancel the changes made to a CalendarEventEdit object, and release the lock. The CalendarEventEdit is disabled, and not to be used after this call.

Specified by:
cancelEvent in interface Calendar
Parameters:
edit - The CalendarEventEdit object to commit.

getEventFields

public String getEventFields()
Return the extra fields kept for each event in this calendar.

Specified by:
getEventFields in interface Calendar
Returns:
the extra fields kept for each event in this calendar, formatted into a single string. %%%

setEventFields

public void setEventFields(String fields)
Set the extra fields kept for each event in this calendar.

Specified by:
setEventFields in interface CalendarEdit
Parameters:
fields - The extra fields kept for each event in this calendar, formatted into a single string. %%%

notify

public void notify(Event event)
Notify the calendar that it has changed

Parameters:
event - The event that caused the update.

toXml

public Element toXml(Document doc,
                     Stack stack)
Serialize the resource into XML, adding an element to the doc under the top of the stack element.

Specified by:
toXml in interface Entity
Parameters:
doc - The DOM doc to contain the XML (or null for a string return).
stack - The DOM elements, the top of which is the containing element of the new "resource" element.
Returns:
The newly added element.

findEvent

protected CalendarEvent findEvent(String eventId)
Find the event, in cache or info store - cache it if newly found.

Parameters:
eventId - The id of the event.
Returns:
The event, if found.

getEvent

protected String getEvent()
Access the event code for this edit.

Returns:
The event code for this edit.

setEvent

protected void setEvent(String event)
Set the event code for this edit.

Parameters:
event - The event code for this edit.

getPropertiesEdit

public ResourcePropertiesEdit getPropertiesEdit()
Access the resource's properties for modification

Specified by:
getPropertiesEdit in interface Edit
Returns:
The resource's properties.

activate

protected void activate()
Enable editing.


isActiveEdit

public boolean isActiveEdit()
Check to see if the edit is still active, or has already been closed.

Specified by:
isActiveEdit in interface Edit
Returns:
true if the edit is active, false if it's been closed.

closeEdit

protected void closeEdit()
Close the edit object - it cannot be used after this.


valueBound

public void valueBound(SessionBindingEvent event)
SessionBindingListener implementation

Specified by:
valueBound in interface SessionBindingListener
Parameters:
event - the event that identifies the session

valueUnbound

public void valueUnbound(SessionBindingEvent event)
Description copied from interface: SessionBindingListener
Notifies the object that it is being unbound from a session.

Specified by:
valueUnbound in interface SessionBindingListener
Parameters:
event - the event that identifies the session