@Test public void isEventTypeEnabledForWiki() throws Exception { WikiReference wiki = new WikiReference("whatever"); when(notificationPreferenceManager.getAllPreferences(wiki)).thenReturn(Collections.emptyList()); assertFalse(mocker.getComponentUnderTest().isEventTypeEnabled("update", NotificationFormat.ALERT, wiki.getName())); NotificationPreference pref1 = mock(NotificationPreference.class); NotificationPreference pref2 = mock(NotificationPreference.class); when(pref1.getFormat()).thenReturn(NotificationFormat.EMAIL); Map<NotificationPreferenceProperty, Object> properties1 = new HashMap<>(); properties1.put(NotificationPreferenceProperty.EVENT_TYPE, "update"); when(pref1.getProperties()).thenReturn(properties1); when(pref2.getFormat()).thenReturn(NotificationFormat.ALERT); Map<NotificationPreferenceProperty, Object> properties2 = new HashMap<>(); properties2.put(NotificationPreferenceProperty.EVENT_TYPE, "update"); when(pref2.getProperties()).thenReturn(properties2); when(pref2.isNotificationEnabled()).thenReturn(true); when(notificationPreferenceManager.getAllPreferences(wiki)).thenReturn(Arrays.asList(pref1, pref2)); assertTrue(mocker.getComponentUnderTest().isEventTypeEnabled("update", NotificationFormat.ALERT, wiki.getName())); assertFalse(mocker.getComponentUnderTest().isEventTypeEnabled("update", NotificationFormat.EMAIL, wiki.getName())); }
public boolean isEventTypeEnabled(String eventType, NotificationFormat format, String wiki) throws NotificationException, AccessDeniedException { WikiReference wikiReference = new WikiReference(wiki); authorizationManager.checkAccess(Right.ADMIN, wikiReference); for (NotificationPreference preference : notificationPreferenceManager.getAllPreferences(wikiReference)) { Object prefEventType = preference.getProperties().get(NotificationPreferenceProperty.EVENT_TYPE); if (prefEventType != null && StringUtils.equals((String) prefEventType, eventType) && preference.getFormat() == format) { return preference.isNotificationEnabled(); } } return false; }
NotificationPreferenceScriptService implements ScriptService { public boolean isEventTypeEnabled(String eventType, NotificationFormat format, String wiki) throws NotificationException, AccessDeniedException { WikiReference wikiReference = new WikiReference(wiki); authorizationManager.checkAccess(Right.ADMIN, wikiReference); for (NotificationPreference preference : notificationPreferenceManager.getAllPreferences(wikiReference)) { Object prefEventType = preference.getProperties().get(NotificationPreferenceProperty.EVENT_TYPE); if (prefEventType != null && StringUtils.equals((String) prefEventType, eventType) && preference.getFormat() == format) { return preference.isNotificationEnabled(); } } return false; } }
NotificationPreferenceScriptService implements ScriptService { public boolean isEventTypeEnabled(String eventType, NotificationFormat format, String wiki) throws NotificationException, AccessDeniedException { WikiReference wikiReference = new WikiReference(wiki); authorizationManager.checkAccess(Right.ADMIN, wikiReference); for (NotificationPreference preference : notificationPreferenceManager.getAllPreferences(wikiReference)) { Object prefEventType = preference.getProperties().get(NotificationPreferenceProperty.EVENT_TYPE); if (prefEventType != null && StringUtils.equals((String) prefEventType, eventType) && preference.getFormat() == format) { return preference.isNotificationEnabled(); } } return false; }  }
NotificationPreferenceScriptService implements ScriptService { public boolean isEventTypeEnabled(String eventType, NotificationFormat format, String wiki) throws NotificationException, AccessDeniedException { WikiReference wikiReference = new WikiReference(wiki); authorizationManager.checkAccess(Right.ADMIN, wikiReference); for (NotificationPreference preference : notificationPreferenceManager.getAllPreferences(wikiReference)) { Object prefEventType = preference.getProperties().get(NotificationPreferenceProperty.EVENT_TYPE); if (prefEventType != null && StringUtils.equals((String) prefEventType, eventType) && preference.getFormat() == format) { return preference.isNotificationEnabled(); } } return false; }  void saveNotificationPreferences(String json, DocumentReference userReference); void saveNotificationPreferences(String json); void saveNotificationPreferencesForCurrentWiki(String json); void setStartDate(Date startDate); void setStartDate(String userId, Date startDate); boolean hasAnyEnabledNotificationPreferences(); NotificationEmailDiffType getDiffType(); NotificationEmailDiffType getDiffType(String userId); boolean isEventTypeEnabled(String eventType, NotificationFormat format, String wiki); boolean isEventTypeEnabled(String eventType, NotificationFormat format); }
NotificationPreferenceScriptService implements ScriptService { public boolean isEventTypeEnabled(String eventType, NotificationFormat format, String wiki) throws NotificationException, AccessDeniedException { WikiReference wikiReference = new WikiReference(wiki); authorizationManager.checkAccess(Right.ADMIN, wikiReference); for (NotificationPreference preference : notificationPreferenceManager.getAllPreferences(wikiReference)) { Object prefEventType = preference.getProperties().get(NotificationPreferenceProperty.EVENT_TYPE); if (prefEventType != null && StringUtils.equals((String) prefEventType, eventType) && preference.getFormat() == format) { return preference.isNotificationEnabled(); } } return false; }  void saveNotificationPreferences(String json, DocumentReference userReference); void saveNotificationPreferences(String json); void saveNotificationPreferencesForCurrentWiki(String json); void setStartDate(Date startDate); void setStartDate(String userId, Date startDate); boolean hasAnyEnabledNotificationPreferences(); NotificationEmailDiffType getDiffType(); NotificationEmailDiffType getDiffType(String userId); boolean isEventTypeEnabled(String eventType, NotificationFormat format, String wiki); boolean isEventTypeEnabled(String eventType, NotificationFormat format);  }