refactor(项目管理): 优化缺陷命名&测试用例补充

This commit is contained in:
WangXu10 2023-10-11 10:19:02 +08:00 committed by Craftsman
parent ef5e46fa83
commit 4dd7177430
12 changed files with 150 additions and 121 deletions

View File

@ -118,8 +118,8 @@ INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_API:UPDATE'); INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_API:UPDATE');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_CASE:READ'); INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_CASE:READ');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_CASE:UPDATE'); INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_CASE:UPDATE');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_ISSUE:READ'); INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_BUG:READ');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_ISSUE:UPDATE'); INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_BUG:UPDATE');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_WORKSTATION:READ'); INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_WORKSTATION:READ');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_WORKSTATION:UPDATE'); INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_WORKSTATION:UPDATE');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_LOG:READ'); INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_LOG:READ');

View File

@ -154,8 +154,8 @@ public class PermissionConstants {
public static final String PROJECT_APPLICATION_API_UPDATE = "PROJECT_APPLICATION_API:UPDATE"; public static final String PROJECT_APPLICATION_API_UPDATE = "PROJECT_APPLICATION_API:UPDATE";
public static final String PROJECT_APPLICATION_CASE_READ = "PROJECT_APPLICATION_CASE:READ"; public static final String PROJECT_APPLICATION_CASE_READ = "PROJECT_APPLICATION_CASE:READ";
public static final String PROJECT_APPLICATION_CASE_UPDATE = "PROJECT_APPLICATION_CASE:UPDATE"; public static final String PROJECT_APPLICATION_CASE_UPDATE = "PROJECT_APPLICATION_CASE:UPDATE";
public static final String PROJECT_APPLICATION_ISSUE_READ = "PROJECT_APPLICATION_ISSUE:READ"; public static final String PROJECT_APPLICATION_BUG_READ = "PROJECT_APPLICATION_BUG:READ";
public static final String PROJECT_APPLICATION_ISSUE_UPDATE = "PROJECT_APPLICATION_ISSUE:UPDATE"; public static final String PROJECT_APPLICATION_BUG_UPDATE = "PROJECT_APPLICATION_BUG:UPDATE";
public static final String PROJECT_APPLICATION_WORKSTATION_READ = "PROJECT_APPLICATION_WORKSTATION:READ"; public static final String PROJECT_APPLICATION_WORKSTATION_READ = "PROJECT_APPLICATION_WORKSTATION:READ";
public static final String PROJECT_APPLICATION_WORKSTATION_UPDATE = "PROJECT_APPLICATION_WORKSTATION:UPDATE"; public static final String PROJECT_APPLICATION_WORKSTATION_UPDATE = "PROJECT_APPLICATION_WORKSTATION:UPDATE";
/*------ end: PROJECT_APPLICATION ------*/ /*------ end: PROJECT_APPLICATION ------*/

View File

@ -62,13 +62,13 @@ public class ProjectApplicationType {
//缺陷管理 //缺陷管理
public enum ISSUE{ public enum BUG{
ISSUE_SYNC BUG_SYNC
} }
//缺陷管理-同步配置项 //缺陷管理-同步配置项
public enum ISSUE_SYNC_CONFIG{ public enum BUG_SYNC_CONFIG{
CRON_EXPRESSION, CRON_EXPRESSION,
SYNC_ENABLE, SYNC_ENABLE,
MECHANISM, MECHANISM,

View File

@ -132,8 +132,8 @@ permission.project_application_api.read=API test read
permission.project_application_api.update=API test update permission.project_application_api.update=API test update
permission.project_application_case.read=Case read permission.project_application_case.read=Case read
permission.project_application_case.update=Case update permission.project_application_case.update=Case update
permission.project_application_issue.read=Issue read permission.project_application_bug.read=Bug read
permission.project_application_issue.update=Issue update permission.project_application_bug.update=Bug update
permission.project_application_workstation.read=Workstation read permission.project_application_workstation.read=Workstation read
permission.project_application_workstation.update=Workstation update permission.project_application_workstation.update=Workstation update
permission.project_base_info.name=Project base info permission.project_base_info.name=Project base info

View File

@ -132,8 +132,8 @@ permission.project_application_api.read=接口测试-查询
permission.project_application_api.update=接口测试-编辑 permission.project_application_api.update=接口测试-编辑
permission.project_application_case.read=用例管理-查询 permission.project_application_case.read=用例管理-查询
permission.project_application_case.update=用例管理-编辑 permission.project_application_case.update=用例管理-编辑
permission.project_application_issue.read=缺陷管理-查询 permission.project_application_bug.read=缺陷管理-查询
permission.project_application_issue.update=缺陷管理-编辑 permission.project_application_bug.update=缺陷管理-编辑
permission.project_application_workstation.read=工作台-查询 permission.project_application_workstation.read=工作台-查询
permission.project_application_workstation.update=工作台-编辑 permission.project_application_workstation.update=工作台-编辑
permission.project_base_info.name=基本信息 permission.project_base_info.name=基本信息

View File

@ -132,8 +132,8 @@ permission.project_application_api.read=接口測試-查詢
permission.project_application_api.update=接口測試-編輯 permission.project_application_api.update=接口測試-編輯
permission.project_application_case.read=用例管理-查詢 permission.project_application_case.read=用例管理-查詢
permission.project_application_case.update=用例管理-編輯 permission.project_application_case.update=用例管理-編輯
permission.project_application_issue.read=缺陷管理-查詢 permission.project_application_bug.read=缺陷管理-查詢
permission.project_application_issue.update=缺陷管理-編輯 permission.project_application_bug.update=缺陷管理-編輯
permission.project_application_workstation.read=工作台-查詢 permission.project_application_workstation.read=工作台-查詢
permission.project_application_workstation.update=工作台-編輯 permission.project_application_workstation.update=工作台-編輯
permission.project_base_info.name=基本信息 permission.project_base_info.name=基本信息

View File

@ -169,6 +169,7 @@ public class ProjectApplicationController {
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_CASE_READ) @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_CASE_READ)
public List<ProjectApplication> getCase(@Validated @RequestBody ProjectApplicationRequest request) { public List<ProjectApplication> getCase(@Validated @RequestBody ProjectApplicationRequest request) {
List<String> types = Arrays.asList(ProjectApplicationType.CASE.values()).stream().map(ProjectApplicationType.CASE::name).collect(Collectors.toList()); List<String> types = Arrays.asList(ProjectApplicationType.CASE.values()).stream().map(ProjectApplicationType.CASE::name).collect(Collectors.toList());
types.add(ProjectApplicationType.CASE_RELATED_CONFIG.CASE_ENABLE.name());
return projectApplicationService.get(request, types); return projectApplicationService.get(request, types);
} }
@ -199,7 +200,7 @@ public class ProjectApplicationController {
@GetMapping("/case/related/info/{projectId}") @GetMapping("/case/related/info/{projectId}")
@Operation(summary = "用例管理-获取关联需求信息") @Operation(summary = "用例管理-获取关联需求信息")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_ISSUE_READ) @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_CASE_READ)
public Map<String, String> getRelatedConfigInfo(@PathVariable("projectId") String projectId) { public Map<String, String> getRelatedConfigInfo(@PathVariable("projectId") String projectId) {
return projectApplicationService.getRelatedConfigInfo(projectId); return projectApplicationService.getRelatedConfigInfo(projectId);
} }
@ -230,52 +231,52 @@ public class ProjectApplicationController {
* ==========缺陷管理========== * ==========缺陷管理==========
*/ */
@PostMapping("/update/issue") @PostMapping("/update/bug")
@Operation(summary = "缺陷管理-配置") @Operation(summary = "缺陷管理-配置")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_ISSUE_UPDATE) @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_BUG_UPDATE)
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateWorkstationLog(#applications)", msClass = ProjectApplicationService.class) @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateWorkstationLog(#applications)", msClass = ProjectApplicationService.class)
public void updateIssue(@Validated({Updated.class}) @RequestBody List<ProjectApplication> applications) { public void updateBug(@Validated({Updated.class}) @RequestBody List<ProjectApplication> applications) {
projectApplicationService.update(applications, SessionUtils.getUserId()); projectApplicationService.update(applications, SessionUtils.getUserId());
} }
@PostMapping("/issue") @PostMapping("/bug")
@Operation(summary = "缺陷管理-获取配置") @Operation(summary = "缺陷管理-获取配置")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_ISSUE_READ) @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_BUG_READ)
public List<ProjectApplication> getIssue(@Validated @RequestBody ProjectApplicationRequest request) { public List<ProjectApplication> getBug(@Validated @RequestBody ProjectApplicationRequest request) {
List<String> types = Arrays.asList(ProjectApplicationType.WORKSTATION.values()).stream().map(ProjectApplicationType.WORKSTATION::name).collect(Collectors.toList()); List<String> types = Arrays.asList(ProjectApplicationType.BUG_SYNC_CONFIG.SYNC_ENABLE.name());
return projectApplicationService.get(request, types); return projectApplicationService.get(request, types);
} }
@GetMapping("/issue/platform/{organizationId}") @GetMapping("/bug/platform/{organizationId}")
@Operation(summary = "缺陷管理-获取平台下拉框列表") @Operation(summary = "缺陷管理-获取平台下拉框列表")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_ISSUE_READ) @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_BUG_READ)
public List<OptionDTO> getIssuePlatformOptions(@PathVariable String organizationId) { public List<OptionDTO> getBugPlatformOptions(@PathVariable String organizationId) {
return projectApplicationService.getPlatformOptions(organizationId); return projectApplicationService.getPlatformOptions(organizationId);
} }
@GetMapping("/issue/platform/info/{pluginId}") @GetMapping("/bug/platform/info/{pluginId}")
@Operation(summary = "缺陷管理-选择平台获取平台信息") @Operation(summary = "缺陷管理-选择平台获取平台信息")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_ISSUE_READ) @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_BUG_READ)
public Object getIssuePlatformInfo(@PathVariable String pluginId) { public Object getBugPlatformInfo(@PathVariable String pluginId) {
return projectApplicationService.getPluginScript(pluginId); return projectApplicationService.getPluginScript(pluginId);
} }
@PostMapping("/update/issue/sync/{projectId}") @PostMapping("/update/bug/sync/{projectId}")
@Operation(summary = "缺陷管理-同步缺陷配置") @Operation(summary = "缺陷管理-同步缺陷配置")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_ISSUE_UPDATE) @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_BUG_UPDATE)
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateIssueSyncLog(#projectId, #configs)", msClass = ProjectApplicationService.class) @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateBugSyncLog(#projectId, #configs)", msClass = ProjectApplicationService.class)
public void syncIssueConfig(@PathVariable("projectId") String projectId, @RequestBody Map<String, String> configs) { public void syncBugConfig(@PathVariable("projectId") String projectId, @RequestBody Map<String, String> configs) {
projectApplicationService.syncIssueConfig(projectId, configs, SessionUtils.getUserId()); projectApplicationService.syncBugConfig(projectId, configs, SessionUtils.getUserId());
} }
@GetMapping("/issue/sync/info/{projectId}") @GetMapping("/bug/sync/info/{projectId}")
@Operation(summary = "缺陷管理-获取同步缺陷信息") @Operation(summary = "缺陷管理-获取同步缺陷信息")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_ISSUE_READ) @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_BUG_READ)
public Map<String, String> getIssueConfigInfo(@PathVariable("projectId") String projectId) { public Map<String, String> getBugConfigInfo(@PathVariable("projectId") String projectId) {
return projectApplicationService.getIssueConfigInfo(projectId); return projectApplicationService.getBugConfigInfo(projectId);
} }

