parent
405e573123
commit
d14dff855f
|
@ -613,6 +613,11 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
String protocol = request.getProtocol();
|
||||
//上传文件时选的模块ID
|
||||
String chooseModuleId = request.getModuleId();
|
||||
|
||||
if (fullCoverage == null) {
|
||||
fullCoverage = false;
|
||||
}
|
||||
|
||||
//标准版ESB数据导入不区分是否覆盖,默认都为覆盖
|
||||
if (apiImport.getEsbApiParamsMap() != null) {
|
||||
fullCoverage = true;
|
||||
|
@ -660,27 +665,35 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
List<ApiDefinitionWithBLOBs> repeatApiDefinitionWithBLOBs;
|
||||
|
||||
if (chooseModule != null) {
|
||||
repeatApiDefinitionWithBLOBs = extApiDefinitionMapper.selectRepeatByBLOBsSameUrl(data, projectId, chooseModule.getId(), updateVersionId);
|
||||
repeatApiDefinitionWithBLOBs = extApiDefinitionMapper.selectRepeatByBLOBsSameUrl(optionData, projectId, chooseModule.getId(), updateVersionId);
|
||||
} else {
|
||||
repeatApiDefinitionWithBLOBs = extApiDefinitionMapper.selectRepeatByBLOBs(data, projectId, updateVersionId);
|
||||
repeatApiDefinitionWithBLOBs = extApiDefinitionMapper.selectRepeatByBLOBs(optionData, projectId, updateVersionId);
|
||||
}
|
||||
|
||||
//处理数据
|
||||
if (urlRepeat) {
|
||||
//按照原来的顺序
|
||||
Map<String, ApiDefinitionWithBLOBs> methodPathMap = data.stream().collect(Collectors.toMap(t -> t.getName() + t.getMethod() + t.getPath() + (t.getModulePath() == null ? "" : t.getModulePath()), api -> api));
|
||||
Map<String, ApiDefinitionWithBLOBs> methodPathMap;
|
||||
//按照原来的顺序
|
||||
if (chooseModule != null) {
|
||||
String chooseModuleParentId = getChooseModuleParentId(chooseModule);
|
||||
String chooseModulePath = getChooseModulePath(idPathMap, chooseModule, chooseModuleParentId);
|
||||
methodPathMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + t.getMethod() + t.getPath() + chooseModulePath, api -> api));
|
||||
} else {
|
||||
methodPathMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + t.getMethod() + t.getPath() + (t.getModulePath() == null ? "" : t.getModulePath()), api -> api));
|
||||
}
|
||||
|
||||
Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getName() + t.getMethod() + t.getPath() + t.getModulePath()));
|
||||
|
||||
//覆盖接口
|
||||
if (fullCoverage) {
|
||||
//允许覆盖模块,用导入的重复数据的最后一条覆盖查询的所有重复数据
|
||||
if (fullCoverageApi) {
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getName() + t.getMethod() + t.getPath() + t.getModulePath()));
|
||||
startCoverModule(toUpdateList, optionData, methodPathMap, repeatDataMap);
|
||||
}
|
||||
} else {
|
||||
//覆盖但不覆盖模块
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getName() + t.getMethod() + t.getPath() + t.getModulePath()));
|
||||
moduleMap = judgeModuleMap(moduleMap, methodPathMap, repeatDataMap);
|
||||
startCover(toUpdateList, optionData, methodPathMap, repeatDataMap);
|
||||
}
|
||||
|
@ -688,23 +701,31 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
} else {
|
||||
//不覆盖,同一接口不做更新
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getName() + t.getMethod() + t.getPath() + t.getModulePath()));
|
||||
removeSameData(repeatDataMap, methodPathMap, optionData);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
Map<String, ApiDefinitionWithBLOBs> methodPathMap = optionData.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), api -> api));
|
||||
Map<String, ApiDefinitionWithBLOBs> methodPathMap;
|
||||
Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getMethod() + t.getPath()));
|
||||
|
||||
//按照原来的顺序
|
||||
if (chooseModule != null) {
|
||||
String chooseModuleParentId = getChooseModuleParentId(chooseModule);
|
||||
String chooseModulePath = getChooseModulePath(idPathMap, chooseModule, chooseModuleParentId);
|
||||
methodPathMap = optionData.stream().collect(Collectors.toMap(t -> t.getMethod() + chooseModulePath, api -> api));
|
||||
} else {
|
||||
methodPathMap = optionData.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), api -> api));
|
||||
}
|
||||
|
||||
if (fullCoverage) {
|
||||
if (fullCoverageApi) {
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getMethod() + t.getPath()));
|
||||
startCoverModule(toUpdateList, optionData, methodPathMap, repeatDataMap);
|
||||
}
|
||||
} else {
|
||||
//不覆盖模块
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getMethod() + t.getPath()));
|
||||
if (repeatDataMap.size() >= methodPathMap.size()) {
|
||||
//导入文件没有新增接口无需创建接口模块
|
||||
moduleMap = new HashMap<>();
|
||||
|
@ -715,7 +736,6 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
} else {
|
||||
//不覆盖,同一接口不做更新
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getMethod() + t.getPath()));
|
||||
removeSameData(repeatDataMap, methodPathMap, optionData);
|
||||
}
|
||||
}
|
||||
|
@ -789,6 +809,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
ApiDefinitionWithBLOBs api = new ApiDefinitionWithBLOBs();
|
||||
BeanUtils.copyBean(api, apiDefinitionWithBLOBs);
|
||||
api.setId(definitionWithBLOBs.getId());
|
||||
api.setVersionId(definitionWithBLOBs.getVersionId());
|
||||
coverApiList.add(api);
|
||||
}
|
||||
optionData.remove(apiDefinitionWithBLOBs);
|
||||
|
@ -806,6 +827,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
ApiDefinitionWithBLOBs api = new ApiDefinitionWithBLOBs();
|
||||
BeanUtils.copyBean(api, apiDefinitionWithBLOBs);
|
||||
api.setId(definitionWithBLOBs.getId());
|
||||
api.setVersionId(definitionWithBLOBs.getVersionId());
|
||||
api.setModuleId(definitionWithBLOBs.getModuleId());
|
||||
api.setModulePath(definitionWithBLOBs.getModulePath());
|
||||
coverApiList.add(api);
|
||||
|
@ -877,20 +899,12 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
|
||||
private void dealChooseModuleData(Map<String, ApiModule> moduleMap, Map<String, List<ApiModule>> pidChildrenMap, Map<String, String> idPathMap, Map<String, ApiModuleDTO> idModuleMap, ApiModuleDTO chooseModule, ApiDefinitionWithBLOBs datum, String modulePath) {
|
||||
String[] pathTree;
|
||||
if (chooseModule.getParentId() == null) {
|
||||
chooseModule.setParentId("root");
|
||||
}
|
||||
String chooseModuleParentId = chooseModule.getParentId();
|
||||
String chooseModuleParentId = getChooseModuleParentId(chooseModule);
|
||||
String chooseModulePath = getChooseModulePath(idPathMap, chooseModule, chooseModuleParentId);
|
||||
//导入时选了模块,且接口有模块的
|
||||
if (StringUtils.isNotBlank(modulePath)) {
|
||||
List<ApiModule> moduleList = pidChildrenMap.get(chooseModuleParentId);
|
||||
String s;
|
||||
if (chooseModuleParentId.equals("root")) {
|
||||
s = "/" + chooseModule.getName();
|
||||
} else {
|
||||
s = idPathMap.get(chooseModuleParentId);
|
||||
}
|
||||
pathTree = getPathTree(s + modulePath);
|
||||
pathTree = getPathTree(chooseModulePath + modulePath);
|
||||
|
||||
ApiModule chooseModuleOne = JSON.parseObject(JSON.toJSONString(chooseModule), ApiModule.class);
|
||||
ApiModule minModule = getMinModule(pathTree, moduleList, chooseModuleOne, pidChildrenMap, moduleMap, idPathMap, idModuleMap);
|
||||
|
@ -904,6 +918,24 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
}
|
||||
}
|
||||
|
||||
private String getChooseModulePath(Map<String, String> idPathMap, ApiModuleDTO chooseModule, String chooseModuleParentId) {
|
||||
String s;
|
||||
if (chooseModuleParentId.equals("root")) {
|
||||
s = "/" + chooseModule.getName();
|
||||
} else {
|
||||
s = idPathMap.get(chooseModuleParentId);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private String getChooseModuleParentId(ApiModuleDTO chooseModule) {
|
||||
if (chooseModule.getParentId() == null) {
|
||||
chooseModule.setParentId("root");
|
||||
}
|
||||
String chooseModuleParentId = chooseModule.getParentId();
|
||||
return chooseModuleParentId;
|
||||
}
|
||||
|
||||
private String[] getPathTree(String modulePath) {
|
||||
String substring = modulePath.substring(0, 1);
|
||||
if (substring.equals("/")) {
|
||||
|
@ -1020,8 +1052,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
if (apiModuleDTO.getChildren() != null) {
|
||||
childrenList.addAll(apiModuleDTO.getChildren());
|
||||
} else {
|
||||
childrenList.addAll(new ArrayList<>());
|
||||
if (i == nodeTreeByProjectId.size() && childrenList.size() == 0) {
|
||||
if (childrenList == null) {
|
||||
pidChildrenMap.put(apiModuleDTO.getId(), new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -474,11 +474,11 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
* 上传文件时对文件的模块进行检测
|
||||
*
|
||||
* @param data
|
||||
* @param fullCoverage 是否覆盖接口
|
||||
* @param fullCoverageApi 是否更新当前接口所在模块
|
||||
* @param fullCoverage 是否覆盖接口
|
||||
* @param fullCoverageScenario 是否更新当前接口所在模块
|
||||
* @return Return to the newly added module map
|
||||
*/
|
||||
public UpdateScenarioModuleDTO checkScenarioModule(ApiTestImportRequest request, List<ApiScenarioWithBLOBs> data, Boolean fullCoverage, Boolean fullCoverageApi) {
|
||||
public UpdateScenarioModuleDTO checkScenarioModule(ApiTestImportRequest request, List<ApiScenarioWithBLOBs> data, Boolean fullCoverage, Boolean fullCoverageScenario) {
|
||||
//需要新增的模块,key 为模块路径
|
||||
Map<String, ApiScenarioModule> moduleMap = new HashMap<>();
|
||||
List<ApiScenarioWithBLOBs> toUpdateList = new ArrayList<>();
|
||||
|
@ -487,6 +487,10 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
String chooseModuleId = request.getModuleId();
|
||||
String projectId = request.getProjectId();
|
||||
|
||||
if (fullCoverageScenario == null) {
|
||||
fullCoverageScenario = false;
|
||||
}
|
||||
|
||||
//获取当前项目的当前协议下的所有模块的Tree
|
||||
List<ApiScenarioModuleDTO> scenarioModules = extApiScenarioModuleMapper.getNodeTreeByProjectId(projectId);
|
||||
List<ApiScenarioModuleDTO> nodeTreeByProjectId = this.getNodeTrees(scenarioModules);
|
||||
|
@ -520,23 +524,30 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
//系统内重复的数据
|
||||
List<ApiScenarioWithBLOBs> repeatApiScenarioWithBLOBs;
|
||||
if (chooseModule != null) {
|
||||
repeatApiScenarioWithBLOBs = extApiScenarioMapper.selectRepeatByBLOBsSameUrl(data, projectId, chooseModule.getId(), updateVersionId);
|
||||
repeatApiScenarioWithBLOBs = extApiScenarioMapper.selectRepeatByBLOBsSameUrl(optionData, projectId, chooseModule.getId(), updateVersionId);
|
||||
} else {
|
||||
repeatApiScenarioWithBLOBs = extApiScenarioMapper.selectRepeatByBLOBs(data, projectId, updateVersionId);
|
||||
repeatApiScenarioWithBLOBs = extApiScenarioMapper.selectRepeatByBLOBs(optionData, projectId, updateVersionId);
|
||||
}
|
||||
|
||||
Map<String, ApiScenarioWithBLOBs> nameModuleMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + (t.getModulePath() == null ? "" : t.getModulePath()), scenario -> scenario));
|
||||
Map<String, ApiScenarioWithBLOBs> repeatDataMap = null;
|
||||
if (!repeatApiScenarioWithBLOBs.isEmpty()) {
|
||||
repeatDataMap = repeatApiScenarioWithBLOBs.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), scenario -> scenario));
|
||||
Map<String, ApiScenarioWithBLOBs> nameModuleMap = null;
|
||||
Map<String, ApiScenarioWithBLOBs> repeatDataMap = repeatApiScenarioWithBLOBs.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), scenario -> scenario));
|
||||
if (chooseModule != null) {
|
||||
if (!repeatApiScenarioWithBLOBs.isEmpty()) {
|
||||
String chooseModuleParentId = getChooseModuleParentId(chooseModule);
|
||||
String chooseModulePath = getChooseModulePath(idPathMap, chooseModule, chooseModuleParentId);
|
||||
nameModuleMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + chooseModulePath, scenario -> scenario));
|
||||
}
|
||||
} else {
|
||||
nameModuleMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + (t.getModulePath() == null ? "" : t.getModulePath()), scenario -> scenario));
|
||||
}
|
||||
//处理数据
|
||||
if (fullCoverage) {
|
||||
if (fullCoverageApi) {
|
||||
if (fullCoverageScenario) {
|
||||
|
||||
startCoverModule(toUpdateList, nameModuleMap, repeatDataMap);
|
||||
} else {
|
||||
//覆盖但不覆盖模块
|
||||
if (repeatDataMap != null) {
|
||||
if (nameModuleMap != null) {
|
||||
//导入文件没有新增场景无需创建接口模块
|
||||
moduleMap = judgeModuleMap(moduleMap, nameModuleMap, repeatDataMap);
|
||||
startCover(toUpdateList, nameModuleMap, repeatDataMap);
|
||||
|
@ -570,6 +581,7 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
ApiScenarioWithBLOBs apiScenarioWithBLOBs = nameModuleMap.get(k);
|
||||
if (apiScenarioWithBLOBs != null) {
|
||||
apiScenarioWithBLOBs.setId(v.getId());
|
||||
apiScenarioWithBLOBs.setVersionId(v.getVersionId());
|
||||
apiScenarioWithBLOBs.setApiScenarioModuleId(v.getApiScenarioModuleId());
|
||||
apiScenarioWithBLOBs.setModulePath(v.getModulePath());
|
||||
toUpdateList.add(apiScenarioWithBLOBs);
|
||||
|
@ -590,6 +602,7 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
ApiScenarioWithBLOBs apiScenarioWithBLOBs = nameModuleMap.get(k);
|
||||
if (apiScenarioWithBLOBs != null) {
|
||||
apiScenarioWithBLOBs.setId(v.getId());
|
||||
apiScenarioWithBLOBs.setVersionId(v.getVersionId());
|
||||
toUpdateList.add(apiScenarioWithBLOBs);
|
||||
}
|
||||
});
|
||||
|
@ -634,22 +647,14 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
String modulePath = datum.getModulePath();
|
||||
ApiScenarioModule scenarioModule = map.get(modulePath);
|
||||
if (chooseModule != null) {
|
||||
if (chooseModule.getParentId() == null) {
|
||||
chooseModule.setParentId("root");
|
||||
}
|
||||
String chooseModuleParentId = chooseModule.getParentId();
|
||||
String chooseModuleParentId = getChooseModuleParentId(chooseModule);
|
||||
String chooseModulePath = getChooseModulePath(idPathMap, chooseModule, chooseModuleParentId);
|
||||
//导入时选了模块,且接口有模块的
|
||||
if (StringUtils.isNotBlank(modulePath)) {
|
||||
//选中模块的同级模块集合,用于和场景的全路径做对比
|
||||
List<ApiScenarioModule> parentModuleList = pidChildrenMap.get(chooseModuleParentId);
|
||||
String s;
|
||||
if (chooseModuleParentId.equals("root")) {
|
||||
s = "/" + chooseModule.getName();
|
||||
} else {
|
||||
s = idPathMap.get(chooseModuleParentId);
|
||||
}
|
||||
//场景的全部路径的集合
|
||||
tagTree = getTagTree(s + modulePath);
|
||||
tagTree = getTagTree(chooseModulePath + modulePath);
|
||||
|
||||
ApiScenarioModule chooseModuleOne = JSON.parseObject(JSON.toJSONString(chooseModule), ApiScenarioModule.class);
|
||||
ApiScenarioModule minModule = getMinModule(tagTree, parentModuleList, chooseModuleOne, pidChildrenMap, map, idPathMap, idModuleMap);
|
||||
|
@ -689,6 +694,24 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
}
|
||||
}
|
||||
|
||||
private String getChooseModuleParentId(ApiScenarioModuleDTO chooseModule) {
|
||||
if (chooseModule.getParentId() == null) {
|
||||
chooseModule.setParentId("root");
|
||||
}
|
||||
String chooseModuleParentId = chooseModule.getParentId();
|
||||
return chooseModuleParentId;
|
||||
}
|
||||
|
||||
private String getChooseModulePath(Map<String, String> idPathMap, ApiScenarioModuleDTO chooseModule, String chooseModuleParentId) {
|
||||
String s;
|
||||
if (chooseModuleParentId.equals("root")) {
|
||||
s = "/" + chooseModule.getName();
|
||||
} else {
|
||||
s = idPathMap.get(chooseModuleParentId);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private String[] getTagTree(String modulePath) {
|
||||
String substring = modulePath.substring(0, 1);
|
||||
if (substring.equals("/")) {
|
||||
|
@ -812,7 +835,7 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
idChildrenMap.put(scenarioModuleDTO.getId(), scenarioModuleDTO.getChildren());
|
||||
}
|
||||
} else {
|
||||
if (i == nodeTreeByProjectId.size() && idChildrenMap.size() == 0) {
|
||||
if (childrenList == null) {
|
||||
pidChildrenMap.put(scenarioModuleDTO.getId(), new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue