Skip to content
Snippets Groups Projects
Commit 4533e473 authored by srosse's avatar srosse
Browse files

OO-1619: add forum notifications to wiki subscriptions

parent 39d7966f
No related branches found
No related tags found
No related merge requests found
......@@ -220,7 +220,8 @@ public class ForumController extends BasicController implements GenericEventList
* @param ureq
* @param wControl
*/
ForumController(Forum forum, ForumCallback focallback, UserRequest ureq, WindowControl wControl) {
public ForumController(UserRequest ureq, WindowControl wControl,
Forum forum, ForumCallback focallback, boolean showSubscriptionButton) {
super(ureq, wControl);
this.forum = forum;
this.focallback = focallback;
......@@ -267,8 +268,7 @@ public class ForumController extends BasicController implements GenericEventList
// --- subscription ---
subsContext = focallback.getSubscriptionContext();
// if sc is null, then no subscription is desired
if (subsContext != null) {
// FIXME fj: implement subscription callback for group forums
if (subsContext != null && showSubscriptionButton) {
String businessPath = wControl.getBusinessControl().getAsString();
String data = String.valueOf(forum.getKey());
PublisherData pdata = new PublisherData(OresHelper.calculateTypeName(Forum.class), data, businessPath);
......
......@@ -81,7 +81,7 @@ public class ForumUIFactory {
* @return a TitledWrapperController
*/
public static Controller getTitledForumController(UserRequest ureq, WindowControl wControl, Forum forum, ForumCallback forumCallback, TitleInfo titleInfo) {
ForumController popupFoCtr = new ForumController(forum, forumCallback, ureq, wControl);
ForumController popupFoCtr = new ForumController(ureq, wControl, forum, forumCallback, true);
TitledWrapperController forumWrapperController = new TitledWrapperController(ureq, wControl, popupFoCtr, "o_course_run", titleInfo);
// Set CSS values to default forum icons if no values are set in the title info
if (!StringHelper.containsNonWhitespace(titleInfo.getIconCssClass())) {
......@@ -99,7 +99,7 @@ public class ForumUIFactory {
* @return
*/
public static ForumController getStandardForumController(UserRequest ureq, WindowControl wControl, Forum forum, ForumCallback forumCallback) {
return new ForumController(forum, forumCallback, ureq, wControl);
return new ForumController(ureq, wControl, forum, forumCallback, true);
}
}
......@@ -96,7 +96,6 @@ import org.olat.modules.fo.Forum;
import org.olat.modules.fo.ForumCallback;
import org.olat.modules.fo.ForumController;
import org.olat.modules.fo.ForumManager;
import org.olat.modules.fo.ForumUIFactory;
import org.olat.modules.wiki.gui.components.wikiToHtml.ErrorEvent;
import org.olat.modules.wiki.gui.components.wikiToHtml.FilterUtil;
import org.olat.modules.wiki.gui.components.wikiToHtml.RequestImageEvent;
......@@ -420,14 +419,14 @@ public class WikiMainController extends BasicController implements CloneableCont
ContextEntry ce = entries.get(0);
String typ = ce.getOLATResourceable().getResourceableTypeName();
if("az".equals(typ)) {
if("az".equalsIgnoreCase(typ)) {
openAtoZPage(ureq, wiki);
} else if ("lastChanges".equals(typ)) {
} else if ("lastChanges".equalsIgnoreCase(typ)) {
openLastChangesPage(ureq, wiki);
} else if ("index".equals(typ)) {
} else if ("index".equalsIgnoreCase(typ)) {
WikiPage page = openIndexPage(ureq, wiki);
pageId = page.getPageId();
} else if ("Forum".equals(typ)) {
} else if ("Forum".equalsIgnoreCase(typ)) {
Long forumKey = ce.getOLATResourceable().getResourceableId();
for(WikiPage page:wiki.getAllPagesWithContent()) {
if(forumKey.longValue() == page.getForumKey()) {
......@@ -462,8 +461,14 @@ public class WikiMainController extends BasicController implements CloneableCont
if(entries.size() > 1) {
List<ContextEntry> subEntries = entries.subList(1, entries.size());
String subTyp = subEntries.get(0).getOLATResourceable().getResourceableTypeName();
if("tab".equals(subTyp)) {
if("tab".equalsIgnoreCase(subTyp)) {
tabs.activate(ureq, subEntries, ce.getTransientState());
} else if("message".equalsIgnoreCase(subTyp)) {
OLATResourceable tabOres = OresHelper.createOLATResourceableInstance("tab", 1l);
ContextEntry tabCe = BusinessControlFactory.getInstance().createContextEntry(tabOres);
tabs.activate(ureq, Collections.singletonList(tabCe), null);
forumController.activate(ureq, subEntries, null);
}
}
}
......@@ -647,7 +652,7 @@ public class WikiMainController extends BasicController implements CloneableCont
WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ce, getWindowControl());
removeAsListenerAndDispose(forumController);
forumController = ForumUIFactory.getStandardForumController(ureq, bwControl, forum, forumCallback);
forumController = new ForumController(ureq, bwControl, forum, forumCallback, false);
listenTo(forumController);
discussionContent.put("articleforum", forumController.getInitialComponent());
}
......
......@@ -45,7 +45,8 @@ import org.olat.core.gui.translator.Translator;
import org.olat.core.id.Identity;
import org.olat.core.id.OLATResourceable;
import org.olat.core.id.context.BusinessControlFactory;
import org.olat.core.logging.LogDelegator;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.Util;
import org.olat.core.util.resource.OresHelper;
import org.olat.course.CourseFactory;
......@@ -59,6 +60,9 @@ import org.olat.fileresource.types.WikiResource;
import org.olat.group.BusinessGroup;
import org.olat.group.BusinessGroupService;
import org.olat.modules.ModuleConfiguration;
import org.olat.modules.fo.ForumManager;
import org.olat.modules.fo.ForumNotificationsHandler;
import org.olat.modules.fo.Message;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryManager;
......@@ -71,9 +75,11 @@ import org.olat.repository.RepositoryManager;
*
* @author guido
*/
public class WikiPageChangeOrCreateNotificationHandler extends LogDelegator implements NotificationsHandler {
public class WikiPageChangeOrCreateNotificationHandler implements NotificationsHandler {
private static final OLog log = Tracing.createLoggerFor(WikiPageChangeOrCreateNotificationHandler.class);
private static final String CSS_CLASS_WIKI_PAGE_CHANGED_ICON = "o_edit_icon";
private static final String CSS_CLASS_WIKI_PAGE_CHANGED_ICON = "o_wiki_icon";
protected String businessControlString;
public WikiPageChangeOrCreateNotificationHandler() {
......@@ -84,14 +90,17 @@ public class WikiPageChangeOrCreateNotificationHandler extends LogDelegator impl
* @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, final Locale locale, Date compareDate) {
Publisher p = subscriber.getPublisher();
final Date latestNews = p.getLatestNewsDate();
Long resId = p.getResId();
SubscriptionInfo si;
final boolean debug = log.isDebug();
// there could be news for me, investigate deeper
logDebug("compareDate=" + compareDate + " ; latestNews=" + latestNews, null);
if(debug) log.debug("compareDate=" + compareDate + " ; latestNews=" + latestNews, null);
try {
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
OLATResourceable ores = null;
......@@ -111,61 +120,88 @@ public class WikiPageChangeOrCreateNotificationHandler extends LogDelegator impl
ModuleConfiguration config = ((WikiCourseNode)courseNode).getModuleConfiguration();
RepositoryEntry re = WikiEditController.getWikiRepoReference(config, true);
resId = re.getOlatResource().getResourceableId();
logDebug("resId=" + resId, null);
if(debug) log.debug("resId=" + resId, null);
ores = OresHelper.createOLATResourceableInstance(WikiResource.TYPE_NAME, resId);
businessControlString = p.getBusinessPath() + "[path=";
} else {
// resName = 'BusinessGroup' or 'FileResource.WIKI'
logDebug("p.getResName()=" + p.getResName(), null);
ores = OresHelper.createOLATResourceableInstance(p.getResName(), resId);
if(debug) log.debug("p.getResName()=" + p.getResName(), null);
ores = OresHelper.createOLATResourceableInstance(p.getResName(), resId);
businessControlString = p.getBusinessPath() + "[path=";
}
Wiki wiki = WikiManager.getInstance().getOrLoadWiki(ores);
final List<WikiPage> pages = wiki.getPagesByDate();
Translator translator = Util.createPackageTranslator(WikiPageChangeOrCreateNotificationHandler.class, locale);
Translator forumTranslator = Util.createPackageTranslator(ForumNotificationsHandler.class, locale);
TitleItem title = getTitleItem(p, translator);
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), title, null);
SubscriptionListItem subListItem;
for (Iterator<WikiPage> it = pages.listIterator(); it.hasNext();) {
WikiPage element = it.next();
// do only show entries newer then the ones already seen
Date modDate = new Date(element.getModificationTime());
logDebug("modDate=" + modDate + " ; compareDate=" + compareDate, null);
if (modDate.after(compareDate)) {
if((element.getPageName().startsWith("O_") || element.getPageName().startsWith(WikiPage.WIKI_MENU_PAGE)) &&
(element.getModifyAuthor() <= 0)) {
//theses pages are created sometimes automatically. Check if this is the case
continue;
}
for (Iterator<WikiPage> it = pages.listIterator(); it.hasNext();) {
WikiPage element = it.next();
// do only show entries newer then the ones already seen
Date modDate = new Date(element.getModificationTime());
if(debug) log.debug("modDate=" + modDate + " ; compareDate=" + compareDate, null);
if (modDate.after(compareDate)) {
if((element.getPageName().startsWith("O_") || element.getPageName().startsWith(WikiPage.WIKI_MENU_PAGE))
&& (element.getModifyAuthor() <= 0)) {
//theses pages are created sometimes automatically. Check if this is the case
continue;
}
//build Businesscontrol-Path
String businessPath = null;
String urlToSend = null;
if(p.getBusinessPath() != null) {
businessPath = businessControlString + element.getPageName() + "]";
urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
}
// string[] gets filled into translation key by adding {0...n} to
// the string
Identity ident = BaseSecurityManager.getInstance().loadIdentityByKey(Long.valueOf(element.getModifyAuthor()));
String desc = translator.translate("notifications.entry", new String[] { element.getPageName(), NotificationHelper.getFormatedName(ident)});
subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSS_CLASS_WIKI_PAGE_CHANGED_ICON);
si.addSubscriptionListItem(subListItem);
} else {
//there are no more new pages so we stop here
break;
}
//build Businesscontrol-Path
String businessPath = null;
String urlToSend = null;
if(p.getBusinessPath() != null) {
businessPath = businessControlString + element.getPageName() + "]";
urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
}
// string[] gets filled into translation key by adding {0...n} to
// the string
Identity ident = BaseSecurityManager.getInstance().loadIdentityByKey(Long.valueOf(element.getModifyAuthor()));
String desc = translator.translate("notifications.entry", new String[] { element.getPageName(), NotificationHelper.getFormatedName(ident)});
SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSS_CLASS_WIKI_PAGE_CHANGED_ICON);
si.addSubscriptionListItem(subListItem);
}
long forumKey = element.getForumKey();
List<Message> mInfos = ForumManager.getInstance().getNewMessageInfo(forumKey, compareDate);
for (Message mInfo : mInfos) {
String messageTitle = mInfo.getTitle();
Identity creator = mInfo.getCreator();
Identity modifier = mInfo.getModifier();
Date messageModDate = mInfo.getLastModified();
String name;
if(modifier != null) {
name = NotificationHelper.getFormatedName(modifier);
} else {
name = NotificationHelper.getFormatedName(creator);
}
final String descKey = "notifications.entry" + (mInfo.getCreationDate().equals(messageModDate) ? "" : ".modified");
final String desc = forumTranslator.translate(descKey, new String[] { messageTitle, name });
String urlToSend = null;
String businessPath = null;
if(p.getBusinessPath() != null) {
businessPath = businessControlString + element.getPageName() + "][message:" + mInfo.getKey().toString() + "]";
urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
}
SubscriptionListItem subListItem =
new SubscriptionListItem(desc, urlToSend, businessPath, messageModDate, CSS_CLASS_WIKI_PAGE_CHANGED_ICON);
si.addSubscriptionListItem(subListItem);
}
}
} else {
//no news
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
} catch (Exception e) {
logError("Error creating wiki's notifications for subscriber: " + subscriber.getKey(), e);
log.error("Error creating wiki's notifications for subscriber: " + subscriber.getKey(), e);
checkPublisher(p);
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
......@@ -177,22 +213,22 @@ public class WikiPageChangeOrCreateNotificationHandler extends LogDelegator impl
if("BusinessGroup".equals(p.getResName())) {
BusinessGroup bg = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(p.getResId());
if(bg == null) {
logInfo("deactivating publisher with key; " + p.getKey(), null);
log.info("deactivating publisher with key; " + p.getKey(), null);
NotificationsManager.getInstance().deactivate(p);
}
} else if ("CourseModule".equals(p.getResName())) {
if(!NotificationsUpgradeHelper.checkCourse(p)) {
logInfo("deactivating publisher with key; " + p.getKey(), null);
log.info("deactivating publisher with key; " + p.getKey(), null);
NotificationsManager.getInstance().deactivate(p);
}
} else {
if(!NotificationsUpgradeHelper.checkOLATResourceable(p)) {
logInfo("deactivating publisher with key; " + p.getKey(), null);
log.info("deactivating publisher with key; " + p.getKey(), null);
NotificationsManager.getInstance().deactivate(p);
}
}
} catch (Exception e) {
logError("", e);
log.error("", e);
}
}
......@@ -220,7 +256,7 @@ public class WikiPageChangeOrCreateNotificationHandler extends LogDelegator impl
TitleItem title = getTitleItem(subscriber.getPublisher(), translator);
return title.getInfoContent("text/plain");
} catch (Exception e) {
logError("Error while creating assessment notifications for subscriber: " + subscriber.getKey(), e);
log.error("Error while creating assessment notifications for subscriber: " + subscriber.getKey(), e);
checkPublisher(subscriber.getPublisher());
return "-";
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment