use of org.olat.core.commons.services.notifications.SubscriptionInfo in project openolat by klemens.
the class InfoMessageNotificationHandler 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.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
try {
final Long resId = subscriber.getPublisher().getResId();
final String resName = subscriber.getPublisher().getResName();
String resSubPath = subscriber.getPublisher().getSubidentifier();
String displayName, notificationtitle;
if ("BusinessGroup".equals(resName)) {
BusinessGroupService groupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
BusinessGroup group = groupService.loadBusinessGroup(resId);
displayName = group.getName();
notificationtitle = "notification.title.group";
} else {
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(resName, resId), false);
if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
displayName = re.getDisplayname();
notificationtitle = "notification.title";
}
Translator translator = Util.createPackageTranslator(this.getClass(), locale);
String title = translator.translate(notificationtitle, new String[] { displayName });
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, CSS_CLASS_ICON), null);
OLATResourceable ores = OresHelper.createOLATResourceableInstance(resName, resId);
List<InfoMessage> infos = infoMessageManager.loadInfoMessageByResource(ores, resSubPath, null, compareDate, null, 0, 0);
for (InfoMessage info : infos) {
Identity ident = info.getAuthor();
String desc = translator.translate("notifications.entry", new String[] { info.getTitle(), NotificationHelper.getFormatedName(ident) });
String tooltip = info.getMessage();
String infoBusinessPath = info.getBusinessPath() + "[InfoMessage:" + info.getKey() + "]";
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(infoBusinessPath);
Date dateInfo = info.getModificationDate() == null ? info.getCreationDate() : info.getModificationDate();
SubscriptionListItem subListItem = new SubscriptionListItem(desc, tooltip, urlToSend, infoBusinessPath, dateInfo, CSS_CLASS_ICON);
si.addSubscriptionListItem(subListItem);
}
} catch (Exception e) {
log.error("Unexpected exception", e);
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
}
use of org.olat.core.commons.services.notifications.SubscriptionInfo in project openolat by klemens.
the class InfoMessagePortletRunController method reloadModel.
@Override
protected void reloadModel(SortingCriteria criteria) {
List<SubscriptionInfo> infos = NotificationsManager.getInstance().getSubscriptionInfos(getIdentity(), "InfoMessage");
List<InfoSubscriptionItem> items = new ArrayList<InfoSubscriptionItem>();
for (SubscriptionInfo info : infos) {
for (SubscriptionListItem item : info.getSubscriptionListItems()) {
items.add(new InfoSubscriptionItem(info, item));
}
}
items = getSortedList(items, criteria);
List<PortletEntry<InfoSubscriptionItem>> entries = convertToPortletEntryList(items);
InfosTableModel model = new InfosTableModel(entries);
tableController.setTableDataModel(model);
}
use of org.olat.core.commons.services.notifications.SubscriptionInfo in project openolat by klemens.
the class DENCourseNodeNotificationHandler method createSubscriptionInfo.
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
try {
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
Long courseId = new Long(p.getData());
final ICourse course = loadCourseFromId(courseId);
if (courseStatus(course)) {
final List<DENCourseNode> denNodes = getCourseDENNodes(course);
final Translator trans = Util.createPackageTranslator(DENCourseNodeNotificationHandler.class, locale);
String cssClass = new DENCourseNodeConfiguration().getIconCSSClass();
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(trans.translate("notifications.header", new String[] { course.getCourseTitle() }), cssClass), null);
SubscriptionListItem subListItem;
for (DENCourseNode denNode : denNodes) {
String changer = "";
String desc = trans.translate("notifications.entry", new String[] { denNode.getLongTitle(), changer });
Date modDate = new Date();
subListItem = new SubscriptionListItem(desc, null, null, modDate, cssClass);
si.addSubscriptionListItem(subListItem);
}
}
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
} catch (Exception e) {
log.error("Error creating enrollment notifications for subscriber: " + subscriber.getKey(), e);
checkPublisher(p);
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
}
use of org.olat.core.commons.services.notifications.SubscriptionInfo in project openolat by klemens.
the class NotificationSubscriptionAndNewsFormatter method getSubscriptionItem.
public SubscriptionItem getSubscriptionItem(Subscriber sub) {
SubscriptionInfo subsInfo = subsInfoMap.get(sub);
NotificationsManager notiMgr = NotificationsManager.getInstance();
SubscriptionItem subscrItem = notiMgr.createSubscriptionItem(subsInfo, sub, translator.getLocale(), SubscriptionInfo.MIME_HTML, SubscriptionInfo.MIME_HTML);
return subscrItem;
}
use of org.olat.core.commons.services.notifications.SubscriptionInfo in project openolat by klemens.
the class NotificationsPortletRunController method reloadModel.
/**
* @see org.olat.core.gui.control.generic.portal.AbstractPortletRunController#reloadModel(org.olat.core.gui.UserRequest, org.olat.core.gui.control.generic.portal.SortingCriteria)
*/
protected void reloadModel(SortingCriteria sortingCriteria) {
if (sortingCriteria.getSortingType() == SortingCriteria.AUTO_SORTING) {
Map<Subscriber, SubscriptionInfo> subscriptionMap = NotificationHelper.getSubscriptionMap(getIdentity(), getLocale(), true, compareDate);
notificationsList = new ArrayList<Subscriber>();
for (Iterator<Map.Entry<Subscriber, SubscriptionInfo>> it_subs = subscriptionMap.entrySet().iterator(); it_subs.hasNext(); ) {
Map.Entry<Subscriber, SubscriptionInfo> sInfo = it_subs.next();
Subscriber subscrer = sInfo.getKey();
SubscriptionInfo infos = sInfo.getValue();
if (infos.hasNews()) {
notificationsList.add(subscrer);
}
}
notificationsList = getSortedList(notificationsList, sortingCriteria);
List<PortletEntry<Subscriber>> entries = convertNotificationToPortletEntryList(notificationsList);
notificationListModel = new NotificationsPortletTableDataModel(entries, getLocale(), subscriptionMap);
tableCtr.setTableDataModel(notificationListModel);
} else {
reloadModel(getPersistentManuallySortedItems());
}
}
Aggregations