feat(消息管理): 新增获取消息模版字段接口
This commit is contained in:
parent
2f9640750d
commit
cea25c2011
|
@ -0,0 +1,30 @@
|
||||||
|
package io.metersphere.project.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import io.metersphere.project.service.NoticeTemplateService;
|
||||||
|
import io.metersphere.sdk.constants.PermissionConstants;
|
||||||
|
import io.metersphere.sdk.dto.OptionDTO;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Tag(name = "项目管理-消息设置-模版设置")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("notice/template/")
|
||||||
|
public class NoticeTemplateController {
|
||||||
|
@Resource
|
||||||
|
private NoticeTemplateService noticeTemplateService;
|
||||||
|
|
||||||
|
@GetMapping("get/fields/{type}")
|
||||||
|
@Operation(summary = "项目管理-消息设置-模版设置-获取消息模版字段")
|
||||||
|
@RequiresPermissions(PermissionConstants.PROJECT_MESSAGE_READ)
|
||||||
|
public List<OptionDTO> getTemplateFields(@PathVariable String type) {
|
||||||
|
return noticeTemplateService.getTemplateFields(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
package io.metersphere.project.service;
|
||||||
|
|
||||||
|
import io.metersphere.api.domain.ApiDefinition;
|
||||||
|
import io.metersphere.api.domain.ApiScenario;
|
||||||
|
import io.metersphere.bug.domain.Bug;
|
||||||
|
import io.metersphere.functional.domain.CaseReview;
|
||||||
|
import io.metersphere.functional.domain.FunctionalCase;
|
||||||
|
import io.metersphere.load.domain.LoadTest;
|
||||||
|
import io.metersphere.plan.domain.TestPlan;
|
||||||
|
import io.metersphere.sdk.dto.OptionDTO;
|
||||||
|
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||||
|
import io.metersphere.ui.domain.UiScenario;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class NoticeTemplateService {
|
||||||
|
|
||||||
|
public List<OptionDTO> getTemplateFields(String type) {
|
||||||
|
List<OptionDTO> optionDTOList = new ArrayList<>();
|
||||||
|
switch (type) {
|
||||||
|
case NoticeConstants.TaskType.API_DEFINITION_TASK -> {
|
||||||
|
Field[] allFields = FieldUtils.getAllFields(ApiDefinition.class);
|
||||||
|
addOptionDto(optionDTOList, allFields);
|
||||||
|
//TODO:获取报告和自定义模版字段
|
||||||
|
}
|
||||||
|
case NoticeConstants.TaskType.API_SCENARIO_TASK, NoticeConstants.TaskType.API_SCHEDULE_TASK -> {
|
||||||
|
Field[] allFields = FieldUtils.getAllFields(ApiScenario.class);
|
||||||
|
addOptionDto(optionDTOList, allFields);
|
||||||
|
//TODO:获取报告和自定义
|
||||||
|
}
|
||||||
|
case NoticeConstants.TaskType.TEST_PLAN_TASK -> {
|
||||||
|
Field[] allFields = FieldUtils.getAllFields(TestPlan.class);
|
||||||
|
addOptionDto(optionDTOList, allFields);
|
||||||
|
//TODO:获取报告和自定义
|
||||||
|
}
|
||||||
|
case NoticeConstants.TaskType.CASE_REVIEW_TASK -> {
|
||||||
|
Field[] allFields = FieldUtils.getAllFields(CaseReview.class);
|
||||||
|
addOptionDto(optionDTOList, allFields);
|
||||||
|
//TODO:获取报告和自定义
|
||||||
|
}
|
||||||
|
case NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK -> {
|
||||||
|
Field[] allFields = FieldUtils.getAllFields(FunctionalCase.class);
|
||||||
|
addOptionDto(optionDTOList, allFields);
|
||||||
|
//TODO:获取报告和自定义
|
||||||
|
}
|
||||||
|
case NoticeConstants.TaskType.BUG_TASK -> {
|
||||||
|
Field[] allFields = FieldUtils.getAllFields(Bug.class);
|
||||||
|
addOptionDto(optionDTOList, allFields);
|
||||||
|
//TODO:获取报告和自定义
|
||||||
|
}
|
||||||
|
case NoticeConstants.TaskType.UI_SCENARIO_TASK -> {
|
||||||
|
Field[] allFields = FieldUtils.getAllFields(UiScenario.class);
|
||||||
|
addOptionDto(optionDTOList, allFields);
|
||||||
|
//TODO:获取报告和自定义
|
||||||
|
}
|
||||||
|
case NoticeConstants.TaskType.LOAD_TEST_TASK -> {
|
||||||
|
Field[] allFields = FieldUtils.getAllFields(LoadTest.class);
|
||||||
|
addOptionDto(optionDTOList, allFields);
|
||||||
|
//TODO:获取报告和自定义
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return optionDTOList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addOptionDto(List<OptionDTO> optionDTOList, Field[] allFields) {
|
||||||
|
for (Field allField : allFields) {
|
||||||
|
OptionDTO optionDTO = new OptionDTO();
|
||||||
|
optionDTO.setId(allField.getName());
|
||||||
|
Schema annotation = allField.getAnnotation(Schema.class);
|
||||||
|
if (annotation != null) {
|
||||||
|
String description = annotation.description();
|
||||||
|
optionDTO.setName(description);
|
||||||
|
}
|
||||||
|
optionDTOList.add(optionDTO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package io.metersphere.project.controller;
|
||||||
|
|
||||||
|
import io.metersphere.system.base.BaseTest;
|
||||||
|
import io.metersphere.sdk.constants.SessionConstants;
|
||||||
|
import io.metersphere.system.controller.handler.ResultHolder;
|
||||||
|
import io.metersphere.sdk.dto.OptionDTO;
|
||||||
|
import io.metersphere.sdk.util.JSON;
|
||||||
|
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.junit.jupiter.api.*;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.test.web.servlet.MvcResult;
|
||||||
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@AutoConfigureMockMvc
|
||||||
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
|
public class NoticeTemplateControllerTests extends BaseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
public void getTemplateFieldsSuccess() throws Exception {
|
||||||
|
List<String> typeList = new ArrayList<>();
|
||||||
|
typeList.add(NoticeConstants.TaskType.API_DEFINITION_TASK);
|
||||||
|
typeList.add(NoticeConstants.TaskType.API_SCENARIO_TASK);
|
||||||
|
typeList.add(NoticeConstants.TaskType.API_SCHEDULE_TASK);
|
||||||
|
typeList.add(NoticeConstants.TaskType.TEST_PLAN_TASK);
|
||||||
|
typeList.add(NoticeConstants.TaskType.CASE_REVIEW_TASK);
|
||||||
|
typeList.add(NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK);
|
||||||
|
typeList.add(NoticeConstants.TaskType.BUG_TASK);
|
||||||
|
typeList.add(NoticeConstants.TaskType.UI_SCENARIO_TASK);
|
||||||
|
typeList.add(NoticeConstants.TaskType.LOAD_TEST_TASK);
|
||||||
|
for (String s : typeList) {
|
||||||
|
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/template/get/fields/" + s)
|
||||||
|
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||||
|
.header(SessionConstants.CSRF_TOKEN, csrfToken))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||||
|
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||||
|
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
||||||
|
List<OptionDTO> projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class);
|
||||||
|
Assertions.assertTrue(CollectionUtils.isNotEmpty(projectList));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,12 +7,14 @@ public interface NoticeConstants {
|
||||||
String TEST_PLAN_TASK = "TEST_PLAN_TASK";
|
String TEST_PLAN_TASK = "TEST_PLAN_TASK";
|
||||||
String CASE_REVIEW_TASK = "CASE_REVIEW_TASK";
|
String CASE_REVIEW_TASK = "CASE_REVIEW_TASK";
|
||||||
String FUNCTIONAL_CASE_TASK = "FUNCTIONAL_CASE_TASK";
|
String FUNCTIONAL_CASE_TASK = "FUNCTIONAL_CASE_TASK";
|
||||||
|
String BUG_TASK = "BUG_TASK";
|
||||||
String TRACK_HOME_TASK = "TRACK_HOME_TASK";
|
String TRACK_HOME_TASK = "TRACK_HOME_TASK";
|
||||||
String TRACK_REPORT_TASK = "TRACK_REPORT_TASK";
|
String TRACK_REPORT_TASK = "TRACK_REPORT_TASK";
|
||||||
String DEFECT_TASK = "DEFECT_TASK";
|
String DEFECT_TASK = "DEFECT_TASK";
|
||||||
String SWAGGER_TASK = "SWAGGER_TASK";
|
String SWAGGER_TASK = "SWAGGER_TASK";
|
||||||
String API_SCENARIO_TASK = "API_SCENARIO_TASK";
|
String API_SCENARIO_TASK = "API_SCENARIO_TASK";
|
||||||
String API_DEFINITION_TASK = "API_DEFINITION_TASK";
|
String API_DEFINITION_TASK = "API_DEFINITION_TASK";
|
||||||
|
String API_SCHEDULE_TASK = "API_SCHEDULE_TASK";
|
||||||
String API_HOME_TASK = "API_HOME_TASK";
|
String API_HOME_TASK = "API_HOME_TASK";
|
||||||
String API_REPORT_TASK = "API_REPORT_TASK";
|
String API_REPORT_TASK = "API_REPORT_TASK";
|
||||||
String LOAD_REPORT_TASK = "LOAD_REPORT_TASK";
|
String LOAD_REPORT_TASK = "LOAD_REPORT_TASK";
|
||||||
|
|
Loading…
Reference in New Issue