style: 格式化代码,优化 import

This commit is contained in:
Captain.B 2020-07-23 09:38:19 +08:00
parent 0b03cd128f
commit 50c6cfa4d2
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 javax.annotation.Resource;
import java.util.List;
@RestController

View File

@ -16,9 +16,8 @@ import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping(value = "/api")
@ -95,7 +94,7 @@ public class APITestController {
@PostMapping(value = "/import", consumes = {"multipart/form-data"})
@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);
}

View File

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

View File

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

View File

@ -1,6 +1,5 @@
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.APITestService;
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.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.InputStream;
import java.lang.reflect.Field;
import javax.annotation.Resource;
@Service
public class JMeterService {

View File

@ -1,9 +1,6 @@
package io.metersphere.api.parse;
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;
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.scenario.Body;
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.request.HttpRequest;
import io.metersphere.api.dto.scenario.request.Request;
import io.metersphere.commons.constants.MsRequestBodyType;
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.scenario.Body;
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.request.HttpRequest;
import io.metersphere.api.dto.scenario.request.Request;
import io.metersphere.commons.constants.MsRequestBodyType;
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());
List<Request> requests = Optional.ofNullable(scenario.getRequests()).orElse(new ArrayList<>());
requests.add(request);
scenario.setRequests(requests);scenario.setName(tag);
scenario.setRequests(requests);
scenario.setName(tag);
scenarioMap.put(tag, scenario);
});
} else {
@ -86,7 +87,7 @@ public class Swagger2Parser extends ApiImportAbstractParser {
List<Parameter> parameters = operation.getParameters();
for (Parameter parameter : parameters) {
switch (parameter.getIn()){
switch (parameter.getIn()) {
// case SwaggerParameterType.PATH:
// parsePathParameters(parameter, request);
// break;
@ -137,7 +138,7 @@ public class Swagger2Parser extends ApiImportAbstractParser {
ArrayModel arrayModel = (ArrayModel) bodyParameter.getSchema();
Property items = arrayModel.getItems();
if (items instanceof RefProperty) {
RefProperty refProperty = (RefProperty) items;
RefProperty refProperty = (RefProperty) items;
Model model = definitions.get(refProperty.getSimpleRef());
JSONArray propertyList = new JSONArray();
propertyList.add(getBodyJSONObjectParameters(model.getProperties(), definitions));
@ -155,11 +156,11 @@ public class Swagger2Parser extends ApiImportAbstractParser {
if (value instanceof ObjectProperty) {
ObjectProperty objectProperty = (ObjectProperty) value;
jsonObject.put(key, getBodyJSONObjectParameters(objectProperty.getProperties(), definitions));
} else if (value instanceof ArrayProperty) {
} else if (value instanceof ArrayProperty) {
ArrayProperty arrayProperty = (ArrayProperty) value;
Property items = arrayProperty.getItems();
if (items instanceof RefProperty) {
RefProperty refProperty = (RefProperty) items;
RefProperty refProperty = (RefProperty) items;
Model model = definitions.get(refProperty.getSimpleRef());
JSONArray propertyList = new JSONArray();
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.exception.MSException;
import io.metersphere.commons.utils.ServiceUtils;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.dto.DashboardTestDTO;
import io.metersphere.i18n.Translator;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
@Service

View File

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

View File

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

View File

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

View File

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

View File

@ -1,14 +1,24 @@
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
* @return
*/

View File

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

View File

@ -7,7 +7,6 @@ import com.fit2cloud.quartz.service.QuartzManageService;
import com.fit2cloud.quartz.util.QuartzBeanFactory;
import org.springframework.beans.factory.ObjectProvider;
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.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

View File

@ -1,7 +1,8 @@
package io.metersphere.controller;
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;

View File

@ -5,7 +5,6 @@ import io.metersphere.commons.constants.ParamConstants;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.ldap.domain.LdapInfo;
import io.metersphere.service.SystemParameterService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@ -34,7 +35,7 @@ public class UserRoleController {
@GetMapping("/all/{userId}")
@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);
}
}

View File

@ -3,6 +3,7 @@ package io.metersphere.controller.request.member;
import io.metersphere.base.domain.User;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -11,6 +12,6 @@ import java.util.Map;
@Setter
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 lombok.Getter;
import lombok.Setter;
import java.util.List;
@Getter

View File

@ -11,9 +11,10 @@ public class ExcelErrData<T> {
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.rowNum = rowNum;
this.errMsg = errMsg;

View File

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

View File

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

View File

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

View File

@ -42,7 +42,7 @@ public class TestCaseDataListener extends EasyExcelListener<TestCaseExcelData> {
if (nodePath != null) {
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") +
TestCaseConstants.MAX_NODE_DEPTH + Translator.get("test_case_node_level"));
}
@ -122,7 +122,7 @@ public class TestCaseDataListener extends EasyExcelListener<TestCaseExcelData> {
String pattern = "(^\\d+)(\\.)?";
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();
step.put("num", i + 1);

View File

@ -1,24 +1,14 @@
package io.metersphere.excel.utils;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.excel.domain.TestCaseExcelData;
import io.metersphere.exception.ExcelException;
import io.metersphere.i18n.Translator;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
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.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
public class EasyExcelExporter {

View File

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

View File

@ -2,7 +2,6 @@ package io.metersphere.excel.utils;
import com.alibaba.excel.annotation.ExcelProperty;
import org.springframework.stereotype.Component;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
@ -20,7 +19,7 @@ public class ExcelValidateHelper {
@Resource
Validator validator;
public static <T> String validateEntity(T obj) throws NoSuchFieldException {
public static <T> String validateEntity(T obj) throws NoSuchFieldException {
StringBuilder result = new StringBuilder();
Set<ConstraintViolation<T>> set = excelValidateHelper.validator.validate(obj, Default.class);
if (set != null && !set.isEmpty()) {
@ -28,7 +27,7 @@ public class ExcelValidateHelper {
Field declaredField = obj.getClass().getDeclaredField(cv.getPropertyPath().toString());
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();

View File

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

View File

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

View File

@ -14,6 +14,7 @@ public class ScheduleManager {
/**
* 添加 simpleJob
*
* @param jobKey
* @param triggerKey
* @param cls
@ -22,7 +23,7 @@ public class ScheduleManager {
* @throws SchedulerException
*/
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);
@ -58,6 +59,7 @@ public class ScheduleManager {
/**
* 添加 cronJob
*
* @param jobKey
* @param triggerKey
* @param jobClass
@ -102,6 +104,7 @@ public class ScheduleManager {
/**
* 修改 cronTrigger
*
* @param triggerKey
* @param cron
* @throws SchedulerException
@ -149,6 +152,7 @@ public class ScheduleManager {
/**
* 修改simpleTrigger触发器的触发时间
*
* @param triggerKey
* @param repeatIntervalTime
* @throws SchedulerException
@ -199,12 +203,10 @@ public class ScheduleManager {
}
/**
*
* @Title:
* @Description: 根据job和trigger删除任务
*
* @param jobKey
* @param triggerKey
* @Title:
* @Description: 根据job和trigger删除任务
*/
public void removeJob(JobKey jobKey, TriggerKey triggerKey) {
@ -248,6 +250,7 @@ public class ScheduleManager {
/**
* 新增或者修改 simpleJob
*
* @param jobKey
* @param triggerKey
* @param clz
@ -256,7 +259,7 @@ public class ScheduleManager {
* @throws SchedulerException
*/
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)) {
modifySimpleJobTime(triggerKey, intervalTime);
@ -273,6 +276,7 @@ public class ScheduleManager {
/**
* 添加或修改 cronJob
*
* @param jobKey
* @param triggerKey
* @param jobClass

View File

@ -13,7 +13,10 @@ import io.metersphere.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
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;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,42 +21,43 @@ public class TestCaseNodeController {
TestCaseNodeService testCaseNodeService;
@GetMapping("/list/{projectId}")
public List<TestCaseNodeDTO> getNodeByProjectId(@PathVariable String projectId){
public List<TestCaseNodeDTO> getNodeByProjectId(@PathVariable String projectId) {
return testCaseNodeService.getNodeTreeByProjectId(projectId);
}
/*模块列表列表*/
@GetMapping("/list/all/plan/{planId}")
public List<TestCaseNodeDTO> getAllNodeByPlanId(@PathVariable String planId){
public List<TestCaseNodeDTO> getAllNodeByPlanId(@PathVariable String planId) {
return testCaseNodeService.getAllNodeByPlanId(planId);
}
@GetMapping("/list/plan/{planId}")
public List<TestCaseNodeDTO> getNodeByPlanId(@PathVariable String planId){
public List<TestCaseNodeDTO> getNodeByPlanId(@PathVariable String planId) {
return testCaseNodeService.getNodeByPlanId(planId);
}
@PostMapping("/add")
@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);
}
@PostMapping("/edit")
@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);
}
@PostMapping("/delete")
@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
return testCaseNodeService.deleteNode(nodeIds);
}
@PostMapping("/drag")
@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);
}
}

View File

@ -3,7 +3,6 @@ package io.metersphere.track.controller;
import io.metersphere.base.domain.TestCaseReport;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.track.request.testCaseReport.CreateReportRequest;
import io.metersphere.track.dto.TestCaseReportMetricDTO;
import io.metersphere.track.service.TestCaseReportService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
@ -25,25 +24,25 @@ public class TestCaseReportController {
}
@GetMapping("/get/{id}")
public TestCaseReport get(@PathVariable String id){
public TestCaseReport get(@PathVariable String id) {
return testCaseReportService.getTestCaseReport(id);
}
@PostMapping("/add")
@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);
}
@PostMapping("/edit")
@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);
}
@PostMapping("/delete/{id}")
@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);
}

View File

@ -24,25 +24,25 @@ public class TestCaseReportTemplateController {
}
@GetMapping("/get/{id}")
public TestCaseReportTemplate get(@PathVariable String id){
public TestCaseReportTemplate get(@PathVariable String id) {
return testCaseReportTemplateService.getTestCaseReportTemplate(id);
}
@PostMapping("/add")
@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);
}
@PostMapping("/edit")
@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);
}
@PostMapping("/delete/{id}")
@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);
}

View File

@ -63,41 +63,41 @@ public class TestPlanController {
}
@PostMapping("/get/{testPlanId}")
public TestPlan getTestPlan(@PathVariable String testPlanId){
public TestPlan getTestPlan(@PathVariable String testPlanId) {
return testPlanService.getTestPlan(testPlanId);
}
@PostMapping("/add")
@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);
}
@PostMapping("/edit")
@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);
}
@PostMapping("/edit/status/{planId}")
@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);
}
@PostMapping("/delete/{testPlanId}")
@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);
}
@PostMapping("/relevance")
public void testPlanRelevance(@RequestBody PlanCaseRelevanceRequest request){
public void testPlanRelevance(@RequestBody PlanCaseRelevanceRequest request) {
testPlanService.testPlanRelevance(request);
}
@GetMapping("/get/metric/{planId}")
public TestCaseReportMetricDTO getMetric(@PathVariable String planId){
public TestCaseReportMetricDTO getMetric(@PathVariable String 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.PageHelper;
import io.metersphere.base.domain.TestPlanTestCase;
import io.metersphere.base.domain.TestPlanTestCaseWithBLOBs;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.track.dto.TestPlanCaseDTO;
import io.metersphere.track.request.testcase.TestPlanCaseBatchRequest;
import io.metersphere.track.request.testplancase.QueryTestPlanCaseRequest;
import io.metersphere.track.dto.TestPlanCaseDTO;
import io.metersphere.track.service.TestPlanTestCaseService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
@ -17,7 +16,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@RequestMapping("/test/plan/case")

View File

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

View File

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

View File

@ -55,7 +55,7 @@ public class ReportResultComponent extends ReportComponent {
});
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) {
moduleResultMap.remove(moduleResult.getModuleId());
}
@ -69,9 +69,9 @@ public class ReportResultComponent extends ReportComponent {
List<TestCaseNodeDTO> children = rootNode.getChildren();
if(children != null) {
if (children != null) {
Iterator<TestCaseNodeDTO> iterator = children.iterator();
while(iterator.hasNext()){
while (iterator.hasNext()) {
getChildIds(iterator.next(), childIds);
}
}
@ -95,7 +95,8 @@ public class ReportResultComponent extends ReportComponent {
if (StringUtils.isNotBlank(testCase.getIssues())) {
if (JSON.parseObject(testCase.getIssues()).getBoolean("hasIssues")) {
moduleResult.setIssuesCount(moduleResult.getIssuesCount() + 1);
};
}
;
}
moduleResultMap.put(rootNodeId, moduleResult);
return;

View File

@ -1,9 +1,5 @@
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.Setter;

View File

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

View File

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

View File

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

View File

@ -1,23 +1,22 @@
package io.metersphere.track.service;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtTestCaseMapper;
import io.metersphere.base.domain.TestCaseReport;
import io.metersphere.base.domain.TestCaseReportExample;
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.ExtTestPlanTestCaseMapper;
import io.metersphere.commons.constants.TestPlanTestCaseStatus;
import io.metersphere.commons.utils.BeanUtils;
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.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.List;
import java.util.UUID;
@Service
@Transactional(rollbackFor = Exception.class)
@ -37,7 +36,7 @@ public class TestCaseReportService {
public List<TestCaseReport> listTestCaseReport(TestCaseReport request) {
TestCaseReportExample example = new TestCaseReportExample();
if ( StringUtils.isNotBlank(request.getName()) ) {
if (StringUtils.isNotBlank(request.getName())) {
example.createCriteria().andNameEqualTo(request.getName());
}
return testCaseReportMapper.selectByExample(example);

View File

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

View File

@ -250,7 +250,7 @@ public class TestCaseService {
if (!testCases.isEmpty()) {
AtomicInteger sort = new AtomicInteger();
AtomicInteger num = new AtomicInteger();
num.set(getNextNum(projectId)+testCases.size());
num.set(getNextNum(projectId) + testCases.size());
testCases.forEach(testcase -> {
testcase.setNodeId(nodePathMap.get(testcase.getNodePath()));
testcase.setSort(sort.getAndIncrement());
@ -431,6 +431,7 @@ public class TestCaseService {
/**
* 获取项目下一个num (页面展示的ID)
*
* @return
*/
private int getNextNum(String projectId) {
@ -438,7 +439,7 @@ public class TestCaseService {
if (testCase == null) {
return 100001;
} 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;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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.ExtTestPlanMapper;
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.ServiceUtils;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.controller.request.ProjectRequest;
import io.metersphere.controller.request.member.QueryMemberRequest;
import io.metersphere.dto.ProjectDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.track.Factory.ReportComponentFactory;
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.QueryTestPlanRequest;
import io.metersphere.i18n.Translator;
import io.metersphere.track.request.testplancase.QueryTestPlanCaseRequest;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
@ -35,10 +37,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Service
@Transactional(rollbackFor = Exception.class)
@ -75,7 +75,8 @@ public class TestPlanService {
public void addTestPlan(TestPlan testPlan) {
if (getTestPlanByName(testPlan.getName()).size() > 0) {
MSException.throwException(Translator.get("plan_name_already_exists"));
};
}
;
testPlan.setId(UUID.randomUUID().toString());
testPlan.setStatus(TestPlanStatus.Prepare.name());
testPlan.setCreateTime(System.currentTimeMillis());
@ -100,7 +101,7 @@ public class TestPlanService {
return testPlanMapper.updateByPrimaryKeySelective(testPlan);
}
private void checkTestPlanExist (TestPlan testPlan) {
private void checkTestPlanExist(TestPlan testPlan) {
if (testPlan.getName() != null) {
TestPlanExample example = new TestPlanExample();
example.createCriteria()
@ -142,8 +143,8 @@ public class TestPlanService {
Map<String, TestCaseWithBLOBs> testCaseMap =
testCaseMapper.selectByExampleWithBLOBs(testCaseExample)
.stream()
.collect(Collectors.toMap(TestCase::getId, testcase -> testcase));
.stream()
.collect(Collectors.toMap(TestCase::getId, testcase -> testcase));
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
TestPlanTestCaseMapper batchMapper = sqlSession.getMapper(TestPlanTestCaseMapper.class);
@ -193,7 +194,7 @@ public class TestPlanService {
public List<TestPlanDTOWithMetric> listRelateAllPlan() {
SessionUser user = SessionUtils.getUser();
QueryTestPlanRequest request = new QueryTestPlanRequest();
QueryTestPlanRequest request = new QueryTestPlanRequest();
request.setPrincipal(user.getId());
request.setWorkspaceId(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.setTestRate(MathUtils.getPercentWithDecimal(testPlan.getTotal() == 0 ? 0 : testPlan.getTested()*1.0/testPlan.getTotal()));
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()));
});
return testPlans;
@ -263,7 +264,7 @@ public class TestPlanService {
List<ReportComponent> components = ReportComponentFactory.createComponents(componentIds.toJavaList(String.class), testPlan);
List<TestPlanCaseDTO> testPlanTestCases = listTestCaseByPlanId(planId);
for (TestPlanCaseDTO testCase: testPlanTestCases) {
for (TestPlanCaseDTO testCase : testPlanTestCases) {
components.forEach(component -> {
component.readRecord(testCase);
});
@ -287,7 +288,7 @@ public class TestPlanService {
TestPlan testPlan = new TestPlan();
testPlan.setId(planId);
for (String status: statusList){
for (String status : statusList) {
if (StringUtils.equals(status, TestPlanTestCaseStatus.Prepare.name())
|| StringUtils.equals(status, TestPlanTestCaseStatus.Underway.name())) {
testPlan.setStatus(TestPlanStatus.Underway.name());

View File

@ -1,7 +1,10 @@
package io.metersphere.track.service;
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.ext.ExtTestPlanTestCaseMapper;
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.ServiceUtils;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.controller.request.OrderRequest;
import io.metersphere.controller.request.member.QueryMemberRequest;
import io.metersphere.service.UserService;
import io.metersphere.track.dto.TestPlanCaseDTO;
import io.metersphere.track.dto.TestPlanDTO;
import io.metersphere.track.request.testcase.TestPlanCaseBatchRequest;
import io.metersphere.track.request.testplancase.QueryTestPlanCaseRequest;
import org.apache.commons.lang3.StringUtils;