Search in sources :

Example 96 with Publisher

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

the class NotificationsManagerImpl method subscribe.

@Override
public void subscribe(List<Identity> identities, SubscriptionContext subscriptionContext, PublisherData publisherData) {
    if (identities == null || identities.isEmpty())
        return;
    Publisher toUpdate = getPublisherForUpdate(subscriptionContext);
    if (toUpdate == null) {
        // create the publisher
        findOrCreatePublisher(subscriptionContext, publisherData);
        // lock the publisher
        toUpdate = getPublisherForUpdate(subscriptionContext);
    }
    for (Identity identity : identities) {
        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) Identity(org.olat.core.id.Identity)

Example 97 with Publisher

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

the class NotificationsManagerImpl method markSubscriberRead.

/**
 * sets the latest visited date of the subscription to 'now' .assumes the
 * identity is already subscribed to the publisher
 *
 * @param identity
 * @param subsContext
 */
@Override
public void markSubscriberRead(Identity identity, SubscriptionContext subsContext) {
    Publisher p = getPublisher(subsContext);
    if (p == null)
        throw new AssertException("cannot markRead for identity " + identity.getName() + ", since the publisher for the given subscriptionContext does not exist: subscontext = " + subsContext);
    markSubscriberRead(identity, p);
}
Also used : AssertException(org.olat.core.logging.AssertException) Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 98 with Publisher

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

the class NotificationsManagerImpl method getFormatedTitle.

/**
 * format the type-title and title-details
 * @param subscriber
 * @param locale
 * @param mimeType
 * @return
 */
private String getFormatedTitle(SubscriptionInfo subsInfo, Subscriber subscriber, Locale locale, String mimeType) {
    Publisher pub = subscriber.getPublisher();
    StringBuilder titleSb = new StringBuilder();
    String title = subsInfo.getTitle(mimeType);
    if (StringHelper.containsNonWhitespace(title)) {
        titleSb.append(title);
    } else {
        NotificationsHandler notifHandler = getNotificationsHandler(pub);
        String titleInfo = notifHandler.createTitleInfo(subscriber, locale);
        if (StringHelper.containsNonWhitespace(titleInfo)) {
            titleSb.append(titleInfo);
        }
    }
    return titleSb.toString();
}
Also used : NotificationsHandler(org.olat.core.commons.services.notifications.NotificationsHandler) Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 99 with Publisher

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

the class NotificationsManagerImpl method findOrCreatePublisher.

/**
 * @param scontext
 * @param pdata
 * @return the publisher
 */
private Publisher findOrCreatePublisher(final SubscriptionContext scontext, final PublisherData pdata) {
    final OLATResourceable ores = OresHelper.createOLATResourceableInstance(scontext.getResName() + "_" + scontext.getSubidentifier(), scontext.getResId());
    // o_clusterOK by:cg
    // fxdiff VCRP-16:prevent nested doInSync
    Publisher pub = getPublisher(scontext);
    if (pub != null) {
        return pub;
    }
    Publisher publisher = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ores, new SyncerCallback<Publisher>() {

        public Publisher execute() {
            Publisher p = getPublisher(scontext);
            // if not found, create it
            if (p == null) {
                p = createAndPersistPublisher(scontext.getResName(), scontext.getResId(), scontext.getSubidentifier(), pdata.getType(), pdata.getData(), pdata.getBusinessPath());
            }
            return p;
        }
    });
    return publisher;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 100 with Publisher

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

the class NotificationsManagerImpl method unsubscribe.

@Override
public void unsubscribe(List<Identity> identities, SubscriptionContext subscriptionContext) {
    if (identities == null || identities.isEmpty())
        return;
    Publisher p = getPublisherForUpdate(subscriptionContext);
    if (p != null) {
        for (Identity identity : identities) {
            Subscriber s = getSubscriber(identity, p);
            if (s != null) {
                deleteSubscriber(s);
            } else {
                logWarn("could not unsubscribe " + identity.getName() + " from publisher:" + p.getResName() + "," + p.getResId() + "," + p.getSubidentifier(), null);
            }
        }
    }
    dbInstance.commit();
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) Publisher(org.olat.core.commons.services.notifications.Publisher) Identity(org.olat.core.id.Identity)

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