use of org.xwiki.notifications.preferences.NotificationPreference in project xwiki-platform by xwiki.
the class AbstractDocumentNotificationPreferenceProvider method savePreferences.
@Override
public void savePreferences(List<NotificationPreference> preferences) throws NotificationException {
// Create a map of preferences per target, so we can save the target's document only once for all preferences
Map<EntityReference, List<NotificationPreference>> preferencesPerTarget = new HashMap<>();
for (NotificationPreference preference : preferences) {
if (preference instanceof TargetableNotificationPreference) {
TargetableNotificationPreference targetablePreference = (TargetableNotificationPreference) preference;
List<NotificationPreference> list = preferencesPerTarget.get(targetablePreference.getTarget());
if (list == null) {
list = new ArrayList<>();
preferencesPerTarget.put(targetablePreference.getTarget(), list);
}
list.add(targetablePreference);
} else {
logger.warn("Unsupported NotificationPreference class: [{}]. This preference will not be saved.", preference.getClass().getName());
}
}
for (Map.Entry<EntityReference, List<NotificationPreference>> entry : preferencesPerTarget.entrySet()) {
savePreferences(entry.getValue(), entry.getKey());
}
}
use of org.xwiki.notifications.preferences.NotificationPreference in project xwiki-platform by xwiki.
the class CachedModelBridge method getNotificationsPreferences.
@Override
public List<NotificationPreference> getNotificationsPreferences(WikiReference wikiReference) throws NotificationException {
// We need to store the wiki reference in the cache's key
final String specificWikiNotificationsPreferences = String.format(CACHE_KEY_PATTERN, WIKI_NOTIFICATIONS_PREFERENCES, serializer.serialize(wikiReference));
ExecutionContext context = execution.getContext();
if (context.hasProperty(specificWikiNotificationsPreferences)) {
return (List<NotificationPreference>) context.getProperty(specificWikiNotificationsPreferences);
}
List<NotificationPreference> preferences = modelBridge.getNotificationsPreferences(wikiReference);
context.setProperty(specificWikiNotificationsPreferences, preferences);
return preferences;
}
use of org.xwiki.notifications.preferences.NotificationPreference 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.NotificationPreference in project xwiki-platform by xwiki.
the class MinorEventNotificationFilterTest method filterExpression.
@Test
public void filterExpression() throws Exception {
NotificationPreference fakePreference = mock(NotificationPreference.class);
DocumentReference randomUser = new DocumentReference("xwiki", "XWiki", "UserA");
assertNull(mocker.getComponentUnderTest().filterExpression(randomUser, fakePreference));
assertEquals("NOT ((TYPE = \"update\" AND NOT (DOCUMENT_VERSION ENDS WITH \".1\")))", mocker.getComponentUnderTest().filterExpression(randomUser, NotificationFilterType.EXCLUSIVE, NotificationFormat.ALERT).toString());
}
use of org.xwiki.notifications.preferences.NotificationPreference in project xwiki-platform by xwiki.
the class ScopeNotificationFilterTest method matchPreferenceWithCorrectPreference.
@Test
public void matchPreferenceWithCorrectPreference() throws Exception {
NotificationPreference preference = mock(NotificationPreference.class);
when(preference.getCategory()).thenReturn(NotificationPreferenceCategory.DEFAULT);
when(preference.getProperties()).thenReturn(Collections.singletonMap(NotificationPreferenceProperty.EVENT_TYPE, ""));
assertTrue(mocker.getComponentUnderTest().matchesPreference(preference));
}
Aggregations