Search in sources :

Example 51 with SubscriptionInfo

use of org.olat.core.commons.services.notifications.SubscriptionInfo 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)

Example 52 with SubscriptionInfo

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

the class NotificationsManagerImpl method sendEmail.

private boolean sendEmail(Identity to, Translator translator, List<SubscriptionItem> subItems) {
    String title = translator.translate("rss.title", new String[] { NotificationHelper.getFormatedName(to) });
    StringBuilder htmlText = new StringBuilder();
    htmlText.append("<style>");
    htmlText.append(".o_m_sub h4 {margin: 0 0 10px 0;}");
    htmlText.append(".o_m_sub ul {padding: 0 0 5px 20px; margin: 0;}");
    htmlText.append(".o_m_sub ul li {padding: 0; margin: 1px 0;}");
    htmlText.append(".o_m_go {padding: 5px 0 0 0}");
    htmlText.append(".o_date {font-size: 90%; color: #888}");
    htmlText.append(".o_m_footer {background: #FAFAFA; border: 1px solid #eee; border-radius: 5px; padding: 0 0.5em 0.5em 0.5em; margin: 1em 0 1em 0;' class='o_m_h'}");
    htmlText.append("</style>");
    for (Iterator<SubscriptionItem> it_subs = subItems.iterator(); it_subs.hasNext(); ) {
        SubscriptionItem subitem = it_subs.next();
        // o_m_wrap class for overriding styles in master mail template
        htmlText.append("<div class='o_m_wrap'>");
        // add background here for gmail as they ignore classes.
        htmlText.append("<div class='o_m_sub' style='background: #FAFAFA; padding: 5px 5px; margin: 10px 0;'>");
        // 1: title
        htmlText.append(subitem.getTitle());
        htmlText.append("\n");
        // 2: content
        String desc = subitem.getDescription();
        if (StringHelper.containsNonWhitespace(desc)) {
            htmlText.append(desc);
        }
        // 3: goto-link
        String link = subitem.getLink();
        if (StringHelper.containsNonWhitespace(link)) {
            htmlText.append("<div class='o_m_go'><a href=\"").append(link).append("\">");
            SubscriptionInfo subscriptionInfo = subitem.getSubsInfo();
            if (subscriptionInfo != null) {
                String innerType = subscriptionInfo.getType();
                String typeName = NewControllerFactory.translateResourceableTypeName(innerType, translator.getLocale());
                String open = translator.translate("resource.open", new String[] { typeName });
                htmlText.append(open);
                htmlText.append(" &raquo;</a></div>");
            }
        }
        htmlText.append("\n");
        htmlText.append("</div></div>");
    }
    String basePath = Settings.getServerContextPathURI() + "/auth/HomeSite/" + to.getKey() + "/";
    htmlText.append("<div class='o_m_footer'>");
    htmlText.append(translator.translate("footer.notifications", new String[] { basePath + "mysettings/0", basePath += "notifications/0", basePath + "/tab/1" }));
    htmlText.append("</div>");
    MailerResult result = null;
    try {
        MailBundle bundle = new MailBundle();
        bundle.setToId(to);
        bundle.setContent(title, htmlText.toString());
        result = CoreSpringFactory.getImpl(MailManager.class).sendExternMessage(bundle, null, true);
    } catch (Exception e) {
    // FXOLAT-294 :: sending the mail will throw nullpointer exception if To-Identity has no
    // valid email-address!, catch it...
    }
    if (result == null || result.getReturnCode() > 0) {
        if (result != null)
            log.warn("Could not send email to identity " + to.getName() + ". (returncode=" + result.getReturnCode() + ", to=" + to + ")");
        else
            log.warn("Could not send email to identity " + to.getName() + ". (returncode = null) , to=" + to + ")");
        return false;
    } else {
        return true;
    }
}
Also used : SubscriptionItem(org.olat.core.commons.services.notifications.SubscriptionItem) MailerResult(org.olat.core.util.mail.MailerResult) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) NoSubscriptionInfo(org.olat.core.commons.services.notifications.model.NoSubscriptionInfo) MailBundle(org.olat.core.util.mail.MailBundle) AssertException(org.olat.core.logging.AssertException)

Example 53 with SubscriptionInfo

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

