From 174d2f00d22d928b3af309772825e5fb8e0ac5a0 Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Mon, 5 Feb 2024 20:24:05 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E9=A1=B9=E7=9B=AE=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E7=8E=AF=E5=A2=83http=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/assertion/MsScriptAssertion.java | 4 +- .../project/dto/environment/KeyValue.java | 16 ------ .../dto/environment/http/HttpConfig.java | 56 ++++++++++++------- .../http/HttpConfigModuleMatchRule.java | 32 +++++++++++ .../http/HttpConfigPathMatchRule.java | 39 +++++++++++++ 5 files changed, 110 insertions(+), 37 deletions(-) delete mode 100644 backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/KeyValue.java create mode 100644 backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfigModuleMatchRule.java create mode 100644 backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfigPathMatchRule.java diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/MsScriptAssertion.java b/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/MsScriptAssertion.java index 8a201b3826..9d2d39fc03 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/MsScriptAssertion.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/MsScriptAssertion.java @@ -2,7 +2,7 @@ package io.metersphere.project.api.assertion; import com.fasterxml.jackson.annotation.JsonTypeName; import io.metersphere.project.api.KeyValueParam; -import io.metersphere.project.api.processor.ScriptProcessor; +import io.metersphere.project.constants.ScriptLanguageType; import lombok.Data; import java.util.List; @@ -21,7 +21,7 @@ public class MsScriptAssertion extends MsAssertion { private String script; /** * 脚本语言 - * @see ScriptProcessor.ScriptLanguageType + * {@link ScriptLanguageType} */ private String scriptLanguage; /** diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/KeyValue.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/KeyValue.java deleted file mode 100644 index 243621692a..0000000000 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/KeyValue.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.metersphere.project.dto.environment; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - - -@Data -public class KeyValue { - @Schema(description = "参数名") - private String name; - @Schema(description = "参数值") - private String value; - @Schema(description = "是否启用") - private Boolean enable = true; - -} diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfig.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfig.java index f02bd24bba..5ac046d000 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfig.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfig.java @@ -1,36 +1,54 @@ package io.metersphere.project.dto.environment.http; - -import io.metersphere.project.dto.environment.KeyValue; import io.metersphere.project.api.KeyValueEnableParam; +import io.metersphere.system.valid.EnumValue; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.Valid; import lombok.Data; import java.io.Serial; import java.io.Serializable; +import java.util.ArrayList; import java.util.List; @Data public class HttpConfig implements Serializable { - @Schema(description = "环境域名") - private String url; - @Schema(description = "启用条件 NONE/MODULE/PATH") - private String type = "NONE"; - @Schema(description = "启用条件为PATH时,需要填写的路径/ key为equal时,value为路径,key为contain时,value为包含的路径") - private List details; - @Schema(description = "启用条件为MODULE时,需要模块的id") - private List moduleIds; - @Schema(description = "请求头") - private List headers; - @Schema(description = "浏览器 选项为chrome/firefox") - private String browser; - private String description; - @Serial private static final long serialVersionUID = 1L; - public HttpConfig() { - this.headers = List.of(new KeyValueEnableParam()); - } + @Schema(description = "环境域名") + private String url; + /** + * 启用条件 + * {@link HttpConfigMatchType} + */ + @Schema(description = "启用条件 NONE/MODULE/PATH") + @EnumValue(enumClass = HttpConfigMatchType.class) + private String type = HttpConfigMatchType.NONE.name(); + @Valid + @Schema(description = "路径匹配规则") + private HttpConfigPathMatchRule pathMatchRule = new HttpConfigPathMatchRule(); + @Valid + @Schema(description = "模块匹配规则") + private HttpConfigModuleMatchRule moduleMatchRule = new HttpConfigModuleMatchRule(); + @Schema(description = "请求头") + private List<@Valid KeyValueEnableParam> headers = new ArrayList<>(0); + /** + * 启用条件匹配类型 + */ + public enum HttpConfigMatchType { + /** + * 路径匹配 + */ + PATH, + /** + * 模块匹配 + */ + MODULE, + /** + * 无条件 + */ + NONE + } } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfigModuleMatchRule.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfigModuleMatchRule.java new file mode 100644 index 0000000000..711d034d68 --- /dev/null +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfigModuleMatchRule.java @@ -0,0 +1,32 @@ +package io.metersphere.project.dto.environment.http; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.Valid; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * @Author: jianxing + * @CreateTime: 2024-02-05 18:53 + */ +@Data +public class HttpConfigModuleMatchRule implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + + @Schema(description = "选中模块") + @Valid + private List modules = new ArrayList<>(0); + + @Data + public class SelectModule { + @Schema(description = "模块ID") + private String moduleId; + @Schema(description = "是否包含新增子模块") + private Boolean containChildModule = false; + } +} diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfigPathMatchRule.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfigPathMatchRule.java new file mode 100644 index 0000000000..0ea990a37e --- /dev/null +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfigPathMatchRule.java @@ -0,0 +1,39 @@ +package io.metersphere.project.dto.environment.http; + +import io.metersphere.system.valid.EnumValue; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +/** + * @Author: jianxing + * @CreateTime: 2024-02-05 18:53 + */ +@Data +public class HttpConfigPathMatchRule implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + + /** + * 匹配规则 CONTAINS/EQUALS + * {@link MatchRuleCondition} + */ + @Schema(description = "匹配条件 CONTAINS/EQUALS") + @EnumValue(enumClass = MatchRuleCondition.class) + private String condition; + @Schema(description = "路径") + private String path; + + public enum MatchRuleCondition { + /** + * 包含 + */ + CONTAINS, + /** + * 等于 + */ + EQUALS + } +}