diff --git a/backend/src/main/java/io/metersphere/service/ProjectService.java b/backend/src/main/java/io/metersphere/service/ProjectService.java index e4c0afc1ad..51c1f9f2ae 100644 --- a/backend/src/main/java/io/metersphere/service/ProjectService.java +++ b/backend/src/main/java/io/metersphere/service/ProjectService.java @@ -128,18 +128,11 @@ public class ProjectService { private ApiScenarioReportStructureMapper apiScenarioReportStructureMapper; @Resource private ApiScenarioReportResultMapper apiScenarioReportResultMapper; + @Resource + private WorkspaceMapper workspaceMapper; public Project addProject(AddProjectRequest project) { - if (StringUtils.isBlank(project.getName())) { - MSException.throwException(Translator.get("project_name_is_null")); - } - ProjectExample example = new ProjectExample(); - example.createCriteria() - .andWorkspaceIdEqualTo(project.getWorkspaceId()) - .andNameEqualTo(project.getName()); - if (projectMapper.countByExample(example) > 0) { - MSException.throwException(Translator.get("project_name_already_exists")); - } + this.checkCreateProjectParam(project); QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class); if (quotaService != null) { @@ -195,6 +188,29 @@ public class ProjectService { return project; } + private void checkCreateProjectParam(AddProjectRequest project) { + String name = project.getName(); + if (StringUtils.isBlank(name)) { + MSException.throwException(Translator.get("project_name_is_null")); + } + + String workspaceId = project.getWorkspaceId(); + if (StringUtils.isBlank(workspaceId)) { + MSException.throwException("project workspace_id is null"); + } + + Workspace workspace = workspaceMapper.selectByPrimaryKey(workspaceId); + if (workspace == null) { + MSException.throwException("project workspace_id is not exist."); + } + + ProjectExample example = new ProjectExample(); + example.createCriteria().andWorkspaceIdEqualTo(workspaceId).andNameEqualTo(name); + if (projectMapper.countByExample(example) > 0) { + MSException.throwException(Translator.get("project_name_already_exists")); + } + } + public void addProjectVersion(Project project) { ProjectVersion projectVersion = new ProjectVersion(); projectVersion.setId(UUID.randomUUID().toString());