use of org.olat.core.commons.services.notifications.Publisher in project openolat by klemens.
the class NotificationSubscriptionAndNewsFormatter method getContainerType.
public String getContainerType(Subscriber sub) {
Publisher pub = sub.getPublisher();
String containerType = pub.getResName();
return NewControllerFactory.translateResourceableTypeName(containerType, translator.getLocale());
}
use of org.olat.core.commons.services.notifications.Publisher in project openolat by klemens.
the class NotificationSubscriptionTableDataModel method getValueAt.
/**
* @see org.olat.core.gui.components.table.DefaultTableDataModel#getValueAt(int,
* int)
*/
@Override
public Object getValueAt(int row, int col) {
Subscriber sub = getObject(row);
Publisher pub = sub.getPublisher();
switch(col) {
case 0:
return sub.getKey();
case 1:
String innerType = pub.getType();
return NewControllerFactory.translateResourceableTypeName(innerType, getLocale());
case 2:
String containerType = pub.getResName();
return NewControllerFactory.translateResourceableTypeName(containerType, getLocale());
case 3:
NotificationsHandler handler = NotificationsManager.getInstance().getNotificationsHandler(pub);
if (handler == null) {
return "";
}
String title = handler.createTitleInfo(sub, getLocale());
if (title == null) {
return "";
}
return title;
case 4:
return sub.getCreationDate();
case 5:
return sub.getLatestEmailed();
default:
return "ERROR";
}
}
use of org.olat.core.commons.services.notifications.Publisher in project openolat by klemens.
the class NotificationsManagerImpl method updatePublisherData.
@Override
public void updatePublisherData(SubscriptionContext subsContext, PublisherData data) {
Publisher publisher = getPublisherForUpdate(subsContext);
if (publisher != null) {
publisher.setData(data.getData());
dbInstance.getCurrentEntityManager().merge(publisher);
dbInstance.commit();
}
}
use of org.olat.core.commons.services.notifications.Publisher 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.Publisher 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);
}
}
Aggregations