From 0eac3e8eae45dfa30856ab32283f1a2ec0b8db20 Mon Sep 17 00:00:00 2001 From: Kirs Date: Tue, 30 Nov 2021 16:06:59 +0800 Subject: [PATCH] [2.0.1-cherrypick]Fix-6941][API] Fix the failure of querying details of alert group (#6942) (#7066) * Fix the failure of querying details of alert group * code cleanup PR #6942 ISSUE #6941 Co-authored-by: Kerwin <37063904+zhuangchong@users.noreply.github.com> --- .../service/impl/AlertGroupServiceImpl.java | 30 +++---- .../api/service/AlertGroupServiceTest.java | 49 ++++------- .../dao/mapper/AlertGroupMapper.java | 9 -- .../dolphinscheduler/dao/vo/AlertGroupVo.java | 87 ------------------- .../dao/mapper/AlertGroupMapper.xml | 10 +-- 5 files changed, 30 insertions(+), 155 deletions(-) delete mode 100644 dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/vo/AlertGroupVo.java 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 887b9113a4..b210207b29 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 @@ -17,6 +17,9 @@ package org.apache.dolphinscheduler.api.service.impl; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.apache.commons.lang.StringUtils; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.service.AlertGroupService; import org.apache.dolphinscheduler.api.utils.PageInfo; @@ -25,15 +28,6 @@ import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.dao.entity.AlertGroup; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper; -import org.apache.dolphinscheduler.dao.vo.AlertGroupVo; - -import org.apache.commons.lang.StringUtils; - -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -41,8 +35,10 @@ import org.springframework.dao.DuplicateKeyException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * alert group service impl @@ -116,12 +112,12 @@ public class AlertGroupServiceImpl extends BaseServiceImpl implements AlertGroup return result; } - Page page = new Page<>(pageNo, pageSize); - IPage alertGroupVoIPage = alertGroupMapper.queryAlertGroupVo(page, searchVal); - PageInfo pageInfo = new PageInfo<>(pageNo, pageSize); - - pageInfo.setTotal((int) alertGroupVoIPage.getTotal()); - pageInfo.setTotalList(alertGroupVoIPage.getRecords()); + Page page = new Page<>(pageNo, pageSize); + IPage alertGroupIPage = alertGroupMapper.queryAlertGroupPage( + page, searchVal); + PageInfo pageInfo = new PageInfo<>(pageNo, pageSize); + pageInfo.setTotal((int) alertGroupIPage.getTotal()); + pageInfo.setTotalList(alertGroupIPage.getRecords()); result.setData(pageInfo); putMsg(result, Status.SUCCESS); 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 cbbeec634a..443b68e064 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 @@ -17,9 +17,9 @@ package org.apache.dolphinscheduler.api.service; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.apache.commons.collections.CollectionUtils; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; + import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.service.impl.AlertGroupServiceImpl; import org.apache.dolphinscheduler.api.utils.PageInfo; @@ -29,7 +29,13 @@ import org.apache.dolphinscheduler.common.enums.UserType; import org.apache.dolphinscheduler.dao.entity.AlertGroup; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper; -import org.apache.dolphinscheduler.dao.vo.AlertGroupVo; + +import org.apache.commons.collections.CollectionUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -41,12 +47,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.dao.DuplicateKeyException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; /** * alert group service test @@ -76,10 +78,10 @@ public class AlertGroupServiceTest { @Test public void testListPaging() { - IPage page = new Page<>(1, 10); + IPage page = new Page<>(1, 10); page.setTotal(1L); - page.setRecords(getAlertGroupVoList()); - Mockito.when(alertGroupMapper.queryAlertGroupVo(any(Page.class), eq(groupName))).thenReturn(page); + page.setRecords(getList()); + Mockito.when(alertGroupMapper.queryAlertGroupPage(any(Page.class), eq(groupName))).thenReturn(page); User user = new User(); // no operate Result result = alertGroupService.listPaging(user, groupName, 1, 10); @@ -89,7 +91,7 @@ public class AlertGroupServiceTest { user.setUserType(UserType.ADMIN_USER); result = alertGroupService.listPaging(user, groupName, 1, 10); logger.info(result.toString()); - PageInfo pageInfo = (PageInfo) result.getData(); + PageInfo pageInfo = (PageInfo) result.getData(); Assert.assertTrue(CollectionUtils.isNotEmpty(pageInfo.getTotalList())); } @@ -215,23 +217,4 @@ public class AlertGroupServiceTest { return alertGroup; } - /** - * get AlertGroupVo list - */ - private List getAlertGroupVoList() { - List alertGroupVos = new ArrayList<>(); - alertGroupVos.add(getAlertGroupVoEntity()); - return alertGroupVos; - } - - /** - * get AlertGroupVo entity - */ - private AlertGroupVo getAlertGroupVoEntity() { - AlertGroupVo alertGroupVo = new AlertGroupVo(); - alertGroupVo.setId(1); - alertGroupVo.setGroupName(groupName); - return alertGroupVo; - } - } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.java index 72eac71441..0e090f43e0 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.java @@ -18,7 +18,6 @@ package org.apache.dolphinscheduler.dao.mapper; import org.apache.dolphinscheduler.dao.entity.AlertGroup; -import org.apache.dolphinscheduler.dao.vo.AlertGroupVo; import org.apache.ibatis.annotations.Param; @@ -84,12 +83,4 @@ public interface AlertGroupMapper extends BaseMapper { */ String queryAlertGroupInstanceIdsById(@Param("alertGroupId") int alertGroupId); - /** - * query alertGroupVo page list - * @param page page - * @param groupName groupName - * @return IPage: include alert group id and group_name - */ - IPage queryAlertGroupVo(Page page, - @Param("groupName") String groupName); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/vo/AlertGroupVo.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/vo/AlertGroupVo.java deleted file mode 100644 index db9c9f50bc..0000000000 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/vo/AlertGroupVo.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.dao.vo; - -import java.util.Date; - -/** - * AlertGroupVo - */ -public class AlertGroupVo { - - /** - * primary key - */ - private int id; - /** - * group_name - */ - private String groupName; - /** - * description - */ - private String description; - /** - * create_time - */ - private Date createTime; - /** - * update_time - */ - private Date updateTime; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getGroupName() { - return groupName; - } - - public void setGroupName(String groupName) { - this.groupName = groupName; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Date getCreateTime() { - return createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } - - public Date getUpdateTime() { - return updateTime; - } - - public void setUpdateTime(Date updateTime) { - this.updateTime = updateTime; - } -} diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.xml index efdacb13de..521fdce41d 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.xml @@ -32,15 +32,7 @@ order by update_time desc - +