From ff9965b2e7e55663b9845b22ccdcca724a34d14e Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Mon, 27 Jul 2020 16:42:12 +0800 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20=E5=AF=BC=E5=85=A5=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E6=97=B6=EF=BC=8C=E7=94=A8=E4=BE=8B=E6=89=80=E6=9C=89?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=80=BC=E9=83=BD=E7=9B=B8=E5=90=8C=E6=89=8D?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E7=94=A8=E4=BE=8B=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../excel/listener/EasyExcelListener.java | 3 ++ .../excel/listener/TestCaseDataListener.java | 47 +++++++++++++++---- .../track/service/TestCaseService.java | 26 ++++++++-- 3 files changed, 63 insertions(+), 13 deletions(-) diff --git a/backend/src/main/java/io/metersphere/excel/listener/EasyExcelListener.java b/backend/src/main/java/io/metersphere/excel/listener/EasyExcelListener.java index 30d6186fd7..04c6f00074 100644 --- a/backend/src/main/java/io/metersphere/excel/listener/EasyExcelListener.java +++ b/backend/src/main/java/io/metersphere/excel/listener/EasyExcelListener.java @@ -7,6 +7,7 @@ import com.alibaba.excel.exception.ExcelAnalysisException; import com.alibaba.excel.util.StringUtils; import io.metersphere.commons.utils.LogUtil; import io.metersphere.excel.domain.ExcelErrData; +import io.metersphere.excel.domain.TestCaseExcelData; import io.metersphere.excel.utils.EasyExcelI18nTranslator; import io.metersphere.excel.utils.ExcelValidateHelper; import io.metersphere.i18n.Translator; @@ -24,6 +25,8 @@ public abstract class EasyExcelListener extends AnalysisEventListener { protected EasyExcelI18nTranslator easyExcelI18nTranslator; + protected List excelDataList = new ArrayList<>(); + /** * 每隔2000条存储数据库,然后清理list ,方便内存回收 */ diff --git a/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java b/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java index 8a200615d9..c5efa2da88 100644 --- a/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java +++ b/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java @@ -10,10 +10,7 @@ import io.metersphere.i18n.Translator; import io.metersphere.track.service.TestCaseService; import org.apache.commons.lang3.StringUtils; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -57,10 +54,35 @@ public class TestCaseDataListener extends EasyExcelListener { if (!userIds.contains(data.getMaintainer())) { stringBuilder.append(Translator.get("user_not_exists") + ":" + data.getMaintainer() + "; "); } + if (testCaseNames.contains(data.getName())) { - stringBuilder.append(Translator.get("test_case_already_exists_excel") + ":" + data.getName() + "; "); + TestCaseWithBLOBs testCase = new TestCaseWithBLOBs(); + BeanUtils.copyBean(testCase, data); + testCase.setProjectId(projectId); + String steps = getSteps(data); + testCase.setSteps(steps); + + boolean dbExist = testCaseService.exist(testCase); + boolean excelExist = false; + + if (dbExist) { + // db exist + stringBuilder.append(Translator.get("test_case_already_exists_excel") + ":" + data.getName() + "; "); + } else { + // @Data 重写了 equals 和 hashCode 方法 + excelExist = excelDataList.contains(data); + } + + if (excelExist) { + // excel exist + stringBuilder.append(Translator.get("test_case_already_exists_excel") + ":" + data.getName() + "; "); + } else { + excelDataList.add(data); + } + } else { testCaseNames.add(data.getName()); + excelDataList.add(data); } return stringBuilder.toString(); } @@ -103,6 +125,13 @@ public class TestCaseDataListener extends EasyExcelListener { testCase.setNodePath(nodePath); + String steps = getSteps(data); + testCase.setSteps(steps); + + return testCase; + } + + public String getSteps(TestCaseExcelData data) { JSONArray jsonArray = new JSONArray(); String[] stepDesc = new String[1]; @@ -124,7 +153,8 @@ public class TestCaseDataListener extends EasyExcelListener { for (int i = 0; i < index; i++) { - JSONObject step = new JSONObject(); + // 保持插入顺序,判断用例是否有相同的steps + JSONObject step = new JSONObject(true); step.put("num", i + 1); Pattern descPattern = Pattern.compile(pattern); @@ -150,10 +180,7 @@ public class TestCaseDataListener extends EasyExcelListener { jsonArray.add(step); } - - testCase.setSteps(jsonArray.toJSONString()); - - return testCase; + return jsonArray.toJSONString(); } } diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index 7307ca7d52..27ab4b3248 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -106,13 +106,16 @@ public class TestCaseService { TestCaseExample.Criteria criteria = example.createCriteria(); criteria.andNameEqualTo(testCase.getName()) .andProjectIdEqualTo(testCase.getProjectId()) - .andNodeIdEqualTo(testCase.getNodeId()) .andNodePathEqualTo(testCase.getNodePath()) .andTypeEqualTo(testCase.getType()) .andMaintainerEqualTo(testCase.getMaintainer()) .andPriorityEqualTo(testCase.getPriority()) .andMethodEqualTo(testCase.getMethod()); +// if (StringUtils.isNotBlank(testCase.getNodeId())) { +// criteria.andNodeIdEqualTo(testCase.getTestId()); +// } + if (StringUtils.isNotBlank(testCase.getTestId())) { criteria.andTestIdEqualTo(testCase.getTestId()); } @@ -371,8 +374,8 @@ public class TestCaseService { JSONArray jsonArray = JSON.parseArray(steps); for (int j = 0; j < jsonArray.size(); j++) { int num = j + 1; - step.append(num + ":" + jsonArray.getJSONObject(j).getString("desc") + "\n"); - result.append(num + ":" + jsonArray.getJSONObject(j).getString("result") + "\n"); + step.append(num + "." + jsonArray.getJSONObject(j).getString("desc") + "\n"); + result.append(num + "." + jsonArray.getJSONObject(j).getString("result") + "\n"); } data.setStepDesc(step.toString()); @@ -471,4 +474,21 @@ public class TestCaseService { return Optional.ofNullable(testCase.getNum() + 1).orElse(100001); } } + + + /** + * 导入用例前,检查数据库是否存在此用例 + * @param testCaseWithBLOBs + * @return + */ + public boolean exist(TestCaseWithBLOBs testCaseWithBLOBs) { + + try { + checkTestCaseExist(testCaseWithBLOBs); + } catch (MSException e) { + return true; + } + + return false; + } } From 5bf3f355f5240c9b8db98eefbe8d753528843e34 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Mon, 27 Jul 2020 18:09:34 +0800 Subject: [PATCH 2/8] =?UTF-8?q?feat:=20=E5=90=AF=E7=94=A8LDAP=E8=AE=A4?= =?UTF-8?q?=E8=AF=81=E5=90=8E=E6=89=8D=E6=98=BE=E7=A4=BALDAP=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/metersphere/config/ShiroConfig.java | 1 + .../ldap/controller/LdapController.java | 10 ++++++---- .../io/metersphere/ldap/service/LdapService.java | 15 +++++++++------ frontend/src/login/Login.vue | 10 +++++++--- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/backend/src/main/java/io/metersphere/config/ShiroConfig.java b/backend/src/main/java/io/metersphere/config/ShiroConfig.java index f668f89d8e..a5b65170cf 100644 --- a/backend/src/main/java/io/metersphere/config/ShiroConfig.java +++ b/backend/src/main/java/io/metersphere/config/ShiroConfig.java @@ -48,6 +48,7 @@ public class ShiroConfig implements EnvironmentAware { filterChainDefinitionMap.put("/", "anon"); filterChainDefinitionMap.put("/signin", "anon"); filterChainDefinitionMap.put("/ldap/signin", "anon"); + filterChainDefinitionMap.put("/ldap/open", "anon"); filterChainDefinitionMap.put("/isLogin", "anon"); filterChainDefinitionMap.put("/css/**", "anon"); filterChainDefinitionMap.put("/js/**", "anon"); diff --git a/backend/src/main/java/io/metersphere/ldap/controller/LdapController.java b/backend/src/main/java/io/metersphere/ldap/controller/LdapController.java index e14bbb3b3d..0a4f0ded72 100644 --- a/backend/src/main/java/io/metersphere/ldap/controller/LdapController.java +++ b/backend/src/main/java/io/metersphere/ldap/controller/LdapController.java @@ -13,10 +13,7 @@ import io.metersphere.service.UserService; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; import org.springframework.ldap.core.DirContextOperations; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -82,4 +79,9 @@ public class LdapController { ldapService.authenticate(request); } + @GetMapping("/open") + public boolean isOpen() { + return ldapService.isOpen(); + } + } diff --git a/backend/src/main/java/io/metersphere/ldap/service/LdapService.java b/backend/src/main/java/io/metersphere/ldap/service/LdapService.java index 123008ea32..7ac413725e 100644 --- a/backend/src/main/java/io/metersphere/ldap/service/LdapService.java +++ b/backend/src/main/java/io/metersphere/ldap/service/LdapService.java @@ -92,9 +92,7 @@ public class LdapService { if (result.size() == 1) { return result.get(0); } - } catch (NameNotFoundException e) { - MSException.throwException(Translator.get("login_fail_ou_error")); - } catch (InvalidNameException e) { + } catch (NameNotFoundException | InvalidNameException e) { MSException.throwException(Translator.get("login_fail_ou_error")); } catch (InvalidSearchFilterException e) { MSException.throwException(Translator.get("login_fail_filter_error")); @@ -125,9 +123,7 @@ public class LdapService { MSException.throwException(Translator.get("ldap_ou_is_null")); } - String[] arr = ou.split("\\|"); - - return arr; + return ou.split("\\|"); } private static class MsContextMapper extends AbstractContextMapper { @@ -217,4 +213,11 @@ public class LdapService { return result; } + public boolean isOpen() { + String open = service.getValue(ParamConstants.LDAP.OPEN.getValue()); + if (StringUtils.isBlank(open)) { + return false; + } + return StringUtils.equals(Boolean.TRUE.toString(), open); + } } diff --git a/frontend/src/login/Login.vue b/frontend/src/login/Login.vue index f59cf45b8f..4e28b5c8c0 100644 --- a/frontend/src/login/Login.vue +++ b/frontend/src/login/Login.vue @@ -17,7 +17,7 @@
- LDAP + LDAP 普通登录 @@ -81,7 +81,8 @@ ] }, msg: '', - ready: false + ready: false, + openLdap: false } }, beforeCreate() { @@ -92,6 +93,9 @@ window.location.href = "/" } }); + this.$get("/ldap/open", response => { + this.openLdap = response.data; + }) }, created: function () { // 主页添加键盘事件,注意,不能直接在焦点事件上添加回车 @@ -145,7 +149,7 @@ if (!language) { this.$get("language", response => { language = response.data; - localStorage.setItem(DEFAULT_LANGUAGE, language) + localStorage.setItem(DEFAULT_LANGUAGE, language); window.location.href = "/" }) } else { From 70a45fe80757d17d4e8ade8004b3df8ab22f15ad Mon Sep 17 00:00:00 2001 From: q4speed Date: Tue, 28 Jul 2020 10:36:35 +0800 Subject: [PATCH 3/8] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0loading=E7=9A=84=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/api/report/ApiReportView.vue | 216 +++++++++--------- frontend/src/i18n/en-US.js | 1 + frontend/src/i18n/zh-CN.js | 1 + frontend/src/i18n/zh-TW.js | 1 + 4 files changed, 111 insertions(+), 108 deletions(-) diff --git a/frontend/src/business/components/api/report/ApiReportView.vue b/frontend/src/business/components/api/report/ApiReportView.vue index bf8ed1dc1a..d1f4323b5e 100644 --- a/frontend/src/business/components/api/report/ApiReportView.vue +++ b/frontend/src/business/components/api/report/ApiReportView.vue @@ -1,12 +1,12 @@ diff --git a/frontend/src/business/components/api/test/components/request/dubbo/RegistryCenter.vue b/frontend/src/business/components/api/test/components/request/dubbo/RegistryCenter.vue index 1ec24150a8..eb5b0efc90 100644 --- a/frontend/src/business/components/api/test/components/request/dubbo/RegistryCenter.vue +++ b/frontend/src/business/components/api/test/components/request/dubbo/RegistryCenter.vue @@ -1,10 +1,10 @@ From e64ada7ae9085907f443000cdd1cd0c5004a104c Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Tue, 28 Jul 2020 13:36:54 +0800 Subject: [PATCH 6/8] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=8D=E5=81=9C?= =?UTF-8?q?=E7=9A=84=E8=BE=93=E5=87=BAdubbo=E6=97=A5=E5=BF=97=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/resources/logback.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/resources/logback.xml b/backend/src/main/resources/logback.xml index 46b9eb3122..33df3bdf25 100644 --- a/backend/src/main/resources/logback.xml +++ b/backend/src/main/resources/logback.xml @@ -157,6 +157,6 @@ - + \ No newline at end of file From ec424af9afa7867a5cf9183a1d097507d18c4c50 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Tue, 28 Jul 2020 13:54:27 +0800 Subject: [PATCH 7/8] =?UTF-8?q?refactor(deps):=20=E5=8E=BB=E6=8E=89POM?= =?UTF-8?q?=E4=B8=AD=E7=9A=84slf4j?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes 155 --- backend/pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/backend/pom.xml b/backend/pom.xml index 430247e92e..3ab3754b2b 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -126,10 +126,6 @@ 1.2.72 - - org.slf4j - slf4j-simple - org.springdoc From 665700d03ff0cdb5dc751da483c624b4cabb62f6 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Tue, 28 Jul 2020 14:35:43 +0800 Subject: [PATCH 8/8] =?UTF-8?q?feat(deps):=20=E5=A2=9E=E5=8A=A0actuator?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=9C=8D=E5=8A=A1=E7=9B=91=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes 156 --- backend/pom.xml | 5 +++++ backend/src/main/java/io/metersphere/Application.java | 6 +++++- backend/src/main/resources/application.properties | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/backend/pom.xml b/backend/pom.xml index 3ab3754b2b..3fa8e2a12d 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -44,6 +44,11 @@ spring-boot-starter + + org.springframework.boot + spring-boot-starter-actuator + + org.springframework.boot spring-boot-starter-test diff --git a/backend/src/main/java/io/metersphere/Application.java b/backend/src/main/java/io/metersphere/Application.java index 5c697419a6..3e9715e775 100644 --- a/backend/src/main/java/io/metersphere/Application.java +++ b/backend/src/main/java/io/metersphere/Application.java @@ -4,13 +4,17 @@ import io.metersphere.config.JmeterProperties; import io.metersphere.config.KafkaProperties; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration; import org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.context.annotation.PropertySource; import org.springframework.scheduling.annotation.EnableScheduling; -@SpringBootApplication(exclude = {QuartzAutoConfiguration.class}) +@SpringBootApplication(exclude = { + QuartzAutoConfiguration.class, + LdapAutoConfiguration.class +}) @ServletComponentScan @EnableConfigurationProperties({ KafkaProperties.class, diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 4a02c75933..6ca797fc77 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -74,3 +74,7 @@ quartz.scheduler-name=msServerJob spring.servlet.multipart.max-file-size=30MB spring.servlet.multipart.max-request-size=30MB +# actuator +management.server.port=8083 +management.endpoints.web.exposure.include=* +