fix(误报库): 修复开原版本误引用xpack误报库代码的问题

修复开原版本误引用xpack误报库代码的问题
This commit is contained in:
song-tianyang 2022-01-03 15:56:56 +08:00 committed by 刘瑞斌
parent 9685d988d0
commit 4a63c924a7
2 changed files with 51 additions and 3 deletions

View File

@ -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<MsAssertions> getAssertionByProjectIdAndStatusIsOpen(String projectId) {
List<MsAssertions> returnList = new ArrayList<>();
ErrorReportLibraryExample example = new ErrorReportLibraryExample();
example.createCriteria().andProjectIdEqualTo(projectId).andStatusEqualTo(true);
List<ErrorReportLibraryWithBLOBs> 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;
}
}

View File

@ -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.MsAssertionRegex;
import io.metersphere.api.dto.definition.request.assertions.MsAssertions; import io.metersphere.api.dto.definition.request.assertions.MsAssertions;
import io.metersphere.api.service.ApiTestEnvironmentService; import io.metersphere.api.service.ApiTestEnvironmentService;
import io.metersphere.api.service.ExtErrorReportLibraryService;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.xpack.errorreportlibrary.service.ErrorReportLibraryService;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.Argument; import org.apache.jmeter.config.Argument;
@ -224,7 +224,7 @@ public class HashTreeUtil {
break; break;
} }
} }
if(!isExit){ if (!isExit) {
duplicatedList.add(regex); duplicatedList.add(regex);
} }
} }
@ -234,7 +234,7 @@ public class HashTreeUtil {
} }
public static List<MsAssertions> getErrorReportByProjectId(String projectId) { public static List<MsAssertions> getErrorReportByProjectId(String projectId) {
ErrorReportLibraryService service = CommonBeanFactory.getBean(ErrorReportLibraryService.class); ExtErrorReportLibraryService service = CommonBeanFactory.getBean(ExtErrorReportLibraryService.class);
return service.getAssertionByProjectIdAndStatusIsOpen(projectId); return service.getAssertionByProjectIdAndStatusIsOpen(projectId);
} }
} }