Search in sources :

Example 51 with SubscriptionListItem

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

the class SubscriptionInfo method getSpecificInfo.

/**
 * looping over List with all contained items for this subs-info
 *
 * @param mimeType the mimetype of the desired output; supported are currently
 *          text/plain and text/html
 * @return the specific (subscriber and type) info for a notification entry.
 *         e.g. "5 new posts" for a forum subscription, or "10 new uploads"
 *         for a folder subscription
 */
public String getSpecificInfo(String mimeType, Locale locale) {
    if (!hasNews())
        return "";
    StringBuilder sb = new StringBuilder();
    boolean firstDone = false;
    if (mimeType.equals(SubscriptionInfo.MIME_HTML))
        sb.append("<ul class='list-unstyled'>");
    for (SubscriptionListItem subListItem : subsList) {
        if (firstDone && mimeType.equals(SubscriptionInfo.MIME_PLAIN)) {
            sb.append("\n");
        }
        // append list item itself
        sb.append(subListItem.getContent(mimeType, locale));
        firstDone = true;
    }
    if (mimeType.equals(SubscriptionInfo.MIME_HTML))
        sb.append("</ul>");
    return sb.toString();
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem)

Example 52 with SubscriptionListItem

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

the class DENCourseNodeNotificationHandler method createSubscriptionInfo.

public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si = null;
    Publisher p = subscriber.getPublisher();
    Date latestNews = p.getLatestNewsDate();
    // can't be loaded when already deleted
    try {
        if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
            Long courseId = new Long(p.getData());
            final ICourse course = loadCourseFromId(courseId);
            if (courseStatus(course)) {
                final List<DENCourseNode> denNodes = getCourseDENNodes(course);
                final Translator trans = Util.createPackageTranslator(DENCourseNodeNotificationHandler.class, locale);
                String cssClass = new DENCourseNodeConfiguration().getIconCSSClass();
                si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(trans.translate("notifications.header", new String[] { course.getCourseTitle() }), cssClass), null);
                SubscriptionListItem subListItem;
                for (DENCourseNode denNode : denNodes) {
                    String changer = "";
                    String desc = trans.translate("notifications.entry", new String[] { denNode.getLongTitle(), changer });
                    Date modDate = new Date();
                    subListItem = new SubscriptionListItem(desc, null, null, modDate, cssClass);
                    si.addSubscriptionListItem(subListItem);
                }
            }
        } else {
            si = NotificationsManager.getInstance().getNoSubscriptionInfo();
        }
    } catch (Exception e) {
        log.error("Error creating enrollment notifications for subscriber: " + subscriber.getKey(), e);
        checkPublisher(p);
        si = NotificationsManager.getInstance().getNoSubscriptionInfo();
    }
    return si;
}
Also used : SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) ICourse(org.olat.course.ICourse) Publisher(org.olat.core.commons.services.notifications.Publisher) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) Date(java.util.Date) DENCourseNode(de.bps.course.nodes.DENCourseNode) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Translator(org.olat.core.gui.translator.Translator)

Example 53 with SubscriptionListItem

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

the class MailNotificationsHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    if (!mailModule.isInternSystem()) {
        return notificationsManager.getNoSubscriptionInfo();
    }
    String realMail = subscriber.getIdentity().getUser().getPreferences().getReceiveRealMail();
    if ("true".equals(realMail)) {
        // receive real e-mails
        return notificationsManager.getNoSubscriptionInfo();
    } else if (!StringHelper.containsNonWhitespace(realMail) && mailModule.isReceiveRealMailUserDefaultSetting()) {
        // user has no settings, check the default setting
        return notificationsManager.getNoSubscriptionInfo();
    }
    SubscriptionInfo si = null;
    Publisher p = subscriber.getPublisher();
    Date latestNews = p.getLatestNewsDate();
    // can't be loaded when already deleted
    if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
        try {
            List<DBMailLight> inbox = mailManager.getInbox(subscriber.getIdentity(), Boolean.TRUE, Boolean.FALSE, compareDate, 0, -1);
            if (!inbox.isEmpty()) {
                Translator translator = Util.createPackageTranslator(MailModule.class, locale);
                si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(translator.translate("mail.notification.type"), "o_co_icon"), null);
                for (DBMailLight mail : inbox) {
                    String subject = mail.getSubject();
                    String businessPath = "[Inbox:0][Inbox:0][DBMail:" + mail.getKey() + "]";
                    String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                    SubscriptionListItem subListItem = new SubscriptionListItem(subject, urlToSend, businessPath, mail.getCreationDate(), "o_co_icon");
                    si.addSubscriptionListItem(subListItem);
                }
            }
        } catch (Exception ex) {
            logError("", ex);
        }
    }
    if (si == null) {
        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) Date(java.util.Date) DBMailLight(org.olat.core.util.mail.model.DBMailLight)

Example 54 with SubscriptionListItem

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

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 SubscriptionListItem

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

the class DocumentPoolNotificationsHandler method createSubscriptionInfo.

private void createSubscriptionInfo(VFSContainer container, String prefixBusinessPath, Date compareDate, SubscriptionInfo si, Publisher p, Translator translator) {
    List<FileInfo> fInfos = FolderManager.getFileInfos(((OlatRelPathImpl) container).getRelPath(), compareDate);
    for (FileInfo infos : fInfos) {
        String title = infos.getRelPath();
        // known exclude prefixes
        if (title != null && title.indexOf("/.") != -1 && FileUtils.isMetaFilename(title)) {
            // skip this file, continue with next item in folder
            continue;
        }
        MetaInfo metaInfo = infos.getMetaInfo();
        String iconCssClass = null;
        if (metaInfo != null) {
            if (metaInfo.getTitle() != null) {
                title += " (" + metaInfo.getTitle() + ")";
            }
            iconCssClass = metaInfo.getIconCssClass();
        }
        Identity ident = infos.getAuthor();
        Date modDate = infos.getLastModified();
        String desc = translator.translate("notifications.document.entry", new String[] { title, NotificationHelper.getFormatedName(ident) });
        String urlToSend = null;
        String businessPath = null;
        if (p.getBusinessPath() != null) {
            businessPath = prefixBusinessPath + infos.getRelPath() + "]";
            urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
        }
        si.addSubscriptionListItem(new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass));
    }
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) FileInfo(org.olat.core.commons.modules.bc.FileInfo) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Aggregations

SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)92 Date (java.util.Date)54 Publisher (org.olat.core.commons.services.notifications.Publisher)36 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)36 ArrayList (java.util.ArrayList)32 Translator (org.olat.core.gui.translator.Translator)30 TitleItem (org.olat.core.commons.services.notifications.model.TitleItem)26 Identity (org.olat.core.id.Identity)20 RepositoryEntry (org.olat.repository.RepositoryEntry)20 OLATResourceable (org.olat.core.id.OLATResourceable)12 ICourse (org.olat.course.ICourse)10 FileInfo (org.olat.core.commons.modules.bc.FileInfo)8 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)8 Formatter (org.olat.core.util.Formatter)6 BusinessGroup (org.olat.group.BusinessGroup)6 Page (org.olat.modules.portfolio.Page)6 HashSet (java.util.HashSet)4 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)4 CourseNode (org.olat.course.nodes.CourseNode)4 Section (org.olat.modules.portfolio.Section)4