use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project OpenOLAT by OpenOLAT.
the class EPNotificationsHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
SubscriptionInfo si = null;
Publisher publisher = subscriber.getPublisher();
EPFrontendManager epMgr = CoreSpringFactory.getImpl(EPFrontendManager.class);
EPMapShort amap = epMgr.loadMapShortByResourceId(publisher.getResId());
if (isInkoveValid(amap, compareDate, publisher)) {
// init the helper;
String rootBusinessPath = "[EPDefaultMap:" + amap.getKey() + "]";
EPNotificationsHelper helper = new EPNotificationsHelper(rootBusinessPath, locale);
String resName = amap.getOlatResource().getResourceableTypeName();
si = new SubscriptionInfo(subscriber.getKey(), publisher.getType(), getTitleItemForMap(amap), null);
List<SubscriptionListItem> allItems = new ArrayList<SubscriptionListItem>(0);
// get subscriptionListItems according to map type
if ("EPDefaultMap".equals(resName) || "EPStructuredMapTemplate".equals(resName)) {
allItems = helper.getAllSubscrItemsDefault(compareDate, amap);
} else if ("EPStructuredMap".equals(resName)) {
allItems = helper.getAllSubscrItemsStructured(compareDate, amap);
}
for (SubscriptionListItem item : allItems) {
si.addSubscriptionListItem(item);
}
}
if (si == null) {
// no info, return empty
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
}
use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project OpenOLAT by OpenOLAT.
the class NewUsersNotificationHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
SubscriptionInfo si;
Translator translator = Util.createPackageTranslator(this.getClass(), locale);
// there could be news for me, investigate deeper
try {
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
List<Identity> identities = UsersSubscriptionManager.getInstance().getNewIdentityCreated(compareDate);
if (identities.isEmpty()) {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
} else {
translator = Util.createPackageTranslator(this.getClass(), locale);
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(getItemTitle(identities, translator), CSSHelper.CSS_CLASS_GROUP), null);
SubscriptionListItem subListItem;
for (Identity newUser : identities) {
String desc = translator.translate("notifications.entry", new String[] { NotificationHelper.getFormatedName(newUser) });
String businessPath = "[Identity:" + newUser.getKey() + "]";
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
Date modDate = newUser.getCreationDate();
subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSSHelper.CSS_CLASS_USER);
si.addSubscriptionListItem(subListItem);
}
}
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
} catch (Exception e) {
log.error("Error creating new identity's notifications for subscriber: " + subscriber.getKey(), e);
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
}
use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class FeedNotifications method getItems.
public List<SubscriptionListItem> getItems() throws Exception {
try {
Publisher p = subscriber.getPublisher();
String data = p.getData();
Date latestNews = p.getLatestNewsDate();
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
String resName = p.getResName();
Long resId = p.getResId();
Feed feed;
if ("CourseModule".equals(resName)) {
OLATResourceable ores = OresHelper.createOLATResourceableInstance(resName, Long.parseLong(data));
feed = feedManager.loadFeed(ores);
} else {
OLATResourceable ores = OresHelper.createOLATResourceableInstance(resName, resId);
feed = feedManager.loadFeed(ores);
}
List<Item> listItems = feedManager.loadItems(feed);
for (Item item : listItems) {
createSubscriptionItem(item, p);
}
}
} catch (Exception e) {
log.error("error in Feed notification", e);
}
return items;
}
use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project OpenOLAT by OpenOLAT.
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);
}
}
Aggregations