Search in sources :

Example 6 with FileInfo

use of org.olat.core.commons.modules.bc.FileInfo in project openolat by klemens.

the class AbstractTaskNotificationHandler 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(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)) {
            String folderRoot = p.getData();
            if (isLogDebugEnabled()) {
                logDebug("folderRoot=", folderRoot);
            }
            final List<FileInfo> fInfos = FolderManager.getFileInfos(folderRoot, compareDate);
            final Translator translator = Util.createPackageTranslator(AbstractTaskNotificationHandler.class, locale);
            RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance("CourseModule", p.getResId()), false);
            if (re == null) {
                if (!checkPublisher(p)) {
                    return NotificationsManager.getInstance().getNoSubscriptionInfo();
                }
            } else if (re.getRepositoryEntryStatus().isClosed()) {
                return NotificationsManager.getInstance().getNoSubscriptionInfo();
            }
            String displayName = re.getDisplayname();
            si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(translator.translate(getNotificationHeaderKey(), new String[] { displayName }), getCssClassIcon()), null);
            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();
                if (isLogDebugEnabled())
                    logDebug("filePath=", filePath);
                String fullUserName = getUserNameFromFilePath(metaInfo, filePath);
                Date modDate = fi.getLastModified();
                String desc = translator.translate(getNotificationEntryKey(), new String[] { filePath, fullUserName });
                String businessPath = p.getBusinessPath();
                String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                String iconCssClass = null;
                if (metaInfo != null) {
                    iconCssClass = metaInfo.getIconCssClass();
                }
                subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass);
                si.addSubscriptionListItem(subListItem);
            }
        } else {
            si = NotificationsManager.getInstance().getNoSubscriptionInfo();
        }
    } catch (Exception e) {
        getLogger().error("Cannot create task notifications for subscriber: " + subscriber.getKey(), e);
        checkPublisher(p);
        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) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) 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)

Example 7 with FileInfo

use of org.olat.core.commons.modules.bc.FileInfo in project OpenOLAT by OpenOLAT.

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)

Example 8 with FileInfo

use of org.olat.core.commons.modules.bc.FileInfo 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)

Aggregations

Date (java.util.Date)8 FileInfo (org.olat.core.commons.modules.bc.FileInfo)8 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)8 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)8 Publisher (org.olat.core.commons.services.notifications.Publisher)4 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)4 Translator (org.olat.core.gui.translator.Translator)4 Identity (org.olat.core.id.Identity)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)2 TitleItem (org.olat.core.commons.services.notifications.model.TitleItem)2