Search in sources :

Example 21 with Publisher

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

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)

Example 22 with Publisher

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

the class NotificationsManagerImpl method markPublisherNews.

@Override
public void markPublisherNews(String publisherType, String data, Identity ignoreNewsFor, boolean sendEvents) {
    // to make sure: ignore if no subscriptionContext
    if (!StringHelper.containsNonWhitespace(publisherType) || !StringHelper.containsNonWhitespace(data))
        return;
    List<Publisher> publisherToUpdates = getPublishers(publisherType, data);
    if (publisherToUpdates == null || publisherToUpdates.isEmpty()) {
        return;
    }
    List<Publisher> updatedPublishers = new ArrayList<>(publisherToUpdates.size());
    for (Publisher toUpdate : publisherToUpdates) {
        toUpdate = getPublisherForUpdate(toUpdate);
        toUpdate.setLatestNewsDate(new Date());
        Publisher publisher = dbInstance.getCurrentEntityManager().merge(toUpdate);
        // commit the select for update
        dbInstance.commit();
        updatedPublishers.add(publisher);
    }
    // user
    if (ignoreNewsFor != null) {
        for (Publisher publisher : updatedPublishers) {
            markSubscriberRead(ignoreNewsFor, publisher);
        }
    }
    if (sendEvents) {
        // commit all things on the database
        dbInstance.commit();
        // channel-notify all interested listeners (e.g. the pnotificationsportletruncontroller)
        // 1. find all subscribers which can be affected
        List<Subscriber> subscribers = getValidSubscribersOf(publisherType, data);
        Set<Long> subsKeys = new HashSet<Long>();
        // 2. collect all keys of the affected subscribers
        for (Subscriber subscriber : subscribers) {
            subsKeys.add(subscriber.getKey());
        }
        // fire the event
        MultiUserEvent mue = EventFactory.createAffectedEvent(subsKeys);
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(mue, oresMyself);
    }
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) ArrayList(java.util.ArrayList) Publisher(org.olat.core.commons.services.notifications.Publisher) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) Date(java.util.Date) HashSet(java.util.HashSet)

Example 23 with Publisher

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

the class NotificationsManagerImpl method getSubscriptionInfos.

@Override
public List<SubscriptionInfo> getSubscriptionInfos(Identity identity, String publisherType) {
    StringBuilder sb = new StringBuilder();
    sb.append("select sub from notisub sub").append(" inner join fetch sub.publisher as pub").append(" where sub.identity=:identity and pub.type=:type and pub.state=:aState");
    List<Subscriber> subscribers = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Subscriber.class).setParameter("aState", PUB_STATE_OK).setParameter("type", publisherType).setParameter("identity", identity).getResultList();
    if (subscribers.isEmpty()) {
        return Collections.emptyList();
    }
    Locale locale = new Locale(identity.getUser().getPreferences().getLanguage());
    Date compareDate = getDefaultCompareDate();
    List<SubscriptionInfo> sis = new ArrayList<SubscriptionInfo>();
    for (Subscriber subscriber : subscribers) {
        Publisher pub = subscriber.getPublisher();
        NotificationsHandler notifHandler = getNotificationsHandler(pub);
        // do not create subscription item when deleted
        if (isPublisherValid(pub)) {
            SubscriptionInfo subsInfo = notifHandler.createSubscriptionInfo(subscriber, locale, compareDate);
            if (subsInfo.hasNews()) {
                sis.add(subsInfo);
            }
        }
    }
    return sis;
}
Also used : Locale(java.util.Locale) Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsHandler(org.olat.core.commons.services.notifications.NotificationsHandler) ArrayList(java.util.ArrayList) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) NoSubscriptionInfo(org.olat.core.commons.services.notifications.model.NoSubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher) Date(java.util.Date)

Example 24 with Publisher

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

the class NotificationsManagerImpl method delete.

/**
 * delete publisher and subscribers
 *
 * @param scontext the subscriptioncontext
 */
@Override
public void delete(SubscriptionContext scontext) {
    Publisher p = getPublisher(scontext);
    // -> nothing to do
    if (p == null)
        return;
    // first delete all subscribers
    List<Subscriber> subscribers = getValidSubscribersOf(p);
    for (Subscriber subscriber : subscribers) {
        deleteSubscriber(subscriber);
    }
    // else:
    dbInstance.deleteObject(p);
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 25 with Publisher

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

the class NotificationsManagerImpl method markPublisherNews.

/**
 * call this method to indicate that there is news for the given
 * subscriptionContext
 *
 * @param subscriptionContext
 * @param ignoreNewsFor
 */
@Override
public void markPublisherNews(final SubscriptionContext subscriptionContext, Identity ignoreNewsFor, boolean sendEvents) {
    // to make sure: ignore if no subscriptionContext
    if (subscriptionContext == null)
        return;
    Publisher toUpdate = getPublisherForUpdate(subscriptionContext);
    if (toUpdate == null) {
        return;
    }
    toUpdate.setLatestNewsDate(new Date());
    Publisher publisher = dbInstance.getCurrentEntityManager().merge(toUpdate);
    // commit the select for update
    dbInstance.commit();
    // user
    if (ignoreNewsFor != null) {
        markSubscriberRead(ignoreNewsFor, publisher);
    }
    if (sendEvents) {
        // commit all things on the database
        dbInstance.commit();
        // channel-notify all interested listeners (e.g. the pnotificationsportletruncontroller)
        // 1. find all subscribers which can be affected
        List<Subscriber> subscribers = getValidSubscribersOf(publisher);
        Set<Long> subsKeys = new HashSet<Long>();
        // 2. collect all keys of the affected subscribers
        for (Subscriber subscriber : subscribers) {
            subsKeys.add(subscriber.getKey());
        }
        // fire the event
        MultiUserEvent mue = EventFactory.createAffectedEvent(subsKeys);
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(mue, oresMyself);
    }
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) Publisher(org.olat.core.commons.services.notifications.Publisher) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) Date(java.util.Date) HashSet(java.util.HashSet)

Aggregations

Publisher (org.olat.core.commons.services.notifications.Publisher)150 Identity (org.olat.core.id.Identity)62 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)60 PublisherData (org.olat.core.commons.services.notifications.PublisherData)44 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)44 Date (java.util.Date)42 Test (org.junit.Test)42 Subscriber (org.olat.core.commons.services.notifications.Subscriber)42 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)38 RepositoryEntry (org.olat.repository.RepositoryEntry)34 Translator (org.olat.core.gui.translator.Translator)30 TitleItem (org.olat.core.commons.services.notifications.model.TitleItem)28 OLATResourceable (org.olat.core.id.OLATResourceable)18 ICourse (org.olat.course.ICourse)18 BusinessGroup (org.olat.group.BusinessGroup)16 ArrayList (java.util.ArrayList)14 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)14 NotificationsHandler (org.olat.core.commons.services.notifications.NotificationsHandler)12 AssertException (org.olat.core.logging.AssertException)12 CourseNode (org.olat.course.nodes.CourseNode)8