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);
}
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();
}
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);
}
}
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();
}
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);
}
Aggregations