@Test public void handlerUsersParameter() { NotificationParameters notificationParameters = new NotificationParameters(); this.usersParameterHandler.handleUsersParameter(null, notificationParameters); assertEquals(new NotificationParameters(), notificationParameters); this.usersParameterHandler.handleUsersParameter("", notificationParameters); assertEquals(new NotificationParameters(), notificationParameters); DocumentReference fooRef = new DocumentReference("currentwiki", "XWiki", "Foo"); DocumentReference currentBarRef = new DocumentReference("currentwiki", "XWiki", "Bar"); DocumentReference defaultBarRef = new DocumentReference("xwiki", "XWiki", "Bar"); DocumentReference bazRef = new DocumentReference("otherwiki", "XWiki", "Baz"); when(this.currentDocumentReferenceResolver.resolve("XWiki.Foo")).thenReturn(fooRef); when(this.currentDocumentReferenceResolver.resolve("XWiki.Bar")).thenReturn(currentBarRef); when(this.currentDocumentReferenceResolver.resolve("otherwiki:XWiki.Baz")).thenReturn(bazRef); when(this.defaultDocumentReferenceResolver.resolve("XWiki.Bar")).thenReturn(defaultBarRef); when(this.documentAccessBridge.exists(fooRef)).thenReturn(true); when(this.documentAccessBridge.exists(currentBarRef)).thenReturn(false); when(this.documentAccessBridge.exists(defaultBarRef)).thenReturn(true); when(this.documentAccessBridge.exists(bazRef)).thenReturn(true); when(this.entityReferenceSerializer.serialize(fooRef)).thenReturn("currentwiki:XWiki.Foo"); when(this.entityReferenceSerializer.serialize(defaultBarRef)).thenReturn("xwiki:XWiki.Bar"); when(this.entityReferenceSerializer.serialize(bazRef)).thenReturn("otherwiki:XWiki.Baz"); List<NotificationFilter> notificationFilterList = Collections.singletonList( new FollowedUserOnlyEventFilter(entityReferenceSerializer, Arrays.asList( "currentwiki:XWiki.Foo", "xwiki:XWiki.Bar", "otherwiki:XWiki.Baz" )) ); List<NotificationFilterPreference> notificationFilterPreferenceList = Arrays.asList( getFilterPreference("currentwiki:XWiki.Foo"), getFilterPreference("xwiki:XWiki.Bar"), getFilterPreference("otherwiki:XWiki.Baz") ); NotificationParameters expectedParameters = new NotificationParameters(); expectedParameters.format = NotificationFormat.EMAIL; expectedParameters.filters = notificationFilterList; expectedParameters.filterPreferences = notificationFilterPreferenceList; notificationParameters.format = NotificationFormat.EMAIL; this.usersParameterHandler.handleUsersParameter("Foo,XWiki.Bar,otherwiki:XWiki.Baz", notificationParameters); assertEquals(expectedParameters, notificationParameters); }
public void handleUsersParameter(String users, NotificationParameters parameters) { if (StringUtils.isNotBlank(users)) { String[] userArray = users.split(FIELD_SEPARATOR); List<String> userList = new ArrayList<>(); for (int i = 0; i < userArray.length; ++i) { String user = userArray[i].trim(); if (!user.contains(".")) { user = "XWiki." + user; } DocumentReference userReference = currentDocumentReferenceResolver.resolve(user); if (documentAccessBridge.exists(userReference)) { userList.add(entityReferenceSerializer.serialize(userReference)); } else { userList.add(entityReferenceSerializer.serialize(defaultDocumentReferenceResolver.resolve(user))); } } parameters.filters.add(new FollowedUserOnlyEventFilter(entityReferenceSerializer, userList)); addFilterPreference(parameters, userList); } }
UsersParameterHandler { public void handleUsersParameter(String users, NotificationParameters parameters) { if (StringUtils.isNotBlank(users)) { String[] userArray = users.split(FIELD_SEPARATOR); List<String> userList = new ArrayList<>(); for (int i = 0; i < userArray.length; ++i) { String user = userArray[i].trim(); if (!user.contains(".")) { user = "XWiki." + user; } DocumentReference userReference = currentDocumentReferenceResolver.resolve(user); if (documentAccessBridge.exists(userReference)) { userList.add(entityReferenceSerializer.serialize(userReference)); } else { userList.add(entityReferenceSerializer.serialize(defaultDocumentReferenceResolver.resolve(user))); } } parameters.filters.add(new FollowedUserOnlyEventFilter(entityReferenceSerializer, userList)); addFilterPreference(parameters, userList); } } }
UsersParameterHandler { public void handleUsersParameter(String users, NotificationParameters parameters) { if (StringUtils.isNotBlank(users)) { String[] userArray = users.split(FIELD_SEPARATOR); List<String> userList = new ArrayList<>(); for (int i = 0; i < userArray.length; ++i) { String user = userArray[i].trim(); if (!user.contains(".")) { user = "XWiki." + user; } DocumentReference userReference = currentDocumentReferenceResolver.resolve(user); if (documentAccessBridge.exists(userReference)) { userList.add(entityReferenceSerializer.serialize(userReference)); } else { userList.add(entityReferenceSerializer.serialize(defaultDocumentReferenceResolver.resolve(user))); } } parameters.filters.add(new FollowedUserOnlyEventFilter(entityReferenceSerializer, userList)); addFilterPreference(parameters, userList); } }  }
UsersParameterHandler { public void handleUsersParameter(String users, NotificationParameters parameters) { if (StringUtils.isNotBlank(users)) { String[] userArray = users.split(FIELD_SEPARATOR); List<String> userList = new ArrayList<>(); for (int i = 0; i < userArray.length; ++i) { String user = userArray[i].trim(); if (!user.contains(".")) { user = "XWiki." + user; } DocumentReference userReference = currentDocumentReferenceResolver.resolve(user); if (documentAccessBridge.exists(userReference)) { userList.add(entityReferenceSerializer.serialize(userReference)); } else { userList.add(entityReferenceSerializer.serialize(defaultDocumentReferenceResolver.resolve(user))); } } parameters.filters.add(new FollowedUserOnlyEventFilter(entityReferenceSerializer, userList)); addFilterPreference(parameters, userList); } }  void handleUsersParameter(String users, NotificationParameters parameters); }
UsersParameterHandler { public void handleUsersParameter(String users, NotificationParameters parameters) { if (StringUtils.isNotBlank(users)) { String[] userArray = users.split(FIELD_SEPARATOR); List<String> userList = new ArrayList<>(); for (int i = 0; i < userArray.length; ++i) { String user = userArray[i].trim(); if (!user.contains(".")) { user = "XWiki." + user; } DocumentReference userReference = currentDocumentReferenceResolver.resolve(user); if (documentAccessBridge.exists(userReference)) { userList.add(entityReferenceSerializer.serialize(userReference)); } else { userList.add(entityReferenceSerializer.serialize(defaultDocumentReferenceResolver.resolve(user))); } } parameters.filters.add(new FollowedUserOnlyEventFilter(entityReferenceSerializer, userList)); addFilterPreference(parameters, userList); } }  void handleUsersParameter(String users, NotificationParameters parameters);  }