Search in sources :

Example 11 with SubscriptionListItem

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

the class EPNotificationManager method getRatingNotifications.

public List<SubscriptionListItem> getRatingNotifications(List<Long> mapKey, String rootBusinessPath, Date compareDate, Translator translator) {
    List<EPRatingNotification> ratings = getRatingNotifications(mapKey, compareDate);
    List<SubscriptionListItem> items = new ArrayList<SubscriptionListItem>();
    for (EPRatingNotification rating : ratings) {
        if (rating.getPageKey() == null) {
            String[] title = new String[] { rating.getMapTitle(), userManager.getUserDisplayName(rating.getAuthor()) };
            String linkUrl = BusinessControlFactory.getInstance().getURLFromBusinessPathString(rootBusinessPath);
            if (rating.getLastModified() != null) {
                // there is a modified date, also add this as a listitem
                items.add(new SubscriptionListItem(translator.translate("li.changerating", title), linkUrl, rootBusinessPath, rating.getLastModified(), "o_icon_rating_on"));
            }
            items.add(new SubscriptionListItem(translator.translate("li.newrating", title), linkUrl, rootBusinessPath, rating.getCreationDate(), "o_icon_rating_on"));
        } else {
            String bPath = rootBusinessPath + "[EPPage:" + rating.getPageKey() + "]";
            String linkUrl = BusinessControlFactory.getInstance().getURLFromBusinessPathString(bPath);
            String[] title = new String[] { rating.getTitle(), userManager.getUserDisplayName(rating.getAuthor()) };
            if (rating.getLastModified() != null) {
                // there is a modified date, also add this as a listitem
                SubscriptionListItem item = new SubscriptionListItem(translator.translate("li.changerating", title), linkUrl, bPath, rating.getLastModified(), "o_icon_rating_on");
                item.setUserObject(rating.getPageKey());
                items.add(item);
            }
            SubscriptionListItem item = new SubscriptionListItem(translator.translate("li.newrating", title), linkUrl, bPath, rating.getCreationDate(), "o_icon_rating_on");
            item.setUserObject(rating.getPageKey());
            items.add(item);
        }
    }
    return items;
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) EPRatingNotification(org.olat.portfolio.model.notification.EPRatingNotification) ArrayList(java.util.ArrayList)

Example 12 with SubscriptionListItem

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

the class EPNotificationManager method getPageSubscriptionListItem.

public List<SubscriptionListItem> getPageSubscriptionListItem(Long mapKey, String rootBusinessPath, Date compareDate, Translator translator) {
    List<EPStructureElementNotification> notifications = getPageNotifications(mapKey, compareDate);
    List<SubscriptionListItem> items = new ArrayList<SubscriptionListItem>();
    for (EPNotification notification : notifications) {
        SubscriptionListItem item = null;
        String[] title = new String[] { StringHelper.escapeHtml(notification.getTitle()) };
        if ("page".equals(notification.getType())) {
            String bPath = rootBusinessPath + "[EPPage:" + notification.getPageKey() + "]";
            String linkUrl = BusinessControlFactory.getInstance().getURLFromBusinessPathString(bPath);
            item = new SubscriptionListItem(translator.translate("li.newpage", title), linkUrl, bPath, notification.getCreationDate(), "o_ep_icon_page");
            item.setUserObject(notification.getPageKey());
        } else {
            String bPath = rootBusinessPath;
            if (notification.getPageKey() != null) {
                bPath = rootBusinessPath + "[EPPage:" + notification.getPageKey() + "]";
            }
            String linkUrl = BusinessControlFactory.getInstance().getURLFromBusinessPathString(bPath);
            item = new SubscriptionListItem(translator.translate("li.newstruct", title), linkUrl, bPath, notification.getCreationDate(), "o_ep_icon_struct");
            item.setUserObject(notification.getPageKey());
        }
        if (item != null) {
            items.add(item);
        }
    }
    return items;
}
Also used : EPStructureElementNotification(org.olat.portfolio.model.notification.EPStructureElementNotification) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) ArrayList(java.util.ArrayList) EPNotification(org.olat.portfolio.model.notification.EPNotification)

