From e50a952944a4d9d5cd8081f8d740a4832916c03b Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 22 Sep 2020 12:35:07 +0800 Subject: [PATCH 1/6] =?UTF-8?q?refactor(XPack):=20=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E6=9C=BA=E5=88=B6=E9=87=8D=E6=9E=84=EF=BC=8C=E6=9D=83=E9=99=90?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/APITestController.java | 8 ++++- .../api/service/APITestService.java | 17 ++++++---- .../java/io/metersphere/dto/LicenseDTO.java | 15 +++++++++ .../metersphere/service/LicenseService.java | 10 ++++++ .../track/service/TestCaseService.java | 4 +-- .../io/metersphere/xmind/XmindCaseParser.java | 32 ++++++++++--------- frontend/src/business/App.vue | 21 ++++-------- 7 files changed, 69 insertions(+), 38 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/dto/LicenseDTO.java create mode 100644 backend/src/main/java/io/metersphere/service/LicenseService.java diff --git a/backend/src/main/java/io/metersphere/api/controller/APITestController.java b/backend/src/main/java/io/metersphere/api/controller/APITestController.java index 4ddbf28531..6ac534febb 100644 --- a/backend/src/main/java/io/metersphere/api/controller/APITestController.java +++ b/backend/src/main/java/io/metersphere/api/controller/APITestController.java @@ -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 listSchedule(@RequestBody QueryScheduleRequest request) { return apiTestService.listSchedule(request); } + + @GetMapping("/license/valid") + public LicenseDTO valid() { + return apiTestService.validateLicense(); + } + } diff --git a/backend/src/main/java/io/metersphere/api/service/APITestService.java b/backend/src/main/java/io/metersphere/api/service/APITestService.java index ab2d8e2302..83b33c5b37 100644 --- a/backend/src/main/java/io/metersphere/api/service/APITestService.java +++ b/backend/src/main/java/io/metersphere/api/service/APITestService.java @@ -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; + } + } diff --git a/backend/src/main/java/io/metersphere/dto/LicenseDTO.java b/backend/src/main/java/io/metersphere/dto/LicenseDTO.java new file mode 100644 index 0000000000..5ed59529aa --- /dev/null +++ b/backend/src/main/java/io/metersphere/dto/LicenseDTO.java @@ -0,0 +1,15 @@ +package io.metersphere.dto; + +import io.metersphere.xpack.license.dto.LicenseInfoDTO; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class LicenseDTO implements Serializable { + + private String status; + + private LicenseInfoDTO license; + +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/service/LicenseService.java b/backend/src/main/java/io/metersphere/service/LicenseService.java new file mode 100644 index 0000000000..8636d4ae0e --- /dev/null +++ b/backend/src/main/java/io/metersphere/service/LicenseService.java @@ -0,0 +1,10 @@ +package io.metersphere.service; + +import io.metersphere.dto.LicenseDTO; + +public interface LicenseService { + + public LicenseDTO valid(); + + public LicenseDTO addValidLicense(String reqLicenseCode); +} diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index 777e82404f..07bb336bad 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -281,8 +281,8 @@ public class TestCaseService { errList.add(excelErrData); excelResponse.setErrList(errList); } else { - if (!xmindParser.testCases.isEmpty()) { - this.saveImportData(xmindParser.testCases, projectId); + if (!xmindParser.getTestCase().isEmpty()) { + this.saveImportData(xmindParser.getTestCase(), projectId); xmindParser.clear(); } excelResponse.setSuccess(true); diff --git a/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java b/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java index 4b2b849f38..0cf380bd99 100644 --- a/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java +++ b/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java @@ -33,10 +33,12 @@ public class XmindCaseParser { private StringBuffer process; // 过程校验记录 // 已存在用例名称 private Set testCaseNames; + // 案例详情重写了hashCode方法去重用 - public List testCases; + private List testCases; + // 用于重复对比 - private List xmindDataList; + private List compartDatas; public XmindCaseParser(TestCaseService testCaseService, String userId, String projectId, Set testCaseNames) { this.testCaseService = testCaseService; @@ -44,21 +46,25 @@ public class XmindCaseParser { this.projectId = projectId; this.testCaseNames = testCaseNames; testCases = new LinkedList<>(); - xmindDataList = new ArrayList<>(); + compartDatas = new ArrayList<>(); process = new StringBuffer(); } // 这里清理是为了 加快jvm 回收 public void clear() { - xmindDataList.clear(); + compartDatas.clear(); testCases.clear(); testCaseNames.clear(); } + public List getTestCase() { + return this.testCases; + } + // 递归处理案例数据 private void recursion(StringBuffer processBuffer, Attached parent, int level, String nodePath, List 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 { @@ -72,8 +78,7 @@ public class XmindCaseParser { } } - 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); @@ -151,9 +156,9 @@ public class XmindCaseParser { List 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); @@ -174,7 +179,7 @@ public class XmindCaseParser { } 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()); @@ -182,7 +187,7 @@ public class XmindCaseParser { testCase.setUpdateTime(System.currentTimeMillis()); testCases.add(testCase); } - xmindDataList.add(compartData); + compartDatas.add(compartData); } // 验证合法性 @@ -236,7 +241,7 @@ public class XmindCaseParser { 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()); @@ -247,9 +252,6 @@ public class XmindCaseParser { } } } - //if (StringUtils.isEmpty(process.toString()) && !testCaseWithBLOBs.isEmpty()) { - // testCaseService.saveImportData(testCaseWithBLOBs, projectId); - //} } catch (Exception ex) { processBuffer.append(Translator.get("incorrect_format")); LogUtil.error(ex.getMessage()); diff --git a/frontend/src/business/App.vue b/frontend/src/business/App.vue index 1fb604f01a..266b73605e 100644 --- a/frontend/src/business/App.vue +++ b/frontend/src/business/App.vue @@ -2,7 +2,7 @@ -
License has expired since +
License has expired since {{(validData!= undefined && validData.license!= undefined) ? validData.license.expired:''}},please update license.
@@ -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: {} From 9e785552cb1f3eb2604de7b0b72d876cb18c3fa9 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 22 Sep 2020 13:00:47 +0800 Subject: [PATCH 2/6] =?UTF-8?q?fix(XPack):=20dto=E5=BC=95=E7=94=A8?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/metersphere/dto/LicenseDTO.java | 1 - .../io/metersphere/dto/LicenseInfoDTO.java | 21 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 backend/src/main/java/io/metersphere/dto/LicenseInfoDTO.java diff --git a/backend/src/main/java/io/metersphere/dto/LicenseDTO.java b/backend/src/main/java/io/metersphere/dto/LicenseDTO.java index 5ed59529aa..245f875979 100644 --- a/backend/src/main/java/io/metersphere/dto/LicenseDTO.java +++ b/backend/src/main/java/io/metersphere/dto/LicenseDTO.java @@ -1,6 +1,5 @@ package io.metersphere.dto; -import io.metersphere.xpack.license.dto.LicenseInfoDTO; import lombok.Data; import java.io.Serializable; diff --git a/backend/src/main/java/io/metersphere/dto/LicenseInfoDTO.java b/backend/src/main/java/io/metersphere/dto/LicenseInfoDTO.java new file mode 100644 index 0000000000..682ebe564e --- /dev/null +++ b/backend/src/main/java/io/metersphere/dto/LicenseInfoDTO.java @@ -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; +} From b65a571a51b8b5dc45016542bb44525d5cd6bbc3 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 22 Sep 2020 13:32:01 +0800 Subject: [PATCH 3/6] =?UTF-8?q?style(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA)?= =?UTF-8?q?:=20=E4=BC=98=E5=8C=96=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/io/metersphere/xmind/XmindCaseParser.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java b/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java index 0cf380bd99..eef17be4a7 100644 --- a/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java +++ b/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java @@ -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; @@ -235,9 +234,7 @@ public class XmindCaseParser { StringBuffer processBuffer = new StringBuffer(); try { // 获取思维导图内容 - String content = XmindParser.parseJson(multipartFile); - 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()) { From fa9aec151f4680dd2964b5c2c4ee8d75df2b198b Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 22 Sep 2020 14:19:36 +0800 Subject: [PATCH 4/6] =?UTF-8?q?style(XPack):=20=E4=BB=A3=E7=A0=81=E5=86=99?= =?UTF-8?q?=E6=B3=95=E8=A7=84=E8=8C=83=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/io/metersphere/service/LicenseService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/io/metersphere/service/LicenseService.java b/backend/src/main/java/io/metersphere/service/LicenseService.java index 8636d4ae0e..25e46b3d18 100644 --- a/backend/src/main/java/io/metersphere/service/LicenseService.java +++ b/backend/src/main/java/io/metersphere/service/LicenseService.java @@ -5,6 +5,6 @@ import io.metersphere.dto.LicenseDTO; public interface LicenseService { public LicenseDTO valid(); - + public LicenseDTO addValidLicense(String reqLicenseCode); } From c46b8dccb6b1e954422872437e5888a55c190e9f Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 22 Sep 2020 14:33:17 +0800 Subject: [PATCH 5/6] =?UTF-8?q?style(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA)?= =?UTF-8?q?:=20=E7=BB=9F=E4=B8=80util=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/metersphere/xmind/XmindCaseParser.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java b/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java index eef17be4a7..99441d8e72 100644 --- a/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java +++ b/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java @@ -12,7 +12,7 @@ import io.metersphere.track.service.TestCaseService; import io.metersphere.xmind.parser.XmindParser; import io.metersphere.xmind.parser.pojo.Attached; import io.metersphere.xmind.parser.pojo.JsonRootBean; -import org.springframework.util.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.web.multipart.MultipartFile; import java.util.*; @@ -21,7 +21,7 @@ import java.util.regex.Pattern; /** * 数据转换 - * 1 解析Xmind文件 XmindParser.parseJson + * 1 解析Xmind文件 XmindParser.parseObject * 2 解析后的JSON this.parse 转成测试用例 */ public class XmindCaseParser { @@ -33,10 +33,10 @@ public class XmindCaseParser { // 已存在用例名称 private Set testCaseNames; - // 案例详情重写了hashCode方法去重用 + // 转换后的案例信息 private List testCases; - // 用于重复对比 + // 案例详情重写了hashCode方法去重用 private List compartDatas; public XmindCaseParser(TestCaseService testCaseService, String userId, String projectId, Set testCaseNames) { @@ -194,21 +194,21 @@ public class XmindCaseParser { String nodePath = data.getNodePath(); StringBuilder stringBuilder = new StringBuilder(); - if (nodePath != null) { + if (!StringUtils.isEmpty(nodePath)) { String[] nodes = nodePath.split("/"); 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") + "; "); } for (int i = 0; i < nodes.length; i++) { - if (i != 0 && org.apache.commons.lang3.StringUtils.equals(nodes[i].trim(), "")) { + if (i != 0 && StringUtils.equals(nodes[i].trim(), "")) { stringBuilder.append(Translator.get("module_not_null") + "; "); break; } } } - if (org.apache.commons.lang3.StringUtils.equals(data.getType(), TestCaseConstants.Type.Functional.getValue()) && org.apache.commons.lang3.StringUtils.equals(data.getMethod(), TestCaseConstants.Method.Auto.getValue())) { + if (StringUtils.equals(data.getType(), TestCaseConstants.Type.Functional.getValue()) && StringUtils.equals(data.getMethod(), TestCaseConstants.Method.Auto.getValue())) { stringBuilder.append(Translator.get("functional_method_tip") + "; "); } From a88f81de2e31ffb2a6168832cae46228582516dc Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Tue, 22 Sep 2020 14:35:25 +0800 Subject: [PATCH 6/6] =?UTF-8?q?fix(=E7=94=A8=E4=BE=8B=E8=AF=84=E5=AE=A1):?= =?UTF-8?q?=20=E5=88=A0=E9=99=A4=E8=AF=84=E5=AE=A1=E6=97=B6=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=85=B3=E8=81=94=E7=9A=84=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/track/service/TestCaseReviewService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java index 2587823c4b..5abe6b7e34 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java @@ -226,6 +226,7 @@ public class TestCaseReviewService { public void deleteCaseReview(String reviewId) { deleteCaseReviewProject(reviewId); deleteCaseReviewUsers(reviewId); + deleteCaseReviewTestCase(reviewId); testCaseReviewMapper.deleteByPrimaryKey(reviewId); } @@ -241,6 +242,12 @@ public class TestCaseReviewService { testCaseReviewUsersMapper.deleteByExample(testCaseReviewUsersExample); } + private void deleteCaseReviewTestCase(String reviewId) { + TestCaseReviewTestCaseExample testCaseReviewTestCaseExample = new TestCaseReviewTestCaseExample(); + testCaseReviewTestCaseExample.createCriteria().andReviewIdEqualTo(reviewId); + testCaseReviewTestCaseMapper.deleteByExample(testCaseReviewTestCaseExample); + } + public List listCaseReviewAll(String currentWorkspaceId) { ProjectExample projectExample = new ProjectExample(); projectExample.createCriteria().andWorkspaceIdEqualTo(currentWorkspaceId); @@ -384,7 +391,7 @@ public class TestCaseReviewService { } return name; } - + public List listTestCaseByProjectIds(List projectIds) { QueryCaseReviewRequest request = new QueryCaseReviewRequest(); request.setProjectIds(projectIds);