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));
}
}
}
Aggregations