Repository: kylin Updated Branches: refs/heads/master d0c015b82 -> 7e6aa3471
KYLIN-2875 Cube e-mail notification Validation Signed-off-by: shaofengshi <shaofeng...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/7e6aa347 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/7e6aa347 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/7e6aa347 Branch: refs/heads/master Commit: 7e6aa347186560ff35b2ac2e2f75860a9ac70cc7 Parents: b8f2292 Author: sanjulian <julian....@hotmail.com> Authored: Thu Dec 7 18:28:47 2017 +0800 Committer: shaofengshi <shaofeng...@apache.org> Committed: Fri Dec 8 18:57:29 2017 +0800 ---------------------------------------------------------------------- core-cube/pom.xml | 4 ++++ .../java/org/apache/kylin/cube/CubeDescManager.java | 1 + .../java/org/apache/kylin/cube/model/CubeDesc.java | 13 +++++++++++++ .../java/org/apache/kylin/cube/CubeDescTest.java | 15 +++++++++++++++ pom.xml | 6 ++++++ .../apache/kylin/rest/service/CacheServiceTest.java | 2 +- webapp/app/js/controllers/cube.js | 6 +++++- 7 files changed, 45 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/7e6aa347/core-cube/pom.xml ---------------------------------------------------------------------- diff --git a/core-cube/pom.xml b/core-cube/pom.xml index 3712f88..2bd1ecd 100644 --- a/core-cube/pom.xml +++ b/core-cube/pom.xml @@ -70,6 +70,10 @@ <groupId>com.esotericsoftware</groupId> <artifactId>kryo-shaded</artifactId> </dependency> + <dependency> + <groupId>commons-validator</groupId> + <artifactId>commons-validator</artifactId> + </dependency> <!-- Env & Test --> <dependency> http://git-wip-us.apache.org/repos/asf/kylin/blob/7e6aa347/core-cube/src/main/java/org/apache/kylin/cube/CubeDescManager.java ---------------------------------------------------------------------- diff --git a/core-cube/src/main/java/org/apache/kylin/cube/CubeDescManager.java b/core-cube/src/main/java/org/apache/kylin/cube/CubeDescManager.java index b72332c..d522263 100644 --- a/core-cube/src/main/java/org/apache/kylin/cube/CubeDescManager.java +++ b/core-cube/src/main/java/org/apache/kylin/cube/CubeDescManager.java @@ -351,6 +351,7 @@ public class CubeDescManager { throw new IllegalArgumentException("CubeDesc '" + name + "' does not exist."); if (desc.isDraft()) throw new IllegalArgumentException("CubeDesc '" + desc.getName() + "' must not be a draft"); + desc.validateNotifyList(); try { desc.init(config); http://git-wip-us.apache.org/repos/asf/kylin/blob/7e6aa347/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java ---------------------------------------------------------------------- diff --git a/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java b/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java index 87a75da..5ff52c1 100644 --- a/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java +++ b/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java @@ -44,6 +44,7 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; +import org.apache.commons.validator.routines.EmailValidator; import org.apache.kylin.common.KylinConfig; import org.apache.kylin.common.KylinConfigExt; import org.apache.kylin.common.KylinVersion; @@ -817,6 +818,18 @@ public class CubeDesc extends RootPersistentEntity implements IEngineAware { } } + public void validateNotifyList() { + List<String> notifyList = getNotifyList(); + if (notifyList != null && !notifyList.isEmpty()) { + EmailValidator emailValidator = EmailValidator.getInstance(); + for (String email: notifyList) { + if (!emailValidator.isValid(email)) { + throw new IllegalArgumentException("Email [" + email + "] is not validation."); + } + } + } + } + private void getDims(Set<String> dims, String[] stringSet) { if (stringSet != null) { for (String str : stringSet) { http://git-wip-us.apache.org/repos/asf/kylin/blob/7e6aa347/core-cube/src/test/java/org/apache/kylin/cube/CubeDescTest.java ---------------------------------------------------------------------- diff --git a/core-cube/src/test/java/org/apache/kylin/cube/CubeDescTest.java b/core-cube/src/test/java/org/apache/kylin/cube/CubeDescTest.java index 9f0ae12..9986909 100644 --- a/core-cube/src/test/java/org/apache/kylin/cube/CubeDescTest.java +++ b/core-cube/src/test/java/org/apache/kylin/cube/CubeDescTest.java @@ -34,6 +34,7 @@ import java.util.Map.Entry; import java.util.Set; import java.util.TreeSet; +import com.google.common.collect.Lists; import org.apache.kylin.common.util.Array; import org.apache.kylin.common.util.JsonUtil; import org.apache.kylin.common.util.LocalFileMetadataTestCase; @@ -397,6 +398,19 @@ public class CubeDescTest extends LocalFileMetadataTestCase { } @Test + public void testValidateNotifyList() throws Exception{ + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Email [test] is not validation."); + + CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC); + List<String> notify = Lists.newArrayList(); + notify.add("test"); + cubeDesc.setNotifyList(notify); + cubeDesc.validateNotifyList(); + cubeDesc.init(getTestConfig()); + } + + @Test public void testSerialize() throws Exception { CubeDesc desc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC); String str = JsonUtil.writeValueAsIndentString(desc); @@ -493,4 +507,5 @@ public class CubeDescTest extends LocalFileMetadataTestCase { Assert.assertNotNull(lc); Assert.assertTrue(lc.getAllCuboids().size() > 0); } + } http://git-wip-us.apache.org/repos/asf/kylin/blob/7e6aa347/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 7a40076..eba302a 100644 --- a/pom.xml +++ b/pom.xml @@ -100,6 +100,7 @@ <!-- Commons --> <commons-lang3.version>3.4</commons-lang3.version> <commons-email.version>1.5</commons-email.version> + <commons-validator.version>1.4.0</commons-validator.version> <!-- Utility --> <log4j.version>1.2.17</log4j.version> @@ -640,6 +641,11 @@ <artifactId>commons-email</artifactId> <version>${commons-email.version}</version> </dependency> + <dependency> + <groupId>commons-validator</groupId> + <artifactId>commons-validator</artifactId> + <version>${commons-validator.version}</version> + </dependency> <!-- Logging --> <dependency> http://git-wip-us.apache.org/repos/asf/kylin/blob/7e6aa347/server/src/test/java/org/apache/kylin/rest/service/CacheServiceTest.java ---------------------------------------------------------------------- diff --git a/server/src/test/java/org/apache/kylin/rest/service/CacheServiceTest.java b/server/src/test/java/org/apache/kylin/rest/service/CacheServiceTest.java index d56cf6c..ff9e23d 100644 --- a/server/src/test/java/org/apache/kylin/rest/service/CacheServiceTest.java +++ b/server/src/test/java/org/apache/kylin/rest/service/CacheServiceTest.java @@ -274,7 +274,7 @@ public class CacheServiceTest extends LocalFileMetadataTestCase { assertNotNull(cubeDescManager.getCubeDesc(cubeDescName)); assertNotNull(cubeDescManagerB.getCubeDesc(cubeDescName)); - cubeDesc.setNotifyList(Arrays.asList("test@email", "test@email", "test@email")); + cubeDesc.setNotifyList(Arrays.asList("t...@email.com", "t...@email.com", "t...@email.com")); cubeDescManager.updateCubeDesc(cubeDesc); assertEquals(1, broadcaster.getCounterAndClear()); waitForCounterAndClear(1); http://git-wip-us.apache.org/repos/asf/kylin/blob/7e6aa347/webapp/app/js/controllers/cube.js ---------------------------------------------------------------------- diff --git a/webapp/app/js/controllers/cube.js b/webapp/app/js/controllers/cube.js index 26dddea..c0e5efb 100755 --- a/webapp/app/js/controllers/cube.js +++ b/webapp/app/js/controllers/cube.js @@ -69,7 +69,11 @@ KylinApp.controller('CubeCtrl', function ($scope, AccessService, MessageService, }; $scope.updateNotifyList = function (cube) { - cube.detail.notify_list = cube.notifyListString.split(","); + if (cube.notifyListString.length === 0) { + cube.detail.notify_list = []; + } else { + cube.detail.notify_list = cube.notifyListString.split(","); + } CubeService.updateNotifyList({cubeId: cube.name}, cube.detail.notify_list, function () { SweetAlert.swal('Success!', 'Notify List updated successfully!', 'success'); },function(e){