Search in sources :

Example 26 with SubscriptionListItem

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

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 27 with SubscriptionListItem

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

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)

Example 28 with SubscriptionListItem

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

the class AssessmentNotificationsHandler 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(final Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si = null;
    Publisher p = subscriber.getPublisher();
    if (!NotificationsUpgradeHelper.checkCourse(p)) {
        // course don't exist anymore
        notificationsManager.deactivate(p);
        return notificationsManager.getNoSubscriptionInfo();
    }
    try {
        Date latestNews = p.getLatestNewsDate();
        Identity identity = subscriber.getIdentity();
        // can't be loaded when already deleted
        if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
            Long courseId = new Long(p.getData());
            final ICourse course = loadCourseFromId(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
                CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
                final boolean hasFullAccess = (cgm.isIdentityCourseAdministrator(identity) ? true : cgm.hasRight(identity, CourseRights.RIGHT_ASSESSMENT));
                final Set<Identity> coachedUsers = new HashSet<Identity>();
                if (!hasFullAccess) {
                    // initialize list of users, only when user has not full access
                    List<BusinessGroup> coachedGroups = cgm.getOwnedBusinessGroups(identity);
                    List<Identity> coachedIdentites = businessGroupService.getMembers(coachedGroups, GroupRoles.participant.name());
                    coachedUsers.addAll(coachedIdentites);
                }
                List<AssessableCourseNode> testNodes = getCourseTestNodes(course);
                Translator translator = Util.createPackageTranslator(AssessmentManager.class, locale);
                for (AssessableCourseNode test : testNodes) {
                    List<AssessmentEntry> assessments = courseNodeAssessmentDao.loadAssessmentEntryBySubIdent(cgm.getCourseEntry(), test.getIdent());
                    for (AssessmentEntry assessment : assessments) {
                        Date modDate = assessment.getLastModified();
                        Identity assessedIdentity = assessment.getIdentity();
                        if (modDate.after(compareDate) && (hasFullAccess || coachedUsers.contains(assessedIdentity))) {
                            BigDecimal score = assessment.getScore();
                            if (test instanceof ScormCourseNode) {
                                ScormCourseNode scormTest = (ScormCourseNode) test;
                                // check if completed or passed
                                String status = ScormAssessmentManager.getInstance().getLastLessonStatus(assessedIdentity.getName(), course.getCourseEnvironment(), scormTest);
                                if (!"passed".equals(status) && !"completed".equals(status)) {
                                    continue;
                                }
                            }
                            String desc;
                            String type = translator.translate("notifications.entry." + test.getType());
                            if (score == null) {
                                desc = translator.translate("notifications.entry.attempt", new String[] { test.getShortTitle(), NotificationHelper.getFormatedName(assessedIdentity), type });
                            } else {
                                String scoreStr = AssessmentHelper.getRoundedScore(score);
                                desc = translator.translate("notifications.entry", new String[] { test.getShortTitle(), NotificationHelper.getFormatedName(assessedIdentity), scoreStr, type });
                            }
                            String urlToSend = null;
                            String businessPath = null;
                            if (p.getBusinessPath() != null) {
                                businessPath = p.getBusinessPath() + "[Users:0][Node:" + test.getIdent() + "][Identity:" + assessedIdentity.getKey() + "]";
                                urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                            }
                            SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSS_CLASS_USER_ICON);
                            if (si == null) {
                                String title = translator.translate("notifications.header", new String[] { course.getCourseTitle() });
                                String css = CourseNodeFactory.getInstance().getCourseNodeConfigurationEvenForDisabledBB(test.getType()).getIconCSSClass();
                                si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, css), null);
                            }
                            si.addSubscriptionListItem(subListItem);
                        }
                    }
                }
            }
        }
        if (si == null) {
            si = notificationsManager.getNoSubscriptionInfo();
        }
        return si;
    } catch (Exception e) {
        log.error("Error while creating assessment notifications", e);
        checkPublisher(p);
        return notificationsManager.getNoSubscriptionInfo();
    }
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) BusinessGroup(org.olat.group.BusinessGroup) 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) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) ScormCourseNode(org.olat.course.nodes.ScormCourseNode) Date(java.util.Date) BigDecimal(java.math.BigDecimal) AssertException(org.olat.core.logging.AssertException) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Translator(org.olat.core.gui.translator.Translator) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet)

Example 29 with SubscriptionListItem

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

the class GTANotifications method appendSubscriptionItem.

private void appendSubscriptionItem(String notificationKey, String[] params, String path, Date modificationDate, boolean coach) {
    String desc = translator.translate(notificationKey, params);
    String businessPath = subscriber.getPublisher().getBusinessPath();
    if (coach) {
        businessPath += "[Coach:0]";
    }
    if (StringHelper.containsNonWhitespace(path)) {
        businessPath += path;
    }
    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 30 with SubscriptionListItem

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

the class DocumentPoolNotificationsHandler method createSubscriptionInfo.

private void createSubscriptionInfo(VFSContainer container, String prefixBusinessPath, Date compareDate, SubscriptionInfo si, Publisher p, Translator translator) {
    List<FileInfo> fInfos = FolderManager.getFileInfos(((OlatRelPathImpl) container).getRelPath(), compareDate);
    for (FileInfo infos : fInfos) {
        String title = infos.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 = infos.getMetaInfo();
        String iconCssClass = null;
        if (metaInfo != null) {
            if (metaInfo.getTitle() != null) {
                title += " (" + metaInfo.getTitle() + ")";
            }
            iconCssClass = metaInfo.getIconCssClass();
        }
        Identity ident = infos.getAuthor();
        Date modDate = infos.getLastModified();
        String desc = translator.translate("notifications.document.entry", new String[] { title, NotificationHelper.getFormatedName(ident) });
        String urlToSend = null;
        String businessPath = null;
        if (p.getBusinessPath() != null) {
            businessPath = prefixBusinessPath + infos.getRelPath() + "]";
            urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
        }
        si.addSubscriptionListItem(new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass));
    }
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) FileInfo(org.olat.core.commons.modules.bc.FileInfo) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) Identity(org.olat.core.id.Identity) 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