use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project openolat by klemens.
the class FeedNotifications method createSubscriptionItem.
private void createSubscriptionItem(Item item, Publisher p) {
Date modDate = item.getPublishDate();
if (compareDate.before(modDate)) {
String title = item.getTitle();
String author = item.getAuthor();
String desc;
if (item.isDraft()) {
return;
} else {
desc = translator.translate("notifications.entry", new String[] { title, author });
}
String businessPath = p.getBusinessPath();
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
String iconCssClass = item.extraCSSClass();
SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass);
items.add(subListItem);
}
}
use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project openolat by klemens.
the class FeedNotificationsHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
SubscriptionInfo si;
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
try {
final Translator translator = Util.createPackageTranslator(FeedMainController.class, locale);
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
String title;
try {
RepositoryEntry re = repoManager.lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false);
if (re.getAccess() == RepositoryEntry.DELETED || re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
return notificationsManager.getNoSubscriptionInfo();
}
String displayName = re.getDisplayname();
if ("CourseModule".equals(p.getResName())) {
ICourse course = CourseFactory.loadCourse(re);
CourseNode node = course.getRunStructure().getNode(p.getSubidentifier());
if (node == null) {
notificationsManager.deactivate(p);
return notificationsManager.getNoSubscriptionInfo();
}
title = translator.translate(NOTIFICATIONS_HEADER_COURSE, new String[] { displayName });
} else {
title = getHeader(translator, displayName);
}
} catch (Exception e) {
log.error("Unknown Exception", e);
return notificationsManager.getNoSubscriptionInfo();
}
OLATResourceable feedOres = OresHelper.createOLATResourceableInstance(p.getType(), new Long(p.getData()));
Feed feed = feedManager.loadFeed(feedOres);
List<Item> listItems = feedManager.loadItems(feed);
List<SubscriptionListItem> items = new ArrayList<>();
for (Item item : listItems) {
if (!item.isDraft()) {
appendSubscriptionItem(item, p, compareDate, translator, items);
}
}
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, getCssClassIcon()), items);
} else {
// no news
si = notificationsManager.getNoSubscriptionInfo();
}
} 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 FeedNotificationsHandler method appendSubscriptionItem.
private void appendSubscriptionItem(Item item, Publisher p, Date compareDate, Translator translator, List<SubscriptionListItem> items) {
String title = item.getTitle();
String author = item.getAuthor();
String businessPath = p.getBusinessPath();
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
String iconCssClass = item.extraCSSClass();
Date publishDate = item.getPublishDate();
if (publishDate != null) {
if (compareDate.before(publishDate)) {
String desc = translator.translate("notifications.entry.published", new String[] { title, author });
items.add(new SubscriptionListItem(desc, urlToSend, businessPath, publishDate, iconCssClass));
}
// modified date.
if (item.getModifierKey() != null || (item.getFeed().isExternal() && !item.getCreationDate().equals(item.getLastModified()) && item.getPublishDate().before(item.getLastModified()))) {
Date modDate = item.getLastModified();
if (compareDate.before(modDate)) {
String desc;
String modifier = item.getModifier();
if (StringHelper.containsNonWhitespace(modifier)) {
desc = translator.translate("notifications.entry.modified", new String[] { title, modifier });
} else {
desc = translator.translate("notifications.entry.modified", new String[] { title, "???" });
}
items.add(new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass));
}
}
List<UserComment> comments = commentAndRatingService.getComments(item.getFeed(), item.getGuid());
for (UserComment comment : comments) {
if (compareDate.before(comment.getCreationDate())) {
String desc;
String modifier = UserManager.getInstance().getUserDisplayName(comment.getCreator().getKey());
if (StringHelper.containsNonWhitespace(modifier)) {
desc = translator.translate("notifications.entry.commented", new String[] { title, modifier });
} else {
desc = translator.translate("notifications.entry.commented", new String[] { title, "???" });
}
items.add(new SubscriptionListItem(desc, urlToSend, businessPath, comment.getCreationDate(), iconCssClass));
}
}
}
}
use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project openolat by klemens.
the class EPChangelogController method updateChangelogDisplay.
/**
* update the changelog-list according to selected date. this method is
* invoked on initForm and again when user changes date in dateChooser
*/
private void updateChangelogDisplay() {
// init the helper;
String path = getWindowControl().getBusinessControl().getAsString();
EPNotificationsHelper helper = new EPNotificationsHelper(path, getLocale());
// get the date from the dateChooser component
Date compareDate = dateChooser.getDate();
EPMapShort mapShort = ePFMgr.loadMapShortByResourceId(map.getOlatResource().getResourceableId());
List<SubscriptionListItem> allItems = new ArrayList<SubscriptionListItem>(0);
// get subscriptionListItems according to map type
if (map instanceof EPDefaultMap || map instanceof EPStructuredMapTemplate) {
allItems = helper.getAllSubscrItemsDefault(compareDate, mapShort);
} else if (map instanceof EPStructuredMap) {
allItems = helper.getAllSubscrItemsStructured(compareDate, mapShort);
}
List<SubscriptionItemBundle> bundles = getItemBundlesForSubscriptionItems(allItems);
flc.contextPut("subscriptionItems", bundles);
}
use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project openolat by klemens.
the class EPChangelogController method getItemBundlesForSubscriptionItems.
/**
* @param subscriptionItems
* @return
*/
private List<SubscriptionItemBundle> getItemBundlesForSubscriptionItems(List<SubscriptionListItem> subscriptionItems) {
List<SubscriptionItemBundle> bundles = new ArrayList<EPChangelogController.SubscriptionItemBundle>();
Formatter f = Formatter.getInstance(getTranslator().getLocale());
for (int i = 0; i < subscriptionItems.size(); i++) {
SubscriptionListItem listItem = subscriptionItems.get(i);
SubscriptionItemBundle bundle = new SubscriptionItemBundle();
bundle.setDateString(f.formatDate(listItem.getDate()));
String linkName = "subscrIL_" + i;
bundle.setLinkName(linkName);
String text = listItem.getDescription();
FormLink link = uifactory.addFormLink(linkName, text, null, flc, Link.NONTRANSLATED);
link.setUserObject(listItem.getUserObject());
bundle.setCssClass(listItem.getIconCssClass());
bundles.add(bundle);
}
return bundles;
}
Aggregations