refactor(接口测试): 优化回收站恢复数据逻辑并增加提示信息 (#15594)

--bug=1014719 --user=王孝刚
【接口测试】接口定义-导入的swagger接口被删除了,所属模块也被删除,再次导入这个接口成功,恢复被删除的接口时没提示接口重复,恢复到未规划模块列表中
https://www.tapd.cn/55049933/s/1197263

Co-authored-by: wxg0103 <727495428@qq.com>
This commit is contained in:
MeterSphere Bot 2022-07-08 09:52:57 +08:00 committed by GitHub
parent 2c390991e2
commit 3ccd5a055b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 26 deletions

View File

@ -263,7 +263,7 @@ public class ApiAutomationService {
msScenario.setHashTree(new LinkedList<>());
request.setScenarioDefinition(msScenario);
}
checkNameExist(request);
checkNameExist(request, false);
int nextNum = getNextNum(request.getProjectId());
if (StringUtils.isBlank(request.getCustomNum())) {
request.setCustomNum(String.valueOf(nextNum));
@ -365,7 +365,7 @@ public class ApiAutomationService {
}
public ApiScenario update(SaveApiScenarioRequest request, List<MultipartFile> bodyFiles, List<MultipartFile> scenarioFiles) {
checkNameExist(request);
checkNameExist(request, false);
checkScenarioNum(request);
//检查场景的请求步骤如果含有ESB请求步骤的话要做参数计算处理
@ -641,8 +641,23 @@ public class ApiAutomationService {
example.createCriteria().andIdIn(scenarioIds);
List<ApiScenario> scenarioList = apiScenarioMapper.selectByExample(example);
Map<String, List<ApiScenario>> nodeMap = new HashMap<>();
ApiScenarioModuleService apiScenarioModuleService = CommonBeanFactory.getBean(ApiScenarioModuleService.class);
for (ApiScenario api : scenarioList) {
//检查是否同名
SaveApiScenarioRequest apiScenarioRequest = new SaveApiScenarioRequest();
apiScenarioRequest.setProjectId(api.getProjectId());
apiScenarioRequest.setName(api.getName());
apiScenarioRequest.setId(api.getId());
apiScenarioRequest.setApiScenarioModuleId(api.getApiScenarioModuleId());
apiScenarioRequest.setModulePath(api.getModulePath());
apiScenarioRequest.setVersionId(extProjectVersionMapper.getDefaultVersion(request.getProjectId()));
String moduleId = api.getApiScenarioModuleId();
long nodeCount = apiScenarioModuleService.countById(moduleId);
if (nodeCount <= 0) {
checkNameExist(apiScenarioRequest, true);
} else {
checkNameExist(apiScenarioRequest, false);
}
if (StringUtils.isEmpty(moduleId)) {
moduleId = "";
}
@ -654,7 +669,6 @@ public class ApiAutomationService {
nodeMap.put(moduleId, list);
}
}
ApiScenarioModuleService apiScenarioModuleService = CommonBeanFactory.getBean(ApiScenarioModuleService.class);
for (Map.Entry<String, List<ApiScenario>> entry : nodeMap.entrySet()) {
String nodeId = entry.getKey();
List<ApiScenario> scenariosListItem = entry.getValue();
@ -681,20 +695,26 @@ public class ApiAutomationService {
});
}
private void checkNameExist(SaveApiScenarioRequest request) {
private void checkNameExist(SaveApiScenarioRequest request, Boolean moduleIdNotExist) {
if (StringUtils.isEmpty(request.getVersionId())) {
request.setVersionId(extProjectVersionMapper.getDefaultVersion(request.getProjectId()));
}
ApiScenarioExample example = new ApiScenarioExample();
example.createCriteria().andNameEqualTo(request.getName())
ApiScenarioExample.Criteria criteria = example.createCriteria();
criteria.andNameEqualTo(request.getName())
.andProjectIdEqualTo(request.getProjectId())
.andStatusNotEqualTo("Trash")
.andIdNotEqualTo(request.getId())
.andVersionIdEqualTo(request.getVersionId())
.andApiScenarioModuleIdEqualTo(request.getApiScenarioModuleId());
if (moduleIdNotExist) {
criteria.andModulePathEqualTo(request.getModulePath());
} else {
criteria.andApiScenarioModuleIdEqualTo(request.getApiScenarioModuleId());
}
if (apiScenarioMapper.countByExample(example) > 0) {
MSException.throwException(Translator.get("automation_name_already_exists"));
MSException.throwException(Translator.get("automation_name_already_exists") + " :" + Translator.get("api_definition_module") + request.getModulePath() + " ," + Translator.get("automation_name") + " :" + request.getName());
}
}

View File

@ -471,17 +471,22 @@ public class ApiDefinitionService {
for (ApiDefinition apiDefinition : reductionCaseList) {
//检查是否同名
SaveApiDefinitionRequest apiDefinitionRequest = new SaveApiDefinitionRequest();
apiDefinitionRequest.setProjectId(request.getProjectId());
apiDefinitionRequest.setProjectId(apiDefinition.getProjectId());
apiDefinitionRequest.setMethod(apiDefinition.getMethod());
apiDefinitionRequest.setProtocol(apiDefinition.getProtocol());
apiDefinitionRequest.setPath(apiDefinition.getPath());
apiDefinitionRequest.setName(apiDefinition.getName());
apiDefinitionRequest.setId(apiDefinition.getId());
apiDefinitionRequest.setModuleId(apiDefinition.getModuleId());
apiDefinitionRequest.setVersionId(extProjectVersionMapper.getDefaultVersion(request.getProjectId()));
checkNameExist(apiDefinitionRequest);
apiDefinitionRequest.setModulePath(apiDefinition.getModulePath());
String moduleId = apiDefinition.getModuleId();
long nodeCount = apiModuleService.countById(moduleId);
if (nodeCount <= 0) {
checkNameExist(apiDefinitionRequest, true);
} else {
checkNameExist(apiDefinitionRequest, false);
}
if (StringUtils.isEmpty(moduleId)) {
moduleId = "";
}
@ -526,42 +531,52 @@ public class ApiDefinitionService {
}
}
private void checkNameExist(SaveApiDefinitionRequest request) {
private void checkNameExist(SaveApiDefinitionRequest request, Boolean moduleIdNotExist) {
if (StringUtils.isEmpty(request.getVersionId())) {
request.setVersionId(extProjectVersionMapper.getDefaultVersion(request.getProjectId()));
}
ApiDefinitionExample example = new ApiDefinitionExample();
if (StringUtils.isNotEmpty(request.getProtocol()) && request.getProtocol().equals(RequestType.HTTP)) {
ApiDefinitionExample.Criteria criteria = example.createCriteria();
if (StringUtils.isNotEmpty(request.getProtocol()) && request.getProtocol().equals(RequestType.HTTP)) {
criteria.andMethodEqualTo(request.getMethod()).andStatusNotEqualTo("Trash")
.andProtocolEqualTo(request.getProtocol()).andPathEqualTo(request.getPath())
.andProjectIdEqualTo(request.getProjectId()).andIdNotEqualTo(request.getId())
.andVersionIdEqualTo(request.getVersionId()).andModuleIdEqualTo(request.getModuleId());
.andVersionIdEqualTo(request.getVersionId());
Project project = projectMapper.selectByPrimaryKey(request.getProjectId());
ProjectConfig config = projectApplicationService.getSpecificTypeValue(project.getId(), ProjectApplicationType.URL_REPEATABLE.name());
boolean urlRepeat = config.getUrlRepeatable();
if (moduleIdNotExist) {
criteria.andModulePathEqualTo(request.getModulePath());
} else {
criteria.andModuleIdEqualTo(request.getModuleId());
}
if (project != null && urlRepeat) {
criteria.andNameEqualTo(request.getName());
if (apiDefinitionMapper.countByExample(example) > 0) {
MSException.throwException(Translator.get("api_definition_name_not_repeating"));
MSException.throwException(Translator.get("api_definition_name_not_repeating") + " :" + Translator.get("api_definition_module") + ":" + request.getModulePath() + " ," + Translator.get("api_definition_name") + " :" + request.getName() + "-" + request.getPath());
}
} else {
if (apiDefinitionMapper.countByExample(example) > 0) {
MSException.throwException(Translator.get("api_definition_url_not_repeating"));
MSException.throwException(Translator.get("api_definition_url_not_repeating") + " :" + Translator.get("api_definition_module") + ":" + request.getModulePath() + " ," + Translator.get("api_definition_name") + " :" + request.getName());
}
}
} else {
example.createCriteria().andProtocolEqualTo(request.getProtocol()).andStatusNotEqualTo("Trash")
criteria.andProtocolEqualTo(request.getProtocol()).andStatusNotEqualTo("Trash")
.andNameEqualTo(request.getName()).andProjectIdEqualTo(request.getProjectId())
.andIdNotEqualTo(request.getId()).andVersionIdEqualTo(request.getVersionId()).andModuleIdEqualTo(request.getModuleId());
.andIdNotEqualTo(request.getId()).andVersionIdEqualTo(request.getVersionId());
if (moduleIdNotExist) {
criteria.andModulePathEqualTo(request.getModulePath());
} else {
criteria.andModuleIdEqualTo(request.getModuleId());
}
if (apiDefinitionMapper.countByExample(example) > 0) {
MSException.throwException(Translator.get("load_test_already_exists"));
MSException.throwException(Translator.get("api_definition_name_already_exists") + " :" + Translator.get("api_definition_module") + ":" + request.getModulePath() + " ," + Translator.get("api_definition_name") + " :" + request.getName());
}
}
}
private ApiDefinitionWithBLOBs updateTest(SaveApiDefinitionRequest request) {
checkNameExist(request);
checkNameExist(request, false);
if (StringUtils.equals(request.getMethod(), "ESB")) {
//ESB的接口类型数据采用TCP方式去发送并将方法类型改为TCP 并修改发送数据
request = esbApiParamService.handleEsbRequest(request);
@ -707,7 +722,7 @@ public class ApiDefinitionService {
}
private ApiDefinitionResult createTest(SaveApiDefinitionRequest request) {
checkNameExist(request);
checkNameExist(request, false);
if (StringUtils.equals(request.getMethod(), "ESB")) {
//ESB的接口类型数据采用TCP方式去发送并将方法类型改为TCP 并修改发送数据
request = esbApiParamService.handleEsbRequest(request);

View File

@ -227,13 +227,17 @@ upload_content_is_null=Imported content is empty
test_plan_notification=Test plan notification
task_defect_notification=Task defect notification
task_notification_=Timing task result notification
api_definition_url_not_repeating=The interface request address already exists
api_definition_name_not_repeating=The same name-url combination already exists
api_definition_url_not_repeating=The interface request address already exists under the same module
api_definition_name_not_repeating=The same name-url combination already exists under the same module
api_definition_name_already_exists=Interface names under the same module cannot be repeated
api_definition_module=The module path is
task_notification_jenkins=Jenkins Task notification
api_definition_name=Interface
task_notification=Result notification
message_task_already_exists=Task recipient already exists
#automation
automation_name_already_exists=the scenario already exists in the module of the same project
automation_name=Scenario
automation_exec_info=There are no test steps to execute
delete_check_reference_by=be referenced by Scenario
not_execute=Not execute

View File

@ -227,13 +227,17 @@ upload_content_is_null=导入内容为空
test_plan_notification=测试计划通知
task_defect_notification=缺陷任务通知
task_notification_=定时任务结果通知
api_definition_url_not_repeating=接口请求地址已经存在
api_definition_name_not_repeating=相同的名称-url组合已存在
api_definition_url_not_repeating=同一模块下接口请求地址已经存在
api_definition_name_not_repeating=同一模块下相同的名称-url组合已存在
api_definition_name_already_exists=同一模块下接口名称不能重复
api_definition_module=模块路径为
api_definition_name=接口
task_notification_jenkins=jenkins任务通知
task_notification=任务通知
message_task_already_exists=任务接收人已经存在
#automation
automation_name_already_exists=同一个项目的同一模块下,场景名称不能重复
automation_name=场景
automation_exec_info=没有测试步骤,无法执行
delete_check_reference_by=被场景引用
not_execute=未执行

View File

@ -226,13 +226,17 @@ upload_content_is_null=導入內容為空
test_plan_notification=測試計劃通知
task_defect_notification=缺陷任務通知
task_notification_=定時任務結果通知
api_definition_url_not_repeating=接口請求地址已經存在
api_definition_name_not_repeating=相同的名稱-url組合已存在
api_definition_url_not_repeating=同一模塊下介面請求地址已經存在
api_definition_name_not_repeating=同一模塊下相同的名稱-url組合已存在
api_definition_name_already_exists=同一模塊下介面名稱不能重複
api_definition_module=模塊路徑為
api_definition_name=介面
task_notification_jenkins=jenkins任務通知
task_notification=任務通知
message_task_already_exists=任務接收人已經存在
#automation
automation_name_already_exists=同一個項目同一模塊下,場景名稱不能重復
automation_name=場景
automation_exec_info=沒有測試步驟,無法執行
delete_check_reference_by=被場景引用
not_execute=未執行