refactor(接口导入): 接口导入覆盖模式规则优化

--user=郭雨琦
--bug=1015688
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001015688
This commit is contained in:
guoyuqi 2022-08-08 13:36:01 +08:00 committed by xiaomeinvG
parent 4ba842b889
commit 11cdba122d
1 changed files with 146 additions and 99 deletions

View File

@ -664,11 +664,11 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
Map<String, List<ApiModule>> pidChildrenMap, Map<String, String> idPathMap,
Map<String, ApiModuleDTO> idModuleMap, ApiTestImportRequest request,
Boolean fullCoverage, List<ApiTestCaseWithBLOBs> importCases, Map<String, EsbApiParamsWithBLOBs> esbApiParamsMap) {
List<ApiDefinitionWithBLOBs> optionData = new ArrayList<>();
List<ApiDefinitionWithBLOBs> optionDatas = new ArrayList<>();
//系统原有的需要更新的list
List<ApiDefinitionWithBLOBs> toUpdateList = new ArrayList<>();
//去重TCP,SQL,DUBBO 模块下名称唯一
removeRepeatOrigin(data, fullCoverage, optionData);
removeRepeatOrigin(data, fullCoverage, optionDatas);
//上传文件时选的模块ID
String chooseModuleId = request.getModuleId();
//获取选中的模块
@ -682,27 +682,34 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
//需要新增的模块key 为模块路径
Map<String, ApiModule> moduleMap = new HashMap<>();
//处理模块
setModule(moduleMap, pidChildrenMap, idPathMap, idModuleMap, optionData, chooseModule);
setModule(moduleMap, pidChildrenMap, idPathMap, idModuleMap, optionDatas, chooseModule);
List<ApiDefinitionWithBLOBs> repeatApiDefinitionWithBLOBs = getApiDefinitionWithBLOBsList(request, optionData);
List<ApiDefinitionWithBLOBs> repeatApiDefinitionWithBLOBs = getApiDefinitionWithBLOBsList(request, optionDatas);
//重复接口的case
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap = new HashMap<>();
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
oldCaseMap = getOldCaseMap(repeatApiDefinitionWithBLOBs);
}
Map<String, ApiDefinitionWithBLOBs> repeatDataMap = null;
Map<String, ApiDefinitionWithBLOBs> optionMap = new HashMap<>();
if (chooseModule != null) {
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
String chooseModuleParentId = getChooseModuleParentId(chooseModule);
String chooseModulePath = getChooseModulePath(idPathMap, chooseModule, chooseModuleParentId);
optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + chooseModulePath, api -> api));
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().filter(t -> t.getModuleId().equals(chooseModuleId)).collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), api -> api));
if (fullCoverage) {
List<ApiDefinitionWithBLOBs> singleOptionDatas = new ArrayList<>();
removeOtherChooseModuleRepeat(optionDatas, singleOptionDatas, chooseModulePath);
optionDatas = singleOptionDatas;
optionMap = optionDatas.stream().collect(Collectors.toMap(t -> t.getName().concat(t.getMethod()).concat(t.getPath()).concat(chooseModulePath), api -> api));
} else {
getNoHChooseModuleUrlRepeatOptionMap(optionDatas, optionMap, chooseModulePath);
}
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().filter(t -> t.getModuleId().equals(chooseModuleId)).collect(Collectors.toMap(t -> t.getName().concat(t.getModulePath()), api -> api));
}
} else {
buildOptionMap(optionData, optionMap);
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), api -> api));
buildOptionMap(optionDatas, optionMap);
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.toMap(t -> t.getName().concat(t.getModulePath()), api -> api));
}
Boolean fullCoverageApi = getFullCoverageApi(request);
String updateVersionId = getUpdateVersionId(request);
@ -716,43 +723,60 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
}
} else {
//不覆盖
removeRepeat(optionData, optionMap, repeatDataMap, moduleMap, versionId, optionDataCases);
removeRepeat(optionDatas, optionMap, repeatDataMap, moduleMap, versionId, optionDataCases);
}
//系统内检查重复
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), api -> api));
optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), api -> api));
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.toMap(t -> t.getName().concat(t.getModulePath()), api -> api));
optionMap = optionDatas.stream().collect(Collectors.toMap(t -> t.getName().concat(t.getModulePath()), api -> api));
if (fullCoverage) {
cover(moduleMap, toUpdateList, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap, esbApiParamsMap);
} else {
//不覆盖,同一接口不做更新
removeRepeat(optionData, optionMap, repeatDataMap, moduleMap, versionId, optionDataCases);
removeRepeat(optionDatas, optionMap, repeatDataMap, moduleMap, versionId, optionDataCases);
}
}
if (optionData.isEmpty()) {
if (optionDatas.isEmpty()) {
moduleMap = new HashMap<>();
}
//将原来的case和更改的case组合在一起为了同步的设置
List<String> caseIds = optionDataCases.stream().map(ApiTestCase::getId).filter(StringUtils::isNotBlank).collect(Collectors.toList());
buildCases(optionDataCases, oldCaseMap, caseIds);
return getUpdateApiModuleDTO(moduleMap, toUpdateList, optionData, optionDataCases);
return getUpdateApiModuleDTO(moduleMap, toUpdateList, optionDatas, optionDataCases);
}
private void buildOptionMap(List<ApiDefinitionWithBLOBs> optionData, Map<String, ApiDefinitionWithBLOBs> optionMap) {
for (ApiDefinitionWithBLOBs optionDatum : optionData) {
private void getNoHChooseModuleUrlRepeatOptionMap(List<ApiDefinitionWithBLOBs> optionDatas, Map<String, ApiDefinitionWithBLOBs> optionMap, String chooseModulePath) {
for (ApiDefinitionWithBLOBs optionDatum : optionDatas) {
if (optionDatum.getModulePath() == null) {
optionMap.put(optionDatum.getName().concat(chooseModulePath), optionDatum);
} else {
optionMap.put(optionDatum.getName().concat(chooseModulePath).concat(optionDatum.getModulePath()), optionDatum);
}
}
}
private void removeOtherChooseModuleRepeat(List<ApiDefinitionWithBLOBs> optionDatas, List<ApiDefinitionWithBLOBs> singleOptionDatas, String chooseModulePath) {
LinkedHashMap<String, List<ApiDefinitionWithBLOBs>> methodPathMap = optionDatas.stream().collect(Collectors.groupingBy(t -> t.getName().concat(chooseModulePath), LinkedHashMap::new, Collectors.toList()));
methodPathMap.forEach((k, v) -> {
singleOptionDatas.add(v.get(v.size() - 1));
});
}
private void buildOptionMap(List<ApiDefinitionWithBLOBs> optionDatas, Map<String, ApiDefinitionWithBLOBs> optionMap) {
for (ApiDefinitionWithBLOBs optionDatum : optionDatas) {
if (optionDatum.getModulePath() == null) {
optionMap.put(optionDatum.getName(), optionDatum);
} else {
optionMap.put(optionDatum.getName() + optionDatum.getModulePath(), optionDatum);
optionMap.put(optionDatum.getName().concat(optionDatum.getModulePath()), optionDatum);
}
}
}
private List<ApiDefinitionWithBLOBs> getApiDefinitionWithBLOBsList(ApiTestImportRequest request, List<ApiDefinitionWithBLOBs> optionData) {
private List<ApiDefinitionWithBLOBs> getApiDefinitionWithBLOBsList(ApiTestImportRequest request, List<ApiDefinitionWithBLOBs> optionDatas) {
//处理数据
List<String> nameList = optionData.stream().map(ApiDefinitionWithBLOBs::getName).collect(Collectors.toList());
List<String> nameList = optionDatas.stream().map(ApiDefinitionWithBLOBs::getName).collect(Collectors.toList());
String projectId = request.getProjectId();
String protocol = request.getProtocol();
//获取系统内重复数据
@ -764,12 +788,12 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
Map<String, ApiModuleDTO> idModuleMap, ApiTestImportRequest request,
Boolean fullCoverage, boolean urlRepeat, List<ApiTestCaseWithBLOBs> importCases) {
List<ApiDefinitionWithBLOBs> optionData = new ArrayList<>();
List<ApiDefinitionWithBLOBs> optionDatas = new ArrayList<>();
//系统原有的需要更新的list
List<ApiDefinitionWithBLOBs> toUpdateList = new ArrayList<>();
//去重 如果url可重复 则模块+名称+请求方式+路径 唯一否则 请求方式+路径唯一
//覆盖模式留重复的最后一个不覆盖留第一个
removeHTTPRepeat(data, fullCoverage, urlRepeat, optionData);
removeHttpRepeat(data, fullCoverage, urlRepeat, optionDatas);
//上传文件时选的模块ID
String chooseModuleId = request.getModuleId();
@ -784,24 +808,23 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
//需要新增的模块key 为模块路径
Map<String, ApiModule> moduleMap = new HashMap<>();
//处理模块
setModule(moduleMap, pidChildrenMap, idPathMap, idModuleMap, optionData, chooseModule);
setModule(moduleMap, pidChildrenMap, idPathMap, idModuleMap, optionDatas, chooseModule);
if (urlRepeat) {
dealHttpUrlRepeat(chooseModule, idPathMap, optionData, fullCoverage, request, moduleMap, toUpdateList, optionDataCases);
optionDatas = dealHttpUrlRepeat(chooseModule, idPathMap, optionDatas, fullCoverage, request, moduleMap, toUpdateList, optionDataCases);
} else {
dealHttpUrlNoRepeat(optionData, fullCoverage, request, moduleMap, toUpdateList, optionDataCases);
dealHttpUrlNoRepeat(optionDatas, fullCoverage, request, moduleMap, toUpdateList, optionDataCases);
}
if (optionData.isEmpty()) {
if (optionDatas.isEmpty()) {
moduleMap = new HashMap<>();
}
return getUpdateApiModuleDTO(moduleMap, toUpdateList, optionData, optionDataCases);
return getUpdateApiModuleDTO(moduleMap, toUpdateList, optionDatas, optionDataCases);
}
private void dealHttpUrlNoRepeat(List<ApiDefinitionWithBLOBs> optionData,
private void dealHttpUrlNoRepeat(List<ApiDefinitionWithBLOBs> optionDatas,
Boolean fullCoverage, ApiTestImportRequest request, Map<String, ApiModule> moduleMap,
List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiTestCaseWithBLOBs> optionDataCases) {
@ -813,36 +836,36 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
Boolean fullCoverageApi = getFullCoverageApi(request);
String projectId = request.getProjectId();
//系统内重复的数据
List<ApiDefinitionWithBLOBs> repeatApiDefinitionWithBLOBs = extApiDefinitionMapper.selectRepeatByBLOBs(optionData, projectId);
List<ApiDefinitionWithBLOBs> repeatApiDefinitionWithBLOBs = extApiDefinitionMapper.selectRepeatByBLOBs(optionDatas, projectId);
//这个是系统内重复的数据
Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getMethod() + t.getPath()));
Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getMethod().concat(t.getPath())));
//按照原来的顺序
optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), api -> api));
optionMap = optionDatas.stream().collect(Collectors.toMap(t -> t.getMethod().concat(t.getPath()), api -> api));
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap = new HashMap<>();
//重复接口的case
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
oldCaseMap = getOldCaseMap(repeatApiDefinitionWithBLOBs);
}
if (fullCoverage) {
if (fullCoverageApi) {
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
startCoverModule(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap);
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
startCoverModule(toUpdateList, optionDatas, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap);
}
} else {
//不覆盖模块
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap);
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
startCover(toUpdateList, optionDatas, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap);
}
}
} else {
//不覆盖,同一接口不做更新
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
removeSameData(repeatDataMap, optionMap, optionData, moduleMap, versionId, optionDataCases);
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
removeSameData(repeatDataMap, optionMap, optionDatas, moduleMap, versionId, optionDataCases);
}
}
//将原来的case和更改的case组合在一起为了同步的设置
@ -850,7 +873,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
buildCases(optionDataCases, oldCaseMap, caseIds);
}
private void dealHttpUrlRepeat(ApiModuleDTO chooseModule, Map<String, String> idPathMap, List<ApiDefinitionWithBLOBs> optionData,
private List<ApiDefinitionWithBLOBs> dealHttpUrlRepeat(ApiModuleDTO chooseModule, Map<String, String> idPathMap, List<ApiDefinitionWithBLOBs> optionDatas,
Boolean fullCoverage, ApiTestImportRequest request, Map<String, ApiModule> moduleMap,
List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiTestCaseWithBLOBs> optionDataCases) {
String updateVersionId = getUpdateVersionId(request);
@ -858,7 +881,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
Boolean fullCoverageApi = getFullCoverageApi(request);
String projectId = request.getProjectId();
//系统内重复的数据
List<ApiDefinitionWithBLOBs> repeatApiDefinitionWithBLOBs = extApiDefinitionMapper.selectRepeatByBLOBs(optionData, projectId);
List<ApiDefinitionWithBLOBs> repeatApiDefinitionWithBLOBs = extApiDefinitionMapper.selectRepeatByBLOBs(optionDatas, projectId);
//这个是名称加请求方式加路径加模块为key的map 就是为了去重
Map<String, ApiDefinitionWithBLOBs> optionMap = new HashMap<>();
@ -866,66 +889,90 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap;
//按照原来的顺序
if (chooseModule != null) {
//如果有选中的模块则在选中的模块下过滤
//如果有选中的模块则在选中的模块下过滤 过滤规则是 选择的模块路径+名称+method+path
String chooseModuleParentId = getChooseModuleParentId(chooseModule);
String chooseModulePath = getChooseModulePath(idPathMap, chooseModule, chooseModuleParentId);
optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + t.getMethod() + t.getPath() + chooseModulePath, api -> api));
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().filter(t -> t.getModuleId().equals(chooseModule.getId())).collect(Collectors.groupingBy(t -> t.getName() + t.getMethod() + t.getPath() + t.getModulePath()));
//这样的过滤规则下可能存在重复接口如果是覆盖模块需要按照去重规则再次去重否则就加上接口原有的模块
if (fullCoverage) {
List<ApiDefinitionWithBLOBs> singleOptionDatas = new ArrayList<>();
removeHttpChooseModuleRepeat(optionDatas, singleOptionDatas, chooseModulePath);
optionDatas = singleOptionDatas;
optionMap = optionDatas.stream().collect(Collectors.toMap(t -> t.getName().concat(t.getMethod()).concat(t.getPath()).concat(chooseModulePath), api -> api));
} else {
getChooseModuleUrlRepeatOptionMap(optionDatas, optionMap, chooseModulePath);
}
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().filter(t -> t.getModuleId().equals(chooseModule.getId())).collect(Collectors.groupingBy(t -> t.getName().concat(t.getMethod()).concat(t.getPath()).concat(t.getModulePath())));
} else {
//否则在整个系统中过滤
getUrlRepeatOptionMap(optionData, optionMap);
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getName() + t.getMethod() + t.getPath() + t.getModulePath()));
getUrlRepeatOptionMap(optionDatas, optionMap);
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getName().concat(t.getMethod()).concat(t.getPath()).concat(t.getModulePath())));
}
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap = new HashMap<>();
//重复接口的case
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
oldCaseMap = getOldCaseMap(repeatApiDefinitionWithBLOBs);
}
//覆盖接口
if (fullCoverage) {
//允许覆盖模块用导入的重复数据的最后一条覆盖查询的所有重复数据; case 在覆盖的时候是拼接到原来的casename唯一不覆盖就用原来的
if (fullCoverageApi) {
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
startCoverModule(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap);
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
startCoverModule(toUpdateList, optionDatas, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap);
}
} else {
//覆盖但不覆盖模块
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
//过滤同一层级重复模块导入文件没有新增接口无需创建接口模块
moduleMap = judgeModuleMap(moduleMap, optionMap, repeatDataMap);
startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap);
startCover(toUpdateList, optionDatas, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap);
}
}
} else {
//不覆盖,同一接口不做更新;可能创建新版本case也直接创建
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
removeSameData(repeatDataMap, optionMap, optionData, moduleMap, versionId, optionDataCases);
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
removeSameData(repeatDataMap, optionMap, optionDatas, moduleMap, versionId, optionDataCases);
}
}
//最后在整个体统内检查一遍防止在有选择的模块时未找到重复直接创建的情况
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getName() + t.getMethod() + t.getPath() + t.getModulePath()));
optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + t.getMethod() + t.getPath() + t.getModulePath(), api -> api));
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getName().concat(t.getMethod()).concat(t.getPath()).concat(t.getModulePath())));
optionMap = optionDatas.stream().collect(Collectors.toMap(t -> t.getName().concat(t.getMethod()).concat(t.getPath()).concat(t.getModulePath()), api -> api));
if (fullCoverage) {
startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap);
startCover(toUpdateList, optionDatas, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap);
} else {
//不覆盖,同一接口不做更新
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
removeSameData(repeatDataMap, optionMap, optionData, moduleMap, versionId, optionDataCases);
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
removeSameData(repeatDataMap, optionMap, optionDatas, moduleMap, versionId, optionDataCases);
}
}
}
//将原来的case和更改的case组合在一起为了同步的设置
List<String> caseIds = optionDataCases.stream().map(ApiTestCase::getId).filter(StringUtils::isNotBlank).collect(Collectors.toList());
buildCases(optionDataCases, oldCaseMap, caseIds);
return optionDatas;
}
private void getUrlRepeatOptionMap(List<ApiDefinitionWithBLOBs> optionData, Map<String, ApiDefinitionWithBLOBs> optionMap) {
for (ApiDefinitionWithBLOBs optionDatum : optionData) {
private void removeHttpChooseModuleRepeat(List<ApiDefinitionWithBLOBs> optionDatas, List<ApiDefinitionWithBLOBs> singleOptionDatas, String chooseModulePath) {
LinkedHashMap<String, List<ApiDefinitionWithBLOBs>> methodPathMap = optionDatas.stream().collect(Collectors.groupingBy(t -> t.getName().concat(t.getMethod()).concat(t.getPath()).concat(chooseModulePath), LinkedHashMap::new, Collectors.toList()));
methodPathMap.forEach((k, v) -> singleOptionDatas.add(v.get(v.size() - 1)));
}
private void getChooseModuleUrlRepeatOptionMap(List<ApiDefinitionWithBLOBs> optionDatas, Map<String, ApiDefinitionWithBLOBs> optionMap, String chooseModulePath) {
for (ApiDefinitionWithBLOBs optionDatum : optionDatas) {
if (optionDatum.getModulePath() == null) {
optionMap.put(optionDatum.getName() + optionDatum.getMethod() + optionDatum.getPath(), optionDatum);
optionMap.put(optionDatum.getName().concat(optionDatum.getMethod()).concat(optionDatum.getPath()).concat(chooseModulePath), optionDatum);
} else {
optionMap.put(optionDatum.getName() + optionDatum.getMethod() + optionDatum.getPath() + optionDatum.getModulePath(), optionDatum);
optionMap.put(optionDatum.getName().concat(optionDatum.getMethod()).concat(optionDatum.getPath()).concat(chooseModulePath).concat(optionDatum.getModulePath()), optionDatum);
}
}
}
private void getUrlRepeatOptionMap(List<ApiDefinitionWithBLOBs> optionDatas, Map<String, ApiDefinitionWithBLOBs> optionMap) {
for (ApiDefinitionWithBLOBs optionDatum : optionDatas) {
if (optionDatum.getModulePath() == null) {
optionMap.put(optionDatum.getName().concat(optionDatum.getMethod()).concat(optionDatum.getPath()), optionDatum);
} else {
optionMap.put(optionDatum.getName().concat(optionDatum.getMethod()).concat(optionDatum.getPath()).concat(optionDatum.getModulePath()), optionDatum);
}
}
}
@ -965,7 +1012,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
}
private void removeRepeatCase(Boolean fullCoverage, List<ApiTestCaseWithBLOBs> importCases, List<ApiTestCaseWithBLOBs> optionDataCases) {
LinkedHashMap<String, List<ApiTestCaseWithBLOBs>> apiIdNameMap = importCases.stream().collect(Collectors.groupingBy(t -> t.getName() + t.getApiDefinitionId(), LinkedHashMap::new, Collectors.toList()));
LinkedHashMap<String, List<ApiTestCaseWithBLOBs>> apiIdNameMap = importCases.stream().collect(Collectors.groupingBy(t -> t.getName().concat(t.getApiDefinitionId()), LinkedHashMap::new, Collectors.toList()));
if (fullCoverage) {
apiIdNameMap.forEach((k, v) -> {
v.get(v.size() - 1).setId(null);
@ -992,21 +1039,21 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
}
private UpdateApiModuleDTO getUpdateApiModuleDTO(Map<String, ApiModule> moduleMap, List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionData, List<ApiTestCaseWithBLOBs> optionDataCases) {
private UpdateApiModuleDTO getUpdateApiModuleDTO(Map<String, ApiModule> moduleMap, List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionDatas, List<ApiTestCaseWithBLOBs> optionDataCases) {
UpdateApiModuleDTO updateApiModuleDTO = new UpdateApiModuleDTO();
updateApiModuleDTO.setModuleList(new ArrayList<>(moduleMap.values()));
updateApiModuleDTO.setNeedUpdateList(toUpdateList);
updateApiModuleDTO.setDefinitionWithBLOBs(optionData);
updateApiModuleDTO.setDefinitionWithBLOBs(optionDatas);
updateApiModuleDTO.setCaseWithBLOBs(optionDataCases);
return updateApiModuleDTO;
}
private void removeRepeat(List<ApiDefinitionWithBLOBs> optionData, Map<String, ApiDefinitionWithBLOBs> nameModuleMap,
private void removeRepeat(List<ApiDefinitionWithBLOBs> optionDatas, Map<String, ApiDefinitionWithBLOBs> nameModuleMap,
Map<String, ApiDefinitionWithBLOBs> repeatDataMap, Map<String, ApiModule> moduleMap,
String versionId,
List<ApiTestCaseWithBLOBs> optionDataCases) {
if (nameModuleMap != null) {
Map<String, List<ApiDefinitionWithBLOBs>> moduleOptionData = optionData.stream().collect(Collectors.groupingBy(ApiDefinition::getModulePath));
Map<String, List<ApiDefinitionWithBLOBs>> moduleOptionData = optionDatas.stream().collect(Collectors.groupingBy(ApiDefinition::getModulePath));
repeatDataMap.forEach((k, v) -> {
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = nameModuleMap.get(k);
if (apiDefinitionWithBLOBs != null) {
@ -1021,8 +1068,8 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
}
//不覆盖选择版本如果被选版本有同接口不导入否则创建新版本接口
if (v.getVersionId().equals(versionId)) {
optionData.remove(apiDefinitionWithBLOBs);
if (distinctNameCases != null && !distinctNameCases.isEmpty()) {
optionDatas.remove(apiDefinitionWithBLOBs);
if (CollectionUtils.isNotEmpty(distinctNameCases)) {
distinctNameCases.forEach(optionDataCases::remove);
}
} else {
@ -1134,29 +1181,29 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
}
}
private void removeRepeatOrigin(List<ApiDefinitionWithBLOBs> data, Boolean fullCoverage, List<ApiDefinitionWithBLOBs> optionData) {
private void removeRepeatOrigin(List<ApiDefinitionWithBLOBs> data, Boolean fullCoverage, List<ApiDefinitionWithBLOBs> optionDatas) {
LinkedHashMap<String, List<ApiDefinitionWithBLOBs>> methodPathMap = data.stream().collect(Collectors.groupingBy(t -> t.getName() + (t.getModulePath() == null ? "" : t.getModulePath()), LinkedHashMap::new, Collectors.toList()));
if (fullCoverage) {
methodPathMap.forEach((k, v) -> optionData.add(v.get(v.size() - 1)));
methodPathMap.forEach((k, v) -> optionDatas.add(v.get(v.size() - 1)));
} else {
methodPathMap.forEach((k, v) -> optionData.add(v.get(0)));
methodPathMap.forEach((k, v) -> optionDatas.add(v.get(0)));
}
}
private void removeHTTPRepeat(List<ApiDefinitionWithBLOBs> data, Boolean fullCoverage, boolean urlRepeat, List<ApiDefinitionWithBLOBs> optionData) {
private void removeHttpRepeat(List<ApiDefinitionWithBLOBs> data, Boolean fullCoverage, boolean urlRepeat, List<ApiDefinitionWithBLOBs> optionDatas) {
if (urlRepeat) {
LinkedHashMap<String, List<ApiDefinitionWithBLOBs>> methodPathMap = data.stream().collect(Collectors.groupingBy(t -> t.getName() + t.getMethod() + t.getPath() + (t.getModulePath() == null ? "" : t.getModulePath()), LinkedHashMap::new, Collectors.toList()));
if (fullCoverage) {
methodPathMap.forEach((k, v) -> optionData.add(v.get(v.size() - 1)));
methodPathMap.forEach((k, v) -> optionDatas.add(v.get(v.size() - 1)));
} else {
methodPathMap.forEach((k, v) -> optionData.add(v.get(0)));
methodPathMap.forEach((k, v) -> optionDatas.add(v.get(0)));
}
} else {
LinkedHashMap<String, List<ApiDefinitionWithBLOBs>> methodPathMap = data.stream().collect(Collectors.groupingBy(t -> t.getMethod() + t.getPath(), LinkedHashMap::new, Collectors.toList()));
LinkedHashMap<String, List<ApiDefinitionWithBLOBs>> methodPathMap = data.stream().collect(Collectors.groupingBy(t -> t.getMethod().concat(t.getPath()), LinkedHashMap::new, Collectors.toList()));
if (fullCoverage) {
methodPathMap.forEach((k, v) -> optionData.add(v.get(v.size() - 1)));
methodPathMap.forEach((k, v) -> optionDatas.add(v.get(v.size() - 1)));
} else {
methodPathMap.forEach((k, v) -> optionData.add(v.get(0)));
methodPathMap.forEach((k, v) -> optionDatas.add(v.get(0)));
}
}
}
@ -1182,10 +1229,10 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
}
private void removeSameData(Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap, Map<String, ApiDefinitionWithBLOBs> methodPathMap,
List<ApiDefinitionWithBLOBs> optionData, Map<String, ApiModule> moduleMap, String versionId,
List<ApiDefinitionWithBLOBs> optionDatas, Map<String, ApiModule> moduleMap, String versionId,
List<ApiTestCaseWithBLOBs> optionDataCases) {
Map<String, List<ApiDefinitionWithBLOBs>> moduleOptionData = optionData.stream().collect(Collectors.groupingBy(ApiDefinition::getModulePath));
Map<String, List<ApiDefinitionWithBLOBs>> moduleOptionData = optionDatas.stream().collect(Collectors.groupingBy(ApiDefinition::getModulePath));
repeatDataMap.forEach((k, v) -> {
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = methodPathMap.get(k);
if (apiDefinitionWithBLOBs != null) {
@ -1200,8 +1247,8 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
}
//不覆盖选择版本如果被选版本有同接口不导入否则创建新版本接口
List<ApiDefinitionWithBLOBs> sameVersionList = v.stream().filter(t -> t.getVersionId().equals(versionId)).collect(Collectors.toList());
if (!sameVersionList.isEmpty()) {
optionData.remove(apiDefinitionWithBLOBs);
if (CollectionUtils.isNotEmpty(sameVersionList)) {
optionDatas.remove(apiDefinitionWithBLOBs);
if (CollectionUtils.isNotEmpty(distinctNameCases)) {
distinctNameCases.forEach(optionDataCases::remove);
}
@ -1239,7 +1286,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
}
private void startCoverModule(List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionData,
private void startCoverModule(List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionDatas,
Map<String, ApiDefinitionWithBLOBs> methodPathMap, Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap,
String updateVersionId, List<ApiTestCaseWithBLOBs> optionDataCases,
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap) {
@ -1276,11 +1323,11 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
addNewVersionApi(apiDefinitionWithBLOBs, v.get(0), "update");
} else {
optionData.remove(apiDefinitionWithBLOBs);
optionDatas.remove(apiDefinitionWithBLOBs);
}
}
});
buildOtherParam(toUpdateList, optionData, coverApiList, updateApiList);
buildOtherParam(toUpdateList, optionDatas, coverApiList, updateApiList);
}
private void buildCaseList(Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap,
@ -1291,7 +1338,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
//map List 结构是因为表里可能一个接口有多个同名case的可能
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseNameMap;
//如果有重复接口处理重复接口
if (apiTestCases != null && !apiTestCases.isEmpty()) {
if (CollectionUtils.isNotEmpty(apiTestCases)) {
oldCaseNameMap = apiTestCases.stream().collect(Collectors.groupingBy(ApiTestCase::getName));
caseNameMap.forEach((name, caseWithBLOBs1) -> {
//如果导入的有重名覆盖接口ID替换成系统内的
@ -1352,7 +1399,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
}
}
private void startCover(List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionData,
private void startCover(List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionDatas,
Map<String, ApiDefinitionWithBLOBs> methodPathMap, Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap,
String updateVersionId, List<ApiTestCaseWithBLOBs> optionDataCases,
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap) {
@ -1389,11 +1436,11 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
addNewVersionApi(apiDefinitionWithBLOBs, v.get(0), "update");
} else {
optionData.remove(apiDefinitionWithBLOBs);
optionDatas.remove(apiDefinitionWithBLOBs);
}
}
});
buildOtherParam(toUpdateList, optionData, coverApiList, updateApiList);
buildOtherParam(toUpdateList, optionDatas, coverApiList, updateApiList);
}
private Map<String, ApiModule> judgeModuleMap(Map<String, ApiModule> moduleMap, Map<String, ApiDefinitionWithBLOBs> methodPathMap, Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap) {
@ -1409,8 +1456,8 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
return moduleMap;
}
private void buildOtherParam(List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionData, List<ApiDefinitionWithBLOBs> coverApiList, List<ApiDefinitionWithBLOBs> updateApiList) {
optionData.addAll(coverApiList);
private void buildOtherParam(List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionDatas, List<ApiDefinitionWithBLOBs> coverApiList, List<ApiDefinitionWithBLOBs> updateApiList) {
optionDatas.addAll(coverApiList);
toUpdateList.addAll(updateApiList);
}
@ -1509,7 +1556,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
for (int i = 0; i < tagTree.length; i++) {
int finalI = i;
List<ApiModule> collect = new ArrayList<>();
if (parentModuleList != null && !parentModuleList.isEmpty()) {
if (CollectionUtils.isNotEmpty(parentModuleList)) {
collect = parentModuleList.stream().filter(t -> t.getName().equals(tagTree[finalI])).collect(Collectors.toList());
}
if (collect.isEmpty()) {
@ -1521,7 +1568,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
parentModule.setLevel(0);
parentModule.setProtocol(pidChildrenMap.get("root").get(0).getProtocol());
} else {
if (parentModuleList != null && !parentModuleList.isEmpty() && parentModule == null) {
if (CollectionUtils.isNotEmpty(parentModuleList) && parentModule == null) {
String parentId = parentModuleList.get(0).getParentId();
ApiModuleDTO apiModuleDTO = idModuleMap.get(parentId);
parentModule = JSON.parseObject(JSON.toJSONString(apiModuleDTO), ApiModule.class);