Example 13 with SubscriptionListItem

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

the class AbstractTaskNotificationHandler method createSubscriptionInfo.

/**
 * @see org.olat.core.commons.services.notifications.NotificationsHandler#createSubscriptionInfo(org.olat.core.commons.services.notifications.Subscriber,
 *      java.util.Locale, java.util.Date)
 */
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)) {
            String folderRoot = p.getData();
            if (isLogDebugEnabled()) {
                logDebug("folderRoot=", folderRoot);
            }
            final List<FileInfo> fInfos = FolderManager.getFileInfos(folderRoot, compareDate);
            final Translator translator = Util.createPackageTranslator(AbstractTaskNotificationHandler.class, locale);
            RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance("CourseModule", p.getResId()), false);
            if (re == null) {
                if (!checkPublisher(p)) {
                    return NotificationsManager.getInstance().getNoSubscriptionInfo();
                }
            } else if (re.getRepositoryEntryStatus().isClosed()) {
                return NotificationsManager.getInstance().getNoSubscriptionInfo();
            }
            String displayName = re.getDisplayname();
            si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(translator.translate(getNotificationHeaderKey(), new String[] { displayName }), getCssClassIcon()), null);
            SubscriptionListItem subListItem;
            for (Iterator<FileInfo> it_infos = fInfos.iterator(); it_infos.hasNext(); ) {
                FileInfo fi = it_infos.next();
                MetaInfo metaInfo = fi.getMetaInfo();
                String filePath = fi.getRelPath();
                if (isLogDebugEnabled())
                    logDebug("filePath=", filePath);
                String fullUserName = getUserNameFromFilePath(metaInfo, filePath);
                Date modDate = fi.getLastModified();
                String desc = translator.translate(getNotificationEntryKey(), new String[] { filePath, fullUserName });
                String businessPath = p.getBusinessPath();
                String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                String iconCssClass = null;
                if (metaInfo != null) {
                    iconCssClass = metaInfo.getIconCssClass();
                }
                subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass);
                si.addSubscriptionListItem(subListItem);
            }
        } else {
            si = NotificationsManager.getInstance().getNoSubscriptionInfo();
        }
    } catch (Exception e) {
        getLogger().error("Cannot create task notifications for subscriber: " + subscriber.getKey(), e);
        checkPublisher(p);
        si = NotificationsManager.getInstance().getNoSubscriptionInfo();
    }
    return si;
}
Also used : MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) 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) FileInfo(org.olat.core.commons.modules.bc.FileInfo) Translator(org.olat.core.gui.translator.Translator)

Example 14 with SubscriptionListItem

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

the class EPChangelogController method getItemBundlesForSubscriptionItems.

/**
 * @param subscriptionItems
 * @return
 */
private List<SubscriptionItemBundle> getItemBundlesForSubscriptionItems(List<SubscriptionListItem> subscriptionItems) {
    List<SubscriptionItemBundle> bundles = new ArrayList<EPChangelogController.SubscriptionItemBundle>();
    Formatter f = Formatter.getInstance(getTranslator().getLocale());
    for (int i = 0; i < subscriptionItems.size(); i++) {
        SubscriptionListItem listItem = subscriptionItems.get(i);
        SubscriptionItemBundle bundle = new SubscriptionItemBundle();
        bundle.setDateString(f.formatDate(listItem.getDate()));
        String linkName = "subscrIL_" + i;
        bundle.setLinkName(linkName);
        String text = listItem.getDescription();
        FormLink link = uifactory.addFormLink(linkName, text, null, flc, Link.NONTRANSLATED);
        link.setUserObject(listItem.getUserObject());
        bundle.setCssClass(listItem.getIconCssClass());
        bundles.add(bundle);
    }
    return bundles;
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Formatter(org.olat.core.util.Formatter) ArrayList(java.util.ArrayList) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 15 with SubscriptionListItem

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

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)

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