Search in sources :

Example 6 with TitleItem

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

the class FeedNotificationsHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si;
    Publisher p = subscriber.getPublisher();
    Date latestNews = p.getLatestNewsDate();
    try {
        final Translator translator = Util.createPackageTranslator(FeedMainController.class, locale);
        if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
            String title;
            try {
                RepositoryEntry re = repoManager.lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false);
                if (re.getAccess() == RepositoryEntry.DELETED || re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
                    return notificationsManager.getNoSubscriptionInfo();
                }
                String displayName = re.getDisplayname();
                if ("CourseModule".equals(p.getResName())) {
                    ICourse course = CourseFactory.loadCourse(re);
                    CourseNode node = course.getRunStructure().getNode(p.getSubidentifier());
                    if (node == null) {
                        notificationsManager.deactivate(p);
                        return notificationsManager.getNoSubscriptionInfo();
                    }
                    title = translator.translate(NOTIFICATIONS_HEADER_COURSE, new String[] { displayName });
                } else {
                    title = getHeader(translator, displayName);
                }
            } catch (Exception e) {
                log.error("Unknown Exception", e);
                return notificationsManager.getNoSubscriptionInfo();
            }
            OLATResourceable feedOres = OresHelper.createOLATResourceableInstance(p.getType(), new Long(p.getData()));
            Feed feed = feedManager.loadFeed(feedOres);
            List<Item> listItems = feedManager.loadItems(feed);
            List<SubscriptionListItem> items = new ArrayList<>();
            for (Item item : listItems) {
                if (!item.isDraft()) {
                    appendSubscriptionItem(item, p, compareDate, translator, items);
                }
            }
            si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, getCssClassIcon()), items);
        } else {
            // no news
            si = notificationsManager.getNoSubscriptionInfo();
        }
    } catch (Exception e) {
        log.error("Unknown Exception", e);
        si = notificationsManager.getNoSubscriptionInfo();
    }
    return si;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) 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) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) Item(org.olat.modules.webFeed.Item) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Translator(org.olat.core.gui.translator.Translator) CourseNode(org.olat.course.nodes.CourseNode) Feed(org.olat.modules.webFeed.Feed)

Example 7 with TitleItem

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

the class ForumNotificationsHandler method getTitleItem.

private TitleItem getTitleItem(Publisher p, final Translator translator) {
    Long resId = p.getResId();
    String type = p.getResName();
    String title;
    try {
        if ("BusinessGroup".equals(type)) {
            BusinessGroup bg = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(resId);
            title = translator.translate("notifications.header.group", new String[] { bg.getName() });
        } else if ("CourseModule".equals(type)) {
            String displayName = RepositoryManager.getInstance().lookupDisplayNameByOLATResourceableId(resId);
            title = translator.translate("notifications.header.course", new String[] { displayName });
        } else {
            title = translator.translate("notifications.header");
        }
    } catch (Exception e) {
        log.error("Error while creating assessment notifications for publisher: " + p.getKey(), e);
        checkPublisher(p);
        title = translator.translate("notifications.header");
    }
    return new TitleItem(title, ForumHelper.CSS_ICON_CLASS_FORUM);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) BusinessGroupService(org.olat.group.BusinessGroupService) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem)

Example 8 with TitleItem

use of org.olat.core.commons.services.notifications.model.TitleItem 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 9 with TitleItem

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

the class PFNotificationsHandler method getTitleItem.

private TitleItem getTitleItem(Publisher p, Translator translator) {
    String title;
    try {
        String resName = p.getResName();
        if ("BusinessGroup".equals(resName)) {
            BusinessGroup bg = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(p.getResId());
            title = translator.translate("notifications.header.group", new String[] { bg.getName() });
        } else if ("CourseModule".equals(resName)) {
            String displayName = RepositoryManager.getInstance().lookupDisplayNameByOLATResourceableId(p.getResId());
            title = translator.translate("notifications.header.course", new String[] { displayName });
        } else {
            title = translator.translate("notifications.header");
        }
    } catch (Exception e) {
        log.error("", e);
        checkPublisher(p);
        title = translator.translate("notifications.header");
    }
    return new TitleItem(title, CSSHelper.CSS_CLASS_FILETYPE_FOLDER);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) BusinessGroupService(org.olat.group.BusinessGroupService) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem)

Example 10 with TitleItem

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

the class FeedNotificationsHandler method createTitleInfo.

@Override
public String createTitleInfo(Subscriber subscriber, Locale locale) {
    Translator translator = Util.createPackageTranslator(FeedMainController.class, locale);
    TitleItem title = getTitleItem(subscriber.getPublisher(), translator);
    return title.getInfoContent("text/plain");
}
Also used : Translator(org.olat.core.gui.translator.Translator) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem)

Aggregations

TitleItem (org.olat.core.commons.services.notifications.model.TitleItem)44 Translator (org.olat.core.gui.translator.Translator)34 Publisher (org.olat.core.commons.services.notifications.Publisher)26 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)26 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)26 Date (java.util.Date)24 BusinessGroup (org.olat.group.BusinessGroup)14 RepositoryEntry (org.olat.repository.RepositoryEntry)14 Identity (org.olat.core.id.Identity)12 OLATResourceable (org.olat.core.id.OLATResourceable)10 ICourse (org.olat.course.ICourse)10 BusinessGroupService (org.olat.group.BusinessGroupService)10 CourseNode (org.olat.course.nodes.CourseNode)4 DENCourseNode (de.bps.course.nodes.DENCourseNode)2 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Kalendar (org.olat.commons.calendar.model.Kalendar)2 KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)2 InfoMessage (org.olat.commons.info.InfoMessage)2