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); } }