fix(接口测试): 修复重复创建未规划接口的缺陷
This commit is contained in:
parent
26fa5d48e5
commit
bcb0f887c9
|
@ -1,21 +1,21 @@
|
|||
package io.metersphere.listener;
|
||||
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import io.metersphere.base.domain.ModuleNode;
|
||||
import io.metersphere.base.domain.Project;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.ApiModuleMapper;
|
||||
import io.metersphere.base.mapper.ApiScenarioModuleMapper;
|
||||
import io.metersphere.base.mapper.ProjectMapper;
|
||||
import io.metersphere.base.mapper.ext.BaseModuleNodeMapper;
|
||||
import io.metersphere.commons.constants.KafkaTopicConstants;
|
||||
import io.metersphere.commons.constants.ProjectModuleDefaultNodeEnum;
|
||||
import io.metersphere.commons.utils.BeanUtils;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.springframework.kafka.annotation.KafkaListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
|
@ -28,6 +28,8 @@ public class ProjectCreatedListener {
|
|||
@Resource
|
||||
private ApiModuleMapper apiModuleMapper;
|
||||
@Resource
|
||||
private ApiScenarioModuleMapper apiScenarioModuleMapper;
|
||||
@Resource
|
||||
private ProjectMapper projectMapper;
|
||||
|
||||
|
||||
|
@ -52,7 +54,12 @@ public class ProjectCreatedListener {
|
|||
record.setUpdateTime(System.currentTimeMillis());
|
||||
record.setProjectId(projectId);
|
||||
record.setName(ProjectModuleDefaultNodeEnum.API_SCENARIO_DEFAULT_NODE.getNodeName());
|
||||
baseModuleNodeMapper.insert(ProjectModuleDefaultNodeEnum.API_SCENARIO_DEFAULT_NODE.getTableName(), record);
|
||||
ApiScenarioModuleExample scenarioModuleExample = new ApiScenarioModuleExample();
|
||||
scenarioModuleExample.createCriteria().andProjectIdEqualTo(projectId).andNameEqualTo(ProjectModuleDefaultNodeEnum.API_SCENARIO_DEFAULT_NODE.getNodeName()).andParentIdIsNull();
|
||||
List<ApiScenarioModule> scenarioModules = apiScenarioModuleMapper.selectByExample(scenarioModuleExample);
|
||||
if (CollectionUtils.isEmpty(scenarioModules)) {
|
||||
baseModuleNodeMapper.insert(ProjectModuleDefaultNodeEnum.API_SCENARIO_DEFAULT_NODE.getTableName(), record);
|
||||
}
|
||||
ApiModule apiRecord = new ApiModule();
|
||||
BeanUtils.copyBean(apiRecord, record);
|
||||
apiRecord.setName(ProjectModuleDefaultNodeEnum.API_MODULE_DEFAULT_NODE.getNodeName());
|
||||
|
@ -60,7 +67,12 @@ public class ProjectCreatedListener {
|
|||
for (String protocol : protocols) {
|
||||
apiRecord.setProtocol(protocol);
|
||||
apiRecord.setId(UUID.randomUUID().toString());
|
||||
apiModuleMapper.insert(apiRecord);
|
||||
ApiModuleExample apiExample = new ApiModuleExample();
|
||||
apiExample.createCriteria().andProjectIdEqualTo(projectId).andProtocolEqualTo(protocol).andNameEqualTo(ProjectModuleDefaultNodeEnum.API_MODULE_DEFAULT_NODE.getNodeName()).andParentIdIsNull();
|
||||
List<ApiModule> apiList = apiModuleMapper.selectByExample(apiExample);
|
||||
if (CollectionUtils.isEmpty(apiList)) {
|
||||
apiModuleMapper.insert(apiRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import io.metersphere.base.domain.*;
|
|||
import io.metersphere.base.mapper.ApiModuleMapper;
|
||||
import io.metersphere.base.mapper.ApiTestCaseMapper;
|
||||
import io.metersphere.commons.constants.NoticeConstants;
|
||||
import io.metersphere.commons.constants.ProjectModuleDefaultNodeEnum;
|
||||
import io.metersphere.commons.constants.PropertyConstant;
|
||||
import io.metersphere.commons.enums.ApiTestDataStatus;
|
||||
import io.metersphere.commons.utils.BeanUtils;
|
||||
|
@ -355,7 +356,7 @@ public class ApiDefinitionImportUtil {
|
|||
public static void setModule(ApiDefinitionWithBLOBs item, ApiModuleMapper apiModuleMapper) {
|
||||
if (item != null && StringUtils.isEmpty(item.getModuleId()) || "default-module".equals(item.getModuleId())) {
|
||||
ApiModuleExample example = new ApiModuleExample();
|
||||
example.createCriteria().andProjectIdEqualTo(item.getProjectId()).andProtocolEqualTo(item.getProtocol()).andNameEqualTo("未规划接口");
|
||||
example.createCriteria().andProjectIdEqualTo(item.getProjectId()).andProtocolEqualTo(item.getProtocol()).andNameEqualTo(ProjectModuleDefaultNodeEnum.API_MODULE_DEFAULT_NODE.getNodeName());
|
||||
List<ApiModule> modules = apiModuleMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(modules)) {
|
||||
item.setModuleId(modules.get(0).getId());
|
||||
|
|
|
@ -1003,7 +1003,7 @@ public class ApiDefinitionService {
|
|||
private void setModule(ApiDefinitionWithBLOBs item) {
|
||||
if (item != null && StringUtils.isEmpty(item.getModuleId()) || "default-module".equals(item.getModuleId())) {
|
||||
ApiModuleExample example = new ApiModuleExample();
|
||||
example.createCriteria().andProjectIdEqualTo(item.getProjectId()).andProtocolEqualTo(item.getProtocol()).andNameEqualTo("未规划接口");
|
||||
example.createCriteria().andProjectIdEqualTo(item.getProjectId()).andProtocolEqualTo(item.getProtocol()).andNameEqualTo(ProjectModuleDefaultNodeEnum.API_MODULE_DEFAULT_NODE.getNodeName());
|
||||
List<ApiModule> modules = apiModuleMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(modules)) {
|
||||
item.setModuleId(modules.get(0).getId());
|
||||
|
@ -1840,7 +1840,7 @@ public class ApiDefinitionService {
|
|||
|
||||
public void initModulePathAndId(String projectId, ApiDefinitionWithBLOBs test) {
|
||||
ApiModuleExample example = new ApiModuleExample();
|
||||
example.createCriteria().andProjectIdEqualTo(projectId).andProtocolEqualTo(test.getProtocol()).andNameEqualTo("未规划接口").andLevelEqualTo(1);
|
||||
example.createCriteria().andProjectIdEqualTo(projectId).andProtocolEqualTo(test.getProtocol()).andNameEqualTo(ProjectModuleDefaultNodeEnum.API_MODULE_DEFAULT_NODE.getNodeName()).andLevelEqualTo(1);
|
||||
List<ApiModule> modules = apiModuleMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(modules)) {
|
||||
test.setModuleId(modules.get(0).getId());
|
||||
|
|
|
@ -1,24 +1,15 @@
|
|||
package io.metersphere.service.definition;
|
||||
|
||||
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionRequest;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.dto.definition.ApiModuleDTO;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseRequest;
|
||||
import io.metersphere.api.dto.definition.DragModuleRequest;
|
||||
import io.metersphere.api.dto.definition.UpdateApiModuleDTO;
|
||||
import io.metersphere.api.dto.definition.*;
|
||||
import io.metersphere.api.parse.api.ApiDefinitionImport;
|
||||
import io.metersphere.base.domain.ApiDefinition;
|
||||
import io.metersphere.base.domain.ApiDefinitionExample;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import io.metersphere.base.domain.ApiModuleExample;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.ApiDefinitionMapper;
|
||||
import io.metersphere.base.mapper.ApiModuleMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtApiDefinitionMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtApiModuleMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper;
|
||||
import io.metersphere.commons.constants.ProjectModuleDefaultNodeEnum;
|
||||
import io.metersphere.commons.constants.PropertyConstant;
|
||||
import io.metersphere.commons.constants.TestCaseConstants;
|
||||
import io.metersphere.commons.enums.ApiTestDataStatus;
|
||||
|
@ -44,15 +35,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -204,7 +187,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
return getNodeTrees(apiModules);
|
||||
}
|
||||
|
||||
public List<ApiModuleDTO> getNodeTreeByCondition(String projectId, String protocol, String versionId, ApiDefinitionRequest request ) {
|
||||
public List<ApiModuleDTO> getNodeTreeByCondition(String projectId, String protocol, String versionId, ApiDefinitionRequest request) {
|
||||
// 判断当前项目下是否有默认模块,没有添加默认模块
|
||||
this.getDefaultNode(projectId, protocol);
|
||||
List<ApiModuleDTO> apiModules = getApiModulesByProjectAndPro(projectId, protocol);
|
||||
|
@ -588,12 +571,12 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
|
||||
public ApiModule getDefaultNode(String projectId, String protocol) {
|
||||
ApiModuleExample example = new ApiModuleExample();
|
||||
example.createCriteria().andProjectIdEqualTo(projectId).andProtocolEqualTo(protocol).andNameEqualTo("未规划接口").andParentIdIsNull();
|
||||
example.createCriteria().andProjectIdEqualTo(projectId).andProtocolEqualTo(protocol).andNameEqualTo(ProjectModuleDefaultNodeEnum.API_MODULE_DEFAULT_NODE.getNodeName()).andParentIdIsNull();
|
||||
List<ApiModule> list = apiModuleMapper.selectByExample(example);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
ApiModule record = new ApiModule();
|
||||
record.setId(UUID.randomUUID().toString());
|
||||
record.setName("未规划接口");
|
||||
record.setName(ProjectModuleDefaultNodeEnum.API_MODULE_DEFAULT_NODE.getNodeName());
|
||||
record.setProtocol(protocol);
|
||||
record.setPos(1.0);
|
||||
record.setLevel(1);
|
||||
|
@ -608,17 +591,6 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
}
|
||||
}
|
||||
|
||||
public ApiModule getDefaultNodeUnCreateNew(String projectId, String protocol) {
|
||||
ApiModuleExample example = new ApiModuleExample();
|
||||
example.createCriteria().andProjectIdEqualTo(projectId).andProtocolEqualTo(protocol).andNameEqualTo("未规划接口").andParentIdIsNull();
|
||||
List<ApiModule> list = apiModuleMapper.selectByExample(example);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return null;
|
||||
} else {
|
||||
return list.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
public long countTrashApiData(String projectId, String protocol) {
|
||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
example.createCriteria().andProjectIdEqualTo(projectId).andProtocolEqualTo(protocol).andStatusEqualTo("Trash");
|
||||
|
@ -666,7 +638,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
if (protocol.equals("HTTP")) {
|
||||
return dealHttp(data, pidChildrenMap, idPathMap, idModuleMap, request, fullCoverage, urlRepeat, importCases);
|
||||
} else {
|
||||
return delOtherProtocol(data, pidChildrenMap, idPathMap, idModuleMap, request, fullCoverage, importCases);
|
||||
return delOtherProtocol(data, pidChildrenMap, idPathMap, idModuleMap, request, fullCoverage, importCases);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -693,7 +665,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
//处理模块
|
||||
setModule(moduleMap, pidChildrenMap, idPathMap, idModuleMap, optionData, chooseModule);
|
||||
|
||||
return getUpdateApiModuleDTO(chooseModule,idPathMap,optionData,fullCoverage, moduleMap,optionDataCases);
|
||||
return getUpdateApiModuleDTO(chooseModule, idPathMap, optionData, fullCoverage, moduleMap, optionDataCases);
|
||||
}
|
||||
|
||||
private UpdateApiModuleDTO dealHttp(List<ApiDefinitionWithBLOBs> data,
|
||||
|
@ -722,8 +694,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
setModule(moduleMap, pidChildrenMap, idPathMap, idModuleMap, optionData, chooseModule);
|
||||
|
||||
|
||||
|
||||
return getUpdateApiModuleDTO(chooseModule,idPathMap,optionData,fullCoverage, moduleMap,optionDataCases);
|
||||
return getUpdateApiModuleDTO(chooseModule, idPathMap, optionData, fullCoverage, moduleMap, optionDataCases);
|
||||
|
||||
}
|
||||
|
||||
|
@ -752,7 +723,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
}
|
||||
}
|
||||
|
||||
private UpdateApiModuleDTO getUpdateApiModuleDTO(ApiModuleDTO chooseModule,Map<String, String> idPathMap,List<ApiDefinitionWithBLOBs> optionData,Boolean fullCoverage,Map<String, ApiModule> moduleMap, List<ApiTestCaseWithBLOBs> optionDataCases) {
|
||||
private UpdateApiModuleDTO getUpdateApiModuleDTO(ApiModuleDTO chooseModule, Map<String, String> idPathMap, List<ApiDefinitionWithBLOBs> optionData, Boolean fullCoverage, Map<String, ApiModule> moduleMap, List<ApiTestCaseWithBLOBs> optionDataCases) {
|
||||
UpdateApiModuleDTO updateApiModuleDTO = new UpdateApiModuleDTO();
|
||||
updateApiModuleDTO.setChooseModule(chooseModule);
|
||||
updateApiModuleDTO.setIdPathMap(idPathMap);
|
||||
|
@ -822,7 +793,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
//导入时即没选中模块,接口自身也没模块的,直接返会当前项目,当前协议下的默认模块
|
||||
List<ApiModule> moduleList = pidChildrenMap.get(PropertyConstant.ROOT);
|
||||
for (ApiModule module : moduleList) {
|
||||
if (module.getName().equals("未规划接口")) {
|
||||
if (module.getName().equals(ProjectModuleDefaultNodeEnum.API_MODULE_DEFAULT_NODE.getNodeName())) {
|
||||
datum.setModuleId(module.getId());
|
||||
datum.setModulePath("/" + module.getName());
|
||||
}
|
||||
|
@ -846,6 +817,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
datum.setModulePath(idPathMap.get(chooseModule.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getPathTree(String modulePath) {
|
||||
String substring = modulePath.substring(0, 1);
|
||||
if (substring.equals("/")) {
|
||||
|
|
|
@ -11,6 +11,7 @@ import io.metersphere.base.mapper.ApiScenarioMapper;
|
|||
import io.metersphere.base.mapper.ApiScenarioModuleMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtApiScenarioMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtApiScenarioModuleMapper;
|
||||
import io.metersphere.commons.constants.ProjectModuleDefaultNodeEnum;
|
||||
import io.metersphere.commons.constants.PropertyConstant;
|
||||
import io.metersphere.commons.constants.TestCaseConstants;
|
||||
import io.metersphere.commons.enums.ApiTestDataStatus;
|
||||
|
@ -157,7 +158,7 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
//回收站数据初始化:被删除了的数据挂在默认模块上
|
||||
initTrashDataModule(projectId);
|
||||
//通过回收站里的接口模块进行反显
|
||||
if(request.getFilters() != null && request.getFilters().get("status") != null){
|
||||
if (request.getFilters() != null && request.getFilters().get("status") != null) {
|
||||
List<String> statusList = new ArrayList<>();
|
||||
statusList.add(ApiTestDataStatus.TRASH.getValue());
|
||||
request.getFilters().put("status", statusList);
|
||||
|
@ -507,12 +508,12 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
|
||||
public ApiScenarioModule getDefaultNode(String projectId) {
|
||||
ApiScenarioModuleExample example = new ApiScenarioModuleExample();
|
||||
example.createCriteria().andProjectIdEqualTo(projectId).andNameEqualTo("未规划场景").andParentIdIsNull();
|
||||
example.createCriteria().andProjectIdEqualTo(projectId).andNameEqualTo(ProjectModuleDefaultNodeEnum.API_SCENARIO_DEFAULT_NODE.getNodeName()).andParentIdIsNull();
|
||||
List<ApiScenarioModule> list = apiScenarioModuleMapper.selectByExample(example);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
ApiScenarioModule record = new ApiScenarioModule();
|
||||
record.setId(UUID.randomUUID().toString());
|
||||
record.setName("未规划场景");
|
||||
record.setName(ProjectModuleDefaultNodeEnum.API_SCENARIO_DEFAULT_NODE.getNodeName());
|
||||
record.setPos(1.0);
|
||||
record.setLevel(1);
|
||||
record.setCreateTime(System.currentTimeMillis());
|
||||
|
@ -825,7 +826,7 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
//导入时即没选中模块,接口自身也没模块的,直接返会当前项目,当前协议下的默认模块
|
||||
List<ApiScenarioModule> moduleList = pidChildrenMap.get(PropertyConstant.ROOT);
|
||||
for (ApiScenarioModule module : moduleList) {
|
||||
if (module.getName().equals("未规划场景")) {
|
||||
if (module.getName().equals(ProjectModuleDefaultNodeEnum.API_SCENARIO_DEFAULT_NODE.getNodeName())) {
|
||||
datum.setApiScenarioModuleId(module.getId());
|
||||
datum.setModulePath("/" + module.getName());
|
||||
}
|
||||
|
|
|
@ -1478,7 +1478,7 @@ public class ApiScenarioService {
|
|||
|
||||
private void replenishScenarioModuleIdPath(String request, ApiScenarioModuleMapper apiScenarioModuleMapper, ApiScenarioWithBLOBs item) {
|
||||
ApiScenarioModuleExample example = new ApiScenarioModuleExample();
|
||||
example.createCriteria().andProjectIdEqualTo(request).andNameEqualTo("未规划场景");
|
||||
example.createCriteria().andProjectIdEqualTo(request).andNameEqualTo(ProjectModuleDefaultNodeEnum.API_SCENARIO_DEFAULT_NODE.getNodeName());
|
||||
List<ApiScenarioModule> modules = apiScenarioModuleMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(modules)) {
|
||||
item.setApiScenarioModuleId(modules.get(0).getId());
|
||||
|
|
Loading…
Reference in New Issue