Search in sources :

Example 41 with SubscriptionListItem

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

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

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

the class EPChangelogController method updateChangelogDisplay.

/**
 * update the changelog-list according to selected date. this method is
 * invoked on initForm and again when user changes date in dateChooser
 */
private void updateChangelogDisplay() {
    // init the helper;
    String path = getWindowControl().getBusinessControl().getAsString();
    EPNotificationsHelper helper = new EPNotificationsHelper(path, getLocale());
    // get the date from the dateChooser component
    Date compareDate = dateChooser.getDate();
    EPMapShort mapShort = ePFMgr.loadMapShortByResourceId(map.getOlatResource().getResourceableId());
    List<SubscriptionListItem> allItems = new ArrayList<SubscriptionListItem>(0);
    // get subscriptionListItems according to map type
    if (map instanceof EPDefaultMap || map instanceof EPStructuredMapTemplate) {
        allItems = helper.getAllSubscrItemsDefault(compareDate, mapShort);
    } else if (map instanceof EPStructuredMap) {
        allItems = helper.getAllSubscrItemsStructured(compareDate, mapShort);
    }
    List<SubscriptionItemBundle> bundles = getItemBundlesForSubscriptionItems(allItems);
    flc.contextPut("subscriptionItems", bundles);
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) EPStructuredMap(org.olat.portfolio.model.structel.EPStructuredMap) EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) EPNotificationsHelper(org.olat.portfolio.manager.EPNotificationsHelper) ArrayList(java.util.ArrayList) EPDefaultMap(org.olat.portfolio.model.structel.EPDefaultMap) EPMapShort(org.olat.portfolio.model.structel.EPMapShort) Date(java.util.Date)

Example 43 with SubscriptionListItem

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

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

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

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

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

the class PFNotificationsHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si = null;
    Publisher p = subscriber.getPublisher();
    try {
        final Translator translator = Util.createPackageTranslator(PFRunController.class, locale);
        PFNotifications notifications = new PFNotifications(subscriber, locale, compareDate, pfManager, notificationsManager, userManager);
        List<SubscriptionListItem> items = notifications.getItems();
        if (items.isEmpty()) {
            si = notificationsManager.getNoSubscriptionInfo();
        } else {
            String displayName = notifications.getDisplayname();
            String title = translator.translate("notifications.header", new String[] { displayName });
            si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, CSS_CLASS_ICON), items);
        }
    } catch (Exception e) {
        log.error("Unknown Exception", e);
        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)

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