View File

@ -5,17 +5,17 @@ import org.quartz.JobExecutionContext;
import org.quartz.JobKey; import org.quartz.JobKey;
import org.quartz.TriggerKey; import org.quartz.TriggerKey;
public class IssueSyncJob extends BaseScheduleJob { public class BugSyncJob extends BaseScheduleJob {
@Override @Override
protected void businessExecute(JobExecutionContext context) { protected void businessExecute(JobExecutionContext context) {
//TODO 定时任务执行 同步issue //TODO 定时任务执行 同步issue
} }
public static JobKey getJobKey(String projectId) { public static JobKey getJobKey(String projectId) {
return new JobKey(projectId, IssueSyncJob.class.getName()); return new JobKey(projectId, BugSyncJob.class.getName());
} }
public static TriggerKey getTriggerKey(String projectId) { public static TriggerKey getTriggerKey(String projectId) {
return new TriggerKey(projectId, IssueSyncJob.class.getName()); return new TriggerKey(projectId, BugSyncJob.class.getName());
} }
} }

View File

@ -6,11 +6,12 @@ import io.metersphere.project.domain.ProjectApplication;
import io.metersphere.project.domain.ProjectApplicationExample; import io.metersphere.project.domain.ProjectApplicationExample;
import io.metersphere.project.dto.ModuleDTO; import io.metersphere.project.dto.ModuleDTO;
import io.metersphere.project.job.CleanUpReportJob; import io.metersphere.project.job.CleanUpReportJob;
import io.metersphere.project.job.IssueSyncJob; import io.metersphere.project.job.BugSyncJob;
import io.metersphere.project.mapper.ExtProjectMapper; import io.metersphere.project.mapper.ExtProjectMapper;
import io.metersphere.project.mapper.ExtProjectUserRoleMapper; import io.metersphere.project.mapper.ExtProjectUserRoleMapper;
import io.metersphere.project.mapper.ProjectApplicationMapper; import io.metersphere.project.mapper.ProjectApplicationMapper;
import io.metersphere.project.request.ProjectApplicationRequest; import io.metersphere.project.request.ProjectApplicationRequest;
import io.metersphere.project.utils.ModuleSortUtils;
import io.metersphere.sdk.constants.OperationLogConstants; import io.metersphere.sdk.constants.OperationLogConstants;
import io.metersphere.sdk.constants.ProjectApplicationType; import io.metersphere.sdk.constants.ProjectApplicationType;
import io.metersphere.sdk.constants.ScheduleType; import io.metersphere.sdk.constants.ScheduleType;
@ -209,41 +210,41 @@ public class ProjectApplicationService {
* @param projectId * @param projectId
* @param configs * @param configs
*/ */
public void syncIssueConfig(String projectId, Map<String, String> configs, String currentUser) { public void syncBugConfig(String projectId, Map<String, String> configs, String currentUser) {
List<ProjectApplication> issueSyncConfigs = configs.entrySet().stream().map(config -> new ProjectApplication(projectId, ProjectApplicationType.ISSUE.ISSUE_SYNC.name() + "_" + config.getKey().toUpperCase(), config.getValue())).collect(Collectors.toList()); List<ProjectApplication> bugSyncConfigs = configs.entrySet().stream().map(config -> new ProjectApplication(projectId, ProjectApplicationType.BUG.BUG_SYNC.name() + "_" + config.getKey().toUpperCase(), config.getValue())).collect(Collectors.toList());
//处理同步缺陷定时任务配置 //处理同步缺陷定时任务配置
doSaveOrUpdateSchedule(issueSyncConfigs, projectId, currentUser); doSaveOrUpdateSchedule(bugSyncConfigs, projectId, currentUser);
ProjectApplicationExample example = new ProjectApplicationExample(); ProjectApplicationExample example = new ProjectApplicationExample();
example.createCriteria().andProjectIdEqualTo(projectId).andTypeLike(ProjectApplicationType.ISSUE.ISSUE_SYNC.name() + "%"); example.createCriteria().andProjectIdEqualTo(projectId).andTypeLike(ProjectApplicationType.BUG.BUG_SYNC.name() + "%");
if (projectApplicationMapper.countByExample(example) > 0) { if (projectApplicationMapper.countByExample(example) > 0) {
example.clear(); example.clear();
example.createCriteria().andTypeLike(ProjectApplicationType.ISSUE.ISSUE_SYNC.name() + "%"); example.createCriteria().andTypeLike(ProjectApplicationType.BUG.BUG_SYNC.name() + "%");
projectApplicationMapper.deleteByExample(example); projectApplicationMapper.deleteByExample(example);
projectApplicationMapper.batchInsert(issueSyncConfigs); projectApplicationMapper.batchInsert(bugSyncConfigs);
} else { } else {
projectApplicationMapper.batchInsert(issueSyncConfigs); projectApplicationMapper.batchInsert(bugSyncConfigs);
} }
} }
private void doSaveOrUpdateSchedule(List<ProjectApplication> issueSyncConfigs, String projectId, String currentUser) { private void doSaveOrUpdateSchedule(List<ProjectApplication> bugSyncConfigs, String projectId, String currentUser) {
List<ProjectApplication> syncCron = issueSyncConfigs.stream().filter(config -> config.getType().equals(ProjectApplicationType.ISSUE.ISSUE_SYNC.name() + "_" + ProjectApplicationType.ISSUE_SYNC_CONFIG.CRON_EXPRESSION.name())).collect(Collectors.toList()); List<ProjectApplication> syncCron = bugSyncConfigs.stream().filter(config -> config.getType().equals(ProjectApplicationType.BUG.BUG_SYNC.name() + "_" + ProjectApplicationType.BUG_SYNC_CONFIG.CRON_EXPRESSION.name())).collect(Collectors.toList());
List<ProjectApplication> syncEnable = issueSyncConfigs.stream().filter(config -> config.getType().equals(ProjectApplicationType.ISSUE.ISSUE_SYNC.name() + "_" + ProjectApplicationType.ISSUE_SYNC_CONFIG.SYNC_ENABLE.name())).collect(Collectors.toList()); List<ProjectApplication> syncEnable = bugSyncConfigs.stream().filter(config -> config.getType().equals(ProjectApplicationType.BUG.BUG_SYNC.name() + "_" + ProjectApplicationType.BUG_SYNC_CONFIG.SYNC_ENABLE.name())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(syncCron)) { if (CollectionUtils.isNotEmpty(syncCron)) {
Boolean enable = Boolean.valueOf(syncEnable.get(0).getTypeValue()); Boolean enable = Boolean.valueOf(syncEnable.get(0).getTypeValue());
String typeValue = syncCron.get(0).getTypeValue(); String typeValue = syncCron.get(0).getTypeValue();
Schedule schedule = scheduleService.getScheduleByResource(projectId, IssueSyncJob.class.getName()); Schedule schedule = scheduleService.getScheduleByResource(projectId, BugSyncJob.class.getName());
Optional<Schedule> optional = Optional.ofNullable(schedule); Optional<Schedule> optional = Optional.ofNullable(schedule);
optional.ifPresentOrElse(s -> { optional.ifPresentOrElse(s -> {
s.setEnable(enable); s.setEnable(enable);
s.setValue(typeValue); s.setValue(typeValue);
scheduleService.editSchedule(s); scheduleService.editSchedule(s);
scheduleService.addOrUpdateCronJob(s, scheduleService.addOrUpdateCronJob(s,
IssueSyncJob.getJobKey(projectId), BugSyncJob.getJobKey(projectId),
IssueSyncJob.getTriggerKey(projectId), BugSyncJob.getTriggerKey(projectId),
IssueSyncJob.class); BugSyncJob.class);
}, () -> { }, () -> {
Schedule request = new Schedule(); Schedule request = new Schedule();
request.setName("Issue Sync Job"); request.setName("Bug Sync Job");
request.setResourceId(projectId); request.setResourceId(projectId);
request.setKey(projectId); request.setKey(projectId);
request.setProjectId(projectId); request.setProjectId(projectId);
@ -252,12 +253,12 @@ public class ProjectApplicationService {
request.setType(ScheduleType.CRON.name()); request.setType(ScheduleType.CRON.name());
// 每天凌晨2点执行清理任务 // 每天凌晨2点执行清理任务
request.setValue(typeValue); request.setValue(typeValue);
request.setJob(IssueSyncJob.class.getName()); request.setJob(BugSyncJob.class.getName());
scheduleService.addSchedule(request); scheduleService.addSchedule(request);
scheduleService.addOrUpdateCronJob(request, scheduleService.addOrUpdateCronJob(request,
IssueSyncJob.getJobKey(projectId), BugSyncJob.getJobKey(projectId),
IssueSyncJob.getTriggerKey(projectId), BugSyncJob.getTriggerKey(projectId),
IssueSyncJob.class); BugSyncJob.class);
}); });
} }
} }
@ -269,14 +270,14 @@ public class ProjectApplicationService {
* @param projectId * @param projectId
* @return * @return
*/ */
public Map<String, String> getIssueConfigInfo(String projectId) { public Map<String, String> getBugConfigInfo(String projectId) {
ProjectApplicationExample example = new ProjectApplicationExample(); ProjectApplicationExample example = new ProjectApplicationExample();
example.createCriteria().andProjectIdEqualTo(projectId).andTypeLike(ProjectApplicationType.ISSUE.ISSUE_SYNC.name() + "_%"); example.createCriteria().andProjectIdEqualTo(projectId).andTypeLike(ProjectApplicationType.BUG.BUG_SYNC.name() + "_%");
List<ProjectApplication> list = projectApplicationMapper.selectByExample(example); List<ProjectApplication> list = projectApplicationMapper.selectByExample(example);
Map<String, String> collect = new HashMap<>(); Map<String, String> collect = new HashMap<>();
if (CollectionUtils.isNotEmpty(list)) { if (CollectionUtils.isNotEmpty(list)) {
list.stream().forEach(config -> { list.stream().forEach(config -> {
collect.put(config.getType().replace(ProjectApplicationType.ISSUE.ISSUE_SYNC.name() + "_", "").toLowerCase(), config.getTypeValue()); collect.put(config.getType().replace(ProjectApplicationType.BUG.BUG_SYNC.name() + "_", "").toLowerCase(), config.getTypeValue());
}); });
} }
return collect; return collect;
@ -373,8 +374,8 @@ public class ProjectApplicationService {
* @param configs * @param configs
* @return * @return
*/ */
public LogDTO updateIssueSyncLog(String projectId, Map<String, String> configs) { public LogDTO updateBugSyncLog(String projectId, Map<String, String> configs) {
Map<String, String> originConfig = getIssueConfigInfo(projectId); Map<String, String> originConfig = getBugConfigInfo(projectId);
LogDTO dto = new LogDTO( LogDTO dto = new LogDTO(
projectId, projectId,
"", "",
@ -435,6 +436,10 @@ public class ProjectApplicationService {
} }
}); });
moduleDTOList = moduleMap.entrySet().stream().map(entry -> new ModuleDTO(entry.getKey(), entry.getValue())).collect(Collectors.toList()); moduleDTOList = moduleMap.entrySet().stream().map(entry -> new ModuleDTO(entry.getKey(), entry.getValue())).collect(Collectors.toList());
Map<String, Integer> module = ModuleSortUtils.getHashMap();
if (CollectionUtils.isNotEmpty(moduleDTOList)) {
moduleDTOList.sort((o1, o2) -> module.getOrDefault(o1.getModule(), Integer.MAX_VALUE) - module.getOrDefault(o2.getModule(), Integer.MAX_VALUE));
}
} }
return moduleDTOList; return moduleDTOList;
} }

View File

@ -0,0 +1,22 @@
package io.metersphere.project.utils;
import java.util.HashMap;
import java.util.Map;
public class ModuleSortUtils {
public static Map<String, Integer> hashMap = new HashMap<>(7);
public static Map<String, Integer> getHashMap() {
hashMap.put("workstation", 1);
hashMap.put("testPlan", 2);
hashMap.put("bugManagement", 3);
hashMap.put("caseManagement", 4);
hashMap.put("apiTest", 5);
hashMap.put("uiTest", 6);
hashMap.put("loadTest", 7);
return hashMap;
}
}

View File

@ -159,25 +159,6 @@
} }
] ]
}, },
{
"id": "PROJECT_FAKE_ERROR",
"name": "permission.project_fake_error.name",
"license": true,
"permissions": [
{
"id": "PROJECT_FAKE_ERROR:READ"
},
{
"id": "PROJECT_FAKE_ERROR:READ+ADD"
},
{
"id": "PROJECT_FAKE_ERROR:READ+UPDATE"
},
{
"id": "PROJECT_FAKE_ERROR:READ+DELETE"
}
]
},
{ {
"id": "PROJECT_APPLICATION", "id": "PROJECT_APPLICATION",
"name": "permission.project_application.name", "name": "permission.project_application.name",
@ -224,12 +205,12 @@
"name": "permission.project_application_case.update" "name": "permission.project_application_case.update"
}, },
{ {
"id": "PROJECT_APPLICATION_ISSUE:READ", "id": "PROJECT_APPLICATION_BUG:READ",
"name": "permission.project_application_issue.read" "name": "permission.project_application_bug.read"
}, },
{ {
"id": "PROJECT_APPLICATION_ISSUE:UPDATE", "id": "PROJECT_APPLICATION_BUG:UPDATE",
"name": "permission.project_application_issue.update" "name": "permission.project_application_bug.update"
}, },
{ {
"id": "PROJECT_APPLICATION_WORKSTATION:READ", "id": "PROJECT_APPLICATION_WORKSTATION:READ",

View File

@ -16,6 +16,9 @@ import jakarta.annotation.Resource;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
import org.mockserver.client.MockServerClient;
import org.mockserver.model.Header;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockMultipartFile; import org.springframework.mock.web.MockMultipartFile;
@ -30,6 +33,8 @@ import java.util.*;
import static io.metersphere.sdk.constants.InternalUserRole.ADMIN; import static io.metersphere.sdk.constants.InternalUserRole.ADMIN;
import static io.metersphere.system.controller.handler.result.MsHttpResultCode.NOT_FOUND; import static io.metersphere.system.controller.handler.result.MsHttpResultCode.NOT_FOUND;
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ -407,33 +412,33 @@ public class ProjectApplicationControllerTests extends BaseTest {
/** /**
* ==========缺陷管理 start========== * ==========缺陷管理 start==========
*/ */
public static final String ISSUE_UPDATE_URL = "/project/application/update/issue"; public static final String BUG_UPDATE_URL = "/project/application/update/bug";
public static final String GET_ISSUE_URL = "/project/application/issue"; public static final String GET_BUG_URL = "/project/application/bug";
public static final String GET_ISSUE_PLATFORM_URL = "/project/application/issue/platform"; public static final String GET_BUG_PLATFORM_URL = "/project/application/bug/platform";
public static final String GET_ISSUE_PLATFORM_INFO_URL = "/project/application/issue/platform/info"; public static final String GET_BUG_PLATFORM_INFO_URL = "/project/application/bug/platform/info";
//工作台 //工作台
@Test @Test
@Order(29) @Order(29)
public void testIssue() throws Exception { public void testBug() throws Exception {
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.ISSUE.ISSUE_SYNC.name()), "true"); List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.BUG.BUG_SYNC.name()), "true");
this.requestPost(ISSUE_UPDATE_URL, request); this.requestPost(BUG_UPDATE_URL, request);
} }
@Test @Test
@Order(30) @Order(30)
public void testGetIssue() throws Exception { public void testGetBug() throws Exception {
ProjectApplicationRequest request = this.getRequest("ISSUE"); ProjectApplicationRequest request = this.getRequest("BUG");
this.requestPostWithOkAndReturn(GET_ISSUE_URL, request); this.requestPostWithOkAndReturn(GET_BUG_URL, request);
} }
//缺陷管理 - 获取平台下拉列表 //缺陷管理 - 获取平台下拉列表
@Test @Test
@Order(31) @Order(31)
public void testGetIssuePlatform() throws Exception { public void testGetBugPlatform() throws Exception {
this.requestGetWithOkAndReturn(GET_ISSUE_PLATFORM_URL + "/100002"); this.requestGetWithOkAndReturn(GET_BUG_PLATFORM_URL + "/100002");
MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_ISSUE_PLATFORM_URL + "/100001"); MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_BUG_PLATFORM_URL + "/100001");
// 获取返回值 // 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
@ -445,8 +450,8 @@ public class ProjectApplicationControllerTests extends BaseTest {
//缺陷管理 - 获取平台信息 //缺陷管理 - 获取平台信息
@Test @Test
@Order(32) @Order(32)
public void testGetIssuePlatformInfo() throws Exception { public void testGetBugPlatformInfo() throws Exception {
MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_ISSUE_PLATFORM_INFO_URL + "/" + plugin.getId()); MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_BUG_PLATFORM_INFO_URL + "/" + plugin.getId());
// 获取返回值 // 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
@ -495,31 +500,28 @@ public class ProjectApplicationControllerTests extends BaseTest {
} }
public static final String UPDATE_ISSUE_CONFIG_URL = "/project/application/update/issue/sync"; public static final String UPDATE_BUG_CONFIG_URL = "/project/application/update/bug/sync";
public static final String GET_ISSUE_CONFIG_INFO_URL = "/project/application/issue/sync/info"; public static final String GET_BUG_CONFIG_INFO_URL = "/project/application/bug/sync/info";
@Test @Test
@Order(34) @Order(34)
public void testIssueConfig() throws Exception { public void testBugConfig() throws Exception {
Map<String, String> configs = mockTestData(); Map<String, String> congifs = mockTestData();
MvcResult mvcResult = this.requestPostWithOkAndReturn(UPDATE_ISSUE_CONFIG_URL + "/default-project-2", configs); MvcResult mvcResult = this.requestPostWithOkAndReturn(UPDATE_BUG_CONFIG_URL + "/default-project-2", congifs);
// 获取返回值 // 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
// 返回请求正常 // 返回请求正常
Assertions.assertNotNull(resultHolder); Assertions.assertNotNull(resultHolder);
congifs.put("jiraKey", "222");
//更新 MvcResult updateResult = this.requestPostWithOkAndReturn(UPDATE_BUG_CONFIG_URL + "/default-project-2", congifs);
configs.put("jiraKey", "222");
MvcResult updateResult = this.requestPostWithOkAndReturn(UPDATE_ISSUE_CONFIG_URL + "/default-project-2", configs);
// 获取返回值 // 获取返回值
String updateData = updateResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String updateData = updateResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder updateResultHolder = JSON.parseObject(updateData, ResultHolder.class); ResultHolder updateResultHolder = JSON.parseObject(updateData, ResultHolder.class);
// 返回请求正常 // 返回请求正常
Assertions.assertNotNull(updateResultHolder); Assertions.assertNotNull(updateResultHolder);
congifs.remove("CRON_EXPRESSION");
configs.remove("CRON_EXPRESSION"); this.requestPostWithOkAndReturn(UPDATE_BUG_CONFIG_URL + "/default-project-2", congifs);
this.requestPostWithOkAndReturn(UPDATE_ISSUE_CONFIG_URL + "/default-project-2", configs);
} }
private Map<String, String> mockTestData() { private Map<String, String> mockTestData() {
@ -536,8 +538,8 @@ public class ProjectApplicationControllerTests extends BaseTest {
@Test @Test
@Order(35) @Order(35)
public void testIssueConfigInfo() throws Exception { public void testBugConfigInfo() throws Exception {
MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_ISSUE_CONFIG_INFO_URL + "/default-project-2"); MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_BUG_CONFIG_INFO_URL + "/default-project-2");
// 获取返回值 // 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
@ -562,7 +564,7 @@ public class ProjectApplicationControllerTests extends BaseTest {
//更新 //更新
List<ProjectApplication> request = creatRequest(Arrays.asList("bugManagement"), "false"); List<ProjectApplication> request = creatRequest(Arrays.asList("bugManagement"), "false");
request.get(0).setProjectId("100001100001"); request.get(0).setProjectId("100001100001");
this.requestPost(ISSUE_UPDATE_URL, request); this.requestPost(BUG_UPDATE_URL, request);
MvcResult updateMvcResult = this.requestGetWithOkAndReturn(GET_MODULE_SETTING_URL + "/100001100001"); MvcResult updateMvcResult = this.requestGetWithOkAndReturn(GET_MODULE_SETTING_URL + "/100001100001");
// 获取返回值 // 获取返回值
String updateReturnData = updateMvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String updateReturnData = updateMvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
@ -620,7 +622,12 @@ public class ProjectApplicationControllerTests extends BaseTest {
public static final String CHECK_PROJECT_KEY_URL = "/project/application/validate"; public static final String CHECK_PROJECT_KEY_URL = "/project/application/validate";
@Resource
private MockServerClient mockServerClient;
@Value("${embedded.mockserver.host}")
private String mockServerHost;
@Value("${embedded.mockserver.port}")
private int mockServerHostPort;
@Test @Test
@Order(39) @Order(39)
public void testCheckProjectKey() throws Exception { public void testCheckProjectKey() throws Exception {
@ -630,6 +637,7 @@ public class ProjectApplicationControllerTests extends BaseTest {
configs.put("jiraStoryTypeId", "10010"); configs.put("jiraStoryTypeId", "10010");
assertErrorCode(this.requestPost(CHECK_PROJECT_KEY_URL + "/" + plugin.getId(), configs), NOT_FOUND); assertErrorCode(this.requestPost(CHECK_PROJECT_KEY_URL + "/" + plugin.getId(), configs), NOT_FOUND);
JiraIntegrationConfig integrationConfig = new JiraIntegrationConfig(); JiraIntegrationConfig integrationConfig = new JiraIntegrationConfig();
integrationConfig.setAddress(String.format("http://%s:%s", mockServerHost, mockServerHostPort));
Map<String, Object> integrationConfigMap = JSON.parseMap(JSON.toJSONString(integrationConfig)); Map<String, Object> integrationConfigMap = JSON.parseMap(JSON.toJSONString(integrationConfig));
ServiceIntegrationUpdateRequest request = new ServiceIntegrationUpdateRequest(); ServiceIntegrationUpdateRequest request = new ServiceIntegrationUpdateRequest();
request.setEnable(true); request.setEnable(true);
@ -637,13 +645,25 @@ public class ProjectApplicationControllerTests extends BaseTest {
request.setConfiguration(integrationConfigMap); request.setConfiguration(integrationConfigMap);
request.setOrganizationId("100001100001"); request.setOrganizationId("100001100001");
this.requestPostWithOkAndReturn("/service/integration/add", request); this.requestPostWithOkAndReturn("/service/integration/add", request);
// TODO 缺少有效数据 mockServerClient
/*MvcResult mvcResult = this.requestPostWithOkAndReturn(CHECK_PROJECT_KEY_URL + "/" + plugin.getId(), configs); .when(
request()
.withMethod("GET")
.withPath("/rest/api/2/project/Test"))
.respond(
response()
.withStatusCode(200)
.withHeaders(
new Header("Content-Type", "application/json; charset=utf-8"),
new Header("Cache-Control", "public, max-age=86400"))
.withBody("{\"id\":\"123456\",\"name\":\"test\"}")
);
MvcResult mvcResult = this.requestPostWithOkAndReturn(CHECK_PROJECT_KEY_URL + "/" + plugin.getId(), configs);
// 获取返回值 // 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
// 返回请求正常 // 返回请求正常
Assertions.assertNotNull(resultHolder);*/ Assertions.assertNotNull(resultHolder);
} }
@Getter @Getter