Search in sources :

Example 6 with NotificationsHandler

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

the class NotificationsManagerImpl method getSubscriptionInfos.

@Override
public List<SubscriptionInfo> getSubscriptionInfos(Identity identity, String publisherType) {
    StringBuilder sb = new StringBuilder();
    sb.append("select sub from notisub sub").append(" inner join fetch sub.publisher as pub").append(" where sub.identity=:identity and pub.type=:type and pub.state=:aState");
    List<Subscriber> subscribers = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Subscriber.class).setParameter("aState", PUB_STATE_OK).setParameter("type", publisherType).setParameter("identity", identity).getResultList();
    if (subscribers.isEmpty()) {
        return Collections.emptyList();
    }
    Locale locale = new Locale(identity.getUser().getPreferences().getLanguage());
    Date compareDate = getDefaultCompareDate();
    List<SubscriptionInfo> sis = new ArrayList<SubscriptionInfo>();
    for (Subscriber subscriber : subscribers) {
        Publisher pub = subscriber.getPublisher();
        NotificationsHandler notifHandler = getNotificationsHandler(pub);
        // do not create subscription item when deleted
        if (isPublisherValid(pub)) {
            SubscriptionInfo subsInfo = notifHandler.createSubscriptionInfo(subscriber, locale, compareDate);
            if (subsInfo.hasNews()) {
                sis.add(subsInfo);
            }
        }
    }
    return sis;
}
Also used : Locale(java.util.Locale) Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsHandler(org.olat.core.commons.services.notifications.NotificationsHandler) ArrayList(java.util.ArrayList) 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)

Example 7 with NotificationsHandler

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

the class NotificationSubscriptionTableDataModel method getValueAt.

/**
 * @see org.olat.core.gui.components.table.DefaultTableDataModel#getValueAt(int,
 *      int)
 */
@Override
public Object getValueAt(int row, int col) {
    Subscriber sub = getObject(row);
    Publisher pub = sub.getPublisher();
    switch(col) {
        case 0:
            return sub.getKey();
        case 1:
            String innerType = pub.getType();
            return NewControllerFactory.translateResourceableTypeName(innerType, getLocale());
        case 2:
            String containerType = pub.getResName();
            return NewControllerFactory.translateResourceableTypeName(containerType, getLocale());
        case 3:
            NotificationsHandler handler = NotificationsManager.getInstance().getNotificationsHandler(pub);
            if (handler == null) {
                return "";
            }
            String title = handler.createTitleInfo(sub, getLocale());
            if (title == null) {
                return "";
            }
            return title;
        case 4:
            return sub.getCreationDate();
        case 5:
            return sub.getLatestEmailed();
        default:
            return "ERROR";
    }
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsHandler(org.olat.core.commons.services.notifications.NotificationsHandler) Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 8 with NotificationsHandler

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

the class NotificationsManagerImpl method getNotificationsHandler.

/**
 * @return the handler for the type
 */
public NotificationsHandler getNotificationsHandler(Publisher publisher) {
    String type = publisher.getType();
    if (notificationHandlers == null) {
        synchronized (lockObject) {
            if (notificationHandlers == null) {
                // check again in synchronized-block, only one may create list
                notificationHandlers = new HashMap<String, NotificationsHandler>();
                Map<String, NotificationsHandler> notificationsHandlerMap = CoreSpringFactory.getBeansOfType(NotificationsHandler.class);
                Collection<NotificationsHandler> notificationsHandlerValues = notificationsHandlerMap.values();
                for (NotificationsHandler notificationsHandler : notificationsHandlerValues) {
                    log.debug("initNotificationUpgrades notificationsHandler=" + notificationsHandler);
                    notificationHandlers.put(notificationsHandler.getType(), notificationsHandler);
                }
            }
        }
    }
    return notificationHandlers.get(type);
}
Also used : NotificationsHandler(org.olat.core.commons.services.notifications.NotificationsHandler)

Example 9 with NotificationsHandler

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

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)

Example 10 with NotificationsHandler

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

the class NotificationsManagerImpl method getFormatedTitle.

/**
 * format the type-title and title-details
 * @param subscriber
 * @param locale
 * @param mimeType
 * @return
 */
private String getFormatedTitle(SubscriptionInfo subsInfo, Subscriber subscriber, Locale locale, String mimeType) {
    Publisher pub = subscriber.getPublisher();
    StringBuilder titleSb = new StringBuilder();
    String title = subsInfo.getTitle(mimeType);
    if (StringHelper.containsNonWhitespace(title)) {
        titleSb.append(title);
    } else {
        NotificationsHandler notifHandler = getNotificationsHandler(pub);
        String titleInfo = notifHandler.createTitleInfo(subscriber, locale);
        if (StringHelper.containsNonWhitespace(titleInfo)) {
            titleSb.append(titleInfo);
        }
    }
    return titleSb.toString();
}
Also used : NotificationsHandler(org.olat.core.commons.services.notifications.NotificationsHandler) Publisher(org.olat.core.commons.services.notifications.Publisher)

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