Search in sources :

Example 11 with SubscriptionItem

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

the class NotificationsManagerImpl method processSubscribersByEmail.

private void processSubscribersByEmail(Identity ident) {
    if (ident.getStatus().compareTo(Identity.STATUS_VISIBLE_LIMIT) >= 0) {
        // send only to active user
        return;
    }
    String userInterval = getUserIntervalOrDefault(ident);
    if ("never".equals(userInterval)) {
        return;
    }
    long start = System.currentTimeMillis();
    Date compareDate = getCompareDateFromInterval(userInterval);
    Property p = propertyManager.findProperty(ident, null, null, null, LATEST_EMAIL_USER_PROP);
    if (p != null) {
        Date latestEmail = new Date(p.getLongValue());
        if (latestEmail.after(compareDate)) {
            // nothing to do
            return;
        }
    }
    Date defaultCompareDate = getDefaultCompareDate();
    List<Subscriber> subscribers = getSubscribers(ident);
    if (subscribers.isEmpty()) {
        return;
    }
    String langPrefs = null;
    if (ident.getUser() != null && ident.getUser().getPreferences() != null) {
        langPrefs = ident.getUser().getPreferences().getLanguage();
    }
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(langPrefs);
    boolean veto = false;
    Subscriber latestSub = null;
    List<SubscriptionItem> items = new ArrayList<>();
    List<Subscriber> subsToUpdate = new ArrayList<>();
    for (Subscriber sub : subscribers) {
        Date latestEmail = sub.getLatestEmailed();
        SubscriptionItem subsitem = null;
        if (latestEmail == null || compareDate.after(latestEmail)) {
            // no notif. ever sent until now
            if (latestEmail == null) {
                latestEmail = defaultCompareDate;
            } else if (latestEmail.before(defaultCompareDate)) {
                // no notification older than a month
                latestEmail = defaultCompareDate;
            }
            subsitem = createSubscriptionItem(sub, locale, SubscriptionInfo.MIME_HTML, SubscriptionInfo.MIME_HTML, latestEmail);
        } else if (latestEmail != null && latestEmail.after(compareDate)) {
        // already send an email within the user's settings interval
        // veto = true;
        }
        if (subsitem != null) {
            items.add(subsitem);
            subsToUpdate.add(sub);
        }
        latestSub = sub;
    }
    Translator translator = Util.createPackageTranslator(NotificationSubscriptionController.class, locale);
    notifySubscribersByEmail(latestSub, items, subsToUpdate, translator, start, veto);
}
Also used : Locale(java.util.Locale) SubscriptionItem(org.olat.core.commons.services.notifications.SubscriptionItem) Subscriber(org.olat.core.commons.services.notifications.Subscriber) Translator(org.olat.core.gui.translator.Translator) ArrayList(java.util.ArrayList) Property(org.olat.properties.Property) Date(java.util.Date)

Example 12 with SubscriptionItem

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

the class NotificationsManagerImpl method createSubscriptionItem.

@Override
public SubscriptionItem createSubscriptionItem(SubscriptionInfo subsInfo, Subscriber subscriber, Locale locale, String mimeTypeTitle, String mimeTypeContent) {
    Publisher pub = subscriber.getPublisher();
    String title = getFormatedTitle(subsInfo, subscriber, locale, mimeTypeTitle);
    String itemLink = null;
    if (subsInfo.getCustomUrl() != null) {
        itemLink = subsInfo.getCustomUrl();
    }
    if (itemLink == null && pub.getBusinessPath() != null) {
        itemLink = BusinessControlFactory.getInstance().getURLFromBusinessPathString(pub.getBusinessPath());
    }
    String description = subsInfo.getSpecificInfo(mimeTypeContent, locale);
    SubscriptionItem subscriptionItem = new SubscriptionItem(title, itemLink, description);
    subscriptionItem.setSubsInfo(subsInfo);
    return subscriptionItem;
}
Also used : SubscriptionItem(org.olat.core.commons.services.notifications.SubscriptionItem) Publisher(org.olat.core.commons.services.notifications.Publisher)

Aggregations

SubscriptionItem (org.olat.core.commons.services.notifications.SubscriptionItem)12 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)6 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)4 Publisher (org.olat.core.commons.services.notifications.Publisher)4 Subscriber (org.olat.core.commons.services.notifications.Subscriber)4 NoSubscriptionInfo (org.olat.core.commons.services.notifications.model.NoSubscriptionInfo)4 AssertException (org.olat.core.logging.AssertException)4 Locale (java.util.Locale)2 NotificationsHandler (org.olat.core.commons.services.notifications.NotificationsHandler)2 Translator (org.olat.core.gui.translator.Translator)2 MailBundle (org.olat.core.util.mail.MailBundle)2 MailerResult (org.olat.core.util.mail.MailerResult)2 Property (org.olat.properties.Property)2