Skip to content
Snippets Groups Projects
Commit 389cdde1 authored by Clément Aubin's avatar Clément Aubin
Browse files

XWIKI-14622: Allow notification filters to customize how they are

displayed
* Add ScopeNotificationFilterClassMigrator
* Remove NotificationPreferenceScopeDocumentInitializer
parent 7f28ec88
No related branches found
No related tags found
No related merge requests found
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.notifications.filters.internal;
import java.util.Arrays;
import java.util.List;
import javax.inject.Named;
import javax.inject.Singleton;
import org.xwiki.component.annotation.Component;
import org.xwiki.model.reference.LocalDocumentReference;
import com.xpn.xwiki.doc.AbstractMandatoryClassInitializer;
import com.xpn.xwiki.objects.classes.BaseClass;
/**
* Define the NotificationPreferenceScopeClass XClass.
* This XClass is used to store filters information in the user profile.
*
* @version $Id$
* @since 9.7R1
*/
@Component
@Named("XWiki.Notifications.Code.NotificationPreferenceScopeClass")
@Singleton
public class NotificationPreferenceScopeDocumentInitializer extends AbstractMandatoryClassInitializer
{
/**
* The path to the class parent document.
*/
private static final List<String> PARENT_PATH = Arrays.asList("XWiki", "Notifications", "Code");
private static final String INPUT = "input";
private static final String SEPARATORS = "|, ";
/**
* Default constructor.
*/
public NotificationPreferenceScopeDocumentInitializer()
{
super(new LocalDocumentReference(PARENT_PATH, "NotificationPreferenceScopeClass"));
}
@Override
protected void createClass(BaseClass xclass)
{
xclass.addStaticListField("eventType", "Event Type", 64, true,
false, "", INPUT, SEPARATORS);
xclass.addStaticListField("format", "Format", 64, false,
"alert=Alert|email=E-mail", INPUT, SEPARATORS);
xclass.addStaticListField("scope", "Filter scope", 64, false,
"pageOnly=Page|pageAndChildren=Page &amp; Children|wiki=Wiki", INPUT, SEPARATORS);
xclass.addStaticListField("scopeFilterType", "Filter type", 64, false,
"inclusive=Inclusive|exclusive=Exclusive", INPUT, SEPARATORS);
xclass.addTextField("scopeReference", "Scope reference", 64);
}
}
...@@ -57,13 +57,13 @@ ...@@ -57,13 +57,13 @@
@Singleton @Singleton
public class ScopeNotificationFilterClassMigrator extends AbstractHibernateDataMigration public class ScopeNotificationFilterClassMigrator extends AbstractHibernateDataMigration
{ {
private static final List<String> NOTIFICATION_CODE_PATH = Arrays.asList("XWiki", "Notifications", "Code");
private static final LocalDocumentReference OLD_XCLASS_REFERENCE = private static final LocalDocumentReference OLD_XCLASS_REFERENCE =
new LocalDocumentReference(Arrays.asList("XWiki", "Notifications", "Code"), new LocalDocumentReference(NOTIFICATION_CODE_PATH, "NotificationPreferenceScopeClass");
"NotificationPreferenceScopeClass");
private static final LocalDocumentReference NEW_XCLASS_REFERENCE = private static final LocalDocumentReference NEW_XCLASS_REFERENCE =
new LocalDocumentReference(Arrays.asList("XWiki", "Notifications", "Code"), new LocalDocumentReference(NOTIFICATION_CODE_PATH, "NotificationFilterPreferenceClass");
"NotificationFilterPreferenceClass");
@Inject @Inject
private QueryManager queryManager; private QueryManager queryManager;
...@@ -135,7 +135,7 @@ protected void hibernateMigrate() throws DataMigrationException, XWikiException ...@@ -135,7 +135,7 @@ protected void hibernateMigrate() throws DataMigrationException, XWikiException
* *
* @param document the document to migrate * @param document the document to migrate
*/ */
private void migrateDocument(XWikiDocument document) private void migrateDocument(XWikiDocument document) throws XWikiException
{ {
List<BaseObject> oldXObjects = document.getXObjects(OLD_XCLASS_REFERENCE); List<BaseObject> oldXObjects = document.getXObjects(OLD_XCLASS_REFERENCE);
...@@ -144,6 +144,10 @@ private void migrateDocument(XWikiDocument document) ...@@ -144,6 +144,10 @@ private void migrateDocument(XWikiDocument document)
} }
document.removeXObjects(OLD_XCLASS_REFERENCE); document.removeXObjects(OLD_XCLASS_REFERENCE);
xcontextProvider.get().getWiki().saveDocument(document,
"[UPGRADE] XObject migration from ScopeNotificationFilterClass to NotificationPreferenceFilterClass.",
xcontextProvider.get());
} }
private BaseObject generateNewXObject(BaseObject oldXObject) private BaseObject generateNewXObject(BaseObject oldXObject)
...@@ -180,6 +184,8 @@ private BaseObject generateNewXObject(BaseObject oldXObject) ...@@ -180,6 +184,8 @@ private BaseObject generateNewXObject(BaseObject oldXObject)
case "wiki": case "wiki":
newXObject.setStringListValue("wikis", oldXObjectScopeReference); newXObject.setStringListValue("wikis", oldXObjectScopeReference);
break; break;
default:
break;
} }
return newXObject; return newXObject;
......
org.xwiki.notifications.filters.internal.DefaultModelBridge org.xwiki.notifications.filters.internal.DefaultModelBridge
org.xwiki.notifications.filters.internal.NotificationPreferenceScopeDocumentInitializer org.xwiki.notifications.filters.internal.ToggleableFilterPreferenceDocumentInitializer
org.xwiki.notifications.filters.internal.ToggleableFilterPreferenceDocumentInitializer org.xwiki.notifications.filters.internal.WikiNotificationFilterDisplayerComponentBuilder
\ No newline at end of file org.xwiki.notifications.filters.internal.WikiNotificationFilterDisplayerDocumentInitializer
org.xwiki.notifications.filters.internal.NotificationFilterPreferenceDocumentInitializer
org.xwiki.notifications.filters.internal.migrators.ScopeNotificationFilterClassMigrator
\ No newline at end of file
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