use of org.olat.core.commons.services.notifications.SubscriptionInfo in project openolat by klemens.
the class NotificationsPortletRunController method getAllPortletEntries.
private List<PortletEntry<Subscriber>> getAllPortletEntries() {
notificationsList = man.getValidSubscribers(getIdentity());
// calc subscriptioninfo for all subscriptions and, if only those with news are to be shown, remove the other ones
for (Iterator<Subscriber> it_subs = notificationsList.iterator(); it_subs.hasNext(); ) {
Subscriber subscriber = it_subs.next();
Publisher pub = subscriber.getPublisher();
NotificationsHandler notifHandler = man.getNotificationsHandler(pub);
if (notifHandler == null) {
it_subs.remove();
} else {
SubscriptionInfo subsInfo = notifHandler.createSubscriptionInfo(subscriber, getLocale(), compareDate);
if (!subsInfo.hasNews()) {
it_subs.remove();
}
}
}
return convertNotificationToPortletEntryList(notificationsList);
}
use of org.olat.core.commons.services.notifications.SubscriptionInfo in project openolat by klemens.
the class NotificationsWebService method getNotifications.
/**
* Retrieves the notification of the logged in user.
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The notifications
* @response.representation.200.example {@link org.olat.core.commons.services.notifications.restapi.vo.Examples#SAMPLE_INFOVOes}
* @response.representation.404.doc The identity not found
* @param date The date (optional)
* @param type The type of notifications (User, Forum...) (optional)
* @param httpRequest The HTTP request
* @return an xml or json representation of a the user being search. The xml
* correspond to a <code>SubscriptionInfoVO</code>. <code>SubscriptionInfoVO</code>
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getNotifications(@QueryParam("date") String date, @QueryParam("type") String type, @Context HttpServletRequest httpRequest) {
Identity identity = RestSecurityHelper.getIdentity(httpRequest);
Locale locale = RestSecurityHelper.getLocale(httpRequest);
Date compareDate;
if (StringHelper.containsNonWhitespace(date)) {
compareDate = parseDate(date, locale);
} else {
NotificationsManager man = NotificationsManager.getInstance();
compareDate = man.getCompareDateFromInterval(man.getUserIntervalOrDefault(identity));
}
List<String> types = new ArrayList<String>(1);
if (StringHelper.containsNonWhitespace(type)) {
types.add(type);
}
Map<Subscriber, SubscriptionInfo> subsInfoMap = NotificationHelper.getSubscriptionMap(identity, locale, true, compareDate, types);
List<SubscriptionInfoVO> voes = new ArrayList<SubscriptionInfoVO>();
for (Map.Entry<Subscriber, SubscriptionInfo> entry : subsInfoMap.entrySet()) {
SubscriptionInfo info = entry.getValue();
if (info.hasNews()) {
Subscriber subscriber = entry.getKey();
voes.add(createSubscriptionInfoVO(subscriber.getPublisher(), info));
}
}
SubscriptionInfoVO[] voesArr = new SubscriptionInfoVO[voes.size()];
voes.toArray(voesArr);
return Response.ok(voesArr).build();
}
use of org.olat.core.commons.services.notifications.SubscriptionInfo in project openolat by klemens.
the class MailNotificationsHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
if (!mailModule.isInternSystem()) {
return notificationsManager.getNoSubscriptionInfo();
}
String realMail = subscriber.getIdentity().getUser().getPreferences().getReceiveRealMail();
if ("true".equals(realMail)) {
// receive real e-mails
return notificationsManager.getNoSubscriptionInfo();
} else if (!StringHelper.containsNonWhitespace(realMail) && mailModule.isReceiveRealMailUserDefaultSetting()) {
// user has no settings, check the default setting
return notificationsManager.getNoSubscriptionInfo();
}
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)) {
try {
List<DBMailLight> inbox = mailManager.getInbox(subscriber.getIdentity(), Boolean.TRUE, Boolean.FALSE, compareDate, 0, -1);
if (!inbox.isEmpty()) {
Translator translator = Util.createPackageTranslator(MailModule.class, locale);
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(translator.translate("mail.notification.type"), "o_co_icon"), null);
for (DBMailLight mail : inbox) {
String subject = mail.getSubject();
String businessPath = "[Inbox:0][Inbox:0][DBMail:" + mail.getKey() + "]";
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
SubscriptionListItem subListItem = new SubscriptionListItem(subject, urlToSend, businessPath, mail.getCreationDate(), "o_co_icon");
si.addSubscriptionListItem(subListItem);
}
}
} catch (Exception ex) {
logError("", ex);
}
}
if (si == null) {
si = notificationsManager.getNoSubscriptionInfo();
}
return si;
}
use of org.olat.core.commons.services.notifications.SubscriptionInfo in project openolat by klemens.
the class FileUploadNotificationHandler 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(Subscriber subscriber, Locale locale, Date compareDate) {
Publisher p = subscriber.getPublisher();
final Date latestNews = p.getLatestNewsDate();
SubscriptionInfo si;
// there could be news for me, investigate deeper
try {
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
RepositoryEntry re = repositoryManager.lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false);
if (re == null) {
if (!checkPublisher(subscriber.getPublisher())) {
return notificationsManager.getNoSubscriptionInfo();
}
} else if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
return notificationsManager.getNoSubscriptionInfo();
}
String displayname = re.getDisplayname();
OLATResourceable ores = OresHelper.createOLATResourceableInstance("CourseModule", p.getResId());
RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(ores, false);
List<DialogElement> dialogElements = dialogElementsMgr.getDialogElements(entry, p.getSubidentifier());
final Translator translator = Util.createPackageTranslator(DialogCourseNodeRunController.class, locale);
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(translator.translate("notifications.header", new String[] { displayname }), CSSS_CLASS_UPLOAD_ICON), null);
for (DialogElement element : dialogElements) {
// do only show entries newer then the ones already seen
if (element.getCreationDate().after(compareDate)) {
String filename = element.getFilename();
Identity author = element.getAuthor();
Date modDate = element.getCreationDate();
String[] params = new String[] { filename, NotificationHelper.getFormatedName(author) };
String desc = translator.translate("notifications.entry", params);
String businessPath = p.getBusinessPath() + "[Element:" + element.getKey() + "]";
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
String cssClass = CSSHelper.createFiletypeIconCssClassFor(filename);
si.addSubscriptionListItem(new SubscriptionListItem(desc, urlToSend, businessPath, modDate, cssClass));
}
}
} else {
si = notificationsManager.getNoSubscriptionInfo();
}
} catch (Exception e) {
log.error("Error creating file upload's notifications for subscriber: " + subscriber.getKey(), e);
si = notificationsManager.getNoSubscriptionInfo();
}
return si;
}
use of org.olat.core.commons.services.notifications.SubscriptionInfo in project openolat by klemens.
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;
}
Aggregations