From 46f064e5e899850d8a62812692959841b8042c85 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 30 Jan 2024 14:16:02 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E9=92=88=E5=AF=B9=E4=B8=8D=E5=90=8C=E4=BD=9C=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E5=AF=B9=E8=B1=A1=E8=BF=9B=E8=A1=8C=E5=BD=92=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/constants/ApiDefinitionStatus.java | 8 +- .../api/constants/PropertyConstant.java | 14 +++ .../definition/ApiDefinitionController.java | 5 +- .../ApiDefinitionScheduleController.java | 2 +- .../ApiDefinitionImport.java | 4 +- .../ApiDefinitionImportDetail.java} | 4 +- .../ApiDetailWithData.java} | 8 +- .../ApiDetailWithDataUpdate.java} | 12 +-- .../ApiScheduleRequest.java | 2 +- .../api/enums/PropertyConstant.java | 33 ------ .../api/mapper/ExtApiDefinitionMapper.java | 4 +- .../api/mapper/ExtApiDefinitionMapper.xml | 2 +- .../api/parser/api/Swagger3Parser.java | 16 +-- .../ApiDefinitionImportUtilService.java | 102 +++++++++--------- .../ApiDefinitionScheduleService.java | 2 +- .../definition/ApiDefinitionService.java | 5 +- .../ApiDefinitionScheduleControllerTests.java | 2 +- 17 files changed, 102 insertions(+), 123 deletions(-) create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/constants/PropertyConstant.java rename backend/services/api-test/src/main/java/io/metersphere/api/dto/{definition/importdto => converter}/ApiDefinitionImport.java (76%) rename backend/services/api-test/src/main/java/io/metersphere/api/dto/{definition/importdto/ApiDefinitionImportDTO.java => converter/ApiDefinitionImportDetail.java} (83%) rename backend/services/api-test/src/main/java/io/metersphere/api/dto/{definition/importdto/ApiDeatlWithData.java => converter/ApiDetailWithData.java} (69%) rename backend/services/api-test/src/main/java/io/metersphere/api/dto/{definition/importdto/ApiDeatlWithDataUpdate.java => converter/ApiDetailWithDataUpdate.java} (53%) rename backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/{importdto => request}/ApiScheduleRequest.java (97%) delete mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/enums/PropertyConstant.java diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/constants/ApiDefinitionStatus.java b/backend/services/api-test/src/main/java/io/metersphere/api/constants/ApiDefinitionStatus.java index bd41df7f66..43f96bd8fd 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/constants/ApiDefinitionStatus.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/constants/ApiDefinitionStatus.java @@ -1,10 +1,13 @@ package io.metersphere.api.constants; +import lombok.Getter; + /** * @author: LAN * @date: 2023/11/16 10:42 * @version: 1.0 */ +@Getter public enum ApiDefinitionStatus { PREPARE("Prepare"), UNDERWAY("Underway"), @@ -12,13 +15,10 @@ public enum ApiDefinitionStatus { OBSOLETE("Obsolete"), COMPLETED("Completed"); - private String value; + private final String value; ApiDefinitionStatus(String value) { this.value = value; } - public String getValue() { - return this.value; - } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/constants/PropertyConstant.java b/backend/services/api-test/src/main/java/io/metersphere/api/constants/PropertyConstant.java new file mode 100644 index 0000000000..99ba65d0cc --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/constants/PropertyConstant.java @@ -0,0 +1,14 @@ +package io.metersphere.api.constants; + +public class PropertyConstant { + public final static String REQUIRED = "required"; + public final static String ARRAY = "array"; + public final static String OBJECT = "object"; + public final static String STRING = "string"; + public final static String BOOLEAN = "boolean"; + public final static String NUMBER = "number"; + public final static String INTEGER = "integer"; + public final static String NULL = "null"; + public final static String NONE = "none"; + +} diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionController.java index b0d8f353f0..b34c9fada9 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionController.java @@ -4,7 +4,6 @@ import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.api.domain.ApiDefinition; import io.metersphere.api.dto.definition.*; -import io.metersphere.api.dto.definition.importdto.ApiDefinitionImport; import io.metersphere.api.dto.request.ImportRequest; import io.metersphere.api.service.definition.ApiDefinitionLogService; import io.metersphere.api.service.definition.ApiDefinitionNoticeService; @@ -204,8 +203,8 @@ public class ApiDefinitionController { @PostMapping(value = "/import", consumes = {"multipart/form-data"}) @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_IMPORT) @Operation(summary = "接口测试-接口管理-导入接口定义") - public ApiDefinitionImport testCaseImport(@RequestPart(value = "file", required = false) MultipartFile file, @RequestPart("request") ImportRequest request) { - return apiDefinitionService.apiTestImport(file, request, SessionUtils.getUser(), SessionUtils.getCurrentProjectId()); + public void testCaseImport(@RequestPart(value = "file", required = false) MultipartFile file, @RequestPart("request") ImportRequest request) { + apiDefinitionService.apiTestImport(file, request, SessionUtils.getUser(), SessionUtils.getCurrentProjectId()); } @PostMapping("/operation-history") diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionScheduleController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionScheduleController.java index 8d31c4f430..f903f6f72b 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionScheduleController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionScheduleController.java @@ -2,7 +2,7 @@ package io.metersphere.api.controller.definition; import io.metersphere.api.dto.definition.ApiScheduleDTO; import io.metersphere.api.dto.definition.SwaggerUrlCheck; -import io.metersphere.api.dto.definition.importdto.ApiScheduleRequest; +import io.metersphere.api.dto.definition.request.ApiScheduleRequest; import io.metersphere.api.service.definition.ApiDefinitionLogService; import io.metersphere.api.service.definition.ApiDefinitionScheduleService; import io.metersphere.sdk.constants.PermissionConstants; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/importdto/ApiDefinitionImport.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/converter/ApiDefinitionImport.java similarity index 76% rename from backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/importdto/ApiDefinitionImport.java rename to backend/services/api-test/src/main/java/io/metersphere/api/dto/converter/ApiDefinitionImport.java index b87a295299..15250ed707 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/importdto/ApiDefinitionImport.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/converter/ApiDefinitionImport.java @@ -1,4 +1,4 @@ -package io.metersphere.api.dto.definition.importdto; +package io.metersphere.api.dto.converter; import io.metersphere.api.dto.definition.ApiTestCaseDTO; import lombok.Data; @@ -10,7 +10,7 @@ import java.util.List; public class ApiDefinitionImport { private String projectName; private String protocol; - private List data; + private List data; // 新版本带用例导出 private List cases = new ArrayList<>(); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/importdto/ApiDefinitionImportDTO.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/converter/ApiDefinitionImportDetail.java similarity index 83% rename from backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/importdto/ApiDefinitionImportDTO.java rename to backend/services/api-test/src/main/java/io/metersphere/api/dto/converter/ApiDefinitionImportDetail.java index b05db3a8f9..ca9df37a7d 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/importdto/ApiDefinitionImportDTO.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/converter/ApiDefinitionImportDetail.java @@ -1,4 +1,4 @@ -package io.metersphere.api.dto.definition.importdto; +package io.metersphere.api.dto.converter; import io.metersphere.api.domain.ApiDefinition; import io.metersphere.api.dto.definition.HttpResponse; @@ -11,7 +11,7 @@ import java.util.List; @Data @EqualsAndHashCode(callSuper = false) -public class ApiDefinitionImportDTO extends ApiDefinition { +public class ApiDefinitionImportDetail extends ApiDefinition { @Schema(description = "请求内容") private AbstractMsTestElement request; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/importdto/ApiDeatlWithData.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/converter/ApiDetailWithData.java similarity index 69% rename from backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/importdto/ApiDeatlWithData.java rename to backend/services/api-test/src/main/java/io/metersphere/api/dto/converter/ApiDetailWithData.java index 281f110fc7..8608ef632b 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/importdto/ApiDeatlWithData.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/converter/ApiDetailWithData.java @@ -1,4 +1,4 @@ -package io.metersphere.api.dto.definition.importdto; +package io.metersphere.api.dto.converter; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -9,14 +9,14 @@ import java.util.List; import java.util.Map; @Data -public class ApiDeatlWithData { +public class ApiDetailWithData { @Schema(description = "相同的数据的key") List sameList = new ArrayList<>(); @Schema(description = "不同的数据的key") List differenceList = new ArrayList<>(); @Schema(description = "数据库中存在的数据") - Map apiDateMap = new HashMap<>(); + Map apiDateMap = new HashMap<>(); @Schema(description = "导入的数据") - Map importDataMap = new HashMap<>(); + Map importDataMap = new HashMap<>(); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/importdto/ApiDeatlWithDataUpdate.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/converter/ApiDetailWithDataUpdate.java similarity index 53% rename from backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/importdto/ApiDeatlWithDataUpdate.java rename to backend/services/api-test/src/main/java/io/metersphere/api/dto/converter/ApiDetailWithDataUpdate.java index 1e169d9201..d4a81c77aa 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/importdto/ApiDeatlWithDataUpdate.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/converter/ApiDetailWithDataUpdate.java @@ -1,4 +1,4 @@ -package io.metersphere.api.dto.definition.importdto; +package io.metersphere.api.dto.converter; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -8,14 +8,14 @@ import java.util.List; import java.util.Map; @Data -public class ApiDeatlWithDataUpdate { +public class ApiDetailWithDataUpdate { @Schema(description = "需要更新模块的数据") - List updateModuleData = new ArrayList<>(); + List updateModuleData = new ArrayList<>(); @Schema(description = "需要更新接口的数据") - List updateRequestData = new ArrayList<>(); + List updateRequestData = new ArrayList<>(); @Schema(description = "需要新增的接口数据") - List addModuleData = new ArrayList<>(); + List addModuleData = new ArrayList<>(); @Schema(description = "需要新增的日志数据") - Map logData; + Map logData; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/importdto/ApiScheduleRequest.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/request/ApiScheduleRequest.java similarity index 97% rename from backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/importdto/ApiScheduleRequest.java rename to backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/request/ApiScheduleRequest.java index e1bd668ee2..f324509173 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/importdto/ApiScheduleRequest.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/request/ApiScheduleRequest.java @@ -1,4 +1,4 @@ -package io.metersphere.api.dto.definition.importdto; +package io.metersphere.api.dto.definition.request; import io.metersphere.sdk.constants.ModuleConstants; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/enums/PropertyConstant.java b/backend/services/api-test/src/main/java/io/metersphere/api/enums/PropertyConstant.java deleted file mode 100644 index 32b120d83a..0000000000 --- a/backend/services/api-test/src/main/java/io/metersphere/api/enums/PropertyConstant.java +++ /dev/null @@ -1,33 +0,0 @@ -package io.metersphere.api.enums; - -public class PropertyConstant { - public final static String REQUIRED = "required"; - public final static String ALL_OF = "allOf"; - public final static String PROPERTIES = "properties"; - public final static String ADDITIONAL_PROPERTIES = "additionalProperties"; - public final static String TYPE = "type"; - public final static String MS_OBJECT = "MS-OBJECT"; - public final static String ARRAY = "array"; - public final static String OBJECT = "object"; - public final static String DEFAULT = "default"; - public final static String STRING = "string"; - public final static String BOOLEAN = "boolean"; - public final static String NUMBER = "number"; - public final static String INTEGER = "integer"; - public final static String MOCK = "mock"; - public final static String NULL = "null"; - public final static String ENUM = "enum"; - public final static String ITEMS = "items"; - public final static String ITEM = "_item"; - public final static String NONE = "none"; - public final static String ROOT = "root"; - public final static String XML_PATH = "XML_PATH"; - public final static String ASS_OPTION = "ASS_OPTION"; - public final static String EXPECTED_VALUE = "EXPECTED_VALUE"; - public final static String ELEMENT_CONDITION = "ElementCondition"; - public final static String ENVIRONMENT = "useEnvironment"; - public final static String ENVIRONMENT_ID = "environmentId"; - public final static String DATASOURCE_ID = "dataSourceId"; - public final static String PROJECT_ID = "projectId"; - -} diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.java b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.java index 40b59e624d..56b36a5faa 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.java @@ -2,7 +2,7 @@ package io.metersphere.api.mapper; import io.metersphere.api.domain.ApiDefinition; import io.metersphere.api.dto.definition.*; -import io.metersphere.api.dto.definition.importdto.ApiDefinitionImportDTO; +import io.metersphere.api.dto.converter.ApiDefinitionImportDetail; import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.table.TableBatchProcessDTO; import org.apache.ibatis.annotations.Param; @@ -42,7 +42,7 @@ public interface ExtApiDefinitionMapper { void updateLatestVersion(@Param("id") String id, @Param("projectId") String projectId); - List importList(@Param("request") ApiDefinitionPageRequest request); + List importList(@Param("request") ApiDefinitionPageRequest request); List selectIdsByIdsAndDeleted(@Param("ids") List ids, @Param("deleted") boolean deleted); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml index bc1a17d368..fc591e72bd 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml @@ -137,7 +137,7 @@ and deleted = #{deleted} - select api_definition.id, api_definition.`name`, api_definition.protocol, api_definition.`method`, api_definition.`path`, api_definition.version_id, diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java index 6f7652a5c6..07bb5f1671 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java @@ -1,14 +1,14 @@ package io.metersphere.api.parser.api; import io.metersphere.api.dto.definition.HttpResponse; -import io.metersphere.api.dto.definition.importdto.ApiDefinitionImport; -import io.metersphere.api.dto.definition.importdto.ApiDefinitionImportDTO; +import io.metersphere.api.dto.converter.ApiDefinitionImport; +import io.metersphere.api.dto.converter.ApiDefinitionImportDetail; import io.metersphere.api.dto.request.ImportRequest; import io.metersphere.api.dto.request.http.*; import io.metersphere.api.dto.request.http.auth.NoAuth; import io.metersphere.api.dto.request.http.body.*; import io.metersphere.api.dto.schema.JsonSchemaItem; -import io.metersphere.api.enums.PropertyConstant; +import io.metersphere.api.constants.PropertyConstant; import io.metersphere.api.parser.ImportParser; import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.sdk.exception.MSException; @@ -102,7 +102,7 @@ public class Swagger3Parser implements ImportParser { return StringUtils.isNotBlank(testStr) ? testStr.toString() : StringUtils.EMPTY; } - private List parseRequests(OpenAPI openAPI, ImportRequest importRequest) { + private List parseRequests(OpenAPI openAPI, ImportRequest importRequest) { Paths paths = openAPI.getPaths(); @@ -110,7 +110,7 @@ public class Swagger3Parser implements ImportParser { this.components = openAPI.getComponents(); - List results = new ArrayList<>(); + List results = new ArrayList<>(); for (String pathName : pathNames) { PathItem pathItem = paths.get(pathName); @@ -129,7 +129,7 @@ public class Swagger3Parser implements ImportParser { Operation operation = operationsMap.get(method); if (operation != null) { //构建基本请求 - ApiDefinitionImportDTO apiDefinitionDTO = buildApiDefinition(operation, pathName, method, importRequest); + ApiDefinitionImportDetail apiDefinitionDTO = buildApiDefinition(operation, pathName, method, importRequest); //构建请求参数 MsHTTPElement request = buildRequest(apiDefinitionDTO.getName(), pathName, method); parseParameters(operation, request); @@ -266,7 +266,7 @@ public class Swagger3Parser implements ImportParser { } } - private ApiDefinitionImportDTO buildApiDefinition(Operation operation, String path, String + private ApiDefinitionImportDetail buildApiDefinition(Operation operation, String path, String method, ImportRequest importRequest) { String name; if (StringUtils.isNotBlank(operation.getSummary())) { @@ -276,7 +276,7 @@ public class Swagger3Parser implements ImportParser { } else { name = path; } - ApiDefinitionImportDTO apiDefinition = new ApiDefinitionImportDTO(); + ApiDefinitionImportDetail apiDefinition = new ApiDefinitionImportDetail(); apiDefinition.setName(name); apiDefinition.setPath(formatPath(path)); apiDefinition.setProtocol("HTTP"); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java index 43bd220e08..165f2cb5b5 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java @@ -9,10 +9,10 @@ import io.metersphere.api.domain.ApiDefinitionModule; import io.metersphere.api.dto.definition.ApiDefinitionDTO; import io.metersphere.api.dto.definition.ApiDefinitionPageRequest; import io.metersphere.api.dto.definition.ApiModuleRequest; -import io.metersphere.api.dto.definition.importdto.ApiDeatlWithData; -import io.metersphere.api.dto.definition.importdto.ApiDeatlWithDataUpdate; -import io.metersphere.api.dto.definition.importdto.ApiDefinitionImport; -import io.metersphere.api.dto.definition.importdto.ApiDefinitionImportDTO; +import io.metersphere.api.dto.converter.ApiDetailWithData; +import io.metersphere.api.dto.converter.ApiDetailWithDataUpdate; +import io.metersphere.api.dto.converter.ApiDefinitionImport; +import io.metersphere.api.dto.converter.ApiDefinitionImportDetail; import io.metersphere.api.dto.request.ImportRequest; import io.metersphere.api.dto.request.http.Header; import io.metersphere.api.dto.request.http.MsHTTPElement; @@ -20,7 +20,7 @@ import io.metersphere.api.dto.request.http.QueryParam; import io.metersphere.api.dto.request.http.RestParam; import io.metersphere.api.dto.request.http.body.*; import io.metersphere.api.dto.schema.JsonSchemaItem; -import io.metersphere.api.enums.PropertyConstant; +import io.metersphere.api.constants.PropertyConstant; import io.metersphere.api.mapper.*; import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.project.domain.Project; @@ -117,7 +117,7 @@ public class ApiDefinitionImportUtilService { if (request.getVersionId() == null) { request.setVersionId(defaultVersion); } - List initData = apiImport.getData(); + List initData = apiImport.getData(); //TODO 查询项目菜单参数 /*ProjectApplicationExample applicationExample = new ProjectApplicationExample(); @@ -127,7 +127,7 @@ public class ApiDefinitionImportUtilService { String typeValue = projectApplications.get(0).getTypeValue(); }*/ //过滤(一次只导入一个协议) - List filterData = initData.stream().filter(t -> t.getProtocol().equals(request.getProtocol())).collect(Collectors.toList()); + List filterData = initData.stream().filter(t -> t.getProtocol().equals(request.getProtocol())).collect(Collectors.toList()); if (filterData.isEmpty()) { return; } @@ -137,13 +137,13 @@ public class ApiDefinitionImportUtilService { } - private void dealWithData(ImportRequest request, List importData, SessionUser user) { + private void dealWithData(ImportRequest request, List importData, SessionUser user) { //查询数据库中所有的数据, 用于判断是否重复 ApiDefinitionPageRequest pageRequest = new ApiDefinitionPageRequest(); pageRequest.setProjectId(request.getProjectId()); pageRequest.setProtocol(request.getProtocol()); //TODO 如果是有版本的话 需要加上版本的判断 - List apiLists = extApiDefinitionMapper.importList(pageRequest); + List apiLists = extApiDefinitionMapper.importList(pageRequest); List apiModules = this.buildTreeData(request.getProjectId(), request.getProtocol()); //将apiModules转换成新的map 要求key是attachInfo中的modulePath 使用stream实现 Map modulePathMap = apiModules.stream().collect(Collectors.toMap(BaseTreeNode::getPath, t -> t)); @@ -161,15 +161,15 @@ public class ApiDefinitionImportUtilService { apiLists.forEach(t -> { t.setModulePath(idModuleMap.get(t.getModuleId()) != null ? idModuleMap.get(t.getModuleId()).getPath() : StringUtils.EMPTY); }); - ApiDeatlWithData apiDeatlWithData = new ApiDeatlWithData(); + ApiDetailWithData apiDeatlWithData = new ApiDetailWithData(); //判断数据是否是唯一的 checkApiDataOnly(request, importData, apiLists, apiDeatlWithData); - ApiDeatlWithDataUpdate apiDeatlWithDataUpdate = new ApiDeatlWithDataUpdate(); - getNeedUpdateData(request, apiDeatlWithData, apiDeatlWithDataUpdate); + ApiDetailWithDataUpdate apiDetailWithDataUpdate = new ApiDetailWithDataUpdate(); + getNeedUpdateData(request, apiDeatlWithData, apiDetailWithDataUpdate); //数据入库 - insertData(modulePathMap, idModuleMap, apiDeatlWithDataUpdate, request, user); + insertData(modulePathMap, idModuleMap, apiDetailWithDataUpdate, request, user); } @@ -211,15 +211,15 @@ public class ApiDefinitionImportUtilService { @Transactional(rollbackFor = Exception.class) public void insertData(Map modulePathMap, Map idModuleMap, - ApiDeatlWithDataUpdate apiDeatlWithDataUpdate, + ApiDetailWithDataUpdate apiDetailWithDataUpdate, ImportRequest request, SessionUser user) { //先判断是否需要新增模块 - List addModuleData = apiDeatlWithDataUpdate.getAddModuleData(); - List updateModuleData = apiDeatlWithDataUpdate.getUpdateModuleData(); + List addModuleData = apiDetailWithDataUpdate.getAddModuleData(); + List updateModuleData = apiDetailWithDataUpdate.getUpdateModuleData(); //取addModuleData的模块放到set中 生成一个新的set - Set moduleSet = addModuleData.stream().map(ApiDefinitionImportDTO::getModulePath).collect(Collectors.toSet()); + Set moduleSet = addModuleData.stream().map(ApiDefinitionImportDetail::getModulePath).collect(Collectors.toSet()); //取updateModuleData的模块放到set中 生成一个新的set - Set updateModuleSet = updateModuleData.stream().map(ApiDefinitionImportDTO::getModulePath).collect(Collectors.toSet()); + Set updateModuleSet = updateModuleData.stream().map(ApiDefinitionImportDetail::getModulePath).collect(Collectors.toSet()); moduleSet.addAll(updateModuleSet); //将modulePathMap的key转成set Set modulePathSet = modulePathMap.keySet(); @@ -277,7 +277,7 @@ public class ApiDefinitionImportUtilService { }); //取出需要更新的数据的id - List updateModuleLists = updateModuleData.stream().map(ApiDefinitionImportDTO::getId).toList(); + List updateModuleLists = updateModuleData.stream().map(ApiDefinitionImportDetail::getId).toList(); //更新模块数据 updateModuleData.forEach(t -> { @@ -289,7 +289,7 @@ public class ApiDefinitionImportUtilService { apiMapper.updateByPrimaryKeySelective(apiDefinition); }); List operationLogs = new ArrayList<>(); - List updateRequestData = apiDeatlWithDataUpdate.getUpdateRequestData(); + List updateRequestData = apiDetailWithDataUpdate.getUpdateRequestData(); updateRequestData.forEach(t -> { if (CollectionUtils.isNotEmpty(updateModuleLists) && updateModuleLists.contains(t.getId())) { ApiDefinition apiDefinition = new ApiDefinition(); @@ -305,7 +305,7 @@ public class ApiDefinitionImportUtilService { apiDefinitionBlob.setResponse(JSON.toJSONBytes(t.getResponse())); apiBlobMapper.updateByPrimaryKeySelective(apiDefinitionBlob); }); - Map logData = apiDeatlWithDataUpdate.getLogData(); + Map logData = apiDetailWithDataUpdate.getLogData(); Project project = projectMapper.selectByPrimaryKey(request.getProjectId()); List updateLists = new ArrayList<>(); if (MapUtils.isNotEmpty(logData)) { @@ -387,28 +387,28 @@ public class ApiDefinitionImportUtilService { afterReturningNoticeSendService.sendNotice(NoticeConstants.TaskType.API_DEFINITION_TASK, NoticeConstants.Event.UPDATE, updateResources, user, request.getProjectId()); } - private void getNeedUpdateData(ImportRequest request, ApiDeatlWithData apiDeatlWithData, ApiDeatlWithDataUpdate apiDeatlWithDataUpdate) { - List sameList = apiDeatlWithData.getSameList(); - List differenceList = apiDeatlWithData.getDifferenceList(); - Map apiDateMap = apiDeatlWithData.getApiDateMap(); - Map importDataMap = apiDeatlWithData.getImportDataMap(); - List updateModuleData = new ArrayList<>(); - List updateRequestData = new ArrayList<>(); - List addData = new ArrayList<>(); - Map logMap = new HashMap<>(); + private void getNeedUpdateData(ImportRequest request, ApiDetailWithData apiDetailWithData, ApiDetailWithDataUpdate apiDetailWithDataUpdate) { + List sameList = apiDetailWithData.getSameList(); + List differenceList = apiDetailWithData.getDifferenceList(); + Map apiDateMap = apiDetailWithData.getApiDateMap(); + Map importDataMap = apiDetailWithData.getImportDataMap(); + List updateModuleData = new ArrayList<>(); + List updateRequestData = new ArrayList<>(); + List addData = new ArrayList<>(); + Map logMap = new HashMap<>(); //判断参数是否一样 一样的参数需要判断是否需要覆盖模块 如果需要就要update数据, 如果不需要 就直接跳过 if (CollectionUtils.isNotEmpty(sameList) && getFullCoverage(request.getCoverData())) { //需要覆盖数据的 会判断是否需要覆盖模块 - List sameData = sameList.stream().map(apiDateMap::get).toList(); + List sameData = sameList.stream().map(apiDateMap::get).toList(); //取所有id为新的list 需要取查询blob的数据 - List sameIds = sameData.stream().map(ApiDefinitionImportDTO::getId).toList(); + List sameIds = sameData.stream().map(ApiDefinitionImportDetail::getId).toList(); ApiDefinitionBlobExample blobExample = new ApiDefinitionBlobExample(); blobExample.createCriteria().andIdIn(sameIds); List apiDefinitionBlobs = apiDefinitionBlobMapper.selectByExampleWithBLOBs(blobExample); Map blobMap = apiDefinitionBlobs.stream().collect(Collectors.toMap(ApiDefinitionBlob::getId, t -> t)); //判断参数是否一样 - for (ApiDefinitionImportDTO apiDefinitionDTO : sameData) { - ApiDefinitionImportDTO importDTO = importDataMap.get(apiDefinitionDTO.getMethod() + apiDefinitionDTO.getPath()); + for (ApiDefinitionImportDetail apiDefinitionDTO : sameData) { + ApiDefinitionImportDetail importDTO = importDataMap.get(apiDefinitionDTO.getMethod() + apiDefinitionDTO.getPath()); ApiDefinitionBlob apiDefinitionBlob = blobMap.get(apiDefinitionDTO.getId()); if (apiDefinitionBlob != null) { MsHTTPElement dbRequest = ApiDataUtils.parseObject(new String(apiDefinitionBlob.getRequest()), MsHTTPElement.class); @@ -437,30 +437,30 @@ public class ApiDefinitionImportUtilService { if (CollectionUtils.isNotEmpty(differenceList)) { addData = differenceList.stream().map(importDataMap::get).toList(); } - apiDeatlWithDataUpdate.setUpdateModuleData(updateModuleData); - apiDeatlWithDataUpdate.setUpdateRequestData(updateRequestData); - apiDeatlWithDataUpdate.setAddModuleData(addData); - apiDeatlWithDataUpdate.setLogData(logMap); + apiDetailWithDataUpdate.setUpdateModuleData(updateModuleData); + apiDetailWithDataUpdate.setUpdateRequestData(updateRequestData); + apiDetailWithDataUpdate.setAddModuleData(addData); + apiDetailWithDataUpdate.setLogData(logMap); } private void checkApiDataOnly(ImportRequest request, - List importData, - List apiLists, - ApiDeatlWithData apiDeatlWithData) { + List importData, + List apiLists, + ApiDetailWithData apiDetailWithData) { //判断是否是同一接口 需要返回的数据 需要insert的 update的 switch (request.getUniquelyIdentifies()) { - case "Method & Path" -> methodAndPath(importData, apiLists, apiDeatlWithData); + case "Method & Path" -> methodAndPath(importData, apiLists, apiDetailWithData); default -> { } } } - public void methodAndPath(List importData, - List lists, - ApiDeatlWithData apiDeatlWithData) { + public void methodAndPath(List importData, + List lists, + ApiDetailWithData apiDetailWithData) { - Map apiDateMap = lists.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), t -> t)); - Map importDataMap = importData.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), t -> t)); + Map apiDateMap = lists.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), t -> t)); + Map importDataMap = importData.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), t -> t)); //判断是否重复 List orgList = apiDateMap.keySet().stream().toList(); List importList = importDataMap.keySet().stream().toList(); @@ -468,10 +468,10 @@ public class ApiDefinitionImportUtilService { List sameList = importList.stream().filter(orgList::contains).toList(); // 不同接口的数据 List differenceList = importList.stream().filter(t -> !orgList.contains(t)).toList(); - apiDeatlWithData.setSameList(sameList); - apiDeatlWithData.setDifferenceList(differenceList); - apiDeatlWithData.setApiDateMap(apiDateMap); - apiDeatlWithData.setImportDataMap(importDataMap); + apiDetailWithData.setSameList(sameList); + apiDetailWithData.setDifferenceList(differenceList); + apiDetailWithData.setApiDateMap(apiDateMap); + apiDetailWithData.setImportDataMap(importDataMap); } public boolean dataIsSame(MsHTTPElement dbRequest, MsHTTPElement importRequest) { diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionScheduleService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionScheduleService.java index 9c824e9fe9..e048766959 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionScheduleService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionScheduleService.java @@ -4,7 +4,7 @@ import io.metersphere.api.domain.ApiDefinitionSwagger; import io.metersphere.api.domain.ApiDefinitionSwaggerExample; import io.metersphere.api.dto.definition.ApiScheduleDTO; import io.metersphere.api.dto.definition.SwaggerBasicAuth; -import io.metersphere.api.dto.definition.importdto.ApiScheduleRequest; +import io.metersphere.api.dto.definition.request.ApiScheduleRequest; import io.metersphere.api.mapper.ApiDefinitionSwaggerMapper; import io.metersphere.api.service.schedule.SwaggerUrlImportJob; import io.metersphere.api.utils.ApiDataUtils; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java index 35c9bf8622..a47e956047 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java @@ -6,7 +6,7 @@ import io.metersphere.api.controller.result.ApiResultCode; import io.metersphere.api.domain.*; import io.metersphere.api.dto.debug.ApiFileResourceUpdateRequest; import io.metersphere.api.dto.definition.*; -import io.metersphere.api.dto.definition.importdto.ApiDefinitionImport; +import io.metersphere.api.dto.converter.ApiDefinitionImport; import io.metersphere.api.dto.request.ImportRequest; import io.metersphere.api.mapper.*; import io.metersphere.api.parser.ImportParser; @@ -890,7 +890,7 @@ public class ApiDefinitionService { return apiDefinitionDocDTO; } - public ApiDefinitionImport apiTestImport(MultipartFile file, ImportRequest request, SessionUser user, String projectId) { + public void apiTestImport(MultipartFile file, ImportRequest request, SessionUser user, String projectId) { if (file != null) { String originalFilename = file.getOriginalFilename(); if (StringUtils.isNotBlank(originalFilename)) { @@ -920,7 +920,6 @@ public class ApiDefinitionService { LogUtils.error(e); throw new MSException(Translator.get("user_import_format_wrong")); } - return apiImport; } public List list(OperationHistoryRequest request) { diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionScheduleControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionScheduleControllerTests.java index 80ad5822ee..210f586b21 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionScheduleControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionScheduleControllerTests.java @@ -4,7 +4,7 @@ import io.metersphere.api.domain.ApiDefinitionSwagger; import io.metersphere.api.domain.ApiDefinitionSwaggerExample; import io.metersphere.api.dto.definition.ApiScheduleDTO; import io.metersphere.api.dto.definition.SwaggerUrlCheck; -import io.metersphere.api.dto.definition.importdto.ApiScheduleRequest; +import io.metersphere.api.dto.definition.request.ApiScheduleRequest; import io.metersphere.api.mapper.ApiDefinitionSwaggerMapper; import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.sdk.util.JSON;