refactor(接口测试): 针对不同作用的对象进行归类
This commit is contained in:
parent
ac3bc36376
commit
46f064e5e8
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
||||
}
|
|
@ -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")
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<ApiDefinitionImportDTO> data;
|
||||
private List<ApiDefinitionImportDetail> data;
|
||||
|
||||
// 新版本带用例导出
|
||||
private List<ApiTestCaseDTO> cases = new ArrayList<>();
|
|
@ -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;
|
|
@ -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<String> sameList = new ArrayList<>();
|
||||
@Schema(description = "不同的数据的key")
|
||||
List<String> differenceList = new ArrayList<>();
|
||||
@Schema(description = "数据库中存在的数据")
|
||||
Map<String, ApiDefinitionImportDTO> apiDateMap = new HashMap<>();
|
||||
Map<String, ApiDefinitionImportDetail> apiDateMap = new HashMap<>();
|
||||
@Schema(description = "导入的数据")
|
||||
Map<String, ApiDefinitionImportDTO> importDataMap = new HashMap<>();
|
||||
Map<String, ApiDefinitionImportDetail> importDataMap = new HashMap<>();
|
||||
|
||||
}
|
|
@ -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<ApiDefinitionImportDTO> updateModuleData = new ArrayList<>();
|
||||
List<ApiDefinitionImportDetail> updateModuleData = new ArrayList<>();
|
||||
@Schema(description = "需要更新接口的数据")
|
||||
List<ApiDefinitionImportDTO> updateRequestData = new ArrayList<>();
|
||||
List<ApiDefinitionImportDetail> updateRequestData = new ArrayList<>();
|
||||
@Schema(description = "需要新增的接口数据")
|
||||
List<ApiDefinitionImportDTO> addModuleData = new ArrayList<>();
|
||||
List<ApiDefinitionImportDetail> addModuleData = new ArrayList<>();
|
||||
@Schema(description = "需要新增的日志数据")
|
||||
Map<String, ApiDefinitionImportDTO> logData;
|
||||
Map<String, ApiDefinitionImportDetail> logData;
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.api.dto.definition.importdto;
|
||||
package io.metersphere.api.dto.definition.request;
|
||||
|
||||
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
|
@ -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";
|
||||
|
||||
}
|
|
@ -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<ApiDefinitionImportDTO> importList(@Param("request") ApiDefinitionPageRequest request);
|
||||
List<ApiDefinitionImportDetail> importList(@Param("request") ApiDefinitionPageRequest request);
|
||||
|
||||
List<String> selectIdsByIdsAndDeleted(@Param("ids") List<String> ids, @Param("deleted") boolean deleted);
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@
|
|||
</foreach>
|
||||
and deleted = #{deleted}
|
||||
</select>
|
||||
<select id="importList" resultType="io.metersphere.api.dto.definition.importdto.ApiDefinitionImportDTO">
|
||||
<select id="importList" resultType="io.metersphere.api.dto.converter.ApiDefinitionImportDetail">
|
||||
select
|
||||
api_definition.id, api_definition.`name`, api_definition.protocol, api_definition.`method`,
|
||||
api_definition.`path`, api_definition.version_id,
|
||||
|
|
|
@ -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<T> implements ImportParser<ApiDefinitionImport> {
|
|||
return StringUtils.isNotBlank(testStr) ? testStr.toString() : StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
private List<ApiDefinitionImportDTO> parseRequests(OpenAPI openAPI, ImportRequest importRequest) {
|
||||
private List<ApiDefinitionImportDetail> parseRequests(OpenAPI openAPI, ImportRequest importRequest) {
|
||||
|
||||
Paths paths = openAPI.getPaths();
|
||||
|
||||
|
@ -110,7 +110,7 @@ public class Swagger3Parser<T> implements ImportParser<ApiDefinitionImport> {
|
|||
|
||||
this.components = openAPI.getComponents();
|
||||
|
||||
List<ApiDefinitionImportDTO> results = new ArrayList<>();
|
||||
List<ApiDefinitionImportDetail> results = new ArrayList<>();
|
||||
|
||||
for (String pathName : pathNames) {
|
||||
PathItem pathItem = paths.get(pathName);
|
||||
|
@ -129,7 +129,7 @@ public class Swagger3Parser<T> implements ImportParser<ApiDefinitionImport> {
|
|||
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<T> implements ImportParser<ApiDefinitionImport> {
|
|||
}
|
||||
}
|
||||
|
||||
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<T> implements ImportParser<ApiDefinitionImport> {
|
|||
} else {
|
||||
name = path;
|
||||
}
|
||||
ApiDefinitionImportDTO apiDefinition = new ApiDefinitionImportDTO();
|
||||
ApiDefinitionImportDetail apiDefinition = new ApiDefinitionImportDetail();
|
||||
apiDefinition.setName(name);
|
||||
apiDefinition.setPath(formatPath(path));
|
||||
apiDefinition.setProtocol("HTTP");
|
||||
|
|
|
@ -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<ApiDefinitionImportDTO> initData = apiImport.getData();
|
||||
List<ApiDefinitionImportDetail> initData = apiImport.getData();
|
||||
|
||||
//TODO 查询项目菜单参数
|
||||
/*ProjectApplicationExample applicationExample = new ProjectApplicationExample();
|
||||
|
@ -127,7 +127,7 @@ public class ApiDefinitionImportUtilService {
|
|||
String typeValue = projectApplications.get(0).getTypeValue();
|
||||
}*/
|
||||
//过滤(一次只导入一个协议)
|
||||
List<ApiDefinitionImportDTO> filterData = initData.stream().filter(t -> t.getProtocol().equals(request.getProtocol())).collect(Collectors.toList());
|
||||
List<ApiDefinitionImportDetail> 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<ApiDefinitionImportDTO> importData, SessionUser user) {
|
||||
private void dealWithData(ImportRequest request, List<ApiDefinitionImportDetail> importData, SessionUser user) {
|
||||
//查询数据库中所有的数据, 用于判断是否重复
|
||||
ApiDefinitionPageRequest pageRequest = new ApiDefinitionPageRequest();
|
||||
pageRequest.setProjectId(request.getProjectId());
|
||||
pageRequest.setProtocol(request.getProtocol());
|
||||
//TODO 如果是有版本的话 需要加上版本的判断
|
||||
List<ApiDefinitionImportDTO> apiLists = extApiDefinitionMapper.importList(pageRequest);
|
||||
List<ApiDefinitionImportDetail> apiLists = extApiDefinitionMapper.importList(pageRequest);
|
||||
List<BaseTreeNode> apiModules = this.buildTreeData(request.getProjectId(), request.getProtocol());
|
||||
//将apiModules转换成新的map 要求key是attachInfo中的modulePath 使用stream实现
|
||||
Map<String, BaseTreeNode> 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<String, BaseTreeNode> modulePathMap,
|
||||
Map<String, BaseTreeNode> idModuleMap,
|
||||
ApiDeatlWithDataUpdate apiDeatlWithDataUpdate,
|
||||
ApiDetailWithDataUpdate apiDetailWithDataUpdate,
|
||||
ImportRequest request, SessionUser user) {
|
||||
//先判断是否需要新增模块
|
||||
List<ApiDefinitionImportDTO> addModuleData = apiDeatlWithDataUpdate.getAddModuleData();
|
||||
List<ApiDefinitionImportDTO> updateModuleData = apiDeatlWithDataUpdate.getUpdateModuleData();
|
||||
List<ApiDefinitionImportDetail> addModuleData = apiDetailWithDataUpdate.getAddModuleData();
|
||||
List<ApiDefinitionImportDetail> updateModuleData = apiDetailWithDataUpdate.getUpdateModuleData();
|
||||
//取addModuleData的模块放到set中 生成一个新的set
|
||||
Set<String> moduleSet = addModuleData.stream().map(ApiDefinitionImportDTO::getModulePath).collect(Collectors.toSet());
|
||||
Set<String> moduleSet = addModuleData.stream().map(ApiDefinitionImportDetail::getModulePath).collect(Collectors.toSet());
|
||||
//取updateModuleData的模块放到set中 生成一个新的set
|
||||
Set<String> updateModuleSet = updateModuleData.stream().map(ApiDefinitionImportDTO::getModulePath).collect(Collectors.toSet());
|
||||
Set<String> updateModuleSet = updateModuleData.stream().map(ApiDefinitionImportDetail::getModulePath).collect(Collectors.toSet());
|
||||
moduleSet.addAll(updateModuleSet);
|
||||
//将modulePathMap的key转成set
|
||||
Set<String> modulePathSet = modulePathMap.keySet();
|
||||
|
@ -277,7 +277,7 @@ public class ApiDefinitionImportUtilService {
|
|||
});
|
||||
|
||||
//取出需要更新的数据的id
|
||||
List<String> updateModuleLists = updateModuleData.stream().map(ApiDefinitionImportDTO::getId).toList();
|
||||
List<String> updateModuleLists = updateModuleData.stream().map(ApiDefinitionImportDetail::getId).toList();
|
||||
|
||||
//更新模块数据
|
||||
updateModuleData.forEach(t -> {
|
||||
|
@ -289,7 +289,7 @@ public class ApiDefinitionImportUtilService {
|
|||
apiMapper.updateByPrimaryKeySelective(apiDefinition);
|
||||
});
|
||||
List<LogDTO> operationLogs = new ArrayList<>();
|
||||
List<ApiDefinitionImportDTO> updateRequestData = apiDeatlWithDataUpdate.getUpdateRequestData();
|
||||
List<ApiDefinitionImportDetail> 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<String, ApiDefinitionImportDTO> logData = apiDeatlWithDataUpdate.getLogData();
|
||||
Map<String, ApiDefinitionImportDetail> logData = apiDetailWithDataUpdate.getLogData();
|
||||
Project project = projectMapper.selectByPrimaryKey(request.getProjectId());
|
||||
List<ApiDefinitionCaseDTO> 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<String> sameList = apiDeatlWithData.getSameList();
|
||||
List<String> differenceList = apiDeatlWithData.getDifferenceList();
|
||||
Map<String, ApiDefinitionImportDTO> apiDateMap = apiDeatlWithData.getApiDateMap();
|
||||
Map<String, ApiDefinitionImportDTO> importDataMap = apiDeatlWithData.getImportDataMap();
|
||||
List<ApiDefinitionImportDTO> updateModuleData = new ArrayList<>();
|
||||
List<ApiDefinitionImportDTO> updateRequestData = new ArrayList<>();
|
||||
List<ApiDefinitionImportDTO> addData = new ArrayList<>();
|
||||
Map<String, ApiDefinitionImportDTO> logMap = new HashMap<>();
|
||||
private void getNeedUpdateData(ImportRequest request, ApiDetailWithData apiDetailWithData, ApiDetailWithDataUpdate apiDetailWithDataUpdate) {
|
||||
List<String> sameList = apiDetailWithData.getSameList();
|
||||
List<String> differenceList = apiDetailWithData.getDifferenceList();
|
||||
Map<String, ApiDefinitionImportDetail> apiDateMap = apiDetailWithData.getApiDateMap();
|
||||
Map<String, ApiDefinitionImportDetail> importDataMap = apiDetailWithData.getImportDataMap();
|
||||
List<ApiDefinitionImportDetail> updateModuleData = new ArrayList<>();
|
||||
List<ApiDefinitionImportDetail> updateRequestData = new ArrayList<>();
|
||||
List<ApiDefinitionImportDetail> addData = new ArrayList<>();
|
||||
Map<String, ApiDefinitionImportDetail> logMap = new HashMap<>();
|
||||
//判断参数是否一样 一样的参数需要判断是否需要覆盖模块 如果需要就要update数据, 如果不需要 就直接跳过
|
||||
if (CollectionUtils.isNotEmpty(sameList) && getFullCoverage(request.getCoverData())) {
|
||||
//需要覆盖数据的 会判断是否需要覆盖模块
|
||||
List<ApiDefinitionImportDTO> sameData = sameList.stream().map(apiDateMap::get).toList();
|
||||
List<ApiDefinitionImportDetail> sameData = sameList.stream().map(apiDateMap::get).toList();
|
||||
//取所有id为新的list 需要取查询blob的数据
|
||||
List<String> sameIds = sameData.stream().map(ApiDefinitionImportDTO::getId).toList();
|
||||
List<String> sameIds = sameData.stream().map(ApiDefinitionImportDetail::getId).toList();
|
||||
ApiDefinitionBlobExample blobExample = new ApiDefinitionBlobExample();
|
||||
blobExample.createCriteria().andIdIn(sameIds);
|
||||
List<ApiDefinitionBlob> apiDefinitionBlobs = apiDefinitionBlobMapper.selectByExampleWithBLOBs(blobExample);
|
||||
Map<String, ApiDefinitionBlob> 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<ApiDefinitionImportDTO> importData,
|
||||
List<ApiDefinitionImportDTO> apiLists,
|
||||
ApiDeatlWithData apiDeatlWithData) {
|
||||
List<ApiDefinitionImportDetail> importData,
|
||||
List<ApiDefinitionImportDetail> 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<ApiDefinitionImportDTO> importData,
|
||||
List<ApiDefinitionImportDTO> lists,
|
||||
ApiDeatlWithData apiDeatlWithData) {
|
||||
public void methodAndPath(List<ApiDefinitionImportDetail> importData,
|
||||
List<ApiDefinitionImportDetail> lists,
|
||||
ApiDetailWithData apiDetailWithData) {
|
||||
|
||||
Map<String, ApiDefinitionImportDTO> apiDateMap = lists.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), t -> t));
|
||||
Map<String, ApiDefinitionImportDTO> importDataMap = importData.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), t -> t));
|
||||
Map<String, ApiDefinitionImportDetail> apiDateMap = lists.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), t -> t));
|
||||
Map<String, ApiDefinitionImportDetail> importDataMap = importData.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), t -> t));
|
||||
//判断是否重复
|
||||
List<String> orgList = apiDateMap.keySet().stream().toList();
|
||||
List<String> importList = importDataMap.keySet().stream().toList();
|
||||
|
@ -468,10 +468,10 @@ public class ApiDefinitionImportUtilService {
|
|||
List<String> sameList = importList.stream().filter(orgList::contains).toList();
|
||||
// 不同接口的数据
|
||||
List<String> 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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<OperationHistoryDTO> list(OperationHistoryRequest request) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue