fix(接口测试): 接口场景导入版本修改
--user=郭雨琦 --bug=1014708 --bug=1014732 --bug=1014731 --bug=1014727 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001014708 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001014732 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001014731 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001014727
This commit is contained in:
parent
3ccd5a055b
commit
ef15966ffd
|
@ -1335,15 +1335,19 @@ public class ApiAutomationService {
|
|||
_importCreate(sameList, batchMapper, extApiScenarioMapper, scenarioWithBLOBs, apiTestImportRequest, apiTestCaseMapper, apiDefinitionMapper);
|
||||
} else if (StringUtils.equals("incrementalMerge", apiTestImportRequest.getModeId())) {
|
||||
if (CollectionUtils.isEmpty(sameList)) {
|
||||
scenarioWithBLOBs.setOrder(getImportNextOrder(request.getProjectId()));
|
||||
if (scenarioWithBLOBs.getVersionId() == null || scenarioWithBLOBs.getVersionId().equals("new")) {
|
||||
scenarioWithBLOBs.setLatest(apiTestImportRequest.getVersionId().equals(apiTestImportRequest.getDefaultVersion()));
|
||||
} else {
|
||||
scenarioWithBLOBs.setOrder(getImportNextOrder(request.getProjectId()));
|
||||
scenarioWithBLOBs.setRefId(scenarioWithBLOBs.getId());
|
||||
scenarioWithBLOBs.setLatest(true);
|
||||
}
|
||||
scenarioWithBLOBs.setId(UUID.randomUUID().toString());
|
||||
scenarioWithBLOBs.setRefId(scenarioWithBLOBs.getId());
|
||||
if (StringUtils.isNotEmpty(apiTestImportRequest.getVersionId())) {
|
||||
scenarioWithBLOBs.setVersionId(apiTestImportRequest.getVersionId());
|
||||
} else {
|
||||
scenarioWithBLOBs.setVersionId(apiTestImportRequest.getDefaultVersion());
|
||||
}
|
||||
scenarioWithBLOBs.setLatest(true);
|
||||
checkReferenceCase(scenarioWithBLOBs, apiTestCaseMapper, apiDefinitionMapper);
|
||||
batchMapper.insert(scenarioWithBLOBs);
|
||||
// 存储依赖关系
|
||||
|
@ -1375,6 +1379,9 @@ public class ApiAutomationService {
|
|||
|
||||
String defaultVersion = extProjectVersionMapper.getDefaultVersion(request.getProjectId());
|
||||
request.setDefaultVersion(defaultVersion);
|
||||
if (request.getVersionId() == null) {
|
||||
request.setVersionId(defaultVersion);
|
||||
}
|
||||
|
||||
UpdateScenarioModuleDTO updateScenarioModuleDTO = apiScenarioModuleService.checkScenarioModule(request, initData, StringUtils.equals("fullCoverage", request.getModeId()), request.getCoverModule());
|
||||
List<ApiScenarioModule> moduleList = updateScenarioModuleDTO.getModuleList();
|
||||
|
@ -1404,7 +1411,9 @@ public class ApiAutomationService {
|
|||
if (item.getName().length() > 255) {
|
||||
item.setName(item.getName().substring(0, 255));
|
||||
}
|
||||
item.setNum(num);
|
||||
if (item.getVersionId() == null || !item.getVersionId().equals("new")) {
|
||||
item.setNum(num);
|
||||
}
|
||||
if (BooleanUtils.isFalse(request.getOpenCustomNum())) {
|
||||
// 如果未开启,即使有自定值也直接覆盖
|
||||
item.setCustomNum(String.valueOf(num));
|
||||
|
|
|
@ -803,17 +803,21 @@ public class ApiDefinitionService {
|
|||
_importCreate(collect, batchMapper, apiTestCaseMapper, apiDefinition, extApiDefinitionMapper, apiTestImportRequest, cases, mocks);
|
||||
} else if (StringUtils.equals("incrementalMerge", apiTestImportRequest.getModeId())) {
|
||||
if (CollectionUtils.isEmpty(collect)) {
|
||||
//postman 可能含有前置脚本,接口定义去掉脚本
|
||||
apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId()));
|
||||
String originId = apiDefinition.getId();
|
||||
//postman 可能含有前置脚本,接口定义去掉脚本
|
||||
if (apiDefinition.getVersionId() == null || apiDefinition.getVersionId().equals("new")) {
|
||||
apiDefinition.setLatest(apiTestImportRequest.getVersionId().equals(apiTestImportRequest.getDefaultVersion()));
|
||||
} else {
|
||||
apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId()));
|
||||
apiDefinition.setRefId(apiDefinition.getId());
|
||||
apiDefinition.setLatest(true); // 新增的接口 latest = true
|
||||
}
|
||||
apiDefinition.setId(UUID.randomUUID().toString());
|
||||
apiDefinition.setRefId(apiDefinition.getId());
|
||||
if (StringUtils.isNotEmpty(apiTestImportRequest.getVersionId())) {
|
||||
apiDefinition.setVersionId(apiTestImportRequest.getVersionId());
|
||||
} else {
|
||||
apiDefinition.setVersionId(apiTestImportRequest.getDefaultVersion());
|
||||
}
|
||||
apiDefinition.setLatest(true); // 新增的接口 latest = true
|
||||
batchMapper.insert(apiDefinition);
|
||||
String requestStr = setImportHashTree(apiDefinition);
|
||||
|
||||
|
@ -917,7 +921,6 @@ public class ApiDefinitionService {
|
|||
apiDefinition.setOriginalState(existApi.getOriginalState());
|
||||
apiDefinition.setCaseStatus(existApi.getCaseStatus());
|
||||
apiDefinition.setNum(existApi.getNum()); //id 不变
|
||||
apiDefinition.setRefId(existApi.getRefId());
|
||||
if (existApi.getRefId() != null) {
|
||||
apiDefinition.setRefId(existApi.getRefId());
|
||||
} else {
|
||||
|
@ -1416,6 +1419,9 @@ public class ApiDefinitionService {
|
|||
currentApiOrder.remove();
|
||||
String defaultVersion = extProjectVersionMapper.getDefaultVersion(request.getProjectId());
|
||||
request.setDefaultVersion(defaultVersion);
|
||||
if (request.getVersionId() == null) {
|
||||
request.setVersionId(defaultVersion);
|
||||
}
|
||||
List<ApiDefinitionWithBLOBs> initData = apiImport.getData();
|
||||
|
||||
Project project = projectMapper.selectByPrimaryKey(request.getProjectId());
|
||||
|
@ -1446,14 +1452,20 @@ public class ApiDefinitionService {
|
|||
apiModuleMapper.insert(apiModule);
|
||||
}
|
||||
}
|
||||
|
||||
//如果需要导入的数据为空。此时清空mock信息
|
||||
if (data.isEmpty()) {
|
||||
apiImport.getMocks().clear();
|
||||
}
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
ApiDefinitionWithBLOBs item = data.get(i);
|
||||
this.setModule(item);
|
||||
if (item.getName().length() > 255) {
|
||||
item.setName(item.getName().substring(0, 255));
|
||||
}
|
||||
item.setNum(num++);
|
||||
//如果是创建版本数据,则num和其他版本数据一致
|
||||
if (item.getVersionId() == null || !item.getVersionId().equals("new")) {
|
||||
item.setNum(num++);
|
||||
}
|
||||
//如果EsbData需要存储,则需要进行接口是否更新的判断
|
||||
if (apiImport.getEsbApiParamsMap() != null) {
|
||||
String apiId = item.getId();
|
||||
|
|
|
@ -619,14 +619,9 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
if (apiImport.getEsbApiParamsMap() != null) {
|
||||
fullCoverage = true;
|
||||
}
|
||||
Set<String> versionSet = new HashSet<>();
|
||||
|
||||
if (fullCoverage) {
|
||||
setFullVersionSet(request, versionSet);
|
||||
} else {
|
||||
String updateVersionId = getUpdateVersionId(request);
|
||||
versionSet.add(updateVersionId);
|
||||
}
|
||||
String updateVersionId = getUpdateVersionId(request);
|
||||
String versionId = getVersionId(request);
|
||||
|
||||
//需要新增的模块,key 为模块路径
|
||||
Map<String, ApiModule> moduleMap = new HashMap<>();
|
||||
|
@ -665,29 +660,87 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
//处理模块
|
||||
setModule(moduleMap, pidChildrenMap, idPathMap, idModuleMap, optionData, chooseModule);
|
||||
//系统内重复的数据
|
||||
repeatApiDefinitionWithBLOBs = extApiDefinitionMapper.selectRepeatByBLOBs(optionData, projectId, versionSet);
|
||||
repeatApiDefinitionWithBLOBs = extApiDefinitionMapper.selectRepeatByBLOBs(optionData, projectId);
|
||||
//处理数据
|
||||
if (urlRepeat) {
|
||||
moduleMap = getRepeatApiModuleMap(fullCoverage, fullCoverageApi, moduleMap, toUpdateList, idPathMap, chooseModule, optionData, repeatApiDefinitionWithBLOBs);
|
||||
//最后在整个体统内检查一遍
|
||||
Map<String, ApiDefinitionWithBLOBs> methodPathMap;
|
||||
Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap;
|
||||
//按照原来的顺序
|
||||
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));
|
||||
ApiModuleDTO finalChooseModule = chooseModule;
|
||||
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().filter(t -> t.getModuleId().equals(finalChooseModule.getId())).collect(Collectors.groupingBy(t -> t.getName() + t.getMethod() + t.getPath() + t.getModulePath()));
|
||||
} else {
|
||||
methodPathMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + t.getMethod() + t.getPath() + (t.getModulePath() == null ? "" : t.getModulePath()), api -> api));
|
||||
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getName() + t.getMethod() + t.getPath() + t.getModulePath()));
|
||||
}
|
||||
|
||||
//覆盖接口
|
||||
if (fullCoverage) {
|
||||
//允许覆盖模块,用导入的重复数据的最后一条覆盖查询的所有重复数据
|
||||
if (fullCoverageApi) {
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
startCoverModule(toUpdateList, optionData, methodPathMap, repeatDataMap, updateVersionId);
|
||||
}
|
||||
} else {
|
||||
//覆盖但不覆盖模块
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
moduleMap = judgeModuleMap(moduleMap, methodPathMap, repeatDataMap);
|
||||
startCover(toUpdateList, optionData, methodPathMap, repeatDataMap, updateVersionId);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//不覆盖,同一接口不做更新
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
removeSameData(repeatDataMap, methodPathMap, optionData, moduleMap, versionId);
|
||||
}
|
||||
} //最后在整个体统内检查一遍
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
Map<String, List<ApiDefinitionWithBLOBs>> repeatMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getName() + t.getMethod() + t.getPath() + t.getModulePath()));
|
||||
Map<String, ApiDefinitionWithBLOBs> optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + t.getMethod() + t.getPath() + t.getModulePath(), api -> api));
|
||||
if (fullCoverage) {
|
||||
startCover(toUpdateList, optionData, optionMap, repeatMap);
|
||||
startCover(toUpdateList, optionData, optionMap, repeatMap, updateVersionId);
|
||||
} else {
|
||||
//不覆盖,同一接口不做更新
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
removeSameData(repeatMap, optionMap, optionData, moduleMap);
|
||||
removeSameData(repeatMap, optionMap, optionData, moduleMap, versionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
moduleMap = getOnlyApiModuleMap(fullCoverage, fullCoverageApi, moduleMap, toUpdateList, optionData, repeatApiDefinitionWithBLOBs);
|
||||
Map<String, ApiDefinitionWithBLOBs> methodPathMap;
|
||||
Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getMethod() + t.getPath()));
|
||||
|
||||
//按照原来的顺序
|
||||
methodPathMap = optionData.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), api -> api));
|
||||
|
||||
if (fullCoverage) {
|
||||
if (fullCoverageApi) {
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
startCoverModule(toUpdateList, optionData, methodPathMap, repeatDataMap, updateVersionId);
|
||||
}
|
||||
} else {
|
||||
//不覆盖模块
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
if (repeatDataMap.size() >= methodPathMap.size()) {
|
||||
//导入文件没有新增接口无需创建接口模块
|
||||
moduleMap = new HashMap<>();
|
||||
}
|
||||
startCover(toUpdateList, optionData, methodPathMap, repeatDataMap, updateVersionId);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//不覆盖,同一接口不做更新
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
removeSameData(repeatDataMap, methodPathMap, optionData, moduleMap, versionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//去重,TCP,SQL,DUBBO 模块下名称唯一
|
||||
removeRepeat(data, fullCoverage, optionData);
|
||||
removeRepeatOrigin(data, fullCoverage, optionData);
|
||||
|
||||
//处理模块
|
||||
setModule(moduleMap, pidChildrenMap, idPathMap, idModuleMap, optionData, chooseModule);
|
||||
|
@ -696,19 +749,43 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
List<String> nameList = optionData.stream().map(ApiDefinitionWithBLOBs::getName).collect(Collectors.toList());
|
||||
|
||||
//获取系统内重复数据
|
||||
repeatApiDefinitionWithBLOBs = extApiDefinitionMapper.selectRepeatByProtocol(nameList, protocol, versionSet);
|
||||
repeatApiDefinitionWithBLOBs = extApiDefinitionMapper.selectRepeatByProtocol(nameList, protocol);
|
||||
|
||||
moduleMap = getOtherApiModuleMap(fullCoverage, fullCoverageApi, chooseModuleId, moduleMap, toUpdateList, idPathMap, chooseModule, optionData, repeatApiDefinitionWithBLOBs);
|
||||
Map<String, ApiDefinitionWithBLOBs> repeatDataMap = null;
|
||||
|
||||
Map<String, ApiDefinitionWithBLOBs> nameModuleMap = null;
|
||||
if (chooseModule != null) {
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
String chooseModuleParentId = getChooseModuleParentId(chooseModule);
|
||||
String chooseModulePath = getChooseModulePath(idPathMap, chooseModule, chooseModuleParentId);
|
||||
nameModuleMap = 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));
|
||||
}
|
||||
} else {
|
||||
nameModuleMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + (t.getModulePath() == null ? "" : t.getModulePath()), api -> api));
|
||||
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), api -> api));
|
||||
}
|
||||
|
||||
//处理数据
|
||||
if (fullCoverage) {
|
||||
if (fullCoverageApi) {
|
||||
coverModule(toUpdateList, nameModuleMap, repeatDataMap, updateVersionId);
|
||||
} else {
|
||||
moduleMap = cover(moduleMap, toUpdateList, nameModuleMap, repeatDataMap, updateVersionId);
|
||||
}
|
||||
} else {
|
||||
//不覆盖
|
||||
removeRepeat(optionData, nameModuleMap, repeatDataMap, moduleMap, versionId);
|
||||
}
|
||||
//系统内检查重复
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
Map<String, ApiDefinitionWithBLOBs> repeatMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), api -> api));
|
||||
Map<String, ApiDefinitionWithBLOBs> optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), api -> api));
|
||||
if (fullCoverage) {
|
||||
cover(moduleMap, toUpdateList, optionMap, repeatMap);
|
||||
cover(moduleMap, toUpdateList, optionMap, repeatMap, updateVersionId);
|
||||
} else {
|
||||
//不覆盖,同一接口不做更新
|
||||
removeRepeat(optionData, optionMap, repeatMap, moduleMap);
|
||||
removeRepeat(optionData, optionMap, repeatMap, moduleMap, versionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -716,36 +793,6 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
return getUpdateApiModuleDTO(moduleMap, toUpdateList, optionData);
|
||||
}
|
||||
|
||||
private Map<String, ApiModule> getOtherApiModuleMap(Boolean fullCoverage, Boolean fullCoverageApi, String chooseModuleId, Map<String, ApiModule> moduleMap, List<ApiDefinitionWithBLOBs> toUpdateList, Map<String, String> idPathMap, ApiModuleDTO chooseModule, List<ApiDefinitionWithBLOBs> optionData, List<ApiDefinitionWithBLOBs> repeatApiDefinitionWithBLOBs) {
|
||||
Map<String, ApiDefinitionWithBLOBs> repeatDataMap = null;
|
||||
|
||||
Map<String, ApiDefinitionWithBLOBs> nameModuleMap = null;
|
||||
if (chooseModule != null) {
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
String chooseModuleParentId = getChooseModuleParentId(chooseModule);
|
||||
String chooseModulePath = getChooseModulePath(idPathMap, chooseModule, chooseModuleParentId);
|
||||
nameModuleMap = 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));
|
||||
}
|
||||
} else {
|
||||
nameModuleMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + (t.getModulePath() == null ? "" : t.getModulePath()), api -> api));
|
||||
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), api -> api));
|
||||
}
|
||||
|
||||
//处理数据
|
||||
if (fullCoverage) {
|
||||
if (fullCoverageApi) {
|
||||
coverModule(toUpdateList, nameModuleMap, repeatDataMap);
|
||||
} else {
|
||||
moduleMap = cover(moduleMap, toUpdateList, nameModuleMap, repeatDataMap);
|
||||
}
|
||||
} else {
|
||||
//不覆盖
|
||||
removeRepeat(optionData, nameModuleMap, repeatDataMap, moduleMap);
|
||||
}
|
||||
return moduleMap;
|
||||
}
|
||||
|
||||
|
||||
private UpdateApiModuleDTO getUpdateApiModuleDTO(Map<String, ApiModule> moduleMap, List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionData) {
|
||||
UpdateApiModuleDTO updateApiModuleDTO = new UpdateApiModuleDTO();
|
||||
|
@ -755,7 +802,9 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
return updateApiModuleDTO;
|
||||
}
|
||||
|
||||
private void removeRepeat(List<ApiDefinitionWithBLOBs> optionData, Map<String, ApiDefinitionWithBLOBs> nameModuleMap, Map<String, ApiDefinitionWithBLOBs> repeatDataMap, Map<String, ApiModule> moduleMap) {
|
||||
private void removeRepeat(List<ApiDefinitionWithBLOBs> optionData, Map<String, ApiDefinitionWithBLOBs> nameModuleMap,
|
||||
Map<String, ApiDefinitionWithBLOBs> repeatDataMap, Map<String, ApiModule> moduleMap,
|
||||
String versionId) {
|
||||
if (nameModuleMap != null) {
|
||||
Map<String, List<ApiDefinitionWithBLOBs>> moduleOptionData = optionData.stream().collect(Collectors.groupingBy(ApiDefinition::getModulePath));
|
||||
Map<String, ApiDefinitionWithBLOBs> finalNameModuleMap = nameModuleMap;
|
||||
|
@ -769,13 +818,25 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
removeModulePath(moduleMap, moduleOptionData, modulePath);
|
||||
moduleDatas.remove(apiDefinitionWithBLOBs);
|
||||
}
|
||||
optionData.remove(apiDefinitionWithBLOBs);
|
||||
//不覆盖选择版本,如果被选版本有同接口,不导入,否则创建新版本接口
|
||||
if (v.getVersionId().equals(versionId)) {
|
||||
optionData.remove(apiDefinitionWithBLOBs);
|
||||
} else {
|
||||
//这里是为了标识当前数据是需要创建版本的,不是全新增的数据
|
||||
apiDefinitionWithBLOBs.setVersionId("new");
|
||||
apiDefinitionWithBLOBs.setNum(v.getNum());
|
||||
apiDefinitionWithBLOBs.setStatus(v.getStatus());
|
||||
apiDefinitionWithBLOBs.setOrder(v.getOrder());
|
||||
apiDefinitionWithBLOBs.setRefId(v.getRefId());
|
||||
apiDefinitionWithBLOBs.setLatest(v.getLatest());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, ApiModule> cover(Map<String, ApiModule> moduleMap, List<ApiDefinitionWithBLOBs> toUpdateList, Map<String, ApiDefinitionWithBLOBs> nameModuleMap, Map<String, ApiDefinitionWithBLOBs> repeatDataMap) {
|
||||
private Map<String, ApiModule> cover(Map<String, ApiModule> moduleMap, List<ApiDefinitionWithBLOBs> toUpdateList,
|
||||
Map<String, ApiDefinitionWithBLOBs> nameModuleMap, Map<String, ApiDefinitionWithBLOBs> repeatDataMap, String updateVersionId) {
|
||||
//覆盖但不覆盖模块
|
||||
if (nameModuleMap != null) {
|
||||
//导入文件没有新增接口无需创建接口模块
|
||||
|
@ -785,7 +846,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = finalNameModuleMap.get(k);
|
||||
if (apiDefinitionWithBLOBs != null) {
|
||||
apiDefinitionWithBLOBs.setId(v.getId());
|
||||
apiDefinitionWithBLOBs.setVersionId(v.getVersionId());
|
||||
apiDefinitionWithBLOBs.setVersionId(updateVersionId);
|
||||
apiDefinitionWithBLOBs.setModuleId(v.getModuleId());
|
||||
apiDefinitionWithBLOBs.setModulePath(v.getModulePath());
|
||||
apiDefinitionWithBLOBs.setNum(v.getNum());
|
||||
|
@ -793,6 +854,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
apiDefinitionWithBLOBs.setOrder(v.getOrder());
|
||||
apiDefinitionWithBLOBs.setRefId(v.getRefId());
|
||||
apiDefinitionWithBLOBs.setLatest(v.getLatest());
|
||||
apiDefinitionWithBLOBs.setCreateTime(v.getCreateTime());
|
||||
toUpdateList.add(apiDefinitionWithBLOBs);
|
||||
}
|
||||
});
|
||||
|
@ -817,26 +879,21 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
return moduleMap;
|
||||
}
|
||||
|
||||
private void coverModule(List<ApiDefinitionWithBLOBs> toUpdateList, Map<String, ApiDefinitionWithBLOBs> nameModuleMap, Map<String, ApiDefinitionWithBLOBs> repeatDataMap) {
|
||||
private void coverModule(List<ApiDefinitionWithBLOBs> toUpdateList, Map<String, ApiDefinitionWithBLOBs> nameModuleMap, Map<String, ApiDefinitionWithBLOBs> repeatDataMap, String updateVersionId) {
|
||||
if (nameModuleMap != null) {
|
||||
Map<String, ApiDefinitionWithBLOBs> finalNameModuleMap = nameModuleMap;
|
||||
repeatDataMap.forEach((k, v) -> {
|
||||
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = finalNameModuleMap.get(k);
|
||||
if (apiDefinitionWithBLOBs != null) {
|
||||
apiDefinitionWithBLOBs.setId(v.getId());
|
||||
apiDefinitionWithBLOBs.setVersionId(v.getVersionId());
|
||||
apiDefinitionWithBLOBs.setNum(v.getNum());
|
||||
apiDefinitionWithBLOBs.setStatus(v.getStatus());
|
||||
apiDefinitionWithBLOBs.setOrder(v.getOrder());
|
||||
apiDefinitionWithBLOBs.setRefId(v.getRefId());
|
||||
apiDefinitionWithBLOBs.setLatest(v.getLatest());
|
||||
setApiParam(apiDefinitionWithBLOBs, updateVersionId, v);
|
||||
toUpdateList.add(apiDefinitionWithBLOBs);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void removeRepeat(List<ApiDefinitionWithBLOBs> data, Boolean fullCoverage, List<ApiDefinitionWithBLOBs> optionData) {
|
||||
private void removeRepeatOrigin(List<ApiDefinitionWithBLOBs> data, Boolean fullCoverage, List<ApiDefinitionWithBLOBs> optionData) {
|
||||
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) -> {
|
||||
|
@ -849,75 +906,6 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
}
|
||||
}
|
||||
|
||||
private Map<String, ApiModule> getOnlyApiModuleMap(Boolean fullCoverage, Boolean fullCoverageApi, Map<String, ApiModule> moduleMap, List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionData, List<ApiDefinitionWithBLOBs> repeatApiDefinitionWithBLOBs) {
|
||||
Map<String, ApiDefinitionWithBLOBs> methodPathMap;
|
||||
Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getMethod() + t.getPath()));
|
||||
|
||||
//按照原来的顺序
|
||||
methodPathMap = optionData.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), api -> api));
|
||||
|
||||
if (fullCoverage) {
|
||||
if (fullCoverageApi) {
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
startCoverModule(toUpdateList, optionData, methodPathMap, repeatDataMap);
|
||||
}
|
||||
} else {
|
||||
//不覆盖模块
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
if (repeatDataMap.size() >= methodPathMap.size()) {
|
||||
//导入文件没有新增接口无需创建接口模块
|
||||
moduleMap = new HashMap<>();
|
||||
}
|
||||
startCover(toUpdateList, optionData, methodPathMap, repeatDataMap);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//不覆盖,同一接口不做更新
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
removeSameData(repeatDataMap, methodPathMap, optionData, moduleMap);
|
||||
}
|
||||
}
|
||||
return moduleMap;
|
||||
}
|
||||
|
||||
private Map<String, ApiModule> getRepeatApiModuleMap(Boolean fullCoverage, Boolean fullCoverageApi, Map<String, ApiModule> moduleMap, List<ApiDefinitionWithBLOBs> toUpdateList, Map<String, String> idPathMap, ApiModuleDTO chooseModule, List<ApiDefinitionWithBLOBs> optionData, List<ApiDefinitionWithBLOBs> repeatApiDefinitionWithBLOBs) {
|
||||
Map<String, ApiDefinitionWithBLOBs> methodPathMap;
|
||||
Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap;
|
||||
//按照原来的顺序
|
||||
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));
|
||||
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().filter(t -> t.getModuleId().equals(chooseModule.getId())).collect(Collectors.groupingBy(t -> t.getName() + t.getMethod() + t.getPath() + t.getModulePath()));
|
||||
} else {
|
||||
methodPathMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + t.getMethod() + t.getPath() + (t.getModulePath() == null ? "" : t.getModulePath()), api -> api));
|
||||
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getName() + t.getMethod() + t.getPath() + t.getModulePath()));
|
||||
}
|
||||
|
||||
|
||||
//覆盖接口
|
||||
if (fullCoverage) {
|
||||
//允许覆盖模块,用导入的重复数据的最后一条覆盖查询的所有重复数据
|
||||
if (fullCoverageApi) {
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
startCoverModule(toUpdateList, optionData, methodPathMap, repeatDataMap);
|
||||
}
|
||||
} else {
|
||||
//覆盖但不覆盖模块
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
moduleMap = judgeModuleMap(moduleMap, methodPathMap, repeatDataMap);
|
||||
startCover(toUpdateList, optionData, methodPathMap, repeatDataMap);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//不覆盖,同一接口不做更新
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
removeSameData(repeatDataMap, methodPathMap, optionData, moduleMap);
|
||||
}
|
||||
}
|
||||
return moduleMap;
|
||||
}
|
||||
|
||||
private void removeHTTPRepeat(List<ApiDefinitionWithBLOBs> data, Boolean fullCoverage, boolean urlRepeat, List<ApiDefinitionWithBLOBs> optionData) {
|
||||
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()));
|
||||
|
@ -944,34 +932,29 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
}
|
||||
}
|
||||
|
||||
private void setFullVersionSet(ApiTestImportRequest request, Set<String> versionSet) {
|
||||
String creatVersionId;
|
||||
if (request.getVersionId() != null) {
|
||||
creatVersionId = request.getVersionId();
|
||||
private String getVersionId(ApiTestImportRequest request) {
|
||||
String versionId;
|
||||
if (request.getVersionId() == null) {
|
||||
versionId = request.getDefaultVersion();
|
||||
} else {
|
||||
creatVersionId = request.getDefaultVersion();
|
||||
versionId = request.getVersionId();
|
||||
}
|
||||
versionSet.add(creatVersionId);
|
||||
return versionId;
|
||||
}
|
||||
|
||||
private String getUpdateVersionId(ApiTestImportRequest request) {
|
||||
String updateVersionId;
|
||||
if (request.getUpdateVersionId() != null) {
|
||||
updateVersionId = request.getUpdateVersionId();
|
||||
} else {
|
||||
updateVersionId = request.getDefaultVersion();
|
||||
}
|
||||
versionSet.add(updateVersionId);
|
||||
}
|
||||
|
||||
private String getUpdateVersionId(ApiTestImportRequest request) {
|
||||
String updateVersionId;
|
||||
if (request.getVersionId() == null) {
|
||||
updateVersionId = request.getDefaultVersion();
|
||||
} else {
|
||||
updateVersionId = request.getVersionId();
|
||||
}
|
||||
return updateVersionId;
|
||||
}
|
||||
|
||||
private void removeSameData(Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap, Map<String, ApiDefinitionWithBLOBs> methodPathMap, List<ApiDefinitionWithBLOBs> optionData, Map<String, ApiModule> moduleMap) {
|
||||
private void removeSameData(Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap, Map<String, ApiDefinitionWithBLOBs> methodPathMap,
|
||||
List<ApiDefinitionWithBLOBs> optionData, Map<String, ApiModule> moduleMap, String versionId) {
|
||||
|
||||
Map<String, List<ApiDefinitionWithBLOBs>> moduleOptionData = optionData.stream().collect(Collectors.groupingBy(ApiDefinition::getModulePath));
|
||||
BiConsumer<String, List<ApiDefinitionWithBLOBs>> stringListBiConsumer = (k, v) -> {
|
||||
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = methodPathMap.get(k);
|
||||
|
@ -983,13 +966,35 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
removeModulePath(moduleMap, moduleOptionData, modulePath);
|
||||
moduleDatas.remove(apiDefinitionWithBLOBs);
|
||||
}
|
||||
|
||||
optionData.remove(apiDefinitionWithBLOBs);
|
||||
//不覆盖选择版本,如果被选版本有同接口,不导入,否则创建新版本接口
|
||||
List<ApiDefinitionWithBLOBs> sameVersionList = v.stream().filter(t -> t.getVersionId().equals(versionId)).collect(Collectors.toList());
|
||||
if (!sameVersionList.isEmpty()) {
|
||||
optionData.remove(apiDefinitionWithBLOBs);
|
||||
} else {
|
||||
for (ApiDefinitionWithBLOBs definitionWithBLOBs : v) {
|
||||
apiDefinitionWithBLOBs.setVersionId("new");
|
||||
apiDefinitionWithBLOBs.setNum(definitionWithBLOBs.getNum());
|
||||
apiDefinitionWithBLOBs.setStatus(definitionWithBLOBs.getStatus());
|
||||
apiDefinitionWithBLOBs.setOrder(definitionWithBLOBs.getOrder());
|
||||
apiDefinitionWithBLOBs.setRefId(definitionWithBLOBs.getRefId());
|
||||
apiDefinitionWithBLOBs.setLatest(definitionWithBLOBs.getLatest());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
repeatDataMap.forEach(stringListBiConsumer);
|
||||
}
|
||||
|
||||
private void setApiParam(ApiDefinitionWithBLOBs apiDefinitionWithBLOBs, String versionId, ApiDefinitionWithBLOBs definitionWithBLOBs) {
|
||||
apiDefinitionWithBLOBs.setVersionId(versionId);
|
||||
apiDefinitionWithBLOBs.setNum(definitionWithBLOBs.getNum());
|
||||
apiDefinitionWithBLOBs.setStatus(definitionWithBLOBs.getStatus());
|
||||
apiDefinitionWithBLOBs.setOrder(definitionWithBLOBs.getOrder());
|
||||
apiDefinitionWithBLOBs.setRefId(definitionWithBLOBs.getRefId());
|
||||
apiDefinitionWithBLOBs.setLatest(definitionWithBLOBs.getLatest());
|
||||
apiDefinitionWithBLOBs.setCreateTime(definitionWithBLOBs.getCreateTime());
|
||||
}
|
||||
|
||||
private void removeModulePath(Map<String, ApiModule> moduleMap, Map<String, List<ApiDefinitionWithBLOBs>> moduleOptionData, String modulePath) {
|
||||
if (StringUtils.isBlank(modulePath)) {
|
||||
return;
|
||||
|
@ -1004,7 +1009,9 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
|
||||
}
|
||||
|
||||
private void startCoverModule(List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionData, Map<String, ApiDefinitionWithBLOBs> methodPathMap, Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap) {
|
||||
private void startCoverModule(List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionData,
|
||||
Map<String, ApiDefinitionWithBLOBs> methodPathMap, Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap,
|
||||
String updateVersionId) {
|
||||
List<ApiDefinitionWithBLOBs> coverApiList = new ArrayList<>();
|
||||
repeatDataMap.forEach((k, v) -> {
|
||||
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = methodPathMap.get(k);
|
||||
|
@ -1013,12 +1020,13 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
ApiDefinitionWithBLOBs api = new ApiDefinitionWithBLOBs();
|
||||
BeanUtils.copyBean(api, apiDefinitionWithBLOBs);
|
||||
api.setId(definitionWithBLOBs.getId());
|
||||
api.setVersionId(definitionWithBLOBs.getVersionId());
|
||||
api.setVersionId(updateVersionId);
|
||||
api.setOrder(definitionWithBLOBs.getOrder());
|
||||
api.setRefId(apiDefinitionWithBLOBs.getRefId());
|
||||
api.setLatest(apiDefinitionWithBLOBs.getLatest());
|
||||
api.setNum(definitionWithBLOBs.getNum());
|
||||
api.setStatus(definitionWithBLOBs.getStatus());
|
||||
api.setCreateTime(definitionWithBLOBs.getCreateTime());
|
||||
coverApiList.add(api);
|
||||
}
|
||||
optionData.remove(apiDefinitionWithBLOBs);
|
||||
|
@ -1027,7 +1035,9 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
buildOtherParam(toUpdateList, optionData, coverApiList);
|
||||
}
|
||||
|
||||
private void startCover(List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionData, Map<String, ApiDefinitionWithBLOBs> methodPathMap, Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap) {
|
||||
private void startCover(List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionData,
|
||||
Map<String, ApiDefinitionWithBLOBs> methodPathMap, Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap,
|
||||
String updateVersionId) {
|
||||
List<ApiDefinitionWithBLOBs> coverApiList = new ArrayList<>();
|
||||
repeatDataMap.forEach((k, v) -> {
|
||||
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = methodPathMap.get(k);
|
||||
|
@ -1038,12 +1048,13 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
api.setId(definitionWithBLOBs.getId());
|
||||
api.setNum(definitionWithBLOBs.getNum());
|
||||
api.setStatus(definitionWithBLOBs.getStatus());
|
||||
api.setVersionId(definitionWithBLOBs.getVersionId());
|
||||
api.setVersionId(updateVersionId);
|
||||
api.setModuleId(definitionWithBLOBs.getModuleId());
|
||||
api.setModulePath(definitionWithBLOBs.getModulePath());
|
||||
api.setOrder(definitionWithBLOBs.getOrder());
|
||||
api.setRefId(apiDefinitionWithBLOBs.getRefId());
|
||||
api.setLatest(apiDefinitionWithBLOBs.getLatest());
|
||||
api.setCreateTime(definitionWithBLOBs.getCreateTime());
|
||||
coverApiList.add(api);
|
||||
}
|
||||
optionData.remove(apiDefinitionWithBLOBs);
|
||||
|
@ -1068,6 +1079,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
private void buildOtherParam(List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionData, List<ApiDefinitionWithBLOBs> coverApiList) {
|
||||
optionData.addAll(coverApiList);
|
||||
toUpdateList.addAll(coverApiList);
|
||||
|
||||
}
|
||||
|
||||
private List<ApiDefinitionWithBLOBs> setModule(Map<String, ApiModule> moduleMap, Map<String, List<ApiModule>> pidChildrenMap,
|
||||
|
@ -1116,7 +1128,6 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
String chooseModuleParentId = getChooseModuleParentId(chooseModule);
|
||||
//导入时选了模块,且接口有模块的
|
||||
if (StringUtils.isNotBlank(modulePath)) {
|
||||
List<ApiModule> moduleList = pidChildrenMap.get(chooseModuleParentId);
|
||||
pathTree = getPathTree(modulePath);
|
||||
ApiModule chooseModuleOne = JSON.parseObject(JSON.toJSONString(chooseModule), ApiModule.class);
|
||||
ApiModule minModule = getChooseMinModule(pathTree, chooseModuleOne, pidChildrenMap, moduleMap, idPathMap);
|
||||
|
|
|
@ -503,49 +503,21 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
chooseModule = idModuleMap.get(chooseModuleId);
|
||||
}
|
||||
|
||||
Set<String> versionSet = new HashSet<>();
|
||||
|
||||
if (fullCoverage) {
|
||||
setFullVersionSet(request, versionSet);
|
||||
} else {
|
||||
String updateVersionId = getUpdateVersionId(request);
|
||||
versionSet.add(updateVersionId);
|
||||
}
|
||||
|
||||
String updateVersionId = getUpdateVersionId(request);
|
||||
String versionId = getVersionId(request);
|
||||
|
||||
List<ApiScenarioWithBLOBs> optionData = new ArrayList<>();
|
||||
|
||||
//覆盖模式留重复的最后一个,不覆盖留第一个
|
||||
LinkedHashMap<String, List<ApiScenarioWithBLOBs>> nameModuleMapList = data.stream().collect(Collectors.groupingBy(t -> t.getName() + (t.getModulePath() == null ? "" : t.getModulePath()), LinkedHashMap::new, Collectors.toList()));
|
||||
removeRepeat(fullCoverage, optionData, nameModuleMapList);
|
||||
removeRepeatOrigin(fullCoverage, optionData, nameModuleMapList);
|
||||
|
||||
//处理模块
|
||||
setModule(optionData, moduleMap, pidChildrenMap, idPathMap, idModuleMap, chooseModule);
|
||||
List<String> names = optionData.stream().map(ApiScenario::getName).collect(Collectors.toList());
|
||||
//系统内重复的数据
|
||||
List<ApiScenarioWithBLOBs> repeatApiScenarioWithBLOBs = extApiScenarioMapper.selectRepeatByBLOBs(names, projectId, versionSet);
|
||||
List<ApiScenarioWithBLOBs> repeatApiScenarioWithBLOBs = extApiScenarioMapper.selectRepeatByBLOBs(names, projectId);
|
||||
|
||||
moduleMap = getApiScenarioModuleMap(fullCoverage, fullCoverageScenario, moduleMap, toUpdateList, chooseModuleId, idPathMap, chooseModule, optionData, repeatApiScenarioWithBLOBs);
|
||||
|
||||
if (!repeatApiScenarioWithBLOBs.isEmpty()) {
|
||||
Map<String, ApiScenarioWithBLOBs> repeatMap = repeatApiScenarioWithBLOBs.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), scenario -> scenario));
|
||||
Map<String, ApiScenarioWithBLOBs> optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), scenario -> scenario));
|
||||
if (fullCoverage) {
|
||||
startCover(toUpdateList, optionMap, repeatMap);
|
||||
} else {
|
||||
//不覆盖,同一接口不做更新
|
||||
removeRepeat(optionData, optionMap, repeatMap, moduleMap);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateScenarioModuleDTO updateScenarioModuleDTO = new UpdateScenarioModuleDTO();
|
||||
updateScenarioModuleDTO.setModuleList(new ArrayList<>(moduleMap.values()));
|
||||
updateScenarioModuleDTO.setNeedUpdateList(toUpdateList);
|
||||
updateScenarioModuleDTO.setApiScenarioWithBLOBsList(optionData);
|
||||
return updateScenarioModuleDTO;
|
||||
}
|
||||
|
||||
private Map<String, ApiScenarioModule> getApiScenarioModuleMap(Boolean fullCoverage, Boolean fullCoverageScenario, Map<String, ApiScenarioModule> moduleMap, List<ApiScenarioWithBLOBs> toUpdateList, String chooseModuleId, Map<String, String> idPathMap, ApiScenarioModuleDTO chooseModule, List<ApiScenarioWithBLOBs> optionData, List<ApiScenarioWithBLOBs> repeatApiScenarioWithBLOBs) {
|
||||
Map<String, ApiScenarioWithBLOBs> nameModuleMap = null;
|
||||
Map<String, ApiScenarioWithBLOBs> repeatDataMap = null;
|
||||
if (chooseModule != null) {
|
||||
|
@ -562,40 +534,41 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
//处理数据
|
||||
if (fullCoverage) {
|
||||
if (fullCoverageScenario) {
|
||||
startCoverModule(toUpdateList, nameModuleMap, repeatDataMap);
|
||||
startCoverModule(toUpdateList, nameModuleMap, repeatDataMap, updateVersionId);
|
||||
} else {
|
||||
//覆盖但不覆盖模块
|
||||
if (nameModuleMap != null) {
|
||||
//导入文件没有新增场景无需创建接口模块
|
||||
moduleMap = judgeModuleMap(moduleMap, nameModuleMap, repeatDataMap);
|
||||
startCover(toUpdateList, nameModuleMap, repeatDataMap);
|
||||
startCover(toUpdateList, nameModuleMap, repeatDataMap, updateVersionId);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//不覆盖
|
||||
removeRepeat(optionData, nameModuleMap, repeatDataMap, moduleMap);
|
||||
removeRepeat(optionData, nameModuleMap, repeatDataMap, moduleMap, versionId);
|
||||
}
|
||||
return moduleMap;
|
||||
|
||||
if (!repeatApiScenarioWithBLOBs.isEmpty()) {
|
||||
Map<String, ApiScenarioWithBLOBs> repeatMap = repeatApiScenarioWithBLOBs.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), scenario -> scenario));
|
||||
Map<String, ApiScenarioWithBLOBs> optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), scenario -> scenario));
|
||||
if (fullCoverage) {
|
||||
startCover(toUpdateList, optionMap, repeatMap, updateVersionId);
|
||||
} else {
|
||||
//不覆盖,同一接口不做更新
|
||||
removeRepeat(optionData, optionMap, repeatMap, moduleMap, versionId);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateScenarioModuleDTO updateScenarioModuleDTO = new UpdateScenarioModuleDTO();
|
||||
updateScenarioModuleDTO.setModuleList(new ArrayList<>(moduleMap.values()));
|
||||
updateScenarioModuleDTO.setNeedUpdateList(toUpdateList);
|
||||
updateScenarioModuleDTO.setApiScenarioWithBLOBsList(optionData);
|
||||
return updateScenarioModuleDTO;
|
||||
}
|
||||
|
||||
private void setFullVersionSet(ApiTestImportRequest request, Set<String> versionSet) {
|
||||
String creatVersionId;
|
||||
if (request.getVersionId() != null) {
|
||||
creatVersionId = request.getVersionId();
|
||||
} else {
|
||||
creatVersionId = request.getDefaultVersion();
|
||||
}
|
||||
versionSet.add(creatVersionId);
|
||||
String updateVersionId;
|
||||
if (request.getUpdateVersionId() != null) {
|
||||
updateVersionId = request.getUpdateVersionId();
|
||||
} else {
|
||||
updateVersionId = request.getDefaultVersion();
|
||||
}
|
||||
versionSet.add(updateVersionId);
|
||||
}
|
||||
|
||||
private void removeRepeat(List<ApiScenarioWithBLOBs> optionData, Map<String, ApiScenarioWithBLOBs> nameModuleMap, Map<String, ApiScenarioWithBLOBs> repeatDataMap, Map<String, ApiScenarioModule> moduleMap) {
|
||||
private void removeRepeat(List<ApiScenarioWithBLOBs> optionData, Map<String, ApiScenarioWithBLOBs> nameModuleMap,
|
||||
Map<String, ApiScenarioWithBLOBs> repeatDataMap, Map<String, ApiScenarioModule> moduleMap,
|
||||
String versionId) {
|
||||
if (repeatDataMap != null) {
|
||||
Map<String, List<ApiScenarioWithBLOBs>> moduleOptionData = optionData.stream().collect(Collectors.groupingBy(ApiScenario::getModulePath));
|
||||
repeatDataMap.forEach((k, v) -> {
|
||||
|
@ -608,7 +581,18 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
removeModulePath(moduleMap, moduleOptionData, modulePath);
|
||||
moduleDatas.remove(apiScenarioWithBLOBs);
|
||||
}
|
||||
optionData.remove(apiScenarioWithBLOBs);
|
||||
//不覆盖选择版本,如果被选版本有同接口,不导入,否则创建新版本接口
|
||||
if (v.getVersionId().equals(versionId)) {
|
||||
optionData.remove(apiScenarioWithBLOBs);
|
||||
} else {
|
||||
apiScenarioWithBLOBs.setVersionId("new");
|
||||
apiScenarioWithBLOBs.setNum(v.getNum());
|
||||
apiScenarioWithBLOBs.setStatus(v.getStatus());
|
||||
apiScenarioWithBLOBs.setCreateTime(v.getCreateTime());
|
||||
apiScenarioWithBLOBs.setRefId(v.getRefId());
|
||||
apiScenarioWithBLOBs.setOrder(v.getOrder());
|
||||
apiScenarioWithBLOBs.setLatest(v.getLatest());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -628,16 +612,20 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
|
||||
}
|
||||
|
||||
private void startCover(List<ApiScenarioWithBLOBs> toUpdateList, Map<String, ApiScenarioWithBLOBs> nameModuleMap, Map<String, ApiScenarioWithBLOBs> repeatDataMap) {
|
||||
private void startCover(List<ApiScenarioWithBLOBs> toUpdateList, Map<String, ApiScenarioWithBLOBs> nameModuleMap, Map<String, ApiScenarioWithBLOBs> repeatDataMap, String updateVersionId) {
|
||||
repeatDataMap.forEach((k, v) -> {
|
||||
ApiScenarioWithBLOBs apiScenarioWithBLOBs = nameModuleMap.get(k);
|
||||
if (apiScenarioWithBLOBs != null) {
|
||||
apiScenarioWithBLOBs.setId(v.getId());
|
||||
apiScenarioWithBLOBs.setVersionId(v.getVersionId());
|
||||
apiScenarioWithBLOBs.setVersionId(updateVersionId);
|
||||
apiScenarioWithBLOBs.setApiScenarioModuleId(v.getApiScenarioModuleId());
|
||||
apiScenarioWithBLOBs.setModulePath(v.getModulePath());
|
||||
apiScenarioWithBLOBs.setNum(v.getNum());
|
||||
apiScenarioWithBLOBs.setStatus(v.getStatus());
|
||||
apiScenarioWithBLOBs.setCreateTime(v.getCreateTime());
|
||||
apiScenarioWithBLOBs.setRefId(v.getRefId());
|
||||
apiScenarioWithBLOBs.setOrder(v.getOrder());
|
||||
apiScenarioWithBLOBs.setLatest(v.getLatest());
|
||||
toUpdateList.add(apiScenarioWithBLOBs);
|
||||
}
|
||||
});
|
||||
|
@ -660,22 +648,27 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
return moduleMap;
|
||||
}
|
||||
|
||||
private void startCoverModule(List<ApiScenarioWithBLOBs> toUpdateList, Map<String, ApiScenarioWithBLOBs> nameModuleMap, Map<String, ApiScenarioWithBLOBs> repeatDataMap) {
|
||||
private void startCoverModule(List<ApiScenarioWithBLOBs> toUpdateList, Map<String, ApiScenarioWithBLOBs> nameModuleMap,
|
||||
Map<String, ApiScenarioWithBLOBs> repeatDataMap, String updateVersionId) {
|
||||
if (repeatDataMap != null) {
|
||||
repeatDataMap.forEach((k, v) -> {
|
||||
ApiScenarioWithBLOBs apiScenarioWithBLOBs = nameModuleMap.get(k);
|
||||
if (apiScenarioWithBLOBs != null) {
|
||||
apiScenarioWithBLOBs.setId(v.getId());
|
||||
apiScenarioWithBLOBs.setVersionId(v.getVersionId());
|
||||
apiScenarioWithBLOBs.setVersionId(updateVersionId);
|
||||
apiScenarioWithBLOBs.setNum(v.getNum());
|
||||
apiScenarioWithBLOBs.setStatus(v.getStatus());
|
||||
apiScenarioWithBLOBs.setCreateTime(v.getCreateTime());
|
||||
apiScenarioWithBLOBs.setRefId(v.getRefId());
|
||||
apiScenarioWithBLOBs.setOrder(v.getOrder());
|
||||
apiScenarioWithBLOBs.setLatest(v.getLatest());
|
||||
toUpdateList.add(apiScenarioWithBLOBs);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void removeRepeat(Boolean fullCoverage, List<ApiScenarioWithBLOBs> optionData, LinkedHashMap<String, List<ApiScenarioWithBLOBs>> nameModuleMapList) {
|
||||
private void removeRepeatOrigin(Boolean fullCoverage, List<ApiScenarioWithBLOBs> optionData, LinkedHashMap<String, List<ApiScenarioWithBLOBs>> nameModuleMapList) {
|
||||
if (fullCoverage) {
|
||||
nameModuleMapList.forEach((k, v) -> {
|
||||
optionData.add(v.get(v.size() - 1));
|
||||
|
@ -687,12 +680,22 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
}
|
||||
}
|
||||
|
||||
private String getVersionId(ApiTestImportRequest request) {
|
||||
String versionId;
|
||||
if (request.getVersionId() == null) {
|
||||
versionId = request.getDefaultVersion();
|
||||
} else {
|
||||
versionId = request.getVersionId();
|
||||
}
|
||||
return versionId;
|
||||
}
|
||||
|
||||
private String getUpdateVersionId(ApiTestImportRequest request) {
|
||||
String updateVersionId;
|
||||
if (request.getVersionId() == null) {
|
||||
if (request.getUpdateVersionId() == null) {
|
||||
updateVersionId = request.getDefaultVersion();
|
||||
} else {
|
||||
updateVersionId = request.getVersionId();
|
||||
updateVersionId = request.getUpdateVersionId();
|
||||
}
|
||||
return updateVersionId;
|
||||
}
|
||||
|
@ -709,11 +712,8 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
String chooseModulePath = getChooseModulePath(idPathMap, chooseModule, chooseModuleParentId);
|
||||
//导入时选了模块,且接口有模块的
|
||||
if (StringUtils.isNotBlank(modulePath)) {
|
||||
//选中模块的同级模块集合,用于和场景的全路径做对比
|
||||
List<ApiScenarioModule> parentModuleList = pidChildrenMap.get(chooseModuleParentId);
|
||||
//场景的全部路径的集合
|
||||
tagTree = getTagTree(chooseModulePath + modulePath);
|
||||
|
||||
tagTree = getTagTree(modulePath);
|
||||
ApiScenarioModule chooseModuleOne = JSON.parseObject(JSON.toJSONString(chooseModule), ApiScenarioModule.class);
|
||||
ApiScenarioModule minModule = getChooseMinModule(tagTree, chooseModuleOne, pidChildrenMap, map, idPathMap);
|
||||
String id = minModule.getId();
|
||||
|
|
|
@ -93,11 +93,11 @@ public interface ExtApiDefinitionMapper {
|
|||
|
||||
int toBeUpdateApi(@Param("ids") List<String> ids, @Param("toBeUpdate") Boolean toBeUpdate);
|
||||
|
||||
List<ApiDefinitionWithBLOBs> selectRepeatByBLOBs(@Param("blobs") List<ApiDefinitionWithBLOBs> blobs, @Param("projectId") String projectId, @Param("versionIds") Set<String> versionIds);
|
||||
List<ApiDefinitionWithBLOBs> selectRepeatByBLOBs(@Param("blobs") List<ApiDefinitionWithBLOBs> blobs, @Param("projectId") String projectId);
|
||||
|
||||
List<ApiDefinitionWithBLOBs> selectRepeatByBLOBsSameUrl(@Param("blobs") List<ApiDefinitionWithBLOBs> blobs, @Param("projectId") String projectId, @Param("moduleId") String moduleId, @Param("versionIds") Set<String> versionIds);
|
||||
List<ApiDefinitionWithBLOBs> selectRepeatByBLOBsSameUrl(@Param("blobs") List<ApiDefinitionWithBLOBs> blobs, @Param("projectId") String projectId, @Param("moduleId") String moduleId);
|
||||
|
||||
List<ApiDefinitionWithBLOBs> selectRepeatByProtocol(@Param("names") List<String> names, @Param("protocol") String protocol, @Param("versionIds") Set<String> versionIds);
|
||||
List<ApiDefinitionWithBLOBs> selectRepeatByProtocol(@Param("names") List<String> names, @Param("protocol") String protocol);
|
||||
|
||||
int countById(String id);
|
||||
}
|
||||
|
|
|
@ -1087,10 +1087,6 @@
|
|||
<include refid="Same_Where_Clause"/>
|
||||
and status != 'Trash'
|
||||
and project_id = #{projectId}
|
||||
and version_id in
|
||||
<foreach collection="versionIds" item="versionId" separator="," open="(" close=")">
|
||||
#{versionId}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="selectRepeatByBLOBsSameUrl" resultType="io.metersphere.base.domain.ApiDefinitionWithBLOBs">
|
||||
SELECT * from api_definition
|
||||
|
@ -1098,10 +1094,6 @@
|
|||
and status != 'TRASH'
|
||||
and project_id = #{projectId}
|
||||
and module_id = #{moduleId}
|
||||
and version_id in
|
||||
<foreach collection="versionIds" item="versionId" separator="," open="(" close=")">
|
||||
#{versionId}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="selectRepeatByProtocol" resultType="io.metersphere.base.domain.ApiDefinitionWithBLOBs">
|
||||
SELECT * from api_definition
|
||||
|
@ -1109,10 +1101,6 @@
|
|||
<foreach collection="names" item="name" separator="," open="(" close=")">
|
||||
#{name}
|
||||
</foreach>
|
||||
and version_id in
|
||||
<foreach collection="versionIds" item="versionId" separator="," open="(" close=")">
|
||||
#{versionId}
|
||||
</foreach>
|
||||
and protocol = #{protocol}
|
||||
and status != 'Trash'
|
||||
</select>
|
||||
|
|
|
@ -91,7 +91,7 @@ public interface ExtApiScenarioMapper {
|
|||
|
||||
List<ApiScenarioWithBLOBs> selectByStatusIsNotTrash();
|
||||
|
||||
List<ApiScenarioWithBLOBs> selectRepeatByBLOBs(@Param("names") List<String> names, @Param("projectId") String projectId, @Param("versionIds") Set<String> versionIds);
|
||||
List<ApiScenarioWithBLOBs> selectRepeatByBLOBs(@Param("names") List<String> names, @Param("projectId") String projectId);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -828,10 +828,6 @@
|
|||
</foreach>
|
||||
and status != 'Trash'
|
||||
and project_id = #{projectId}
|
||||
and version_id in
|
||||
<foreach collection="versionIds" item="versionId" separator="," open="(" close=")">
|
||||
#{versionId}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue