use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project openolat by klemens.
the class PFNotificationsHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
SubscriptionInfo si = null;
Publisher p = subscriber.getPublisher();
try {
final Translator translator = Util.createPackageTranslator(PFRunController.class, locale);
PFNotifications notifications = new PFNotifications(subscriber, locale, compareDate, pfManager, notificationsManager, userManager);
List<SubscriptionListItem> items = notifications.getItems();
if (items.isEmpty()) {
si = notificationsManager.getNoSubscriptionInfo();
} else {
String displayName = notifications.getDisplayname();
String title = translator.translate("notifications.header", new String[] { displayName });
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, CSS_CLASS_ICON), items);
}
} catch (Exception e) {
log.error("Unknown Exception", e);
si = notificationsManager.getNoSubscriptionInfo();
}
return si;
}
use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project openolat by klemens.
the class ForumNotificationsHandler 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) {
try {
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
SubscriptionInfo si;
// there could be news for me, investigate deeper
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
String businessControlString = "";
Long forumKey = Long.valueOf(0);
try {
forumKey = Long.parseLong(p.getData());
} catch (NumberFormatException e) {
logError("Could not parse forum key!", e);
NotificationsManager.getInstance().deactivate(p);
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
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();
}
}
final List<Message> mInfos = ForumManager.getInstance().getNewMessageInfo(forumKey, compareDate);
final Translator translator = Util.createPackageTranslator(ForumNotificationsHandler.class, locale);
businessControlString = p.getBusinessPath() + "[Message:";
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), getTitleItem(p, translator), null);
for (Message mInfo : mInfos) {
String title = mInfo.getTitle();
Identity creator = mInfo.getCreator();
Identity modifier = mInfo.getModifier();
Date modDate = mInfo.getLastModified();
String name;
if (modifier != null) {
if (modifier.equals(creator) && StringHelper.containsNonWhitespace(mInfo.getPseudonym())) {
name = mInfo.getPseudonym();
} else {
name = NotificationHelper.getFormatedName(modifier);
}
} else if (StringHelper.containsNonWhitespace(mInfo.getPseudonym())) {
name = mInfo.getPseudonym();
} else if (mInfo.isGuest()) {
name = translator.translate("anonymous.poster");
} else {
name = NotificationHelper.getFormatedName(creator);
}
final String descKey = "notifications.entry" + (mInfo.getCreationDate().equals(mInfo.getLastModified()) ? "" : ".modified");
final String desc = translator.translate(descKey, new String[] { title, name });
String urlToSend = null;
String businessPath = null;
if (p.getBusinessPath() != null) {
businessPath = businessControlString + mInfo.getKey().toString() + "]";
urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
}
SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, ForumHelper.CSS_ICON_CLASS_MESSAGE);
si.addSubscriptionListItem(subListItem);
}
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
} catch (Exception e) {
log.error("Error while creating forum's notifications from publisher with key:" + subscriber.getKey(), e);
checkPublisher(subscriber.getPublisher());
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
}
Aggregations