use of org.xwiki.watchlist.internal.api.AutomaticWatchMode in project xwiki-platform by xwiki.
the class DefaultWatchListStore method getAutomaticWatchMode.
@Override
public AutomaticWatchMode getAutomaticWatchMode(String user) {
XWikiContext context = contextProvider.get();
AutomaticWatchMode mode = null;
try {
BaseObject watchObject = getWatchListObject(user);
String value = watchObject.getStringValue(WatchListClassDocumentInitializer.AUTOMATICWATCH_PROPERTY);
if (StringUtils.isNotBlank(value) && !WatchListClassDocumentInitializer.AUTOMATICWATCH_DEFAULT_VALUE.equals(value)) {
mode = AutomaticWatchMode.valueOf(value);
}
} catch (Exception e) {
// Failed for some reason, now try getting it from xwiki.cfg
logger.error("Failed to get automatic watch mode for user [{}], using fallbacks", user, e);
}
if (mode == null) {
String value = context.getWiki().Param("xwiki.plugin.watchlist.automaticwatch");
if (value != null) {
try {
mode = AutomaticWatchMode.valueOf(value.toUpperCase());
} catch (Exception e) {
logger.warn("Invalid configuration in xwiki.plugin.watchlist.automaticwatch", e);
}
}
}
return mode != null ? mode : AutomaticWatchMode.MAJOR;
}
use of org.xwiki.watchlist.internal.api.AutomaticWatchMode in project xwiki-platform by xwiki.
the class AutomaticWatchModeListener method documentModifiedHandler.
/**
* Automatically watch modified document depending on the configuration.
*
* @param event the observation event we check for a deleted document event
* @param currentDoc document version after event occurred
* @param context the XWiki context
*/
private void documentModifiedHandler(Event event, XWikiDocument currentDoc, XWikiContext context) {
String user = currentDoc.getContentAuthor();
DocumentReference userReference = currentDoc.getContentAuthorReference();
// Avoid handling guests or the superadmin user.
if (userReference == null || !context.getWiki().exists(userReference, context)) {
return;
}
// Determine if the current event should be registered, based on the user's prefereces.
boolean register = false;
AutomaticWatchMode mode = this.store.getAutomaticWatchMode(user);
switch(mode) {
case ALL:
register = true;
break;
case MAJOR:
register = !currentDoc.isMinorEdit();
break;
case NEW:
register = event instanceof DocumentCreatedEvent;
break;
default:
break;
}
if (register) {
try {
this.store.addWatchedElement(user, currentDoc.getPrefixedFullName(), WatchedElementType.DOCUMENT);
} catch (XWikiException e) {
logger.warn("Failed to watch document [{}] for user [{}]", currentDoc.getPrefixedFullName(), user, e);
}
}
}
Aggregations