Search in sources :

Example 1 with NotificationsHandler

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

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 2 with NotificationsHandler

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

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 3 with NotificationsHandler

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

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 4 with NotificationsHandler

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

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)

Example 5 with NotificationsHandler

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

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)

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