From 7ff569957e8639426a1052b70578b41c2e888303 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Fri, 20 Oct 2023 19:04:26 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E9=A1=B9=E7=9B=AE=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=20=E9=85=8D=E7=BD=AE=E6=97=A5=E5=BF=97=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E9=85=8D=E7=BD=AE=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/i18n/project_en_US.properties | 1 + .../resources/i18n/project_zh_CN.properties | 2 + .../resources/i18n/project_zh_TW.properties | 2 +- .../ProjectApplicationController.java | 28 ++++++-- .../service/ProjectApplicationService.java | 68 +++++++++---------- .../ProjectApplicationControllerTests.java | 34 ++++++---- 6 files changed, 77 insertions(+), 58 deletions(-) diff --git a/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties index 53ad3eeeb3..4da043a074 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties @@ -343,3 +343,4 @@ file.name.cannot.be.empty=File name cannot be empty # template project_template_permission_error=The project template is not turned on +third_part_config_is_null=Third party configuration cannot be empty \ No newline at end of file diff --git a/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties index 8631334cb6..4672485653 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties @@ -342,3 +342,5 @@ file.name.cannot.be.empty=文件名称不能为空 #file management over # template project_template_permission_error=未开启项目模板 + +third_part_config_is_null=第三方平台配置信息不能为空 \ No newline at end of file diff --git a/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties index 0a1030edc4..717d8caff0 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties @@ -342,4 +342,4 @@ file.name.cannot.be.empty=文件名稱不能為空 # template project_template_permission_error=未開啟項目模板 - +third_part_config_is_null=第三方平臺配置信息不能爲空 diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java index 3c954d34e2..63b296f78a 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java @@ -9,6 +9,8 @@ import io.metersphere.sdk.constants.ModuleType; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.ProjectApplicationType; import io.metersphere.sdk.dto.OptionDTO; +import io.metersphere.sdk.exception.MSException; +import io.metersphere.sdk.util.Translator; import io.metersphere.system.domain.User; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; @@ -45,7 +47,7 @@ public class ProjectApplicationController { @PostMapping("/update/test-plan") @Operation(summary = "测试计划-配置") @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_TEST_PLAN_UPDATE) - @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateTestPlanLog(#applications)", msClass = ProjectApplicationService.class) + @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateTestPlanLog(#application)", msClass = ProjectApplicationService.class) public void updateTestPlan(@Validated({Updated.class}) @RequestBody ProjectApplication application) { projectApplicationService.update(application, SessionUtils.getUserId()); } @@ -66,7 +68,7 @@ public class ProjectApplicationController { @PostMapping("/update/ui") @Operation(summary = "UI测试-配置") @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_UI_UPDATE) - @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateUiLog(#applications)", msClass = ProjectApplicationService.class) + @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateUiLog(#application)", msClass = ProjectApplicationService.class) public void updateUI(@Validated({Updated.class}) @RequestBody ProjectApplication application) { projectApplicationService.update(application, SessionUtils.getUserId()); } @@ -94,7 +96,7 @@ public class ProjectApplicationController { @PostMapping("/update/performance-test") @Operation(summary = "性能测试-配置") @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_PERFORMANCE_TEST_UPDATE) - @Log(type = OperationLogType.UPDATE, expression = "#msClass.updatePerformanceLog(#applications)", msClass = ProjectApplicationService.class) + @Log(type = OperationLogType.UPDATE, expression = "#msClass.updatePerformanceLog(#application)", msClass = ProjectApplicationService.class) public void updatePerformanceTest(@Validated({Updated.class}) @RequestBody ProjectApplication application) { projectApplicationService.update(application, SessionUtils.getUserId()); } @@ -122,7 +124,7 @@ public class ProjectApplicationController { @PostMapping("/update/api") @Operation(summary = "接口测试-配置") @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_API_UPDATE) - @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateApiLog(#applications)", msClass = ProjectApplicationService.class) + @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateApiLog(#application)", msClass = ProjectApplicationService.class) public void updateApi(@Validated({Updated.class}) @RequestBody ProjectApplication application) { projectApplicationService.update(application, SessionUtils.getUserId()); } @@ -161,8 +163,14 @@ public class ProjectApplicationController { @PostMapping("/update/case") @Operation(summary = "用例管理-配置") @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_CASE_UPDATE) - @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateCaseLog(#applications)", msClass = ProjectApplicationService.class) + @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateCaseLog(#application)", msClass = ProjectApplicationService.class) public void updateCase(@Validated({Updated.class}) @RequestBody ProjectApplication application) { + if (ProjectApplicationType.CASE_RELATED_CONFIG.CASE_ENABLE.name().equals(application.getType())) { + String projectDemandThirdPartConfig = projectApplicationService.getProjectDemandThirdPartConfig(application.getProjectId()); + if (StringUtils.isBlank(projectDemandThirdPartConfig)) { + throw new MSException(Translator.get("third_part_config_is_null")); + } + } projectApplicationService.update(application, SessionUtils.getUserId()); } @@ -216,7 +224,7 @@ public class ProjectApplicationController { @PostMapping("/update/workstation") @Operation(summary = "工作台-配置") @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_WORKSTATION_UPDATE) - @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateWorkstationLog(#applications)", msClass = ProjectApplicationService.class) + @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateWorkstationLog(#application)", msClass = ProjectApplicationService.class) public void updateWorkstation(@Validated({Updated.class}) @RequestBody ProjectApplication application) { projectApplicationService.update(application, SessionUtils.getUserId()); } @@ -237,8 +245,14 @@ public class ProjectApplicationController { @PostMapping("/update/bug") @Operation(summary = "缺陷管理-配置") @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_BUG_UPDATE) - @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateWorkstationLog(#applications)", msClass = ProjectApplicationService.class) + @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateWorkstationLog(#application)", msClass = ProjectApplicationService.class) public void updateBug(@Validated({Updated.class}) @RequestBody ProjectApplication application) { + if (ProjectApplicationType.BUG_SYNC_CONFIG.SYNC_ENABLE.name().equals(application.getType())) { + String projectBugThirdPartConfig = projectApplicationService.getProjectBugThirdPartConfig(application.getProjectId()); + if (StringUtils.isBlank(projectBugThirdPartConfig)) { + throw new MSException(Translator.get("third_part_config_is_null")); + } + } projectApplicationService.update(application, SessionUtils.getUserId()); } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java index beb70e4d43..4e4ab1ca5f 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java @@ -290,83 +290,79 @@ public class ProjectApplicationService { /** * 测试计划 日志 * - * @param applications + * @param application * @return */ - public List updateTestPlanLog(List applications) { - return delLog(applications, OperationLogModule.PROJECT_PROJECT_MANAGER, "测试计划配置"); + public LogDTO updateTestPlanLog(ProjectApplication application) { + return delLog(application, OperationLogModule.PROJECT_PROJECT_MANAGER, "测试计划配置"); } /** * UI 日志 * - * @param applications + * @param application * @return */ - public List updateUiLog(List applications) { - return delLog(applications, OperationLogModule.PROJECT_PROJECT_MANAGER, "UI配置"); + public LogDTO updateUiLog(ProjectApplication application) { + return delLog(application, OperationLogModule.PROJECT_PROJECT_MANAGER, "UI配置"); } /** * 性能测试 日志 * - * @param applications + * @param application * @return */ - public List updatePerformanceLog(List applications) { - return delLog(applications, OperationLogModule.PROJECT_PROJECT_MANAGER, "性能测试配置"); + public LogDTO updatePerformanceLog(ProjectApplication application) { + return delLog(application, OperationLogModule.PROJECT_PROJECT_MANAGER, "性能测试配置"); } /** * 接口测试 日志 * - * @param applications + * @param application * @return */ - public List updateApiLog(List applications) { - return delLog(applications, OperationLogModule.PROJECT_PROJECT_MANAGER, "接口测试配置"); + public LogDTO updateApiLog(ProjectApplication application) { + return delLog(application, OperationLogModule.PROJECT_PROJECT_MANAGER, "接口测试配置"); } /** * 用例管理 日志 * - * @param applications + * @param application * @return */ - public List updateCaseLog(List applications) { - return delLog(applications, OperationLogModule.PROJECT_PROJECT_MANAGER, "用例管理配置"); + public LogDTO updateCaseLog(ProjectApplication application) { + return delLog(application, OperationLogModule.PROJECT_PROJECT_MANAGER, "用例管理配置"); } /** * 工作台 日志 * - * @param applications + * @param application * @return */ - public List updateWorkstationLog(List applications) { - return delLog(applications, OperationLogModule.PROJECT_PROJECT_MANAGER, "工作台配置"); + public LogDTO updateWorkstationLog(ProjectApplication application) { + return delLog(application, OperationLogModule.PROJECT_PROJECT_MANAGER, "工作台配置"); } - private List delLog(List applications, String module, String content) { - List logs = new ArrayList<>(); - applications.forEach(application -> { - ProjectApplicationExample example = new ProjectApplicationExample(); - example.createCriteria().andTypeEqualTo(application.getType()).andProjectIdEqualTo(application.getProjectId()); - List list = projectApplicationMapper.selectByExample(example); - LogDTO dto = new LogDTO( - application.getProjectId(), - "", - OperationLogConstants.SYSTEM, - null, - OperationLogType.UPDATE.name(), - module, - content); - dto.setOriginalValue(JSON.toJSONBytes(list)); - logs.add(dto); - }); - return logs; + private LogDTO delLog(ProjectApplication application, String module, String content) { + ProjectApplicationExample example = new ProjectApplicationExample(); + example.createCriteria().andTypeEqualTo(application.getType()).andProjectIdEqualTo(application.getProjectId()); + List list = projectApplicationMapper.selectByExample(example); + LogDTO dto = new LogDTO( + application.getProjectId(), + "", + OperationLogConstants.SYSTEM, + null, + OperationLogType.UPDATE.name(), + module, + content); + dto.setOriginalValue(JSON.toJSONBytes(list)); + return dto; } diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java index e37140dde4..cf7d419625 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java @@ -507,15 +507,18 @@ public class ProjectApplicationControllerTests extends BaseTest { @Test @Order(34) public void testBugConfig() throws Exception { + ProjectApplication request = creatRequest(ProjectApplicationType.BUG_SYNC_CONFIG.SYNC_ENABLE.name(), "true"); + this.requestPost(BUG_UPDATE_URL, request); + Map congifs = mockTestData(); - MvcResult mvcResult = this.requestPostWithOkAndReturn(UPDATE_BUG_CONFIG_URL + "/default-project-2", congifs); + MvcResult mvcResult = this.requestPostWithOkAndReturn(UPDATE_BUG_CONFIG_URL + "/project_application_test_id", congifs); // 获取返回值 String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); // 返回请求正常 Assertions.assertNotNull(resultHolder); congifs.put("jiraKey", "222"); - MvcResult updateResult = this.requestPostWithOkAndReturn(UPDATE_BUG_CONFIG_URL + "/default-project-2", congifs); + MvcResult updateResult = this.requestPostWithOkAndReturn(UPDATE_BUG_CONFIG_URL + "/project_application_test_id", congifs); // 获取返回值 String updateData = updateResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder updateResultHolder = JSON.parseObject(updateData, ResultHolder.class); @@ -523,16 +526,17 @@ public class ProjectApplicationControllerTests extends BaseTest { Assertions.assertNotNull(updateResultHolder); congifs.remove("CRON_EXPRESSION"); this.requestPostWithOkAndReturn(UPDATE_BUG_CONFIG_URL + "/default-project-2", congifs); + + ProjectApplication afterRequest = creatRequest(ProjectApplicationType.BUG_SYNC_CONFIG.SYNC_ENABLE.name(), "true"); + this.requestPost(BUG_UPDATE_URL, afterRequest); } private Map mockTestData() { + String jsonConfig = "{\"jiraKey\":\"111\",\"jiraIssueTypeId\":\"10086\",\"jiraStoryTypeId\":\"10010\"}"; Map configs = new HashMap<>(); - configs.put("platform", "jira"); - configs.put("jiraKey", "111"); - configs.put("jiraIssueTypeId", "10086"); - configs.put("jiraStoryTypeId", "10010"); configs.put("CRON_EXPRESSION", "0 0 0/1 * * ?"); configs.put("SYNC_ENABLE", "true"); + configs.put("PLATFORM", jsonConfig); configs.put("MECHANISM", "1"); return configs; } @@ -581,8 +585,10 @@ public class ProjectApplicationControllerTests extends BaseTest { @Test @Order(37) public void testCaseRelatedConfig() throws Exception { + ProjectApplication request = creatRequest(ProjectApplicationType.CASE_RELATED_CONFIG.CASE_ENABLE.name(), "true"); + this.requestPost(CASE_UPDATE_URL, request); Map configs = mockRelatedTestData(); - MvcResult mvcResult = this.requestPostWithOkAndReturn(UPDATE_CASE_RELATED_CONFIG_URL + "/default-project-2", configs); + MvcResult mvcResult = this.requestPostWithOkAndReturn(UPDATE_CASE_RELATED_CONFIG_URL + "/project_application_test_id", configs); // 获取返回值 String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); @@ -591,21 +597,21 @@ public class ProjectApplicationControllerTests extends BaseTest { //更新 configs.put("jiraKey", "222"); - MvcResult updateResult = this.requestPostWithOkAndReturn(UPDATE_CASE_RELATED_CONFIG_URL + "/default-project-2", configs); + MvcResult updateResult = this.requestPostWithOkAndReturn(UPDATE_CASE_RELATED_CONFIG_URL + "/project_application_test_id", configs); // 获取返回值 String updateData = updateResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder updateResultHolder = JSON.parseObject(updateData, ResultHolder.class); // 返回请求正常 Assertions.assertNotNull(updateResultHolder); + ProjectApplication afterRequest = creatRequest(ProjectApplicationType.CASE_RELATED_CONFIG.CASE_ENABLE.name(), "true"); + this.requestPost(CASE_UPDATE_URL, afterRequest); } private Map mockRelatedTestData() { + String jsonConfig = "{\"jiraKey\":\"111\",\"jiraIssueTypeId\":\"10086\",\"jiraStoryTypeId\":\"10010\"}"; Map configs = new HashMap<>(); - configs.put("platform", "jira"); - configs.put("jiraKey", "111"); - configs.put("jiraIssueTypeId", "10086"); - configs.put("jiraStoryTypeId", "10010"); - configs.put("ENABLE", "true"); + configs.put("PLATFORM", jsonConfig); + configs.put("CASE_ENABLE", "true"); return configs; } @@ -692,7 +698,7 @@ public class ProjectApplicationControllerTests extends BaseTest { @Order(40) public void testGetProjectDemandThirdPartConfig() throws Exception { projectApplicationService.getProjectDemandThirdPartConfig(DEFAULT_PROJECT_ID); - projectApplicationService.getProjectDemandThirdPartConfig("test+project_id"); + projectApplicationService.getProjectDemandThirdPartConfig("test_project_id"); } }