This commit is contained in:
chenjianxing 2020-07-23 09:59:09 +08:00
commit c20e4c4e8c
64 changed files with 225 additions and 220 deletions

View File

@ -16,7 +16,6 @@ import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
@RestController @RestController

View File

@ -16,9 +16,8 @@ import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
@RestController @RestController
@RequestMapping(value = "/api") @RequestMapping(value = "/api")
@ -95,7 +94,7 @@ public class APITestController {
@PostMapping(value = "/import", consumes = {"multipart/form-data"}) @PostMapping(value = "/import", consumes = {"multipart/form-data"})
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public ApiTest testCaseImport(@RequestPart(value = "file", required = false) MultipartFile file, @RequestPart("request") ApiTestImportRequest request) { public ApiTest testCaseImport(@RequestPart(value = "file", required = false) MultipartFile file, @RequestPart("request") ApiTestImportRequest request) {
return apiTestService.apiTestImport(file, request); return apiTestService.apiTestImport(file, request);
} }

View File

@ -1,10 +1,7 @@
package io.metersphere.api.dto.parse.postman; package io.metersphere.api.dto.parse.postman;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data; import lombok.Data;
import java.util.List;
@Data @Data
public class PostmanItem { public class PostmanItem {

View File

@ -7,6 +7,7 @@ import lombok.EqualsAndHashCode;
@Data @Data
public class ExtractRegex extends ExtractCommon { public class ExtractRegex extends ExtractCommon {
private String useHeaders; private String useHeaders;
public ExtractRegex() { public ExtractRegex() {
setType(ExtractType.REGEX); setType(ExtractType.REGEX);
} }

View File

@ -1,6 +1,5 @@
package io.metersphere.api.jmeter; package io.metersphere.api.jmeter;
import io.github.ningyu.jmeter.plugin.dubbo.sample.ProviderService;
import io.metersphere.api.service.APIReportService; import io.metersphere.api.service.APIReportService;
import io.metersphere.api.service.APITestService; import io.metersphere.api.service.APITestService;
import io.metersphere.commons.constants.APITestStatus; import io.metersphere.commons.constants.APITestStatus;

View File

@ -10,11 +10,10 @@ import org.apache.jmeter.visualizers.backend.BackendListener;
import org.apache.jorphan.collections.HashTree; import org.apache.jorphan.collections.HashTree;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import javax.annotation.Resource;
@Service @Service
public class JMeterService { public class JMeterService {

View File

@ -1,9 +1,6 @@
package io.metersphere.api.parse; package io.metersphere.api.parse;
import io.metersphere.commons.constants.ApiImportPlatform; import io.metersphere.commons.constants.ApiImportPlatform;
import io.metersphere.commons.constants.FileType;
import io.metersphere.performance.parse.EngineSourceParser;
import io.metersphere.performance.parse.xml.XmlEngineSourceParse;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
public class ApiImportParserFactory { public class ApiImportParserFactory {

View File

@ -7,8 +7,8 @@ import io.metersphere.api.dto.parse.ApiImport;
import io.metersphere.api.dto.parse.postman.*; import io.metersphere.api.dto.parse.postman.*;
import io.metersphere.api.dto.scenario.Body; import io.metersphere.api.dto.scenario.Body;
import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.KeyValue;
import io.metersphere.api.dto.scenario.request.HttpRequest;
import io.metersphere.api.dto.scenario.Scenario; import io.metersphere.api.dto.scenario.Scenario;
import io.metersphere.api.dto.scenario.request.HttpRequest;
import io.metersphere.api.dto.scenario.request.Request; import io.metersphere.api.dto.scenario.request.Request;
import io.metersphere.commons.constants.MsRequestBodyType; import io.metersphere.commons.constants.MsRequestBodyType;
import io.metersphere.commons.constants.PostmanRequestBodyMode; import io.metersphere.commons.constants.PostmanRequestBodyMode;

View File

@ -6,8 +6,8 @@ import io.metersphere.api.dto.ApiTestImportRequest;
import io.metersphere.api.dto.parse.ApiImport; import io.metersphere.api.dto.parse.ApiImport;
import io.metersphere.api.dto.scenario.Body; import io.metersphere.api.dto.scenario.Body;
import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.KeyValue;
import io.metersphere.api.dto.scenario.request.HttpRequest;
import io.metersphere.api.dto.scenario.Scenario; import io.metersphere.api.dto.scenario.Scenario;
import io.metersphere.api.dto.scenario.request.HttpRequest;
import io.metersphere.api.dto.scenario.request.Request; import io.metersphere.api.dto.scenario.request.Request;
import io.metersphere.commons.constants.MsRequestBodyType; import io.metersphere.commons.constants.MsRequestBodyType;
import io.metersphere.commons.constants.SwaggerParameterType; import io.metersphere.commons.constants.SwaggerParameterType;
@ -64,7 +64,8 @@ public class Swagger2Parser extends ApiImportAbstractParser {
Scenario scenario = Optional.ofNullable(scenarioMap.get(tag)).orElse(new Scenario()); Scenario scenario = Optional.ofNullable(scenarioMap.get(tag)).orElse(new Scenario());
List<Request> requests = Optional.ofNullable(scenario.getRequests()).orElse(new ArrayList<>()); List<Request> requests = Optional.ofNullable(scenario.getRequests()).orElse(new ArrayList<>());
requests.add(request); requests.add(request);
scenario.setRequests(requests);scenario.setName(tag); scenario.setRequests(requests);
scenario.setName(tag);
scenarioMap.put(tag, scenario); scenarioMap.put(tag, scenario);
}); });
} else { } else {
@ -86,7 +87,7 @@ public class Swagger2Parser extends ApiImportAbstractParser {
List<Parameter> parameters = operation.getParameters(); List<Parameter> parameters = operation.getParameters();
for (Parameter parameter : parameters) { for (Parameter parameter : parameters) {
switch (parameter.getIn()){ switch (parameter.getIn()) {
// case SwaggerParameterType.PATH: // case SwaggerParameterType.PATH:
// parsePathParameters(parameter, request); // parsePathParameters(parameter, request);
// break; // break;
@ -137,7 +138,7 @@ public class Swagger2Parser extends ApiImportAbstractParser {
ArrayModel arrayModel = (ArrayModel) bodyParameter.getSchema(); ArrayModel arrayModel = (ArrayModel) bodyParameter.getSchema();
Property items = arrayModel.getItems(); Property items = arrayModel.getItems();
if (items instanceof RefProperty) { if (items instanceof RefProperty) {
RefProperty refProperty = (RefProperty) items; RefProperty refProperty = (RefProperty) items;
Model model = definitions.get(refProperty.getSimpleRef()); Model model = definitions.get(refProperty.getSimpleRef());
JSONArray propertyList = new JSONArray(); JSONArray propertyList = new JSONArray();
propertyList.add(getBodyJSONObjectParameters(model.getProperties(), definitions)); propertyList.add(getBodyJSONObjectParameters(model.getProperties(), definitions));
@ -155,11 +156,11 @@ public class Swagger2Parser extends ApiImportAbstractParser {
if (value instanceof ObjectProperty) { if (value instanceof ObjectProperty) {
ObjectProperty objectProperty = (ObjectProperty) value; ObjectProperty objectProperty = (ObjectProperty) value;
jsonObject.put(key, getBodyJSONObjectParameters(objectProperty.getProperties(), definitions)); jsonObject.put(key, getBodyJSONObjectParameters(objectProperty.getProperties(), definitions));
} else if (value instanceof ArrayProperty) { } else if (value instanceof ArrayProperty) {
ArrayProperty arrayProperty = (ArrayProperty) value; ArrayProperty arrayProperty = (ArrayProperty) value;
Property items = arrayProperty.getItems(); Property items = arrayProperty.getItems();
if (items instanceof RefProperty) { if (items instanceof RefProperty) {
RefProperty refProperty = (RefProperty) items; RefProperty refProperty = (RefProperty) items;
Model model = definitions.get(refProperty.getSimpleRef()); Model model = definitions.get(refProperty.getSimpleRef());
JSONArray propertyList = new JSONArray(); JSONArray propertyList = new JSONArray();
propertyList.add(getBodyJSONObjectParameters(model.getProperties(), definitions)); propertyList.add(getBodyJSONObjectParameters(model.getProperties(), definitions));

View File

@ -12,19 +12,16 @@ import io.metersphere.base.mapper.ext.ExtApiTestReportMapper;
import io.metersphere.commons.constants.APITestStatus; import io.metersphere.commons.constants.APITestStatus;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.ServiceUtils; import io.metersphere.commons.utils.ServiceUtils;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.dto.DashboardTestDTO; import io.metersphere.dto.DashboardTestDTO;
import io.metersphere.i18n.Translator; import io.metersphere.i18n.Translator;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.time.Instant; import java.time.Instant;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
@Service @Service

View File

@ -34,9 +34,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;

View File

@ -21,7 +21,7 @@ public class ApiTestEnvironmentService {
private ApiTestEnvironmentMapper apiTestEnvironmentMapper; private ApiTestEnvironmentMapper apiTestEnvironmentMapper;
public List<ApiTestEnvironmentWithBLOBs> list(String projectId) { public List<ApiTestEnvironmentWithBLOBs> list(String projectId) {
ApiTestEnvironmentExample example =new ApiTestEnvironmentExample(); ApiTestEnvironmentExample example = new ApiTestEnvironmentExample();
example.createCriteria().andProjectIdEqualTo(projectId); example.createCriteria().andProjectIdEqualTo(projectId);
return apiTestEnvironmentMapper.selectByExampleWithBLOBs(example); return apiTestEnvironmentMapper.selectByExampleWithBLOBs(example);
} }
@ -46,7 +46,7 @@ public class ApiTestEnvironmentService {
return apiTestEnvironmentWithBLOBs.getId(); return apiTestEnvironmentWithBLOBs.getId();
} }
private void checkEnvironmentExist (ApiTestEnvironmentWithBLOBs environment) { private void checkEnvironmentExist(ApiTestEnvironmentWithBLOBs environment) {
if (environment.getName() != null) { if (environment.getName() != null) {
ApiTestEnvironmentExample example = new ApiTestEnvironmentExample(); ApiTestEnvironmentExample example = new ApiTestEnvironmentExample();
ApiTestEnvironmentExample.Criteria criteria = example.createCriteria(); ApiTestEnvironmentExample.Criteria criteria = example.createCriteria();

View File

@ -1,5 +1,5 @@
package io.metersphere.commons.constants; package io.metersphere.commons.constants;
public enum ApiImportPlatform { public enum ApiImportPlatform {
Metersphere, Postman, Swagger2 Metersphere, Postman, Swagger2
} }

View File

@ -1,5 +1,5 @@
package io.metersphere.commons.constants; package io.metersphere.commons.constants;
public enum ReportTriggerMode { public enum ReportTriggerMode {
MANUAL,SCHEDULE,API MANUAL, SCHEDULE, API
} }

View File

@ -1,14 +1,24 @@
package io.metersphere.commons.exception; package io.metersphere.commons.exception;
public class MSException extends RuntimeException{ public class MSException extends RuntimeException {
private MSException(String message) { super(message); } private MSException(String message) {
super(message);
}
private MSException(Throwable t) { super(t); } private MSException(Throwable t) {
super(t);
}
public static void throwException(String message) { throw new MSException(message); } public static void throwException(String message) {
throw new MSException(message);
}
public static MSException getException(String message) { throw new MSException(message); } public static MSException getException(String message) {
throw new MSException(message);
}
public static void throwException(Throwable t) { throw new MSException(t); } public static void throwException(Throwable t) {
throw new MSException(t);
}
} }

View File

@ -7,6 +7,7 @@ public class MathUtils {
/** /**
* 获取百分比 * 获取百分比
* 保留一位小数 * 保留一位小数
*
* @param value * @param value
* @return * @return
*/ */

View File

@ -7,9 +7,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
import javax.validation.Validator; import javax.validation.Validator;
@ -31,6 +29,7 @@ public class I18nConfig {
/** /**
* JSR-303校验国际化 * JSR-303校验国际化
*
* @param messageSource * @param messageSource
* @return * @return
*/ */
@ -43,7 +42,7 @@ public class I18nConfig {
} }
@Bean @Bean
public Validator validator(LocalValidatorFactoryBean localValidatorFactoryBean){ public Validator validator(LocalValidatorFactoryBean localValidatorFactoryBean) {
return localValidatorFactoryBean.getValidator(); return localValidatorFactoryBean.getValidator();
} }

View File

@ -7,7 +7,6 @@ import com.fit2cloud.quartz.service.QuartzManageService;
import com.fit2cloud.quartz.util.QuartzBeanFactory; import com.fit2cloud.quartz.util.QuartzBeanFactory;
import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

View File

@ -1,7 +1,8 @@
package io.metersphere.controller; package io.metersphere.controller;
import io.metersphere.service.ScheduleService; import io.metersphere.service.ScheduleService;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;

View File

@ -5,7 +5,6 @@ import io.metersphere.commons.constants.ParamConstants;
import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.ldap.domain.LdapInfo; import io.metersphere.ldap.domain.LdapInfo;
import io.metersphere.service.SystemParameterService; import io.metersphere.service.SystemParameterService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles; import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;

View File

@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -34,7 +35,7 @@ public class UserRoleController {
@GetMapping("/all/{userId}") @GetMapping("/all/{userId}")
@RequiresRoles(RoleConstants.ADMIN) @RequiresRoles(RoleConstants.ADMIN)
public List<Map<String,Object>> getUserRole(@PathVariable("userId") String userId) { public List<Map<String, Object>> getUserRole(@PathVariable("userId") String userId) {
return userRoleService.getUserRole(userId); return userRoleService.getUserRole(userId);
} }
} }

View File

@ -3,6 +3,7 @@ package io.metersphere.controller.request.member;
import io.metersphere.base.domain.User; import io.metersphere.base.domain.User;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -11,6 +12,6 @@ import java.util.Map;
@Setter @Setter
public class UserRequest extends User { public class UserRequest extends User {
private List<Map<String,Object>> roles = new ArrayList<>(); private List<Map<String, Object>> roles = new ArrayList<>();
} }

View File

@ -4,6 +4,7 @@ import io.metersphere.base.domain.Role;
import io.metersphere.base.domain.UserRole; import io.metersphere.base.domain.UserRole;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.List; import java.util.List;
@Getter @Getter

View File

@ -11,9 +11,10 @@ public class ExcelErrData<T> {
private String errMsg; private String errMsg;
public ExcelErrData(){} public ExcelErrData() {
}
public ExcelErrData(T t, Integer rowNum,String errMsg){ public ExcelErrData(T t, Integer rowNum, String errMsg) {
this.t = t; this.t = t;
this.rowNum = rowNum; this.rowNum = rowNum;
this.errMsg = errMsg; this.errMsg = errMsg;

View File

@ -3,6 +3,7 @@ package io.metersphere.excel.domain;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
@Data @Data
public class ExcelResponse<T> { public class ExcelResponse<T> {

View File

@ -13,12 +13,12 @@ import javax.validation.constraints.Pattern;
public class TestCaseExcelData { public class TestCaseExcelData {
@NotBlank(message = "{cannot_be_null}") @NotBlank(message = "{cannot_be_null}")
@Length(max=50) @Length(max = 50)
@ExcelProperty("{test_case_name}") @ExcelProperty("{test_case_name}")
private String name; private String name;
@NotBlank(message = "{cannot_be_null}") @NotBlank(message = "{cannot_be_null}")
@Length(max=1000) @Length(max = 1000)
@ExcelProperty("{test_case_module}") @ExcelProperty("{test_case_module}")
@ColumnWidth(30) @ColumnWidth(30)
@Pattern(regexp = "^(?!.*//).*$", message = "{incorrect_format}") @Pattern(regexp = "^(?!.*//).*$", message = "{incorrect_format}")
@ -45,21 +45,21 @@ public class TestCaseExcelData {
@ColumnWidth(50) @ColumnWidth(50)
@ExcelProperty("{test_case_prerequisite}") @ExcelProperty("{test_case_prerequisite}")
@Length(min=0, max=1000) @Length(min = 0, max = 1000)
private String prerequisite; private String prerequisite;
@ColumnWidth(50) @ColumnWidth(50)
@ExcelProperty("{test_case_remark}") @ExcelProperty("{test_case_remark}")
@Length(max=1000) @Length(max = 1000)
private String remark; private String remark;
@ColumnWidth(50) @ColumnWidth(50)
@ExcelProperty("{test_case_step_desc}") @ExcelProperty("{test_case_step_desc}")
@Length(max=1000) @Length(max = 1000)
private String stepDesc; private String stepDesc;
@ColumnWidth(50) @ColumnWidth(50)
@ExcelProperty("{test_case_step_result}") @ExcelProperty("{test_case_step_result}")
@Length(max=1000) @Length(max = 1000)
private String stepResult; private String stepResult;
} }

View File

@ -11,10 +11,12 @@ import io.metersphere.excel.utils.EasyExcelI18nTranslator;
import io.metersphere.excel.utils.ExcelValidateHelper; import io.metersphere.excel.utils.ExcelValidateHelper;
import io.metersphere.i18n.Translator; import io.metersphere.i18n.Translator;
import java.lang.reflect.*; import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.*; import java.util.*;
public abstract class EasyExcelListener <T> extends AnalysisEventListener<T> { public abstract class EasyExcelListener<T> extends AnalysisEventListener<T> {
protected List<ExcelErrData<T>> errList = new ArrayList<>(); protected List<ExcelErrData<T>> errList = new ArrayList<>();
@ -29,7 +31,7 @@ public abstract class EasyExcelListener <T> extends AnalysisEventListener<T> {
protected Class<T> clazz; protected Class<T> clazz;
public EasyExcelListener(){ public EasyExcelListener() {
Type type = getClass().getGenericSuperclass(); Type type = getClass().getGenericSuperclass();
this.clazz = (Class<T>) ((ParameterizedType) type).getActualTypeArguments()[0]; this.clazz = (Class<T>) ((ParameterizedType) type).getActualTypeArguments()[0];
//防止多线程修改运行时类注解后saveOriginalExcelProperty保存的是修改后的值 //防止多线程修改运行时类注解后saveOriginalExcelProperty保存的是修改后的值
@ -61,7 +63,7 @@ public abstract class EasyExcelListener <T> extends AnalysisEventListener<T> {
if (!StringUtils.isEmpty(errMsg)) { if (!StringUtils.isEmpty(errMsg)) {
ExcelErrData excelErrData = new ExcelErrData(t, rowIndex, ExcelErrData excelErrData = new ExcelErrData(t, rowIndex,
Translator.get("number")+ " " + rowIndex + " " + Translator.get("row") + Translator.get("error") Translator.get("number") + " " + rowIndex + " " + Translator.get("row") + Translator.get("error")
+ "" + errMsg); + "" + errMsg);
errList.add(excelErrData); errList.add(excelErrData);
} else { } else {
@ -77,6 +79,7 @@ public abstract class EasyExcelListener <T> extends AnalysisEventListener<T> {
/** /**
* 可重写该方法 * 可重写该方法
* 自定义校验规则 * 自定义校验规则
*
* @param data * @param data
* @param errMsg * @param errMsg
* @return * @return
@ -98,18 +101,19 @@ public abstract class EasyExcelListener <T> extends AnalysisEventListener<T> {
/** /**
* 校验excel头部 * 校验excel头部
* @param headMap 传入excel的头部第一行数据数据的index,name *
* @param context * @param headMap 传入excel的头部第一行数据数据的index,name
*/ * @param context
*/
@Override @Override
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) { public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
if (clazz != null){ if (clazz != null) {
try { try {
Set<String> fieldNameSet = getFieldNameSet(clazz); Set<String> fieldNameSet = getFieldNameSet(clazz);
Collection<String> values = headMap.values(); Collection<String> values = headMap.values();
for (String key : fieldNameSet) { for (String key : fieldNameSet) {
if (!values.contains(key)){ if (!values.contains(key)) {
throw new ExcelAnalysisException(Translator.get("missing_header_information") + ":" + key); throw new ExcelAnalysisException(Translator.get("missing_header_information") + ":" + key);
} }
} }
@ -121,17 +125,17 @@ public abstract class EasyExcelListener <T> extends AnalysisEventListener<T> {
} }
/** /**
* @description: 获取注解里ExcelProperty的value * @description: 获取注解里ExcelProperty的value
*/ */
public Set<String> getFieldNameSet(Class clazz) throws NoSuchFieldException { public Set<String> getFieldNameSet(Class clazz) throws NoSuchFieldException {
Set<String> result = new HashSet<>(); Set<String> result = new HashSet<>();
Field field; Field field;
Field[] fields = clazz.getDeclaredFields(); Field[] fields = clazz.getDeclaredFields();
for (int i = 0; i < fields.length ; i++) { for (int i = 0; i < fields.length; i++) {
field = clazz.getDeclaredField(fields[i].getName()); field = clazz.getDeclaredField(fields[i].getName());
field.setAccessible(true); field.setAccessible(true);
ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class); ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class);
if(excelProperty != null){ if (excelProperty != null) {
StringBuilder value = new StringBuilder(); StringBuilder value = new StringBuilder();
for (String v : excelProperty.value()) { for (String v : excelProperty.value()) {
value.append(v); value.append(v);
@ -146,7 +150,7 @@ public abstract class EasyExcelListener <T> extends AnalysisEventListener<T> {
return errList; return errList;
} }
public void close () { public void close() {
this.easyExcelI18nTranslator.resetExcelProperty(); this.easyExcelI18nTranslator.resetExcelProperty();
} }
} }

View File

@ -42,7 +42,7 @@ public class TestCaseDataListener extends EasyExcelListener<TestCaseExcelData> {
if (nodePath != null) { if (nodePath != null) {
String[] nodes = nodePath.split("/"); String[] nodes = nodePath.split("/");
if ( nodes.length > TestCaseConstants.MAX_NODE_DEPTH + 1) { if (nodes.length > TestCaseConstants.MAX_NODE_DEPTH + 1) {
stringBuilder.append(Translator.get("test_case_node_level_tip") + stringBuilder.append(Translator.get("test_case_node_level_tip") +
TestCaseConstants.MAX_NODE_DEPTH + Translator.get("test_case_node_level")); TestCaseConstants.MAX_NODE_DEPTH + Translator.get("test_case_node_level"));
} }
@ -122,7 +122,7 @@ public class TestCaseDataListener extends EasyExcelListener<TestCaseExcelData> {
String pattern = "(^\\d+)(\\.)?"; String pattern = "(^\\d+)(\\.)?";
int index = stepDesc.length > stepRes.length ? stepDesc.length : stepRes.length; int index = stepDesc.length > stepRes.length ? stepDesc.length : stepRes.length;
for (int i = 0; i < index; i++){ for (int i = 0; i < index; i++) {
JSONObject step = new JSONObject(); JSONObject step = new JSONObject();
step.put("num", i + 1); step.put("num", i + 1);

View File

@ -1,24 +1,14 @@
package io.metersphere.excel.utils; package io.metersphere.excel.utils;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
import io.metersphere.excel.domain.TestCaseExcelData;
import io.metersphere.exception.ExcelException; import io.metersphere.exception.ExcelException;
import io.metersphere.i18n.Translator;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
public class EasyExcelExporter { public class EasyExcelExporter {

View File

@ -33,12 +33,12 @@ public class EasyExcelI18nTranslator {
private void readExcelProperty(Class clazz, BiConsumer<String, Map<String, Object>> operate) { private void readExcelProperty(Class clazz, BiConsumer<String, Map<String, Object>> operate) {
Field field; Field field;
Field[] fields = clazz.getDeclaredFields(); Field[] fields = clazz.getDeclaredFields();
for (int i = 0; i < fields.length ; i++) { for (int i = 0; i < fields.length; i++) {
try { try {
field = clazz.getDeclaredField(fields[i].getName()); field = clazz.getDeclaredField(fields[i].getName());
field.setAccessible(true); field.setAccessible(true);
ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class); ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class);
if(excelProperty != null){ if (excelProperty != null) {
InvocationHandler invocationHandler = Proxy.getInvocationHandler(excelProperty); InvocationHandler invocationHandler = Proxy.getInvocationHandler(excelProperty);
Field fieldValue = invocationHandler.getClass().getDeclaredField("memberValues"); Field fieldValue = invocationHandler.getClass().getDeclaredField("memberValues");
fieldValue.setAccessible(true); fieldValue.setAccessible(true);
@ -51,7 +51,7 @@ public class EasyExcelI18nTranslator {
} }
operate.accept(field.getName(), memberValues); operate.accept(field.getName(), memberValues);
} }
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
e.printStackTrace(); e.printStackTrace();
@ -64,7 +64,7 @@ public class EasyExcelI18nTranslator {
public void saveOriginalExcelProperty() { public void saveOriginalExcelProperty() {
readExcelProperty(clazz, (fieldName, memberValues) -> { readExcelProperty(clazz, (fieldName, memberValues) -> {
List<String> values = Arrays.asList((String [])memberValues.get("value")); List<String> values = Arrays.asList((String[]) memberValues.get("value"));
List<String> copyValues = new ArrayList<>(); List<String> copyValues = new ArrayList<>();
values.forEach(value -> { values.forEach(value -> {
copyValues.add(value); copyValues.add(value);
@ -74,11 +74,11 @@ public class EasyExcelI18nTranslator {
} }
public void translateExcelProperty() { public void translateExcelProperty() {
readExcelProperty(TestCaseExcelData.class, (fieldName, memberValues) -> { readExcelProperty(TestCaseExcelData.class, (fieldName, memberValues) -> {
String [] values = (String[]) memberValues.get("value"); String[] values = (String[]) memberValues.get("value");
for (int j = 0; j < values.length; j++) { for (int j = 0; j < values.length; j++) {
if (Pattern.matches("^\\{.+\\}$", values[j])) { if (Pattern.matches("^\\{.+\\}$", values[j])) {
values[j] = Translator.get(values[j].substring(1, values[j].length() - 1)); values[j] = Translator.get(values[j].substring(1, values[j].length() - 1));
} }
} }
memberValues.put("value", values); memberValues.put("value", values);
@ -87,7 +87,7 @@ public class EasyExcelI18nTranslator {
public void resetExcelProperty() { public void resetExcelProperty() {
readExcelProperty(clazz, (fieldName, memberValues) -> { readExcelProperty(clazz, (fieldName, memberValues) -> {
String [] values = (String[]) memberValues.get("value"); String[] values = (String[]) memberValues.get("value");
List<String> list = excelPropertyMap.get(fieldName); List<String> list = excelPropertyMap.get(fieldName);
for (int j = 0; j < values.length; j++) { for (int j = 0; j < values.length; j++) {
values[j] = list.get(j); values[j] = list.get(j);

View File

@ -2,7 +2,6 @@ package io.metersphere.excel.utils;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -20,7 +19,7 @@ public class ExcelValidateHelper {
@Resource @Resource
Validator validator; Validator validator;
public static <T> String validateEntity(T obj) throws NoSuchFieldException { public static <T> String validateEntity(T obj) throws NoSuchFieldException {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
Set<ConstraintViolation<T>> set = excelValidateHelper.validator.validate(obj, Default.class); Set<ConstraintViolation<T>> set = excelValidateHelper.validator.validate(obj, Default.class);
if (set != null && !set.isEmpty()) { if (set != null && !set.isEmpty()) {
@ -28,7 +27,7 @@ public class ExcelValidateHelper {
Field declaredField = obj.getClass().getDeclaredField(cv.getPropertyPath().toString()); Field declaredField = obj.getClass().getDeclaredField(cv.getPropertyPath().toString());
ExcelProperty annotation = declaredField.getAnnotation(ExcelProperty.class); ExcelProperty annotation = declaredField.getAnnotation(ExcelProperty.class);
//拼接错误信息包含当前出错数据的标题名字+错误信息 //拼接错误信息包含当前出错数据的标题名字+错误信息
result.append(annotation.value()[0]+cv.getMessage()).append("; "); result.append(annotation.value()[0] + cv.getMessage()).append("; ");
} }
} }
return result.toString(); return result.toString();

View File

@ -7,11 +7,11 @@ public class ExcelException extends RuntimeException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public ExcelException(String message, Exception e){ public ExcelException(String message, Exception e) {
super(message, e); super(message, e);
} }
public ExcelException(String message){ public ExcelException(String message) {
super(message); super(message);
} }

View File

@ -20,7 +20,7 @@ public abstract class MsScheduleJob implements Job {
this.userId = jobDataMap.getString("userId"); this.userId = jobDataMap.getString("userId");
this.expression = jobDataMap.getString("expression"); this.expression = jobDataMap.getString("expression");
LogUtil.info(jobKey.getGroup()+ " Running: " + resourceId); LogUtil.info(jobKey.getGroup() + " Running: " + resourceId);
LogUtil.info("CronExpression: " + expression); LogUtil.info("CronExpression: " + expression);
businessExecute(context); businessExecute(context);
} }

View File

@ -14,6 +14,7 @@ public class ScheduleManager {
/** /**
* 添加 simpleJob * 添加 simpleJob
*
* @param jobKey * @param jobKey
* @param triggerKey * @param triggerKey
* @param cls * @param cls
@ -22,7 +23,7 @@ public class ScheduleManager {
* @throws SchedulerException * @throws SchedulerException
*/ */
public void addSimpleJob(JobKey jobKey, TriggerKey triggerKey, Class<? extends Job> cls, int repeatIntervalTime, public void addSimpleJob(JobKey jobKey, TriggerKey triggerKey, Class<? extends Job> cls, int repeatIntervalTime,
JobDataMap jobDataMap) throws SchedulerException { JobDataMap jobDataMap) throws SchedulerException {
JobBuilder jobBuilder = JobBuilder.newJob(cls).withIdentity(jobKey); JobBuilder jobBuilder = JobBuilder.newJob(cls).withIdentity(jobKey);
@ -58,6 +59,7 @@ public class ScheduleManager {
/** /**
* 添加 cronJob * 添加 cronJob
*
* @param jobKey * @param jobKey
* @param triggerKey * @param triggerKey
* @param jobClass * @param jobClass
@ -102,6 +104,7 @@ public class ScheduleManager {
/** /**
* 修改 cronTrigger * 修改 cronTrigger
*
* @param triggerKey * @param triggerKey
* @param cron * @param cron
* @throws SchedulerException * @throws SchedulerException
@ -149,6 +152,7 @@ public class ScheduleManager {
/** /**
* 修改simpleTrigger触发器的触发时间 * 修改simpleTrigger触发器的触发时间
*
* @param triggerKey * @param triggerKey
* @param repeatIntervalTime * @param repeatIntervalTime
* @throws SchedulerException * @throws SchedulerException
@ -199,12 +203,10 @@ public class ScheduleManager {
} }
/** /**
*
* @Title:
* @Description: 根据job和trigger删除任务
*
* @param jobKey * @param jobKey
* @param triggerKey * @param triggerKey
* @Title:
* @Description: 根据job和trigger删除任务
*/ */
public void removeJob(JobKey jobKey, TriggerKey triggerKey) { public void removeJob(JobKey jobKey, TriggerKey triggerKey) {
@ -248,6 +250,7 @@ public class ScheduleManager {
/** /**
* 新增或者修改 simpleJob * 新增或者修改 simpleJob
*
* @param jobKey * @param jobKey
* @param triggerKey * @param triggerKey
* @param clz * @param clz
@ -256,7 +259,7 @@ public class ScheduleManager {
* @throws SchedulerException * @throws SchedulerException
*/ */
public void addOrUpdateSimpleJob(JobKey jobKey, TriggerKey triggerKey, Class clz, public void addOrUpdateSimpleJob(JobKey jobKey, TriggerKey triggerKey, Class clz,
int intervalTime, JobDataMap jobDataMap) throws SchedulerException { int intervalTime, JobDataMap jobDataMap) throws SchedulerException {
if (scheduler.checkExists(triggerKey)) { if (scheduler.checkExists(triggerKey)) {
modifySimpleJobTime(triggerKey, intervalTime); modifySimpleJobTime(triggerKey, intervalTime);
@ -273,6 +276,7 @@ public class ScheduleManager {
/** /**
* 添加或修改 cronJob * 添加或修改 cronJob
*
* @param jobKey * @param jobKey
* @param triggerKey * @param triggerKey
* @param jobClass * @param jobClass

View File

@ -13,7 +13,10 @@ import io.metersphere.service.UserService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.springframework.ldap.core.DirContextOperations; import org.springframework.ldap.core.DirContextOperations;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;

View File

@ -14,7 +14,7 @@ public class Person {
@Id @Id
private Name id; private Name id;
@DnAttribute(value="uid",index = 0) @DnAttribute(value = "uid", index = 0)
private String uid; private String uid;
@Attribute(name = "cn") @Attribute(name = "cn")
private String commonName; private String commonName;

View File

@ -55,7 +55,6 @@ public class LdapService {
getMappingAttr("email", dirContextOperations); getMappingAttr("email", dirContextOperations);
return dirContextOperations; return dirContextOperations;
} }

View File

@ -19,7 +19,7 @@ public class AppStartListener implements ApplicationListener<ApplicationReadyEve
System.out.println("================= 应用启动 ================="); System.out.println("================= 应用启动 =================");
try { try {
Thread.sleep(5*60*1000); Thread.sleep(5 * 60 * 1000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -10,13 +10,12 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.Resource;
@Service @Service
public class FileService { public class FileService {
@Resource @Resource

View File

@ -129,7 +129,7 @@ public class ProjectService {
projectMapper.updateByPrimaryKeySelective(project); projectMapper.updateByPrimaryKeySelective(project);
} }
private void checkProjectExist (Project project) { private void checkProjectExist(Project project) {
if (project.getName() != null) { if (project.getName() != null) {
ProjectExample example = new ProjectExample(); ProjectExample example = new ProjectExample();
example.createCriteria() example.createCriteria()

View File

@ -5,6 +5,7 @@ import io.metersphere.base.mapper.RoleMapper;
import io.metersphere.base.mapper.ext.ExtRoleMapper; import io.metersphere.base.mapper.ext.ExtRoleMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;

View File

@ -22,7 +22,7 @@ import java.util.UUID;
@Service @Service
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public class ScheduleService { public class ScheduleService {
@Resource @Resource
private ScheduleMapper scheduleMapper; private ScheduleMapper scheduleMapper;
@Resource @Resource

View File

@ -13,6 +13,7 @@ import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import java.util.*; import java.util.*;

View File

@ -18,7 +18,6 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;

View File

@ -33,8 +33,8 @@ public class UserRoleService {
return extUserRoleMapper.getWorkspaceMemberRoles(workspaceId, userId); return extUserRoleMapper.getWorkspaceMemberRoles(workspaceId, userId);
} }
public List<Map<String,Object>> getUserRole(String userId) { public List<Map<String, Object>> getUserRole(String userId) {
List<Map<String,Object>> list = new ArrayList<>(); List<Map<String, Object>> list = new ArrayList<>();
UserRoleExample userRoleExample = new UserRoleExample(); UserRoleExample userRoleExample = new UserRoleExample();
userRoleExample.createCriteria().andUserIdEqualTo(userId); userRoleExample.createCriteria().andUserIdEqualTo(userId);
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample); List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);

View File

@ -26,7 +26,6 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;

View File

@ -62,40 +62,40 @@ public class TestCaseController {
} }
@PostMapping("/list") @PostMapping("/list")
public List<TestCase> getTestCaseByNodeId(@RequestBody List<String> nodeIds){ public List<TestCase> getTestCaseByNodeId(@RequestBody List<String> nodeIds) {
return testCaseService.getTestCaseByNodeId(nodeIds); return testCaseService.getTestCaseByNodeId(nodeIds);
} }
@PostMapping("/name") @PostMapping("/name")
public List<TestCase> getTestCaseNames(@RequestBody QueryTestCaseRequest request){ public List<TestCase> getTestCaseNames(@RequestBody QueryTestCaseRequest request) {
return testCaseService.getTestCaseNames(request); return testCaseService.getTestCaseNames(request);
} }
@GetMapping("/get/{testCaseId}") @GetMapping("/get/{testCaseId}")
public TestCaseWithBLOBs getTestCase(@PathVariable String testCaseId){ public TestCaseWithBLOBs getTestCase(@PathVariable String testCaseId) {
return testCaseService.getTestCase(testCaseId); return testCaseService.getTestCase(testCaseId);
} }
@GetMapping("/project/{testCaseId}") @GetMapping("/project/{testCaseId}")
public Project getProjectByTestCaseId(@PathVariable String testCaseId){ public Project getProjectByTestCaseId(@PathVariable String testCaseId) {
return testCaseService.getProjectByTestCaseId(testCaseId); return testCaseService.getProjectByTestCaseId(testCaseId);
} }
@PostMapping("/add") @PostMapping("/add")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void addTestCase(@RequestBody TestCaseWithBLOBs testCase){ public void addTestCase(@RequestBody TestCaseWithBLOBs testCase) {
testCaseService.addTestCase(testCase); testCaseService.addTestCase(testCase);
} }
@PostMapping("/edit") @PostMapping("/edit")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void editTestCase(@RequestBody TestCaseWithBLOBs testCase){ public void editTestCase(@RequestBody TestCaseWithBLOBs testCase) {
testCaseService.editTestCase(testCase); testCaseService.editTestCase(testCase);
} }
@PostMapping("/delete/{testCaseId}") @PostMapping("/delete/{testCaseId}")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public int deleteTestCase(@PathVariable String testCaseId){ public int deleteTestCase(@PathVariable String testCaseId) {
return testCaseService.deleteTestCase(testCaseId); return testCaseService.deleteTestCase(testCaseId);
} }
@ -107,24 +107,25 @@ public class TestCaseController {
@GetMapping("/export/template") @GetMapping("/export/template")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void testCaseTemplateExport(HttpServletResponse response){ public void testCaseTemplateExport(HttpServletResponse response) {
testCaseService.testCaseTemplateExport(response); testCaseService.testCaseTemplateExport(response);
} }
@PostMapping("/export/testcase") @PostMapping("/export/testcase")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void testCaseExport( HttpServletResponse response,@RequestBody TestCaseBatchRequest request){ public void testCaseExport(HttpServletResponse response, @RequestBody TestCaseBatchRequest request) {
testCaseService.testCaseExport(response,request); testCaseService.testCaseExport(response, request);
} }
@PostMapping("/batch/edit") @PostMapping("/batch/edit")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void editTestCaseBath(@RequestBody TestCaseBatchRequest request){ public void editTestCaseBath(@RequestBody TestCaseBatchRequest request) {
testCaseService.editTestCaseBath(request); testCaseService.editTestCaseBath(request);
} }
@PostMapping("/batch/delete") @PostMapping("/batch/delete")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void deleteTestCaseBath(@RequestBody TestCaseBatchRequest request){ public void deleteTestCaseBath(@RequestBody TestCaseBatchRequest request) {
testCaseService.deleteTestCaseBath(request); testCaseService.deleteTestCaseBath(request);
} }

View File

@ -21,42 +21,43 @@ public class TestCaseNodeController {
TestCaseNodeService testCaseNodeService; TestCaseNodeService testCaseNodeService;
@GetMapping("/list/{projectId}") @GetMapping("/list/{projectId}")
public List<TestCaseNodeDTO> getNodeByProjectId(@PathVariable String projectId){ public List<TestCaseNodeDTO> getNodeByProjectId(@PathVariable String projectId) {
return testCaseNodeService.getNodeTreeByProjectId(projectId); return testCaseNodeService.getNodeTreeByProjectId(projectId);
} }
/*模块列表列表*/ /*模块列表列表*/
@GetMapping("/list/all/plan/{planId}") @GetMapping("/list/all/plan/{planId}")
public List<TestCaseNodeDTO> getAllNodeByPlanId(@PathVariable String planId){ public List<TestCaseNodeDTO> getAllNodeByPlanId(@PathVariable String planId) {
return testCaseNodeService.getAllNodeByPlanId(planId); return testCaseNodeService.getAllNodeByPlanId(planId);
} }
@GetMapping("/list/plan/{planId}") @GetMapping("/list/plan/{planId}")
public List<TestCaseNodeDTO> getNodeByPlanId(@PathVariable String planId){ public List<TestCaseNodeDTO> getNodeByPlanId(@PathVariable String planId) {
return testCaseNodeService.getNodeByPlanId(planId); return testCaseNodeService.getNodeByPlanId(planId);
} }
@PostMapping("/add") @PostMapping("/add")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public String addNode(@RequestBody TestCaseNode node){ public String addNode(@RequestBody TestCaseNode node) {
return testCaseNodeService.addNode(node); return testCaseNodeService.addNode(node);
} }
@PostMapping("/edit") @PostMapping("/edit")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public int editNode(@RequestBody DragNodeRequest node){ public int editNode(@RequestBody DragNodeRequest node) {
return testCaseNodeService.editNode(node); return testCaseNodeService.editNode(node);
} }
@PostMapping("/delete") @PostMapping("/delete")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public int deleteNode(@RequestBody List<String> nodeIds){ public int deleteNode(@RequestBody List<String> nodeIds) {
//nodeIds 包含删除节点ID及其所有子节点ID //nodeIds 包含删除节点ID及其所有子节点ID
return testCaseNodeService.deleteNode(nodeIds); return testCaseNodeService.deleteNode(nodeIds);
} }
@PostMapping("/drag") @PostMapping("/drag")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void dragNode(@RequestBody DragNodeRequest node){ public void dragNode(@RequestBody DragNodeRequest node) {
testCaseNodeService.dragNode(node); testCaseNodeService.dragNode(node);
} }
} }

View File

@ -3,7 +3,6 @@ package io.metersphere.track.controller;
import io.metersphere.base.domain.TestCaseReport; import io.metersphere.base.domain.TestCaseReport;
import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.track.request.testCaseReport.CreateReportRequest; import io.metersphere.track.request.testCaseReport.CreateReportRequest;
import io.metersphere.track.dto.TestCaseReportMetricDTO;
import io.metersphere.track.service.TestCaseReportService; import io.metersphere.track.service.TestCaseReportService;
import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles; import org.apache.shiro.authz.annotation.RequiresRoles;
@ -25,25 +24,25 @@ public class TestCaseReportController {
} }
@GetMapping("/get/{id}") @GetMapping("/get/{id}")
public TestCaseReport get(@PathVariable String id){ public TestCaseReport get(@PathVariable String id) {
return testCaseReportService.getTestCaseReport(id); return testCaseReportService.getTestCaseReport(id);
} }
@PostMapping("/add") @PostMapping("/add")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public String addByTemplateId(@RequestBody CreateReportRequest request){ public String addByTemplateId(@RequestBody CreateReportRequest request) {
return testCaseReportService.addTestCaseReportByTemplateId(request); return testCaseReportService.addTestCaseReportByTemplateId(request);
} }
@PostMapping("/edit") @PostMapping("/edit")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void edit(@RequestBody TestCaseReport TestCaseReport){ public void edit(@RequestBody TestCaseReport TestCaseReport) {
testCaseReportService.editTestCaseReport(TestCaseReport); testCaseReportService.editTestCaseReport(TestCaseReport);
} }
@PostMapping("/delete/{id}") @PostMapping("/delete/{id}")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public int delete(@PathVariable String id){ public int delete(@PathVariable String id) {
return testCaseReportService.deleteTestCaseReport(id); return testCaseReportService.deleteTestCaseReport(id);
} }

View File

@ -24,25 +24,25 @@ public class TestCaseReportTemplateController {
} }
@GetMapping("/get/{id}") @GetMapping("/get/{id}")
public TestCaseReportTemplate get(@PathVariable String id){ public TestCaseReportTemplate get(@PathVariable String id) {
return testCaseReportTemplateService.getTestCaseReportTemplate(id); return testCaseReportTemplateService.getTestCaseReportTemplate(id);
} }
@PostMapping("/add") @PostMapping("/add")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void add(@RequestBody TestCaseReportTemplate testCaseReportTemplate){ public void add(@RequestBody TestCaseReportTemplate testCaseReportTemplate) {
testCaseReportTemplateService.addTestCaseReportTemplate(testCaseReportTemplate); testCaseReportTemplateService.addTestCaseReportTemplate(testCaseReportTemplate);
} }
@PostMapping("/edit") @PostMapping("/edit")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void edit(@RequestBody TestCaseReportTemplate testCaseReportTemplate){ public void edit(@RequestBody TestCaseReportTemplate testCaseReportTemplate) {
testCaseReportTemplateService.editTestCaseReportTemplate(testCaseReportTemplate); testCaseReportTemplateService.editTestCaseReportTemplate(testCaseReportTemplate);
} }
@PostMapping("/delete/{id}") @PostMapping("/delete/{id}")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public int delete(@PathVariable String id){ public int delete(@PathVariable String id) {
return testCaseReportTemplateService.deleteTestCaseReportTemplate(id); return testCaseReportTemplateService.deleteTestCaseReportTemplate(id);
} }

View File

@ -63,41 +63,41 @@ public class TestPlanController {
} }
@PostMapping("/get/{testPlanId}") @PostMapping("/get/{testPlanId}")
public TestPlan getTestPlan(@PathVariable String testPlanId){ public TestPlan getTestPlan(@PathVariable String testPlanId) {
return testPlanService.getTestPlan(testPlanId); return testPlanService.getTestPlan(testPlanId);
} }
@PostMapping("/add") @PostMapping("/add")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void addTestPlan(@RequestBody TestPlan testPlan){ public void addTestPlan(@RequestBody TestPlan testPlan) {
testPlanService.addTestPlan(testPlan); testPlanService.addTestPlan(testPlan);
} }
@PostMapping("/edit") @PostMapping("/edit")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void editTestPlan(@RequestBody TestPlan testPlan){ public void editTestPlan(@RequestBody TestPlan testPlan) {
testPlanService.editTestPlan(testPlan); testPlanService.editTestPlan(testPlan);
} }
@PostMapping("/edit/status/{planId}") @PostMapping("/edit/status/{planId}")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void editTestPlanStatus(@PathVariable String planId){ public void editTestPlanStatus(@PathVariable String planId) {
testPlanService.editTestPlanStatus(planId); testPlanService.editTestPlanStatus(planId);
} }
@PostMapping("/delete/{testPlanId}") @PostMapping("/delete/{testPlanId}")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public int deleteTestPlan(@PathVariable String testPlanId){ public int deleteTestPlan(@PathVariable String testPlanId) {
return testPlanService.deleteTestPlan(testPlanId); return testPlanService.deleteTestPlan(testPlanId);
} }
@PostMapping("/relevance") @PostMapping("/relevance")
public void testPlanRelevance(@RequestBody PlanCaseRelevanceRequest request){ public void testPlanRelevance(@RequestBody PlanCaseRelevanceRequest request) {
testPlanService.testPlanRelevance(request); testPlanService.testPlanRelevance(request);
} }
@GetMapping("/get/metric/{planId}") @GetMapping("/get/metric/{planId}")
public TestCaseReportMetricDTO getMetric(@PathVariable String planId){ public TestCaseReportMetricDTO getMetric(@PathVariable String planId) {
return testPlanService.getMetric(planId); return testPlanService.getMetric(planId);
} }
} }

View File

@ -2,14 +2,13 @@ package io.metersphere.track.controller;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.TestPlanTestCase;
import io.metersphere.base.domain.TestPlanTestCaseWithBLOBs; import io.metersphere.base.domain.TestPlanTestCaseWithBLOBs;
import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager; import io.metersphere.commons.utils.Pager;
import io.metersphere.track.dto.TestPlanCaseDTO;
import io.metersphere.track.request.testcase.TestPlanCaseBatchRequest; import io.metersphere.track.request.testcase.TestPlanCaseBatchRequest;
import io.metersphere.track.request.testplancase.QueryTestPlanCaseRequest; import io.metersphere.track.request.testplancase.QueryTestPlanCaseRequest;
import io.metersphere.track.dto.TestPlanCaseDTO;
import io.metersphere.track.service.TestPlanTestCaseService; import io.metersphere.track.service.TestPlanTestCaseService;
import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles; import org.apache.shiro.authz.annotation.RequiresRoles;
@ -17,7 +16,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
@RequestMapping("/test/plan/case") @RequestMapping("/test/plan/case")

View File

@ -7,9 +7,12 @@ import io.metersphere.track.dto.TestPlanDTO;
public abstract class ReportComponent { public abstract class ReportComponent {
protected String componentId; protected String componentId;
protected TestPlanDTO testPlan; protected TestPlanDTO testPlan;
public ReportComponent(TestPlanDTO testPlan) { public ReportComponent(TestPlanDTO testPlan) {
this.testPlan = testPlan; this.testPlan = testPlan;
} }
public abstract void readRecord(TestPlanCaseDTO testCase); public abstract void readRecord(TestPlanCaseDTO testCase);
public abstract void afterBuild(TestCaseReportMetricDTO testCaseReportMetric); public abstract void afterBuild(TestCaseReportMetricDTO testCaseReportMetric);
} }

View File

@ -11,6 +11,7 @@ import java.util.List;
public class ReportFailureResultComponent extends ReportComponent { public class ReportFailureResultComponent extends ReportComponent {
private List<TestPlanCaseDTO> failureTestCases = new ArrayList<>(); private List<TestPlanCaseDTO> failureTestCases = new ArrayList<>();
public ReportFailureResultComponent(TestPlanDTO testPlan) { public ReportFailureResultComponent(TestPlanDTO testPlan) {
super(testPlan); super(testPlan);
componentId = "4"; componentId = "4";

View File

@ -55,7 +55,7 @@ public class ReportResultComponent extends ReportComponent {
}); });
for (TestCaseReportModuleResultDTO moduleResult : moduleResultMap.values()) { for (TestCaseReportModuleResultDTO moduleResult : moduleResultMap.values()) {
moduleResult.setPassRate(MathUtils.getPercentWithDecimal(moduleResult.getPassCount()*1.0f/moduleResult.getCaseCount())); moduleResult.setPassRate(MathUtils.getPercentWithDecimal(moduleResult.getPassCount() * 1.0f / moduleResult.getCaseCount()));
if (moduleResult.getCaseCount() <= 0) { if (moduleResult.getCaseCount() <= 0) {
moduleResultMap.remove(moduleResult.getModuleId()); moduleResultMap.remove(moduleResult.getModuleId());
} }
@ -69,9 +69,9 @@ public class ReportResultComponent extends ReportComponent {
List<TestCaseNodeDTO> children = rootNode.getChildren(); List<TestCaseNodeDTO> children = rootNode.getChildren();
if(children != null) { if (children != null) {
Iterator<TestCaseNodeDTO> iterator = children.iterator(); Iterator<TestCaseNodeDTO> iterator = children.iterator();
while(iterator.hasNext()){ while (iterator.hasNext()) {
getChildIds(iterator.next(), childIds); getChildIds(iterator.next(), childIds);
} }
} }
@ -95,7 +95,8 @@ public class ReportResultComponent extends ReportComponent {
if (StringUtils.isNotBlank(testCase.getIssues())) { if (StringUtils.isNotBlank(testCase.getIssues())) {
if (JSON.parseObject(testCase.getIssues()).getBoolean("hasIssues")) { if (JSON.parseObject(testCase.getIssues()).getBoolean("hasIssues")) {
moduleResult.setIssuesCount(moduleResult.getIssuesCount() + 1); moduleResult.setIssuesCount(moduleResult.getIssuesCount() + 1);
}; }
;
} }
moduleResultMap.put(rootNodeId, moduleResult); moduleResultMap.put(rootNodeId, moduleResult);
return; return;

View File

@ -1,9 +1,5 @@
package io.metersphere.track.dto; package io.metersphere.track.dto;
import io.metersphere.track.domain.ReportBaseInfoComponent;
import io.metersphere.track.domain.ReportFailureResultComponent;
import io.metersphere.track.domain.ReportResultChartComponent;
import io.metersphere.track.domain.ReportResultComponent;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;

View File

@ -1,6 +1,5 @@
package io.metersphere.track.dto; package io.metersphere.track.dto;
import io.metersphere.base.domain.TestPlan;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;

View File

@ -12,7 +12,7 @@ import java.util.Map;
@Setter @Setter
public class QueryTestCaseRequest extends TestCase { public class QueryTestCaseRequest extends TestCase {
private String name; private String name;
private List<String> nodeIds; private List<String> nodeIds;

View File

@ -54,7 +54,7 @@ public class TestCaseNodeService {
} }
private void validateNode(TestCaseNode node) { private void validateNode(TestCaseNode node) {
if(node.getLevel() > TestCaseConstants.MAX_NODE_DEPTH){ if (node.getLevel() > TestCaseConstants.MAX_NODE_DEPTH) {
throw new RuntimeException(Translator.get("test_case_node_level_tip") throw new RuntimeException(Translator.get("test_case_node_level_tip")
+ TestCaseConstants.MAX_NODE_DEPTH + Translator.get("test_case_node_level")); + TestCaseConstants.MAX_NODE_DEPTH + Translator.get("test_case_node_level"));
} }
@ -97,7 +97,7 @@ public class TestCaseNodeService {
nodes.forEach(node -> { nodes.forEach(node -> {
Integer level = node.getLevel(); Integer level = node.getLevel();
if( nodeLevelMap.containsKey(level) ){ if (nodeLevelMap.containsKey(level)) {
nodeLevelMap.get(level).add(node); nodeLevelMap.get(level).add(node);
} else { } else {
List<TestCaseNode> testCaseNodes = new ArrayList<>(); List<TestCaseNode> testCaseNodes = new ArrayList<>();
@ -114,25 +114,26 @@ public class TestCaseNodeService {
/** /**
* 递归构建节点树 * 递归构建节点树
*
* @param nodeLevelMap * @param nodeLevelMap
* @param rootNode * @param rootNode
* @return * @return
*/ */
private TestCaseNodeDTO buildNodeTree(Map<Integer,List<TestCaseNode>> nodeLevelMap, TestCaseNode rootNode) { private TestCaseNodeDTO buildNodeTree(Map<Integer, List<TestCaseNode>> nodeLevelMap, TestCaseNode rootNode) {
TestCaseNodeDTO nodeTree = new TestCaseNodeDTO(); TestCaseNodeDTO nodeTree = new TestCaseNodeDTO();
BeanUtils.copyBean(nodeTree, rootNode); BeanUtils.copyBean(nodeTree, rootNode);
nodeTree.setLabel(rootNode.getName()); nodeTree.setLabel(rootNode.getName());
List<TestCaseNode> lowerNodes = nodeLevelMap.get(rootNode.getLevel() + 1); List<TestCaseNode> lowerNodes = nodeLevelMap.get(rootNode.getLevel() + 1);
if(lowerNodes == null){ if (lowerNodes == null) {
return nodeTree; return nodeTree;
} }
List<TestCaseNodeDTO> children = Optional.ofNullable(nodeTree.getChildren()).orElse(new ArrayList<>()); List<TestCaseNodeDTO> children = Optional.ofNullable(nodeTree.getChildren()).orElse(new ArrayList<>());
lowerNodes.forEach(node -> { lowerNodes.forEach(node -> {
if (node.getParentId() != null && node.getParentId().equals(rootNode.getId())){ if (node.getParentId() != null && node.getParentId().equals(rootNode.getId())) {
children.add(buildNodeTree(nodeLevelMap, node)); children.add(buildNodeTree(nodeLevelMap, node));
nodeTree.setChildren(children); nodeTree.setChildren(children);
} }
@ -150,7 +151,7 @@ public class TestCaseNodeService {
StringBuilder path = new StringBuilder(testCase.getNodePath()); StringBuilder path = new StringBuilder(testCase.getNodePath());
List<String> pathLists = Arrays.asList(path.toString().split("/")); List<String> pathLists = Arrays.asList(path.toString().split("/"));
pathLists.set(request.getLevel(), request.getName()); pathLists.set(request.getLevel(), request.getName());
path.delete( 0, path.length()); path.delete(0, path.length());
for (int i = 1; i < pathLists.size(); i++) { for (int i = 1; i < pathLists.size(); i++) {
path = path.append("/").append(pathLists.get(i)); path = path.append("/").append(pathLists.get(i));
} }
@ -175,6 +176,7 @@ public class TestCaseNodeService {
/** /**
* 获取当前计划下 * 获取当前计划下
* 有关联数据的节点 * 有关联数据的节点
*
* @param planId * @param planId
* @return * @return
*/ */
@ -207,9 +209,9 @@ public class TestCaseNodeService {
List<TestCaseNodeDTO> nodeTrees = getNodeTrees(nodes); List<TestCaseNodeDTO> nodeTrees = getNodeTrees(nodes);
Iterator<TestCaseNodeDTO> iterator = nodeTrees.iterator(); Iterator<TestCaseNodeDTO> iterator = nodeTrees.iterator();
while(iterator.hasNext()){ while (iterator.hasNext()) {
TestCaseNodeDTO rootNode = iterator.next(); TestCaseNodeDTO rootNode = iterator.next();
if(pruningTree(rootNode, dataNodeIds)){ if (pruningTree(rootNode, dataNodeIds)) {
iterator.remove(); iterator.remove();
} }
} }
@ -219,26 +221,27 @@ public class TestCaseNodeService {
/** /**
* 去除没有数据的节点 * 去除没有数据的节点
*
* @param rootNode * @param rootNode
* @param nodeIds * @param nodeIds
* @return 是否剪枝 * @return 是否剪枝
* */ */
public boolean pruningTree(TestCaseNodeDTO rootNode, List<String> nodeIds) { public boolean pruningTree(TestCaseNodeDTO rootNode, List<String> nodeIds) {
List<TestCaseNodeDTO> children = rootNode.getChildren(); List<TestCaseNodeDTO> children = rootNode.getChildren();
if(children == null || children.isEmpty()){ if (children == null || children.isEmpty()) {
//叶子节点,并且该节点无数据 //叶子节点,并且该节点无数据
if(!nodeIds.contains(rootNode.getId())){ if (!nodeIds.contains(rootNode.getId())) {
return true; return true;
} }
} }
if(children != null) { if (children != null) {
Iterator<TestCaseNodeDTO> iterator = children.iterator(); Iterator<TestCaseNodeDTO> iterator = children.iterator();
while(iterator.hasNext()){ while (iterator.hasNext()) {
TestCaseNodeDTO subNode = iterator.next(); TestCaseNodeDTO subNode = iterator.next();
if(pruningTree(subNode, nodeIds)){ if (pruningTree(subNode, nodeIds)) {
iterator.remove(); iterator.remove();
} }
} }
@ -293,7 +296,8 @@ public class TestCaseNodeService {
hasNode = true; hasNode = true;
createNodeByPathIterator(pathIterator, "/" + rootNodeName, nodeTree, createNodeByPathIterator(pathIterator, "/" + rootNodeName, nodeTree,
pathMap, projectId, 2); pathMap, projectId, 2);
}; }
;
} }
} }
@ -309,18 +313,19 @@ public class TestCaseNodeService {
/** /**
* 根据目标节点路径创建相关节点 * 根据目标节点路径创建相关节点
*
* @param pathIterator 遍历子路径 * @param pathIterator 遍历子路径
* @param path 当前路径 * @param path 当前路径
* @param treeNode 当前节点 * @param treeNode 当前节点
* @param pathMap 记录节点路径对应的nodeId * @param pathMap 记录节点路径对应的nodeId
*/ */
private void createNodeByPathIterator(Iterator<String> pathIterator, String path, TestCaseNodeDTO treeNode, private void createNodeByPathIterator(Iterator<String> pathIterator, String path, TestCaseNodeDTO treeNode,
Map<String, String> pathMap, String projectId, Integer level) { Map<String, String> pathMap, String projectId, Integer level) {
List<TestCaseNodeDTO> children = treeNode.getChildren(); List<TestCaseNodeDTO> children = treeNode.getChildren();
if (children == null || children.isEmpty() || !pathIterator.hasNext()) { if (children == null || children.isEmpty() || !pathIterator.hasNext()) {
pathMap.put(path , treeNode.getId()); pathMap.put(path, treeNode.getId());
if (pathIterator.hasNext()) { if (pathIterator.hasNext()) {
createNodeByPath(pathIterator, pathIterator.next().trim(), treeNode, projectId, level, path, pathMap); createNodeByPath(pathIterator, pathIterator.next().trim(), treeNode, projectId, level, path, pathMap);
} }
@ -336,7 +341,8 @@ public class TestCaseNodeService {
hasNode = true; hasNode = true;
createNodeByPathIterator(pathIterator, path + "/" + child.getName(), createNodeByPathIterator(pathIterator, path + "/" + child.getName(),
child, pathMap, projectId, level + 1); child, pathMap, projectId, level + 1);
}; }
;
} }
//若子节点中不包含该目标节点则在该节点下创建 //若子节点中不包含该目标节点则在该节点下创建
@ -347,10 +353,9 @@ public class TestCaseNodeService {
} }
/** /**
*
* @param pathIterator 迭代器遍历子节点 * @param pathIterator 迭代器遍历子节点
* @param nodeName 当前节点 * @param nodeName 当前节点
* @param pNode 父节点 * @param pNode 父节点
*/ */
private void createNodeByPath(Iterator<String> pathIterator, String nodeName, private void createNodeByPath(Iterator<String> pathIterator, String nodeName,
TestCaseNodeDTO pNode, String projectId, Integer level, TestCaseNodeDTO pNode, String projectId, Integer level,
@ -467,7 +472,7 @@ public class TestCaseNodeService {
} }
List<TestCaseNodeDTO> children = rootNode.getChildren(); List<TestCaseNodeDTO> children = rootNode.getChildren();
if (children != null && children.size() > 0){ if (children != null && children.size() > 0) {
for (int i = 0; i < children.size(); i++) { for (int i = 0; i < children.size(); i++) {
buildUpdateTestCase(children.get(i), testCases, updateNodes, rootPath + '/', rootNode.getId(), level + 1); buildUpdateTestCase(children.get(i), testCases, updateNodes, rootPath + '/', rootNode.getId(), level + 1);
} }

View File

@ -1,23 +1,22 @@
package io.metersphere.track.service; package io.metersphere.track.service;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.TestCaseReport;
import io.metersphere.base.mapper.*; import io.metersphere.base.domain.TestCaseReportExample;
import io.metersphere.base.mapper.ext.ExtTestCaseMapper; import io.metersphere.base.domain.TestCaseReportTemplate;
import io.metersphere.base.domain.TestPlan;
import io.metersphere.base.mapper.TestCaseReportMapper;
import io.metersphere.base.mapper.TestCaseReportTemplateMapper;
import io.metersphere.base.mapper.TestPlanMapper;
import io.metersphere.base.mapper.ext.ExtTestPlanMapper; import io.metersphere.base.mapper.ext.ExtTestPlanMapper;
import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper;
import io.metersphere.commons.constants.TestPlanTestCaseStatus;
import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.BeanUtils;
import io.metersphere.track.request.testCaseReport.CreateReportRequest; import io.metersphere.track.request.testCaseReport.CreateReportRequest;
import io.metersphere.track.request.testcase.QueryTestPlanRequest;
import io.metersphere.track.request.testplancase.QueryTestPlanCaseRequest;
import io.metersphere.track.dto.*;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.util.List;
import java.util.*; import java.util.UUID;
@Service @Service
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -37,7 +36,7 @@ public class TestCaseReportService {
public List<TestCaseReport> listTestCaseReport(TestCaseReport request) { public List<TestCaseReport> listTestCaseReport(TestCaseReport request) {
TestCaseReportExample example = new TestCaseReportExample(); TestCaseReportExample example = new TestCaseReportExample();
if ( StringUtils.isNotBlank(request.getName()) ) { if (StringUtils.isNotBlank(request.getName())) {
example.createCriteria().andNameEqualTo(request.getName()); example.createCriteria().andNameEqualTo(request.getName());
} }
return testCaseReportMapper.selectByExample(example); return testCaseReportMapper.selectByExample(example);

View File

@ -26,11 +26,11 @@ public class TestCaseReportTemplateService {
TestCaseReportTemplateExample example = new TestCaseReportTemplateExample(); TestCaseReportTemplateExample example = new TestCaseReportTemplateExample();
TestCaseReportTemplateExample.Criteria criteria1 = example.createCriteria(); TestCaseReportTemplateExample.Criteria criteria1 = example.createCriteria();
TestCaseReportTemplateExample.Criteria criteria2 = example.createCriteria(); TestCaseReportTemplateExample.Criteria criteria2 = example.createCriteria();
if ( StringUtils.isNotBlank(request.getName()) ) { if (StringUtils.isNotBlank(request.getName())) {
criteria1.andNameLike("%" + request.getName() + "%"); criteria1.andNameLike("%" + request.getName() + "%");
criteria2.andNameLike("%" + request.getName() + "%"); criteria2.andNameLike("%" + request.getName() + "%");
} }
if ( StringUtils.isNotBlank(request.getWorkspaceId()) ) { if (StringUtils.isNotBlank(request.getWorkspaceId())) {
criteria1.andWorkspaceIdEqualTo(request.getWorkspaceId()); criteria1.andWorkspaceIdEqualTo(request.getWorkspaceId());
} }
if (request.getQueryDefault() != null) { if (request.getQueryDefault() != null) {
@ -55,7 +55,7 @@ public class TestCaseReportTemplateService {
testCaseReportTemplateMapper.updateByPrimaryKeyWithBLOBs(testCaseReportTemplate); testCaseReportTemplateMapper.updateByPrimaryKeyWithBLOBs(testCaseReportTemplate);
} }
private void checkCaseReportTemplateExist (TestCaseReportTemplate testCaseReportTemplate) { private void checkCaseReportTemplateExist(TestCaseReportTemplate testCaseReportTemplate) {
TestCaseReportTemplateExample example = new TestCaseReportTemplateExample(); TestCaseReportTemplateExample example = new TestCaseReportTemplateExample();
example.createCriteria() example.createCriteria()
.andNameEqualTo(testCaseReportTemplate.getName()) .andNameEqualTo(testCaseReportTemplate.getName())

View File

@ -250,7 +250,7 @@ public class TestCaseService {
if (!testCases.isEmpty()) { if (!testCases.isEmpty()) {
AtomicInteger sort = new AtomicInteger(); AtomicInteger sort = new AtomicInteger();
AtomicInteger num = new AtomicInteger(); AtomicInteger num = new AtomicInteger();
num.set(getNextNum(projectId)+testCases.size()); num.set(getNextNum(projectId) + testCases.size());
testCases.forEach(testcase -> { testCases.forEach(testcase -> {
testcase.setNodeId(nodePathMap.get(testcase.getNodePath())); testcase.setNodeId(nodePathMap.get(testcase.getNodePath()));
testcase.setSort(sort.getAndIncrement()); testcase.setSort(sort.getAndIncrement());
@ -431,6 +431,7 @@ public class TestCaseService {
/** /**
* 获取项目下一个num (页面展示的ID) * 获取项目下一个num (页面展示的ID)
*
* @return * @return
*/ */
private int getNextNum(String projectId) { private int getNextNum(String projectId) {
@ -438,7 +439,7 @@ public class TestCaseService {
if (testCase == null) { if (testCase == null) {
return 100001; return 100001;
} else { } else {
return Optional.ofNullable(testCase.getNum()+1).orElse(100001); return Optional.ofNullable(testCase.getNum() + 1).orElse(100001);
} }
} }
} }

View File

@ -1,11 +1,13 @@
package io.metersphere.track.service; package io.metersphere.track.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.TestCaseMapper;
import io.metersphere.base.mapper.TestCaseReportMapper;
import io.metersphere.base.mapper.TestPlanMapper;
import io.metersphere.base.mapper.TestPlanTestCaseMapper;
import io.metersphere.base.mapper.ext.ExtProjectMapper; import io.metersphere.base.mapper.ext.ExtProjectMapper;
import io.metersphere.base.mapper.ext.ExtTestPlanMapper; import io.metersphere.base.mapper.ext.ExtTestPlanMapper;
import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper; import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper;
@ -16,15 +18,15 @@ import io.metersphere.commons.user.SessionUser;
import io.metersphere.commons.utils.MathUtils; import io.metersphere.commons.utils.MathUtils;
import io.metersphere.commons.utils.ServiceUtils; import io.metersphere.commons.utils.ServiceUtils;
import io.metersphere.commons.utils.SessionUtils; import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.controller.request.ProjectRequest; import io.metersphere.i18n.Translator;
import io.metersphere.controller.request.member.QueryMemberRequest;
import io.metersphere.dto.ProjectDTO;
import io.metersphere.track.Factory.ReportComponentFactory; import io.metersphere.track.Factory.ReportComponentFactory;
import io.metersphere.track.domain.ReportComponent; import io.metersphere.track.domain.ReportComponent;
import io.metersphere.track.dto.*; import io.metersphere.track.dto.TestCaseReportMetricDTO;
import io.metersphere.track.dto.TestPlanCaseDTO;
import io.metersphere.track.dto.TestPlanDTO;
import io.metersphere.track.dto.TestPlanDTOWithMetric;
import io.metersphere.track.request.testcase.PlanCaseRelevanceRequest; import io.metersphere.track.request.testcase.PlanCaseRelevanceRequest;
import io.metersphere.track.request.testcase.QueryTestPlanRequest; import io.metersphere.track.request.testcase.QueryTestPlanRequest;
import io.metersphere.i18n.Translator;
import io.metersphere.track.request.testplancase.QueryTestPlanCaseRequest; import io.metersphere.track.request.testplancase.QueryTestPlanCaseRequest;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.ExecutorType;
@ -35,10 +37,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
@Service @Service
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -75,7 +75,8 @@ public class TestPlanService {
public void addTestPlan(TestPlan testPlan) { public void addTestPlan(TestPlan testPlan) {
if (getTestPlanByName(testPlan.getName()).size() > 0) { if (getTestPlanByName(testPlan.getName()).size() > 0) {
MSException.throwException(Translator.get("plan_name_already_exists")); MSException.throwException(Translator.get("plan_name_already_exists"));
}; }
;
testPlan.setId(UUID.randomUUID().toString()); testPlan.setId(UUID.randomUUID().toString());
testPlan.setStatus(TestPlanStatus.Prepare.name()); testPlan.setStatus(TestPlanStatus.Prepare.name());
testPlan.setCreateTime(System.currentTimeMillis()); testPlan.setCreateTime(System.currentTimeMillis());
@ -100,7 +101,7 @@ public class TestPlanService {
return testPlanMapper.updateByPrimaryKeySelective(testPlan); return testPlanMapper.updateByPrimaryKeySelective(testPlan);
} }
private void checkTestPlanExist (TestPlan testPlan) { private void checkTestPlanExist(TestPlan testPlan) {
if (testPlan.getName() != null) { if (testPlan.getName() != null) {
TestPlanExample example = new TestPlanExample(); TestPlanExample example = new TestPlanExample();
example.createCriteria() example.createCriteria()
@ -142,8 +143,8 @@ public class TestPlanService {
Map<String, TestCaseWithBLOBs> testCaseMap = Map<String, TestCaseWithBLOBs> testCaseMap =
testCaseMapper.selectByExampleWithBLOBs(testCaseExample) testCaseMapper.selectByExampleWithBLOBs(testCaseExample)
.stream() .stream()
.collect(Collectors.toMap(TestCase::getId, testcase -> testcase)); .collect(Collectors.toMap(TestCase::getId, testcase -> testcase));
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
TestPlanTestCaseMapper batchMapper = sqlSession.getMapper(TestPlanTestCaseMapper.class); TestPlanTestCaseMapper batchMapper = sqlSession.getMapper(TestPlanTestCaseMapper.class);
@ -193,7 +194,7 @@ public class TestPlanService {
public List<TestPlanDTOWithMetric> listRelateAllPlan() { public List<TestPlanDTOWithMetric> listRelateAllPlan() {
SessionUser user = SessionUtils.getUser(); SessionUser user = SessionUtils.getUser();
QueryTestPlanRequest request = new QueryTestPlanRequest(); QueryTestPlanRequest request = new QueryTestPlanRequest();
request.setPrincipal(user.getId()); request.setPrincipal(user.getId());
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId()); request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
request.setPlanIds(extTestPlanTestCaseMapper.findRelateTestPlanId(user.getId(), SessionUtils.getCurrentWorkspaceId())); request.setPlanIds(extTestPlanTestCaseMapper.findRelateTestPlanId(user.getId(), SessionUtils.getCurrentWorkspaceId()));
@ -231,8 +232,8 @@ public class TestPlanService {
} }
}); });
} }
testPlan.setPassRate(MathUtils.getPercentWithDecimal(testPlan.getTested() == 0 ? 0 : testPlan.getPassed()*1.0/testPlan.getTested())); testPlan.setPassRate(MathUtils.getPercentWithDecimal(testPlan.getTested() == 0 ? 0 : testPlan.getPassed() * 1.0 / testPlan.getTested()));
testPlan.setTestRate(MathUtils.getPercentWithDecimal(testPlan.getTotal() == 0 ? 0 : testPlan.getTested()*1.0/testPlan.getTotal())); testPlan.setTestRate(MathUtils.getPercentWithDecimal(testPlan.getTotal() == 0 ? 0 : testPlan.getTested() * 1.0 / testPlan.getTotal()));
}); });
return testPlans; return testPlans;
@ -263,7 +264,7 @@ public class TestPlanService {
List<ReportComponent> components = ReportComponentFactory.createComponents(componentIds.toJavaList(String.class), testPlan); List<ReportComponent> components = ReportComponentFactory.createComponents(componentIds.toJavaList(String.class), testPlan);
List<TestPlanCaseDTO> testPlanTestCases = listTestCaseByPlanId(planId); List<TestPlanCaseDTO> testPlanTestCases = listTestCaseByPlanId(planId);
for (TestPlanCaseDTO testCase: testPlanTestCases) { for (TestPlanCaseDTO testCase : testPlanTestCases) {
components.forEach(component -> { components.forEach(component -> {
component.readRecord(testCase); component.readRecord(testCase);
}); });
@ -287,7 +288,7 @@ public class TestPlanService {
TestPlan testPlan = new TestPlan(); TestPlan testPlan = new TestPlan();
testPlan.setId(planId); testPlan.setId(planId);
for (String status: statusList){ for (String status : statusList) {
if (StringUtils.equals(status, TestPlanTestCaseStatus.Prepare.name()) if (StringUtils.equals(status, TestPlanTestCaseStatus.Prepare.name())
|| StringUtils.equals(status, TestPlanTestCaseStatus.Underway.name())) { || StringUtils.equals(status, TestPlanTestCaseStatus.Underway.name())) {
testPlan.setStatus(TestPlanStatus.Underway.name()); testPlan.setStatus(TestPlanStatus.Underway.name());

View File

@ -1,7 +1,10 @@
package io.metersphere.track.service; package io.metersphere.track.service;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.TestPlan;
import io.metersphere.base.domain.TestPlanTestCaseExample;
import io.metersphere.base.domain.TestPlanTestCaseWithBLOBs;
import io.metersphere.base.domain.User;
import io.metersphere.base.mapper.TestPlanTestCaseMapper; import io.metersphere.base.mapper.TestPlanTestCaseMapper;
import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper; import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper;
import io.metersphere.commons.constants.TestPlanTestCaseStatus; import io.metersphere.commons.constants.TestPlanTestCaseStatus;
@ -9,11 +12,9 @@ import io.metersphere.commons.user.SessionUser;
import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.BeanUtils;
import io.metersphere.commons.utils.ServiceUtils; import io.metersphere.commons.utils.ServiceUtils;
import io.metersphere.commons.utils.SessionUtils; import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.controller.request.OrderRequest;
import io.metersphere.controller.request.member.QueryMemberRequest; import io.metersphere.controller.request.member.QueryMemberRequest;
import io.metersphere.service.UserService; import io.metersphere.service.UserService;
import io.metersphere.track.dto.TestPlanCaseDTO; import io.metersphere.track.dto.TestPlanCaseDTO;
import io.metersphere.track.dto.TestPlanDTO;
import io.metersphere.track.request.testcase.TestPlanCaseBatchRequest; import io.metersphere.track.request.testcase.TestPlanCaseBatchRequest;
import io.metersphere.track.request.testplancase.QueryTestPlanCaseRequest; import io.metersphere.track.request.testplancase.QueryTestPlanCaseRequest;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;