部分国际化

This commit is contained in:
Captain.B 2020-03-05 15:27:47 +08:00
parent 8025d1102c
commit 0fed287cdb
6 changed files with 37 additions and 16 deletions

View File

@ -24,6 +24,7 @@ import java.util.List;
@RestController
@RequestMapping(value = "/testplan")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
public class LoadTestController {
@Resource
private LoadTestService loadTestService;
@ -31,7 +32,6 @@ public class LoadTestController {
private FileService fileService;
@GetMapping("recent/{count}")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
public List<LoadTestDTO> recentTestPlans(@PathVariable int count) {
String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId();
QueryTestPlanRequest request = new QueryTestPlanRequest();
@ -84,7 +84,7 @@ public class LoadTestController {
}
@PostMapping("/run")
public void delete(@RequestBody RunTestPlanRequest request) {
public void run(@RequestBody RunTestPlanRequest request) {
loadTestService.run(request);
}

View File

@ -1,9 +1,6 @@
package io.metersphere.service;
import io.metersphere.base.domain.FileContent;
import io.metersphere.base.domain.FileMetadata;
import io.metersphere.base.domain.LoadTestFile;
import io.metersphere.base.domain.LoadTestWithBLOBs;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtLoadTestMapper;
import io.metersphere.commons.constants.EngineType;
@ -12,6 +9,7 @@ import io.metersphere.controller.request.testplan.*;
import io.metersphere.dto.LoadTestDTO;
import io.metersphere.engine.Engine;
import io.metersphere.engine.EngineFactory;
import io.metersphere.i18n.Translator;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@ -69,6 +67,13 @@ public class LoadTestService {
}
private LoadTestWithBLOBs saveLoadTest(SaveTestPlanRequest request) {
LoadTestExample example = new LoadTestExample();
example.createCriteria().andNameEqualTo(request.getName()).andProjectIdEqualTo(request.getProjectId());
if (loadTestMapper.countByExample(example) > 0) {
MSException.throwException(Translator.get("load_test_already_exists"));
}
final LoadTestWithBLOBs loadTest = new LoadTestWithBLOBs();
loadTest.setId(UUID.randomUUID().toString());
loadTest.setName(request.getName());

View File

@ -7,9 +7,9 @@ import io.metersphere.base.mapper.ext.ExtProjectMapper;
import io.metersphere.commons.exception.MSException;
import io.metersphere.controller.request.ProjectRequest;
import io.metersphere.dto.ProjectDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.user.SessionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -27,14 +27,14 @@ public class ProjectService {
public Project addProject(Project project) {
if (StringUtils.isBlank(project.getName())) {
MSException.throwException("Project name cannot be null");
MSException.throwException(Translator.get("project_name_is_null"));
}
ProjectExample example = new ProjectExample();
example.createCriteria()
.andWorkspaceIdEqualTo(SessionUtils.getCurrentWorkspaceId())
.andNameEqualTo(project.getName());
if (projectMapper.countByExample(example) > 0) {
MSException.throwException("The project name already exists");
MSException.throwException(Translator.get("project_name_already_exists"));
}
project.setId(UUID.randomUUID().toString());
long createTime = System.currentTimeMillis();

View File

@ -13,6 +13,7 @@ import io.metersphere.controller.request.WorkspaceRequest;
import io.metersphere.dto.UserRoleHelpDTO;
import io.metersphere.dto.WorkspaceDTO;
import io.metersphere.dto.WorkspaceMemberDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.user.SessionUser;
import io.metersphere.user.SessionUtils;
import org.apache.commons.lang3.StringUtils;
@ -44,7 +45,7 @@ public class WorkspaceService {
public Workspace saveWorkspace(Workspace workspace) {
if (StringUtils.isBlank(workspace.getName())) {
MSException.throwException("Workspace name cannot be null.");
MSException.throwException(Translator.get("workspace_name_is_null"));
}
// set organization id
workspace.setOrganizationId(SessionUtils.getCurrentOrganizationId());
@ -56,7 +57,7 @@ public class WorkspaceService {
.andOrganizationIdEqualTo(SessionUtils.getCurrentOrganizationId())
.andNameEqualTo(workspace.getName());
if (workspaceMapper.countByExample(example) > 0) {
MSException.throwException("The workspace name already exists");
MSException.throwException(Translator.get("workspace_name_already_exists"));
}
workspace.setId(UUID.randomUUID().toString()); // 设置ID
workspace.setCreateTime(currentTime);
@ -89,6 +90,9 @@ public class WorkspaceService {
workspaceMapper.deleteByPrimaryKey(workspaceId);
}
/**
* ORG_ADMIN 需要检查是否有操作此工作空间的权限
*/
public void checkOwner(String workspaceId) {
SessionUser user = SessionUtils.getUser();
List<String> orgIds = user.getUserRoles().stream()
@ -100,7 +104,7 @@ public class WorkspaceService {
.andOrganizationIdIn(orgIds)
.andIdEqualTo(workspaceId);
if (workspaceMapper.countByExample(example) == 0) {
MSException.throwException("The current workspace does not belong to the current user");
MSException.throwException(Translator.get("workspace_does_not_belong_to_user"));
}
}

View File

@ -1,3 +1,9 @@
{
"error_lang_invalid": "Invalid language parameter"
"error_lang_invalid": "Invalid language parameter",
"load_test_already_exists": "Duplicate load test name",
"project_name_is_null": "Project name cannot be null",
"project_name_already_exists": "The project name already exists",
"workspace_name_is_null": "Workspace name cannot be null",
"workspace_name_already_exists": "The workspace name already exists",
"workspace_does_not_belong_to_user": "The current workspace does not belong to the current user"
}

View File

@ -1,3 +1,9 @@
{
"error_lang_invalid": "语言参数错误"
"error_lang_invalid": "语言参数错误",
"load_test_already_exists": "测试名称不能重复",
"project_name_is_null": "项目名称不能为空",
"project_name_already_exists": "项目名称已存在",
"workspace_name_is_null": "工作空间名不能为空",
"workspace_name_already_exists": "工作空间名已存在",
"workspace_does_not_belong_to_user": "当前工作空间不属于当前用户"
}