@Test public void createNotificationParameters() throws NotificationException { when(this.configuration.isEventPrefilteringEnabled()).thenReturn(false); NotificationParameters notificationParameters = new NotificationParameters(); notificationParameters.format = NotificationFormat.ALERT; notificationParameters.filters = this.filterList; notificationParameters.preferences = Arrays.asList(new InternalNotificationPreference(this.recordableEventDescriptors.get(0)), new InternalNotificationPreference(this.recordableEventDescriptors.get(1))); assertEquals(notificationParameters, this.parametersFactory.createNotificationParameters(Collections.emptyMap())); verify(wikiDescriptorManager).getCurrentWikiId(); Map<ParametersKey, String> parametersMap = new HashMap<>(); parametersMap.put(ParametersKey.FORMAT, "EMAIL"); parametersMap.put(ParametersKey.USER_ID, USER_SERIALIZED_REFERENCE); parametersMap.put(ParametersKey.USE_USER_PREFERENCES, "true"); parametersMap.put(ParametersKey.UNTIL_DATE, "4242"); parametersMap.put(ParametersKey.UNTIL_DATE_INCLUDED, "true"); parametersMap.put(ParametersKey.MAX_COUNT, "1258"); parametersMap.put(ParametersKey.ONLY_UNREAD, "true"); parametersMap.put(ParametersKey.BLACKLIST, "foo,bar,baz"); parametersMap.put(ParametersKey.PAGES, "a,b,c"); parametersMap.put(ParametersKey.TAGS, "d,e,f"); parametersMap.put(ParametersKey.CURRENT_WIKI, "mywiki"); parametersMap.put(ParametersKey.DISPLAY_READ_EVENTS, "true"); parametersMap.put(ParametersKey.DISPLAY_SYSTEM_EVENTS, "false"); parametersMap.put(ParametersKey.DISPLAY_OWN_EVENTS, "true"); parametersMap.put(ParametersKey.DISPLAY_MINOR_EVENTS, "false"); parametersMap.put(ParametersKey.USERS, "foobar,barbar"); parametersMap.put(ParametersKey.WIKIS, "wiki1,wiki2"); parametersMap.put(ParametersKey.SPACES, "space1,space2"); notificationParameters = new NotificationParameters(); notificationParameters.format = NotificationFormat.EMAIL; notificationParameters.endDate = new Date(4242); notificationParameters.onlyUnread = true; notificationParameters.user = USER_REFERENCE; notificationParameters.expectedCount = 1258; notificationParameters.blackList = Arrays.asList("foo", "bar", "baz"); notificationParameters.preferences = this.mailPreferenceList; notificationParameters.filterPreferences = this.filterPreferenceList; notificationParameters.filters = Collections.singletonList(this.filterList.get(1)); assertEquals(notificationParameters, this.parametersFactory.createNotificationParameters(parametersMap)); parametersMap.put(ParametersKey.FORMAT, NotificationFormat.ALERT.name()); notificationParameters.format = NotificationFormat.ALERT; notificationParameters.preferences = this.alertPreferenceList; assertEquals(notificationParameters, this.parametersFactory.createNotificationParameters(parametersMap)); when(this.configuration.isEventPrefilteringEnabled()).thenReturn(true); notificationParameters.preferences = Arrays.asList(new InternalNotificationPreference(this.recordableEventDescriptors.get(0)), new InternalNotificationPreference(this.recordableEventDescriptors.get(1))); notificationParameters.filterPreferences = Collections.emptyList(); parametersMap.put(ParametersKey.FORMAT, NotificationFormat.EMAIL.name()); notificationParameters.format = NotificationFormat.EMAIL; notificationParameters.filters = Collections.singletonList(new ForUserEventFilter(NotificationFormat.EMAIL, null)); assertEquals(notificationParameters, this.parametersFactory.createNotificationParameters(parametersMap)); parametersMap.put(ParametersKey.FORMAT, NotificationFormat.ALERT.name()); notificationParameters.format = NotificationFormat.ALERT; notificationParameters.filters = Collections.singletonList(new ForUserEventFilter(NotificationFormat.ALERT, null)); assertEquals(notificationParameters, this.parametersFactory.createNotificationParameters(parametersMap)); parametersMap.put(ParametersKey.USE_USER_PREFERENCES, "false"); notificationParameters.filters = Arrays.asList(filterList.get(1), filterList.get(2)); List<NotificationFilterPreference> notificationFilterPreferences = new ArrayList<>(); DefaultNotificationFilterPreference filterPref = getFilterPreference("PAGE", 0); filterPref.setPageOnly("mywiki@@a"); notificationFilterPreferences .add(new ScopeNotificationFilterPreference(filterPref, this.entityReferenceResolver)); filterPref = getFilterPreference("PAGE", 1); filterPref.setPageOnly("mywiki@@b"); notificationFilterPreferences .add(new ScopeNotificationFilterPreference(filterPref, this.entityReferenceResolver)); filterPref = getFilterPreference("PAGE", 2); filterPref.setPageOnly("mywiki@@c"); notificationFilterPreferences .add(new ScopeNotificationFilterPreference(filterPref, this.entityReferenceResolver)); filterPref = getFilterPreference("SPACE", 0); filterPref.setPage("mywiki@@space1"); notificationFilterPreferences .add(new ScopeNotificationFilterPreference(filterPref, this.entityReferenceResolver)); filterPref = getFilterPreference("SPACE", 1); filterPref.setPage("mywiki@@space2"); notificationFilterPreferences .add(new ScopeNotificationFilterPreference(filterPref, this.entityReferenceResolver)); filterPref = getFilterPreference("WIKI", 0); filterPref.setWiki("wiki1"); notificationFilterPreferences .add(new ScopeNotificationFilterPreference(filterPref, this.entityReferenceResolver)); filterPref = getFilterPreference("WIKI", 1); filterPref.setWiki("wiki2"); notificationFilterPreferences .add(new ScopeNotificationFilterPreference(filterPref, this.entityReferenceResolver)); notificationFilterPreferences.add(new TagNotificationFilterPreference("d", "mywiki")); notificationFilterPreferences.add(new TagNotificationFilterPreference("e", "mywiki")); notificationFilterPreferences.add(new TagNotificationFilterPreference("f", "mywiki")); notificationParameters.filterPreferences = notificationFilterPreferences; assertEquals(notificationParameters, this.parametersFactory.createNotificationParameters(parametersMap)); verify(this.usersParameterHandler).handleUsersParameter("foobar,barbar", notificationParameters); parametersMap.remove(ParametersKey.CURRENT_WIKI); when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("mywiki"); assertEquals(notificationParameters, this.parametersFactory.createNotificationParameters(parametersMap)); verify(wikiDescriptorManager, times(2)).getCurrentWikiId(); }
public NotificationParameters createNotificationParameters(Map<ParametersKey, String> parameters) throws NotificationException { NotificationParameters notificationParameters = new NotificationParameters(); for (Map.Entry<ParametersKey, String> parameterPair : parameters.entrySet()) { ParametersKey actualKey = parameterPair.getKey(); String parameterValue = parameterPair.getValue(); if (actualKey.isDirectlyUsed()) { switch (actualKey) { case FORMAT: this.handleFormat(notificationParameters, parameterValue); break; case USER_ID: this.handleUserId(notificationParameters, parameterValue); break; case UNTIL_DATE: this.handleUntilDate(notificationParameters, parameterValue, BooleanUtils .toBooleanObject(parameters.get(ParametersKey.UNTIL_DATE_INCLUDED)) != Boolean.FALSE); break; case BLACKLIST: this.handleBlacklist(notificationParameters, parameterValue); break; case MAX_COUNT: this.handleMaxCount(notificationParameters, parameterValue); break; case ONLY_UNREAD: this.handleOnlyUnread(notificationParameters, parameterValue); break; default: logger.error("The notification parameters key [{}] exist but has not been implemented.", actualKey.name()); } } } if (notificationParameters.format == null) { notificationParameters.format = NotificationFormat.ALERT; } try { if (Boolean.parseBoolean(parameters.get(ParametersKey.USE_USER_PREFERENCES))) { this.useUserPreferences(notificationParameters); } else { this.dontUseUserPreferences(notificationParameters, parameters); } } catch (EventStreamException e) { throw new NotificationException("Error while adding the filters to the notification parameters.", e); } return notificationParameters; }
DefaultNotificationParametersFactory { public NotificationParameters createNotificationParameters(Map<ParametersKey, String> parameters) throws NotificationException { NotificationParameters notificationParameters = new NotificationParameters(); for (Map.Entry<ParametersKey, String> parameterPair : parameters.entrySet()) { ParametersKey actualKey = parameterPair.getKey(); String parameterValue = parameterPair.getValue(); if (actualKey.isDirectlyUsed()) { switch (actualKey) { case FORMAT: this.handleFormat(notificationParameters, parameterValue); break; case USER_ID: this.handleUserId(notificationParameters, parameterValue); break; case UNTIL_DATE: this.handleUntilDate(notificationParameters, parameterValue, BooleanUtils .toBooleanObject(parameters.get(ParametersKey.UNTIL_DATE_INCLUDED)) != Boolean.FALSE); break; case BLACKLIST: this.handleBlacklist(notificationParameters, parameterValue); break; case MAX_COUNT: this.handleMaxCount(notificationParameters, parameterValue); break; case ONLY_UNREAD: this.handleOnlyUnread(notificationParameters, parameterValue); break; default: logger.error("The notification parameters key [{}] exist but has not been implemented.", actualKey.name()); } } } if (notificationParameters.format == null) { notificationParameters.format = NotificationFormat.ALERT; } try { if (Boolean.parseBoolean(parameters.get(ParametersKey.USE_USER_PREFERENCES))) { this.useUserPreferences(notificationParameters); } else { this.dontUseUserPreferences(notificationParameters, parameters); } } catch (EventStreamException e) { throw new NotificationException("Error while adding the filters to the notification parameters.", e); } return notificationParameters; } }
DefaultNotificationParametersFactory { public NotificationParameters createNotificationParameters(Map<ParametersKey, String> parameters) throws NotificationException { NotificationParameters notificationParameters = new NotificationParameters(); for (Map.Entry<ParametersKey, String> parameterPair : parameters.entrySet()) { ParametersKey actualKey = parameterPair.getKey(); String parameterValue = parameterPair.getValue(); if (actualKey.isDirectlyUsed()) { switch (actualKey) { case FORMAT: this.handleFormat(notificationParameters, parameterValue); break; case USER_ID: this.handleUserId(notificationParameters, parameterValue); break; case UNTIL_DATE: this.handleUntilDate(notificationParameters, parameterValue, BooleanUtils .toBooleanObject(parameters.get(ParametersKey.UNTIL_DATE_INCLUDED)) != Boolean.FALSE); break; case BLACKLIST: this.handleBlacklist(notificationParameters, parameterValue); break; case MAX_COUNT: this.handleMaxCount(notificationParameters, parameterValue); break; case ONLY_UNREAD: this.handleOnlyUnread(notificationParameters, parameterValue); break; default: logger.error("The notification parameters key [{}] exist but has not been implemented.", actualKey.name()); } } } if (notificationParameters.format == null) { notificationParameters.format = NotificationFormat.ALERT; } try { if (Boolean.parseBoolean(parameters.get(ParametersKey.USE_USER_PREFERENCES))) { this.useUserPreferences(notificationParameters); } else { this.dontUseUserPreferences(notificationParameters, parameters); } } catch (EventStreamException e) { throw new NotificationException("Error while adding the filters to the notification parameters.", e); } return notificationParameters; }  }
DefaultNotificationParametersFactory { public NotificationParameters createNotificationParameters(Map<ParametersKey, String> parameters) throws NotificationException { NotificationParameters notificationParameters = new NotificationParameters(); for (Map.Entry<ParametersKey, String> parameterPair : parameters.entrySet()) { ParametersKey actualKey = parameterPair.getKey(); String parameterValue = parameterPair.getValue(); if (actualKey.isDirectlyUsed()) { switch (actualKey) { case FORMAT: this.handleFormat(notificationParameters, parameterValue); break; case USER_ID: this.handleUserId(notificationParameters, parameterValue); break; case UNTIL_DATE: this.handleUntilDate(notificationParameters, parameterValue, BooleanUtils .toBooleanObject(parameters.get(ParametersKey.UNTIL_DATE_INCLUDED)) != Boolean.FALSE); break; case BLACKLIST: this.handleBlacklist(notificationParameters, parameterValue); break; case MAX_COUNT: this.handleMaxCount(notificationParameters, parameterValue); break; case ONLY_UNREAD: this.handleOnlyUnread(notificationParameters, parameterValue); break; default: logger.error("The notification parameters key [{}] exist but has not been implemented.", actualKey.name()); } } } if (notificationParameters.format == null) { notificationParameters.format = NotificationFormat.ALERT; } try { if (Boolean.parseBoolean(parameters.get(ParametersKey.USE_USER_PREFERENCES))) { this.useUserPreferences(notificationParameters); } else { this.dontUseUserPreferences(notificationParameters, parameters); } } catch (EventStreamException e) { throw new NotificationException("Error while adding the filters to the notification parameters.", e); } return notificationParameters; }  NotificationParameters createNotificationParametersWithStringMap(Map<String, String> parameters); NotificationParameters createNotificationParameters(Map<ParametersKey, String> parameters); void useUserPreferences(NotificationParameters parameters); }
DefaultNotificationParametersFactory { public NotificationParameters createNotificationParameters(Map<ParametersKey, String> parameters) throws NotificationException { NotificationParameters notificationParameters = new NotificationParameters(); for (Map.Entry<ParametersKey, String> parameterPair : parameters.entrySet()) { ParametersKey actualKey = parameterPair.getKey(); String parameterValue = parameterPair.getValue(); if (actualKey.isDirectlyUsed()) { switch (actualKey) { case FORMAT: this.handleFormat(notificationParameters, parameterValue); break; case USER_ID: this.handleUserId(notificationParameters, parameterValue); break; case UNTIL_DATE: this.handleUntilDate(notificationParameters, parameterValue, BooleanUtils .toBooleanObject(parameters.get(ParametersKey.UNTIL_DATE_INCLUDED)) != Boolean.FALSE); break; case BLACKLIST: this.handleBlacklist(notificationParameters, parameterValue); break; case MAX_COUNT: this.handleMaxCount(notificationParameters, parameterValue); break; case ONLY_UNREAD: this.handleOnlyUnread(notificationParameters, parameterValue); break; default: logger.error("The notification parameters key [{}] exist but has not been implemented.", actualKey.name()); } } } if (notificationParameters.format == null) { notificationParameters.format = NotificationFormat.ALERT; } try { if (Boolean.parseBoolean(parameters.get(ParametersKey.USE_USER_PREFERENCES))) { this.useUserPreferences(notificationParameters); } else { this.dontUseUserPreferences(notificationParameters, parameters); } } catch (EventStreamException e) { throw new NotificationException("Error while adding the filters to the notification parameters.", e); } return notificationParameters; }  NotificationParameters createNotificationParametersWithStringMap(Map<String, String> parameters); NotificationParameters createNotificationParameters(Map<ParametersKey, String> parameters); void useUserPreferences(NotificationParameters parameters);  }