From dfba8556a4f8ff9b167ba4e4034e16195fd97d0a Mon Sep 17 00:00:00 2001 From: Simon Urli <simon.urli@xwiki.com> Date: Thu, 6 Jun 2024 09:22:55 +0200 Subject: [PATCH] XWIKI-22211: Deprecate NotificationFilterPreferenceProvider (#2882) * Deprecate and legacify NotificationFilterPreferenceProvider and NotificationFilterPreference#getProviderHint * Clean up all code relying on it simplifying a lot the implem of NotificationFilterPreference * Only valid usage of the providerHint was for checking if a filter preference was stored or not: replaced it with checking the ID of the filter * Fix bad prefix in filters internal ids * Fix typos --- xwiki-platform-core/pom.xml | 12 ++ .../pom.xml | 134 +++++++++++- ...tionFilterPreferenceCompatibilityAspect.aj | 31 +++ ...atibilityNotificationFilterPreference.java | 39 ++++ .../NotificationFilterPreferenceProvider.java | 8 +- ...aultNotificationParametersFactoryTest.java | 1 - .../pom.xml | 2 + .../filters/NotificationFilterPreference.java | 13 +- .../NotificationFilterPreferenceManager.java | 3 +- ...ltNotificationFilterPreferenceManager.java | 197 +++--------------- ...eNotificationFilterPreferenceProvider.java | 116 ----------- ...NotificationFilterExpressionGenerator.java | 13 +- .../ScopeNotificationFilterPreference.java | 6 - .../main/resources/META-INF/components.txt | 1 - ...tificationFilterPreferenceManagerTest.java | 90 ++------ .../scope/ScopeNotificationFilterTest.java | 5 +- .../DefaultNotificationFilterPreference.java | 22 +- .../NotificationFilterPreferenceStore.java | 24 +-- .../internal/UserAddedEventListener.java | 1 - ...NotificationFilterPreferencesMigrator.java | 1 - .../R160300000XWIKI17243DataMigration.java | 2 - ...NotificationFilterPreferenceStoreTest.java | 2 - .../internal/UserAddedEventListenerTest.java | 3 - ...ficationFilterPreferencesMigratorTest.java | 1 - .../watch/WatchedLocationReference.java | 2 - .../filters/watch/WatchedUserReference.java | 3 - .../watch/WatchedLocationReferenceTest.java | 2 - .../DefaultNotificationParametersFactory.java | 1 - .../TagNotificationFilterPreference.java | 6 - ...aultNotificationParametersFactoryTest.java | 1 - 30 files changed, 288 insertions(+), 454 deletions(-) create mode 100644 xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-filters/xwiki-platform-legacy-notifications-filters-api/src/main/aspect/org/xwiki/notifications/filters/NotificationFilterPreferenceCompatibilityAspect.aj create mode 100644 xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-filters/xwiki-platform-legacy-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/CompatibilityNotificationFilterPreference.java rename xwiki-platform-core/{xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api => xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-filters/xwiki-platform-legacy-notifications-filters-api}/src/main/java/org/xwiki/notifications/filters/NotificationFilterPreferenceProvider.java (96%) delete mode 100644 xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/internal/UserProfileNotificationFilterPreferenceProvider.java diff --git a/xwiki-platform-core/pom.xml b/xwiki-platform-core/pom.xml index 2414f19badc..a1dbd0a8392 100644 --- a/xwiki-platform-core/pom.xml +++ b/xwiki-platform-core/pom.xml @@ -138,6 +138,18 @@ Single justification example: --> + <revapi.differences> + <justification>Deprecated method available through legacy but breakage triggered by a + dependant module.</justification> + <criticality>allowed</criticality> + <differences> + <item> + <ignore>true</ignore> + <code>java.method.removed</code> + <old>method java.lang.String org.xwiki.notifications.filters.NotificationFilterPreference::getProviderHint()</old> + </item> + </differences> + </revapi.differences> </analysisConfiguration> diff --git a/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-filters/xwiki-platform-legacy-notifications-filters-api/pom.xml b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-filters/xwiki-platform-legacy-notifications-filters-api/pom.xml index 100bf07d733..ea792f7b0a4 100644 --- a/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-filters/xwiki-platform-legacy-notifications-filters-api/pom.xml +++ b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-filters/xwiki-platform-legacy-notifications-filters-api/pom.xml @@ -37,14 +37,18 @@ By setting this property, we make sure this application would be automatically uninstalled if the administrator installs the old Activity Stream Application. --> <xwiki.extension.features>org.xwiki.platform:xwiki-platform-notifications-filters-api</xwiki.extension.features> - <xwiki.jacoco.instructionRatio>0.63</xwiki.jacoco.instructionRatio> + <xwiki.jacoco.instructionRatio>0.08</xwiki.jacoco.instructionRatio> </properties> <dependencies> + <!-- Trigger xwiki-platform-notifications-filters-api dependencies (but without + xwiki-platform-notifications-filters-api jar itself) --> <dependency> <groupId>org.xwiki.platform</groupId> <artifactId>xwiki-platform-notifications-filters-api</artifactId> <version>${project.version}</version> + <type>pom</type> <exclusions> + <!-- We want the legacy dependency of notification-api --> <exclusion> <groupId>org.xwiki.platform</groupId> <artifactId>xwiki-platform-notifications-api</artifactId> @@ -56,6 +60,27 @@ <artifactId>xwiki-platform-legacy-notifications-api</artifactId> <version>${project.version}</version> </dependency> + <!-- Aspectified dependency --> + <dependency> + <groupId>org.xwiki.platform</groupId> + <artifactId>xwiki-platform-notifications-filters-api</artifactId> + <version>${project.version}</version> + <!-- We don't want to draw this dependency since we're wrapping it --> + <scope>provided</scope> + <exclusions> + <!-- We want the legacy dependency of notification-api --> + <exclusion> + <groupId>org.xwiki.platform</groupId> + <artifactId>xwiki-platform-notifications-api</artifactId> + </exclusion> + </exclusions> + </dependency> + <!-- Build tools --> + <!-- Needed for backward compatibility Aspects --> + <dependency> + <groupId>org.aspectj</groupId> + <artifactId>aspectjrt</artifactId> + </dependency> <!-- Test dependencies --> <dependency> <groupId>org.xwiki.commons</groupId> @@ -64,4 +89,111 @@ <scope>test</scope> </dependency> </dependencies> + <build> + <plugins> + <!-- Apply Backward compatibility Aspects using the strategy described at + http://blogs.sonatype.com/john/2007/11/09/1194630418546.html --> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>aspectj-maven-plugin</artifactId> + <executions> + <execution> + <id>backward-compatibility-aspects</id> + <configuration> + <weaveDependencies> + <weaveDependency> + <groupId>org.xwiki.platform</groupId> + <artifactId>xwiki-platform-notifications-filters-api</artifactId> + </weaveDependency> + </weaveDependencies> + </configuration> + </execution> + </executions> + </plugin> + <!-- Exclude AspectJ's builddef.lst file form the generated JAR since it's not useful there. --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <excludes> + <exclude>**/builddef.lst</exclude> + </excludes> + </configuration> + </plugin> + <plugin> + <!-- Merge components.txt files --> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-antrun-plugin</artifactId> + <executions> + <execution> + <phase>process-classes</phase> + <configuration> + <target> + <!-- Add a line separator before appending the legacy components. + NOTE: The following solutions didn't work: + * the fixlastline parameter of the concat task affects only the appended files, NOT the destination + file; we need the new line at the end of the destination file! + * the text content of the header element inside the concat task is trimmed when the POM is parsed. + See http://jira.codehaus.org/browse/PLX-461 --> + <echo message="${line.separator}" file="${project.build.directory}/classes/META-INF/components.txt" append="true" /> + <concat destfile="${project.build.directory}/classes/META-INF/components.txt" append="true"> + <filelist dir="${basedir}/src/main/resources/META-INF/" files="components.txt" /> + </concat> + </target> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + </executions> + </plugin> + <!-- Make sure we run the tests only with the aspectified JARs since otherwise components will be registered + twice for example. --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <classpathDependencyExcludes> + <classpathDependencyExcludes>org.xwiki.platform:xwiki-platform-notifications-filters-api:jar</classpathDependencyExcludes> + </classpathDependencyExcludes> + </configuration> + </plugin> + <plugin> + <groupId>fr.inria.gforge.spoon</groupId> + <artifactId>spoon-maven-plugin</artifactId> + <executions> + <execution> + <id>spoon-main</id> + <configuration> + <processorProperties combine.children="append"> + <processorProperty> + <name>org.xwiki.tool.spoon.ComponentAnnotationProcessor</name> + <properties> + <property> + <!-- Skip foreign declaration checks since we merge the components.txt --> + <name>skipForeignDeclarations</name> + <value>true</value> + </property> + <!-- TODO: Ideally inherit this from the top level pom but I couldn't find how to do it, or remove + it when spoon is fixed, see https://github.com/INRIA/spoon/issues/3339 --> + <property> + <name>componentsTxtPath</name> + <value>target/classes/META-INF/components.txt</value> + </property> + </properties> + </processorProperty> + </processorProperties> + </configuration> + </execution> + <execution> + <id>spoon-test</id> + <configuration> + <!-- TODO: Remove once https://github.com/INRIA/spoon/issues/3583 is fixed --> + <skip>true</skip> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> \ No newline at end of file diff --git a/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-filters/xwiki-platform-legacy-notifications-filters-api/src/main/aspect/org/xwiki/notifications/filters/NotificationFilterPreferenceCompatibilityAspect.aj b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-filters/xwiki-platform-legacy-notifications-filters-api/src/main/aspect/org/xwiki/notifications/filters/NotificationFilterPreferenceCompatibilityAspect.aj new file mode 100644 index 00000000000..c7ee91a0ec6 --- /dev/null +++ b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-filters/xwiki-platform-legacy-notifications-filters-api/src/main/aspect/org/xwiki/notifications/filters/NotificationFilterPreferenceCompatibilityAspect.aj @@ -0,0 +1,31 @@ +/* + * 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; + +/** + * Add a backward compatibility layer to {@link NotificationFilterPreference}. + * + * @version $Id$ + * @since 16.5.0RC1 + */ +public privileged aspect NotificationFilterPreferenceCompatibilityAspect +{ + declare parents : NotificationFilterPreference implements CompatibilityNotificationFilterPreference; +} diff --git a/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-filters/xwiki-platform-legacy-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/CompatibilityNotificationFilterPreference.java b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-filters/xwiki-platform-legacy-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/CompatibilityNotificationFilterPreference.java new file mode 100644 index 00000000000..4a54383c508 --- /dev/null +++ b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-filters/xwiki-platform-legacy-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/CompatibilityNotificationFilterPreference.java @@ -0,0 +1,39 @@ +/* + * 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; + +/** + * Deprecated methods of {@link NotificationFilterPreference}. + * + * @version $Id$ + * @since 16.5.0RC1 + */ +public interface CompatibilityNotificationFilterPreference +{ + /** + * @return the name of the provider hint associated with this preference. + * @deprecated this information is now useless with support of a single location for storing preferences + */ + @Deprecated(since = "16.5.0RC1") + default String getProviderHint() + { + return ""; + } +} diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/NotificationFilterPreferenceProvider.java b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-filters/xwiki-platform-legacy-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/NotificationFilterPreferenceProvider.java similarity index 96% rename from xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/NotificationFilterPreferenceProvider.java rename to xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-filters/xwiki-platform-legacy-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/NotificationFilterPreferenceProvider.java index b374ceed51b..51b014a7561 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/NotificationFilterPreferenceProvider.java +++ b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-filters/xwiki-platform-legacy-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/NotificationFilterPreferenceProvider.java @@ -34,8 +34,10 @@ * * @version $Id$ * @since 9.8RC1 + * @deprecated this interface is not used anywhere anymore in XWiki Standard. */ @Role +@Deprecated(since = "16.5.0RC1") public interface NotificationFilterPreferenceProvider { /** @@ -73,7 +75,7 @@ default Set<NotificationFilterPreference> getFilterPreferences(WikiReference wik * @since 9.11.9 */ void saveFilterPreferences(DocumentReference user, Set<NotificationFilterPreference> filterPreferences) - throws NotificationException; + throws NotificationException; /** * Delete a filter preference. @@ -129,7 +131,7 @@ default void deleteFilterPreference(WikiReference wikiReference, String filterPr * @since 9.11.9 */ void setFilterPreferenceEnabled(DocumentReference user, String filterPreferenceId, boolean enabled) - throws NotificationException; + throws NotificationException; /** * Enable or disable a filter preference. @@ -158,4 +160,4 @@ default void setFilterPreferenceEnabled(WikiReference wikiReference, String filt * @since 9.11.5 */ void setStartDateForUser(DocumentReference user, Date startDate) throws NotificationException; -} +} \ No newline at end of file diff --git a/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-sources/src/test/java/org/xwiki/notifications/sources/internal/LegacyDefaultNotificationParametersFactoryTest.java b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-sources/src/test/java/org/xwiki/notifications/sources/internal/LegacyDefaultNotificationParametersFactoryTest.java index 85d9f6b55d3..7617d8b5de5 100644 --- a/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-sources/src/test/java/org/xwiki/notifications/sources/internal/LegacyDefaultNotificationParametersFactoryTest.java +++ b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-notifications/xwiki-platform-legacy-notifications-sources/src/test/java/org/xwiki/notifications/sources/internal/LegacyDefaultNotificationParametersFactoryTest.java @@ -368,7 +368,6 @@ private DefaultNotificationFilterPreference getFilterPreference(String property, filterPreference.setFilterName(ScopeNotificationFilter.FILTER_NAME); filterPreference.setFilterType(NotificationFilterType.INCLUSIVE); filterPreference.setNotificationFormats(Collections.singleton(NotificationFormat.ALERT)); - filterPreference.setProviderHint("FACTORY"); return filterPreference; } } diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/pom.xml b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/pom.xml index 4b0436bd171..6ed1072e2aa 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/pom.xml +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/pom.xml @@ -35,6 +35,8 @@ <!-- Name to display by the Extension Manager --> <xwiki.extension.name>Notifications Filters API</xwiki.extension.name> <checkstyle.suppressions.location>${basedir}/src/checkstyle/checkstyle-suppressions.xml</checkstyle.suppressions.location> + <!-- Skip revapi since it's handled by the legacy module --> + <xwiki.revapi.skip>true</xwiki.revapi.skip> </properties> <dependencies> <dependency> diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/NotificationFilterPreference.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/NotificationFilterPreference.java index ca191db0abc..ddba1eb1194 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/NotificationFilterPreference.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/NotificationFilterPreference.java @@ -26,6 +26,7 @@ import org.apache.commons.lang3.StringUtils; import org.xwiki.notifications.NotificationFormat; +import org.xwiki.stability.Unstable; import static com.xpn.xwiki.doc.XWikiDocument.DB_SPACE_SEP; @@ -47,6 +48,13 @@ */ public interface NotificationFilterPreference { + /** + * Prefix to be used for the ID only when the preference is stored in database. + * @since 16.5.0RC1 + */ + @Unstable + String DB_ID_FILTER_PREFIX = "NFP_"; + /** * @return the unique identifier of the filter preference. * @since 10.8RC1 @@ -59,11 +67,6 @@ public interface NotificationFilterPreference */ String getFilterName(); - /** - * @return the name of the {@link NotificationFilterPreferenceProvider} associated with this preference. - */ - String getProviderHint(); - /** * @return true if the current notification preference is enabled. */ diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/NotificationFilterPreferenceManager.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/NotificationFilterPreferenceManager.java index 048dc872a31..7a44c9ae721 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/NotificationFilterPreferenceManager.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/NotificationFilterPreferenceManager.java @@ -105,7 +105,8 @@ Stream<NotificationFilterPreference> getFilterPreferences( * @since 10.8.3 * @since 9.11.9 */ - void saveFilterPreferences(DocumentReference user, Set<NotificationFilterPreference> notificationFilterPreferences); + void saveFilterPreferences(DocumentReference user, Set<NotificationFilterPreference> notificationFilterPreferences) + throws NotificationException; /** * Delete a filter preference. diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/internal/DefaultNotificationFilterPreferenceManager.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/internal/DefaultNotificationFilterPreferenceManager.java index b2d02ca16b3..30180415f45 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/internal/DefaultNotificationFilterPreferenceManager.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/internal/DefaultNotificationFilterPreferenceManager.java @@ -19,25 +19,16 @@ */ package org.xwiki.notifications.filters.internal; -import java.util.ArrayList; import java.util.Collection; import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.inject.Inject; +import javax.inject.Named; import javax.inject.Singleton; -import org.apache.commons.lang3.exception.ExceptionUtils; -import org.slf4j.Logger; import org.xwiki.component.annotation.Component; -import org.xwiki.component.manager.ComponentLookupException; -import org.xwiki.component.manager.ComponentManager; import org.xwiki.model.reference.DocumentReference; import org.xwiki.model.reference.WikiReference; import org.xwiki.notifications.NotificationException; @@ -45,11 +36,10 @@ import org.xwiki.notifications.filters.NotificationFilter; import org.xwiki.notifications.filters.NotificationFilterPreference; import org.xwiki.notifications.filters.NotificationFilterPreferenceManager; -import org.xwiki.notifications.filters.NotificationFilterPreferenceProvider; import org.xwiki.notifications.filters.NotificationFilterType; /** - * Default implementation of {@link NotificationFilterPreferenceManager}. + * Default implementation of the role {@link NotificationFilterPreferenceManager}. * * @version $Id$ * @since 10.9 @@ -58,227 +48,94 @@ @Singleton public class DefaultNotificationFilterPreferenceManager implements NotificationFilterPreferenceManager { - @Inject - private ComponentManager componentManager; @Inject - private Logger logger; - - @FunctionalInterface - interface ProviderCallable - { - void doInProvider(NotificationFilterPreferenceProvider provider) throws NotificationException; - } - - @FunctionalInterface - interface RetrieveWithProviderCallable<E> - { - Collection<E> retrieveWithProvider(NotificationFilterPreferenceProvider provider) - throws NotificationException; - } - - private List<NotificationFilterPreferenceProvider> getProviderList() throws NotificationException - { - try { - return componentManager.getInstanceList(NotificationFilterPreferenceProvider.class); - } catch (ComponentLookupException e) { - throw new NotificationException("Error when trying to load the list of providers", e); - } - } - - private String getProviderDebugMessage(String loggerMessage, NotificationFilterPreferenceProvider provider) - { - return String.format("%s with provider %s", loggerMessage, provider); - } - - private String getExceptionMessage(String loggerMessage, List<NotificationException> exceptions) - { - return String.format("%s - All providers called failed, see exceptions: [%s].", - loggerMessage, - exceptions.stream().map(ExceptionUtils::getRootCauseMessage).collect(Collectors.joining(","))); - } - - private void providerExceptionWrapper(ProviderCallable callable, String loggerMessage) throws NotificationException - { - boolean allFailing = true; - List<NotificationException> exceptions = new ArrayList<>(); - List<NotificationFilterPreferenceProvider> providerList = getProviderList(); - if (providerList.size() > 1) { - for (NotificationFilterPreferenceProvider provider : providerList) { - try { - callable.doInProvider(provider); - allFailing = false; - } catch (NotificationException e) { - this.logger.debug(getProviderDebugMessage(loggerMessage, provider), e); - exceptions.add(e); - } - } - if (allFailing) { - throw new NotificationException(getExceptionMessage(loggerMessage, exceptions)); - } - } else { - callable.doInProvider(providerList.get(0)); - } - } - - private <E> Collection<E> retrieveWithProviderExceptionWrapper(RetrieveWithProviderCallable<E> callable, - String loggerMessage) throws NotificationException - { - boolean allFailing = true; - List<NotificationException> exceptions = new ArrayList<>(); - Set<E> result = new HashSet<>(); - List<NotificationFilterPreferenceProvider> providerList = getProviderList(); - if (providerList.size() > 1) { - for (NotificationFilterPreferenceProvider provider : getProviderList()) { - try { - result.addAll(callable.retrieveWithProvider(provider)); - allFailing = false; - } catch (NotificationException e) { - this.logger.debug(getProviderDebugMessage(loggerMessage, provider), e); - exceptions.add(e); - } - } - if (allFailing) { - throw new NotificationException(getExceptionMessage(loggerMessage, exceptions)); - } - } else { - result.addAll(callable.retrieveWithProvider(providerList.get(0))); - } - return result; - } + @Named("cached") + private FilterPreferencesModelBridge filterPreferencesModelBridge; @Override - public Collection<NotificationFilterPreference> getFilterPreferences(DocumentReference user) - throws NotificationException + public Set<NotificationFilterPreference> getFilterPreferences(DocumentReference user) throws NotificationException { - return this.retrieveWithProviderExceptionWrapper(provider -> provider.getFilterPreferences(user), - String.format("Error when trying to get filter preferences for user [%s]", user)); + + return this.filterPreferencesModelBridge.getFilterPreferences(user); } @Override - public Collection<NotificationFilterPreference> getFilterPreferences(WikiReference wikiReference) + public Set<NotificationFilterPreference> getFilterPreferences(WikiReference wikiReference) throws NotificationException { - return this.retrieveWithProviderExceptionWrapper(provider -> provider.getFilterPreferences(wikiReference), - String.format("Error when trying to get filter preferences for wiki [%s]", wikiReference)); + return this.filterPreferencesModelBridge.getFilterPreferences(wikiReference); } @Override public Stream<NotificationFilterPreference> getFilterPreferences( - Collection<NotificationFilterPreference> filterPreferences, NotificationFilter filter) + Collection<NotificationFilterPreference> filterPreferences, NotificationFilter filter) { return filterPreferences.stream().filter(preference -> filter.getName().equals(preference.getFilterName())); } @Override public Stream<NotificationFilterPreference> getFilterPreferences( - Collection<NotificationFilterPreference> filterPreferences, NotificationFilter filter, - NotificationFilterType filterType) + Collection<NotificationFilterPreference> filterPreferences, NotificationFilter filter, + NotificationFilterType filterType) { - return getFilterPreferences(filterPreferences, filter).filter( - preference -> preference.getFilterType() == filterType); + return getFilterPreferences(filterPreferences, filter) + .filter(preference -> preference.getFilterType() == filterType); } @Override public Stream<NotificationFilterPreference> getFilterPreferences( - Collection<NotificationFilterPreference> filterPreferences, NotificationFilter filter, - NotificationFilterType filterType, NotificationFormat format) + Collection<NotificationFilterPreference> filterPreferences, NotificationFilter filter, + NotificationFilterType filterType, NotificationFormat format) { - return getFilterPreferences(filterPreferences, filter, filterType).filter( - preference -> preference.getNotificationFormats().contains(format)); + return getFilterPreferences(filterPreferences, filter, filterType) + .filter(preference -> preference.getNotificationFormats().contains(format)); } @Override public void saveFilterPreferences(DocumentReference user, Set<NotificationFilterPreference> filterPreferences) + throws NotificationException { - Map<String, Set<NotificationFilterPreference>> preferencesMapping = new HashMap<>(); - - for (NotificationFilterPreference filterPreference : filterPreferences) { - // Try to get the corresponding provider, if no provider can be found, discard the save of the preference - String providerHint = filterPreference.getProviderHint(); - if (componentManager.hasComponent(NotificationFilterPreferenceProvider.class, providerHint)) { - if (!preferencesMapping.containsKey(providerHint)) { - preferencesMapping.put(providerHint, new HashSet<>()); - } - - preferencesMapping.get(providerHint).add(filterPreference); - } - } - - // Once we have created the mapping, save all the preferences using their correct providers - for (String providerHint : preferencesMapping.keySet()) { - try { - NotificationFilterPreferenceProvider provider = - componentManager.getInstance(NotificationFilterPreferenceProvider.class, providerHint); - - provider.saveFilterPreferences(user, preferencesMapping.get(providerHint)); - - } catch (ComponentLookupException e) { - logger.error("Unable to retrieve the notification filter preference provider for hint [{}]:", - providerHint, e); - } catch (NotificationException e) { - logger.warn("Unable save the filter preferences [{}] against the provider [{}]: [{}]", - preferencesMapping.get(providerHint), providerHint, ExceptionUtils.getRootCauseMessage(e)); - } - } + this.filterPreferencesModelBridge.saveFilterPreferences(user, filterPreferences); } @Override public void deleteFilterPreference(DocumentReference user, String filterPreferenceId) throws NotificationException { - deleteFilterPreferences(user, Set.of(filterPreferenceId)); + this.filterPreferencesModelBridge.deleteFilterPreference(user, filterPreferenceId); } @Override public void deleteFilterPreferences(DocumentReference user, Set<String> filterPreferenceIds) throws NotificationException { - this.providerExceptionWrapper(provider -> provider.deleteFilterPreferences(user, filterPreferenceIds), - String.format("Error when trying to remove filter preferences %s for user [%s]", filterPreferenceIds, - user)); + this.filterPreferencesModelBridge.deleteFilterPreferences(user, filterPreferenceIds); } @Override public void deleteFilterPreference(WikiReference wikiReference, String filterPreferenceId) throws NotificationException { - this.providerExceptionWrapper(provider -> provider.deleteFilterPreference(wikiReference, filterPreferenceId), - String.format("Error when trying to remove filter preference [%s] for wiki [%s]", filterPreferenceId, - wikiReference)); + this.filterPreferencesModelBridge.deleteFilterPreference(wikiReference, filterPreferenceId); } - @Override public void setFilterPreferenceEnabled(DocumentReference user, String filterPreferenceId, boolean enabled) - throws NotificationException + throws NotificationException { - this.providerExceptionWrapper(provider -> - provider.setFilterPreferenceEnabled(user, filterPreferenceId, enabled), - String.format("Error when trying to set filter preference [%s] enabled to [%s] for user [%s]", - enabled, - filterPreferenceId, - user)); + this.filterPreferencesModelBridge.setFilterPreferenceEnabled(user, filterPreferenceId, enabled); } @Override public void setFilterPreferenceEnabled(WikiReference wikiReference, String filterPreferenceId, boolean enabled) throws NotificationException { - this.providerExceptionWrapper(provider -> - provider.setFilterPreferenceEnabled(wikiReference, filterPreferenceId, enabled), - String.format("Error when trying to set filter preference [%s] enabled to [%s] for wiki [%s]", - enabled, - filterPreferenceId, - wikiReference)); + this.filterPreferencesModelBridge.setFilterPreferenceEnabled(wikiReference, filterPreferenceId, enabled); } @Override public void setStartDateForUser(DocumentReference user, Date startDate) throws NotificationException { - this.providerExceptionWrapper(provider -> - provider.setStartDateForUser(user, startDate), - String.format("Error when trying to set start date to [%s] for user [%s]", - startDate, - user)); + this.filterPreferencesModelBridge.setStartDateForUser(user, startDate); } } diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/internal/UserProfileNotificationFilterPreferenceProvider.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/internal/UserProfileNotificationFilterPreferenceProvider.java deleted file mode 100644 index 8739d5a8a26..00000000000 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/internal/UserProfileNotificationFilterPreferenceProvider.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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.Date; -import java.util.Set; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.xwiki.component.annotation.Component; -import org.xwiki.model.reference.DocumentReference; -import org.xwiki.model.reference.WikiReference; -import org.xwiki.notifications.NotificationException; -import org.xwiki.notifications.filters.NotificationFilterPreference; -import org.xwiki.notifications.filters.NotificationFilterPreferenceProvider; - -/** - * This is the default implementation of the role {@link NotificationFilterPreferenceProvider}. It allows retrieving - * filter preferences from the user XObjects. - * - * @version $Id$ - * @since 9.8RC1 - */ -@Component -@Named(UserProfileNotificationFilterPreferenceProvider.HINT) -@Singleton -public class UserProfileNotificationFilterPreferenceProvider implements NotificationFilterPreferenceProvider -{ - /** - * Hint for this provider. - */ - public static final String HINT = "userProfile"; - - @Inject - @Named("cached") - private FilterPreferencesModelBridge filterPreferencesModelBridge; - - @Override - public Set<NotificationFilterPreference> getFilterPreferences(DocumentReference user) throws NotificationException - { - return this.filterPreferencesModelBridge.getFilterPreferences(user); - } - - @Override - public Set<NotificationFilterPreference> getFilterPreferences(WikiReference wikiReference) - throws NotificationException - { - return this.filterPreferencesModelBridge.getFilterPreferences(wikiReference); - } - - @Override - public void saveFilterPreferences(DocumentReference user, Set<NotificationFilterPreference> filterPreferences) - throws NotificationException - { - this.filterPreferencesModelBridge.saveFilterPreferences(user, filterPreferences); - } - - @Override - public void deleteFilterPreference(DocumentReference user, String filterPreferenceId) throws NotificationException - { - this.filterPreferencesModelBridge.deleteFilterPreference(user, filterPreferenceId); - } - - @Override - public void deleteFilterPreferences(DocumentReference user, Set<String> filterPreferenceIds) - throws NotificationException - { - this.filterPreferencesModelBridge.deleteFilterPreferences(user, filterPreferenceIds); - } - - @Override - public void deleteFilterPreference(WikiReference wikiReference, String filterPreferenceId) - throws NotificationException - { - this.filterPreferencesModelBridge.deleteFilterPreference(wikiReference, filterPreferenceId); - } - - @Override - public void setFilterPreferenceEnabled(DocumentReference user, String filterPreferenceId, boolean enabled) - throws NotificationException - { - this.filterPreferencesModelBridge.setFilterPreferenceEnabled(user, filterPreferenceId, enabled); - } - - @Override - public void setFilterPreferenceEnabled(WikiReference wikiReference, String filterPreferenceId, boolean enabled) - throws NotificationException - { - this.filterPreferencesModelBridge.setFilterPreferenceEnabled(wikiReference, filterPreferenceId, enabled); - } - - @Override - public void setStartDateForUser(DocumentReference user, Date startDate) throws NotificationException - { - this.filterPreferencesModelBridge.setStartDateForUser(user, startDate); - } -} diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/internal/scope/ScopeNotificationFilterExpressionGenerator.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/internal/scope/ScopeNotificationFilterExpressionGenerator.java index ef5bb2025df..0a5575d2f52 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/internal/scope/ScopeNotificationFilterExpressionGenerator.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/internal/scope/ScopeNotificationFilterExpressionGenerator.java @@ -28,6 +28,7 @@ import javax.inject.Inject; import javax.inject.Singleton; +import org.apache.commons.lang3.StringUtils; import org.xwiki.component.annotation.Component; import org.xwiki.model.reference.DocumentReference; import org.xwiki.model.reference.EntityReferenceSerializer; @@ -39,8 +40,6 @@ import org.xwiki.notifications.filters.expression.generics.AbstractOperatorNode; import org.xwiki.notifications.filters.expression.generics.AbstractValueNode; import org.xwiki.notifications.filters.internal.LocationOperatorNodeGenerator; -import org.xwiki.notifications.filters.internal.UserProfileNotificationFilterPreferenceProvider; -import org.xwiki.text.StringUtils; import static org.xwiki.notifications.filters.expression.generics.ExpressionBuilder.not; import static org.xwiki.notifications.filters.expression.generics.ExpressionBuilder.value; @@ -204,7 +203,6 @@ private boolean isPageOnly(ScopeNotificationFilterPreference pref) // filterExpression(Collection<NotificationFilterPreference> filterPreferences, NotificationFormat format, // NotificationFilterType type, DocumentReference user). return StringUtils.isNotBlank(pref.getPageOnly()) - && UserProfileNotificationFilterPreferenceProvider.HINT.equals(pref.getProviderHint()) && pref.getEventTypes().isEmpty(); } @@ -288,17 +286,16 @@ public AbstractOperatorNode filterExpression(Collection<NotificationFilterPrefer private Predicate<NotificationFilterPreference> isAPageOnlyFilterPreferenceThatConcernAllEvents( NotificationFormat format, NotificationFilterType type) { - return nfp -> isEnabledScopeNotificationFilterPreference(nfp) + return nfp -> isEnabledAndStoredScopeNotificationFilterPreference(nfp) && doesFilterTypeAndFormatMatch(nfp, format, type) && StringUtils.isNotBlank(nfp.getPageOnly()); } - private boolean isEnabledScopeNotificationFilterPreference(NotificationFilterPreference nfp) + private boolean isEnabledAndStoredScopeNotificationFilterPreference(NotificationFilterPreference nfp) { - // This optimization can only works on preferences stored by the user, that's why we add a condition - // on the provider hint. + // This optimization can only works on preferences stored by the user, that's why we add the final condition return nfp.isEnabled() && ScopeNotificationFilter.FILTER_NAME.equals(nfp.getFilterName()) - && UserProfileNotificationFilterPreferenceProvider.HINT.equals(nfp.getProviderHint()); + && StringUtils.startsWith(nfp.getId(), NotificationFilterPreference.DB_ID_FILTER_PREFIX); } private boolean doesFilterTypeAndFormatMatch(NotificationFilterPreference nfp, NotificationFormat format, diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/internal/scope/ScopeNotificationFilterPreference.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/internal/scope/ScopeNotificationFilterPreference.java index 1faab1d6be8..87423defd65 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/internal/scope/ScopeNotificationFilterPreference.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/java/org/xwiki/notifications/filters/internal/scope/ScopeNotificationFilterPreference.java @@ -146,12 +146,6 @@ public String getFilterName() return filterPreference.getFilterName(); } - @Override - public String getProviderHint() - { - return filterPreference.getProviderHint(); - } - @Override public boolean isEnabled() { diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/resources/META-INF/components.txt b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/resources/META-INF/components.txt index 84fa677bd07..093bc7f4545 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/resources/META-INF/components.txt +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/main/resources/META-INF/components.txt @@ -17,7 +17,6 @@ org.xwiki.notifications.filters.internal.DeletedDocumentCleanUpFilterListener org.xwiki.notifications.filters.internal.DeletedDocumentCleanUpFilterProcessingQueue org.xwiki.notifications.filters.internal.LocationOperatorNodeGenerator org.xwiki.notifications.filters.internal.SystemUserNotificationFilter -org.xwiki.notifications.filters.internal.UserProfileNotificationFilterPreferenceProvider org.xwiki.notifications.filters.internal.listener.DeletedWikiEventListener org.xwiki.notifications.filters.internal.listener.DeleteUserEventListener org.xwiki.notifications.filters.script.NotificationFiltersScriptService diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/test/java/org/xwiki/notifications/filters/internal/DefaultNotificationFilterPreferenceManagerTest.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/test/java/org/xwiki/notifications/filters/internal/DefaultNotificationFilterPreferenceManagerTest.java index c35b98b6202..e4dee496c1d 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/test/java/org/xwiki/notifications/filters/internal/DefaultNotificationFilterPreferenceManagerTest.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/test/java/org/xwiki/notifications/filters/internal/DefaultNotificationFilterPreferenceManagerTest.java @@ -24,29 +24,24 @@ import java.util.Set; import java.util.stream.Collectors; +import javax.inject.Named; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.internal.util.collections.Sets; import org.xwiki.model.reference.DocumentReference; import org.xwiki.model.reference.WikiReference; -import org.xwiki.notifications.NotificationException; import org.xwiki.notifications.filters.NotificationFilter; import org.xwiki.notifications.filters.NotificationFilterPreference; -import org.xwiki.notifications.filters.NotificationFilterPreferenceProvider; import org.xwiki.notifications.filters.NotificationFilterType; import org.xwiki.test.junit5.mockito.ComponentTest; -import org.xwiki.test.junit5.mockito.InjectComponentManager; import org.xwiki.test.junit5.mockito.InjectMockComponents; import org.xwiki.test.junit5.mockito.MockComponent; -import org.xwiki.test.mockito.MockitoComponentManager; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -62,13 +57,11 @@ public class DefaultNotificationFilterPreferenceManagerTest @InjectMockComponents private DefaultNotificationFilterPreferenceManager filterPreferenceManager; - private DocumentReference testUser; - @MockComponent - private NotificationFilterPreferenceProvider testProvider; + @Named("cached") + private FilterPreferencesModelBridge filterPreferencesModelBridge; - @InjectComponentManager - private MockitoComponentManager componentManager; + private DocumentReference testUser; @BeforeEach public void setUp() throws Exception @@ -82,7 +75,8 @@ void filterPreferences() throws Exception NotificationFilterPreference filterPreference1 = mock(NotificationFilterPreference.class); NotificationFilterPreference filterPreference2 = mock(NotificationFilterPreference.class); - when(testProvider.getFilterPreferences(testUser)).thenReturn(Sets.newSet(filterPreference1, filterPreference2)); + when(filterPreferencesModelBridge.getFilterPreferences(testUser)) + .thenReturn(Sets.newSet(filterPreference1, filterPreference2)); Collection<NotificationFilterPreference> resultSet = filterPreferenceManager.getFilterPreferences(testUser); @@ -146,44 +140,7 @@ void filterPreferencesWithFilterAndFilterType() throws Exception void deleteFilterPreference() throws Exception { filterPreferenceManager.deleteFilterPreference(testUser, "myFilter"); - - verify(testProvider).deleteFilterPreferences(testUser, Set.of("myFilter")); - } - - @Test - void deleteFilterPreferenceProviderException() throws Exception - { - String providerName1 = "providerName1"; - String providerName2 = "providerName2"; - - NotificationFilterPreferenceProvider provider1 = - componentManager.registerMockComponent(NotificationFilterPreferenceProvider.class, providerName1); - NotificationFilterPreferenceProvider provider2 = - componentManager.registerMockComponent(NotificationFilterPreferenceProvider.class, providerName2); - - String filterId = "filterId"; - doThrow(new NotificationException("error provider1")).when(provider1).deleteFilterPreferences(testUser, - Set.of(filterId)); - filterPreferenceManager.deleteFilterPreference(testUser, filterId); - verify(testProvider).deleteFilterPreferences(testUser, Set.of(filterId)); - verify(provider1).deleteFilterPreferences(testUser, Set.of(filterId)); - verify(provider2).deleteFilterPreferences(testUser, Set.of(filterId)); - - doThrow(new NotificationException("error provider2")).when(provider2).deleteFilterPreferences(testUser, - Set.of(filterId)); - filterPreferenceManager.deleteFilterPreference(testUser, filterId); - verify(testProvider, times(2)).deleteFilterPreferences(testUser, Set.of(filterId)); - verify(provider1, times(2)).deleteFilterPreferences(testUser, Set.of(filterId)); - verify(provider2, times(2)).deleteFilterPreferences(testUser, Set.of(filterId)); - - doThrow(new NotificationException("error testprovider")).when(testProvider).deleteFilterPreferences(testUser, - Set.of(filterId)); - NotificationException notificationException = assertThrows(NotificationException.class, - () -> filterPreferenceManager.deleteFilterPreference(testUser, filterId)); - assertEquals("Error when trying to remove filter preferences [filterId] for user [wiki:test.user] - " - + "All providers called failed, see exceptions: [NotificationException: error testprovider," - + "NotificationException: error provider1,NotificationException: error provider2].", - notificationException.getMessage()); + verify(filterPreferencesModelBridge).deleteFilterPreference(testUser, "myFilter"); } @Test @@ -194,20 +151,15 @@ void setFilterPreferenceEnabled() throws Exception filterPreferenceManager.setFilterPreferenceEnabled(new WikiReference("foo"), "myFilter3", true); filterPreferenceManager.setFilterPreferenceEnabled(new WikiReference("foo"), "myFilter4", false); - verify(testProvider).setFilterPreferenceEnabled(testUser, "myFilter1", true); - verify(testProvider).setFilterPreferenceEnabled(testUser, "myFilter2", false); - verify(testProvider).setFilterPreferenceEnabled(new WikiReference("foo"), "myFilter3", true); - verify(testProvider).setFilterPreferenceEnabled(new WikiReference("foo"), "myFilter4", false); + verify(filterPreferencesModelBridge).setFilterPreferenceEnabled(testUser, "myFilter1", true); + verify(filterPreferencesModelBridge).setFilterPreferenceEnabled(testUser, "myFilter2", false); + verify(filterPreferencesModelBridge).setFilterPreferenceEnabled(new WikiReference("foo"), "myFilter3", true); + verify(filterPreferencesModelBridge).setFilterPreferenceEnabled(new WikiReference("foo"), "myFilter4", false); } @Test void setStartDateForUser() throws Exception { - NotificationFilterPreferenceProvider provider1 = - componentManager.registerMockComponent(NotificationFilterPreferenceProvider.class, "provider1"); - NotificationFilterPreferenceProvider provider2 = - componentManager.registerMockComponent(NotificationFilterPreferenceProvider.class, "provider2"); - DocumentReference user = new DocumentReference("xwiki", "XWiki", "User"); Date date = new Date(); @@ -215,8 +167,7 @@ void setStartDateForUser() throws Exception filterPreferenceManager.setStartDateForUser(user, date); // Checks - verify(provider1).setStartDateForUser(eq(user), eq(date)); - verify(provider2).setStartDateForUser(eq(user), eq(date)); + verify(filterPreferencesModelBridge).setStartDateForUser(eq(user), eq(date)); } @Test @@ -227,20 +178,7 @@ void saveFilterPreferences() throws Exception NotificationFilterPreference pref2 = mock(NotificationFilterPreference.class, "pref2"); NotificationFilterPreference pref3 = mock(NotificationFilterPreference.class, "pref3"); - String providerName1 = "providerName1"; - String providerName2 = "providerName2"; - - NotificationFilterPreferenceProvider provider1 = - componentManager.registerMockComponent(NotificationFilterPreferenceProvider.class, providerName1); - NotificationFilterPreferenceProvider provider2 = - componentManager.registerMockComponent(NotificationFilterPreferenceProvider.class, providerName2); - - when(pref1.getProviderHint()).thenReturn(providerName1); - when(pref2.getProviderHint()).thenReturn(providerName2); - when(pref3.getProviderHint()).thenReturn(providerName1); - this.filterPreferenceManager.saveFilterPreferences(user, Set.of(pref1, pref2, pref3)); - verify(provider1).saveFilterPreferences(user, Set.of(pref1, pref3)); - verify(provider2).saveFilterPreferences(user, Set.of(pref2)); + verify(filterPreferencesModelBridge).saveFilterPreferences(user, Set.of(pref1, pref2, pref3)); } } diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/test/java/org/xwiki/notifications/filters/internal/scope/ScopeNotificationFilterTest.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/test/java/org/xwiki/notifications/filters/internal/scope/ScopeNotificationFilterTest.java index 9c47e0cc11c..4c9d63be0c8 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/test/java/org/xwiki/notifications/filters/internal/scope/ScopeNotificationFilterTest.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-api/src/test/java/org/xwiki/notifications/filters/internal/scope/ScopeNotificationFilterTest.java @@ -95,6 +95,7 @@ private NotificationFilterPreference mockNotificationFilterPreference(String ent EntityReference resultReference, NotificationFilterType filterType, String eventName) { NotificationFilterPreference preference = mock(NotificationFilterPreference.class); + when(preference.getId()).thenReturn("NFP_343"); if (resultReference.getType() == EntityType.SPACE) { when(preference.getPage()).thenReturn(entityStringValue); } @@ -117,8 +118,6 @@ private NotificationFilterPreference mockNotificationFilterPreference(String ent when(serializer.serialize(eq(resultReference))).thenReturn(entityStringValue); - when(preference.getProviderHint()).thenReturn("userProfile"); - when(preference.getStartingDate()).thenReturn(new Date(0)); return preference; @@ -268,7 +267,6 @@ void withTopLevelInclusiveFilters() throws Exception DocumentReference documentReference = new DocumentReference("wikiA", "SpaceM", "DocumentN"); NotificationFilterPreference prefζ = mockNotificationFilterPreference("wikiA:SpaceM.DocumentN", documentReference, NotificationFilterType.INCLUSIVE, null); - when(prefζ.getProviderHint()).thenReturn("userProfile"); when(prefζ.getStartingDate()).thenReturn(new Date(99000)); Collection<NotificationFilterPreference> filterPreferences = Sets.newSet(prefγ, prefζ); @@ -408,7 +406,6 @@ void targetableEvent() DocumentReference documentReference = new DocumentReference("wikiA", "SpaceM", "DocumentN"); NotificationFilterPreference prefζ = mockNotificationFilterPreference("wikiA:SpaceM.DocumentN", documentReference, NotificationFilterType.EXCLUSIVE, null); - when(prefζ.getProviderHint()).thenReturn("userProfile"); Collection<NotificationFilterPreference> filterPreferences = Sets.newSet(prefγ, prefζ); diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/internal/DefaultNotificationFilterPreference.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/internal/DefaultNotificationFilterPreference.java index 83cdda8077f..2333966fef0 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/internal/DefaultNotificationFilterPreference.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/internal/DefaultNotificationFilterPreference.java @@ -49,8 +49,6 @@ public class DefaultNotificationFilterPreference implements NotificationFilterPr private String filterName; - private String providerHint; - private boolean enabled; private boolean active; @@ -105,7 +103,6 @@ public DefaultNotificationFilterPreference(NotificationFilterPreference notifica this.id = notificationFilterPreference.getId(); this.filterName = notificationFilterPreference.getFilterName(); - this.providerHint = notificationFilterPreference.getProviderHint(); this.enabled = notificationFilterPreference.isEnabled(); this.active = notificationFilterPreference.isActive(); this.filterType = notificationFilterPreference.getFilterType(); @@ -142,7 +139,7 @@ public long getInternalId() public void setInternalId(long internalId) { this.internalId = internalId; - this.id = String.format("NFP_%d", internalId); + this.id = String.format("%s%d", DB_ID_FILTER_PREFIX, internalId); } /** @@ -169,14 +166,6 @@ public void setFilterName(String filterName) this.filterName = filterName; } - /** - * @param providerHint the name of the provider that have built this preference - */ - public void setProviderHint(String providerHint) - { - this.providerHint = providerHint; - } - /** * @param enabled if the preference is enabled or not */ @@ -280,12 +269,6 @@ public String getFilterName() return filterName; } - @Override - public String getProviderHint() - { - return providerHint; - } - @Override public boolean isEnabled() { @@ -429,7 +412,6 @@ public String toString() + ", internalId=" + internalId + ", owner='" + owner + '\'' + ", filterName='" + filterName + '\'' - + ", providerHint='" + providerHint + '\'' + ", enabled=" + enabled + ", active=" + active + ", filterType=" + filterType @@ -462,7 +444,6 @@ public boolean equals(Object o) .append(id, other.id) .append(owner, other.owner) .append(filterName, other.filterName) - .append(providerHint, other.providerHint) .append(filterType, other.filterType) .append(notificationFormats, other.notificationFormats) .append(startingDate, other.startingDate) @@ -484,7 +465,6 @@ public int hashCode() .append(id) .append(owner) .append(filterName) - .append(providerHint) .append(filterType) .append(notificationFormats) .append(startingDate) diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/internal/NotificationFilterPreferenceStore.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/internal/NotificationFilterPreferenceStore.java index 65877d9e7e9..78d37bbd7f9 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/internal/NotificationFilterPreferenceStore.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/internal/NotificationFilterPreferenceStore.java @@ -42,8 +42,6 @@ import org.xwiki.notifications.filters.NotificationFilterPreference; import org.xwiki.notifications.filters.internal.event.NotificationFilterPreferenceAddOrUpdatedEvent; import org.xwiki.notifications.filters.internal.event.NotificationFilterPreferenceDeletedEvent; -import org.xwiki.notifications.preferences.internal.UserProfileNotificationPreferenceProvider; -import org.xwiki.notifications.preferences.internal.WikiNotificationPreferenceProvider; import org.xwiki.observation.ObservationManager; import org.xwiki.query.Query; import org.xwiki.query.QueryException; @@ -64,7 +62,6 @@ @Singleton public class NotificationFilterPreferenceStore { - private static final String FILTER_PREFIX = "NFP_"; private static final String ID = "id"; @Inject @@ -167,7 +164,7 @@ public List<DefaultNotificationFilterPreference> getPreferencesOfUser(DocumentRe throws NotificationException { try { - return this.getPreferencesOfEntity(user, UserProfileNotificationPreferenceProvider.NAME); + return this.getPreferencesOfEntity(user); } catch (QueryException e) { throw new NotificationException(String.format( "Error while loading the notification filter preferences of the user [%s].", user.toString()), e); @@ -186,7 +183,7 @@ public List<DefaultNotificationFilterPreference> getPreferencesOfWiki(WikiRefere throws NotificationException { try { - return getPreferencesOfEntity(wikiReference, WikiNotificationPreferenceProvider.NAME); + return getPreferencesOfEntity(wikiReference); } catch (QueryException e) { throw new NotificationException( String.format("Error while loading the notification filter preferences of the wiki [%s].", @@ -224,8 +221,8 @@ public Set<DefaultNotificationFilterPreference> getPaginatedFilterPreferences(in }); } - private List<DefaultNotificationFilterPreference> getPreferencesOfEntity(EntityReference entityReference, - String providerHint) throws QueryException + private List<DefaultNotificationFilterPreference> getPreferencesOfEntity(EntityReference entityReference) + throws QueryException { if (entityReference == null) { return Collections.emptyList(); @@ -239,13 +236,7 @@ private List<DefaultNotificationFilterPreference> getPreferencesOfEntity(EntityR Query.HQL); query.bindValue("owner", serializedEntity); - List<DefaultNotificationFilterPreference> results = query.execute(); - - for (DefaultNotificationFilterPreference preference : results) { - preference.setProviderHint(providerHint); - } - - return results; + return query.execute(); }); } @@ -335,8 +326,9 @@ public void deleteFilterPreference(WikiReference wikiReference, String filterPre private long getInternalIdFromId(String filterPreferenceId) throws NotificationException { - if (StringUtils.startsWith(filterPreferenceId, FILTER_PREFIX)) { - return Long.parseLong(filterPreferenceId.substring(FILTER_PREFIX.length())); + if (StringUtils.startsWith(filterPreferenceId, NotificationFilterPreference.DB_ID_FILTER_PREFIX)) { + return Long.parseLong( + filterPreferenceId.substring(NotificationFilterPreference.DB_ID_FILTER_PREFIX.length())); } else { throw new NotificationException(String.format("Cannot guess internal id of preference with id [%s].", filterPreferenceId)); diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/internal/UserAddedEventListener.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/internal/UserAddedEventListener.java index 4cf7cd60559..c248aaddb05 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/internal/UserAddedEventListener.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/internal/UserAddedEventListener.java @@ -113,7 +113,6 @@ private void copyFilterPreferences(DocumentReference userDocReference) throws No for (NotificationFilterPreference filterPreference : filterPreferences) { DefaultNotificationFilterPreference preference = new DefaultNotificationFilterPreference(filterPreference, false); - preference.setProviderHint(UserProfileNotificationFilterPreferenceProvider.HINT); userFilterPreferences.add(preference); } this.notificationFilterPreferenceManager.saveFilterPreferences(userDocReference, userFilterPreferences); diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/internal/migrators/NotificationFilterPreferencesMigrator.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/internal/migrators/NotificationFilterPreferencesMigrator.java index a123a05313b..7e521ac7355 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/internal/migrators/NotificationFilterPreferencesMigrator.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/internal/migrators/NotificationFilterPreferencesMigrator.java @@ -206,7 +206,6 @@ private void handleObject(List<NotificationFilterPreference> preferencesToConver filterFormats.add(NotificationFormat.valueOf(format.toUpperCase())); } - preference.setProviderHint("userProfile"); preference.setFilterName(obj.getStringValue(FIELD_FILTER_NAME)); preference.setEnabled(obj.getIntValue(FIELD_IS_ENABLED, 1) == 1); preference.setActive(obj.getIntValue(FIELD_IS_ACTIVE, 1) == 1); diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/migration/R160300000XWIKI17243DataMigration.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/migration/R160300000XWIKI17243DataMigration.java index 956aa2c90db..9b82837e23a 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/migration/R160300000XWIKI17243DataMigration.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/main/java/org/xwiki/notifications/filters/migration/R160300000XWIKI17243DataMigration.java @@ -43,7 +43,6 @@ import org.xwiki.notifications.filters.NotificationFilterType; import org.xwiki.notifications.filters.internal.DefaultNotificationFilterPreference; import org.xwiki.notifications.filters.internal.NotificationFilterPreferenceStore; -import org.xwiki.notifications.filters.internal.UserProfileNotificationFilterPreferenceProvider; import org.xwiki.notifications.filters.internal.scope.ScopeNotificationFilter; import org.xwiki.query.Query; import org.xwiki.query.QueryException; @@ -263,7 +262,6 @@ private DefaultNotificationFilterPreference createNotificationFilterPreference(S pref.setId(id); pref.setEnabled(true); pref.setNotificationFormats(Set.of(NotificationFormat.values())); - pref.setProviderHint(UserProfileNotificationFilterPreferenceProvider.HINT); pref.setFilterName(ScopeNotificationFilter.FILTER_NAME); pref.setFilterType(NotificationFilterType.INCLUSIVE); return pref; diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/test/java/org/xwiki/notifications/filters/internal/NotificationFilterPreferenceStoreTest.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/test/java/org/xwiki/notifications/filters/internal/NotificationFilterPreferenceStoreTest.java index 7e8ba9f34fe..c11582399f8 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/test/java/org/xwiki/notifications/filters/internal/NotificationFilterPreferenceStoreTest.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/test/java/org/xwiki/notifications/filters/internal/NotificationFilterPreferenceStoreTest.java @@ -280,7 +280,5 @@ void getPreferencesOfUser() throws QueryException, NotificationException verify(this.context).setWikiReference(new WikiReference("subwiki")); verify(this.context).setWikiReference(CURRENT_WIKI_REFERENCE); verify(xwikiQuery).bindValue("owner", serializedRef); - verify(pref1).setProviderHint(UserProfileNotificationFilterPreferenceProvider.HINT); - verify(pref2).setProviderHint(UserProfileNotificationFilterPreferenceProvider.HINT); } } diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/test/java/org/xwiki/notifications/filters/internal/UserAddedEventListenerTest.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/test/java/org/xwiki/notifications/filters/internal/UserAddedEventListenerTest.java index 0b4c7aef2a0..577569cbf61 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/test/java/org/xwiki/notifications/filters/internal/UserAddedEventListenerTest.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/test/java/org/xwiki/notifications/filters/internal/UserAddedEventListenerTest.java @@ -102,17 +102,14 @@ void onEvent() throws NotificationException, XWikiException Set<NotificationFilterPreference> expectedSet = new HashSet<>(); DefaultNotificationFilterPreference expectedFilterPref1 = new DefaultNotificationFilterPreference(); expectedFilterPref1.setFilterName("filter1"); - expectedFilterPref1.setProviderHint(UserProfileNotificationFilterPreferenceProvider.HINT); expectedSet.add(expectedFilterPref1); DefaultNotificationFilterPreference expectedFilterPref2 = new DefaultNotificationFilterPreference(); expectedFilterPref2.setFilterName("filter2"); - expectedFilterPref2.setProviderHint(UserProfileNotificationFilterPreferenceProvider.HINT); expectedSet.add(expectedFilterPref2); DefaultNotificationFilterPreference expectedFilterPref3 = new DefaultNotificationFilterPreference(); expectedFilterPref3.setFilterName("filter3"); - expectedFilterPref3.setProviderHint(UserProfileNotificationFilterPreferenceProvider.HINT); expectedSet.add(expectedFilterPref3); when(userDoc.getXObjects(UserAddedEventListener.TOGGLEABLE_FILTER_PREFERENCE_CLASS)) diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/test/java/org/xwiki/notifications/filters/internal/migrators/NotificationFilterPreferencesMigratorTest.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/test/java/org/xwiki/notifications/filters/internal/migrators/NotificationFilterPreferencesMigratorTest.java index f1a9837b5ba..d01704d2d82 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/test/java/org/xwiki/notifications/filters/internal/migrators/NotificationFilterPreferencesMigratorTest.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-default/src/test/java/org/xwiki/notifications/filters/internal/migrators/NotificationFilterPreferencesMigratorTest.java @@ -195,7 +195,6 @@ private DefaultNotificationFilterPreference createExpectedPreference( preference.setEventTypes(eventType); preference.setNotificationFormats(formats); preference.setFilterType(filterType); - preference.setProviderHint("userProfile"); preference.setFilterName(filterName); preference.setEnabled(isEnabled); preference.setStartingDate(date); diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-watch/src/main/java/org/xwiki/notifications/filters/watch/WatchedLocationReference.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-watch/src/main/java/org/xwiki/notifications/filters/watch/WatchedLocationReference.java index 0f4f3a279d4..06bbd7cdefc 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-watch/src/main/java/org/xwiki/notifications/filters/watch/WatchedLocationReference.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-watch/src/main/java/org/xwiki/notifications/filters/watch/WatchedLocationReference.java @@ -34,7 +34,6 @@ import org.xwiki.notifications.filters.internal.scope.ScopeNotificationFilter; import org.xwiki.notifications.filters.internal.scope.ScopeNotificationFilterLocationStateComputer; import org.xwiki.notifications.filters.internal.scope.ScopeNotificationFilterPreference; -import org.xwiki.notifications.preferences.internal.UserProfileNotificationPreferenceProvider; /** * Reference of a location to watch. @@ -142,7 +141,6 @@ private DefaultNotificationFilterPreference createFilterPreference() filterPreference.setFilterType(NotificationFilterType.INCLUSIVE); filterPreference.setFilterName(ScopeNotificationFilter.FILTER_NAME); filterPreference.setNotificationFormats(ALL_NOTIFICATION_FORMATS); - filterPreference.setProviderHint(UserProfileNotificationPreferenceProvider.NAME); filterPreference.setActive(false); filterPreference.setStartingDate(new Date()); diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-watch/src/main/java/org/xwiki/notifications/filters/watch/WatchedUserReference.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-watch/src/main/java/org/xwiki/notifications/filters/watch/WatchedUserReference.java index 99172b4f810..4b35b7543c7 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-watch/src/main/java/org/xwiki/notifications/filters/watch/WatchedUserReference.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-watch/src/main/java/org/xwiki/notifications/filters/watch/WatchedUserReference.java @@ -31,7 +31,6 @@ import org.xwiki.notifications.filters.internal.DefaultNotificationFilterPreference; import org.xwiki.notifications.filters.internal.user.EventUserFilter; import org.xwiki.notifications.filters.internal.user.EventUserFilterPreferencesGetter; -import org.xwiki.notifications.preferences.internal.UserProfileNotificationPreferenceProvider; /** * Reference to a user to watch. @@ -96,7 +95,6 @@ public NotificationFilterPreference createInclusiveFilterPreference() filterPreference.setFilterType(NotificationFilterType.INCLUSIVE); filterPreference.setFilterName(EventUserFilter.FILTER_NAME); filterPreference.setNotificationFormats(Sets.newHashSet(NotificationFormat.values())); - filterPreference.setProviderHint(UserProfileNotificationPreferenceProvider.NAME); filterPreference.setActive(true); filterPreference.setStartingDate(new Date()); filterPreference.setUser(userId); @@ -113,7 +111,6 @@ public NotificationFilterPreference createExclusiveFilterPreference() filterPreference.setFilterType(NotificationFilterType.EXCLUSIVE); filterPreference.setFilterName(EventUserFilter.FILTER_NAME); filterPreference.setNotificationFormats(Sets.newHashSet(NotificationFormat.values())); - filterPreference.setProviderHint(UserProfileNotificationPreferenceProvider.NAME); filterPreference.setActive(false); filterPreference.setStartingDate(new Date()); filterPreference.setUser(userId); diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-watch/src/test/java/org/xwiki/notifications/filters/watch/WatchedLocationReferenceTest.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-watch/src/test/java/org/xwiki/notifications/filters/watch/WatchedLocationReferenceTest.java index 937c714d08a..8118c124e6c 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-watch/src/test/java/org/xwiki/notifications/filters/watch/WatchedLocationReferenceTest.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-filters/xwiki-platform-notifications-filters-watch/src/test/java/org/xwiki/notifications/filters/watch/WatchedLocationReferenceTest.java @@ -179,7 +179,6 @@ void createInclusiveFilterPreference() filterPreference.setFilterType(NotificationFilterType.INCLUSIVE); filterPreference.setFilterName(ScopeNotificationFilter.FILTER_NAME); filterPreference.setNotificationFormats(Set.of(NotificationFormat.values())); - filterPreference.setProviderHint(UserProfileNotificationPreferenceProvider.NAME); filterPreference.setActive(false); filterPreference.setPageOnly(this.serializedReference); @@ -216,7 +215,6 @@ void createExclusiveFilterPreference() filterPreference.setFilterType(NotificationFilterType.EXCLUSIVE); filterPreference.setFilterName(ScopeNotificationFilter.FILTER_NAME); filterPreference.setNotificationFormats(Set.of(NotificationFormat.values())); - filterPreference.setProviderHint(UserProfileNotificationPreferenceProvider.NAME); filterPreference.setActive(false); filterPreference.setPage(this.serializedReference); diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-sources/src/main/java/org/xwiki/notifications/sources/internal/DefaultNotificationParametersFactory.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-sources/src/main/java/org/xwiki/notifications/sources/internal/DefaultNotificationParametersFactory.java index 45b572b7819..0699a93ebe9 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-sources/src/main/java/org/xwiki/notifications/sources/internal/DefaultNotificationParametersFactory.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-sources/src/main/java/org/xwiki/notifications/sources/internal/DefaultNotificationParametersFactory.java @@ -538,7 +538,6 @@ private void handleLocationParameter(String locations, NotificationParameters pa pref.setFilterName(ScopeNotificationFilter.FILTER_NAME); pref.setFilterType(NotificationFilterType.INCLUSIVE); pref.setNotificationFormats(formats); - pref.setProviderHint("FACTORY"); switch (property) { case WIKI: pref.setWiki(locationArray[i]); diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-sources/src/main/java/org/xwiki/notifications/sources/internal/TagNotificationFilterPreference.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-sources/src/main/java/org/xwiki/notifications/sources/internal/TagNotificationFilterPreference.java index 5360f509ddf..4474e15a871 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-sources/src/main/java/org/xwiki/notifications/sources/internal/TagNotificationFilterPreference.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-sources/src/main/java/org/xwiki/notifications/sources/internal/TagNotificationFilterPreference.java @@ -79,12 +79,6 @@ public String getFilterName() return TagNotificationFilter.NAME; } - @Override - public String getProviderHint() - { - return "FACTORY"; - } - @Override public boolean isEnabled() { diff --git a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-sources/src/test/java/org/xwiki/notifications/sources/internal/DefaultNotificationParametersFactoryTest.java b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-sources/src/test/java/org/xwiki/notifications/sources/internal/DefaultNotificationParametersFactoryTest.java index 59bb6fdb9fd..b71abc7a69a 100644 --- a/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-sources/src/test/java/org/xwiki/notifications/sources/internal/DefaultNotificationParametersFactoryTest.java +++ b/xwiki-platform-core/xwiki-platform-notifications/xwiki-platform-notifications-sources/src/test/java/org/xwiki/notifications/sources/internal/DefaultNotificationParametersFactoryTest.java @@ -397,7 +397,6 @@ private DefaultNotificationFilterPreference getFilterPreference(String property, filterPreference.setFilterName(ScopeNotificationFilter.FILTER_NAME); filterPreference.setFilterType(NotificationFilterType.INCLUSIVE); filterPreference.setNotificationFormats(Collections.singleton(NotificationFormat.ALERT)); - filterPreference.setProviderHint("FACTORY"); return filterPreference; } } -- GitLab