use of org.olat.core.commons.services.notifications.Subscriber 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();
}
use of org.olat.core.commons.services.notifications.Subscriber 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);
}
}
use of org.olat.core.commons.services.notifications.Subscriber in project openolat by klemens.
the class NotificationsManagerImpl method getSubscriber.
/**
* @param key
* @return the subscriber with this key or null if not found
*/
@Override
public Subscriber getSubscriber(Long key) {
StringBuilder q = new StringBuilder();
q.append("select sub from notisub as sub").append(" inner join fetch sub.publisher ").append(" where sub.key=:aKey");
List<Subscriber> res = dbInstance.getCurrentEntityManager().createQuery(q.toString(), Subscriber.class).setParameter("aKey", key.longValue()).getResultList();
if (res.isEmpty())
return null;
if (res.size() > 1)
throw new AssertException("more than one subscriber for key " + key);
return res.get(0);
}
use of org.olat.core.commons.services.notifications.Subscriber 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();
}
use of org.olat.core.commons.services.notifications.Subscriber in project openolat by klemens.
the class NotificationsManagerImpl method getSubscriber.
/**
* @param identity
* @param publisher
* @return a Subscriber object belonging to the identity and listening to the
* given publisher
*/
@Override
public Subscriber getSubscriber(Identity identity, Publisher publisher) {
List<Subscriber> res = dbInstance.getCurrentEntityManager().createNamedQuery("subscribersByPublisherAndIdentity", Subscriber.class).setParameter("publisherKey", publisher.getKey()).setParameter("identityKey", identity.getKey()).getResultList();
if (res.size() == 0)
return null;
if (res.size() != 1)
throw new AssertException("only one subscriber per person and publisher!!");
Subscriber s = res.get(0);
return s;
}
Aggregations