Search in sources :

Example 16 with TitleItem

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

the class FolderNotificationsHandler method createTitleInfo.

@Override
public String createTitleInfo(Subscriber subscriber, Locale locale) {
    Translator translator = Util.createPackageTranslator(FolderNotificationsHandler.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)

Example 17 with TitleItem

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

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 18 with TitleItem

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

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 19 with TitleItem

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

the class CalendarNotificationHandler method createSubscriptionInfo.

@Override
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
    if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
        Long id = p.getResId();
        String type = p.getSubidentifier();
        try {
            Translator translator = Util.createPackageTranslator(CalendarModule.class, locale);
            String calType = null;
            String title = null;
            if (type.equals(CalendarController.ACTION_CALENDAR_COURSE)) {
                RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance("CourseModule", id), false);
                if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
                    return NotificationsManager.getInstance().getNoSubscriptionInfo();
                }
                String displayName = re.getDisplayname();
                calType = CalendarManager.TYPE_COURSE;
                title = translator.translate("cal.notifications.header.course", new String[] { displayName });
            } else if (type.equals(CalendarController.ACTION_CALENDAR_GROUP)) {
                BusinessGroup group = businessGroupDao.load(id);
                calType = CalendarManager.TYPE_GROUP;
                if (group == null) {
                    return notificationsManager.getNoSubscriptionInfo();
                }
                title = translator.translate("cal.notifications.header.group", new String[] { group.getName() });
            }
            if (calType != null) {
                Formatter form = Formatter.getInstance(locale);
                si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, CSS_CLASS_CALENDAR_ICON), null);
                String bPath;
                if (StringHelper.containsNonWhitespace(p.getBusinessPath())) {
                    bPath = p.getBusinessPath();
                } else if ("CalendarManager.course".equals(p.getResName())) {
                    try {
                        OLATResourceable ores = OresHelper.createOLATResourceableInstance(CourseModule.getCourseTypeName(), p.getResId());
                        RepositoryEntry re = repositoryManager.lookupRepositoryEntry(ores, true);
                        // Fallback
                        bPath = "[RepositoryEntry:" + re.getKey() + "]";
                    } catch (Exception e) {
                        log.error("Error processing calendar notifications of publisher:" + p.getKey(), e);
                        return notificationsManager.getNoSubscriptionInfo();
                    }
                } else {
                    // cannot make link without business path
                    return notificationsManager.getNoSubscriptionInfo();
                }
                Kalendar cal = calendarManager.getCalendar(calType, id.toString());
                Collection<KalendarEvent> calEvents = cal.getEvents();
                for (KalendarEvent kalendarEvent : calEvents) {
                    if (showEvent(compareDate, kalendarEvent)) {
                        log.debug("found a KalendarEvent: " + kalendarEvent.getSubject() + " with time: " + kalendarEvent.getBegin() + " modified before: " + compareDate.toString(), null);
                        // found a modified event in this calendar
                        Date modDate = null;
                        if (kalendarEvent.getLastModified() > 0) {
                            modDate = new Date(kalendarEvent.getLastModified());
                        } else if (kalendarEvent.getCreated() > 0) {
                            modDate = new Date(kalendarEvent.getCreated());
                        } else if (kalendarEvent.getBegin() != null) {
                            modDate = kalendarEvent.getBegin();
                        }
                        String subject = kalendarEvent.getSubject();
                        String author = kalendarEvent.getCreatedBy();
                        if (author == null)
                            author = "";
                        String location = "";
                        if (StringHelper.containsNonWhitespace(kalendarEvent.getLocation())) {
                            location = kalendarEvent.getLocation() == null ? "" : translator.translate("cal.notifications.location", new String[] { kalendarEvent.getLocation() });
                        }
                        String dateStr;
                        if (kalendarEvent.isAllDayEvent()) {
                            dateStr = form.formatDate(kalendarEvent.getBegin());
                        } else {
                            dateStr = form.formatDate(kalendarEvent.getBegin()) + " - " + form.formatDate(kalendarEvent.getEnd());
                        }
                        String desc = translator.translate("cal.notifications.entry", new String[] { subject, dateStr, location, author });
                        String businessPath = bPath + "[path=" + kalendarEvent.getID() + ":0]";
                        String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                        SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSS_CLASS_CALENDAR_ICON);
                        si.addSubscriptionListItem(subListItem);
                    }
                }
            }
        } catch (Exception e) {
            log.error("Unexpected exception", e);
            checkPublisher(p);
            si = notificationsManager.getNoSubscriptionInfo();
        }
    } else {
        si = notificationsManager.getNoSubscriptionInfo();
    }
    return si;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) OLATResourceable(org.olat.core.id.OLATResourceable) Formatter(org.olat.core.util.Formatter) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) 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) Kalendar(org.olat.commons.calendar.model.Kalendar) Translator(org.olat.core.gui.translator.Translator)

Example 20 with TitleItem

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

the class NewUsersNotificationHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    Publisher p = subscriber.getPublisher();
    Date latestNews = p.getLatestNewsDate();
    SubscriptionInfo si;
    Translator translator = Util.createPackageTranslator(this.getClass(), locale);
    // there could be news for me, investigate deeper
    try {
        if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
            List<Identity> identities = UsersSubscriptionManager.getInstance().getNewIdentityCreated(compareDate);
            if (identities.isEmpty()) {
                si = NotificationsManager.getInstance().getNoSubscriptionInfo();
            } else {
                translator = Util.createPackageTranslator(this.getClass(), locale);
                si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(getItemTitle(identities, translator), CSSHelper.CSS_CLASS_GROUP), null);
                SubscriptionListItem subListItem;
                for (Identity newUser : identities) {
                    String desc = translator.translate("notifications.entry", new String[] { NotificationHelper.getFormatedName(newUser) });
                    String businessPath = "[Identity:" + newUser.getKey() + "]";
                    String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                    Date modDate = newUser.getCreationDate();
                    subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSSHelper.CSS_CLASS_USER);
                    si.addSubscriptionListItem(subListItem);
                }
            }
        } else {
            si = NotificationsManager.getInstance().getNoSubscriptionInfo();
        }
    } catch (Exception e) {
        log.error("Error creating new identity's notifications for subscriber: " + subscriber.getKey(), e);
        si = NotificationsManager.getInstance().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) Identity(org.olat.core.id.Identity) Date(java.util.Date)

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