Search in sources :

Example 36 with TitleItem

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

the class InfoMessageNotificationHandler 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.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
        try {
            final Long resId = subscriber.getPublisher().getResId();
            final String resName = subscriber.getPublisher().getResName();
            String resSubPath = subscriber.getPublisher().getSubidentifier();
            String displayName, notificationtitle;
            if ("BusinessGroup".equals(resName)) {
                BusinessGroupService groupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
                BusinessGroup group = groupService.loadBusinessGroup(resId);
                displayName = group.getName();
                notificationtitle = "notification.title.group";
            } else {
                RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(resName, resId), false);
                if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
                    return NotificationsManager.getInstance().getNoSubscriptionInfo();
                }
                displayName = re.getDisplayname();
                notificationtitle = "notification.title";
            }
            Translator translator = Util.createPackageTranslator(this.getClass(), locale);
            String title = translator.translate(notificationtitle, new String[] { displayName });
            si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, CSS_CLASS_ICON), null);
            OLATResourceable ores = OresHelper.createOLATResourceableInstance(resName, resId);
            List<InfoMessage> infos = infoMessageManager.loadInfoMessageByResource(ores, resSubPath, null, compareDate, null, 0, 0);
            for (InfoMessage info : infos) {
                Identity ident = info.getAuthor();
                String desc = translator.translate("notifications.entry", new String[] { info.getTitle(), NotificationHelper.getFormatedName(ident) });
                String tooltip = info.getMessage();
                String infoBusinessPath = info.getBusinessPath() + "[InfoMessage:" + info.getKey() + "]";
                String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(infoBusinessPath);
                Date dateInfo = info.getModificationDate() == null ? info.getCreationDate() : info.getModificationDate();
                SubscriptionListItem subListItem = new SubscriptionListItem(desc, tooltip, urlToSend, infoBusinessPath, dateInfo, CSS_CLASS_ICON);
                si.addSubscriptionListItem(subListItem);
            }
        } catch (Exception e) {
            log.error("Unexpected exception", e);
            si = NotificationsManager.getInstance().getNoSubscriptionInfo();
        }
    } else {
        si = NotificationsManager.getInstance().getNoSubscriptionInfo();
    }
    return si;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) OLATResourceable(org.olat.core.id.OLATResourceable) 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) BusinessGroupService(org.olat.group.BusinessGroupService) Translator(org.olat.core.gui.translator.Translator) InfoMessage(org.olat.commons.info.InfoMessage) Identity(org.olat.core.id.Identity)

Example 37 with TitleItem

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

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

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

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

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

the class FileUploadNotificationHandler method createSubscriptionInfo.

/**
 * @see org.olat.core.commons.services.notifications.NotificationsHandler#createSubscriptionInfo(org.olat.core.commons.services.notifications.Subscriber,
 *      java.util.Locale, java.util.Date)
 */
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    Publisher p = subscriber.getPublisher();
    final Date latestNews = p.getLatestNewsDate();
    SubscriptionInfo si;
    // there could be news for me, investigate deeper
    try {
        if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
            RepositoryEntry re = repositoryManager.lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false);
            if (re == null) {
                if (!checkPublisher(subscriber.getPublisher())) {
                    return notificationsManager.getNoSubscriptionInfo();
                }
            } else if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
                return notificationsManager.getNoSubscriptionInfo();
            }
            String displayname = re.getDisplayname();
            OLATResourceable ores = OresHelper.createOLATResourceableInstance("CourseModule", p.getResId());
            RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(ores, false);
            List<DialogElement> dialogElements = dialogElementsMgr.getDialogElements(entry, p.getSubidentifier());
            final Translator translator = Util.createPackageTranslator(DialogCourseNodeRunController.class, locale);
            si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(translator.translate("notifications.header", new String[] { displayname }), CSSS_CLASS_UPLOAD_ICON), null);
            for (DialogElement element : dialogElements) {
                // do only show entries newer then the ones already seen
                if (element.getCreationDate().after(compareDate)) {
                    String filename = element.getFilename();
                    Identity author = element.getAuthor();
                    Date modDate = element.getCreationDate();
                    String[] params = new String[] { filename, NotificationHelper.getFormatedName(author) };
                    String desc = translator.translate("notifications.entry", params);
                    String businessPath = p.getBusinessPath() + "[Element:" + element.getKey() + "]";
                    String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                    String cssClass = CSSHelper.createFiletypeIconCssClassFor(filename);
                    si.addSubscriptionListItem(new SubscriptionListItem(desc, urlToSend, businessPath, modDate, cssClass));
                }
            }
        } else {
            si = notificationsManager.getNoSubscriptionInfo();
        }
    } catch (Exception e) {
        log.error("Error creating file upload's notifications for subscriber: " + subscriber.getKey(), e);
        si = notificationsManager.getNoSubscriptionInfo();
    }
    return si;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) 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) Translator(org.olat.core.gui.translator.Translator) DialogElement(org.olat.course.nodes.dialog.DialogElement) Identity(org.olat.core.id.Identity)

Example 40 with TitleItem

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

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