refactor(项目管理): 修改返回option对象

This commit is contained in:
wxg0103 2023-09-21 18:56:37 +08:00 committed by wxg0103
parent b73229e74b
commit 2e6d636997
8 changed files with 49 additions and 36 deletions

View File

@ -5,10 +5,10 @@ import io.metersphere.project.request.ProjectSwitchRequest;
import io.metersphere.project.service.ProjectLogService;
import io.metersphere.project.service.ProjectService;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.dto.OptionDTO;
import io.metersphere.sdk.dto.UserDTO;
import io.metersphere.system.dto.ProjectDTO;
import io.metersphere.system.dto.UpdateProjectRequest;
import io.metersphere.sdk.dto.UserDTO;
import io.metersphere.system.domain.TestResourcePool;
import io.metersphere.system.log.annotation.Log;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.utils.SessionUtils;
@ -61,7 +61,7 @@ public class ProjectController {
@GetMapping("/pool-options/{type}/{projectId}")
@Operation(summary = "项目管理-获取项目下的资源池")
@RequiresPermissions(PermissionConstants.PROJECT_BASE_INFO_READ)
public List<TestResourcePool> getPoolOptions(@PathVariable String type ,@PathVariable String projectId) {
public List<OptionDTO> getPoolOptions(@PathVariable String type , @PathVariable String projectId) {
return projectService.getPoolOptions(projectId, type);
}

View File

@ -10,6 +10,7 @@ import io.metersphere.project.mapper.ProjectTestResourcePoolMapper;
import io.metersphere.project.request.ProjectSwitchRequest;
import io.metersphere.sdk.constants.InternalUserRole;
import io.metersphere.sdk.constants.ModuleType;
import io.metersphere.sdk.dto.OptionDTO;
import io.metersphere.sdk.dto.SessionUser;
import io.metersphere.sdk.dto.UserDTO;
import io.metersphere.sdk.exception.MSException;
@ -161,14 +162,14 @@ public class ProjectService {
return poolIds;
}
public List<TestResourcePool> getPoolOptions(String projectId, String type) {
//判断项目是否关联了资源池
public List<OptionDTO> getPoolOptions(String projectId, String type) {
checkProjectNotExist(projectId);
List<String> poolIds = getPoolIds(projectId);
TestResourcePoolExample example = new TestResourcePoolExample();
TestResourcePoolExample.Criteria criteria = example.createCriteria();
criteria.andIdIn(poolIds).andEnableEqualTo(true).andDeletedEqualTo(false);
return switch (type) {
List<TestResourcePool> testResourcePools = new ArrayList<>();
testResourcePools = switch (type) {
case ModuleType.API_TEST-> {
criteria.andApiTestEqualTo(true);
yield testResourcePoolMapper.selectByExample(example);
@ -183,5 +184,8 @@ public class ProjectService {
}
default -> new ArrayList<>();
};
return testResourcePools.stream().map(testResourcePool ->
new OptionDTO(testResourcePool.getId(), testResourcePool.getName())
).toList();
}
}

View File

@ -8,13 +8,12 @@ import io.metersphere.project.request.ProjectSwitchRequest;
import io.metersphere.sdk.constants.ModuleType;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.constants.SessionConstants;
import io.metersphere.system.dto.ProjectDTO;
import io.metersphere.system.dto.UpdateProjectRequest;
import io.metersphere.sdk.dto.UserDTO;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.domain.TestResourcePool;
import io.metersphere.system.dto.ProjectDTO;
import io.metersphere.system.dto.UpdateProjectRequest;
import io.metersphere.system.log.constants.OperationLogType;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
@ -67,6 +66,15 @@ public class ProjectControllerTests extends BaseTest {
return null;
}
private void responseGet(String url, ResultMatcher resultMatcher) throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get(url)
.header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(resultMatcher)
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
}
private MvcResult responseGet(String url) throws Exception {
return mockMvc.perform(MockMvcRequestBuilders.get(url)
.header(SessionConstants.HEADER_TOKEN, sessionId)
@ -323,15 +331,14 @@ public class ProjectControllerTests extends BaseTest {
mvcResult = this.responseGet(getPoolOptions + ModuleType.UI_TEST + "/" + DEFAULT_PROJECT_ID);
mvcResult = this.responseGet(getPoolOptions + ModuleType.LOAD_TEST + "/" + DEFAULT_PROJECT_ID);
mvcResult = this.responseGet(getPoolOptions + "test" + "/" + DEFAULT_PROJECT_ID);
List<TestResourcePool> list = parseObjectFromMvcResult(mvcResult, List.class);
//断言为空的list
Assertions.assertEquals(0, list.size());
mvcResult = this.responseGet(getPoolOptions + ModuleType.API_TEST + "/" + "projectId");
mvcResult = this.responseGet(getPoolOptions + ModuleType.UI_TEST + "/" + "projectId");
mvcResult = this.responseGet(getPoolOptions + ModuleType.LOAD_TEST + "/" + "projectId");
//项目不存在
this.responseGet(getPoolOptions + ModuleType.LOAD_TEST + "/" + "projectId20", status().is5xxServerError());
//权限校验
requestGetPermissionTest(PermissionConstants.PROJECT_BASE_INFO_READ, getPoolOptions + "api_test" + "/" + DEFAULT_PROJECT_ID);
}

View File

@ -4,22 +4,22 @@ package io.metersphere.system.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.dto.*;
import io.metersphere.system.domain.TestResourcePool;
import io.metersphere.sdk.dto.OptionDTO;
import io.metersphere.sdk.dto.UserExtend;
import io.metersphere.sdk.util.PageUtils;
import io.metersphere.sdk.util.Pager;
import io.metersphere.system.dto.AddProjectRequest;
import io.metersphere.system.dto.ProjectDTO;
import io.metersphere.system.dto.UpdateProjectRequest;
import io.metersphere.system.log.annotation.Log;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.sdk.util.PageUtils;
import io.metersphere.sdk.util.Pager;
import io.metersphere.system.utils.SessionUtils;
import io.metersphere.system.request.OrganizationProjectRequest;
import io.metersphere.system.request.ProjectAddMemberBatchRequest;
import io.metersphere.system.request.ProjectAddMemberRequest;
import io.metersphere.system.request.ProjectMemberRequest;
import io.metersphere.system.service.OrganizationProjectLogService;
import io.metersphere.system.service.OrganizationProjectService;
import io.metersphere.system.utils.SessionUtils;
import io.metersphere.validation.groups.Created;
import io.metersphere.validation.groups.Updated;
import io.swagger.v3.oas.annotations.Operation;
@ -161,7 +161,7 @@ public class OrganizationProjectController {
@GetMapping("/pool-options/{organizationId}")
@Operation(summary = "系统设置-组织-项目-获取资源池下拉选项")
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ)
public List<TestResourcePool> getProjectOptions(@PathVariable String organizationId) {
public List<OptionDTO> getProjectOptions(@PathVariable String organizationId) {
return organizationProjectService.getTestResourcePoolOptions(organizationId);
}

View File

@ -4,10 +4,10 @@ package io.metersphere.system.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.dto.*;
import io.metersphere.sdk.dto.OptionDTO;
import io.metersphere.sdk.dto.UserExtend;
import io.metersphere.sdk.util.PageUtils;
import io.metersphere.sdk.util.Pager;
import io.metersphere.system.domain.TestResourcePool;
import io.metersphere.system.domain.User;
import io.metersphere.system.dto.AddProjectRequest;
import io.metersphere.system.dto.ProjectDTO;
@ -156,7 +156,7 @@ public class SystemProjectController {
@GetMapping("/pool-options/{organizationId}")
@Operation(summary = "系统设置-系统-组织与项目-项目-获取资源池下拉选项")
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
public List<TestResourcePool> getProjectOptions(@PathVariable String organizationId) {
public List<OptionDTO> getProjectOptions(@PathVariable String organizationId) {
return systemProjectService.getTestResourcePoolOptions(organizationId);
}

View File

@ -588,7 +588,7 @@ public class CommonProjectService {
projectMapper.updateByPrimaryKeySelective(project);
}
public List<TestResourcePool> getTestResourcePoolOptions(String organizationId) {
public List<OptionDTO> getTestResourcePoolOptions(String organizationId) {
//获取制定组织的资源池 和全部组织的资源池
List<TestResourcePool> testResourcePools = new ArrayList<>();
TestResourcePoolOrganizationExample example = new TestResourcePoolOrganizationExample();
@ -606,6 +606,8 @@ public class CommonProjectService {
testResourcePools.addAll(testResourcePoolMapper.selectByExample(poolExample));
testResourcePools = testResourcePools.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList());
return testResourcePools;
return testResourcePools.stream().map(testResourcePool ->
new OptionDTO(testResourcePool.getId(), testResourcePool.getName())
).toList();
}
}

View File

@ -1,17 +1,17 @@
package io.metersphere.system.service;
import io.metersphere.sdk.dto.*;
import io.metersphere.sdk.dto.OptionDTO;
import io.metersphere.sdk.dto.UserExtend;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.system.domain.TestResourcePool;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.UserRoleRelation;
import io.metersphere.system.domain.UserRoleRelationExample;
import io.metersphere.system.dto.AddProjectRequest;
import io.metersphere.system.dto.ProjectDTO;
import io.metersphere.system.dto.UpdateProjectRequest;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.UserRoleRelation;
import io.metersphere.system.domain.UserRoleRelationExample;
import io.metersphere.system.mapper.ExtSystemProjectMapper;
import io.metersphere.system.mapper.OrganizationMapper;
import io.metersphere.system.mapper.UserRoleRelationMapper;
@ -130,7 +130,7 @@ public class OrganizationProjectService {
}
}
public List<TestResourcePool> getTestResourcePoolOptions(String organizationId) {
public List<OptionDTO> getTestResourcePoolOptions(String organizationId) {
return commonProjectService.getTestResourcePoolOptions(organizationId);
}
}

View File

@ -1,15 +1,15 @@
package io.metersphere.system.service;
import io.metersphere.project.domain.Project;
import io.metersphere.sdk.dto.*;
import io.metersphere.system.domain.TestResourcePool;
import io.metersphere.sdk.dto.OptionDTO;
import io.metersphere.sdk.dto.UserExtend;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.dto.AddProjectRequest;
import io.metersphere.system.dto.OrganizationProjectOptionsDTO;
import io.metersphere.system.dto.ProjectDTO;
import io.metersphere.system.dto.UpdateProjectRequest;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.dto.OrganizationProjectOptionsDTO;
import io.metersphere.system.mapper.ExtSystemProjectMapper;
import io.metersphere.system.request.ProjectAddMemberBatchRequest;
import io.metersphere.system.request.ProjectMemberRequest;
@ -99,7 +99,7 @@ public class SystemProjectService {
commonProjectService.disable(id, updateUser);
}
public List<TestResourcePool> getTestResourcePoolOptions(String organizationId) {
public List<OptionDTO> getTestResourcePoolOptions(String organizationId) {
return commonProjectService.getTestResourcePoolOptions(organizationId);
}