Skip to content

Commit

Permalink
KNL-62
Browse files Browse the repository at this point in the history
Patch from Carl Hall

Fixes Delayed events structure

Thanks


git-svn-id: https://source.sakaiproject.org/svn/kernel/trunk@53024 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information
ieb committed Oct 2, 2008
1 parent f0026d8 commit f6c8c61
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public interface ContentHostingService extends EntityProducer
/** Name of the event when removing a resource. */
public static final String EVENT_RESOURCE_REMOVE = "content.delete";

/** Name of the event when removing a resource. */
public static final String EVENT_RESOURCE_AVAILABLE = "content.available";

/** Security function for creating a resource. */
public static final String AUTH_RESOURCE_ADD = "content.new";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public static org.sakaiproject.content.api.ContentHostingService getInstance()
public static java.lang.String EVENT_RESOURCE_WRITE = org.sakaiproject.content.api.ContentHostingService.EVENT_RESOURCE_WRITE;

public static java.lang.String EVENT_RESOURCE_REMOVE = org.sakaiproject.content.api.ContentHostingService.EVENT_RESOURCE_REMOVE;
String EVENT_RESOURCE_AVAILABLE = org.sakaiproject.content.api.ContentHostingService.EVENT_RESOURCE_AVAILABLE;

public static java.lang.String AUTH_RESOURCE_ADD = org.sakaiproject.content.api.ContentHostingService.AUTH_RESOURCE_ADD;
public static java.lang.String AUTH_RESOURCE_READ = org.sakaiproject.content.api.ContentHostingService.AUTH_RESOURCE_READ;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package org.sakaiproject.event.api;

import java.util.List;

import org.sakaiproject.time.api.Time;

