Search in sources :

Example 1 with NotificationFilterPreferenceProvider

use of org.xwiki.notifications.filters.NotificationFilterPreferenceProvider in project xwiki-platform by xwiki.

the class DefaultNotificationFilterManager method saveFilterPreferences.

@Override
public void saveFilterPreferences(Set<NotificationFilterPreference> filterPreferences) {
    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(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));
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) NotificationFilterPreferenceProvider(org.xwiki.notifications.filters.NotificationFilterPreferenceProvider) NotificationFilterPreference(org.xwiki.notifications.filters.NotificationFilterPreference) NotificationException(org.xwiki.notifications.NotificationException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 NotificationException (org.xwiki.notifications.NotificationException)1 NotificationFilterPreference (org.xwiki.notifications.filters.NotificationFilterPreference)1 NotificationFilterPreferenceProvider (org.xwiki.notifications.filters.NotificationFilterPreferenceProvider)1