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);
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()
.filter(param -> StringUtils.equals(commonParam.getKey(), param.getKey()))
.findFirst()
.ifPresent(param -> commonParam.setValue(param.getValue()))
)
Optional.ofNullable(commonScriptInfo.getParams()).flatMap(params -> params.stream()
.filter(param -> StringUtils.equals(commonParam.getKey(), param.getKey()))
.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;
}
/**

View File

@ -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) {

View File

@ -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).

View File

@ -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 -> {
}
}

View File

@ -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