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