/** * Get the user's notification option for this... one of the NotificationService's PREF_ settings */ protected int getOption(User user, Notification notification, Event event) { return getOption(user, notification.getId(), notification.getResourceFilter(), event .getPriority(), event); }
public void notifySiteParticipant(String filter) { List<Notification> notifications = notificationService().findNotifications( "gradebook.updateItemScore", filter); for (Notification notification : notifications) { String eventDataString = notification.getProperties().getProperty("SAKAI:conditionEventState"); Event event = eventTrackingService().newEvent( "cond+" + notification.getFunction(), notification.getResourceFilter() + eventDataString, false); NotificationAction action = notification.getAction(); action.notify(notification, event); } }
/** * Filter the preference option based on the notification resource type. Alias call to * {@link isImmediateDeliveryOption(int, Sring)}. * * @param option * The preference option. * @param notification * The notification responding to the event. * @return A boolean value which tells if the User is one of immediate recipients. */ protected boolean isImmediateDeliveryOption(int option, Notification notification) { return isImmediateDeliveryOption(option, notification.getResourceFilter()); }
/** * This method is called whenever the observed object is changed. An application calls an <tt>Observable</tt> object's <code>notifyObservers</code> method to have all the object's observers notified of the change. default implementation is to * cause the courier service to deliver to the interface controlled by my controller. Extensions can override. * * @param o * the observable object. * @param arg * an argument passed to the <code>notifyObservers</code> method. */ public void update(Observable o, Object arg) { // arg is Event if (!(arg instanceof Event)) return; Event event = (Event) arg; // check the event function against the functions we have notifications watching for String function = event.getEvent(); // for each notification watching for this event List notifications = getNotifications(function); for (Iterator it = notifications.iterator(); it.hasNext();) { Notification notification = (Notification) it.next(); // if the resource matches the notification's resource filter if (match(notification.getResourceFilter(), event.getResource())) { // cause the notification to run notification.notify(event); } } } // update
public class CustomGridViewAdapter extends ArrayAdapter<Category> implements Notifiable { int layoutResourceId; public CustomGridViewAdapter(Context context, int layoutResourceId) { super(context, layoutResourceId); this.layoutResourceId = layoutResourceId; loadCategories(false); NotificationCenter.singelton().addObserver(NotificationID.IMAGES_CACHE_READY, this); } public void onDestroy() { NotificationCenter.singelton().removeObserver(this); } @Override public void onNotification(Notification notify) { switch (notify.getId()) { case IMAGES_CACHE_READY: loadCategories(true); break; } } ... }
/** * Get a Set of all the notifications that are interested in this Event function. Note: instead of this looking, we could have an additional "key" in storage of the event... -ggolen * * @param function * The Event function * @return The Set (Notification) of all the notifications that are interested in this Event function. */ public List getAll(String function) { List rv = new Vector(); if (function == null) return rv; List all = super.getAllResources(); for (Iterator it = all.iterator(); it.hasNext();) { Notification notification = (Notification) it.next(); if (notification.containsFunction(function)) { rv.add(notification); } } return rv; }
/** * @inheritDoc */ public Notification findNotification(String function, String filter) { // start with all those for this function (just 'cause we have a nice method to get them -ggolden) List notifications = getNotifications(function); for (Iterator iNotifications = notifications.iterator(); iNotifications.hasNext();) { Notification notification = (Notification) iNotifications.next(); if (notification.getResourceFilter().equals(filter)) { return notification; } } return null; }
/** * @inheritDoc */ public List getNotifications(String function) { List notifications = m_storage.getAll(function); // if none found in storage if (notifications == null) { notifications = new Vector(); } // add transients for (Iterator it = m_transients.iterator(); it.hasNext();) { Notification notification = (Notification) it.next(); if (notification.containsFunction(function)) { notifications.add(notification); } } return notifications; }
/** * Do the notification. * * @param notification * The notification responding to the event. * @param event * The event that matched criteria to cause the notification. */ public void notify(Notification notification, Event event) { reNotify(notification.getId(), notification.getResourceFilter(), event.getPriority(), event); }
/** * @inheritDoc */ public List<Notification> findNotifications(String function, String filter) { List<Notification> notificationsFound = new ArrayList<Notification>(); // start with all those for this function (just 'cause we have a nice method to get them -ggolden) List notifications = getNotifications(function); for (Iterator iNotifications = notifications.iterator(); iNotifications.hasNext();) { Notification notification = (Notification) iNotifications.next(); if (notification.getResourceFilter().startsWith(filter) && !notificationsFound.contains(notification)) { notificationsFound.add(notification); } } return notificationsFound; }
/** * Filter the recipients Users into the list of those who get this one by digest. Combine the * event's notification priority with the user's notification profile. Alias call to * {@link digestRecipients(List, String, String, int)} * * @param recipients * The List (User) of potential recipients. * @param notification * The notification responding to the event. * @param event * The event that matched criteria to cause the notification. * @return The List (User) of digest recipients. */ protected List digestRecipients(List recipients, Notification notification, Event event) { return digestRecipients(recipients, notification.getId(), notification.getResourceFilter(), event.getPriority(), event); }
/** * Filter the recipients Users into the list of those who get this one immediately. Combine the * event's notification priority with the user's notification profile. Alias call to * {@link immediateRecipients(List<String>, String, String, int)} * * @param recipients * The List (User) of potential recipients. * @param notification * The notification responding to the event. * @param event * The event that matched criteria to cause the notification. * @return The List (User) of immediate recipients. */ protected List immediateRecipients(List recipients, Notification notification, Event event) { return immediateRecipients(recipients, notification.getId(), notification.getResourceFilter(), event.getPriority(), event); }