From ef78a7eb16a1f74a71c1904ad01f6ab73467b0f7 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Mon, 3 Jan 2022 15:56:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=AF=AF=E6=8A=A5=E5=BA=93):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=BC=80=E5=8E=9F=E7=89=88=E6=9C=AC=E8=AF=AF=E5=BC=95?= =?UTF-8?q?=E7=94=A8xpack=E8=AF=AF=E6=8A=A5=E5=BA=93=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复开原版本误引用xpack误报库代码的问题 --- .../service/ExtErrorReportLibraryService.java | 48 +++++++++++++++++++ .../commons/utils/HashTreeUtil.java | 6 +-- 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/api/service/ExtErrorReportLibraryService.java diff --git a/backend/src/main/java/io/metersphere/api/service/ExtErrorReportLibraryService.java b/backend/src/main/java/io/metersphere/api/service/ExtErrorReportLibraryService.java new file mode 100644 index 0000000000..06a641258e --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/service/ExtErrorReportLibraryService.java @@ -0,0 +1,48 @@ +package io.metersphere.api.service; + +import com.alibaba.fastjson.JSONObject; +import io.metersphere.api.dto.definition.request.assertions.MsAssertions; +import io.metersphere.base.domain.ErrorReportLibraryExample; +import io.metersphere.base.domain.ErrorReportLibraryWithBLOBs; +import io.metersphere.base.mapper.ErrorReportLibraryMapper; +import io.metersphere.commons.utils.LogUtil; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * @author song.tianyang + * @Date 2022/1/3 3:51 下午 + */ +@Service +@Transactional(rollbackFor = Exception.class) +public class ExtErrorReportLibraryService { + @Resource + private ErrorReportLibraryMapper errorReportLibraryMapper; + + public List getAssertionByProjectIdAndStatusIsOpen(String projectId) { + List returnList = new ArrayList<>(); + ErrorReportLibraryExample example = new ErrorReportLibraryExample(); + example.createCriteria().andProjectIdEqualTo(projectId).andStatusEqualTo(true); + List bloBs = errorReportLibraryMapper.selectByExampleWithBLOBs(example); + bloBs.forEach(item -> { + if (StringUtils.isNotEmpty(item.getContent())) { + try { + MsAssertions assertions = JSONObject.parseObject(item.getContent(), MsAssertions.class); + if (assertions != null && CollectionUtils.isNotEmpty(assertions.getRegex())) { + assertions.getRegex().get(0).setDescription("Error report:" + item.getErrorCode()); + returnList.add(assertions); + } + } catch (Exception e) { + LogUtil.error(e); + } + } + }); + return returnList; + } +} diff --git a/backend/src/main/java/io/metersphere/commons/utils/HashTreeUtil.java b/backend/src/main/java/io/metersphere/commons/utils/HashTreeUtil.java index 37ced4cc09..a4ab0deed9 100644 --- a/backend/src/main/java/io/metersphere/commons/utils/HashTreeUtil.java +++ b/backend/src/main/java/io/metersphere/commons/utils/HashTreeUtil.java @@ -6,8 +6,8 @@ import io.metersphere.api.dto.RunningParamKeys; import io.metersphere.api.dto.definition.request.assertions.MsAssertionRegex; import io.metersphere.api.dto.definition.request.assertions.MsAssertions; import io.metersphere.api.service.ApiTestEnvironmentService; +import io.metersphere.api.service.ExtErrorReportLibraryService; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; -import io.metersphere.xpack.errorreportlibrary.service.ErrorReportLibraryService; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.config.Argument; @@ -224,7 +224,7 @@ public class HashTreeUtil { break; } } - if(!isExit){ + if (!isExit) { duplicatedList.add(regex); } } @@ -234,7 +234,7 @@ public class HashTreeUtil { } public static List getErrorReportByProjectId(String projectId) { - ErrorReportLibraryService service = CommonBeanFactory.getBean(ErrorReportLibraryService.class); + ExtErrorReportLibraryService service = CommonBeanFactory.getBean(ExtErrorReportLibraryService.class); return service.getAssertionByProjectIdAndStatusIsOpen(projectId); } }