From e532cdb6348300a288b930ceef895e963fd0dd95 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Mon, 8 Mar 2021 17:38:32 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E7=BB=9F=E4=B8=80=E6=96=87=E4=BB=B6=E8=B7=AF?= =?UTF-8?q?=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/api/dto/definition/request/MsScenario.java | 3 ++- .../metersphere/api/dto/definition/request/MsTestElement.java | 3 ++- .../src/main/java/io/metersphere/api/dto/scenario/Body.java | 4 ++-- .../java/io/metersphere/api/service/ApiDefinitionService.java | 2 +- .../java/io/metersphere/api/service/ApiTestCaseService.java | 2 +- .../src/main/java/io/metersphere/commons/utils/FileUtils.java | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java index 77ead9342b..6303166c99 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java @@ -15,6 +15,7 @@ import io.metersphere.api.service.ApiTestEnvironmentService; import io.metersphere.base.domain.ApiScenarioWithBLOBs; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.commons.utils.CommonBeanFactory; +import io.metersphere.commons.utils.FileUtils; import io.metersphere.commons.utils.SessionUtils; import lombok.Data; import lombok.EqualsAndHashCode; @@ -58,7 +59,7 @@ public class MsScenario extends MsTestElement { @JSONField(ordinal = 27) private Map environmentMap; - private static final String BODY_FILE_DIR = "/opt/metersphere/data/body"; + private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR; public MsScenario() { } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java index 25e59c6395..182dbf5512 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java @@ -33,6 +33,7 @@ import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.commons.constants.LoopConstants; import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.utils.CommonBeanFactory; +import io.metersphere.commons.utils.FileUtils; import io.metersphere.commons.utils.LogUtil; import lombok.Data; import org.apache.commons.collections.CollectionUtils; @@ -108,7 +109,7 @@ public abstract class MsTestElement { private MsTestElement parent; - private static final String BODY_FILE_DIR = "/opt/metersphere/data/body"; + private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR; /** * todo 公共环境逐层传递,如果自身有环境 以自身引用环境为准否则以公共环境作为请求环境 diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java b/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java index bbe7959c49..f3f484b747 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java @@ -2,6 +2,7 @@ package io.metersphere.api.dto.scenario; import io.metersphere.api.dto.scenario.request.BodyFile; import io.metersphere.commons.json.JSONSchemaGenerator; +import io.metersphere.commons.utils.FileUtils; import lombok.Data; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -96,11 +97,10 @@ public class Body { } private void setFileArg(List list, List files, KeyValue keyValue, String requestId) { - final String BODY_FILE_DIR = "/opt/metersphere/data/body"; if (files != null) { files.forEach(file -> { String paramName = keyValue.getName() == null ? requestId : keyValue.getName(); - String path = BODY_FILE_DIR + '/' + file.getId() + '_' + file.getName(); + String path = FileUtils.BODY_FILE_DIR + '/' + file.getId() + '_' + file.getName(); String mimetype = keyValue.getContentType(); list.add(new HTTPFileArg(path, paramName, mimetype)); }); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index cc58b14e73..01148eaa55 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -91,7 +91,7 @@ public class ApiDefinitionService { private static Cache cache = Cache.newHardMemoryCache(0, 3600 * 24); - private static final String BODY_FILE_DIR = "/opt/metersphere/data/body"; + private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR; public List list(ApiDefinitionRequest request) { request = this.initRequest(request, true, true); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java index ee452d424a..a81b53f786 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -77,7 +77,7 @@ public class ApiTestCaseService { @Resource private TestPlanApiCaseMapper testPlanApiCaseMapper; - private static final String BODY_FILE_DIR = "/opt/metersphere/data/body"; + private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR; public List list(ApiTestCaseRequest request) { request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); diff --git a/backend/src/main/java/io/metersphere/commons/utils/FileUtils.java b/backend/src/main/java/io/metersphere/commons/utils/FileUtils.java index 01830daeab..fd14d28549 100644 --- a/backend/src/main/java/io/metersphere/commons/utils/FileUtils.java +++ b/backend/src/main/java/io/metersphere/commons/utils/FileUtils.java @@ -10,7 +10,7 @@ import java.io.*; import java.util.List; public class FileUtils { - private static final String BODY_FILE_DIR = "/opt/metersphere/data/body"; + public static final String BODY_FILE_DIR = "/opt/metersphere/data/body"; public static void createBodyFiles(List bodyUploadIds, List bodyFiles) { if (CollectionUtils.isNotEmpty(bodyUploadIds) && CollectionUtils.isNotEmpty(bodyFiles)) {