From adb6153db4ea606030570d181bfaea7d9420e1ba Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Wed, 28 Apr 2021 12:53:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9C=BA=E6=99=AF=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=BC=95=E7=94=A8=E7=9A=84=E5=9C=BA=E6=99=AF=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E5=A4=8D=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../automation/parse/MsScenarioParser.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsScenarioParser.java b/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsScenarioParser.java index 28b95d8e9b..9226f39280 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsScenarioParser.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsScenarioParser.java @@ -1,6 +1,7 @@ package io.metersphere.api.dto.automation.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; @@ -63,6 +64,15 @@ public class MsScenarioParser extends MsAbstractParser { List data = apiDefinitionImport.getData(); if (CollectionUtils.isNotEmpty(data)) { data.forEach(item -> { + String scenarioDefinitionStr = item.getScenarioDefinition(); + if (StringUtils.isNotBlank(scenarioDefinitionStr)) { + JSONObject scenarioDefinition = JSONObject.parseObject(scenarioDefinitionStr); + if (scenarioDefinition != null) { + JSONArray hashTree = scenarioDefinition.getJSONArray("hashTree"); + setCopy(hashTree); + item.setScenarioDefinition(JSONObject.toJSONString(scenarioDefinition)); + } + } if (StringUtils.isBlank(item.getModulePath())) { item.setApiScenarioModuleId(null); } @@ -74,6 +84,19 @@ public class MsScenarioParser extends MsAbstractParser { return apiDefinitionImport; } + private void setCopy(JSONArray hashTree) { + // 将引用转成复制 + if (CollectionUtils.isNotEmpty(hashTree)) { + for (int i = 0; i < hashTree.size(); i++) { + JSONObject object = (JSONObject) hashTree.get(i); + object.put("referenced", "Copy"); + if (CollectionUtils.isNotEmpty(object.getJSONArray("hashTree"))) { + setCopy(object.getJSONArray("hashTree")); + } + } + } + } + protected void parseModule(String modulePath, ApiTestImportRequest importRequest, ApiScenarioWithBLOBs apiScenarioWithBLOBs) { if (StringUtils.isEmpty(modulePath)) { return;