the class CertificationNotificationHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si = null;
    Publisher p = subscriber.getPublisher();
    if (!NotificationsUpgradeHelper.checkCourse(p)) {
        // course don't exist anymore
        NotificationsManager.getInstance().deactivate(p);
        return NotificationsManager.getInstance().getNoSubscriptionInfo();
    }
    try {
        Date latestNews = p.getLatestNewsDate();
        Identity identity = subscriber.getIdentity();
        Translator trans = Util.createPackageTranslator(CertificateController.class, locale);
        // can't be loaded when already deleted
        if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
            Long courseId = new Long(p.getData());
            final ICourse course = CourseFactory.loadCourse(courseId);
            if (courseStatus(course)) {
                // course admins or users with the course right to have full access to
                // the assessment tool will have full access to user tests
                RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
                List<Certificate> certificates = certificatesManager.getCertificatesForNotifications(identity, entry, latestNews);
                for (Certificate certificate : certificates) {
                    Date modDate = certificate.getCreationDate();
                    Identity assessedIdentity = certificate.getIdentity();
                    String fullname = userManager.getUserDisplayName(assessedIdentity);
                    String desc = trans.translate("notifications.desc", new String[] { fullname });
                    String urlToSend = null;
                    String businessPath = null;
                    if (p.getBusinessPath() != null) {
                        businessPath = p.getBusinessPath() + "[assessmentTool:0][Identity:" + assessedIdentity.getKey() + "]";
                        urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                    }
                    SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, "o_icon_certificate");
                    if (si == null) {
                        String title = trans.translate("notifications.header", new String[] { course.getCourseTitle() });
                        si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, "o_icon_certificate"), null);
                    }
                    si.addSubscriptionListItem(subListItem);
                }
            }
        }
        if (si == null) {
            si = NotificationsManager.getInstance().getNoSubscriptionInfo();
        }
        return si;
    } catch (Exception e) {
        log.error("Error while creating assessment notifications", e);
        return NotificationsManager.getInstance().getNoSubscriptionInfo();
    }
}
Also used : SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) ICourse(org.olat.course.ICourse) Publisher(org.olat.core.commons.services.notifications.Publisher) RepositoryEntry(org.olat.repository.RepositoryEntry) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) Date(java.util.Date) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Translator(org.olat.core.gui.translator.Translator) Identity(org.olat.core.id.Identity) Certificate(org.olat.course.certificate.Certificate)

Example 54 with SubscriptionInfo

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

the class GTANotificationsHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    Publisher p = subscriber.getPublisher();
    Date latestNews = p.getLatestNewsDate();
    SubscriptionInfo si;
    // there could be news for me, investigate deeper
    try {
        if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
            GTANotifications notifications = new GTANotifications(subscriber, locale, compareDate, repositoryService, gtaManager, businessGroupService, userManager, courseNodeAssessmentDao);
            List<SubscriptionListItem> items = notifications.getItems();
            if (items.isEmpty()) {
                si = NotificationsManager.getInstance().getNoSubscriptionInfo();
            } else {
                String title = notifications.getNotifificationHeader();
                TitleItem titleItem = new TitleItem(title, CSS_CLASS_ICON);
                si = new SubscriptionInfo(subscriber.getKey(), p.getType(), titleItem, items);
            }
        } else {
            si = NotificationsManager.getInstance().getNoSubscriptionInfo();
        }
    } catch (Exception e) {
        log.error("Cannot create gtask notifications for subscriber: " + subscriber.getKey(), e);
        // checkPublisher(p);
        si = NotificationsManager.getInstance().getNoSubscriptionInfo();
    }
    return si;
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) Date(java.util.Date)

Example 55 with SubscriptionInfo

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

the class PFNotificationsHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si = null;
    Publisher p = subscriber.getPublisher();
    try {
        final Translator translator = Util.createPackageTranslator(PFRunController.class, locale);
        PFNotifications notifications = new PFNotifications(subscriber, locale, compareDate, pfManager, notificationsManager, userManager);
        List<SubscriptionListItem> items = notifications.getItems();
        if (items.isEmpty()) {
            si = notificationsManager.getNoSubscriptionInfo();
        } else {
            String displayName = notifications.getDisplayname();
            String title = translator.translate("notifications.header", new String[] { displayName });
            si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, CSS_CLASS_ICON), items);
        }
    } catch (Exception e) {
        log.error("Unknown Exception", e);
        si = notificationsManager.getNoSubscriptionInfo();
    }
    return si;
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Translator(org.olat.core.gui.translator.Translator) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem)

Aggregations

SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)56 Publisher (org.olat.core.commons.services.notifications.Publisher)44 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)38 Date (java.util.Date)36 Translator (org.olat.core.gui.translator.Translator)30 TitleItem (org.olat.core.commons.services.notifications.model.TitleItem)28 Identity (org.olat.core.id.Identity)24 RepositoryEntry (org.olat.repository.RepositoryEntry)18 ArrayList (java.util.ArrayList)10 Subscriber (org.olat.core.commons.services.notifications.Subscriber)10 OLATResourceable (org.olat.core.id.OLATResourceable)10 ICourse (org.olat.course.ICourse)10 NotificationsHandler (org.olat.core.commons.services.notifications.NotificationsHandler)8 Locale (java.util.Locale)6 FileInfo (org.olat.core.commons.modules.bc.FileInfo)6 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)6 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)6 SubscriptionItem (org.olat.core.commons.services.notifications.SubscriptionItem)6 NoSubscriptionInfo (org.olat.core.commons.services.notifications.model.NoSubscriptionInfo)6 AssertException (org.olat.core.logging.AssertException)6