Search in sources :

Example 41 with Publisher

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

the class NotificationsManagerImpl method getPublisher.

/**
 * @param subsContext
 * @return the publisher belonging to the given context or null
 */
@Override
public Publisher getPublisher(SubscriptionContext subsContext) {
    StringBuilder q = new StringBuilder();
    q.append("select pub from notipublisher pub ").append(" where pub.resName=:resName and pub.resId = :resId");
    if (StringHelper.containsNonWhitespace(subsContext.getSubidentifier())) {
        q.append(" and pub.subidentifier=:subidentifier");
    } else {
        q.append(" and (pub.subidentifier='' or pub.subidentifier is null)");
    }
    TypedQuery<Publisher> query = dbInstance.getCurrentEntityManager().createQuery(q.toString(), Publisher.class).setParameter("resName", subsContext.getResName()).setParameter("resId", subsContext.getResId());
    if (StringHelper.containsNonWhitespace(subsContext.getSubidentifier())) {
        query.setParameter("subidentifier", subsContext.getSubidentifier());
    }
    List<Publisher> res = query.getResultList();
    if (res.isEmpty())
        return null;
    if (res.size() != 1)
        throw new AssertException("only one subscriber per person and publisher!!");
    return res.get(0);
}
Also used : AssertException(org.olat.core.logging.AssertException) Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 42 with Publisher

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

the class NotificationsManagerImpl method unsubscribe.

/**
 * @param identity
 * @param subscriptionContext
 */
@Override
public void unsubscribe(Identity identity, SubscriptionContext subscriptionContext) {
    Publisher p = getPublisherForUpdate(subscriptionContext);
    if (p != null) {
        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)

Example 43 with Publisher

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

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 44 with Publisher

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

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 45 with Publisher

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

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)

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