From de897cb7c5195f4e53baff8fb500203e1a32d430 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Wed, 7 Apr 2021 17:55:27 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E5=9C=BA=E6=99=AF=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E5=85=BC=E5=AE=B9=E5=8E=86=E5=8F=B2=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/definition/request/MsScenario.java | 1 + .../request/sampler/MsHTTPSamplerProxy.java | 21 +++++++++++++++++-- .../api/service/ApiAutomationService.java | 4 ++++ 3 files changed, 24 insertions(+), 2 deletions(-) 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 6267b7ee35..478a7a5805 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 @@ -89,6 +89,7 @@ public class MsScenario extends MsTestElement { if (scenario != null && StringUtils.isNotEmpty(scenario.getScenarioDefinition())) { JSONObject element = JSON.parseObject(scenario.getScenarioDefinition()); this.setName(scenario.getName()); + this.setProjectId(scenario.getProjectId()); hashTree = mapper.readValue(element.getString("hashTree"), new TypeReference>() { }); // 场景变量 diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 4e0a353f18..2584f58a20 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -126,8 +126,14 @@ public class MsHTTPSamplerProxy extends MsTestElement { config.setConfig(getEnvironmentConfig(useEnvironment)); } - // 1.8 之前历史数据 - if (StringUtils.isEmpty(this.getProjectId()) && config.getConfig() != null && !config.getConfig().isEmpty()) { + // 数据兼容处理 + if(config.getConfig() != null && StringUtils.isNotEmpty(this.getProjectId()) && config.getConfig().containsKey(this.getProjectId())){ + // 1.8 之后 当前正常数据 + } else if (config.getConfig() != null && config.getConfig().containsKey(getParentProjectId())) { + // 1.8 前后 混合数据 + this.setProjectId(getParentProjectId()); + } else { + // 1.8 之前 数据 this.setProjectId("historyProjectID"); } @@ -279,6 +285,17 @@ public class MsHTTPSamplerProxy extends MsTestElement { return false; } + private String getParentProjectId() { + MsTestElement parent = this.getParent(); + while(parent != null) { + if (StringUtils.isNotBlank(parent.getProjectId())) { + return parent.getProjectId(); + } + parent = parent.getParent(); + } + return ""; + } + private String getRestParameters(String path) { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(path); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index f3d2dd1433..19aa55f9f4 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -409,6 +409,7 @@ public class ApiAutomationService { } else if (StringUtils.equals(tr.getType(), "scenario")) { if (tr.isEnable()) { ApiScenarioDTO apiScenario = getApiScenario(tr.getId()); + env.getProjectIds().add(apiScenario.getProjectId()); String scenarioDefinition = apiScenario.getScenarioDefinition(); JSONObject element1 = JSON.parseObject(scenarioDefinition); LinkedList hashTree1 = mapper.readValue(element1.getString("hashTree"), new TypeReference>(){}); @@ -432,6 +433,7 @@ public class ApiAutomationService { if (!tr.isEnable()) { continue; } + env.getProjectIds().add(tr.getProjectId()); if (CollectionUtils.isNotEmpty(tr.getHashTree())) { getHashTree(tr.getHashTree(), env); } @@ -476,6 +478,7 @@ public class ApiAutomationService { } else if (StringUtils.equals(tr.getType(), "scenario")) { if (tr.isEnable()) { ApiScenarioDTO apiScenario = getApiScenario(tr.getId()); + env.getProjectIds().add(apiScenario.getProjectId()); String scenarioDefinition = apiScenario.getScenarioDefinition(); JSONObject element1 = JSON.parseObject(scenarioDefinition); LinkedList hashTree1 = mapper.readValue(element1.getString("hashTree"), new TypeReference>(){}); @@ -499,6 +502,7 @@ public class ApiAutomationService { if (!tr.isEnable()) { continue; } + env.getProjectIds().add(tr.getProjectId()); if (CollectionUtils.isNotEmpty(tr.getHashTree())) { getHashTree(tr.getHashTree(), env); }