chore: 部分警告代码微调
This commit is contained in:
parent
eefadfe59b
commit
43b19e4f03
|
@ -133,7 +133,7 @@ public class ApiCommonService {
|
|||
linkFile.setDelete(true);
|
||||
List<FileAssociation> fileAssociations = fileAssociationService.getByFileIdAndSourceId(resourceId, linkFile.getFileId());
|
||||
if (CollectionUtils.isNotEmpty(fileAssociations)) {
|
||||
linkFile.setFileAlias(fileAssociations.get(0).getDeletedFileName());
|
||||
linkFile.setFileAlias(fileAssociations.getFirst().getDeletedFileName());
|
||||
}
|
||||
} else {
|
||||
String fileName = fileMetadata.getName();
|
||||
|
@ -221,7 +221,7 @@ public class ApiCommonService {
|
|||
*/
|
||||
public void setScriptElementEnableCommonScriptInfo(List<MsScriptElement> msScriptElements) {
|
||||
List<CommonScriptInfo> commonScriptInfos = msScriptElements.stream()
|
||||
.filter(msScriptElement -> BooleanUtils.isTrue(msScriptElement.getEnableCommonScript()) && msScriptElement.getEnableCommonScript() != null)
|
||||
.filter(msScriptElement -> BooleanUtils.isTrue(msScriptElement.getEnableCommonScript()))
|
||||
.map(MsScriptElement::getCommonScriptInfo)
|
||||
.toList();
|
||||
|
||||
|
@ -277,12 +277,9 @@ public class ApiCommonService {
|
|||
List<KeyValueParam> commonParams = JSON.parseArray(new String(paramsBlob), KeyValueParam.class);
|
||||
// 替换用户输入值
|
||||
commonParams.forEach(commonParam ->
|
||||
Optional.ofNullable(commonScriptInfo.getParams()).ifPresent(params ->
|
||||
params.stream()
|
||||
Optional.ofNullable(commonScriptInfo.getParams()).flatMap(params -> params.stream()
|
||||
.filter(param -> StringUtils.equals(commonParam.getKey(), param.getKey()))
|
||||
.findFirst()
|
||||
.ifPresent(param -> commonParam.setValue(param.getValue()))
|
||||
)
|
||||
.findFirst()).ifPresent(param -> commonParam.setValue(param.getValue()))
|
||||
);
|
||||
commonScriptInfo.setParams(commonParams);
|
||||
});
|
||||
|
@ -311,13 +308,12 @@ public class ApiCommonService {
|
|||
}
|
||||
|
||||
// 获取使用公共脚本的前后置
|
||||
List<ScriptProcessor> scriptsProcessors = processors.stream()
|
||||
return processors.stream()
|
||||
.filter(processor -> processor instanceof ScriptProcessor)
|
||||
.map(processor -> (ScriptProcessor) processor)
|
||||
.filter(ScriptProcessor::isEnableCommonScript)
|
||||
.filter(ScriptProcessor::isValid)
|
||||
.collect(Collectors.toList());
|
||||
return scriptsProcessors;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -364,10 +360,9 @@ public class ApiCommonService {
|
|||
* @return
|
||||
*/
|
||||
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()
|
||||
.collect(Collectors.toMap(ApiDefinitionExecuteInfo::getResourceId, Function.identity()));
|
||||
return resourceModuleMap;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -158,12 +158,9 @@ public class ApiEnvironmentService {
|
|||
}
|
||||
|
||||
private boolean isBlankLine(JsonNode lastNode) {
|
||||
boolean nameBlank = lastNode.get(NAME) == null ? true : StringUtils.isBlank(lastNode.get(NAME).asText());
|
||||
boolean valueBlank = lastNode.get(VALUE) == null ? true : StringUtils.isBlank(lastNode.get(VALUE).asText());
|
||||
if (nameBlank && valueBlank) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
boolean nameBlank = lastNode.get(NAME) == null || StringUtils.isBlank(lastNode.get(NAME).asText());
|
||||
boolean valueBlank = lastNode.get(VALUE) == null || StringUtils.isBlank(lastNode.get(VALUE).asText());
|
||||
return nameBlank && valueBlank;
|
||||
}
|
||||
|
||||
private List<JsonNode> createArray(Map<String, String> varMap) {
|
||||
|
|
|
@ -230,7 +230,7 @@ public class ApiExecuteService {
|
|||
|
||||
} catch (HttpServerErrorException 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()) {
|
||||
// 匹配资源池的错误代码,抛出相应异常
|
||||
if (taskRunnerResultCode.getCode() == errorCode) {
|
||||
|
@ -433,7 +433,7 @@ public class ApiExecuteService {
|
|||
if (CollectionUtils.isEmpty(taskInfo.getProjectResource().getFuncJars())) {
|
||||
ApiExecuteFileInfo tempFileInfo = new ApiExecuteFileInfo();
|
||||
tempFileInfo.setProjectId(taskInfo.getProjectId());
|
||||
CopyOnWriteArrayList copyOnWriteArrayList = new CopyOnWriteArrayList();
|
||||
CopyOnWriteArrayList<ApiExecuteFileInfo> copyOnWriteArrayList = new CopyOnWriteArrayList<>();
|
||||
copyOnWriteArrayList.add(tempFileInfo);
|
||||
taskInfo.getProjectResource().setFuncJars(copyOnWriteArrayList);
|
||||
}
|
||||
|
@ -492,7 +492,7 @@ public class ApiExecuteService {
|
|||
// 查询包括资源所需的文件
|
||||
Set<String> resourceIdsSet = runRequest.getFileResourceIds();
|
||||
resourceIdsSet.add(resourceId);
|
||||
List<String> resourceIds = resourceIdsSet.stream().collect(Collectors.toList());
|
||||
List<String> resourceIds = new ArrayList<>(resourceIdsSet);
|
||||
SubListUtils.dealForSubList(resourceIds, 50, subResourceIds -> {
|
||||
// 查询通过本地上传的文件
|
||||
List<ApiExecuteFileInfo> localFiles = apiFileResourceService.getByResourceIds(subResourceIds).
|
||||
|
|
|
@ -11,6 +11,8 @@ import io.metersphere.sdk.util.CommonBeanFactory;
|
|||
import io.metersphere.sdk.util.FileAssociationSourceUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Author: jianxing
|
||||
* @CreateTime: 2024-02-06 20:48
|
||||
|
@ -29,13 +31,17 @@ public class ApiFileAssociationUpdateService implements FileAssociationUpdateSer
|
|||
String sourceType = originFileAssociation.getSourceType();
|
||||
switch (sourceType) {
|
||||
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 ->
|
||||
CommonBeanFactory.getBean(ApiDefinitionService.class).handleFileAssociationUpgrade(originFileAssociation, newFileMetadata);
|
||||
Objects.requireNonNull(CommonBeanFactory.getBean(ApiDefinitionService.class))
|
||||
.handleFileAssociationUpgrade(originFileAssociation, newFileMetadata);
|
||||
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 ->
|
||||
CommonBeanFactory.getBean(ApiScenarioService.class).handleStepFileAssociationUpgrade(originFileAssociation, newFileMetadata);
|
||||
Objects.requireNonNull(CommonBeanFactory.getBean(ApiScenarioService.class))
|
||||
.handleStepFileAssociationUpgrade(originFileAssociation, newFileMetadata);
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,21 +9,18 @@ import io.metersphere.api.service.definition.ApiDefinitionScheduleService;
|
|||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||
import io.metersphere.system.schedule.BaseScheduleJob;
|
||||
import io.metersphere.system.service.SimpleUserService;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobKey;
|
||||
import org.quartz.TriggerKey;
|
||||
|
||||
public class SwaggerUrlImportJob extends BaseScheduleJob {
|
||||
private ApiDefinitionImportService apiDefinitionImportService;
|
||||
private ApiDefinitionScheduleService apiDefinitionScheduleService;
|
||||
private SimpleUserService simpleUserService;
|
||||
private final ApiDefinitionImportService apiDefinitionImportService;
|
||||
private final ApiDefinitionScheduleService apiDefinitionScheduleService;
|
||||
|
||||
public SwaggerUrlImportJob() {
|
||||
apiDefinitionImportService = CommonBeanFactory.getBean(ApiDefinitionImportService.class);
|
||||
apiDefinitionScheduleService = CommonBeanFactory.getBean(ApiDefinitionScheduleService.class);
|
||||
simpleUserService = CommonBeanFactory.getBean(SimpleUserService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -223,7 +223,7 @@ public class TestPlanReportService {
|
|||
* @param 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 当前用户
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
||||
public Map<String, String> genReportByExecution(String prepareReportId,TestPlanReportGenRequest request, String currentUser) {
|
||||
return genReport(prepareReportId,request, false, currentUser, "/test-plan/report/gen");
|
||||
public Map<String, String> genReportByExecution(String prepareReportId, TestPlanReportGenRequest request, String currentUser) {
|
||||
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<>();
|
||||
try {
|
||||
// 所有计划
|
||||
|
@ -292,6 +292,7 @@ public class TestPlanReportService {
|
|||
|
||||
/**
|
||||
* 预生成报告内容(汇总前调用)
|
||||
*
|
||||
* @return 报告
|
||||
*/
|
||||
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 moduleParam 模块参数
|
||||
* @param report 报告
|
||||
|
@ -470,7 +472,7 @@ public class TestPlanReportService {
|
|||
*/
|
||||
TestPlanReportSummaryExample example = new TestPlanReportSummaryExample();
|
||||
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();
|
||||
CaseCount summaryCount = JSON.parseObject(new String(reportSummary.getExecuteResult()), CaseCount.class);
|
||||
|
@ -496,6 +498,7 @@ public class TestPlanReportService {
|
|||
|
||||
/**
|
||||
* 获取报告
|
||||
*
|
||||
* @param reportId 报告ID
|
||||
* @return 报告详情
|
||||
*/
|
||||
|
@ -517,7 +520,7 @@ public class TestPlanReportService {
|
|||
if (CollectionUtils.isEmpty(testPlanReportSummaries)) {
|
||||
throw new MSException(Translator.get("test_plan_report_detail_not_exist"));
|
||||
}
|
||||
TestPlanReportSummary reportSummary = testPlanReportSummaries.get(0);
|
||||
TestPlanReportSummary reportSummary = testPlanReportSummaries.getFirst();
|
||||
TestPlanReportDetailResponse planReportDetail = new TestPlanReportDetailResponse();
|
||||
BeanUtils.copyBean(planReportDetail, planReport);
|
||||
int caseTotal = (int) (reportSummary.getFunctionalCaseCount() + reportSummary.getApiCaseCount() + reportSummary.getApiScenarioCount());
|
||||
|
@ -577,6 +580,7 @@ public class TestPlanReportService {
|
|||
|
||||
/**
|
||||
* 分页查询报告详情-用例分页数据
|
||||
*
|
||||
* @param request 请求参数
|
||||
* @return 用例分页数据
|
||||
*/
|
||||
|
@ -625,7 +629,7 @@ public class TestPlanReportService {
|
|||
.fakeError(functionalCaseCount.getFakeError() + apiCaseCount.getFakeError() + scenarioCaseCount.getFakeError()).build();
|
||||
|
||||
// 入库汇总数据 => 报告详情表
|
||||
TestPlanReportSummary reportSummary = testPlanReportSummaries.get(0);
|
||||
TestPlanReportSummary reportSummary = testPlanReportSummaries.getFirst();
|
||||
reportSummary.setFunctionalExecuteResult(JSON.toJSONBytes(functionalCaseCount));
|
||||
reportSummary.setApiExecuteResult(JSON.toJSONBytes(apiCaseCount));
|
||||
reportSummary.setScenarioExecuteResult(JSON.toJSONBytes(scenarioCaseCount));
|
||||
|
@ -635,6 +639,7 @@ public class TestPlanReportService {
|
|||
|
||||
/**
|
||||
* 汇总生成的计划组报告
|
||||
*
|
||||
* @param reportId 报告ID
|
||||
*/
|
||||
public void summaryGroupReport(String reportId) {
|
||||
|
@ -645,12 +650,12 @@ public class TestPlanReportService {
|
|||
// 报告详情不存在
|
||||
return;
|
||||
}
|
||||
TestPlanReportSummary groupSummary = testPlanReportSummaries.get(0);
|
||||
TestPlanReportSummary groupSummary = testPlanReportSummaries.getFirst();
|
||||
|
||||
TestPlanReportExample example = new TestPlanReportExample();
|
||||
example.createCriteria().andParentIdEqualTo(reportId).andIntegratedEqualTo(false);
|
||||
List<TestPlanReport> testPlanReports = testPlanReportMapper.selectByExample(example);
|
||||
if(CollectionUtils.isEmpty(testPlanReports)){
|
||||
if (CollectionUtils.isEmpty(testPlanReports)) {
|
||||
// 不存在子报告, 不需要汇总数据
|
||||
return;
|
||||
}
|
||||
|
@ -859,7 +864,7 @@ public class TestPlanReportService {
|
|||
if (CollectionUtils.isEmpty(folderFileNames)) {
|
||||
return null;
|
||||
}
|
||||
String[] pathSplit = folderFileNames.get(0).split("/");
|
||||
String[] pathSplit = folderFileNames.getFirst().split("/");
|
||||
return pathSplit[pathSplit.length - 1];
|
||||
} catch (Exception e) {
|
||||
LogUtils.error(e);
|
||||
|
@ -903,6 +908,7 @@ public class TestPlanReportService {
|
|||
|
||||
/**
|
||||
* 构建预生成报告的参数
|
||||
*
|
||||
* @param genRequest 报告请求参数
|
||||
* @return 预生成报告参数
|
||||
*/
|
||||
|
@ -1008,7 +1014,7 @@ public class TestPlanReportService {
|
|||
bytes = getPreviewImg(fileName, fileId, compressed);
|
||||
} else {
|
||||
//在正式目录获取
|
||||
TestPlanReportAttachment attachment = reportAttachments.get(0);
|
||||
TestPlanReportAttachment attachment = reportAttachments.getFirst();
|
||||
fileName = attachment.getFileName();
|
||||
FileRequest fileRequest = buildPlanFileRequest(projectId, attachment.getTestPlanReportId(), attachment.getFileId(), attachment.getFileName());
|
||||
try {
|
||||
|
@ -1029,6 +1035,7 @@ public class TestPlanReportService {
|
|||
|
||||
/**
|
||||
* 构建计划报告文件请求
|
||||
*
|
||||
* @param projectId 项目ID
|
||||
* @param resourceId 资源ID
|
||||
* @param fileId 文件ID
|
||||
|
|
Loading…
Reference in New Issue