perf(接口测试): 保存场景优化
This commit is contained in:
parent
c2e7a1a0f6
commit
d2ac8ae5c6
|
@ -255,7 +255,7 @@ public class ApiAutomationService {
|
||||||
esbApiParamService.checkScenarioRequests(request);
|
esbApiParamService.checkScenarioRequests(request);
|
||||||
|
|
||||||
apiScenarioMapper.insert(scenario);
|
apiScenarioMapper.insert(scenario);
|
||||||
apiScenarioReferenceIdService.saveByApiScenario(scenario);
|
apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenario);
|
||||||
// 存储依赖关系
|
// 存储依赖关系
|
||||||
ApiAutomationRelationshipEdgeService relationshipEdgeService = CommonBeanFactory.getBean(ApiAutomationRelationshipEdgeService.class);
|
ApiAutomationRelationshipEdgeService relationshipEdgeService = CommonBeanFactory.getBean(ApiAutomationRelationshipEdgeService.class);
|
||||||
if (relationshipEdgeService != null) {
|
if (relationshipEdgeService != null) {
|
||||||
|
@ -384,12 +384,11 @@ public class ApiAutomationService {
|
||||||
apiScenarioMapper.updateByExampleSelective(apiScenarioWithBLOBs, example);
|
apiScenarioMapper.updateByExampleSelective(apiScenarioWithBLOBs, example);
|
||||||
}
|
}
|
||||||
|
|
||||||
apiScenarioReferenceIdService.saveByApiScenario(scenario);
|
apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenario);
|
||||||
extScheduleMapper.updateNameByResourceID(request.getId(), request.getName());// 修改场景name,同步到修改首页定时任务
|
extScheduleMapper.updateNameByResourceID(request.getId(), request.getName());// 修改场景name,同步到修改首页定时任务
|
||||||
uploadFiles(request, bodyFiles, scenarioFiles);
|
uploadFiles(request, bodyFiles, scenarioFiles);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 存储依赖关系
|
// 存储依赖关系
|
||||||
ApiAutomationRelationshipEdgeService relationshipEdgeService = CommonBeanFactory.getBean(ApiAutomationRelationshipEdgeService.class);
|
ApiAutomationRelationshipEdgeService relationshipEdgeService = CommonBeanFactory.getBean(ApiAutomationRelationshipEdgeService.class);
|
||||||
if (relationshipEdgeService != null) {
|
if (relationshipEdgeService != null) {
|
||||||
|
@ -399,14 +398,14 @@ public class ApiAutomationService {
|
||||||
return scenario;
|
return scenario;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkReferenceCase(ApiScenarioWithBLOBs scenario,ApiTestCaseMapper apiTestCaseMapper,ApiDefinitionMapper apiDefinitionMapper) {
|
private void checkReferenceCase(ApiScenarioWithBLOBs scenario, ApiTestCaseMapper apiTestCaseMapper, ApiDefinitionMapper apiDefinitionMapper) {
|
||||||
if (scenario == null || StringUtils.isEmpty(scenario.getScenarioDefinition())) {
|
if (scenario == null || StringUtils.isEmpty(scenario.getScenarioDefinition())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSONObject element = JSON.parseObject(scenario.getScenarioDefinition());
|
JSONObject element = JSON.parseObject(scenario.getScenarioDefinition());
|
||||||
JSONArray hashTree = element.getJSONArray("hashTree");
|
JSONArray hashTree = element.getJSONArray("hashTree");
|
||||||
ApiScenarioImportUtil.formatHashTree(hashTree);
|
ApiScenarioImportUtil.formatHashTree(hashTree);
|
||||||
setReferenced(hashTree,scenario.getVersionId(),scenario.getProjectId(),apiTestCaseMapper,apiDefinitionMapper,true);
|
setReferenced(hashTree, scenario.getVersionId(), scenario.getProjectId(), apiTestCaseMapper, apiDefinitionMapper, true);
|
||||||
scenario.setScenarioDefinition(JSONObject.toJSONString(element));
|
scenario.setScenarioDefinition(JSONObject.toJSONString(element));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1101,7 +1100,7 @@ public class ApiAutomationService {
|
||||||
item.setScenarioDefinition(JSONObject.toJSONString(object));
|
item.setScenarioDefinition(JSONObject.toJSONString(object));
|
||||||
}
|
}
|
||||||
apiScenarioMapper.updateByPrimaryKeySelective(item);
|
apiScenarioMapper.updateByPrimaryKeySelective(item);
|
||||||
apiScenarioReferenceIdService.saveByApiScenario(item);
|
apiScenarioReferenceIdService.saveApiAndScenarioRelation(item);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1124,7 +1123,7 @@ public class ApiAutomationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _importCreate(List<ApiScenarioWithBLOBs> sameRequest, ApiScenarioMapper batchMapper, ExtApiScenarioMapper extApiScenarioMapper,
|
private void _importCreate(List<ApiScenarioWithBLOBs> sameRequest, ApiScenarioMapper batchMapper, ExtApiScenarioMapper extApiScenarioMapper,
|
||||||
ApiScenarioWithBLOBs scenarioWithBLOBs, ApiTestImportRequest apiTestImportRequest,ApiTestCaseMapper apiTestCaseMapper, ApiDefinitionMapper apiDefinitionMapper) {
|
ApiScenarioWithBLOBs scenarioWithBLOBs, ApiTestImportRequest apiTestImportRequest, ApiTestCaseMapper apiTestCaseMapper, ApiDefinitionMapper apiDefinitionMapper) {
|
||||||
if (CollectionUtils.isEmpty(sameRequest)) {
|
if (CollectionUtils.isEmpty(sameRequest)) {
|
||||||
scenarioWithBLOBs.setId(UUID.randomUUID().toString());
|
scenarioWithBLOBs.setId(UUID.randomUUID().toString());
|
||||||
List<ApiMethodUrlDTO> useUrl = this.parseUrl(scenarioWithBLOBs);
|
List<ApiMethodUrlDTO> useUrl = this.parseUrl(scenarioWithBLOBs);
|
||||||
|
@ -1138,9 +1137,9 @@ public class ApiAutomationService {
|
||||||
scenarioWithBLOBs.setVersionId(apiTestImportRequest.getDefaultVersion());
|
scenarioWithBLOBs.setVersionId(apiTestImportRequest.getDefaultVersion());
|
||||||
}
|
}
|
||||||
scenarioWithBLOBs.setLatest(true);
|
scenarioWithBLOBs.setLatest(true);
|
||||||
checkReferenceCase(scenarioWithBLOBs,apiTestCaseMapper,apiDefinitionMapper);
|
checkReferenceCase(scenarioWithBLOBs, apiTestCaseMapper, apiDefinitionMapper);
|
||||||
batchMapper.insert(scenarioWithBLOBs);
|
batchMapper.insert(scenarioWithBLOBs);
|
||||||
apiScenarioReferenceIdService.saveByApiScenario(scenarioWithBLOBs);
|
apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenarioWithBLOBs);
|
||||||
} else {
|
} else {
|
||||||
//如果存在则修改
|
//如果存在则修改
|
||||||
if (StringUtils.isEmpty(apiTestImportRequest.getUpdateVersionId())) {
|
if (StringUtils.isEmpty(apiTestImportRequest.getUpdateVersionId())) {
|
||||||
|
@ -1169,15 +1168,15 @@ public class ApiAutomationService {
|
||||||
scenarioWithBLOBs.setUseUrl(JSONArray.toJSONString(useUrl));
|
scenarioWithBLOBs.setUseUrl(JSONArray.toJSONString(useUrl));
|
||||||
batchMapper.updateByPrimaryKeyWithBLOBs(scenarioWithBLOBs);
|
batchMapper.updateByPrimaryKeyWithBLOBs(scenarioWithBLOBs);
|
||||||
}
|
}
|
||||||
checkReferenceCase(scenarioWithBLOBs,apiTestCaseMapper,apiDefinitionMapper);
|
checkReferenceCase(scenarioWithBLOBs, apiTestCaseMapper, apiDefinitionMapper);
|
||||||
apiScenarioReferenceIdService.saveByApiScenario(scenarioWithBLOBs);
|
apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenarioWithBLOBs);
|
||||||
extApiScenarioMapper.clearLatestVersion(scenarioWithBLOBs.getRefId());
|
extApiScenarioMapper.clearLatestVersion(scenarioWithBLOBs.getRefId());
|
||||||
extApiScenarioMapper.addLatestVersion(scenarioWithBLOBs.getRefId());
|
extApiScenarioMapper.addLatestVersion(scenarioWithBLOBs.getRefId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApiScenarioWithBLOBs importCreate(ApiScenarioWithBLOBs request, ApiScenarioMapper batchMapper, ExtApiScenarioMapper extApiScenarioMapper,
|
private ApiScenarioWithBLOBs importCreate(ApiScenarioWithBLOBs request, ApiScenarioMapper batchMapper, ExtApiScenarioMapper extApiScenarioMapper,
|
||||||
ApiTestImportRequest apiTestImportRequest,ApiTestCaseMapper apiTestCaseMapper, ApiDefinitionMapper apiDefinitionMapper) {
|
ApiTestImportRequest apiTestImportRequest, ApiTestCaseMapper apiTestCaseMapper, ApiDefinitionMapper apiDefinitionMapper) {
|
||||||
final ApiScenarioWithBLOBs scenarioWithBLOBs = new ApiScenarioWithBLOBs();
|
final ApiScenarioWithBLOBs scenarioWithBLOBs = new ApiScenarioWithBLOBs();
|
||||||
BeanUtils.copyBean(scenarioWithBLOBs, request);
|
BeanUtils.copyBean(scenarioWithBLOBs, request);
|
||||||
scenarioWithBLOBs.setCreateTime(System.currentTimeMillis());
|
scenarioWithBLOBs.setCreateTime(System.currentTimeMillis());
|
||||||
|
@ -1226,7 +1225,7 @@ public class ApiAutomationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.equals("fullCoverage", apiTestImportRequest.getModeId())) {
|
if (StringUtils.equals("fullCoverage", apiTestImportRequest.getModeId())) {
|
||||||
_importCreate(sameRequest, batchMapper, extApiScenarioMapper, scenarioWithBLOBs, apiTestImportRequest,apiTestCaseMapper,apiDefinitionMapper);
|
_importCreate(sameRequest, batchMapper, extApiScenarioMapper, scenarioWithBLOBs, apiTestImportRequest, apiTestCaseMapper, apiDefinitionMapper);
|
||||||
} else if (StringUtils.equals("incrementalMerge", apiTestImportRequest.getModeId())) {
|
} else if (StringUtils.equals("incrementalMerge", apiTestImportRequest.getModeId())) {
|
||||||
if (CollectionUtils.isEmpty(sameRequest)) {
|
if (CollectionUtils.isEmpty(sameRequest)) {
|
||||||
List<ApiMethodUrlDTO> useUrl = this.parseUrl(scenarioWithBLOBs);
|
List<ApiMethodUrlDTO> useUrl = this.parseUrl(scenarioWithBLOBs);
|
||||||
|
@ -1240,18 +1239,18 @@ public class ApiAutomationService {
|
||||||
scenarioWithBLOBs.setVersionId(apiTestImportRequest.getDefaultVersion());
|
scenarioWithBLOBs.setVersionId(apiTestImportRequest.getDefaultVersion());
|
||||||
}
|
}
|
||||||
scenarioWithBLOBs.setLatest(true);
|
scenarioWithBLOBs.setLatest(true);
|
||||||
checkReferenceCase(scenarioWithBLOBs,apiTestCaseMapper,apiDefinitionMapper);
|
checkReferenceCase(scenarioWithBLOBs, apiTestCaseMapper, apiDefinitionMapper);
|
||||||
batchMapper.insert(scenarioWithBLOBs);
|
batchMapper.insert(scenarioWithBLOBs);
|
||||||
// 存储依赖关系
|
// 存储依赖关系
|
||||||
ApiAutomationRelationshipEdgeService relationshipEdgeService = CommonBeanFactory.getBean(ApiAutomationRelationshipEdgeService.class);
|
ApiAutomationRelationshipEdgeService relationshipEdgeService = CommonBeanFactory.getBean(ApiAutomationRelationshipEdgeService.class);
|
||||||
if (relationshipEdgeService != null) {
|
if (relationshipEdgeService != null) {
|
||||||
relationshipEdgeService.initRelationshipEdge(null, scenarioWithBLOBs);
|
relationshipEdgeService.initRelationshipEdge(null, scenarioWithBLOBs);
|
||||||
}
|
}
|
||||||
apiScenarioReferenceIdService.saveByApiScenario(scenarioWithBLOBs);
|
apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenarioWithBLOBs);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
_importCreate(sameRequest, batchMapper, extApiScenarioMapper, scenarioWithBLOBs, apiTestImportRequest,apiTestCaseMapper,apiDefinitionMapper);
|
_importCreate(sameRequest, batchMapper, extApiScenarioMapper, scenarioWithBLOBs, apiTestImportRequest, apiTestCaseMapper, apiDefinitionMapper);
|
||||||
}
|
}
|
||||||
return scenarioWithBLOBs;
|
return scenarioWithBLOBs;
|
||||||
}
|
}
|
||||||
|
@ -1303,7 +1302,7 @@ public class ApiAutomationService {
|
||||||
item.setUserId(SessionUtils.getUserId());
|
item.setUserId(SessionUtils.getUserId());
|
||||||
item.setPrincipal(SessionUtils.getUserId());
|
item.setPrincipal(SessionUtils.getUserId());
|
||||||
// 导入之后刷新latest
|
// 导入之后刷新latest
|
||||||
importCreate(item, batchMapper, extApiScenarioMapper, request,apiTestCaseMapper,apiDefinitionMapper);
|
importCreate(item, batchMapper, extApiScenarioMapper, request, apiTestCaseMapper, apiDefinitionMapper);
|
||||||
if (i % 300 == 0) {
|
if (i % 300 == 0) {
|
||||||
sqlSession.flushStatements();
|
sqlSession.flushStatements();
|
||||||
}
|
}
|
||||||
|
@ -1375,14 +1374,14 @@ public class ApiAutomationService {
|
||||||
if (CollectionUtils.isNotEmpty(result.getData())) {
|
if (CollectionUtils.isNotEmpty(result.getData())) {
|
||||||
List<String> names = new ArrayList<>();
|
List<String> names = new ArrayList<>();
|
||||||
List<String> ids = new ArrayList<>();
|
List<String> ids = new ArrayList<>();
|
||||||
checkDefinition(result,names,ids);
|
checkDefinition(result, names, ids);
|
||||||
request.setName(String.join(",", names));
|
request.setName(String.join(",", names));
|
||||||
request.setId(JSON.toJSONString(ids));
|
request.setId(JSON.toJSONString(ids));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkDefinition(ApiScenrioExportResult result, List<String> names, List<String> ids){
|
public void checkDefinition(ApiScenrioExportResult result, List<String> names, List<String> ids) {
|
||||||
for (ApiScenarioWithBLOBs scenario : result.getData()) {
|
for (ApiScenarioWithBLOBs scenario : result.getData()) {
|
||||||
if (scenario == null || StringUtils.isEmpty(scenario.getScenarioDefinition())) {
|
if (scenario == null || StringUtils.isEmpty(scenario.getScenarioDefinition())) {
|
||||||
return;
|
return;
|
||||||
|
@ -1396,7 +1395,8 @@ public class ApiAutomationService {
|
||||||
ids.add(scenario.getId());
|
ids.add(scenario.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void setHashTree(JSONArray hashTree){
|
|
||||||
|
public void setHashTree(JSONArray hashTree) {
|
||||||
try {
|
try {
|
||||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||||
for (int i = 0; i < hashTree.size(); i++) {
|
for (int i = 0; i < hashTree.size(); i++) {
|
||||||
|
@ -1411,13 +1411,13 @@ public class ApiAutomationService {
|
||||||
ApiTestCaseInfo model = extApiTestCaseMapper.selectApiCaseInfoByPrimaryKey(object.getString("id"));
|
ApiTestCaseInfo model = extApiTestCaseMapper.selectApiCaseInfoByPrimaryKey(object.getString("id"));
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
JSONObject element = JSON.parseObject(model.getRequest());
|
JSONObject element = JSON.parseObject(model.getRequest());
|
||||||
object.put("hashTree",element.getJSONArray("hashTree"));
|
object.put("hashTree", element.getJSONArray("hashTree"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotEmpty(object.getString("refType"))){
|
if (StringUtils.isNotEmpty(object.getString("refType"))) {
|
||||||
if (CollectionUtils.isNotEmpty(object.getJSONArray("hashTree"))) {
|
if (CollectionUtils.isNotEmpty(object.getJSONArray("hashTree"))) {
|
||||||
setHashTree(object.getJSONArray("hashTree"));
|
setHashTree(object.getJSONArray("hashTree"));
|
||||||
}
|
}
|
||||||
|
@ -1426,11 +1426,11 @@ public class ApiAutomationService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public List<ApiScenarioExportJmxDTO> exportJmx(ApiScenarioBatchRequest request) {
|
public List<ApiScenarioExportJmxDTO> exportJmx(ApiScenarioBatchRequest request) {
|
||||||
List<ApiScenarioWithBLOBs> apiScenarioWithBLOBs = getExportResult(request);
|
List<ApiScenarioWithBLOBs> apiScenarioWithBLOBs = getExportResult(request);
|
||||||
// 生成jmx
|
// 生成jmx
|
||||||
List<ApiScenarioExportJmxDTO> resList = new ArrayList<>();
|
List<ApiScenarioExportJmxDTO> resList = new ArrayList<>();
|
||||||
|
@ -1630,13 +1630,7 @@ public class ApiAutomationService {
|
||||||
|
|
||||||
public List<ApiMethodUrlDTO> parseUrl(ApiScenarioWithBLOBs scenario) {
|
public List<ApiMethodUrlDTO> parseUrl(ApiScenarioWithBLOBs scenario) {
|
||||||
List<ApiMethodUrlDTO> urlList = new ArrayList<>();
|
List<ApiMethodUrlDTO> urlList = new ArrayList<>();
|
||||||
String scenarioDefinition = scenario.getScenarioDefinition();
|
// 去除未生效且影响性能的方法
|
||||||
JSONObject scenarioObj = JSONObject.parseObject(scenarioDefinition);
|
|
||||||
List<ApiMethodUrlDTO> stepUrlList = hashTreeService.getMethodUrlDTOByHashTreeJsonObj(scenarioObj);
|
|
||||||
if (CollectionUtils.isNotEmpty(stepUrlList)) {
|
|
||||||
Collection unionList = CollectionUtils.union(urlList, stepUrlList);
|
|
||||||
urlList = new ArrayList<>(unionList);
|
|
||||||
}
|
|
||||||
return urlList;
|
return urlList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1750,18 +1744,16 @@ public class ApiAutomationService {
|
||||||
updateModel.setId(scenario.getId());
|
updateModel.setId(scenario.getId());
|
||||||
updateModel.setUseUrl(JSONArray.toJSONString(useUrl));
|
updateModel.setUseUrl(JSONArray.toJSONString(useUrl));
|
||||||
apiScenarioMapper.updateByPrimaryKeySelective(updateModel);
|
apiScenarioMapper.updateByPrimaryKeySelective(updateModel);
|
||||||
apiScenarioReferenceIdService.saveByApiScenario(updateModel);
|
apiScenarioReferenceIdService.saveApiAndScenarioRelation(updateModel);
|
||||||
updateModel = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scenario = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkApiScenarioReferenceId() {
|
public void checkApiScenarioReferenceId() {
|
||||||
List<ApiScenarioWithBLOBs> scenarioNoRefs = extApiScenarioMapper.selectByNoReferenceId();
|
List<ApiScenarioWithBLOBs> scenarioNoRefs = extApiScenarioMapper.selectByNoReferenceId();
|
||||||
for (ApiScenarioWithBLOBs model : scenarioNoRefs) {
|
for (ApiScenarioWithBLOBs model : scenarioNoRefs) {
|
||||||
apiScenarioReferenceIdService.saveByApiScenario(model);
|
apiScenarioReferenceIdService.saveApiAndScenarioRelation(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2022,10 +2014,10 @@ public class ApiAutomationService {
|
||||||
return strings;
|
return strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setReferenced(JSONArray hashTree,String versionId,String projectId, ApiTestCaseMapper apiTestCaseMapper,ApiDefinitionMapper apiDefinitionMapper,boolean isAdd) {
|
private void setReferenced(JSONArray hashTree, String versionId, String projectId, ApiTestCaseMapper apiTestCaseMapper, ApiDefinitionMapper apiDefinitionMapper, boolean isAdd) {
|
||||||
// 将引用转成复制
|
// 将引用转成复制
|
||||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||||
Map<String,ApiDefinition>definitionMap = new HashMap<>();
|
Map<String, ApiDefinition> definitionMap = new HashMap<>();
|
||||||
for (int i = 0; i < hashTree.size(); i++) {
|
for (int i = 0; i < hashTree.size(); i++) {
|
||||||
JSONObject object = (JSONObject) hashTree.get(i);
|
JSONObject object = (JSONObject) hashTree.get(i);
|
||||||
String referenced = object.getString("referenced");
|
String referenced = object.getString("referenced");
|
||||||
|
@ -2033,32 +2025,32 @@ public class ApiAutomationService {
|
||||||
// 检测引用对象是否存在,若果不存在则改成复制对象
|
// 检测引用对象是否存在,若果不存在则改成复制对象
|
||||||
String refType = object.getString("refType");
|
String refType = object.getString("refType");
|
||||||
if (StringUtils.isNotEmpty(refType)) {
|
if (StringUtils.isNotEmpty(refType)) {
|
||||||
if (refType.equals("CASE")&&isAdd) {
|
if (refType.equals("CASE") && isAdd) {
|
||||||
ApiScenarioImportUtil.checkCase(i,object,versionId,projectId,apiTestCaseMapper,apiDefinitionMapper,definitionMap);
|
ApiScenarioImportUtil.checkCase(i, object, versionId, projectId, apiTestCaseMapper, apiDefinitionMapper, definitionMap);
|
||||||
} else {
|
} else {
|
||||||
checkAutomation(object);
|
checkAutomation(object);
|
||||||
object.put("projectId", projectId);
|
object.put("projectId", projectId);
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
object.put("referenced", "Copy");
|
object.put("referenced", "Copy");
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
object.put("projectId", projectId);
|
object.put("projectId", projectId);
|
||||||
if(StringUtils.isEmpty(object.getString("url"))){
|
if (StringUtils.isEmpty(object.getString("url"))) {
|
||||||
object.put("isRefEnvironment",true);
|
object.put("isRefEnvironment", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JSONObject environmentMap = object.getJSONObject("environmentMap");
|
JSONObject environmentMap = object.getJSONObject("environmentMap");
|
||||||
if (environmentMap != null) {
|
if (environmentMap != null) {
|
||||||
object.put("environmentMap", new HashMap<>());
|
object.put("environmentMap", new HashMap<>());
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotEmpty(object.getString("refType"))&&object.getString("refType").equals("CASE")){
|
if (StringUtils.isNotEmpty(object.getString("refType")) && object.getString("refType").equals("CASE")) {
|
||||||
if (CollectionUtils.isNotEmpty(object.getJSONArray("hashTree"))) {
|
if (CollectionUtils.isNotEmpty(object.getJSONArray("hashTree"))) {
|
||||||
setReferenced(object.getJSONArray("hashTree"),versionId,projectId,apiTestCaseMapper,apiDefinitionMapper,true);
|
setReferenced(object.getJSONArray("hashTree"), versionId, projectId, apiTestCaseMapper, apiDefinitionMapper, true);
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
if (CollectionUtils.isNotEmpty(object.getJSONArray("hashTree"))) {
|
if (CollectionUtils.isNotEmpty(object.getJSONArray("hashTree"))) {
|
||||||
setReferenced(object.getJSONArray("hashTree"),versionId,projectId,apiTestCaseMapper,apiDefinitionMapper,false);
|
setReferenced(object.getJSONArray("hashTree"), versionId, projectId, apiTestCaseMapper, apiDefinitionMapper, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2070,12 +2062,12 @@ public class ApiAutomationService {
|
||||||
ApiScenarioWithBLOBs bloBs = getDto(object.getString("id"));
|
ApiScenarioWithBLOBs bloBs = getDto(object.getString("id"));
|
||||||
if (bloBs == null) {
|
if (bloBs == null) {
|
||||||
object.put("referenced", "Copy");
|
object.put("referenced", "Copy");
|
||||||
}else{
|
} else {
|
||||||
CheckPermissionService checkPermissionService = CommonBeanFactory.getBean(CheckPermissionService.class);
|
CheckPermissionService checkPermissionService = CommonBeanFactory.getBean(CheckPermissionService.class);
|
||||||
Set<String> userRelatedProjectIds = checkPermissionService.getUserRelatedProjectIds();
|
Set<String> userRelatedProjectIds = checkPermissionService.getUserRelatedProjectIds();
|
||||||
if(!userRelatedProjectIds.contains(bloBs.getProjectId())){
|
if (!userRelatedProjectIds.contains(bloBs.getProjectId())) {
|
||||||
object.put("referenced", "Copy");
|
object.put("referenced", "Copy");
|
||||||
}else{
|
} else {
|
||||||
object.put("id", bloBs.getId());
|
object.put("id", bloBs.getId());
|
||||||
object.put("resourceId", bloBs.getId());
|
object.put("resourceId", bloBs.getId());
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,14 @@ import io.metersphere.base.domain.ApiScenarioReferenceId;
|
||||||
import io.metersphere.base.domain.ApiScenarioReferenceIdExample;
|
import io.metersphere.base.domain.ApiScenarioReferenceIdExample;
|
||||||
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
|
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
|
||||||
import io.metersphere.base.mapper.ApiScenarioReferenceIdMapper;
|
import io.metersphere.base.mapper.ApiScenarioReferenceIdMapper;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
|
||||||
import io.metersphere.commons.utils.SessionUtils;
|
import io.metersphere.commons.utils.SessionUtils;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.collections.MapUtils;
|
import org.apache.commons.collections.MapUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.ibatis.session.ExecutorType;
|
||||||
|
import org.apache.ibatis.session.SqlSession;
|
||||||
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
|
import org.mybatis.spring.SqlSessionUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@ -26,6 +29,8 @@ import java.util.*;
|
||||||
public class ApiScenarioReferenceIdService {
|
public class ApiScenarioReferenceIdService {
|
||||||
@Resource
|
@Resource
|
||||||
private ApiScenarioReferenceIdMapper apiScenarioReferenceIdMapper;
|
private ApiScenarioReferenceIdMapper apiScenarioReferenceIdMapper;
|
||||||
|
@Resource
|
||||||
|
private SqlSessionFactory sqlSessionFactory;
|
||||||
|
|
||||||
public List<ApiScenarioReferenceId> findByReferenceIds(List<String> deleteIds) {
|
public List<ApiScenarioReferenceId> findByReferenceIds(List<String> deleteIds) {
|
||||||
if (CollectionUtils.isEmpty(deleteIds)) {
|
if (CollectionUtils.isEmpty(deleteIds)) {
|
||||||
|
@ -43,112 +48,80 @@ public class ApiScenarioReferenceIdService {
|
||||||
apiScenarioReferenceIdMapper.deleteByExample(example);
|
apiScenarioReferenceIdMapper.deleteByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveByApiScenario(ApiScenarioWithBLOBs scenario) {
|
public void saveApiAndScenarioRelation(ApiScenarioWithBLOBs scenario) {
|
||||||
if(scenario.getId() == null){
|
if (scenario.getId() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.deleteByScenarioId(scenario.getId());
|
this.deleteByScenarioId(scenario.getId());
|
||||||
|
Map<String, ApiScenarioReferenceId> referenceIdMap = new HashMap<>();
|
||||||
long createTime = System.currentTimeMillis();
|
if (StringUtils.isNotEmpty(scenario.getScenarioDefinition())) {
|
||||||
String createUser = SessionUtils.getUserId();
|
JSONObject jsonObject = JSONObject.parseObject(scenario.getScenarioDefinition());
|
||||||
|
if (!jsonObject.containsKey(MsHashTreeService.HASH_TREE)) {
|
||||||
Map<String, ApiScenarioReferenceId> refreceIdDic = new HashMap<>();
|
return;
|
||||||
try {
|
}
|
||||||
if (scenario.getScenarioDefinition() != null) {
|
JSONArray hashTree = jsonObject.getJSONArray(MsHashTreeService.HASH_TREE);
|
||||||
JSONObject jsonObject = JSONObject.parseObject(scenario.getScenarioDefinition());
|
for (int index = 0; index < hashTree.size(); index++) {
|
||||||
if (jsonObject.containsKey("hashTree")) {
|
JSONObject item = hashTree.getJSONObject(index);
|
||||||
JSONArray testElementList = jsonObject.getJSONArray("hashTree");
|
if (item == null) {
|
||||||
for (int index = 0; index < testElementList.size(); index++) {
|
continue;
|
||||||
JSONObject item = testElementList.getJSONObject(index);
|
}
|
||||||
String refId = "";
|
if (item.containsKey(MsHashTreeService.ID) && item.containsKey(MsHashTreeService.REFERENCED)) {
|
||||||
String refrenced = "";
|
ApiScenarioReferenceId saveItem = new ApiScenarioReferenceId();
|
||||||
String dataType = "";
|
saveItem.setId(UUID.randomUUID().toString());
|
||||||
if(item.containsKey("id")){
|
saveItem.setApiScenarioId(scenario.getId());
|
||||||
refId = item.getString("id");
|
saveItem.setReferenceId(item.getString(MsHashTreeService.ID));
|
||||||
}
|
saveItem.setReferenceType(item.getString(MsHashTreeService.REFERENCED));
|
||||||
if(item.containsKey("referenced")){
|
saveItem.setDataType(item.getString(MsHashTreeService.REF_TYPE));
|
||||||
refrenced = item.getString("referenced");
|
referenceIdMap.put(item.getString(MsHashTreeService.ID), saveItem);
|
||||||
}
|
}
|
||||||
if(item.containsKey("refType")){
|
if (item.containsKey(MsHashTreeService.HASH_TREE)) {
|
||||||
dataType = item.getString("refType");
|
referenceIdMap.putAll(this.deepElementRelation(scenario.getId(), item.getJSONArray(MsHashTreeService.HASH_TREE)));
|
||||||
}
|
|
||||||
|
|
||||||
if (StringUtils.isNotEmpty(refId) && StringUtils.isNotEmpty(refrenced)) {
|
|
||||||
ApiScenarioReferenceId saveItem = new ApiScenarioReferenceId();
|
|
||||||
saveItem.setId(UUID.randomUUID().toString());
|
|
||||||
saveItem.setApiScenarioId(scenario.getId());
|
|
||||||
saveItem.setCreateTime(createTime);
|
|
||||||
saveItem.setCreateUserId(createUser);
|
|
||||||
saveItem.setReferenceId(refId);
|
|
||||||
saveItem.setReferenceType(refrenced);
|
|
||||||
saveItem.setDataType(dataType);
|
|
||||||
refreceIdDic.put(refId,saveItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(item.containsKey("hashTree")){
|
|
||||||
refreceIdDic.putAll(this.deepParseTestElement(createTime,createUser,scenario.getId(),item.getJSONArray("hashTree")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
LogUtil.error(e);
|
|
||||||
}
|
}
|
||||||
if(MapUtils.isNotEmpty(refreceIdDic)){
|
if (MapUtils.isNotEmpty(referenceIdMap)) {
|
||||||
for (ApiScenarioReferenceId model:refreceIdDic.values()) {
|
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||||
apiScenarioReferenceIdMapper.insert(model);
|
ApiScenarioReferenceIdMapper referenceIdMapper = sqlSession.getMapper(ApiScenarioReferenceIdMapper.class);
|
||||||
|
for (ApiScenarioReferenceId apiScenarioReferenceId : referenceIdMap.values()) {
|
||||||
|
apiScenarioReferenceId.setCreateTime(System.currentTimeMillis());
|
||||||
|
apiScenarioReferenceId.setCreateUserId(SessionUtils.getUserId());
|
||||||
|
referenceIdMapper.insert(apiScenarioReferenceId);
|
||||||
}
|
}
|
||||||
}else {
|
sqlSession.flushStatements();
|
||||||
|
if (sqlSession != null && sqlSessionFactory != null) {
|
||||||
|
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
ApiScenarioReferenceId saveItem = new ApiScenarioReferenceId();
|
ApiScenarioReferenceId saveItem = new ApiScenarioReferenceId();
|
||||||
saveItem.setId(UUID.randomUUID().toString());
|
saveItem.setId(UUID.randomUUID().toString());
|
||||||
saveItem.setApiScenarioId(scenario.getId());
|
saveItem.setApiScenarioId(scenario.getId());
|
||||||
saveItem.setCreateTime(createTime);
|
saveItem.setCreateTime(System.currentTimeMillis());
|
||||||
saveItem.setCreateUserId(createUser);
|
saveItem.setCreateUserId(SessionUtils.getUserId());
|
||||||
try{
|
apiScenarioReferenceIdMapper.insert(saveItem);
|
||||||
apiScenarioReferenceIdMapper.insert(saveItem);
|
|
||||||
}catch (Exception e){
|
|
||||||
LogUtil.error(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String,ApiScenarioReferenceId> deepParseTestElement(long createTime,String createUser,String scenarioId,JSONArray testElementList){
|
public Map<String, ApiScenarioReferenceId> deepElementRelation(String scenarioId, JSONArray hashTree) {
|
||||||
Map<String,ApiScenarioReferenceId> returnMap = new HashMap<>();
|
Map<String, ApiScenarioReferenceId> deepRelations = new HashMap<>();
|
||||||
|
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||||
if(CollectionUtils.isNotEmpty(testElementList)){
|
for (int index = 0; index < hashTree.size(); index++) {
|
||||||
for (int index = 0; index < testElementList.size(); index++) {
|
JSONObject item = hashTree.getJSONObject(index);
|
||||||
JSONObject item = testElementList.getJSONObject(index);
|
if (item.containsKey(MsHashTreeService.ID) && item.containsKey(MsHashTreeService.REFERENCED)) {
|
||||||
String refId = "";
|
|
||||||
String refrenced = "";
|
|
||||||
String dataType = "";
|
|
||||||
if(item.containsKey("id")){
|
|
||||||
refId = item.getString("id");
|
|
||||||
}
|
|
||||||
if(item.containsKey("referenced")){
|
|
||||||
refrenced = item.getString("referenced");
|
|
||||||
}
|
|
||||||
if(item.containsKey("refType")){
|
|
||||||
dataType = item.getString("refType");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StringUtils.isNotEmpty(refId) && StringUtils.isNotEmpty(refrenced)) {
|
|
||||||
ApiScenarioReferenceId saveItem = new ApiScenarioReferenceId();
|
ApiScenarioReferenceId saveItem = new ApiScenarioReferenceId();
|
||||||
saveItem.setId(UUID.randomUUID().toString());
|
saveItem.setId(UUID.randomUUID().toString());
|
||||||
saveItem.setApiScenarioId(scenarioId);
|
saveItem.setApiScenarioId(scenarioId);
|
||||||
saveItem.setCreateTime(createTime);
|
saveItem.setReferenceId(item.getString(MsHashTreeService.ID));
|
||||||
saveItem.setCreateUserId(createUser);
|
saveItem.setReferenceType(item.getString(MsHashTreeService.REFERENCED));
|
||||||
saveItem.setReferenceId(refId);
|
saveItem.setDataType(item.getString(MsHashTreeService.REF_TYPE));
|
||||||
saveItem.setReferenceType(refrenced);
|
deepRelations.put(item.getString(MsHashTreeService.ID), saveItem);
|
||||||
saveItem.setDataType(dataType);
|
|
||||||
returnMap.put(refId,saveItem);
|
|
||||||
}
|
}
|
||||||
if(item.containsKey("hashTree")){
|
if (item.containsKey(MsHashTreeService.HASH_TREE)) {
|
||||||
returnMap.putAll(this.deepParseTestElement(createTime,createUser,scenarioId,item.getJSONArray("hashTree")));
|
deepRelations.putAll(this.deepElementRelation(scenarioId, item.getJSONArray(MsHashTreeService.HASH_TREE)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return deepRelations;
|
||||||
return returnMap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ApiScenarioReferenceId> findByReferenceIdsAndRefType(List<String> deleteIds, String referenceType) {
|
public List<ApiScenarioReferenceId> findByReferenceIdsAndRefType(List<String> deleteIds, String referenceType) {
|
||||||
|
|
|
@ -371,7 +371,7 @@ public class HistoricalDataUpgradeService {
|
||||||
List<ApiMethodUrlDTO> useUrl = apiAutomationService.parseUrl(scenario);
|
List<ApiMethodUrlDTO> useUrl = apiAutomationService.parseUrl(scenario);
|
||||||
scenario.setUseUrl(JSONArray.toJSONString(useUrl));
|
scenario.setUseUrl(JSONArray.toJSONString(useUrl));
|
||||||
mapper.updateByPrimaryKeySelective(scenario);
|
mapper.updateByPrimaryKeySelective(scenario);
|
||||||
apiScenarioReferenceIdService.saveByApiScenario(scenario);
|
apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenario);
|
||||||
} else {
|
} else {
|
||||||
scenario = new ApiScenarioWithBLOBs();
|
scenario = new ApiScenarioWithBLOBs();
|
||||||
scenario.setId(id);
|
scenario.setId(id);
|
||||||
|
@ -392,7 +392,7 @@ public class HistoricalDataUpgradeService {
|
||||||
List<ApiMethodUrlDTO> useUrl = apiAutomationService.parseUrl(scenario);
|
List<ApiMethodUrlDTO> useUrl = apiAutomationService.parseUrl(scenario);
|
||||||
scenario.setUseUrl(JSONArray.toJSONString(useUrl));
|
scenario.setUseUrl(JSONArray.toJSONString(useUrl));
|
||||||
mapper.insert(scenario);
|
mapper.insert(scenario);
|
||||||
apiScenarioReferenceIdService.saveByApiScenario(scenario);
|
apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenario);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,32 +34,33 @@ public class MsHashTreeService {
|
||||||
@Resource
|
@Resource
|
||||||
private ExtApiScenarioMapper extApiScenarioMapper;
|
private ExtApiScenarioMapper extApiScenarioMapper;
|
||||||
|
|
||||||
private static final String CASE = "CASE";
|
public static final String CASE = "CASE";
|
||||||
private static final String REFERENCED = "referenced";
|
public static final String REFERENCED = "referenced";
|
||||||
private static final String REF = "REF";
|
public static final String REF = "REF";
|
||||||
private static final String REF_TYPE = "refType";
|
public static final String CREATED = "Created";
|
||||||
private static final String ID = "id";
|
public static final String REF_TYPE = "refType";
|
||||||
private static final String NAME = "name";
|
public static final String ID = "id";
|
||||||
private static final String SCENARIO = "scenario";
|
public static final String NAME = "name";
|
||||||
private static final String TYPE = "type";
|
public static final String SCENARIO = "scenario";
|
||||||
private static final String HASH_TREE = "hashTree";
|
public static final String TYPE = "type";
|
||||||
private static final String PATH = "path";
|
public static final String HASH_TREE = "hashTree";
|
||||||
private static final String METHOD = "method";
|
public static final String PATH = "path";
|
||||||
private static final String ENABLE = "enable";
|
public static final String METHOD = "method";
|
||||||
private static final String NUM = "num";
|
public static final String ENABLE = "enable";
|
||||||
private static final String ENV_ENABLE = "environmentEnable";
|
public static final String NUM = "num";
|
||||||
private static final String VARIABLE_ENABLE = "variableEnable";
|
public static final String ENV_ENABLE = "environmentEnable";
|
||||||
private static final String DISABLED = "disabled";
|
public static final String VARIABLE_ENABLE = "variableEnable";
|
||||||
private static final String VERSION_NAME = "versionName";
|
public static final String DISABLED = "disabled";
|
||||||
private static final String VERSION_ENABLE = "versionEnable";
|
public static final String VERSION_NAME = "versionName";
|
||||||
private static final String URL = "url";
|
public static final String VERSION_ENABLE = "versionEnable";
|
||||||
private static final String HEADERS = "headers";
|
public static final String URL = "url";
|
||||||
private static final String REST = "rest";
|
public static final String HEADERS = "headers";
|
||||||
private static final String BODY = "body";
|
public static final String REST = "rest";
|
||||||
private static final String ARGUMENTS = "arguments";
|
public static final String BODY = "body";
|
||||||
private static final String AUTH_MANAGER = "authManager";
|
public static final String ARGUMENTS = "arguments";
|
||||||
private static final String PROJECT_ID = "projectId";
|
public static final String AUTH_MANAGER = "authManager";
|
||||||
private static final String ACTIVE = "active";
|
public static final String PROJECT_ID = "projectId";
|
||||||
|
public static final String ACTIVE = "active";
|
||||||
|
|
||||||
public void setHashTree(JSONArray hashTree) {
|
public void setHashTree(JSONArray hashTree) {
|
||||||
// 将引用转成复制
|
// 将引用转成复制
|
||||||
|
|
Loading…
Reference in New Issue