refactor(项目设置): 项目版本资源接口实现
This commit is contained in:
parent
8fd6d79a8b
commit
7cc063f6d5
|
@ -153,5 +153,8 @@ VALUES(uuid(), (select id from custom_field where name = 'functional_priority'),
|
|||
Insert into project_robot(id, project_id, name, platform, webhook, type, app_key, app_secret, enable, create_user, create_time, update_user, update_time, description) VALUES (UUID_SHORT(), '100001100001', '站内信', 'IN_SITE', 'NONE', null, null, null, true, 'admin', unix_timestamp() * 1000,'admin', unix_timestamp() * 1000, null);
|
||||
Insert into project_robot(id, project_id, name, platform, webhook, type, app_key, app_secret, enable, create_user, create_time, update_user, update_time, description) VALUES (UUID_SHORT(), '100001100001', '邮件', 'MAIL', 'NONE', null, null, null, true, 'admin', unix_timestamp() * 1000,'admin', unix_timestamp() * 1000, null);
|
||||
|
||||
-- 初始化默认项目版本
|
||||
INSERT INTO project_version (id, project_id, name, description, status, latest, publish_time, start_time, end_time, create_time, create_user) VALUES (UUID_SHORT(), 'default_project', 'v1.0', NULL, 'open', 0, NULL, NULL, NULL, UNIX_TIMESTAMP(), 'admin');
|
||||
|
||||
-- set innodb lock wait timeout to default
|
||||
SET SESSION innodb_lock_wait_timeout = DEFAULT;
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package io.metersphere.project.service;
|
||||
|
||||
import io.metersphere.project.domain.ProjectVersionExample;
|
||||
import io.metersphere.project.mapper.ProjectVersionMapper;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.system.service.CleanupProjectResourceService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 项目删除-清空版本资源
|
||||
*
|
||||
* @author song-cc-rock
|
||||
*/
|
||||
@Component
|
||||
public class CleanupVersionResourceService implements CleanupProjectResourceService {
|
||||
|
||||
@Resource
|
||||
private ProjectVersionMapper projectVersionMapper;
|
||||
@Override
|
||||
public void deleteResources(String projectId) {
|
||||
// 删除所有项目版本
|
||||
ProjectVersionExample example = new ProjectVersionExample();
|
||||
example.createCriteria().andProjectIdEqualTo(projectId);
|
||||
projectVersionMapper.deleteByExample(example);
|
||||
LogUtils.info("清理当前项目[" + projectId + "]相关版本资源");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanReportResources(String projectId) {
|
||||
LogUtils.info("清理当前项目[" + projectId + "]相关报告资源");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package io.metersphere.project.service;
|
||||
|
||||
import io.metersphere.project.domain.ProjectVersion;
|
||||
import io.metersphere.project.mapper.ProjectVersionMapper;
|
||||
import io.metersphere.sdk.constants.InternalUserRole;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.system.service.CreateProjectResourceService;
|
||||
import io.metersphere.system.uid.UUID;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 项目创建-初始化版本资源
|
||||
*
|
||||
* @author song-cc-rock
|
||||
*/
|
||||
@Component
|
||||
public class CreateVersionResourceService implements CreateProjectResourceService {
|
||||
|
||||
public static final String DEFAULT_VERSION = "v1.0";
|
||||
public static final String DEFAULT_VERSION_STATUS = "open";
|
||||
|
||||
@Resource
|
||||
private ProjectVersionMapper projectVersionMapper;
|
||||
|
||||
@Override
|
||||
public void createResources(String projectId) {
|
||||
// 初始化版本V1.0
|
||||
ProjectVersion defaultVersion = new ProjectVersion();
|
||||
defaultVersion.setId(UUID.randomUUID().toString());
|
||||
defaultVersion.setProjectId(projectId);
|
||||
defaultVersion.setName(DEFAULT_VERSION);
|
||||
defaultVersion.setStatus(DEFAULT_VERSION_STATUS);
|
||||
defaultVersion.setLatest(true);
|
||||
defaultVersion.setCreateTime(System.currentTimeMillis());
|
||||
defaultVersion.setCreateUser(InternalUserRole.ADMIN.getValue());
|
||||
projectVersionMapper.insert(defaultVersion);
|
||||
LogUtils.info("初始化当前项目[" + projectId + "]相关版本资源");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package io.metersphere.project.controller;
|
||||
|
||||
import io.metersphere.project.domain.ProjectVersion;
|
||||
import io.metersphere.project.domain.ProjectVersionExample;
|
||||
import io.metersphere.project.mapper.ProjectVersionMapper;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.invoker.ProjectServiceInvoker;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
@AutoConfigureMockMvc
|
||||
public class ProjectVersionResourceTests extends BaseTest {
|
||||
|
||||
private final ProjectServiceInvoker serviceInvoker;
|
||||
|
||||
public static final String TEST_PROJECT_ID = "project-version-test-id";
|
||||
|
||||
@Resource
|
||||
private ProjectVersionMapper projectVersionMapper;
|
||||
|
||||
@Autowired
|
||||
public ProjectVersionResourceTests(ProjectServiceInvoker serviceInvoker) {
|
||||
this.serviceInvoker = serviceInvoker;
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
public void test() {
|
||||
ProjectVersionExample example = new ProjectVersionExample();
|
||||
example.createCriteria().andProjectIdEqualTo(TEST_PROJECT_ID);
|
||||
// 默认为空
|
||||
List<ProjectVersion> projectVersions = projectVersionMapper.selectByExample(example);
|
||||
Assertions.assertTrue(projectVersions.isEmpty());
|
||||
// 项目资源初始化版本, 默认为一条版本记录
|
||||
serviceInvoker.invokeCreateServices(TEST_PROJECT_ID);
|
||||
List<ProjectVersion> createVersions = projectVersionMapper.selectByExample(example);
|
||||
Assertions.assertEquals(1, createVersions.size());
|
||||
// 项目资源清理版本, 为空
|
||||
serviceInvoker.invokeServices(TEST_PROJECT_ID);
|
||||
List<ProjectVersion> cleanUpVersions = projectVersionMapper.selectByExample(example);
|
||||
Assertions.assertTrue(cleanUpVersions.isEmpty());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue