use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
the class FolderNotificationsHandler method createSubscriptionInfo.
/**
* @see org.olat.core.commons.services.notifications.NotificationsHandler#createSubscriptionInfo(org.olat.core.commons.services.notifications.Subscriber,
* java.util.Locale, java.util.Date)
*/
@Override
public SubscriptionInfo createSubscriptionInfo(final Subscriber subscriber, Locale locale, Date compareDate) {
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
String genericBusinessPath = p.getBusinessPath() + "[path=";
SubscriptionInfo si;
// there could be news for me, investigate deeper
try {
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
if ("CourseModule".equals(p.getResName())) {
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false);
if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
}
String folderRoot = p.getData();
final List<FileInfo> fInfos = FolderManager.getFileInfos(folderRoot, compareDate);
final Translator translator = Util.createPackageTranslator(FolderNotificationsHandler.class, locale);
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), getTitleItem(p, translator), null);
SubscriptionListItem subListItem;
for (Iterator<FileInfo> it_infos = fInfos.iterator(); it_infos.hasNext(); ) {
FileInfo fi = it_infos.next();
String title = fi.getRelPath();
// known exclude prefixes
if (title != null && title.indexOf("/.") != -1 && FileUtils.isMetaFilename(title)) {
// skip this file, continue with next item in folder
continue;
}
MetaInfo metaInfo = fi.getMetaInfo();
String iconCssClass = null;
if (metaInfo != null) {
if (metaInfo.getTitle() != null) {
title += " (" + metaInfo.getTitle() + ")";
}
iconCssClass = metaInfo.getIconCssClass();
}
Identity ident = fi.getAuthor();
Date modDate = fi.getLastModified();
String desc = translator.translate("notifications.entry", new String[] { title, NotificationHelper.getFormatedName(ident) });
String urlToSend = null;
String businessPath = null;
if (p.getBusinessPath() != null) {
businessPath = genericBusinessPath + fi.getRelPath() + "]";
urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
}
subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass);
si.addSubscriptionListItem(subListItem);
}
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
} catch (Exception e) {
log.error("Error creating folder's notifications for subscriber: " + subscriber.getKey(), e);
checkPublisher(subscriber.getPublisher());
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
}
use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class NotificationsManagerImpl method getSubscriptionInfos.
@Override
public List<SubscriptionInfo> getSubscriptionInfos(Identity identity, String publisherType) {
StringBuilder sb = new StringBuilder();
sb.append("select sub from notisub sub").append(" inner join fetch sub.publisher as pub").append(" where sub.identity=:identity and pub.type=:type and pub.state=:aState");
List<Subscriber> subscribers = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Subscriber.class).setParameter("aState", PUB_STATE_OK).setParameter("type", publisherType).setParameter("identity", identity).getResultList();
if (subscribers.isEmpty()) {
return Collections.emptyList();
}
Locale locale = new Locale(identity.getUser().getPreferences().getLanguage());
Date compareDate = getDefaultCompareDate();
List<SubscriptionInfo> sis = new ArrayList<SubscriptionInfo>();
for (Subscriber subscriber : subscribers) {
Publisher pub = subscriber.getPublisher();
NotificationsHandler notifHandler = getNotificationsHandler(pub);
// do not create subscription item when deleted
if (isPublisherValid(pub)) {
SubscriptionInfo subsInfo = notifHandler.createSubscriptionInfo(subscriber, locale, compareDate);
if (subsInfo.hasNews()) {
sis.add(subsInfo);
}
}
}
return sis;
}
use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
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);
}
use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
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