From 5fa1c4e7e3d2b0ea8ec30e6981c0ca9997cfaa29 Mon Sep 17 00:00:00 2001 From: ouyangyewei Date: Sun, 13 Mar 2022 21:20:36 +0800 Subject: [PATCH] [Feature][dolphinscheduler-api] Return domain object after creating success (#8825) Co-authored-by: ouyangyewei --- .../api/service/impl/AlertGroupServiceImpl.java | 7 ++++++- .../api/service/impl/AlertPluginInstanceServiceImpl.java | 2 +- .../api/service/AlertGroupServiceTest.java | 1 + .../api/service/AlertPluginInstanceServiceTest.java | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java index 2e319204f6..afd0846d11 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java @@ -157,7 +157,12 @@ public class AlertGroupServiceImpl extends BaseServiceImpl implements AlertGroup // insert try { int insert = alertGroupMapper.insert(alertGroup); - putMsg(result, insert > 0 ? Status.SUCCESS : Status.CREATE_ALERT_GROUP_ERROR); + if (insert > 0) { + result.put(Constants.DATA_LIST, alertGroup); + putMsg(result, Status.SUCCESS); + } else { + putMsg(result, Status.CREATE_ALERT_GROUP_ERROR); + } } catch (DuplicateKeyException ex) { logger.error("Create alert group error.", ex); putMsg(result, Status.ALERT_GROUP_EXIST); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertPluginInstanceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertPluginInstanceServiceImpl.java index ec55880b4c..0848968635 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertPluginInstanceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertPluginInstanceServiceImpl.java @@ -91,8 +91,8 @@ public class AlertPluginInstanceServiceImpl extends BaseServiceImpl implements A } int i = alertPluginInstanceMapper.insert(alertPluginInstance); - if (i > 0) { + result.put(Constants.DATA_LIST, alertPluginInstance); putMsg(result, Status.SUCCESS); return result; } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java index 443b68e064..b78e32995c 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java @@ -110,6 +110,7 @@ public class AlertGroupServiceTest { result = alertGroupService.createAlertgroup(user, groupName, groupName, null); logger.info(result.toString()); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); + Assert.assertNotNull(result.get(Constants.DATA_LIST)); } @Test diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java index 071d59bfe8..bb36487a85 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java @@ -163,6 +163,7 @@ public class AlertPluginInstanceServiceTest { Mockito.when(alertPluginInstanceMapper.insert(Mockito.any())).thenReturn(1); result = alertPluginInstanceService.create(user, 1, "test1", uiParams); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); + Assert.assertNotNull(result.get(Constants.DATA_LIST)); } @Test