use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project openolat by klemens.
the class InfoPortletEntryComparator method compare.
@Override
public int compare(InfoSubscriptionItem isi1, InfoSubscriptionItem isi2) {
if (isi1 == null)
return -1;
else if (isi2 == null)
return 1;
SubscriptionListItem m1 = isi1.getItem();
SubscriptionListItem m2 = isi2.getItem();
if (m1 == null)
return -1;
else if (m2 == null)
return 1;
// only sorting per date
Date d1 = m1.getDate();
Date d2 = m2.getDate();
if (d1 == null)
return -1;
else if (d2 == null)
return 1;
int result = d1.compareTo(d2);
return criteria.isAscending() ? result : -result;
}
use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project openolat by klemens.
the class AbstractTaskNotificationHandler method createSubscriptionInfo.
/**
* @see org.olat.core.commons.services.notifications.NotificationsHandler#createSubscriptionInfo(org.olat.core.commons.services.notifications.Subscriber,
* java.util.Locale, java.util.Date)
*/
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
SubscriptionInfo si;
// there could be news for me, investigate deeper
try {
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
String folderRoot = p.getData();
if (isLogDebugEnabled()) {
logDebug("folderRoot=", folderRoot);
}
final List<FileInfo> fInfos = FolderManager.getFileInfos(folderRoot, compareDate);
final Translator translator = Util.createPackageTranslator(AbstractTaskNotificationHandler.class, locale);
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance("CourseModule", p.getResId()), false);
if (re == null) {
if (!checkPublisher(p)) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
} else if (re.getRepositoryEntryStatus().isClosed()) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
String displayName = re.getDisplayname();
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(translator.translate(getNotificationHeaderKey(), new String[] { displayName }), getCssClassIcon()), null);
SubscriptionListItem subListItem;
for (Iterator<FileInfo> it_infos = fInfos.iterator(); it_infos.hasNext(); ) {
FileInfo fi = it_infos.next();
MetaInfo metaInfo = fi.getMetaInfo();
String filePath = fi.getRelPath();
if (isLogDebugEnabled())
logDebug("filePath=", filePath);
String fullUserName = getUserNameFromFilePath(metaInfo, filePath);
Date modDate = fi.getLastModified();
String desc = translator.translate(getNotificationEntryKey(), new String[] { filePath, fullUserName });
String businessPath = p.getBusinessPath();
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
String iconCssClass = null;
if (metaInfo != null) {
iconCssClass = metaInfo.getIconCssClass();
}
subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass);
si.addSubscriptionListItem(subListItem);
}
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
} catch (Exception e) {
getLogger().error("Cannot create task notifications for subscriber: " + subscriber.getKey(), e);
checkPublisher(p);
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
}
use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project openolat by klemens.
the class CalendarNotificationHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
SubscriptionInfo si = null;
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
// can't be loaded when already deleted
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
Long id = p.getResId();
String type = p.getSubidentifier();
try {
Translator translator = Util.createPackageTranslator(CalendarModule.class, locale);
String calType = null;
String title = null;
if (type.equals(CalendarController.ACTION_CALENDAR_COURSE)) {
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance("CourseModule", id), false);
if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
String displayName = re.getDisplayname();
calType = CalendarManager.TYPE_COURSE;
title = translator.translate("cal.notifications.header.course", new String[] { displayName });
} else if (type.equals(CalendarController.ACTION_CALENDAR_GROUP)) {
BusinessGroup group = businessGroupDao.load(id);
calType = CalendarManager.TYPE_GROUP;
if (group == null) {
return notificationsManager.getNoSubscriptionInfo();
}
title = translator.translate("cal.notifications.header.group", new String[] { group.getName() });
}
if (calType != null) {
Formatter form = Formatter.getInstance(locale);
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, CSS_CLASS_CALENDAR_ICON), null);
String bPath;
if (StringHelper.containsNonWhitespace(p.getBusinessPath())) {
bPath = p.getBusinessPath();
} else if ("CalendarManager.course".equals(p.getResName())) {
try {
OLATResourceable ores = OresHelper.createOLATResourceableInstance(CourseModule.getCourseTypeName(), p.getResId());
RepositoryEntry re = repositoryManager.lookupRepositoryEntry(ores, true);
// Fallback
bPath = "[RepositoryEntry:" + re.getKey() + "]";
} catch (Exception e) {
log.error("Error processing calendar notifications of publisher:" + p.getKey(), e);
return notificationsManager.getNoSubscriptionInfo();
}
} else {
// cannot make link without business path
return notificationsManager.getNoSubscriptionInfo();
}
Kalendar cal = calendarManager.getCalendar(calType, id.toString());
Collection<KalendarEvent> calEvents = cal.getEvents();
for (KalendarEvent kalendarEvent : calEvents) {
if (showEvent(compareDate, kalendarEvent)) {
log.debug("found a KalendarEvent: " + kalendarEvent.getSubject() + " with time: " + kalendarEvent.getBegin() + " modified before: " + compareDate.toString(), null);
// found a modified event in this calendar
Date modDate = null;
if (kalendarEvent.getLastModified() > 0) {
modDate = new Date(kalendarEvent.getLastModified());
} else if (kalendarEvent.getCreated() > 0) {
modDate = new Date(kalendarEvent.getCreated());
} else if (kalendarEvent.getBegin() != null) {
modDate = kalendarEvent.getBegin();
}
String subject = kalendarEvent.getSubject();
String author = kalendarEvent.getCreatedBy();
if (author == null)
author = "";
String location = "";
if (StringHelper.containsNonWhitespace(kalendarEvent.getLocation())) {
location = kalendarEvent.getLocation() == null ? "" : translator.translate("cal.notifications.location", new String[] { kalendarEvent.getLocation() });
}
String dateStr;
if (kalendarEvent.isAllDayEvent()) {
dateStr = form.formatDate(kalendarEvent.getBegin());
} else {
dateStr = form.formatDate(kalendarEvent.getBegin()) + " - " + form.formatDate(kalendarEvent.getEnd());
}
String desc = translator.translate("cal.notifications.entry", new String[] { subject, dateStr, location, author });
String businessPath = bPath + "[path=" + kalendarEvent.getID() + ":0]";
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSS_CLASS_CALENDAR_ICON);
si.addSubscriptionListItem(subListItem);
}
}
}
} catch (Exception e) {
log.error("Unexpected exception", e);
checkPublisher(p);
si = notificationsManager.getNoSubscriptionInfo();
}
} else {
si = notificationsManager.getNoSubscriptionInfo();
}
return si;
}
use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project OpenOLAT by OpenOLAT.
the class EPNotificationManager method getCommentNotifications.
public List<SubscriptionListItem> getCommentNotifications(List<Long> mapKey, String rootBusinessPath, Date compareDate, Translator translator) {
List<EPCommentNotification> comments = getCommentNotifications(mapKey, compareDate);
List<SubscriptionListItem> items = new ArrayList<SubscriptionListItem>();
for (EPCommentNotification comment : comments) {
SubscriptionListItem item;
if (comment.getPageKey() == null) {
String[] title = new String[] { comment.getMapTitle(), userManager.getUserDisplayName(comment.getAuthor()) };
String linkUrl = BusinessControlFactory.getInstance().getURLFromBusinessPathString(rootBusinessPath);
item = new SubscriptionListItem(translator.translate("li.newcomment", title), linkUrl, rootBusinessPath, comment.getCreationDate(), "o_info_icon");
} else {
String bPath = rootBusinessPath + "[EPPage:" + comment.getPageKey() + "]";
String linkUrl = BusinessControlFactory.getInstance().getURLFromBusinessPathString(bPath);
String[] title = new String[] { comment.getTitle(), userManager.getUserDisplayName(comment.getAuthor()) };
item = new SubscriptionListItem(translator.translate("li.newcomment", title), linkUrl, bPath, comment.getCreationDate(), "o_info_icon");
item.setUserObject(comment.getPageKey());
}
items.add(item);
}
return items;
}
use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project OpenOLAT by OpenOLAT.
the class EPNotificationManager method getArtefactNotifications.
public List<SubscriptionListItem> getArtefactNotifications(List<Long> mapKey, String rootBusinessPath, Date compareDate, Translator translator) {
List<EPArtefactNotification> links = getArtefactNotifications(mapKey, compareDate);
List<SubscriptionListItem> items = new ArrayList<SubscriptionListItem>();
for (EPArtefactNotification link : links) {
Long pageKey = link.getPageKey();
String targetTitle = link.getStructureTitle();
String[] title = new String[] { StringHelper.escapeHtml(userManager.getUserDisplayName(link.getAuthor())), StringHelper.escapeHtml(link.getArtefactTitle()), StringHelper.escapeHtml(targetTitle) };
String bPath = rootBusinessPath + "[EPPage:" + pageKey + "]";
String linkUrl = BusinessControlFactory.getInstance().getURLFromBusinessPathString(bPath);
SubscriptionListItem item = new SubscriptionListItem(translator.translate("li.newartefact", title), linkUrl, bPath, link.getCreationDate(), "o_icon_eportfolio_link");
item.setUserObject(pageKey);
items.add(item);
}
return items;
}
Aggregations