Merge remote-tracking branch 'origin/master'

This commit is contained in:
q4speed 2020-09-22 14:27:21 +08:00
commit a52ae19526
30 changed files with 406 additions and 280 deletions

View File

@ -12,6 +12,7 @@ import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.controller.request.QueryScheduleRequest;
import io.metersphere.dto.LicenseDTO;
import io.metersphere.dto.ScheduleDao;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
@ -19,7 +20,6 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.List;
@RestController
@ -127,4 +127,10 @@ public class APITestController {
public List<ScheduleDao> listSchedule(@RequestBody QueryScheduleRequest request) {
return apiTestService.listSchedule(request);
}
@GetMapping("/license/valid")
public LicenseDTO valid() {
return apiTestService.validateLicense();
}
}

View File

@ -12,7 +12,6 @@ import io.metersphere.api.parse.JmeterDocumentParser;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ApiTestFileMapper;
import io.metersphere.base.mapper.ApiTestMapper;
import io.metersphere.base.mapper.UserMapper;
import io.metersphere.base.mapper.ext.ExtApiTestMapper;
import io.metersphere.commons.constants.APITestStatus;
import io.metersphere.commons.constants.FileType;
@ -21,15 +20,13 @@ import io.metersphere.commons.constants.ScheduleType;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.*;
import io.metersphere.controller.request.QueryScheduleRequest;
import io.metersphere.dto.LicenseDTO;
import io.metersphere.dto.ScheduleDao;
import io.metersphere.i18n.Translator;
import io.metersphere.job.sechedule.ApiTestJob;
import io.metersphere.notice.service.MailService;
import io.metersphere.notice.service.NoticeService;
import io.metersphere.service.FileService;
import io.metersphere.service.QuotaService;
import io.metersphere.service.ScheduleService;
import io.metersphere.service.UserService;
import io.metersphere.service.*;
import io.metersphere.track.service.TestCaseService;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.CommonConstants;
@ -40,7 +37,6 @@ import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
@ -441,4 +437,13 @@ public class APITestService {
quotaService.checkAPITestQuota();
}
}
public LicenseDTO validateLicense() {
LicenseService licenseService = CommonBeanFactory.getBean(LicenseService.class);
if (licenseService != null) {
return licenseService.valid();
}
return null;
}
}

View File

