Search in sources :

Example 36 with Publisher

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

the class NotificationSubscriptionAndNewsFormatter method getContainerType.

public String getContainerType(Subscriber sub) {
    Publisher pub = sub.getPublisher();
    String containerType = pub.getResName();
    return NewControllerFactory.translateResourceableTypeName(containerType, translator.getLocale());
}
Also used : Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 37 with Publisher

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

the class NotificationSubscriptionTableDataModel method getValueAt.

/**
 * @see org.olat.core.gui.components.table.DefaultTableDataModel#getValueAt(int,
 *      int)
 */
@Override
public Object getValueAt(int row, int col) {
    Subscriber sub = getObject(row);
    Publisher pub = sub.getPublisher();
    switch(col) {
        case 0:
            return sub.getKey();
        case 1:
            String innerType = pub.getType();
            return NewControllerFactory.translateResourceableTypeName(innerType, getLocale());
        case 2:
            String containerType = pub.getResName();
            return NewControllerFactory.translateResourceableTypeName(containerType, getLocale());
        case 3:
            NotificationsHandler handler = NotificationsManager.getInstance().getNotificationsHandler(pub);
            if (handler == null) {
                return "";
            }
            String title = handler.createTitleInfo(sub, getLocale());
            if (title == null) {
                return "";
            }
            return title;
        case 4:
            return sub.getCreationDate();
        case 5:
            return sub.getLatestEmailed();
        default:
            return "ERROR";
    }
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsHandler(org.olat.core.commons.services.notifications.NotificationsHandler) Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 38 with Publisher

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

the class NotificationsManagerImpl method updatePublisherData.

@Override
public void updatePublisherData(SubscriptionContext subsContext, PublisherData data) {
    Publisher publisher = getPublisherForUpdate(subsContext);
    if (publisher != null) {
        publisher.setData(data.getData());
        dbInstance.getCurrentEntityManager().merge(publisher);
        dbInstance.commit();
    }
}
Also used : Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 39 with Publisher

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

the class NotificationsManagerImpl method subscribe.

/**
 * @param identity
 * @param subscriptionContext
 * @param publisherData
 */
@Override
public void subscribe(Identity identity, SubscriptionContext subscriptionContext, PublisherData publisherData) {
    // need to sync as opt-in is sometimes implemented
    Publisher toUpdate = getPublisherForUpdate(subscriptionContext);
    if (toUpdate == null) {
        // create the publisher
        findOrCreatePublisher(subscriptionContext, publisherData);
        // lock the publisher
        toUpdate = getPublisherForUpdate(subscriptionContext);
    }
    Subscriber s = getSubscriber(identity, toUpdate);
    if (s == null) {
        // no subscriber -> create.
        // s.latestReadDate >= p.latestNewsDate == no news for subscriber when no
        // news after subscription time
        doCreateAndPersistSubscriber(toUpdate, identity);
    }
    dbInstance.commit();
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 40 with Publisher

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

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