From 66abe978fe70b0f38ee9e9e4c35ef9f144df0fc5 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 20 Oct 2021 10:15:05 +0800 Subject: [PATCH] =?UTF-8?q?feat=20(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E5=88=A0=E9=99=A4=E5=9C=BA=E6=99=AF=E7=BA=A7?= =?UTF-8?q?=E8=81=94=E5=90=8C=E6=AD=A5=E5=88=A0=E9=99=A4=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/definition/request/ElementUtil.java | 25 +++++++++++-------- .../api/service/ApiAutomationService.java | 15 ++++++----- backend/src/main/java/io/metersphere/xpack | 2 +- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java index 48067aefb2..14f4173cd5 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java @@ -180,16 +180,6 @@ public class ElementUtil { public static String getParentName(MsTestElement parent) { if (parent != null) { -// if (MsTestElementConstants.TransactionController.name().equals(parent.getType())) { -// MsTransactionController transactionController = (MsTransactionController) parent; -// if (StringUtils.isNotEmpty(transactionController.getName())) { -// return transactionController.getName(); -// } else if (StringUtils.isNotEmpty(transactionController.getLabelName())) { -// return transactionController.getLabelName(); -// } else { -// return "TransactionController"; -// } -// } // 获取全路径以备后面使用 String fullPath = getFullPath(parent, new String()); return fullPath + DelimiterConstants.SEPARATOR.toString() + parent.getName(); @@ -291,6 +281,21 @@ public class ElementUtil { } } + public static void relationships(JSONArray hashTree, List referenceRelationships) { + for (int i = 0; i < hashTree.size(); i++) { + JSONObject element = hashTree.getJSONObject(i); + if (element != null && StringUtils.equals(element.get("type").toString(), "scenario") && StringUtils.equals(element.get("referenced").toString(), "REF")) { + if (!referenceRelationships.contains(element.get("id").toString())) { + referenceRelationships.add(element.get("id").toString()); + } + } + if (element.containsKey("hashTree")) { + JSONArray elementJSONArray = element.getJSONArray("hashTree"); + relationships(elementJSONArray, referenceRelationships); + } + } + } + public static void dataFormatting(JSONArray hashTree) { for (int i = 0; i < hashTree.size(); i++) { JSONObject element = hashTree.getJSONObject(i); 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 aa9943e5c0..c70dfe6e01 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -44,6 +44,7 @@ import io.metersphere.log.vo.DetailColumn; import io.metersphere.log.vo.OperatingLogDetails; import io.metersphere.log.vo.api.AutomationReference; import io.metersphere.plugin.core.MsTestElement; +import io.metersphere.service.RelationshipEdgeService; import io.metersphere.service.ScheduleService; import io.metersphere.service.SystemParameterService; import io.metersphere.track.dto.TestPlanDTO; @@ -139,6 +140,8 @@ public class ApiAutomationService { private NodeKafkaService nodeKafkaService; @Resource private ExtTestPlanScenarioCaseMapper extTestPlanScenarioCaseMapper; + @Resource + private RelationshipEdgeService relationshipEdgeService; private ThreadLocal currentScenarioOrder = new ThreadLocal<>(); @@ -474,7 +477,8 @@ public class ApiAutomationService { example.createCriteria().andIdIn(idList); testPlanApiScenarioMapper.deleteByExample(example); } - + // 删除引用关系 + relationshipEdgeService.delete(scenarioId); deleteBodyFileByScenarioId(scenarioId); } @@ -539,6 +543,8 @@ public class ApiAutomationService { example.createCriteria().andIdIn(testPlanApiScenarioIdList); testPlanApiScenarioMapper.deleteByExample(example); } + // 删除引用关系 + relationshipEdgeService.delete(scenarioIds); deleteBodyFileByScenarioIds(scenarioIds); } @@ -2153,7 +2159,6 @@ public class ApiAutomationService { public void deleteBatchByCondition(ApiScenarioBatchRequest request) { ServiceUtils.getSelectAllIds(request, request.getCondition(), (query) -> extApiScenarioMapper.selectIdsByQuery(query)); - this.deleteBatch(request.getIds()); } @@ -2170,7 +2175,6 @@ public class ApiAutomationService { * @return */ public float countInterfaceCoverage(List allScenarioInfoList, List allEffectiveApiList) { - float intetfaceCoverage = 0; if (allEffectiveApiList == null || allEffectiveApiList.isEmpty()) { return 100; } @@ -2206,7 +2210,6 @@ public class ApiAutomationService { } } } - useUrl = null; } List containsApiIdList = new ArrayList<>(); @@ -2245,8 +2248,8 @@ public class ApiAutomationService { List urlList = new ArrayList<>(); try { - String scenarioDefiniton = scenario.getScenarioDefinition(); - JSONObject scenarioObj = JSONObject.parseObject(scenarioDefiniton); + String scenarioDefinition = scenario.getScenarioDefinition(); + JSONObject scenarioObj = JSONObject.parseObject(scenarioDefinition); List stepUrlList = this.getMethodUrlDTOByHashTreeJsonObj(scenarioObj); if (CollectionUtils.isNotEmpty(stepUrlList)) { Collection unionList = CollectionUtils.union(urlList, stepUrlList); diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index 7fa58311f2..951a09e190 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit 7fa58311f24417999905d463f17dc142963c3524 +Subproject commit 951a09e1903d4e93f2cc270a165464986cabaa3b