From def0db3f5069a31eb253facd819be9102405e6b5 Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Tue, 6 Feb 2024 20:02:01 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E6=8E=A5=E5=8F=A3=E6=89=A7=E8=A1=8C=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8F=92=E4=BB=B6=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sdk/dto/api/task/ApiExecuteFileInfo.java | 8 +++++++- .../sdk/dto/api/task/TaskRequestDTO.java | 6 +++++- .../jmeter/body/MsFormDataBodyConverter.java | 5 ++++- .../api/service/ApiExecuteService.java | 18 ++++++++++++------ .../system/service/ApiPluginService.java | 17 +++++++++++++++++ 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/ApiExecuteFileInfo.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/ApiExecuteFileInfo.java index 310e5b71db..045b77fce9 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/ApiExecuteFileInfo.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/ApiExecuteFileInfo.java @@ -4,12 +4,18 @@ import io.metersphere.sdk.dto.FileMetadataRepositoryDTO; import io.metersphere.sdk.dto.FileModuleRepositoryDTO; import lombok.Data; +import java.io.Serial; +import java.io.Serializable; + /** * @Author: jianxing * @CreateTime: 2023-12-15 16:59 */ @Data -public class ApiExecuteFileInfo { +public class ApiExecuteFileInfo implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + private String fileId; private String fileName; /** diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/TaskRequestDTO.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/TaskRequestDTO.java index fef9dde037..992987101d 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/TaskRequestDTO.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/TaskRequestDTO.java @@ -61,11 +61,15 @@ public class TaskRequestDTO implements Serializable { * 执行时下载文件后,按原文件命名 */ private List refFiles; + /** + * 插件文件列表 + * id 为插件的 id + 更新时间戳 + */ + private List pluginFiles; /** * 误报规则 */ List msRegexList; - /** * 项目id */ diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsFormDataBodyConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsFormDataBodyConverter.java index 9f740e8165..9f7c387163 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsFormDataBodyConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/body/MsFormDataBodyConverter.java @@ -23,10 +23,13 @@ public class MsFormDataBodyConverter extends MsBodyConverter { @Override public void parse(HTTPSamplerProxy sampler, FormDataBody body, ParameterConfig config) { List formValues = body.getFormValues(); + sampler.setDoMultipart(true); + if (CollectionUtils.isEmpty(formValues)) { + return; + } List validFormValues = formValues.stream().filter(FormDataKV::isValid).collect(Collectors.toList()); List fileFormValues = validFormValues.stream().filter(FormDataKV::isFile).collect(Collectors.toList()); List textFormValues = validFormValues.stream().filter(kv -> !kv.isFile()).collect(Collectors.toList()); - sampler.setDoMultipart(true); sampler.setHTTPFiles(getHttpFileArg(fileFormValues)); sampler.setArguments(getArguments(textFormValues)); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiExecuteService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiExecuteService.java index a91f0caa62..fc3def75ed 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiExecuteService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiExecuteService.java @@ -12,6 +12,7 @@ import io.metersphere.plugin.api.dto.ParameterConfig; import io.metersphere.plugin.api.spi.AbstractMsTestElement; import io.metersphere.project.domain.ProjectApplication; import io.metersphere.project.dto.customfunction.request.CustomFunctionRunRequest; +import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.project.service.FileAssociationService; import io.metersphere.project.service.FileManagementService; import io.metersphere.project.service.FileMetadataService; @@ -29,6 +30,7 @@ import io.metersphere.system.config.MinioProperties; import io.metersphere.system.domain.TestResourcePool; import io.metersphere.system.dto.pool.TestResourceNodeDTO; import io.metersphere.system.dto.pool.TestResourcePoolReturnDTO; +import io.metersphere.system.service.ApiPluginService; import io.metersphere.system.service.CommonProjectService; import io.metersphere.system.service.SystemParameterService; import io.metersphere.system.service.TestResourcePoolService; @@ -78,7 +80,8 @@ public class ApiExecuteService { private FileMetadataService fileMetadataService; @Resource private FileManagementService fileManagementService; - + @Resource + private ApiPluginService apiPluginService; @PostConstruct private void init() { @@ -136,11 +139,11 @@ public class ApiExecuteService { /** * 发送执行任务 * - * @param reportId 报告ID - * @param testId 资源ID - * @param taskRequest 执行参数 - * @param executeScript 执行脚本 - * @param projectId 项目ID + * @param reportId 报告ID + * @param testId 资源ID + * @param taskRequest 执行参数 + * @param executeScript 执行脚本 + * @param projectId 项目ID */ private void doDebug(String reportId, String testId, @@ -148,6 +151,9 @@ public class ApiExecuteService { String executeScript, String projectId) { + // 设置插件文件信息 + taskRequest.setPluginFiles(apiPluginService.getFileInfoByProjectId(projectId)); + TestResourcePoolReturnDTO testResourcePoolDTO = getGetResourcePoolNodeDTO(projectId); TestResourceNodeDTO testResourceNodeDTO = getProjectExecuteNode(testResourcePoolDTO); if (StringUtils.isNotBlank(testResourcePoolDTO.getServerUrl())) { diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/ApiPluginService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/ApiPluginService.java index 7041d13628..ce8d8bb422 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/ApiPluginService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/ApiPluginService.java @@ -4,7 +4,9 @@ import io.metersphere.plugin.api.spi.AbstractApiPlugin; import io.metersphere.plugin.api.spi.AbstractMsTestElement; import io.metersphere.plugin.api.spi.AbstractProtocolPlugin; import io.metersphere.plugin.api.spi.MsTestElement; +import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.sdk.constants.PluginScenarioType; +import io.metersphere.sdk.dto.api.task.ApiExecuteFileInfo; import io.metersphere.sdk.util.LogUtils; import io.metersphere.system.domain.Plugin; import io.metersphere.system.dto.ProtocolDTO; @@ -26,6 +28,8 @@ public class ApiPluginService { private PluginLoadService pluginLoadService; @Resource private BasePluginService basePluginService; + @Resource + private ProjectMapper projectMapper; /** * 获取协议插件的的协议列表 @@ -83,6 +87,7 @@ public class ApiPluginService { /** * 返回 MsTestElement 实现类与插件 ID 的映射 + * * @return */ public Map, String> getTestElementPluginMap() { @@ -97,6 +102,7 @@ public class ApiPluginService { /** * 返回 MsTestElement 实现类与接口协议的映射 + * * @return */ public Map, String> getTestElementProtocolMap() { @@ -114,4 +120,15 @@ public class ApiPluginService { } return testElementProtocolMap; } + + public List getFileInfoByProjectId(String projectId) { + return basePluginService.getOrgEnabledPlugins(projectMapper.selectByPrimaryKey(projectId).getOrganizationId(), PluginScenarioType.API_PROTOCOL) + .stream().map(plugin -> { + ApiExecuteFileInfo apiExecuteFileInfo = new ApiExecuteFileInfo(); + apiExecuteFileInfo.setFileId(plugin.getId() + "_" + plugin.getUpdateTime()); + apiExecuteFileInfo.setFileName(plugin.getFileName()); + return apiExecuteFileInfo; + }).toList(); + + } }