use of org.xwiki.notifications.filters.NotificationFilterProperty in project xwiki-platform by xwiki.
the class DefaultModelBridge method getFilterPreferences.
@Override
public Set<NotificationFilterPreference> getFilterPreferences(DocumentReference user) throws NotificationException {
XWikiContext context = contextProvider.get();
XWiki xwiki = context.getWiki();
final DocumentReference notificationFilterPreferenceClass = NOTIFICATION_FILTER_PREFERENCE_CLASS.setWikiReference(user.getWikiReference());
Set<NotificationFilterPreference> preferences = new HashSet<>();
try {
XWikiDocument doc = xwiki.getDocument(user, context);
List<BaseObject> preferencesObj = doc.getXObjects(notificationFilterPreferenceClass);
if (preferencesObj != null) {
for (BaseObject obj : preferencesObj) {
if (obj != null) {
Map<NotificationFilterProperty, List<String>> filterPreferenceProperties = createNotificationFilterPropertiesMap(obj);
NotificationFilterType filterType = NotificationFilterType.valueOf(obj.getStringValue(FIELD_FILTER_TYPE).toUpperCase());
Set<NotificationFormat> filterFormats = new HashSet<>();
for (String format : (List<String>) obj.getListValue(FIELD_FILTER_FORMATS)) {
filterFormats.add(NotificationFormat.valueOf(format.toUpperCase()));
}
// Create the new filter preference and add it to the list of preferences
DefaultNotificationFilterPreference notificationFilterPreference = new DefaultNotificationFilterPreference(obj.getStringValue(FILTER_PREFERENCE_NAME));
notificationFilterPreference.setProviderHint("userProfile");
notificationFilterPreference.setFilterName(obj.getStringValue(FIELD_FILTER_NAME));
notificationFilterPreference.setEnabled(obj.getIntValue(FIELD_IS_ENABLED, 1) == 1);
notificationFilterPreference.setActive(obj.getIntValue(FIELD_IS_ACTIVE, 1) == 1);
notificationFilterPreference.setFilterType(filterType);
notificationFilterPreference.setNotificationFormats(filterFormats);
notificationFilterPreference.setPreferenceProperties(filterPreferenceProperties);
preferences.add(notificationFilterPreference);
}
}
}
} catch (Exception e) {
throw new NotificationException(String.format("Failed to get the notification preferences scope for the user [%s].", user), e);
}
return preferences;
}
use of org.xwiki.notifications.filters.NotificationFilterProperty in project xwiki-platform by xwiki.
the class WatchedLocationReference method createFilterPreference.
private DefaultNotificationFilterPreference createFilterPreference() {
DefaultNotificationFilterPreference filterPreference = new DefaultNotificationFilterPreference(Long.toString(new Date().getTime()));
// Fields
filterPreference.setEnabled(true);
filterPreference.setFilterType(NotificationFilterType.INCLUSIVE);
filterPreference.setFilterName(ScopeNotificationFilter.FILTER_NAME);
filterPreference.setNotificationFormats(ALL_NOTIFICATION_FORMATS);
filterPreference.setProviderHint(UserProfileNotificationPreferenceProvider.NAME);
filterPreference.setActive(false);
// Properties
Map<NotificationFilterProperty, List<String>> preferenceProperties = new HashMap<>();
filterPreference.setPreferenceProperties(preferenceProperties);
preferenceProperties.put(NotificationFilterProperty.EVENT_TYPE, Collections.emptyList());
// Scope value
List<String> value = Collections.singletonList(serializedReference);
switch(entityReference.getType()) {
case WIKI:
preferenceProperties.put(NotificationFilterProperty.WIKI, value);
break;
case SPACE:
preferenceProperties.put(NotificationFilterProperty.SPACE, value);
break;
case DOCUMENT:
preferenceProperties.put(NotificationFilterProperty.PAGE, value);
break;
default:
break;
}
return filterPreference;
}
use of org.xwiki.notifications.filters.NotificationFilterProperty in project xwiki-platform by xwiki.
the class WatchedUserReference method createInclusiveFilterPreference.
@Override
public NotificationFilterPreference createInclusiveFilterPreference() {
DefaultNotificationFilterPreference filterPreference = new DefaultNotificationFilterPreference(Long.toString(new Date().getTime()));
filterPreference.setEnabled(true);
filterPreference.setFilterType(NotificationFilterType.INCLUSIVE);
filterPreference.setFilterName(EventUserFilter.FILTER_NAME);
filterPreference.setNotificationFormats(Sets.newHashSet(NotificationFormat.values()));
filterPreference.setProviderHint(UserProfileNotificationPreferenceProvider.NAME);
filterPreference.setActive(true);
// Properties
Map<NotificationFilterProperty, List<String>> preferenceProperties = new HashMap<>();
filterPreference.setPreferenceProperties(preferenceProperties);
preferenceProperties.put(NotificationFilterProperty.EVENT_TYPE, Collections.emptyList());
preferenceProperties.put(NotificationFilterProperty.USER, Collections.singletonList(userId));
return filterPreference;
}
use of org.xwiki.notifications.filters.NotificationFilterProperty in project xwiki-platform by xwiki.
the class DefaultNotificationFilterPreferenceTest method defaultNotificationFilterPreference.
@Test
public void defaultNotificationFilterPreference() throws Exception {
String filterPreferenceName = "fp1";
String filterName = "f1";
boolean isEnabled = true;
boolean isActive = true;
NotificationFilterType filterType = NotificationFilterType.INCLUSIVE;
Set<NotificationFormat> notificationFormats = Sets.newSet(NotificationFormat.ALERT, NotificationFormat.EMAIL);
Map<NotificationFilterProperty, List<String>> propertiesMap = new HashMap<>();
propertiesMap.put(NotificationFilterProperty.APPLICATION, Arrays.asList("a1", "a2"));
DefaultNotificationFilterPreference preference = new DefaultNotificationFilterPreference(filterPreferenceName);
preference.setFilterName(filterName);
preference.setEnabled(isEnabled);
preference.setActive(isActive);
preference.setFilterType(filterType);
preference.setNotificationFormats(notificationFormats);
preference.setPreferenceProperties(propertiesMap);
assertEquals(filterPreferenceName, preference.getFilterPreferenceName());
assertEquals(filterName, preference.getFilterName());
assertEquals(isEnabled, preference.isEnabled());
assertEquals(isActive, preference.isActive());
assertEquals(filterType, preference.getFilterType());
assertEquals(notificationFormats, preference.getFilterFormats());
assertEquals(propertiesMap.get(NotificationFilterProperty.APPLICATION), preference.getProperties(NotificationFilterProperty.APPLICATION));
}
use of org.xwiki.notifications.filters.NotificationFilterProperty in project xwiki-platform by xwiki.
the class ScopeNotificationFilterTest method mockNotificationFilterPreference.
private NotificationFilterPreference mockNotificationFilterPreference(String entityStringValue, EntityReference resultReference, NotificationFilterType filterType, String eventName) {
NotificationFilterProperty property;
if (resultReference.getType().equals(EntityType.DOCUMENT)) {
property = NotificationFilterProperty.PAGE;
} else if (resultReference.getType().equals(EntityType.SPACE)) {
property = NotificationFilterProperty.SPACE;
} else {
property = NotificationFilterProperty.WIKI;
}
NotificationFilterPreference preference = mock(NotificationFilterPreference.class);
when(preference.getProperties(property)).thenReturn(Collections.singletonList(entityStringValue));
when(preference.getFilterName()).thenReturn(ScopeNotificationFilter.FILTER_NAME);
when(preference.getProperties(eq(NotificationFilterProperty.EVENT_TYPE))).thenReturn(eventName != null ? Arrays.asList(eventName) : Collections.emptyList());
when(preference.getFilterType()).thenReturn(filterType);
when(preference.getFilterFormats()).thenReturn(Sets.newSet(NotificationFormat.ALERT, NotificationFormat.EMAIL));
when(preference.isEnabled()).thenReturn(true);
when(resolver.resolve(entityStringValue, resultReference.getType())).thenReturn(resultReference);
when(serializer.serialize(eq(resultReference))).thenReturn(entityStringValue);
return preference;
}
Aggregations