/**
* Event delayers delay an event for future propagation by the system.
*/
public interface EventDelayHandler
{
/**
* Read an event delay by a specified delay ID.
*
* @param delayId
* @return
*/
Event readDelay(String delayId);

/**
* Read a list of event delay IDs using the provided event and user ID.
*
* @param event
* @param userId
* @return
*/
List<String> findDelayIds(Event event, String userId);

/**
* Read a list of event delay IDs using the provided event. Does not look at the user ID.
*
* @param event
* @return
*/
List<String> findDelayIds(Event event);

/**
* Read a list of event delay IDs using resource and event.
*
* @param resource
* @param event
* @return
*/
List<String> findDelayIds(String resource, String event);

/**
* Read a list of event delay IDs using resource and event.
*
* @param resource
* @param event
* @return
*/
List<String> findDelayIds(String resource);

/**
* Schedules a delayed invocation of this notification to run at the requested time.
*
* @param event
* @return The ID of the delay
*/
String createDelay(Event event, Time fireTime);

/**
* Schedules a delayed invocation of this notification to run at the requested time.
*
* @param event
* @param userId
* @return The ID of the delay
*/
String createDelay(Event event, String userId, Time fireTime);

/**
* Delete an event delay by referencing the delay ID.
*
* @param delayId
* @return
*/
boolean deleteDelayById(String delayId);

/**
* Delete an event delay by matching the event information.
*
* @param e
* @return
*/
boolean deleteDelay(Event e);

/**
* Delete a delayed event by matching resource and event
*
* @param resource
* @param event
* @return
*/
boolean deleteDelay(String resource, String event);

/**
* Delete all delayed events for a resource
*
* @param resource
* @param event
* @return
*/
boolean deleteDelay(String resource);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.util.Observer;

import org.sakaiproject.time.api.Time;
import org.sakaiproject.user.api.User;

/**
Expand Down Expand Up @@ -144,16 +145,33 @@ public interface EventTrackingService
void deleteObserver(Observer observer);

/**
* Add an event voter.
* Sets the event delay handler if the service is to allow events to be delayed to a specified
* firing time.
*
* @param voter
* @param handler
*/
void addVoter(EventVoter voter);
void setEventDelayHandler(EventDelayHandler handler);

/**
* Delete an event voter.
* Schedule an event to be fired at a specific time. If the time is null or already passed, the
* event is fired immediately.
*
* @param voter
* @param event
* @param fireTime
*/
void delay(Event event, Time fireTime);

/**
* Cancel all delayed events for a resource that haven't yet fired.
*
* @param resource
*/
void cancelDelays(String resource);

/**
* Cancel delays for a resource of a certain event
* @param resource
* @param event
*/
void deleteVoter(EventVoter voter);
void cancelDelays(String resource, String event);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
package org.sakaiproject.event.cover;

import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.event.api.Event;
import org.sakaiproject.time.api.Time;

/**
* <p>
Expand Down Expand Up @@ -128,4 +130,28 @@ public static void post(org.sakaiproject.event.api.Event param0)

service.post(param0);
}

public static void delay(Event event, Time fireTime)
{
org.sakaiproject.event.api.EventTrackingService service = getInstance();
if (service == null) return;

service.delay(event, fireTime);
}

public static void cancelDelays(String resource)
{
org.sakaiproject.event.api.EventTrackingService service = getInstance();
if (service == null) return;

service.cancelDelays(resource);
}

public static void cancelDelays(String resource, String event)
{
org.sakaiproject.event.api.EventTrackingService service = getInstance();
if (service == null) return;

service.cancelDelays(resource, event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@
import org.sakaiproject.util.BaseResourcePropertiesEdit;
import org.sakaiproject.util.Blob;
import org.sakaiproject.util.DefaultEntityHandler;
import org.sakaiproject.util.EntityReaderAdapter;
import org.sakaiproject.util.SAXEntityReader;
import org.sakaiproject.util.StorageUser;
import org.sakaiproject.util.StringUtil;
Expand Down Expand Up @@ -2569,8 +2568,10 @@ public void removeCollection(ContentCollectionEdit edit) throws TypeException, P
}

// track it (no notification)
EventTrackingService.post(EventTrackingService.newEvent(EVENT_RESOURCE_REMOVE, edit.getReference(null), true,
String ref = edit.getReference(null);
EventTrackingService.post(EventTrackingService.newEvent(EVENT_RESOURCE_REMOVE, ref, true,
NotificationService.NOTI_NONE));
EventTrackingService.cancelDelays(ref);

} // removeCollection

Expand Down Expand Up @@ -2690,11 +2691,29 @@ public void commitCollection(ContentCollectionEdit edit)
//ThreadLocalManager.set("getResources@" + containerId, null);

// track it (no notification)
EventTrackingService.post(EventTrackingService.newEvent(((BaseCollectionEdit) edit).getEvent(), edit.getReference(null), true,
NotificationService.NOTI_NONE));
// delete any delays for this same event then fire new event
String ref = edit.getReference(null);
EventTrackingService.cancelDelays(ref, ((BaseCollectionEdit) edit).getEvent());
EventTrackingService.post(EventTrackingService.newEvent(((BaseCollectionEdit) edit)
.getEvent(), ref, true, NotificationService.NOTI_NONE));

postAvailableEvent(edit, ref);

} // commitCollection

private void postAvailableEvent(GroupAwareEntity entity, String ref)
{
// cancel all scheduled available events for this entity.
EventTrackingService.cancelDelays(ref, EVENT_RESOURCE_AVAILABLE);

// if resource isn't available yet, schedule an event to tell when it becomes available
if (entity.isAvailable())
{
EventTrackingService.delay(EventTrackingService.newEvent(EVENT_RESOURCE_AVAILABLE, ref,
false), entity.getReleaseDate());
}
}

/**
* Recursively traverse the heirarchy of ContentEntity objects contained within a collection and remove access groups if they
* are not included in the set defined for the initial collection. The branching stops whenever we verify a ContentCollection
Expand Down Expand Up @@ -4367,8 +4386,10 @@ public void removeResource(ContentResourceEdit edit) throws PermissionException
}

// track it (no notification)
EventTrackingService.post(EventTrackingService.newEvent(EVENT_RESOURCE_REMOVE, edit.getReference(null), true,
String ref = edit.getReference(null);
EventTrackingService.post(EventTrackingService.newEvent(EVENT_RESOURCE_REMOVE, ref, true,
NotificationService.NOTI_NONE));
EventTrackingService.cancelDelays(ref);

} // removeResource

Expand Down Expand Up @@ -4970,13 +4991,17 @@ protected String moveResource(ContentResourceEdit thisResource, String new_id) t
((BaseResourceEdit) edit).closeEdit();

// track it (no notification)
EventTrackingService.post(EventTrackingService.newEvent(EVENT_RESOURCE_ADD, edit.getReference(null), true,
String ref = edit.getReference(null);
EventTrackingService.post(EventTrackingService.newEvent(EVENT_RESOURCE_ADD, ref, true,
NotificationService.NOTI_NONE));
postAvailableEvent(edit, ref);

m_storage.removeResource(thisResource);

// track it (no notification)
EventTrackingService.post(EventTrackingService.newEvent(EVENT_RESOURCE_REMOVE, thisResource.getReference(null), true,
String thisRef = thisResource.getReference(null);
EventTrackingService.cancelDelays(thisRef);
EventTrackingService.post(EventTrackingService.newEvent(EVENT_RESOURCE_REMOVE, thisRef, true,
NotificationService.NOTI_NONE));

if (M_log.isDebugEnabled()) M_log.debug("moveResource successful");
Expand Down Expand Up @@ -5516,9 +5541,12 @@ protected void commitResourceEdit(ContentResourceEdit edit, int priority) throws
ThreadLocalManager.set("getResources@" + containerId, null);

// track it
// edit.getReference() returns the
EventTrackingService.post(EventTrackingService.newEvent(((BaseResourceEdit) edit).getEvent(), edit.getReference(null), true,
priority));
// edit.getReference() returns the
String ref = edit.getReference(null);
EventTrackingService.cancelDelays(ref, ((BaseResourceEdit) edit).getEvent());
EventTrackingService.post(EventTrackingService.newEvent(((BaseResourceEdit) edit).getEvent(),
ref, true, priority));
postAvailableEvent(edit, ref);

} // commitResourceEdit

Expand Down Expand Up @@ -7884,8 +7912,10 @@ protected ContentResource mergeResource(Element element, byte[] body) throws Per
}

// track it
EventTrackingService.post(EventTrackingService.newEvent(((BaseResourceEdit) edit).getEvent(), edit.getReference(null), true,
String ref = edit.getReference(null);
EventTrackingService.post(EventTrackingService.newEvent(((BaseResourceEdit) edit).getEvent(), ref, true,
NotificationService.NOTI_NONE));
postAvailableEvent(edit, ref);

// close the edit object
((BaseResourceEdit) edit).closeEdit();
Expand Down
Loading

0 comments on commit f6c8c61

Please sign in to comment.