Search in sources :

Example 31 with TitleItem

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

the class ForumNotificationsHandler method createTitleInfo.

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

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

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

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

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

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

the class WikiPageChangeOrCreateNotificationHandler 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, final Locale locale, Date compareDate) {
    Publisher p = subscriber.getPublisher();
    final Date latestNews = p.getLatestNewsDate();
    Long resId = p.getResId();
    SubscriptionInfo si;
    final boolean debug = log.isDebug();
    // there could be news for me, investigate deeper
    if (debug)
        log.debug("compareDate=" + compareDate + " ; latestNews=" + latestNews, null);
    try {
        if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
            OLATResourceable ores = null;
            if (p.getResName().equals(CourseModule.getCourseTypeName())) {
                // resId = CourseResourceableId           p.getSubidentifier() = wikiCourseNode.getIdent()
                ICourse course = CourseFactory.loadCourse(resId);
                if (!courseStatus(course)) {
                    return NotificationsManager.getInstance().getNoSubscriptionInfo();
                }
                CourseEnvironment cenv = course.getCourseEnvironment();
                CourseNode courseNode = cenv.getRunStructure().getNode(p.getSubidentifier());
                if (courseNode == null) {
                    // OLAT-3356 because removing wikicoursenodes was not propagated to
                    // disable subcriptions, we may end up here with a NULL wikicoursenode
                    // Best we can do here -> return noSubsInfo and clean up
                    NotificationsManager.getInstance().deactivate(p);
                    // return nothing available
                    return NotificationsManager.getInstance().getNoSubscriptionInfo();
                }
                ModuleConfiguration config = ((WikiCourseNode) courseNode).getModuleConfiguration();
                RepositoryEntry re = WikiEditController.getWikiRepoReference(config, true);
                resId = re.getOlatResource().getResourceableId();
                if (debug)
                    log.debug("resId=" + resId, null);
                ores = OresHelper.createOLATResourceableInstance(WikiResource.TYPE_NAME, resId);
                businessControlString = p.getBusinessPath() + "[path=";
            } else {
                // resName = 'BusinessGroup' or 'FileResource.WIKI'
                if (debug)
                    log.debug("p.getResName()=" + p.getResName(), null);
                ores = OresHelper.createOLATResourceableInstance(p.getResName(), resId);
                businessControlString = p.getBusinessPath() + "[path=";
            }
            Wiki wiki = WikiManager.getInstance().getOrLoadWiki(ores);
            final List<WikiPage> pages = wiki.getPagesByDate();
            Translator translator = Util.createPackageTranslator(WikiPageChangeOrCreateNotificationHandler.class, locale);
            Translator forumTranslator = Util.createPackageTranslator(ForumNotificationsHandler.class, locale);
            TitleItem title = getTitleItem(p, translator);
            si = new SubscriptionInfo(subscriber.getKey(), p.getType(), title, null);
            for (Iterator<WikiPage> it = pages.listIterator(); it.hasNext(); ) {
                WikiPage element = it.next();
                // do only show entries newer then the ones already seen
                Date modDate = new Date(element.getModificationTime());
                if (debug)
                    log.debug("modDate=" + modDate + " ; compareDate=" + compareDate, null);
                if (modDate.after(compareDate)) {
                    if ((element.getPageName().startsWith("O_") || element.getPageName().startsWith(WikiPage.WIKI_MENU_PAGE)) && (element.getModifyAuthor() <= 0)) {
                        // theses pages are created sometimes automatically. Check if this is the case
                        continue;
                    }
                    // build Businesscontrol-Path
                    String businessPath = null;
                    String urlToSend = null;
                    if (p.getBusinessPath() != null) {
                        businessPath = businessControlString + element.getPageName() + "]";
                        urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                    }
                    // string[] gets filled into translation key by adding {0...n} to
                    // the string
                    Identity ident = BaseSecurityManager.getInstance().loadIdentityByKey(Long.valueOf(element.getModifyAuthor()));
                    String desc = translator.translate("notifications.entry", new String[] { element.getPageName(), NotificationHelper.getFormatedName(ident) });
                    SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSS_CLASS_WIKI_PAGE_CHANGED_ICON);
                    si.addSubscriptionListItem(subListItem);
                }
                long forumKey = element.getForumKey();
                List<Message> mInfos = ForumManager.getInstance().getNewMessageInfo(forumKey, compareDate);
                for (Message mInfo : mInfos) {
                    String messageTitle = mInfo.getTitle();
                    Identity creator = mInfo.getCreator();
                    Identity modifier = mInfo.getModifier();
                    Date messageModDate = mInfo.getLastModified();
                    String name;
                    if (modifier != null) {
                        name = NotificationHelper.getFormatedName(modifier);
                    } else {
                        name = NotificationHelper.getFormatedName(creator);
                    }
                    final String descKey = "notifications.entry" + (mInfo.getCreationDate().equals(messageModDate) ? "" : ".modified");
                    final String desc = forumTranslator.translate(descKey, new String[] { messageTitle, name });
                    String urlToSend = null;
                    String businessPath = null;
                    if (p.getBusinessPath() != null) {
                        businessPath = businessControlString + element.getPageName() + "][message:" + mInfo.getKey().toString() + "]";
                        urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                    }
                    SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, messageModDate, CSS_CLASS_WIKI_PAGE_CHANGED_ICON);
                    si.addSubscriptionListItem(subListItem);
                }
            }
        } else {
            // no news
            si = NotificationsManager.getInstance().getNoSubscriptionInfo();
        }
    } catch (Exception e) {
        log.error("Error creating wiki's notifications for subscriber: " + subscriber.getKey(), e);
        checkPublisher(p);
        si = NotificationsManager.getInstance().getNoSubscriptionInfo();
    }
    return si;
}
Also used : Message(org.olat.modules.fo.Message) OLATResourceable(org.olat.core.id.OLATResourceable) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Translator(org.olat.core.gui.translator.Translator) CourseNode(org.olat.course.nodes.CourseNode) WikiCourseNode(org.olat.course.nodes.WikiCourseNode) Identity(org.olat.core.id.Identity) WikiCourseNode(org.olat.course.nodes.WikiCourseNode) ModuleConfiguration(org.olat.modules.ModuleConfiguration) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) Publisher(org.olat.core.commons.services.notifications.Publisher) Date(java.util.Date)

Example 35 with TitleItem

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

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)

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