@ -2,12 +2,16 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="io.metersphere.base.mapper.ext.ExtTestCaseReviewMapper">
<select id="list" resultType="io.metersphere.track.dto.TestCaseReviewDTO" parameterType="io.metersphere.track.request.testreview.QueryCaseReviewRequest">
select distinct test_case_review.*
from test_case_review, project, test_case_review_project
<select id="list" resultType="io.metersphere.track.dto.TestCaseReviewDTO"
parameterType="io.metersphere.track.request.testreview.QueryCaseReviewRequest">
select distinct test_case_review.id, test_case_review.name, user.name as creator, test_case_review.status,
test_case_review.create_time, test_case_review.update_time, test_case_review.end_time,
test_case_review.description
from test_case_review, project, test_case_review_project, user
<where>
test_case_review.id = test_case_review_project.review_id
and test_case_review_project.project_id = project.id
and user.id = test_case_review.creator
<if test="request.name != null">
and test_case_review.name like CONCAT('%', #{request.name},'%')
</if>
@ -21,7 +25,8 @@
</if>
</select>
<select id="listByWorkspaceId" resultType="io.metersphere.track.dto.TestCaseReviewDTO" parameterType="io.metersphere.track.request.testreview.QueryCaseReviewRequest">
<select id="listByWorkspaceId" resultType="io.metersphere.track.dto.TestCaseReviewDTO"
parameterType="io.metersphere.track.request.testreview.QueryCaseReviewRequest">
select distinct test_case_review.*
from test_case_review, project, test_case_review_project
where test_case_review.id = test_case_review_project.review_id

View File

@ -0,0 +1,14 @@
package io.metersphere.dto;
import lombok.Data;
import java.io.Serializable;
@Data
public class LicenseDTO implements Serializable {
private String status;
private LicenseInfoDTO license;
}

View File

@ -0,0 +1,21 @@
package io.metersphere.dto;
import lombok.Data;
import java.io.Serializable;
@Data
public class LicenseInfoDTO implements Serializable {
// 客户名称
private String corporation;
// 授权截止时间
private String expired;
//产品名称
private String product;
//产品版本
private String edition;
//icense版本
private String licenseVersion;
//授权数量
private int licenseCount;
}

View File

@ -0,0 +1,10 @@
package io.metersphere.service;
import io.metersphere.dto.LicenseDTO;
public interface LicenseService {
public LicenseDTO valid();
public LicenseDTO addValidLicense(String reqLicenseCode);
}

View File

@ -27,7 +27,7 @@ import io.metersphere.i18n.Translator;
import io.metersphere.track.dto.TestCaseDTO;
import io.metersphere.track.request.testcase.QueryTestCaseRequest;
import io.metersphere.track.request.testcase.TestCaseBatchRequest;
import io.metersphere.xmind.XmindToTestCaseParser;
import io.metersphere.xmind.XmindCaseParser;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
@ -273,13 +273,18 @@ public class TestCaseService {
if (multipartFile.getOriginalFilename().endsWith(".xmind")) {
try {
errList = new ArrayList<>();
String processLog = new XmindToTestCaseParser(this, userId, projectId, testCaseNames).importXmind(multipartFile);
XmindCaseParser xmindParser = new XmindCaseParser(this, userId, projectId, testCaseNames);
String processLog = xmindParser.parse(multipartFile);
if (!StringUtils.isEmpty(processLog)) {
excelResponse.setSuccess(false);
ExcelErrData excelErrData = new ExcelErrData(null, 1, Translator.get("upload_fail")+""+ processLog);
ExcelErrData excelErrData = new ExcelErrData(null, 1, Translator.get("upload_fail") + "" + processLog);
errList.add(excelErrData);
excelResponse.setErrList(errList);
} else {
if (!xmindParser.getTestCase().isEmpty()) {
this.saveImportData(xmindParser.getTestCase(), projectId);
xmindParser.clear();
}
excelResponse.setSuccess(true);
}
} catch (Exception e) {
@ -345,7 +350,7 @@ public class TestCaseService {
// 发送给客户端的数据
byte[] buff = new byte[1024];
try (OutputStream outputStream = res.getOutputStream();
BufferedInputStream bis = new BufferedInputStream(TestCaseService.class.getResourceAsStream("/io/metersphere/xmind/template/testcase.xml"));) {
BufferedInputStream bis = new BufferedInputStream(TestCaseService.class.getResourceAsStream("/io/metersphere/xmind/template/xmind.xml"));) {
int i = bis.read(buff);
while (i != -1) {
outputStream.write(buff, 0, buff.length);

View File

@ -1,6 +1,5 @@
package io.metersphere.xmind;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.base.domain.TestCaseWithBLOBs;
@ -11,15 +10,11 @@ import io.metersphere.excel.domain.TestCaseExcelData;
import io.metersphere.i18n.Translator;
import io.metersphere.track.service.TestCaseService;
import io.metersphere.xmind.parser.XmindParser;
import io.metersphere.xmind.parser.domain.Attached;
import io.metersphere.xmind.parser.domain.JsonRootBean;
import io.metersphere.xmind.parser.pojo.Attached;
import io.metersphere.xmind.parser.pojo.JsonRootBean;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -27,35 +22,48 @@ import java.util.regex.Pattern;
/**
* 数据转换
* 1 解析Xmind文件 XmindParser.parseJson
* 2 解析后的JSON 转成测试用例
* 2 解析后的JSON this.parse 转成测试用例
*/
public class XmindToTestCaseParser {
public class XmindCaseParser {
private TestCaseService testCaseService;
private String maintainer;
private String projectId;
private StringBuffer process; // 过程校验记录
// 已存在用例名称
private Set<String> testCaseNames;
public XmindToTestCaseParser(TestCaseService testCaseService, String userId, String projectId, Set<String> testCaseNames) {
// 案例详情重写了hashCode方法去重用
private List<TestCaseWithBLOBs> testCases;
// 用于重复对比
private List<TestCaseExcelData> compartDatas;
public XmindCaseParser(TestCaseService testCaseService, String userId, String projectId, Set<String> testCaseNames) {
this.testCaseService = testCaseService;
this.maintainer = userId;
this.projectId = projectId;
this.testCaseNames = testCaseNames;
testCaseWithBLOBs = new LinkedList<>();
xmindDataList = new ArrayList<>();
testCases = new LinkedList<>();
compartDatas = new ArrayList<>();
process = new StringBuffer();
}
// 案例详情
private List<TestCaseWithBLOBs> testCaseWithBLOBs;
// 用于重复对比
protected List<TestCaseExcelData> xmindDataList;
// 这里清理是为了 加快jvm 回收
public void clear() {
compartDatas.clear();
testCases.clear();
testCaseNames.clear();
}
public List<TestCaseWithBLOBs> getTestCase() {
return this.testCases;
}
// 递归处理案例数据
private void makeXmind(StringBuffer processBuffer, Attached parent, int level, String nodePath, List<Attached> attacheds) {
private void recursion(StringBuffer processBuffer, Attached parent, int level, String nodePath, List<Attached> attacheds) {
for (Attached item : attacheds) {
if (isBlack(item.getTitle(), "(?:tc|tc:|tc)")) { // 用例
if (isAvailable(item.getTitle(), "(?:tc|tc:|tc)")) { // 用例
item.setParent(parent);
this.newTestCase(item.getTitle(), parent.getPath(), item.getChildren() != null ? item.getChildren().getAttached() : null);
} else {
@ -63,14 +71,13 @@ public class XmindToTestCaseParser {
item.setPath(nodePath);
if (item.getChildren() != null && !item.getChildren().getAttached().isEmpty()) {
item.setParent(parent);
makeXmind(processBuffer, item, level + 1, nodePath, item.getChildren().getAttached());
recursion(processBuffer, item, level + 1, nodePath, item.getChildren().getAttached());
}
}
}
}
private boolean isBlack(String str, String regex) {
// regex = "(?:tc:|tc)"
private boolean isAvailable(String str, String regex) {
if (StringUtils.isEmpty(str) || StringUtils.isEmpty(regex))
return false;
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
@ -88,7 +95,7 @@ public class XmindToTestCaseParser {
}
// 获取步骤数据
public String getSteps(List<Attached> attacheds) {
private String getSteps(List<Attached> attacheds) {
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < attacheds.size(); i++) {
// 保持插入顺序判断用例是否有相同的steps
@ -148,9 +155,9 @@ public class XmindToTestCaseParser {
List<Attached> steps = new LinkedList<>();
if (attacheds != null && !attacheds.isEmpty()) {
attacheds.forEach(item -> {
if (isBlack(item.getTitle(), "(?:pc:|pc)")) {
if (isAvailable(item.getTitle(), "(?:pc:|pc)")) {
testCase.setPrerequisite(replace(item.getTitle(), "(?:pc:|pc)"));
} else if (isBlack(item.getTitle(), "(?:rc:|rc)")) {
} else if (isAvailable(item.getTitle(), "(?:rc:|rc)")) {
testCase.setRemark(replace(item.getTitle(), "(?:rc:|rc)"));
} else {
steps.add(item);
@ -171,49 +178,19 @@ public class XmindToTestCaseParser {
}
TestCaseExcelData compartData = new TestCaseExcelData();
BeanUtils.copyBean(compartData, testCase);
if (xmindDataList.contains(compartData)) {
if (compartDatas.contains(compartData)) {
process.append(Translator.get("test_case_already_exists_excel") + "" + testCase.getName() + "; ");
} else if (validate(testCase)) {
testCase.setId(UUID.randomUUID().toString());
testCase.setCreateTime(System.currentTimeMillis());
testCase.setUpdateTime(System.currentTimeMillis());
testCaseWithBLOBs.add(testCase);
testCases.add(testCase);
}
xmindDataList.add(compartData);
compartDatas.add(compartData);
}
//获取流文件
private static void inputStreamToFile(InputStream ins, File file) {
try (OutputStream os = new FileOutputStream(file);) {
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
} catch (Exception e) {
LogUtil.error(e.getMessage());
}
}
/**
* MultipartFile File
*
* @param file
* @throws Exception
*/
private File multipartFileToFile(MultipartFile file) throws Exception {
if (file != null && file.getSize() > 0) {
try (InputStream ins = file.getInputStream();) {
File toFile = new File(file.getOriginalFilename());
inputStreamToFile(ins, toFile);
return toFile;
}
}
return null;
}
public boolean validate(TestCaseWithBLOBs data) {
// 验证合法性
private boolean validate(TestCaseWithBLOBs data) {
String nodePath = data.getNodePath();
StringBuilder stringBuilder = new StringBuilder();
@ -237,8 +214,6 @@ public class XmindToTestCaseParser {
if (testCaseNames.contains(data.getName())) {
boolean dbExist = testCaseService.exist(data);
boolean excelExist = false;
if (dbExist) {
// db exist
stringBuilder.append(Translator.get("test_case_already_exists_excel") + "" + data.getName() + "; ");
@ -255,49 +230,29 @@ public class XmindToTestCaseParser {
}
// 导入思维导图处理
public String importXmind(MultipartFile multipartFile) {
public String parse(MultipartFile multipartFile) {
StringBuffer processBuffer = new StringBuffer();
File file = null;
try {
file = multipartFileToFile(multipartFile);
if (file == null || !file.exists())
return Translator.get("incorrect_format");
// 获取思维导图内容
String content = XmindParser.parseJson(file);
if (StringUtils.isEmpty(content) || content.split("(?:tc:|tc|TC:|TC|tc|TC)").length == 1) {
return Translator.get("import_xmind_not_found");
}
if (!StringUtils.isEmpty(content) && content.split("(?:tc:|tc|TC:|TC|tc|TC)").length > 500) {
return Translator.get("import_xmind_count_error");
}
JsonRootBean root = JSON.parseObject(content, JsonRootBean.class);
JsonRootBean root = XmindParser.parseObject(multipartFile);
if (root != null && root.getRootTopic() != null && root.getRootTopic().getChildren() != null) {
// 判断是模块还是用例
for (Attached item : root.getRootTopic().getChildren().getAttached()) {
if (isBlack(item.getTitle(), "(?:tc:|tc|tc)")) { // 用例
if (isAvailable(item.getTitle(), "(?:tc:|tc|tc)")) { // 用例
return replace(item.getTitle(), "(?:tc:|tc|tc)") + "" + Translator.get("test_case_create_module_fail");
} else {
item.setPath(item.getTitle());
if (item.getChildren() != null && !item.getChildren().getAttached().isEmpty()) {
item.setPath(item.getTitle());
makeXmind(processBuffer, item, 1, item.getPath(), item.getChildren().getAttached());
recursion(processBuffer, item, 1, item.getPath(), item.getChildren().getAttached());
}
}
}
}
if (StringUtils.isEmpty(process.toString()) && !testCaseWithBLOBs.isEmpty()) {
testCaseService.saveImportData(testCaseWithBLOBs, projectId);
}
} catch (Exception ex) {
processBuffer.append(Translator.get("incorrect_format"));
LogUtil.error(ex.getMessage());
ex.printStackTrace();
} finally {
if (file != null)
file.delete();
testCaseWithBLOBs.clear();
return ex.getMessage();
}
return process.toString();
}

View File

@ -1,9 +1,14 @@
package io.metersphere.xmind.parser;
import com.alibaba.fastjson.JSON;
import io.metersphere.xmind.parser.domain.JsonRootBean;
import io.metersphere.commons.exception.MSException;
import io.metersphere.i18n.Translator;
import io.metersphere.xmind.parser.pojo.JsonRootBean;
import io.metersphere.xmind.utils.FileUtil;
import org.apache.commons.compress.archivers.ArchiveException;
import org.dom4j.DocumentException;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
@ -16,101 +21,98 @@ import java.util.Objects;
* @Description 解析主体
*/
public class XmindParser {
public static final String xmindZenJson = "content.json";
public static final String xmindLegacyContent = "content.xml";
public static final String xmindLegacyComments = "comments.xml";
public static final String xmindZenJson = "content.json";
public static final String xmindLegacyContent = "content.xml";
public static final String xmindLegacyComments = "comments.xml";
/**
* 解析脑图文件返回content整合后的内容
*
* @param file
* @return
* @throws IOException
* @throws ArchiveException
* @throws DocumentException
*/
public static String parseJson(File file) throws IOException, ArchiveException, DocumentException {
String res = ZipUtils.extract(file);
/**
* 解析脑图文件返回content整合后的内容
*
* @param multipartFile
* @return
* @throws IOException
* @throws ArchiveException
* @throws DocumentException
*/
public static String parseJson(MultipartFile multipartFile) throws IOException, ArchiveException, DocumentException {
String content = null;
if (isXmindZen(res, file)) {
content = getXmindZenContent(file, res);
} else {
content = getXmindLegacyContent(file, res);
}
File file = FileUtil.multipartFileToFile(multipartFile);
if (file == null || !file.exists())
MSException.throwException(Translator.get("incorrect_format"));
// 删除生成的文件夹
File dir = new File(res);
boolean flag = deleteDir(dir);
if (flag) {
// do something
}
JsonRootBean jsonRootBean = JSON.parseObject(content, JsonRootBean.class);
return (JSON.toJSONString(jsonRootBean, false));
}
String res = ZipUtils.extract(file);
String content = null;
if (isXmindZen(res, file)) {
content = getXmindZenContent(file, res);
} else {
content = getXmindLegacyContent(file, res);
}
public static JsonRootBean parseObject(File file) throws DocumentException, ArchiveException, IOException {
String content = parseJson(file);
JsonRootBean jsonRootBean = JSON.parseObject(content, JsonRootBean.class);
return jsonRootBean;
}
// 删除生成的文件夹
File dir = new File(res);
FileUtil.deleteDir(dir);
JsonRootBean jsonRootBean = JSON.parseObject(content, JsonRootBean.class);
// 删除零时文件
if (file != null)
file.delete();
String json = (JSON.toJSONString(jsonRootBean, false));
public static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
// 递归删除目录中的子目录下
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
// 目录此时为空可以删除
return dir.delete();
}
if (StringUtils.isEmpty(content) || content.split("(?:tc:|tc|TC:|TC|tc|TC)").length == 1) {
MSException.throwException(Translator.get("import_xmind_not_found"));
}
if (!StringUtils.isEmpty(content) && content.split("(?:tc:|tc|TC:|TC|tc|TC)").length > 500) {
MSException.throwException(Translator.get("import_xmind_count_error"));
}
return json;
}
/**
* @return
*/
public static String getXmindZenContent(File file, String extractFileDir)
throws IOException, ArchiveException {
List<String> keys = new ArrayList<>();
keys.add(xmindZenJson);
Map<String, String> map = ZipUtils.getContents(keys, file, extractFileDir);
String content = map.get(xmindZenJson);
content = XmindZen.getContent(content);
return content;
}
public static JsonRootBean parseObject(MultipartFile multipartFile) throws DocumentException, ArchiveException, IOException {
String content = parseJson(multipartFile);
JsonRootBean jsonRootBean = JSON.parseObject(content, JsonRootBean.class);
return jsonRootBean;
}
/**
* @return
*/
public static String getXmindLegacyContent(File file, String extractFileDir)
throws IOException, ArchiveException, DocumentException {
List<String> keys = new ArrayList<>();
keys.add(xmindLegacyContent);
keys.add(xmindLegacyComments);
Map<String, String> map = ZipUtils.getContents(keys, file, extractFileDir);
/**
* @return
*/
public static String getXmindZenContent(File file, String extractFileDir)
throws IOException, ArchiveException {
List<String> keys = new ArrayList<>();
keys.add(xmindZenJson);
Map<String, String> map = ZipUtils.getContents(keys, file, extractFileDir);
String content = map.get(xmindZenJson);
content = XmindZen.getContent(content);
return content;
}
String contentXml = map.get(xmindLegacyContent);
String commentsXml = map.get(xmindLegacyComments);
String xmlContent = XmindLegacy.getContent(contentXml, commentsXml);
/**
* @return
*/
public static String getXmindLegacyContent(File file, String extractFileDir)
throws IOException, ArchiveException, DocumentException {
List<String> keys = new ArrayList<>();
keys.add(xmindLegacyContent);
keys.add(xmindLegacyComments);
Map<String, String> map = ZipUtils.getContents(keys, file, extractFileDir);
return xmlContent;
}
String contentXml = map.get(xmindLegacyContent);
String commentsXml = map.get(xmindLegacyComments);
String xmlContent = XmindLegacy.getContent(contentXml, commentsXml);
private static boolean isXmindZen(String res, File file) throws IOException, ArchiveException {
// 解压
File parent = new File(res);
if (parent.isDirectory()) {
String[] files = parent.list(new ZipUtils.FileFilter());
for (int i = 0; i < Objects.requireNonNull(files).length; i++) {
if (files[i].equals(xmindZenJson)) {
return true;
}
}
}
return false;
}
return xmlContent;
}
private static boolean isXmindZen(String res, File file) throws IOException, ArchiveException {
// 解压
File parent = new File(res);
if (parent.isDirectory()) {
String[] files = parent.list(new ZipUtils.FileFilter());
for (int i = 0; i < Objects.requireNonNull(files).length; i++) {
if (files[i].equals(xmindZenJson)) {
return true;
}
}
}
return false;
}
}

View File

@ -1,5 +1,5 @@
package io.metersphere.xmind.parser.domain;
package io.metersphere.xmind.parser.pojo;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package io.metersphere.xmind.parser.domain;
package io.metersphere.xmind.parser.pojo;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package io.metersphere.xmind.parser.domain;
package io.metersphere.xmind.parser.pojo;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package io.metersphere.xmind.parser.domain;
package io.metersphere.xmind.parser.pojo;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package io.metersphere.xmind.parser.domain;
package io.metersphere.xmind.parser.pojo;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package io.metersphere.xmind.parser.domain;
package io.metersphere.xmind.parser.pojo;
import lombok.Data;

View File

@ -0,0 +1,61 @@
package io.metersphere.xmind.utils;
import io.metersphere.commons.utils.LogUtil;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class FileUtil {
//获取流文件
private static void inputStreamToFile(InputStream ins, File file) {
try (OutputStream os = new FileOutputStream(file);) {
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
} catch (Exception e) {
LogUtil.error(e.getMessage());
}
}
/**
* MultipartFile File
*
* @param file
* @throws Exception
*/
public static File multipartFileToFile(MultipartFile file) {
if (file != null && file.getSize() > 0) {
try (InputStream ins = file.getInputStream();) {
File toFile = new File(file.getOriginalFilename());
inputStreamToFile(ins, toFile);
return toFile;
} catch (Exception e) {
LogUtil.error(e.getMessage());
}
}
return null;
}
public static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
// 递归删除目录中的子目录下
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
// 目录此时为空可以删除
return dir.delete();
}
}

View File

@ -2,7 +2,7 @@
<el-col v-if="auth">
<el-row id="header-top1" type="flex" justify="space-between" align="middle">
<el-col>
<div class="license-head" v-if="valid === true && validData.status == 'expired'">License has expired since
<div class="license-head" v-if="validData.status == 'expired'">License has expired since
{{(validData!= undefined && validData.license!= undefined) ? validData.license.expired:''}},please
update license.
</div>
@ -40,15 +40,7 @@
export default {
name: 'app',
data() {
let xpack = false;
Setting.children.forEach(child => {
if (child.path === "license") {
xpack = true;
return;
}
})
return {
valid: xpack,
validData: {},
auth: false
}
@ -67,13 +59,14 @@
});
},
beforeMount() {
if (this.valid === true) {
// license
this.result = this.$get("/license/valid", response => {
// license
this.result = this.$get("/api/license/valid", response => {
let data = response.data;
if (data != undefined && data != null) {
this.validData = response.data;
saveLicense(response.data);
});
}
}
});
},
components: {MsLanguageSwitch, MsUser, MsView, MsTopMenus, MsHeaderOrgWs},
methods: {}

View File

@ -20,7 +20,7 @@
import MsMainContainer from "../../../common/components/MsMainContainer";
import MsAsideItem from "../../../common/components/MsAsideItem";
import EnvironmentEdit from "./environment/EnvironmentEdit";
import {listenGoBack, removeGoBackListener} from "../../../../../common/js/utils";
import {deepClone, listenGoBack, removeGoBackListener} from "../../../../../common/js/utils";
import {Environment, parseEnvironment} from "../model/EnvironmentModel";
export default {
@ -68,12 +68,13 @@
}
},
copyEnvironment(environment) {
this.currentEnvironment = environment;
if (!environment.id) {
this.$warning(this.$t('commons.please_save'));
return;
}
let newEnvironment = {};
Object.assign(newEnvironment, environment);
newEnvironment = new Environment(environment);
newEnvironment.id = null;
newEnvironment.name = this.getNoRepeatName(newEnvironment.name);
if (!this.validateEnvironment(newEnvironment)) {
@ -84,11 +85,7 @@
this.$refs.environmentItems.itemSelected(this.environments.length - 1, newEnvironment);
},
validateEnvironment(environment) {
if (!environment.name || !!environment.name && environment.name.length > 64) {
this.$error(this.$t('commons.input_limit', [1, 64]));
return false;
}
if (!this.$refs.environmentEdit.validateSocket(environment.socket)) {
if (!this.$refs.environmentEdit.validate()) {
this.$error(this.$t('commons.formatErr'));
return false;
}

View File

@ -79,6 +79,17 @@
}
});
},
validate() {
let isValidate = false;
this.$refs['environment'].validate((valid) => {
if (valid && this.$refs.commonConfig.validate() && this.$refs.httpConfig.validate()) {
isValidate = true;
} else {
isValidate = false;
}
});
return isValidate;
},
_save(environment) {
let param = this.buildParam(environment);
let url = '/api/environment/add';

View File

@ -8,13 +8,14 @@ export class Environment extends BaseConfig {
this.projectId = undefined;
this.name = undefined;
this.id = undefined;
this.config = options.config || new Config();
this.config = undefined;
this.set(options);
this.sets({}, options);
}
initOptions(options = {}) {
this.config = new Config(options.config);
return options;
}
}
@ -22,14 +23,16 @@ export class Environment extends BaseConfig {
export class Config extends BaseConfig {
constructor(options = {}) {
super();
this.commonConfig = options.commonConfig || new CommonConfig();
this.httpConfig = options.httpConfig || new HttpConfig();
this.commonConfig = undefined;
this.httpConfig = undefined;
this.databaseConfigs = [];
this.set(options);
this.sets({databaseConfigs: DatabaseConfig}, options);
}
initOptions(options = {}) {
this.commonConfig = new CommonConfig(options.commonConfig);
this.httpConfig = new HttpConfig(options.httpConfig);
options.databaseConfigs = options.databaseConfigs || [];
return options;
}

View File

@ -32,12 +32,12 @@
<el-submenu v-permission="['test_manager','test_user','test_viewer']"
index="8" popper-class="submenu">
<template v-slot:title>用例评审</template>
<template v-slot:title>{{$t('test_track.review.test_review')}}</template>
<ms-recent-list ref="reviewRecent" :options="reviewRecent"/>
<el-divider/>
<ms-show-all :index="'/track/review/all'"/>
<el-menu-item :index="testCaseReviewEditPath" class="blank_item"/>
<ms-create-button v-permission="['test_manager','test_user']" :index="'/track/review/create'" title="创建用例评审"/>
<ms-create-button v-permission="['test_manager','test_user']" :index="'/track/review/create'" :title="$t('test_track.review.create_review')"/>
</el-submenu>
<el-submenu v-permission="['test_manager','test_user','test_viewer']" index="7" popper-class="submenu">
@ -94,7 +94,7 @@ export default {
}
},
reviewRecent: {
title: "最近的评审",
title: this.$t('test_track.recent_review'),
url: "/test/case/review/recent/5",
index: function (item) {
return '/track/review/view/' + item.id;

View File

@ -3,7 +3,7 @@
<div>
<el-dialog :close-on-click-modal="false"
:title="operationType === 'edit' ? '编辑用例评审' : '创建用例评审'"
:title="operationType === 'edit' ? $t('test_track.review.edit_review') : $t('test_track.review.create_review')"
:visible.sync="dialogFormVisible"
@close="close"
v-loading="result.loading"
@ -14,8 +14,8 @@
<el-row>
<el-col :span="8" :offset="1">
<el-form-item
placeholder="请输入评审标题"
label="评审标题"
:placeholder="$t('test_track.review.input_review_name')"
:label="$t('test_track.review.review_name')"
:label-width="formLabelWidth"
prop="name">
<el-input v-model="form.name"/>
@ -23,10 +23,10 @@
</el-col>
<el-col :span="11" :offset="2">
<el-form-item :label="$t('test_track.plan.plan_project')" :label-width="formLabelWidth" prop="projectIds">
<el-form-item :label="$t('test_track.review.review_project')" :label-width="formLabelWidth" prop="projectIds">
<el-select
v-model="form.projectIds"
:placeholder="$t('test_track.plan.input_plan_project')"
:placeholder="$t('test_track.review.input_review_project')"
multiple
style="width: 100%"
collapse-tags
@ -44,10 +44,10 @@
<el-row>
<el-col :span="10" :offset="1">
<el-form-item label="评审人" :label-width="formLabelWidth" prop="userIds">
<el-form-item :label="$t('test_track.review.reviewer')" :label-width="formLabelWidth" prop="userIds">
<el-select
v-model="form.userIds"
placeholder="请选择评审人"
:placeholder="$t('test_track.review.input_reviewer')"
filterable multiple
collapse-tags
>
@ -62,7 +62,7 @@
</el-col>
<el-col :span="10">
<el-form-item label="截止时间" :label-width="formLabelWidth" prop="endTime">
<el-form-item :label="$t('test_track.review.end_time')" :label-width="formLabelWidth" prop="endTime">
<el-date-picker @change="endTimeChange" type="datetime" :placeholder="$t('commons.select_date')"
v-model="form.endTime"/>
</el-form-item>
@ -84,7 +84,7 @@
<el-row v-if="operationType == 'edit'" type="flex" justify="left" style="margin-top: 10px;">
<el-col :span="19" :offset="1">
<el-form-item label="当前状态" :label-width="formLabelWidth" prop="status">
<el-form-item :label="$t('test_track.review.review_status')" :label-width="formLabelWidth" prop="status">
<test-plan-status-button :status="form.status" @statusChange="statusChange"/>
</el-form-item>
</el-col>

View File

@ -3,8 +3,8 @@
<template v-slot:header>
<ms-table-header :is-tester-permission="true" :condition.sync="condition"
@search="initTableData" @create="testCaseReviewCreate"
create-tip="创建用例评审"
title="用例评审"/>
:create-tip="$t('test_track.review.create_review')"
:title="$t('test_track.review.test_review')"/>
</template>
<el-table
@ -16,28 +16,28 @@
@row-click="intoReview">
<el-table-column
prop="name"
label="评审名称"
:label="$t('test_track.review.review_name')"
show-overflow-tooltip>
</el-table-column>
<el-table-column
prop="reviewer"
label="评审人"
:label="$t('test_track.review.reviewer')"
show-overflow-tooltip>
</el-table-column>
<el-table-column
prop="projectName"
label="所属项目"
:label="$t('test_track.review.review_project')"
show-overflow-tooltip>
</el-table-column>
<el-table-column
prop="creator"
label="发起人"
:label="$t('test_track.review.review_creator')"
show-overflow-tooltip>
</el-table-column>
<el-table-column
prop="status"
column-key="status"
:label="$t('test_track.plan.plan_status')"
:label="$t('test_track.review.review_status')"
show-overflow-tooltip>
<template v-slot:default="scope">
<span class="el-dropdown-link">
@ -55,7 +55,7 @@
</el-table-column>
<el-table-column
prop="endTime"
label="截止时间"
:label="$t('test_track.review.end_time')"
show-overflow-tooltip>
<template v-slot:default="scope">
<span>{{ scope.row.endTime | timestampFormatDate }}</span>
@ -77,7 +77,7 @@
<ms-table-pagination :change="initTableData" :current-page.sync="currentPage" :page-size.sync="pageSize"
:total="total"/>
<ms-delete-confirm title="取消用例关联" @delete="_handleDelete" ref="deleteConfirm"/>
<ms-delete-confirm :title="$t('test_track.review.delete')" @delete="_handleDelete" ref="deleteConfirm"/>
</el-card>
</template>

View File

@ -5,7 +5,7 @@
<select-menu
:data="testReviews"
:current-data="currentReview"
title="评审"
:title="$t('test_track.review_view.review')"
@dataChange="changeReview"/>
<node-tree class="node-tree"
v-loading="result.loading"

View File

@ -2,7 +2,7 @@
<div>
<el-dialog title="关联测试评审"
<el-dialog :title="$t('test_track.review_view.relevance_case')"
:visible.sync="dialogFormVisible"
@close="close"
width="60%" v-loading="result.loading"

View File

@ -5,13 +5,13 @@
<ms-table-header :is-tester-permission="true" :condition.sync="condition" @search="initTableData"
:show-create="false" :tip="$t('commons.search_by_name_or_id')">
<template v-slot:title>
<node-breadcrumb class="table-title" :nodes="selectParentNodes" @refresh="refresh" title="全部评审"/>
<node-breadcrumb class="table-title" :nodes="selectParentNodes" @refresh="refresh" :title="$t('test_track.review_view.all_review')"/>
</template>
<template v-slot:button>
<ms-table-button :is-tester-permission="true" icon="el-icon-video-play"
content="开始用例评审" @click="startReview"/>
:content="$t('test_track.review_view.start_review')" @click="startReview"/>
<ms-table-button :is-tester-permission="true" icon="el-icon-connection"
content="关联用例评审"
:content="$t('test_track.review_view.relevance_case')"
@click="$emit('openTestReviewRelevanceDialog')"/>
</template>
</ms-table-header>
@ -91,13 +91,13 @@
<el-table-column
prop="projectName"
:label="$t('test_track.plan.plan_project')"
:label="$t('test_track.review.review_project')"
show-overflow-tooltip>
</el-table-column>
<el-table-column
prop="reviewerName"
label="评审人"
:label="$t('test_track.review.review_creator')"
show-overflow-tooltip
>
</el-table-column>
@ -106,7 +106,7 @@
prop="status"
:filters="statusFilters"
column-key="status"
:label="$t('test_track.plan_view.execute_result')">
:label="$t('test_track.review_view.execute_result')">
<template v-slot:default="scope">
<span class="el-dropdown-link">
<status-table-item :value="scope.row.status"/>
@ -348,41 +348,10 @@ export default {
});
},
handleSelectAll(selection) {
if (selection.length > 0) {
if (selection.length === 1) {
this.selectRows.add(selection[0]);
} else {
this.tableData.forEach(item => {
this.$set(item, "showMore", true);
this.selectRows.add(item);
});
}
} else {
this.selectRows.clear();
this.tableData.forEach(row => {
this.$set(row, "showMore", false);
})
}
},
handleSelectionChange(selection, row) {
if (this.selectRows.has(row)) {
this.$set(row, "showMore", false);
this.selectRows.delete(row);
} else {
this.$set(row, "showMore", true);
this.selectRows.add(row);
}
let arr = Array.from(this.selectRows);
// 1
if (this.selectRows.size === 1) {
this.$set(arr[0], "showMore", false);
} else if (this.selectRows.size === 2) {
arr.forEach(row => {
this.$set(row, "showMore", true);
})
}
},
handleBatch(type) {
if (this.selectRows.size < 1) {

View File

@ -617,6 +617,7 @@ export default {
length_less_than: "The length less than",
recent_plan: "Recent plan",
recent_case: "Recent case",
recent_review: "Recent review",
pass_rate: "Pass rate",
execution_result: ": Please select the execution result",
actual_result: ": The actual result is empty",
@ -722,6 +723,28 @@ export default {
plan_delete_confirm: "All use cases under this plan will be deleted,confirm delete test plan: ",
plan_delete: "Delete test plan",
},
review: {
test_review: "Test Review",
create_review: "Create Review",
edit_review: "Edit Review",
review_name: "Name",
reviewer: "Reviewer",
review_project: "Project",
review_creator: "Creator",
review_status: "Status",
end_time: "EndTime",
delete: "Delete",
input_review_name: "Please enter the name of the review",
input_review_project: "Please select the project",
input_reviewer: "Please select reviewer",
},
review_view: {
review: "Review",
all_review: "All Review",
start_review: "Start Review",
relevance_case: "Relevance Case",
execute_result: "Result",
},
module: {
search: "Search module",
rename: "Rename",

View File

@ -619,6 +619,7 @@ export default {
length_less_than: "长度必须小于",
recent_plan: "最近的计划",
recent_case: "最近的用例",
recent_review: "最近的评审",
pass_rate: "通过率",
execution_result: ": 请选择执行结果",
actual_result: ": 实际结果为空",
@ -725,6 +726,28 @@ export default {
plan_delete_confirm: "将删除该测试计划下所有用例,确认删除测试计划: ",
plan_delete: "删除计划",
},
review: {
test_review: "用例评审",
create_review: "创建用例评审",
edit_review: "编辑用例评审",
review_name: "评审名称",
reviewer: "评审人",
review_project: "所属项目",
review_creator: "发起人",
review_status: "当前状态",
end_time: "截止时间",
delete: "删除评审",
input_review_name: "请输入评审名称",
input_review_project: "请选择所属项目",
input_reviewer: "请选择评审人",
},
review_view: {
review: "评审",
all_review: "全部评审",
start_review: "开始评审",
relevance_case: "关联用例",
execute_result: "执行结果",
},
module: {
search: "搜索模块",
rename: "重命名",

View File

@ -619,6 +619,7 @@ export default {
length_less_than: "長度必須小於",
recent_plan: "最近的計劃",
recent_case: "最近的用例",
recent_review: "最近的評審",
pass_rate: "通過率",
execution_result: ": 請選擇執行結果",
actual_result: ": 實際結果為空",
@ -725,6 +726,28 @@ export default {
plan_delete_confirm: "將刪除該測試計劃下所有用例,確認刪除測試計劃: ",
plan_delete: "刪除計劃",
},
review: {
test_review: "用例評審",
create_review: "創建用例評審",
edit_review: "編輯用例評審",
review_name: "評審名稱",
reviewer: "評審人",
review_project: "所屬項目",
review_creator: "發起人",
review_status: "當前狀態",
end_time: "截止時間",
delete: "刪除評審",
input_review_name: "請輸入評審名稱",
input_review_project: "請選擇所屬項目",
input_reviewer: "請選擇評審人",
},
review_view: {
review: "評審",
all_review: "全部評審",
start_review: "開始評審",
relevance_case: "關聯用例",
execute_result: "執行結果",
},
module: {
search: "搜索模塊",
rename: "重命名",