private static final String CSS_CLASS_CALENDAR_ICON = "o_calendar_icon";
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
SubscriptionInfo si = null;
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
// do not try to create a subscription info if state is deleted - results in
// exceptions, course
// can't be loaded when already deleted
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
Long id = p.getResId();
String type = p.getSubidentifier();
try {
Translator translator = Util.createPackageTranslator(this.getClass(), locale);
String calType = null;
String title = null;
if (type.equals(CalendarController.ACTION_CALENDAR_COURSE)) {
String displayName = RepositoryManager.getInstance().lookupDisplayNameByOLATResourceableId(id);
calType = CalendarManager.TYPE_COURSE;
title = translator.translate("cal.notifications.header.course", new String[]{displayName});
} else if (type.equals(CalendarController.ACTION_CALENDAR_GROUP)) {
BusinessGroup group = BusinessGroupManagerImpl.getInstance().loadBusinessGroup(id, false);
calType = CalendarManager.TYPE_GROUP;
title = translator.translate("cal.notifications.header.group", new String[]{group.getName()});
}
if (calType != null) {
Formatter form = Formatter.getInstance(locale);
si = new SubscriptionInfo(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 {
ICourse course = CourseFactory.loadCourse(p.getResId());
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(course, true);
bPath = "[RepositoryEntry:" + re.getKey() + "]";//Fallback
} catch (Exception e) {
logError("Error processing calendar notifications of publisher:" + p.getKey(), e);
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
} else {
//cannot make link without business path
return NotificationsManager.getInstance().getNoSubscriptionInfo();