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