Search in sources :

Example 11 with NotificationsHandler

use of org.olat.core.commons.services.notifications.NotificationsHandler in project openolat by klemens.

the class NotificationsPortletRunController method getAllPortletEntries.

private List<PortletEntry<Subscriber>> getAllPortletEntries() {
    notificationsList = man.getValidSubscribers(getIdentity());
    // calc subscriptioninfo for all subscriptions and, if only those with news are to be shown, remove the other ones
    for (Iterator<Subscriber> it_subs = notificationsList.iterator(); it_subs.hasNext(); ) {
        Subscriber subscriber = it_subs.next();
        Publisher pub = subscriber.getPublisher();
        NotificationsHandler notifHandler = man.getNotificationsHandler(pub);
        if (notifHandler == null) {
            it_subs.remove();
        } else {
            SubscriptionInfo subsInfo = notifHandler.createSubscriptionInfo(subscriber, getLocale(), compareDate);
            if (!subsInfo.hasNews()) {
                it_subs.remove();
            }
        }
    }
    return convertNotificationToPortletEntryList(notificationsList);
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsHandler(org.olat.core.commons.services.notifications.NotificationsHandler) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 12 with NotificationsHandler

use of org.olat.core.commons.services.notifications.NotificationsHandler in project openolat by klemens.

the class NotificationsManagerImpl method createSubscriptionItem.

/**
 * @param subscriber
 * @param locale
 * @param mimeType
 * @param latestEmailed needs to be given! SubscriptionInfo is collected from then until latestNews of publisher
 * @return null if the publisher is not valid anymore (deleted), or if there are no news
 */
@Override
public SubscriptionItem createSubscriptionItem(Subscriber subscriber, Locale locale, String mimeTypeTitle, String mimeTypeContent, Date latestEmailed) {
    if (latestEmailed == null)
        throw new AssertException("compareDate may not be null, use a date from history");
    try {
        boolean debug = isLogDebugEnabled();
        SubscriptionItem si = null;
        Publisher pub = subscriber.getPublisher();
        NotificationsHandler notifHandler = getNotificationsHandler(pub);
        if (debug)
            logDebug("create subscription with handler: " + notifHandler.getClass().getName());
        // do not create subscription item when deleted
        if (isPublisherValid(pub) && notifHandler != null) {
            if (debug)
                logDebug("NotifHandler: " + notifHandler.getClass().getName() + " compareDate: " + latestEmailed.toString() + " now: " + new Date().toString(), null);
            SubscriptionInfo subsInfo = notifHandler.createSubscriptionInfo(subscriber, locale, latestEmailed);
            if (subsInfo.hasNews()) {
                si = createSubscriptionItem(subsInfo, subscriber, locale, mimeTypeTitle, mimeTypeContent);
            }
        }
        return si;
    } catch (Exception e) {
        log.error("Cannot generate a subscription item.", e);
        return null;
    }
}
Also used : SubscriptionItem(org.olat.core.commons.services.notifications.SubscriptionItem) AssertException(org.olat.core.logging.AssertException) NotificationsHandler(org.olat.core.commons.services.notifications.NotificationsHandler) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) NoSubscriptionInfo(org.olat.core.commons.services.notifications.model.NoSubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher) Date(java.util.Date) AssertException(org.olat.core.logging.AssertException)

Aggregations

NotificationsHandler (org.olat.core.commons.services.notifications.NotificationsHandler)12 Publisher (org.olat.core.commons.services.notifications.Publisher)10 Subscriber (org.olat.core.commons.services.notifications.Subscriber)6 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)6 Date (java.util.Date)4 NoSubscriptionInfo (org.olat.core.commons.services.notifications.model.NoSubscriptionInfo)4 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 SubscriptionItem (org.olat.core.commons.services.notifications.SubscriptionItem)2 AssertException (org.olat.core.logging.AssertException)2