use of org.xwiki.notifications.preferences.NotificationPreferenceProvider in project xwiki-platform by xwiki.
the class DefaultNotificationPreferenceManager method savePreferences.
@Override
public void savePreferences(List<NotificationPreference> preferences) throws NotificationException {
// We construct a map where each key is a provider hint and each value is a list of associated providers
// this allows calling each provider only once
Map<String, List<NotificationPreference>> preferencesMapping = new HashMap<>();
for (NotificationPreference notificationPreference : preferences) {
// Try to get the corresponding provider, if no provider can be found, discard the save of the preference
String providerHint = notificationPreference.getProviderHint();
if (componentManager.hasComponent(NotificationPreferenceProvider.class, providerHint)) {
if (!preferencesMapping.containsKey(providerHint)) {
preferencesMapping.put(providerHint, new ArrayList<>());
}
preferencesMapping.get(providerHint).add(notificationPreference);
}
}
// Once we have created the mapping, save all the preferences using their correct providers
for (String providerHint : preferencesMapping.keySet()) {
try {
NotificationPreferenceProvider provider = componentManager.getInstance(NotificationPreferenceProvider.class, providerHint);
provider.savePreferences(preferencesMapping.get(providerHint));
} catch (ComponentLookupException e) {
logger.error("Unable to retrieve the notification preference provide for hint {}: {}", providerHint, e);
}
}
}
use of org.xwiki.notifications.preferences.NotificationPreferenceProvider in project xwiki-platform by xwiki.
the class DefaultNotificationPreferenceManager method getProviders.
private List<NotificationPreferenceProvider> getProviders() throws NotificationException {
try {
// Get every registered notification provider
List<NotificationPreferenceProvider> providers = componentManager.getInstanceList(NotificationPreferenceProvider.class);
// We handle conflicts between similar preferences by sorting the providers by order. Since
// notificationPreferences is a set, only the first occurrence of a preference is stored.
Collections.sort(providers, (o1, o2) -> o2.getProviderPriority() - o1.getProviderPriority());
return providers;
} catch (ComponentLookupException e) {
throw new NotificationException("Unable to fetch the notifications preferences providers from the component manager", e);
}
}
Aggregations