chore: 部分警告代码微调

This commit is contained in:
fit2-zhao 2024-07-03 13:57:07 +08:00 committed by Craftsman
parent eefadfe59b
commit 43b19e4f03
6 changed files with 491 additions and 489 deletions

View File

@ -133,7 +133,7 @@ public class ApiCommonService {
linkFile.setDelete(true); linkFile.setDelete(true);
List<FileAssociation> fileAssociations = fileAssociationService.getByFileIdAndSourceId(resourceId, linkFile.getFileId()); List<FileAssociation> fileAssociations = fileAssociationService.getByFileIdAndSourceId(resourceId, linkFile.getFileId());
if (CollectionUtils.isNotEmpty(fileAssociations)) { if (CollectionUtils.isNotEmpty(fileAssociations)) {
linkFile.setFileAlias(fileAssociations.get(0).getDeletedFileName()); linkFile.setFileAlias(fileAssociations.getFirst().getDeletedFileName());
} }
} else { } else {
String fileName = fileMetadata.getName(); String fileName = fileMetadata.getName();
@ -221,7 +221,7 @@ public class ApiCommonService {
*/ */
public void setScriptElementEnableCommonScriptInfo(List<MsScriptElement> msScriptElements) { public void setScriptElementEnableCommonScriptInfo(List<MsScriptElement> msScriptElements) {
List<CommonScriptInfo> commonScriptInfos = msScriptElements.stream() List<CommonScriptInfo> commonScriptInfos = msScriptElements.stream()
.filter(msScriptElement -> BooleanUtils.isTrue(msScriptElement.getEnableCommonScript()) && msScriptElement.getEnableCommonScript() != null) .filter(msScriptElement -> BooleanUtils.isTrue(msScriptElement.getEnableCommonScript()))
.map(MsScriptElement::getCommonScriptInfo) .map(MsScriptElement::getCommonScriptInfo)
.toList(); .toList();
@ -277,12 +277,9 @@ public class ApiCommonService {
List<KeyValueParam> commonParams = JSON.parseArray(new String(paramsBlob), KeyValueParam.class); List<KeyValueParam> commonParams = JSON.parseArray(new String(paramsBlob), KeyValueParam.class);
// 替换用户输入值 // 替换用户输入值
commonParams.forEach(commonParam -> commonParams.forEach(commonParam ->
Optional.ofNullable(commonScriptInfo.getParams()).ifPresent(params -> Optional.ofNullable(commonScriptInfo.getParams()).flatMap(params -> params.stream()
params.stream()
.filter(param -> StringUtils.equals(commonParam.getKey(), param.getKey())) .filter(param -> StringUtils.equals(commonParam.getKey(), param.getKey()))
.findFirst() .findFirst()).ifPresent(param -> commonParam.setValue(param.getValue()))
.ifPresent(param -> commonParam.setValue(param.getValue()))
)
); );
commonScriptInfo.setParams(commonParams); commonScriptInfo.setParams(commonParams);
}); });
@ -311,13 +308,12 @@ public class ApiCommonService {
} }
// 获取使用公共脚本的前后置 // 获取使用公共脚本的前后置
List<ScriptProcessor> scriptsProcessors = processors.stream() return processors.stream()
.filter(processor -> processor instanceof ScriptProcessor) .filter(processor -> processor instanceof ScriptProcessor)
.map(processor -> (ScriptProcessor) processor) .map(processor -> (ScriptProcessor) processor)
.filter(ScriptProcessor::isEnableCommonScript) .filter(ScriptProcessor::isEnableCommonScript)
.filter(ScriptProcessor::isValid) .filter(ScriptProcessor::isValid)
.collect(Collectors.toList()); .collect(Collectors.toList());
return scriptsProcessors;
} }
/** /**
@ -364,10 +360,9 @@ public class ApiCommonService {
* @return * @return
*/ */
public Map<String, ApiDefinitionExecuteInfo> getApiDefinitionExecuteInfoMap(Function<List<String>, List<ApiDefinitionExecuteInfo>> getDefinitionInfoFunc, List<String> resourceIds) { public Map<String, ApiDefinitionExecuteInfo> getApiDefinitionExecuteInfoMap(Function<List<String>, List<ApiDefinitionExecuteInfo>> getDefinitionInfoFunc, List<String> resourceIds) {
Map<String, ApiDefinitionExecuteInfo> resourceModuleMap = getDefinitionInfoFunc.apply(resourceIds) return getDefinitionInfoFunc.apply(resourceIds)
.stream() .stream()
.collect(Collectors.toMap(ApiDefinitionExecuteInfo::getResourceId, Function.identity())); .collect(Collectors.toMap(ApiDefinitionExecuteInfo::getResourceId, Function.identity()));
return resourceModuleMap;
} }
/** /**

View File

@ -158,12 +158,9 @@ public class ApiEnvironmentService {
} }
private boolean isBlankLine(JsonNode lastNode) { private boolean isBlankLine(JsonNode lastNode) {
boolean nameBlank = lastNode.get(NAME) == null ? true : StringUtils.isBlank(lastNode.get(NAME).asText()); boolean nameBlank = lastNode.get(NAME) == null || StringUtils.isBlank(lastNode.get(NAME).asText());
boolean valueBlank = lastNode.get(VALUE) == null ? true : StringUtils.isBlank(lastNode.get(VALUE).asText()); boolean valueBlank = lastNode.get(VALUE) == null || StringUtils.isBlank(lastNode.get(VALUE).asText());
if (nameBlank && valueBlank) { return nameBlank && valueBlank;
return true;
}
return false;
} }
private List<JsonNode> createArray(Map<String, String> varMap) { private List<JsonNode> createArray(Map<String, String> varMap) {

View File

@ -230,7 +230,7 @@ public class ApiExecuteService {
} catch (HttpServerErrorException e) { } catch (HttpServerErrorException e) {
LogUtils.error(e); LogUtils.error(e);
int errorCode = e.getResponseBodyAs(ResultHolder.class).getCode(); int errorCode = Objects.requireNonNull(e.getResponseBodyAs(ResultHolder.class)).getCode();
for (TaskRunnerResultCode taskRunnerResultCode : TaskRunnerResultCode.values()) { for (TaskRunnerResultCode taskRunnerResultCode : TaskRunnerResultCode.values()) {
// 匹配资源池的错误代码抛出相应异常 // 匹配资源池的错误代码抛出相应异常
if (taskRunnerResultCode.getCode() == errorCode) { if (taskRunnerResultCode.getCode() == errorCode) {
@ -433,7 +433,7 @@ public class ApiExecuteService {
if (CollectionUtils.isEmpty(taskInfo.getProjectResource().getFuncJars())) { if (CollectionUtils.isEmpty(taskInfo.getProjectResource().getFuncJars())) {
ApiExecuteFileInfo tempFileInfo = new ApiExecuteFileInfo(); ApiExecuteFileInfo tempFileInfo = new ApiExecuteFileInfo();
tempFileInfo.setProjectId(taskInfo.getProjectId()); tempFileInfo.setProjectId(taskInfo.getProjectId());
CopyOnWriteArrayList copyOnWriteArrayList = new CopyOnWriteArrayList(); CopyOnWriteArrayList<ApiExecuteFileInfo> copyOnWriteArrayList = new CopyOnWriteArrayList<>();
copyOnWriteArrayList.add(tempFileInfo); copyOnWriteArrayList.add(tempFileInfo);
taskInfo.getProjectResource().setFuncJars(copyOnWriteArrayList); taskInfo.getProjectResource().setFuncJars(copyOnWriteArrayList);
} }
@ -492,7 +492,7 @@ public class ApiExecuteService {
// 查询包括资源所需的文件 // 查询包括资源所需的文件
Set<String> resourceIdsSet = runRequest.getFileResourceIds(); Set<String> resourceIdsSet = runRequest.getFileResourceIds();
resourceIdsSet.add(resourceId); resourceIdsSet.add(resourceId);
List<String> resourceIds = resourceIdsSet.stream().collect(Collectors.toList()); List<String> resourceIds = new ArrayList<>(resourceIdsSet);
SubListUtils.dealForSubList(resourceIds, 50, subResourceIds -> { SubListUtils.dealForSubList(resourceIds, 50, subResourceIds -> {
// 查询通过本地上传的文件 // 查询通过本地上传的文件
List<ApiExecuteFileInfo> localFiles = apiFileResourceService.getByResourceIds(subResourceIds). List<ApiExecuteFileInfo> localFiles = apiFileResourceService.getByResourceIds(subResourceIds).

View File

@ -11,6 +11,8 @@ import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.sdk.util.FileAssociationSourceUtil; import io.metersphere.sdk.util.FileAssociationSourceUtil;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Objects;
/** /**
* @Author: jianxing * @Author: jianxing
* @CreateTime: 2024-02-06 20:48 * @CreateTime: 2024-02-06 20:48
@ -29,13 +31,17 @@ public class ApiFileAssociationUpdateService implements FileAssociationUpdateSer
String sourceType = originFileAssociation.getSourceType(); String sourceType = originFileAssociation.getSourceType();
switch (sourceType) { switch (sourceType) {
case FileAssociationSourceUtil.SOURCE_TYPE_API_DEBUG -> case FileAssociationSourceUtil.SOURCE_TYPE_API_DEBUG ->
CommonBeanFactory.getBean(ApiDebugService.class).handleFileAssociationUpgrade(originFileAssociation, newFileMetadata); Objects.requireNonNull(CommonBeanFactory.getBean(ApiDebugService.class))
.handleFileAssociationUpgrade(originFileAssociation, newFileMetadata);
case FileAssociationSourceUtil.SOURCE_TYPE_API_DEFINITION -> case FileAssociationSourceUtil.SOURCE_TYPE_API_DEFINITION ->
CommonBeanFactory.getBean(ApiDefinitionService.class).handleFileAssociationUpgrade(originFileAssociation, newFileMetadata); Objects.requireNonNull(CommonBeanFactory.getBean(ApiDefinitionService.class))
.handleFileAssociationUpgrade(originFileAssociation, newFileMetadata);
case FileAssociationSourceUtil.SOURCE_TYPE_API_TEST_CASE -> case FileAssociationSourceUtil.SOURCE_TYPE_API_TEST_CASE ->
CommonBeanFactory.getBean(ApiTestCaseService.class).handleFileAssociationUpgrade(originFileAssociation, newFileMetadata); Objects.requireNonNull(CommonBeanFactory.getBean(ApiTestCaseService.class))
.handleFileAssociationUpgrade(originFileAssociation, newFileMetadata);
case FileAssociationSourceUtil.SOURCE_TYPE_API_SCENARIO_STEP -> case FileAssociationSourceUtil.SOURCE_TYPE_API_SCENARIO_STEP ->
CommonBeanFactory.getBean(ApiScenarioService.class).handleStepFileAssociationUpgrade(originFileAssociation, newFileMetadata); Objects.requireNonNull(CommonBeanFactory.getBean(ApiScenarioService.class))
.handleStepFileAssociationUpgrade(originFileAssociation, newFileMetadata);
default -> { default -> {
} }
} }

View File

@ -9,21 +9,18 @@ import io.metersphere.api.service.definition.ApiDefinitionScheduleService;
import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.system.schedule.BaseScheduleJob; import io.metersphere.system.schedule.BaseScheduleJob;
import io.metersphere.system.service.SimpleUserService;
import org.quartz.JobDataMap; import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionContext;
import org.quartz.JobKey; import org.quartz.JobKey;
import org.quartz.TriggerKey; import org.quartz.TriggerKey;
public class SwaggerUrlImportJob extends BaseScheduleJob { public class SwaggerUrlImportJob extends BaseScheduleJob {
private ApiDefinitionImportService apiDefinitionImportService; private final ApiDefinitionImportService apiDefinitionImportService;
private ApiDefinitionScheduleService apiDefinitionScheduleService; private final ApiDefinitionScheduleService apiDefinitionScheduleService;
private SimpleUserService simpleUserService;
public SwaggerUrlImportJob() { public SwaggerUrlImportJob() {
apiDefinitionImportService = CommonBeanFactory.getBean(ApiDefinitionImportService.class); apiDefinitionImportService = CommonBeanFactory.getBean(ApiDefinitionImportService.class);
apiDefinitionScheduleService = CommonBeanFactory.getBean(ApiDefinitionScheduleService.class); apiDefinitionScheduleService = CommonBeanFactory.getBean(ApiDefinitionScheduleService.class);
simpleUserService = CommonBeanFactory.getBean(SimpleUserService.class);
} }
@Override @Override

View File

@ -223,7 +223,7 @@ public class TestPlanReportService {
* @param currentUser 当前用户 * @param currentUser 当前用户
*/ */
public void genReportByManual(TestPlanReportGenRequest request, String currentUser) { public void genReportByManual(TestPlanReportGenRequest request, String currentUser) {
genReport(IDGenerator.nextStr(),request, true, currentUser, "/test-plan/report/gen"); genReport(IDGenerator.nextStr(), request, true, currentUser, "/test-plan/report/gen");
} }
/** /**
@ -234,11 +234,11 @@ public class TestPlanReportService {
* @param currentUser 当前用户 * @param currentUser 当前用户
*/ */
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
public Map<String, String> genReportByExecution(String prepareReportId,TestPlanReportGenRequest request, String currentUser) { public Map<String, String> genReportByExecution(String prepareReportId, TestPlanReportGenRequest request, String currentUser) {
return genReport(prepareReportId,request, false, currentUser, "/test-plan/report/gen"); return genReport(prepareReportId, request, false, currentUser, "/test-plan/report/gen");
} }
public Map<String, String> genReport(String prepareReportId,TestPlanReportGenRequest request, boolean manual, String currentUser, String logPath) { public Map<String, String> genReport(String prepareReportId, TestPlanReportGenRequest request, boolean manual, String currentUser, String logPath) {
Map<String, String> preReportMap = new HashMap<>(); Map<String, String> preReportMap = new HashMap<>();
try { try {
// 所有计划 // 所有计划
@ -292,6 +292,7 @@ public class TestPlanReportService {
/** /**
* 预生成报告内容(汇总前调用) * 预生成报告内容(汇总前调用)
*
* @return 报告 * @return 报告
*/ */
public TestPlanReport preGenReport(String prepareId, TestPlanReportGenPreParam genParam, String currentUser, String logPath, TestPlanReportModuleParam moduleParam, List<String> childPlanIds) { public TestPlanReport preGenReport(String prepareId, TestPlanReportGenPreParam genParam, String currentUser, String logPath, TestPlanReportModuleParam moduleParam, List<String> childPlanIds) {
@ -341,6 +342,7 @@ public class TestPlanReportService {
/** /**
* 生成独立报告的关联数据 * 生成独立报告的关联数据
*
* @param genParam 报告生成的参数 * @param genParam 报告生成的参数
* @param moduleParam 模块参数 * @param moduleParam 模块参数
* @param report 报告 * @param report 报告
@ -470,7 +472,7 @@ public class TestPlanReportService {
*/ */
TestPlanReportSummaryExample example = new TestPlanReportSummaryExample(); TestPlanReportSummaryExample example = new TestPlanReportSummaryExample();
example.createCriteria().andTestPlanReportIdEqualTo(postParam.getReportId()); example.createCriteria().andTestPlanReportIdEqualTo(postParam.getReportId());
TestPlanReportSummary reportSummary = testPlanReportSummaryMapper.selectByExampleWithBLOBs(example).get(0); TestPlanReportSummary reportSummary = testPlanReportSummaryMapper.selectByExampleWithBLOBs(example).getFirst();
// 用例总数 // 用例总数
long caseTotal = reportSummary.getFunctionalCaseCount() + reportSummary.getApiCaseCount() + reportSummary.getApiScenarioCount(); long caseTotal = reportSummary.getFunctionalCaseCount() + reportSummary.getApiCaseCount() + reportSummary.getApiScenarioCount();
CaseCount summaryCount = JSON.parseObject(new String(reportSummary.getExecuteResult()), CaseCount.class); CaseCount summaryCount = JSON.parseObject(new String(reportSummary.getExecuteResult()), CaseCount.class);
@ -496,6 +498,7 @@ public class TestPlanReportService {
/** /**
* 获取报告 * 获取报告
*
* @param reportId 报告ID * @param reportId 报告ID
* @return 报告详情 * @return 报告详情
*/ */
@ -517,7 +520,7 @@ public class TestPlanReportService {
if (CollectionUtils.isEmpty(testPlanReportSummaries)) { if (CollectionUtils.isEmpty(testPlanReportSummaries)) {
throw new MSException(Translator.get("test_plan_report_detail_not_exist")); throw new MSException(Translator.get("test_plan_report_detail_not_exist"));
} }
TestPlanReportSummary reportSummary = testPlanReportSummaries.get(0); TestPlanReportSummary reportSummary = testPlanReportSummaries.getFirst();
TestPlanReportDetailResponse planReportDetail = new TestPlanReportDetailResponse(); TestPlanReportDetailResponse planReportDetail = new TestPlanReportDetailResponse();
BeanUtils.copyBean(planReportDetail, planReport); BeanUtils.copyBean(planReportDetail, planReport);
int caseTotal = (int) (reportSummary.getFunctionalCaseCount() + reportSummary.getApiCaseCount() + reportSummary.getApiScenarioCount()); int caseTotal = (int) (reportSummary.getFunctionalCaseCount() + reportSummary.getApiCaseCount() + reportSummary.getApiScenarioCount());
@ -577,6 +580,7 @@ public class TestPlanReportService {
/** /**
* 分页查询报告详情-用例分页数据 * 分页查询报告详情-用例分页数据
*
* @param request 请求参数 * @param request 请求参数
* @return 用例分页数据 * @return 用例分页数据
*/ */
@ -625,7 +629,7 @@ public class TestPlanReportService {
.fakeError(functionalCaseCount.getFakeError() + apiCaseCount.getFakeError() + scenarioCaseCount.getFakeError()).build(); .fakeError(functionalCaseCount.getFakeError() + apiCaseCount.getFakeError() + scenarioCaseCount.getFakeError()).build();
// 入库汇总数据 => 报告详情表 // 入库汇总数据 => 报告详情表
TestPlanReportSummary reportSummary = testPlanReportSummaries.get(0); TestPlanReportSummary reportSummary = testPlanReportSummaries.getFirst();
reportSummary.setFunctionalExecuteResult(JSON.toJSONBytes(functionalCaseCount)); reportSummary.setFunctionalExecuteResult(JSON.toJSONBytes(functionalCaseCount));
reportSummary.setApiExecuteResult(JSON.toJSONBytes(apiCaseCount)); reportSummary.setApiExecuteResult(JSON.toJSONBytes(apiCaseCount));
reportSummary.setScenarioExecuteResult(JSON.toJSONBytes(scenarioCaseCount)); reportSummary.setScenarioExecuteResult(JSON.toJSONBytes(scenarioCaseCount));
@ -635,6 +639,7 @@ public class TestPlanReportService {
/** /**
* 汇总生成的计划组报告 * 汇总生成的计划组报告
*
* @param reportId 报告ID * @param reportId 报告ID
*/ */
public void summaryGroupReport(String reportId) { public void summaryGroupReport(String reportId) {
@ -645,12 +650,12 @@ public class TestPlanReportService {
// 报告详情不存在 // 报告详情不存在
return; return;
} }
TestPlanReportSummary groupSummary = testPlanReportSummaries.get(0); TestPlanReportSummary groupSummary = testPlanReportSummaries.getFirst();
TestPlanReportExample example = new TestPlanReportExample(); TestPlanReportExample example = new TestPlanReportExample();
example.createCriteria().andParentIdEqualTo(reportId).andIntegratedEqualTo(false); example.createCriteria().andParentIdEqualTo(reportId).andIntegratedEqualTo(false);
List<TestPlanReport> testPlanReports = testPlanReportMapper.selectByExample(example); List<TestPlanReport> testPlanReports = testPlanReportMapper.selectByExample(example);
if(CollectionUtils.isEmpty(testPlanReports)){ if (CollectionUtils.isEmpty(testPlanReports)) {
// 不存在子报告, 不需要汇总数据 // 不存在子报告, 不需要汇总数据
return; return;
} }
@ -859,7 +864,7 @@ public class TestPlanReportService {
if (CollectionUtils.isEmpty(folderFileNames)) { if (CollectionUtils.isEmpty(folderFileNames)) {
return null; return null;
} }
String[] pathSplit = folderFileNames.get(0).split("/"); String[] pathSplit = folderFileNames.getFirst().split("/");
return pathSplit[pathSplit.length - 1]; return pathSplit[pathSplit.length - 1];
} catch (Exception e) { } catch (Exception e) {
LogUtils.error(e); LogUtils.error(e);
@ -903,6 +908,7 @@ public class TestPlanReportService {
/** /**
* 构建预生成报告的参数 * 构建预生成报告的参数
*
* @param genRequest 报告请求参数 * @param genRequest 报告请求参数
* @return 预生成报告参数 * @return 预生成报告参数
*/ */
@ -1008,7 +1014,7 @@ public class TestPlanReportService {
bytes = getPreviewImg(fileName, fileId, compressed); bytes = getPreviewImg(fileName, fileId, compressed);
} else { } else {
//在正式目录获取 //在正式目录获取
TestPlanReportAttachment attachment = reportAttachments.get(0); TestPlanReportAttachment attachment = reportAttachments.getFirst();
fileName = attachment.getFileName(); fileName = attachment.getFileName();
FileRequest fileRequest = buildPlanFileRequest(projectId, attachment.getTestPlanReportId(), attachment.getFileId(), attachment.getFileName()); FileRequest fileRequest = buildPlanFileRequest(projectId, attachment.getTestPlanReportId(), attachment.getFileId(), attachment.getFileName());
try { try {
@ -1029,6 +1035,7 @@ public class TestPlanReportService {
/** /**
* 构建计划报告文件请求 * 构建计划报告文件请求
*
* @param projectId 项目ID * @param projectId 项目ID
* @param resourceId 资源ID * @param resourceId 资源ID
* @param fileId 文件ID * @param fileId 文件ID