refactor(项目管理): 配置日志参数优化,增加三方平台配置校验

This commit is contained in:
WangXu10 2023-10-20 19:04:26 +08:00 committed by 刘瑞斌
parent c3904fd1d2
commit 7ff569957e
6 changed files with 77 additions and 58 deletions

View File

@ -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

View File

@ -342,3 +342,5 @@ file.name.cannot.be.empty=文件名称不能为空
#file management over
# template
project_template_permission_error=未开启项目模板
third_part_config_is_null=第三方平台配置信息不能为空

View File

@ -342,4 +342,4 @@ file.name.cannot.be.empty=文件名稱不能為空
# template
project_template_permission_error=未開啟項目模板
third_part_config_is_null=第三方平臺配置信息不能爲空

View File

@ -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());
}

View File

@ -290,83 +290,79 @@ public class ProjectApplicationService {
/**
* 测试计划 日志
*
* @param applications
* @param application
* @return
*/
public List<LogDTO> updateTestPlanLog(List<ProjectApplication> 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<LogDTO> updateUiLog(List<ProjectApplication> 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<LogDTO> updatePerformanceLog(List<ProjectApplication> 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<LogDTO> updateApiLog(List<ProjectApplication> 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<LogDTO> updateCaseLog(List<ProjectApplication> 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<LogDTO> updateWorkstationLog(List<ProjectApplication> applications) {
return delLog(applications, OperationLogModule.PROJECT_PROJECT_MANAGER, "工作台配置");
public LogDTO updateWorkstationLog(ProjectApplication application) {
return delLog(application, OperationLogModule.PROJECT_PROJECT_MANAGER, "工作台配置");
}
private List<LogDTO> delLog(List<ProjectApplication> applications, String module, String content) {
List<LogDTO> logs = new ArrayList<>();
applications.forEach(application -> {
ProjectApplicationExample example = new ProjectApplicationExample();
example.createCriteria().andTypeEqualTo(application.getType()).andProjectIdEqualTo(application.getProjectId());
List<ProjectApplication> 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<ProjectApplication> 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;
}

View File

@ -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<String, String> 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<String, String> mockTestData() {
String jsonConfig = "{\"jiraKey\":\"111\",\"jiraIssueTypeId\":\"10086\",\"jiraStoryTypeId\":\"10010\"}";
Map<String, String> 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<String, String> 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<String, String> mockRelatedTestData() {
String jsonConfig = "{\"jiraKey\":\"111\",\"jiraIssueTypeId\":\"10086\",\"jiraStoryTypeId\":\"10010\"}";
Map<String, String> 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");
}
}