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 caef1f312d..bfde235433 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -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 bodyFiles, List scenarioFiles) { - checkNameExist(request); + checkNameExist(request, false); checkScenarioNum(request); //检查场景的请求步骤。如果含有ESB请求步骤的话,要做参数计算处理。 @@ -641,8 +641,23 @@ public class ApiAutomationService { example.createCriteria().andIdIn(scenarioIds); List scenarioList = apiScenarioMapper.selectByExample(example); Map> 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> entry : nodeMap.entrySet()) { String nodeId = entry.getKey(); List 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()); } } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index ea4862105f..71ef39eea8 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -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(); + ApiDefinitionExample.Criteria criteria = example.createCriteria(); if (StringUtils.isNotEmpty(request.getProtocol()) && request.getProtocol().equals(RequestType.HTTP)) { - ApiDefinitionExample.Criteria criteria = example.createCriteria(); 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); diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index 33acde60a1..23021e6ee3 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -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 diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index e793d89017..a824261e84 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -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=未执行 diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index 1312d8529b..f5cf66fc10 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -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=未執行