Search in sources :

Example 6 with SubscriptionListItem

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

the class PortfolioNotificationsHandler method evaluationModifiedItem.

private SubscriptionListItem evaluationModifiedItem(Long pageKey, String pageTitle, Date pageCreationDate, String rootBusinessPath, Translator translator) {
    String title = translator.translate("notifications.modified.evaluation", new String[] { pageTitle });
    String bPath = rootBusinessPath + "[Page:" + pageKey + "]";
    String linkUrl = BusinessControlFactory.getInstance().getURLFromBusinessPathString(bPath);
    SubscriptionListItem item = new SubscriptionListItem(title, linkUrl, bPath, pageCreationDate, "o_icon_pf_page");
    item.setUserObject(pageKey);
    return item;
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem)

Example 7 with SubscriptionListItem

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

the class PortfolioNotificationsHandler method sectionCreateItem.

private SubscriptionListItem sectionCreateItem(Long sectionKey, String sectionTitle, Date sectionCreationDate, String rootBusinessPath, Translator translator) {
    String title = translator.translate("notifications.new.section", new String[] { sectionTitle });
    String bPath = rootBusinessPath + "[Section:" + sectionKey + "]";
    String linkUrl = BusinessControlFactory.getInstance().getURLFromBusinessPathString(bPath);
    SubscriptionListItem item = new SubscriptionListItem(title, linkUrl, bPath, sectionCreationDate, "o_icon_pf_section");
    item.setUserObject(sectionKey);
    return item;
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem)

Example 8 with SubscriptionListItem

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

the class PFNotifications method gatherItems.

private void gatherItems(Identity participant, Publisher p, CourseEnvironment courseEnv, CourseNode node) {
    Path folderRoot = Paths.get(courseEnv.getCourseBaseContainer().getRelPath(), PFManager.FILENAME_PARTICIPANTFOLDER, node.getIdent(), pfManager.getIdFolderName(participant));
    final List<FileInfo> fInfos = FolderManager.getFileInfos(folderRoot.toString(), compareDate);
    SubscriptionListItem subListItem;
    for (Iterator<FileInfo> it_infos = fInfos.iterator(); it_infos.hasNext(); ) {
        FileInfo fi = it_infos.next();
        MetaInfo metaInfo = fi.getMetaInfo();
        String filePath = fi.getRelPath();
        Date modDate = fi.getLastModified();
        String action = "upload";
        try {
            Path basepath = courseEnv.getCourseBaseContainer().getBasefile().toPath();
            Path completepath = Paths.get(basepath.toString(), PFManager.FILENAME_PARTICIPANTFOLDER, node.getIdent(), pfManager.getIdFolderName(participant), filePath);
            BasicFileAttributes attrs = Files.readAttributes(completepath, BasicFileAttributes.class);
            if (attrs.creationTime().toMillis() < attrs.lastModifiedTime().toMillis()) {
                action = "modify";
            }
        } catch (IOException ioe) {
            log.error("IOException", ioe);
        }
        String forby = translator.translate("notifications.entry." + (filePath.contains(PFManager.FILENAME_DROPBOX) ? "by" : "for"));
        String userDisplayName = userManager.getUserDisplayName(participant);
        String desc = translator.translate("notifications.entry." + action, new String[] { filePath, forby, userDisplayName });
        String businessPath = p.getBusinessPath();
        String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
        String iconCssClass = null;
        if (metaInfo != null) {
            iconCssClass = metaInfo.getIconCssClass();
        }
        if (metaInfo != null && !metaInfo.getName().startsWith(".")) {
            subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass);
            items.add(subListItem);
        }
    }
}
Also used : Path(java.nio.file.Path) 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) IOException(java.io.IOException) Date(java.util.Date) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 9 with SubscriptionListItem

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

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)

Example 10 with SubscriptionListItem

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

the class ForumNotificationsHandler 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) {
    try {
        Publisher p = subscriber.getPublisher();
        Date latestNews = p.getLatestNewsDate();
        SubscriptionInfo si;
        // there could be news for me, investigate deeper
        if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
            String businessControlString = "";
            Long forumKey = Long.valueOf(0);
            try {
                forumKey = Long.parseLong(p.getData());
            } catch (NumberFormatException e) {
                logError("Could not parse forum key!", e);
                NotificationsManager.getInstance().deactivate(p);
                return NotificationsManager.getInstance().getNoSubscriptionInfo();
            }
            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();
                }
            }
            final List<Message> mInfos = ForumManager.getInstance().getNewMessageInfo(forumKey, compareDate);
            final Translator translator = Util.createPackageTranslator(ForumNotificationsHandler.class, locale);
            businessControlString = p.getBusinessPath() + "[Message:";
            si = new SubscriptionInfo(subscriber.getKey(), p.getType(), getTitleItem(p, translator), null);
            for (Message mInfo : mInfos) {
                String title = mInfo.getTitle();
                Identity creator = mInfo.getCreator();
                Identity modifier = mInfo.getModifier();
                Date modDate = mInfo.getLastModified();
                String name;
                if (modifier != null) {
                    if (modifier.equals(creator) && StringHelper.containsNonWhitespace(mInfo.getPseudonym())) {
                        name = mInfo.getPseudonym();
                    } else {
                        name = NotificationHelper.getFormatedName(modifier);
                    }
                } else if (StringHelper.containsNonWhitespace(mInfo.getPseudonym())) {
                    name = mInfo.getPseudonym();
                } else if (mInfo.isGuest()) {
                    name = translator.translate("anonymous.poster");
                } else {
                    name = NotificationHelper.getFormatedName(creator);
                }
                final String descKey = "notifications.entry" + (mInfo.getCreationDate().equals(mInfo.getLastModified()) ? "" : ".modified");
                final String desc = translator.translate(descKey, new String[] { title, name });
                String urlToSend = null;
                String businessPath = null;
                if (p.getBusinessPath() != null) {
                    businessPath = businessControlString + mInfo.getKey().toString() + "]";
                    urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                }
                SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, ForumHelper.CSS_ICON_CLASS_MESSAGE);
                si.addSubscriptionListItem(subListItem);
            }
        } else {
            si = NotificationsManager.getInstance().getNoSubscriptionInfo();
        }
        return si;
    } catch (Exception e) {
        log.error("Error while creating forum's notifications from publisher with key:" + subscriber.getKey(), e);
        checkPublisher(subscriber.getPublisher());
        return NotificationsManager.getInstance().getNoSubscriptionInfo();
    }
}
Also used : 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) Translator(org.olat.core.gui.translator.Translator) Identity(org.olat.core.id.Identity)

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