feat (接口自动化): 删除场景级联同步删除场景关系

This commit is contained in:
fit2-zhao 2021-10-20 10:15:05 +08:00 committed by fit2-zhao
parent 0d60c65b94
commit 66abe978fe
3 changed files with 25 additions and 17 deletions

View File

@ -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<String> 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);

View File

@ -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<Long> 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<ApiScenarioWithBLOBs> allScenarioInfoList, List<ApiDefinition> allEffectiveApiList) {
float intetfaceCoverage = 0;
if (allEffectiveApiList == null || allEffectiveApiList.isEmpty()) {
return 100;
}
@ -2206,7 +2210,6 @@ public class ApiAutomationService {
}
}
}
useUrl = null;
}
List<String> containsApiIdList = new ArrayList<>();
@ -2245,8 +2248,8 @@ public class ApiAutomationService {
List<ApiMethodUrlDTO> urlList = new ArrayList<>();
try {
String scenarioDefiniton = scenario.getScenarioDefinition();
JSONObject scenarioObj = JSONObject.parseObject(scenarioDefiniton);
String scenarioDefinition = scenario.getScenarioDefinition();
JSONObject scenarioObj = JSONObject.parseObject(scenarioDefinition);
List<ApiMethodUrlDTO> stepUrlList = this.getMethodUrlDTOByHashTreeJsonObj(scenarioObj);
if (CollectionUtils.isNotEmpty(stepUrlList)) {
Collection unionList = CollectionUtils.union(urlList, stepUrlList);

@ -1 +1 @@
Subproject commit 7fa58311f24417999905d463f17dc142963c3524
Subproject commit 951a09e1903d4e93f2cc270a165464986cabaa3b