From c90c061738454161402bd8105d54cb37d3211f8e Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Tue, 9 Mar 2021 18:08:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E7=8E=AF=E5=A2=83=E9=85=8D=E7=BD=AE=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/definition/request/MsScenario.java | 1 + .../dto/definition/request/MsTestElement.java | 1 + .../definition/request/OldVersionUtil.java | 23 +++++++++++++++++++ .../automation/scenario/EditApiScenario.vue | 11 +++++++-- .../component/ApiScenarioComponent.vue | 6 +++++ 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/api/dto/definition/request/OldVersionUtil.java diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java index 6303166c99..642b71b976 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java @@ -85,6 +85,7 @@ public class MsScenario extends MsTestElement { JSONObject element = JSON.parseObject(scenario.getScenarioDefinition()); hashTree = mapper.readValue(element.getString("hashTree"), new TypeReference>() { }); + OldVersionUtil.transferHashTree(hashTree); // εœΊζ™―ε˜ι‡ if (StringUtils.isNotEmpty(element.getString("variables"))) { LinkedList variables = mapper.readValue(element.getString("variables"), diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java index 182dbf5512..8238f27752 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java @@ -161,6 +161,7 @@ public abstract class MsTestElement { element = mapper.readValue(apiDefinition.getRequest(), new TypeReference() { }); hashTree.add(element); + OldVersionUtil.transferHashTree(hashTree); } } catch (Exception ex) { ex.printStackTrace(); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/OldVersionUtil.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/OldVersionUtil.java new file mode 100644 index 0000000000..943f5502a8 --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/OldVersionUtil.java @@ -0,0 +1,23 @@ +package io.metersphere.api.dto.definition.request; + + +import io.metersphere.commons.utils.SessionUtils; +import org.apache.commons.lang3.StringUtils; + +import java.util.List; + +public class OldVersionUtil { + + public static void transferHashTree(List hashTree) { + for (int i = 0; i < hashTree.size(); i++) { + MsTestElement element = hashTree.get(i); + if (StringUtils.isBlank(element.getProjectId())) { + element.setProjectId(SessionUtils.getCurrentProjectId()); + } + if (element.getHashTree() != null && element.getHashTree().size() > 0) { + transferHashTree(element.getHashTree()); + } + } + } + +} diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index b0b2fbfd21..a75e44cc43 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -532,6 +532,9 @@ if (arr[i].type === ELEMENT_TYPE.LoopController && arr[i].hashTree && arr[i].hashTree.length > 1) { arr[i].countController.proceed = true; } + if (!arr[i].projectId) { + arr[i].projectId = getCurrentProjectID(); + } if (arr[i].hashTree != undefined && arr[i].hashTree.length > 0) { this.recursiveSorting(arr[i].hashTree); } @@ -544,6 +547,9 @@ && this.scenarioDefinition[i].hashTree.length > 1) { this.scenarioDefinition[i].countController.proceed = true; } + if (!this.scenarioDefinition[i].projectId) { + this.scenarioDefinition.projectId = getCurrentProjectID(); + } if (this.scenarioDefinition[i].hashTree != undefined && this.scenarioDefinition[i].hashTree.length > 0) { this.recursiveSorting(this.scenarioDefinition[i].hashTree); } @@ -919,14 +925,15 @@ } this.enableCookieShare = obj.enableCookieShare; this.scenarioDefinition = obj.hashTree; - this.initProjectIds(); } } if (this.currentScenario.copy) { this.path = "/api/automation/create"; } } - this.getEnvironments(); + this.sort(); + this.initProjectIds(); + // this.getEnvironments(); }) } }, diff --git a/frontend/src/business/components/api/automation/scenario/component/ApiScenarioComponent.vue b/frontend/src/business/components/api/automation/scenario/component/ApiScenarioComponent.vue index a0b2873f78..932ad0f4f8 100644 --- a/frontend/src/business/components/api/automation/scenario/component/ApiScenarioComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/component/ApiScenarioComponent.vue @@ -108,6 +108,9 @@ recursive(arr) { for (let i in arr) { arr[i].disabled = true; + if (!arr[i].projectId) { + arr[i].projectId = getCurrentProjectID(); + } if (arr[i].hashTree != undefined && arr[i].hashTree.length > 0) { this.recursive(arr[i].hashTree); } @@ -116,6 +119,9 @@ setDisabled(scenarioDefinition) { for (let i in scenarioDefinition) { scenarioDefinition[i].disabled = true; + if (!scenarioDefinition[i].projectId) { + scenarioDefinition[i].projectId = getCurrentProjectID(); + } if (scenarioDefinition[i].hashTree != undefined && scenarioDefinition[i].hashTree.length > 0) { this.recursive(scenarioDefinition[i].hashTree); }