From cd42469860e45be0a35f3ff07960c57cfd1ba27d Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 17 Sep 2020 19:37:28 +0800 Subject: [PATCH 1/9] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20swagger=20=E5=AF=BC=E5=85=A5=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/api/parse/Swagger2Parser.java | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java b/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java index 399efb3f6e..a982f5798a 100644 --- a/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java +++ b/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java @@ -159,32 +159,34 @@ public class Swagger2Parser extends ApiImportAbstractParser { private JSONObject getBodyJSONObjectParameters(Map properties, Map definitions, HashSet refSet) { JSONObject jsonObject = new JSONObject(); - properties.forEach((key, value) -> { - if (value instanceof ObjectProperty) { - ObjectProperty objectProperty = (ObjectProperty) value; - jsonObject.put(key, getBodyJSONObjectParameters(objectProperty.getProperties(), definitions, refSet)); - } else if (value instanceof ArrayProperty) { - ArrayProperty arrayProperty = (ArrayProperty) value; - Property items = arrayProperty.getItems(); - if (items instanceof RefProperty) { - RefProperty refProperty = (RefProperty) items; - String simpleRef = refProperty.getSimpleRef(); - if (refSet.contains(simpleRef)) { - jsonObject.put(key, new JSONArray()); - return; + if (properties != null) { + properties.forEach((key, value) -> { + if (value instanceof ObjectProperty) { + ObjectProperty objectProperty = (ObjectProperty) value; + jsonObject.put(key, getBodyJSONObjectParameters(objectProperty.getProperties(), definitions, refSet)); + } else if (value instanceof ArrayProperty) { + ArrayProperty arrayProperty = (ArrayProperty) value; + Property items = arrayProperty.getItems(); + if (items instanceof RefProperty) { + RefProperty refProperty = (RefProperty) items; + String simpleRef = refProperty.getSimpleRef(); + if (refSet.contains(simpleRef)) { + jsonObject.put(key, new JSONArray()); + return; + } + refSet.add(simpleRef); + Model model = definitions.get(simpleRef); + JSONArray propertyList = new JSONArray(); + propertyList.add(getBodyJSONObjectParameters(model.getProperties(), definitions, refSet)); + jsonObject.put(key, propertyList); + } else { + jsonObject.put(key, new ArrayList<>()); } - refSet.add(simpleRef); - Model model = definitions.get(simpleRef); - JSONArray propertyList = new JSONArray(); - propertyList.add(getBodyJSONObjectParameters(model.getProperties(), definitions, refSet)); - jsonObject.put(key, propertyList); } else { - jsonObject.put(key, new ArrayList<>()); + jsonObject.put(key, Optional.ofNullable(value.getDescription()).orElse("")); } - } else { - jsonObject.put(key, Optional.ofNullable(value.getDescription()).orElse("")); - } - }); + }); + } return jsonObject; } From d78cdd45e64f220f434251523ff5efea560c8beb Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 17 Sep 2020 21:10:54 +0800 Subject: [PATCH 2/9] =?UTF-8?q?fix:=20AutoCloseable=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/parse/ApiImportAbstractParser.java | 9 ++------- .../excel/listener/EasyExcelListener.java | 4 +++- .../excel/utils/EasyExcelExporter.java | 4 ++-- .../track/service/TestCaseService.java | 18 +++--------------- 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java b/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java index d39b963607..b725ffb06d 100644 --- a/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java +++ b/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java @@ -9,10 +9,7 @@ import io.metersphere.commons.utils.LogUtil; import org.apache.commons.lang3.StringUtils; import org.eclipse.jetty.http.HttpHeader; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; +import java.io.*; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -21,10 +18,8 @@ import java.util.Optional; public abstract class ApiImportAbstractParser implements ApiImportParser { protected String getApiTestStr(InputStream source) { - BufferedReader bufferedReader; StringBuilder testStr = null; - try { - bufferedReader = new BufferedReader(new InputStreamReader(source, StandardCharsets.UTF_8)); + try(BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(source, StandardCharsets.UTF_8))) { testStr = new StringBuilder(); String inputStr; while ((inputStr = bufferedReader.readLine()) != null) { 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 04c6f00074..9bb8f6e96e 100644 --- a/backend/src/main/java/io/metersphere/excel/listener/EasyExcelListener.java +++ b/backend/src/main/java/io/metersphere/excel/listener/EasyExcelListener.java @@ -17,7 +17,7 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.*; -public abstract class EasyExcelListener extends AnalysisEventListener { +public abstract class EasyExcelListener extends AnalysisEventListener implements AutoCloseable { protected List> errList = new ArrayList<>(); @@ -153,6 +153,8 @@ public abstract class EasyExcelListener extends AnalysisEventListener { return errList; } + + @Override public void close() { this.easyExcelI18nTranslator.resetExcelProperty(); } diff --git a/backend/src/main/java/io/metersphere/excel/utils/EasyExcelExporter.java b/backend/src/main/java/io/metersphere/excel/utils/EasyExcelExporter.java index 5a6b39fd20..b2b4d6fe0d 100644 --- a/backend/src/main/java/io/metersphere/excel/utils/EasyExcelExporter.java +++ b/backend/src/main/java/io/metersphere/excel/utils/EasyExcelExporter.java @@ -5,7 +5,6 @@ import com.alibaba.excel.write.metadata.style.WriteCellStyle; import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; import io.metersphere.commons.utils.LogUtil; import io.metersphere.exception.ExcelException; -import org.apache.poi.ss.usermodel.IndexedColors; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @@ -13,7 +12,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.List; -public class EasyExcelExporter { +public class EasyExcelExporter implements AutoCloseable { EasyExcelI18nTranslator easyExcelI18nTranslator; @@ -47,6 +46,7 @@ public class EasyExcelExporter { } } + @Override public void close() { easyExcelI18nTranslator.resetExcelProperty(); } 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 d6005b3409..f722d5263b 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -273,16 +273,12 @@ public class TestCaseService { Set userIds = userRoleMapper.selectByExample(userRoleExample).stream().map(UserRole::getUserId).collect(Collectors.toSet()); - EasyExcelListener easyExcelListener = null; - try { - easyExcelListener = new TestCaseDataListener(this, projectId, testCaseNames, userIds); + try (EasyExcelListener easyExcelListener = new TestCaseDataListener(this, projectId, testCaseNames, userIds)) { EasyExcelFactory.read(multipartFile.getInputStream(), TestCaseExcelData.class, easyExcelListener).sheet().doRead(); errList = easyExcelListener.getErrList(); } catch (Exception e) { LogUtil.error(e.getMessage(), e); MSException.throwException(e.getMessage()); - } finally { - easyExcelListener.close(); } } @@ -316,15 +312,11 @@ public class TestCaseService { } public void testCaseTemplateExport(HttpServletResponse response) { - EasyExcelExporter easyExcelExporter = null; - try { - easyExcelExporter = new EasyExcelExporter(TestCaseExcelData.class); + try (EasyExcelExporter easyExcelExporter = new EasyExcelExporter(TestCaseExcelData.class)) { easyExcelExporter.export(response, generateExportTemplate(), Translator.get("test_case_import_template_name"), Translator.get("test_case_import_template_sheet")); } catch (Exception e) { MSException.throwException(e); - } finally { - easyExcelExporter.close(); } } @@ -398,15 +390,11 @@ public class TestCaseService { } public void testCaseExport(HttpServletResponse response, TestCaseBatchRequest request) { - EasyExcelExporter easyExcelExporter = null; - try { - easyExcelExporter = new EasyExcelExporter(TestCaseExcelData.class); + try (EasyExcelExporter easyExcelExporter = new EasyExcelExporter(TestCaseExcelData.class)) { easyExcelExporter.export(response, generateTestCaseExcel(request), Translator.get("test_case_import_template_name"), Translator.get("test_case_import_template_sheet")); } catch (Exception e) { MSException.throwException(e); - } finally { - easyExcelExporter.close(); } } From 98a46cc5f4e29d428477ef29a68f5e96e7e0b411 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 17 Sep 2020 21:19:29 +0800 Subject: [PATCH 3/9] =?UTF-8?q?fix:=20shiro=20=E5=8D=87=E7=BA=A7=E8=87=B3?= =?UTF-8?q?=201.6.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/pom.xml b/backend/pom.xml index a54a86c0df..ef2af712b3 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -15,7 +15,7 @@ UTF-8 - 1.5.1 + 1.6.0 1.8 5.2.1 1.1.3 From 5c9c645016eaecf1448bb69617ea3a855786bfcb Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Thu, 17 Sep 2020 21:27:02 +0800 Subject: [PATCH 4/9] =?UTF-8?q?fix(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E5=88=9B=E5=BB=BA=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=97=B6ID=E5=90=AB=E4=B8=AD=E6=96=87=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/io/metersphere/xpack | 2 +- frontend/src/business/components/settings/system/User.vue | 1 + frontend/src/business/components/xpack | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index d5b4969642..321c869938 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit d5b4969642fd8d10cc2f949d7377e0a0e5217a3a +Subproject commit 321c869938357e8c2253e5bd86c963828664ae23 diff --git a/frontend/src/business/components/settings/system/User.vue b/frontend/src/business/components/settings/system/User.vue index 02ea001e4f..ee0aec578b 100644 --- a/frontend/src/business/components/settings/system/User.vue +++ b/frontend/src/business/components/settings/system/User.vue @@ -342,6 +342,7 @@ {min: 2, max: 50, message: this.$t('commons.input_limit', [2, 50]), trigger: 'blur'}, { required: true, + pattern: '^[^\u4e00-\u9fa5]+$', message: this.$t('user.special_characters_are_not_supported'), trigger: 'blur' } diff --git a/frontend/src/business/components/xpack b/frontend/src/business/components/xpack index 0a375848d0..f2d5a342c8 160000 --- a/frontend/src/business/components/xpack +++ b/frontend/src/business/components/xpack @@ -1 +1 @@ -Subproject commit 0a375848d034d20eaf05caf11769e1c75c39235c +Subproject commit f2d5a342c82e629f510550d5778d752bb73bf5e7 From 89e5c55add4c4085ae4036a0928c85e50d0f575d Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Thu, 17 Sep 2020 21:41:52 +0800 Subject: [PATCH 5/9] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):?= =?UTF-8?q?=20=E6=8F=90=E7=BC=BA=E9=99=B7=E6=97=B6=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=AE=9E=E9=99=85=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../track/plan/view/comonents/TestPlanTestCaseEdit.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseEdit.vue b/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseEdit.vue index 8731050c0c..3997725bc3 100644 --- a/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseEdit.vue +++ b/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseEdit.vue @@ -490,14 +490,14 @@ if (this.issuesSwitch) { let desc = this.addPLabel('[' + this.$t('test_track.plan_view.operate_step') + ']'); let result = this.addPLabel('[' + this.$t('test_track.case.expected_results') + ']'); - let executeResult = this.addPLabel('[' + this.$t('test_track.plan_view.actual_result') + ']'); + let actualResult = this.addPLabel('[' + this.$t('test_track.plan_view.actual_result') + ']'); this.testCase.steps.forEach(step => { let stepPrefix = this.$t('test_track.plan_view.step') + step.num + ':'; desc += this.addPLabel(stepPrefix + (step.desc == undefined ? '' : step.desc)); result += this.addPLabel(stepPrefix + (step.result == undefined ? '' : step.result)); - executeResult += this.addPLabel(stepPrefix + (step.executeResult == undefined ? '' : step.executeResult)); + actualResult += this.addPLabel(stepPrefix + (step.actualResult == undefined ? '' : step.actualResult)); }); - this.testCase.issues.content = desc + this.addPLabel('') + result + this.addPLabel('') + executeResult + this.addPLabel(''); + this.testCase.issues.content = desc + this.addPLabel('') + result + this.addPLabel('') + actualResult + this.addPLabel(''); this.$get("/test/case/project/" + this.testCase.caseId, res => { const project = res.data; From fbbd9439901c61f69c6647ebf53ead11a43f6a9b Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 17 Sep 2020 21:45:31 +0800 Subject: [PATCH 6/9] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20GET=20=E8=AF=B7=E6=B1=82=E6=94=AF=E6=8C=81=20body?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/test/components/request/ApiHttpRequestForm.vue | 5 +---- .../test/components/request/condition/ConditionLabel.vue | 6 +++--- .../business/components/api/test/model/ScenarioModel.js | 7 ++----- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/frontend/src/business/components/api/test/components/request/ApiHttpRequestForm.vue b/frontend/src/business/components/api/test/components/request/ApiHttpRequestForm.vue index 0bbb5cb7a5..2749261bb4 100644 --- a/frontend/src/business/components/api/test/components/request/ApiHttpRequestForm.vue +++ b/frontend/src/business/components/api/test/components/request/ApiHttpRequestForm.vue @@ -57,7 +57,7 @@ - + + v-if="request.controller && request.controller.isValid()">
{{ request.controller.label() }}
@@ -16,10 +16,10 @@ + v-if="request.timer && request.timer.isValid()"> -
{{ request.timer.label() }}
+
{{ request.timer && request.timer.label() }}
diff --git a/frontend/src/business/components/api/test/model/ScenarioModel.js b/frontend/src/business/components/api/test/model/ScenarioModel.js index f8186e3bc5..cb669f3477 100644 --- a/frontend/src/business/components/api/test/model/ScenarioModel.js +++ b/frontend/src/business/components/api/test/model/ScenarioModel.js @@ -1065,11 +1065,8 @@ class JMXGenerator { } else if (request instanceof HttpRequest) { sampler = new HTTPSamplerProxy(request.name || "", new JMXHttpRequest(request, scenario.environment)); this.addRequestHeader(sampler, request); - if (request.method.toUpperCase() === 'GET') { - this.addRequestArguments(sampler, request); - } else { - this.addRequestBody(sampler, request, testId); - } + this.addRequestArguments(sampler, request); + this.addRequestBody(sampler, request, testId); } else if (request instanceof SqlRequest) { request.dataSource = scenario.databaseConfigMap.get(request.dataSource); sampler = new JDBCSampler(request.name || "", request); From 0952b270a1826c0f6aa2c54562dd07902afd024d Mon Sep 17 00:00:00 2001 From: q4speed Date: Fri, 18 Sep 2020 10:40:15 +0800 Subject: [PATCH 7/9] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E6=B5=8F=E8=A7=88=E5=99=A8=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E5=BD=95=E5=88=B6=E7=9A=84=E8=84=9A=E6=9C=AC=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=88=B0=E6=B5=8B=E8=AF=95=E5=B9=B3=E5=8F=B0=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E6=8E=A5=E5=8F=A3=E9=A1=BA=E5=BA=8F=E5=8F=91=E7=94=9F?= =?UTF-8?q?=E5=8F=98=E5=8C=96=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #396 --- backend/src/main/java/io/metersphere/api/parse/MsParser.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/io/metersphere/api/parse/MsParser.java b/backend/src/main/java/io/metersphere/api/parse/MsParser.java index 4e9c90f5b5..065a4e8da1 100644 --- a/backend/src/main/java/io/metersphere/api/parse/MsParser.java +++ b/backend/src/main/java/io/metersphere/api/parse/MsParser.java @@ -3,6 +3,7 @@ package io.metersphere.api.parse; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.parser.Feature; import io.metersphere.api.dto.ApiTestImportRequest; import io.metersphere.api.dto.parse.ApiImport; import io.metersphere.api.dto.scenario.request.RequestType; @@ -23,7 +24,7 @@ public class MsParser extends ApiImportAbstractParser { } private String parsePluginFormat(String testStr) { - JSONObject testObject = JSONObject.parseObject(testStr); + JSONObject testObject = JSONObject.parseObject(testStr, Feature.OrderedField); if (testObject.get("scenarios") != null) { return testStr; } else { From 316617d04ae62f0f653be262b626932695219bff Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Fri, 18 Sep 2020 10:55:36 +0800 Subject: [PATCH 8/9] =?UTF-8?q?refactor(=E6=80=A7=E8=83=BD=E6=B5=8B?= =?UTF-8?q?=E8=AF=95):=20=E4=BF=AE=E6=94=B9Kafka=20acks=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/io/metersphere/config/KafkaProperties.java | 2 +- backend/src/main/resources/application.properties | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/main/java/io/metersphere/config/KafkaProperties.java b/backend/src/main/java/io/metersphere/config/KafkaProperties.java index 912352b24b..59c24022af 100644 --- a/backend/src/main/java/io/metersphere/config/KafkaProperties.java +++ b/backend/src/main/java/io/metersphere/config/KafkaProperties.java @@ -10,7 +10,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; public class KafkaProperties { public static final String KAFKA_PREFIX = "kafka"; - private String acks; + private String acks = "all"; private String topic; private String fields; private String timestamp; diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index a3a405615e..5a57cf4026 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -40,7 +40,6 @@ spring.flyway.validate-on-migrate=false spring.messages.basename=i18n/messages # kafka -kafka.acks=1 kafka.fields= kafka.timestamp=yyyy-MM-dd'T'HH:mm:ss.SSSZZ kafka.sample-filter= From 7a6151ab794403e66e65cab61db63bb79a0dabdb Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Fri, 18 Sep 2020 11:09:37 +0800 Subject: [PATCH 9/9] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):?= =?UTF-8?q?=20=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=80=E5=B1=9E=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../track/controller/TestPlanController.java | 4 +- .../io/metersphere/track/dto/TestPlanDTO.java | 3 ++ .../track/service/TestPlanService.java | 42 ++++++++++++++++++- .../track/case/components/SwitchProject.vue | 2 +- .../track/plan/components/TestPlanEdit.vue | 31 ++++++++++---- .../review/components/TestCaseReviewEdit.vue | 6 ++- 6 files changed, 74 insertions(+), 14 deletions(-) diff --git a/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java b/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java index 6fbea3d40d..7f9135fcb9 100644 --- a/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java +++ b/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java @@ -81,8 +81,8 @@ public class TestPlanController { @PostMapping("/edit") @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) - public void editTestPlan(@RequestBody TestPlan testPlan) { - testPlanService.editTestPlan(testPlan); + public void editTestPlan(@RequestBody TestPlanDTO testPlanDTO) { + testPlanService.editTestPlan(testPlanDTO); } @PostMapping("/edit/status/{planId}") diff --git a/backend/src/main/java/io/metersphere/track/dto/TestPlanDTO.java b/backend/src/main/java/io/metersphere/track/dto/TestPlanDTO.java index 232c77ada0..a9b9fb545f 100644 --- a/backend/src/main/java/io/metersphere/track/dto/TestPlanDTO.java +++ b/backend/src/main/java/io/metersphere/track/dto/TestPlanDTO.java @@ -4,8 +4,11 @@ import io.metersphere.base.domain.TestPlan; import lombok.Getter; import lombok.Setter; +import java.util.List; + @Getter @Setter public class TestPlanDTO extends TestPlan { private String projectName; + private List projectIds; } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index bdd198c510..7f95cd805d 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -34,6 +34,7 @@ import org.apache.ibatis.session.SqlSessionFactory; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.util.*; @@ -110,12 +111,51 @@ public class TestPlanService { return Optional.ofNullable(testPlanMapper.selectByPrimaryKey(testPlanId)).orElse(new TestPlan()); } - public int editTestPlan(TestPlan testPlan) { + public int editTestPlan(TestPlanDTO testPlan) { + editTestPlanProject(testPlan); testPlan.setUpdateTime(System.currentTimeMillis()); checkTestPlanExist(testPlan); return testPlanMapper.updateByPrimaryKeySelective(testPlan); } + private void editTestPlanProject(TestPlanDTO testPlan) { + List projectIds = testPlan.getProjectIds(); + if (!CollectionUtils.isEmpty(projectIds)) { + TestPlanProjectExample testPlanProjectExample1 = new TestPlanProjectExample(); + testPlanProjectExample1.createCriteria().andTestPlanIdEqualTo(testPlan.getId()); + List testPlanProjects = testPlanProjectMapper.selectByExample(testPlanProjectExample1); + // 已经关联的项目idList + List dbProjectIds = testPlanProjects.stream().map(TestPlanProject::getProjectId).collect(Collectors.toList()); + // 修改后传过来的项目idList,如果还未关联,进行关联 + projectIds.forEach(projectId -> { + if (!dbProjectIds.contains(projectId)) { + TestPlanProject testPlanProject = new TestPlanProject(); + testPlanProject.setTestPlanId(testPlan.getId()); + testPlanProject.setProjectId(projectId); + testPlanProjectMapper.insert(testPlanProject); + } + }); + + TestPlanProjectExample testPlanProjectExample = new TestPlanProjectExample(); + testPlanProjectExample.createCriteria().andTestPlanIdEqualTo(testPlan.getId()).andProjectIdNotIn(projectIds); + testPlanProjectMapper.deleteByExample(testPlanProjectExample); + + // 关联的项目下的用例idList + TestCaseExample example = new TestCaseExample(); + example.createCriteria().andProjectIdIn(projectIds); + List caseList = testCaseMapper.selectByExample(example); + List caseIds = caseList.stream().map(TestCase::getId).collect(Collectors.toList()); + + // 取消关联所属项目下的用例和计划的关系 + TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample(); + TestPlanTestCaseExample.Criteria criteria = testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(testPlan.getId()); + if (!CollectionUtils.isEmpty(caseIds)) { + criteria.andCaseIdNotIn(caseIds); + } + testPlanTestCaseMapper.deleteByExample(testPlanTestCaseExample); + } + } + private void checkTestPlanExist(TestPlan testPlan) { if (testPlan.getName() != null) { TestPlanExample example = new TestPlanExample(); diff --git a/frontend/src/business/components/track/case/components/SwitchProject.vue b/frontend/src/business/components/track/case/components/SwitchProject.vue index 57b9335340..035d52312e 100644 --- a/frontend/src/business/components/track/case/components/SwitchProject.vue +++ b/frontend/src/business/components/track/case/components/SwitchProject.vue @@ -4,7 +4,7 @@ :close-on-click-modal="false" class="ms-switch-project" > - + { - this.$success(this.$t('commons.save_success')); - this.dialogFormVisible = false; - this.$emit("refresh"); - // 发送广播,刷新 head 上的最新列表 - TrackEvent.$emit(LIST_CHANGE); - }); + + if (this.operationType === 'edit') { + this.$confirm('取消项目关联会同时取消该项目下已关联的测试用例', '提示', { + confirmButtonText: this.$t('commons.confirm'), + cancelButtonText: this.$t('commons.cancel'), + type: 'warning' + }).then(() => { + this.editTestPlan(param); + }).catch(() => { + this.$info(this.$t('commons.cancel')) + }); + } else { + this.editTestPlan(param); + } } else { return false; } }); }, + editTestPlan(param) { + this.$post('/test/plan/' + this.operationType, param, () => { + this.$success(this.$t('commons.save_success')); + this.dialogFormVisible = false; + this.$emit("refresh"); + // 发送广播,刷新 head 上的最新列表 + TrackEvent.$emit(LIST_CHANGE); + }); + }, getProjects() { this.$get("/project/listAll", (response) => { if (response.success) { diff --git a/frontend/src/business/components/track/review/components/TestCaseReviewEdit.vue b/frontend/src/business/components/track/review/components/TestCaseReviewEdit.vue index 7dfc0298b8..aaeea31402 100644 --- a/frontend/src/business/components/track/review/components/TestCaseReviewEdit.vue +++ b/frontend/src/business/components/track/review/components/TestCaseReviewEdit.vue @@ -6,6 +6,7 @@ :title="operationType === 'edit' ? '编辑用例评审' : '创建用例评审'" :visible.sync="dialogFormVisible" @close="close" + v-loading="result.loading" width="65%"> @@ -122,6 +123,7 @@ export default { data() { return { dialogFormVisible: false, + result: {}, form: { name: '', projectIds: [], @@ -187,7 +189,7 @@ export default { }); }, getProjects() { - this.$get("/project/listAll", (response) => { + this.result = this.$get("/project/listAll", (response) => { if (response.success) { this.projects = response.data; } else { @@ -197,7 +199,7 @@ export default { }, setReviewerOptions() { let workspaceId = localStorage.getItem(WORKSPACE_ID); - this.$post('/user/ws/member/tester/list', {workspaceId: workspaceId}, response => { + this.result = this.$post('/user/ws/member/tester/list', {workspaceId: workspaceId}, response => { this.reviewerOptions = response.data; }); },