Search in sources :

Example 86 with SubscriptionListItem

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

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

the class FolderNotificationsHandler 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(final Subscriber subscriber, Locale locale, Date compareDate) {
    Publisher p = subscriber.getPublisher();
    Date latestNews = p.getLatestNewsDate();
    String genericBusinessPath = p.getBusinessPath() + "[path=";
    SubscriptionInfo si;
    // there could be news for me, investigate deeper
    try {
        if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
            if ("CourseModule".equals(p.getResName())) {
                RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false);
                if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
                    return NotificationsManager.getInstance().getNoSubscriptionInfo();
                }
            }
            String folderRoot = p.getData();
            final List<FileInfo> fInfos = FolderManager.getFileInfos(folderRoot, compareDate);
            final Translator translator = Util.createPackageTranslator(FolderNotificationsHandler.class, locale);
            si = new SubscriptionInfo(subscriber.getKey(), p.getType(), getTitleItem(p, translator), null);
            SubscriptionListItem subListItem;
            for (Iterator<FileInfo> it_infos = fInfos.iterator(); it_infos.hasNext(); ) {
                FileInfo fi = it_infos.next();
                String title = fi.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 = fi.getMetaInfo();
                String iconCssClass = null;
                if (metaInfo != null) {
                    if (metaInfo.getTitle() != null) {
                        title += " (" + metaInfo.getTitle() + ")";
                    }
                    iconCssClass = metaInfo.getIconCssClass();
                }
                Identity ident = fi.getAuthor();
                Date modDate = fi.getLastModified();
                String desc = translator.translate("notifications.entry", new String[] { title, NotificationHelper.getFormatedName(ident) });
                String urlToSend = null;
                String businessPath = null;
                if (p.getBusinessPath() != null) {
                    businessPath = genericBusinessPath + fi.getRelPath() + "]";
                    urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                }
                subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass);
                si.addSubscriptionListItem(subListItem);
            }
        } else {
            si = NotificationsManager.getInstance().getNoSubscriptionInfo();
        }
    } catch (Exception e) {
        log.error("Error creating folder's notifications for subscriber: " + subscriber.getKey(), e);
        checkPublisher(subscriber.getPublisher());
        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) 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) Identity(org.olat.core.id.Identity)

Example 88 with SubscriptionListItem

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

Example 89 with SubscriptionListItem

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

the class GTANotifications method appendSubscriptionItemForFile.

private void appendSubscriptionItemForFile(String notificationKey, String[] params, String idPath, String fileCategory, File file, Date modificationDate, boolean coach) {
    if (modificationDate == null) {
        cal.setTimeInMillis(file.lastModified());
        modificationDate = cal.getTime();
    }
    if (modificationDate.compareTo(compareDate) >= 0) {
        String desc = translator.translate(notificationKey, params);
        String businessPath = subscriber.getPublisher().getBusinessPath();
        if (coach) {
            businessPath += "[Coach:0]";
        }
        if (StringHelper.containsNonWhitespace(idPath)) {
            businessPath += idPath;
        }
        if (StringHelper.containsNonWhitespace(fileCategory)) {
            businessPath += fileCategory;
        }
        if (file != null) {
            businessPath += "[path=" + file.getName() + ":0]";
        }
        String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
        String iconCssClass = GTANotificationsHandler.CSS_CLASS_ICON;
        SubscriptionListItem item = new SubscriptionListItem(desc, urlToSend, businessPath, modificationDate, iconCssClass);
        items.add(item);
    }
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem)

Example 90 with SubscriptionListItem

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

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)

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