parent
1b45326a54
commit
443868dbd9
|
@ -46,12 +46,6 @@ public class ApiModuleController {
|
|||
return apiModuleService.countTrashApiData(projectId, protocol);
|
||||
}
|
||||
|
||||
@GetMapping("/getModuleByName/{projectId}/{protocol}")
|
||||
public ApiModule getModuleByName(@PathVariable String projectId, @PathVariable String protocol) {
|
||||
// checkPermissionService.checkProjectOwner(projectId);
|
||||
return apiModuleService.getModuleByName(projectId, protocol);
|
||||
}
|
||||
|
||||
@GetMapping("/getUserDefaultApiType")
|
||||
public String getUserDefaultApiType() {
|
||||
String returnStr = ApiDefinitionDefaultApiTypeUtil.HTTP;
|
||||
|
|
|
@ -39,5 +39,4 @@ public class ApiTestImportRequest {
|
|||
private Boolean coverModule;
|
||||
// 当前协议
|
||||
private String protocol;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package io.metersphere.api.dto.automation;
|
||||
|
||||
import io.metersphere.base.domain.ApiScenarioModule;
|
||||
import io.metersphere.track.dto.TreeNodeDTO;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ApiScenarioModuleDTO extends TreeNodeDTO<ApiScenarioModuleDTO> {
|
||||
private String path;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package io.metersphere.api.dto.automation;
|
||||
|
||||
import io.metersphere.base.domain.ApiScenarioModule;
|
||||
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class UpdateScenarioModuleDTO {
|
||||
private List<ApiScenarioModule> moduleList;
|
||||
private List<ApiScenarioWithBLOBs> apiScenarioWithBLOBsList;
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package io.metersphere.api.dto.automation.parse;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import io.metersphere.api.dto.automation.EsbDataStruct;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.commons.utils.XMLUtils;
|
||||
|
@ -89,11 +88,11 @@ public class EsbDataParser {
|
|||
} else {
|
||||
returnData = dataStuct.copy(true);
|
||||
}
|
||||
}else if(index == 0){
|
||||
} else if (index == 0) {
|
||||
//如果是第一个节点不符合,则遍历子节点是否有符合的。
|
||||
int newIndex = index;
|
||||
EsbDataStruct itemData = selectEsbDataStructByNameStruct(dataStuct.getChildren(), paramArr, newIndex);
|
||||
if(itemData != null ){
|
||||
if (itemData != null) {
|
||||
returnData = itemData;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import io.metersphere.api.dto.definition.request.MsScenario;
|
|||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||
import io.metersphere.api.dto.scenario.KeyValue;
|
||||
import io.metersphere.api.parse.HarScenarioAbstractParser;
|
||||
import io.metersphere.base.domain.ApiScenarioModule;
|
||||
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
|
@ -16,7 +15,6 @@ import io.metersphere.dto.RequestResult;
|
|||
import io.metersphere.dto.ResponseResult;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
@ -49,7 +47,7 @@ public class HarScenarioParser extends HarScenarioAbstractParser<ScenarioImport>
|
|||
MsScenario msScenario = new MsScenario();
|
||||
msScenario.setName(harName);
|
||||
this.projectId = request.getProjectId();
|
||||
if (!ObjectUtils.isEmpty(har.log)&&!ObjectUtils.isEmpty(har.log.entries)) {
|
||||
if (!ObjectUtils.isEmpty(har.log) && !ObjectUtils.isEmpty(har.log.entries)) {
|
||||
parseItem(har.log.entries, msScenario, apiScenarioWithBLOBs);
|
||||
}
|
||||
|
||||
|
@ -61,13 +59,15 @@ public class HarScenarioParser extends HarScenarioAbstractParser<ScenarioImport>
|
|||
}
|
||||
|
||||
private void parseScenarioWithBLOBs(List<ApiScenarioWithBLOBs> scenarioWithBLOBsList, MsScenario msScenario, ApiTestImportRequest request) {
|
||||
/*
|
||||
ApiScenarioModule selectModule = null;
|
||||
if (StringUtils.isNotBlank(request.getModuleId())) {
|
||||
*/
|
||||
/*if (StringUtils.isNotBlank(request.getModuleId())) {
|
||||
selectModule = ApiScenarioImportUtil.getSelectModule(request.getModuleId());
|
||||
}
|
||||
ApiScenarioModule module = ApiScenarioImportUtil.buildModule(selectModule, msScenario.getName(), this.projectId);
|
||||
ApiScenarioModule module = ApiScenarioImportUtil.buildModule(selectModule, msScenario.getName(), this.projectId);*/
|
||||
ApiScenarioWithBLOBs scenarioWithBLOBs = parseScenario(msScenario);
|
||||
if (module != null) {
|
||||
/*if (module != null) {
|
||||
scenarioWithBLOBs.setApiScenarioModuleId(module.getId());
|
||||
if (selectModule != null) {
|
||||
String selectModulePath = ApiScenarioImportUtil.getSelectModulePath(selectModule.getName(), selectModule.getParentId());
|
||||
|
@ -75,7 +75,7 @@ public class HarScenarioParser extends HarScenarioAbstractParser<ScenarioImport>
|
|||
} else {
|
||||
scenarioWithBLOBs.setModulePath("/" + module.getName());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
scenarioWithBLOBsList.add(scenarioWithBLOBs);
|
||||
}
|
||||
|
||||
|
@ -89,47 +89,47 @@ public class HarScenarioParser extends HarScenarioAbstractParser<ScenarioImport>
|
|||
scenario.setHashTree(results);
|
||||
}
|
||||
|
||||
private RequestResult getRequestResult(MsHTTPSamplerProxy samplerProxy, HarEntry harEntry) {
|
||||
HarRequest request = harEntry.request;
|
||||
HarResponse response = harEntry.response;
|
||||
private RequestResult getRequestResult(MsHTTPSamplerProxy samplerProxy, HarEntry harEntry) {
|
||||
HarRequest request = harEntry.request;
|
||||
HarResponse response = harEntry.response;
|
||||
|
||||
RequestResult requestResult = new RequestResult();
|
||||
requestResult.setName("Response");
|
||||
requestResult.setUrl(request.url);
|
||||
requestResult.setMethod(request.method);
|
||||
if(samplerProxy.getBody()!= null){
|
||||
List<KeyValue> keyValueList = new ArrayList<>();
|
||||
if(!ObjectUtils.isEmpty(request.queryString)){
|
||||
for (HarQueryParm model : request.queryString) {
|
||||
KeyValue keyValue = new KeyValue(model.name,model.value);
|
||||
keyValueList.add(keyValue);
|
||||
RequestResult requestResult = new RequestResult();
|
||||
requestResult.setName("Response");
|
||||
requestResult.setUrl(request.url);
|
||||
requestResult.setMethod(request.method);
|
||||
if (samplerProxy.getBody() != null) {
|
||||
List<KeyValue> keyValueList = new ArrayList<>();
|
||||
if (!ObjectUtils.isEmpty(request.queryString)) {
|
||||
for (HarQueryParm model : request.queryString) {
|
||||
KeyValue keyValue = new KeyValue(model.name, model.value);
|
||||
keyValueList.add(keyValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!ObjectUtils.isEmpty(request.postData)&&!ObjectUtils.isEmpty(request.postData.params)){
|
||||
for (HarPostParam model : request.postData.params) {
|
||||
KeyValue keyValue = new KeyValue(model.name,model.value);
|
||||
keyValueList.add(keyValue);
|
||||
if (!ObjectUtils.isEmpty(request.postData) && !ObjectUtils.isEmpty(request.postData.params)) {
|
||||
for (HarPostParam model : request.postData.params) {
|
||||
KeyValue keyValue = new KeyValue(model.name, model.value);
|
||||
keyValueList.add(keyValue);
|
||||
}
|
||||
}
|
||||
|
||||
requestResult.setBody(JSONArray.toJSONString(keyValueList));
|
||||
}
|
||||
|
||||
requestResult.setBody(JSONArray.toJSONString(keyValueList));
|
||||
}
|
||||
requestResult.setHeaders(JSONArray.toJSONString(request.headers));
|
||||
requestResult.setRequestSize(request.bodySize);
|
||||
if (!ObjectUtils.isEmpty(request.cookies)) {
|
||||
requestResult.setCookies(JSONArray.toJSONString(request.cookies));
|
||||
}
|
||||
|
||||
requestResult.setHeaders(JSONArray.toJSONString(request.headers));
|
||||
requestResult.setRequestSize(request.bodySize);
|
||||
if(!ObjectUtils.isEmpty(request.cookies)){
|
||||
requestResult.setCookies(JSONArray.toJSONString(request.cookies));
|
||||
}
|
||||
ResponseResult responseResult = requestResult.getResponseResult();
|
||||
responseResult.setHeaders(JSONArray.toJSONString(response.headers));
|
||||
responseResult.setResponseCode(String.valueOf(response.status));
|
||||
responseResult.setResponseSize(response.bodySize);
|
||||
if (response.content != null && response.content.text != null) {
|
||||
responseResult.setBody(response.content.text);
|
||||
responseResult.setResponseMessage(response.content.text);
|
||||
}
|
||||
|
||||
ResponseResult responseResult = requestResult.getResponseResult();
|
||||
responseResult.setHeaders(JSONArray.toJSONString(response.headers));
|
||||
responseResult.setResponseCode(String.valueOf(response.status));
|
||||
responseResult.setResponseSize(response.bodySize);
|
||||
if(response.content != null && response.content.text != null){
|
||||
responseResult.setBody(response.content.text);
|
||||
responseResult.setResponseMessage(response.content.text);
|
||||
return requestResult;
|
||||
}
|
||||
|
||||
return requestResult;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import io.github.ningyu.jmeter.plugin.util.Constants;
|
|||
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||
import io.metersphere.api.dto.automation.ImportPoolsDTO;
|
||||
import io.metersphere.api.dto.definition.request.MsScenario;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
import io.metersphere.api.dto.definition.request.assertions.*;
|
||||
import io.metersphere.api.dto.definition.request.controller.MsLoopController;
|
||||
import io.metersphere.api.dto.definition.request.controller.MsTransactionController;
|
||||
|
@ -39,7 +38,6 @@ import io.metersphere.api.dto.scenario.request.BodyFile;
|
|||
import io.metersphere.api.dto.scenario.request.RequestType;
|
||||
import io.metersphere.api.parse.ApiImportAbstractParser;
|
||||
import io.metersphere.api.service.ApiTestEnvironmentService;
|
||||
import io.metersphere.base.domain.ApiScenarioModule;
|
||||
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiTestEnvironmentExample;
|
||||
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
||||
|
@ -48,6 +46,7 @@ import io.metersphere.commons.exception.MSException;
|
|||
import io.metersphere.commons.utils.BeanUtils;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.jmeter.assertions.*;
|
||||
|
@ -115,7 +114,7 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
|||
private List<ApiScenarioWithBLOBs> parseObj(MsScenario msScenario, ApiTestImportRequest request) {
|
||||
List<ApiScenarioWithBLOBs> scenarioWithBLOBsList = new ArrayList<>();
|
||||
ApiScenarioWithBLOBs scenarioWithBLOBs = new ApiScenarioWithBLOBs();
|
||||
ApiScenarioModule selectModule = null;
|
||||
/* ApiScenarioModule selectModule = null;
|
||||
String selectModulePath = null;
|
||||
if (StringUtils.isNotBlank(request.getModuleId())) {
|
||||
selectModule = ApiScenarioImportUtil.getSelectModule(request.getModuleId());
|
||||
|
@ -123,20 +122,20 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
|||
selectModulePath = ApiScenarioImportUtil.getSelectModulePath(selectModule.getName(), selectModule.getParentId());
|
||||
}
|
||||
}
|
||||
ApiScenarioModule module = ApiScenarioImportUtil.buildModule(selectModule, msScenario.getName(), this.projectId);
|
||||
ApiScenarioModule module = ApiScenarioImportUtil.buildModule(selectModule, msScenario.getName(), this.projectId);*/
|
||||
scenarioWithBLOBs.setName(request.getFileName());
|
||||
scenarioWithBLOBs.setProjectId(request.getProjectId());
|
||||
if (msScenario != null && CollectionUtils.isNotEmpty(msScenario.getHashTree())) {
|
||||
scenarioWithBLOBs.setStepTotal(msScenario.getHashTree().size());
|
||||
}
|
||||
if (module != null) {
|
||||
/*if (module != null) {
|
||||
scenarioWithBLOBs.setApiScenarioModuleId(module.getId());
|
||||
if (StringUtils.isNotBlank(selectModulePath)) {
|
||||
scenarioWithBLOBs.setModulePath(selectModulePath + "/" + module.getName());
|
||||
} else {
|
||||
scenarioWithBLOBs.setModulePath("/" + module.getName());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
scenarioWithBLOBs.setId(UUID.randomUUID().toString());
|
||||
scenarioWithBLOBs.setScenarioDefinition(JSON.toJSONString(msScenario));
|
||||
scenarioWithBLOBsList.add(scenarioWithBLOBs);
|
||||
|
|
|
@ -5,23 +5,24 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import com.alibaba.fastjson.parser.Feature;
|
||||
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||
import io.metersphere.api.dto.EnvironmentType;
|
||||
import io.metersphere.api.dto.definition.parse.ms.NodeTree;
|
||||
import io.metersphere.api.dto.definition.request.MsScenario;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
import io.metersphere.api.parse.MsAbstractParser;
|
||||
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class MsScenarioParser extends MsAbstractParser<ScenarioImport> {
|
||||
|
||||
private ApiScenarioModule selectModule;
|
||||
/* private ApiScenarioModule selectModule;
|
||||
|
||||
private String selectModulePath;
|
||||
private String selectModulePath;*/
|
||||
|
||||
@Override
|
||||
public ScenarioImport parse(InputStream source, ApiTestImportRequest request) {
|
||||
|
@ -29,12 +30,12 @@ public class MsScenarioParser extends MsAbstractParser<ScenarioImport> {
|
|||
this.projectId = request.getProjectId();
|
||||
JSONObject testObject = JSONObject.parseObject(testStr, Feature.OrderedField);
|
||||
|
||||
if (StringUtils.isNotBlank(request.getModuleId())) {
|
||||
/*if (StringUtils.isNotBlank(request.getModuleId())) {
|
||||
this.selectModule = ApiScenarioImportUtil.getSelectModule(request.getModuleId());
|
||||
if (this.selectModule != null) {
|
||||
this.selectModulePath = ApiScenarioImportUtil.getSelectModulePath(this.selectModule.getName(), this.selectModule.getParentId());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
if (testObject.get("projectName") != null || testObject.get("projectId") != null) {
|
||||
return parseMsFormat(testStr, request);
|
||||
|
@ -64,19 +65,25 @@ public class MsScenarioParser extends MsAbstractParser<ScenarioImport> {
|
|||
ScenarioImport scenarioImport = JSON.parseObject(testStr, ScenarioImport.class, Feature.DisableSpecialKeyDetect);
|
||||
List<ApiScenarioWithBLOBs> data = scenarioImport.getData();
|
||||
|
||||
Set<String> moduleIdSet = scenarioImport.getData().stream()
|
||||
.map(ApiScenarioWithBLOBs::getApiScenarioModuleId).collect(Collectors.toSet());
|
||||
/*Set<String> moduleIdSet = scenarioImport.getData().stream()
|
||||
.map(ApiScenarioWithBLOBs::getApiScenarioModuleId).collect(Collectors.toSet());*/
|
||||
|
||||
/*
|
||||
Map<String, NodeTree> nodeMap = null;
|
||||
*/
|
||||
/*
|
||||
List<NodeTree> nodeTree = scenarioImport.getNodeTree();
|
||||
if (CollectionUtils.isNotEmpty(nodeTree)) {
|
||||
*/
|
||||
/*if (CollectionUtils.isNotEmpty(nodeTree)) {
|
||||
cutDownTree(nodeTree, moduleIdSet);
|
||||
ApiScenarioImportUtil.createNodeTree(nodeTree, projectId, importRequest.getModuleId());
|
||||
nodeMap = getNodeMap(nodeTree);
|
||||
}
|
||||
}*/
|
||||
|
||||
if (CollectionUtils.isNotEmpty(data)) {
|
||||
/*
|
||||
Map<String, NodeTree> finalNodeMap = nodeMap;
|
||||
*/
|
||||
data.forEach(item -> {
|
||||
String scenarioDefinitionStr = item.getScenarioDefinition();
|
||||
if (StringUtils.isNotBlank(scenarioDefinitionStr)) {
|
||||
|
@ -94,7 +101,7 @@ public class MsScenarioParser extends MsAbstractParser<ScenarioImport> {
|
|||
}
|
||||
}
|
||||
|
||||
if (finalNodeMap != null && finalNodeMap.get(item.getApiScenarioModuleId()) != null) {
|
||||
/*if (finalNodeMap != null && finalNodeMap.get(item.getApiScenarioModuleId()) != null) {
|
||||
NodeTree node = finalNodeMap.get(item.getApiScenarioModuleId());
|
||||
item.setApiScenarioModuleId(node.getNewId());
|
||||
item.setModulePath(node.getPath());
|
||||
|
@ -104,13 +111,14 @@ public class MsScenarioParser extends MsAbstractParser<ScenarioImport> {
|
|||
}
|
||||
// 旧版本未导出模块
|
||||
parseModule(item.getModulePath(), importRequest, item);
|
||||
}
|
||||
}*/
|
||||
item.setProjectId(this.projectId);
|
||||
});
|
||||
}
|
||||
return scenarioImport;
|
||||
}
|
||||
|
||||
/*
|
||||
protected void parseModule(String modulePath, ApiTestImportRequest importRequest, ApiScenarioWithBLOBs apiScenarioWithBLOBs) {
|
||||
if (StringUtils.isEmpty(modulePath)) {
|
||||
return;
|
||||
|
@ -138,4 +146,5 @@ public class MsScenarioParser extends MsAbstractParser<ScenarioImport> {
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package io.metersphere.api.dto.automation.parse;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||
import io.metersphere.api.dto.definition.request.MsScenario;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||
import io.metersphere.api.dto.definition.request.variable.ScenarioVariable;
|
||||
import io.metersphere.api.dto.parse.postman.PostmanCollection;
|
||||
|
@ -11,9 +10,9 @@ import io.metersphere.api.dto.parse.postman.PostmanCollectionInfo;
|
|||
import io.metersphere.api.dto.parse.postman.PostmanItem;
|
||||
import io.metersphere.api.dto.parse.postman.PostmanKeyValue;
|
||||
import io.metersphere.api.parse.PostmanAbstractParserParser;
|
||||
import io.metersphere.base.domain.ApiScenarioModule;
|
||||
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
|
||||
import io.metersphere.commons.constants.VariableTypeConstants;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
@ -46,11 +45,11 @@ public class PostmanScenarioParser extends PostmanAbstractParserParser<ScenarioI
|
|||
}
|
||||
|
||||
private void parseScenarioWithBLOBs(List<ApiScenarioWithBLOBs> scenarioWithBLOBsList, MsScenario msScenario, ApiTestImportRequest request) {
|
||||
ApiScenarioModule selectModule = ApiScenarioImportUtil.getSelectModule(request.getModuleId());
|
||||
/* ApiScenarioModule selectModule = ApiScenarioImportUtil.getSelectModule(request.getModuleId());
|
||||
|
||||
ApiScenarioModule module = ApiScenarioImportUtil.buildModule(selectModule, msScenario.getName(), this.projectId);
|
||||
ApiScenarioModule module = ApiScenarioImportUtil.buildModule(selectModule, msScenario.getName(), this.projectId);*/
|
||||
ApiScenarioWithBLOBs scenarioWithBLOBs = parseScenario(msScenario);
|
||||
if (module != null) {
|
||||
/*if (module != null) {
|
||||
scenarioWithBLOBs.setApiScenarioModuleId(module.getId());
|
||||
if (selectModule != null) {
|
||||
String selectModulePath = ApiScenarioImportUtil.getSelectModulePath(selectModule.getName(), selectModule.getParentId());
|
||||
|
@ -58,7 +57,7 @@ public class PostmanScenarioParser extends PostmanAbstractParserParser<ScenarioI
|
|||
} else {
|
||||
scenarioWithBLOBs.setModulePath("/" + module.getName());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
scenarioWithBLOBsList.add(scenarioWithBLOBs);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,4 +8,6 @@ import lombok.Setter;
|
|||
@Setter
|
||||
public class ApiModuleDTO extends TreeNodeDTO<ApiModuleDTO> {
|
||||
private String protocol;
|
||||
|
||||
private String path;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class UpdateApiModuleDTO {
|
||||
private List<ApiModule> moduleList;
|
||||
private List<ApiDefinitionWithBLOBs> apiDefinitionWithBLOBsList;
|
||||
|
||||
}
|
|
@ -13,7 +13,6 @@ import io.metersphere.api.dto.scenario.KeyValue;
|
|||
import io.metersphere.api.dto.scenario.request.RequestType;
|
||||
import io.metersphere.api.service.EsbApiParamService;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import io.metersphere.base.domain.EsbApiParamsWithBLOBs;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
|
@ -580,7 +579,9 @@ public class ESBParser extends EsbAbstractParser {
|
|||
ApiDefinitionImport resultModel = new ApiDefinitionImport();
|
||||
List<ApiDefinitionWithBLOBs> apiDataList = new ArrayList<>();
|
||||
|
||||
/*
|
||||
ApiModule parentNode = ApiDefinitionImportUtil.getSelectModule(importRequest.getModuleId());
|
||||
*/
|
||||
EsbSheetDataStruct headSheetData = esbExcelDataStruct.getHeadData();
|
||||
List<EsbSheetDataStruct> interfaceDataList = esbExcelDataStruct.getInterfaceList();
|
||||
List<String> savedNames = new ArrayList<>();
|
||||
|
@ -603,8 +604,8 @@ public class ESBParser extends EsbAbstractParser {
|
|||
apiDefinition.setMethod("ESB");
|
||||
apiDefinition.setId(apiId);
|
||||
apiDefinition.setProjectId(this.projectId);
|
||||
apiDefinition.setModuleId(importRequest.getModuleId());
|
||||
apiDefinition.setModulePath(importRequest.getModulePath());
|
||||
/* apiDefinition.setModuleId(importRequest.getModuleId());
|
||||
apiDefinition.setModulePath(importRequest.getModulePath());*/
|
||||
apiDefinition.setRequest(genTCPSampler(esbSendRequest, reqDataStructStr));
|
||||
if (StringUtils.equalsIgnoreCase("schedule", importRequest.getType())) {
|
||||
apiDefinition.setUserId(importRequest.getUserId());
|
||||
|
@ -612,7 +613,7 @@ public class ESBParser extends EsbAbstractParser {
|
|||
apiDefinition.setUserId(SessionUtils.getUserId());
|
||||
}
|
||||
apiDefinition.setProtocol(RequestType.TCP);
|
||||
buildModule(parentNode, apiDefinition, null);
|
||||
/* buildModule(parentNode, apiDefinition, null);*/
|
||||
apiDataList.add(apiDefinition);
|
||||
|
||||
EsbApiParamsWithBLOBs apiParams = new EsbApiParamsWithBLOBs();
|
||||
|
|
|
@ -11,7 +11,6 @@ import io.metersphere.api.dto.scenario.Body;
|
|||
import io.metersphere.api.dto.scenario.KeyValue;
|
||||
import io.metersphere.api.dto.scenario.request.RequestType;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.commons.utils.XMLUtils;
|
||||
|
@ -60,14 +59,14 @@ public class HarParser extends HarAbstractParser {
|
|||
private List<ApiDefinitionWithBLOBs> parseRequests(Har har, ApiTestImportRequest importRequest) {
|
||||
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
||||
|
||||
ApiModule selectModule = null;
|
||||
String selectModulePath = null;
|
||||
if (StringUtils.isNotBlank(importRequest.getModuleId())) {
|
||||
/* ApiModule selectModule = null;
|
||||
String selectModulePath = null;*/
|
||||
/*if (StringUtils.isNotBlank(importRequest.getModuleId())) {
|
||||
selectModule = ApiDefinitionImportUtil.getSelectModule(importRequest.getModuleId());
|
||||
if (selectModule != null) {
|
||||
selectModulePath = ApiDefinitionImportUtil.getSelectModulePath(selectModule.getName(), selectModule.getParentId());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
List<HarEntry> harEntryList = new ArrayList<>();
|
||||
|
@ -113,7 +112,7 @@ public class HarParser extends HarAbstractParser {
|
|||
addBodyHeader(request);
|
||||
apiDefinition.setRequest(JSON.toJSONString(request));
|
||||
apiDefinition.setResponse(JSON.toJSONString(parseResponse(entry.response)));
|
||||
if (selectModule == null) {
|
||||
/*if (selectModule == null) {
|
||||
apiDefinition.setModuleId("default-module");
|
||||
|
||||
} else {
|
||||
|
@ -123,7 +122,7 @@ public class HarParser extends HarAbstractParser {
|
|||
apiDefinition.setModulePath(selectModulePath);
|
||||
} else {
|
||||
apiDefinition.setModulePath("/未规划接口");
|
||||
}
|
||||
}*/
|
||||
results.add(apiDefinition);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,6 @@ import io.metersphere.api.dto.definition.request.extract.MsExtractRegex;
|
|||
import io.metersphere.api.dto.definition.request.extract.MsExtractXPath;
|
||||
import io.metersphere.api.dto.definition.request.processors.post.MsJSR223PostProcessor;
|
||||
import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsDubboSampler;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsJDBCSampler;
|
||||
|
@ -35,11 +33,16 @@ import io.metersphere.api.dto.scenario.request.BodyFile;
|
|||
import io.metersphere.api.dto.scenario.request.RequestType;
|
||||
import io.metersphere.api.parse.ApiImportAbstractParser;
|
||||
import io.metersphere.api.service.ApiTestEnvironmentService;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiTestEnvironmentExample;
|
||||
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.BeanUtils;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.jmeter.assertions.*;
|
||||
|
@ -72,9 +75,7 @@ public class JmeterDefinitionParser extends ApiImportAbstractParser<ApiDefinitio
|
|||
private ImportPoolsDTO dataPools;
|
||||
private final String ENV_NAME = "导入数据环境";
|
||||
|
||||
private ApiModule selectModule;
|
||||
private ApiModule apiModule;
|
||||
private String selectModulePath;
|
||||
|
||||
private String planName = "default";
|
||||
private static final Integer GROUP_GLOBAL = 1;
|
||||
|
||||
|
@ -93,11 +94,11 @@ public class JmeterDefinitionParser extends ApiImportAbstractParser<ApiDefinitio
|
|||
|
||||
jmeterHashTree(testPlan, scenario);
|
||||
|
||||
this.selectModule = ApiDefinitionImportUtil.getSelectModule(request.getModuleId());
|
||||
/* this.selectModule = ApiDefinitionImportUtil.getSelectModule(request.getModuleId());
|
||||
if (this.selectModule != null) {
|
||||
this.selectModulePath = ApiDefinitionImportUtil.getSelectModulePath(this.selectModule.getName(), this.selectModule.getParentId());
|
||||
}
|
||||
this.apiModule = ApiDefinitionImportUtil.buildModule(this.selectModule, this.planName, this.projectId);
|
||||
this.apiModule = ApiDefinitionImportUtil.buildModule(this.selectModule, this.planName, this.projectId);*/
|
||||
|
||||
LinkedList<MsTestElement> elements = scenario.getHashTree();
|
||||
LinkedList<MsTestElement> results = new LinkedList<>();
|
||||
|
@ -279,14 +280,14 @@ public class JmeterDefinitionParser extends ApiImportAbstractParser<ApiDefinitio
|
|||
apiDefinition.setName(element.getName());
|
||||
apiDefinition.setProjectId(this.projectId);
|
||||
apiDefinition.setRequest(JSON.toJSONString(element));
|
||||
if (this.apiModule != null) {
|
||||
/* if (this.apiModule != null) {
|
||||
apiDefinition.setModuleId(this.apiModule.getId());
|
||||
if (StringUtils.isNotBlank(this.selectModulePath)) {
|
||||
apiDefinition.setModulePath(this.selectModulePath + "/" + this.apiModule.getName());
|
||||
} else {
|
||||
apiDefinition.setModulePath("/" + this.apiModule.getName());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
// todo 除HTTP协议外,其它协议设置默认模块
|
||||
apiDefinition.setStatus("Prepare");
|
||||
apiDefinition.setProtocol(protocol);
|
||||
|
@ -638,7 +639,7 @@ public class JmeterDefinitionParser extends ApiImportAbstractParser<ApiDefinitio
|
|||
});
|
||||
}
|
||||
elementNode.setAttachmentArgs(attachmentArgs);
|
||||
if(StringUtils.isEmpty(elementNode.getMethod())){
|
||||
if (StringUtils.isEmpty(elementNode.getMethod())) {
|
||||
elementNode.setMethod(elementNode.getProtocol());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,11 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||
import io.metersphere.api.dto.definition.parse.ms.NodeTree;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||
import io.metersphere.api.dto.scenario.request.RequestType;
|
||||
import io.metersphere.api.parse.ApiImportAbstractParser;
|
||||
import io.metersphere.api.parse.MsAbstractParser;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import io.metersphere.commons.constants.ApiImportPlatform;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
|
@ -21,26 +19,30 @@ import org.apache.commons.collections.MapUtils;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
||||
|
||||
private ApiModule selectModule;
|
||||
|
||||
private String selectModulePath;
|
||||
/* private ApiModule selectModule;
|
||||
|
||||
private String selectModulePath;*/
|
||||
|
||||
@Override
|
||||
public ApiDefinitionImport parse(InputStream source, ApiTestImportRequest request) {
|
||||
String testStr = getApiTestStr(source);
|
||||
JSONObject testObject = JSONObject.parseObject(testStr, Feature.DisableSpecialKeyDetect);
|
||||
this.projectId = request.getProjectId();
|
||||
if (StringUtils.isNotBlank(request.getModuleId())) {
|
||||
/*if (StringUtils.isNotBlank(request.getModuleId())) {
|
||||
this.selectModule = ApiDefinitionImportUtil.getSelectModule(request.getModuleId());
|
||||
if (this.selectModule != null) {
|
||||
this.selectModulePath = ApiDefinitionImportUtil.getSelectModulePath(this.selectModule.getName(), this.selectModule.getParentId());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
if (testObject.get("projectName") != null || testObject.get("projectId") != null) {// metersphere 格式导入
|
||||
return parseMsFormat(testStr, request);
|
||||
|
@ -56,14 +58,16 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
|||
protected List<ApiDefinitionWithBLOBs> parsePluginFormat(JSONObject testObject, ApiTestImportRequest importRequest, Boolean isCreateModule) {
|
||||
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
||||
testObject.keySet().forEach(tag -> {
|
||||
String moduleId = null;
|
||||
/*String moduleId = null;
|
||||
if (isCreateModule) {
|
||||
moduleId = ApiDefinitionImportUtil.buildModule(this.selectModule, tag, this.projectId).getId();
|
||||
}
|
||||
}*/
|
||||
List<MsHTTPSamplerProxy> msHTTPSamplerProxies = parseMsHTTPSamplerProxy(testObject, tag, false);
|
||||
for (MsHTTPSamplerProxy msHTTPSamplerProxy : msHTTPSamplerProxies) {
|
||||
ApiDefinitionWithBLOBs apiDefinition = buildApiDefinition(msHTTPSamplerProxy.getId(), msHTTPSamplerProxy.getName(), msHTTPSamplerProxy.getPath(), msHTTPSamplerProxy.getMethod(), importRequest);
|
||||
/*
|
||||
apiDefinition.setModuleId(moduleId);
|
||||
*/
|
||||
apiDefinition.setProjectId(this.projectId);
|
||||
apiDefinition.setRequest(JSONObject.toJSONString(msHTTPSamplerProxy));
|
||||
apiDefinition.setName(apiDefinition.getPath() + " [" + apiDefinition.getMethod() + "]");
|
||||
|
@ -89,21 +93,21 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
|||
caseList.add(item);
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
Set<String> moduleIdSet = apiDefinitionImport.getData().stream()
|
||||
.map(ApiDefinitionWithBLOBs::getModuleId).collect(Collectors.toSet());
|
||||
.map(ApiDefinitionWithBLOBs::getModuleId).collect(Collectors.toSet());*/
|
||||
|
||||
Map<String, NodeTree> nodeMap = null;
|
||||
/* Map<String, NodeTree> nodeMap = null;
|
||||
List<NodeTree> nodeTree = apiDefinitionImport.getNodeTree();
|
||||
if (CollectionUtils.isNotEmpty(nodeTree)) {
|
||||
cutDownTree(nodeTree, moduleIdSet);
|
||||
ApiDefinitionImportUtil.createNodeTree(nodeTree, projectId, importRequest.getModuleId());
|
||||
nodeMap = getNodeMap(nodeTree);
|
||||
}
|
||||
}*/
|
||||
|
||||
Map<String, NodeTree> finalNodeMap = nodeMap;
|
||||
/*Map<String, NodeTree> finalNodeMap = nodeMap;*/
|
||||
apiDefinitionImport.getData().forEach(apiDefinition -> {
|
||||
parseApiDefinition(apiDefinition, importRequest, caseMap, finalNodeMap);
|
||||
parseApiDefinition(apiDefinition, importRequest, caseMap);
|
||||
});
|
||||
if (MapUtils.isNotEmpty(caseMap)) {
|
||||
List<ApiTestCaseWithBLOBs> list = new ArrayList<>();
|
||||
|
@ -116,9 +120,9 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
|||
}
|
||||
|
||||
private void parseApiDefinition(ApiDefinitionWithBLOBs apiDefinition, ApiTestImportRequest importRequest,
|
||||
Map<String, List<ApiTestCaseWithBLOBs>> caseMap, Map<String, NodeTree> nodeMap) {
|
||||
Map<String, List<ApiTestCaseWithBLOBs>> caseMap) {
|
||||
String originId = apiDefinition.getId();
|
||||
if (nodeMap != null && nodeMap.get(apiDefinition.getModuleId()) != null) {
|
||||
/*if (nodeMap != null && nodeMap.get(apiDefinition.getModuleId()) != null) {
|
||||
NodeTree nodeTree = nodeMap.get(apiDefinition.getModuleId());
|
||||
apiDefinition.setModuleId(nodeTree.getNewId());
|
||||
apiDefinition.setModulePath(nodeTree.getPath());
|
||||
|
@ -128,7 +132,7 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
|||
}
|
||||
// 旧版本未导出模块
|
||||
parseModule(apiDefinition.getModulePath(), importRequest, apiDefinition);
|
||||
}
|
||||
}*/
|
||||
|
||||
apiDefinition.setProjectId(this.projectId);
|
||||
JSONObject requestObj = this.parseObject(apiDefinition.getRequest(), apiDefinition.getProjectId());
|
||||
|
@ -191,6 +195,7 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
private void parseModule(String modulePath, ApiTestImportRequest importRequest, ApiDefinitionWithBLOBs apiDefinition) {
|
||||
if (StringUtils.isEmpty(modulePath)) {
|
||||
return;
|
||||
|
@ -218,4 +223,5 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import io.metersphere.api.dto.parse.postman.PostmanItem;
|
|||
import io.metersphere.api.dto.parse.postman.PostmanKeyValue;
|
||||
import io.metersphere.api.parse.PostmanAbstractParserParser;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import io.metersphere.base.domain.Project;
|
||||
import io.metersphere.base.mapper.ProjectMapper;
|
||||
|
@ -19,16 +18,15 @@ import io.metersphere.commons.utils.BeanUtils;
|
|||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.dto.ProjectConfig;
|
||||
import io.metersphere.service.ProjectApplicationService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
||||
public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefinitionImport> {
|
||||
|
||||
private ApiModule selectModule;
|
||||
/*private ApiModule selectModule;
|
||||
|
||||
private String selectModulePath;
|
||||
private String selectModulePath;*/
|
||||
|
||||
@Override
|
||||
public ApiDefinitionImport parse(InputStream source, ApiTestImportRequest request) {
|
||||
|
@ -38,12 +36,12 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefi
|
|||
List<PostmanKeyValue> variables = postmanCollection.getVariable();
|
||||
ApiDefinitionImport apiImport = new ApiDefinitionImport();
|
||||
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
||||
this.selectModule = ApiDefinitionImportUtil.getSelectModule(request.getModuleId());
|
||||
/*this.selectModule = ApiDefinitionImportUtil.getSelectModule(request.getModuleId());
|
||||
if (this.selectModule != null) {
|
||||
this.selectModulePath = ApiDefinitionImportUtil.getSelectModulePath(this.selectModule.getName(), this.selectModule.getParentId());
|
||||
}
|
||||
|
||||
ApiModule apiModule = ApiDefinitionImportUtil.buildModule(this.selectModule, postmanCollection.getInfo().getName(), this.projectId);
|
||||
ApiModule apiModule = ApiDefinitionImportUtil.buildModule(this.selectModule, postmanCollection.getInfo().getName(), this.projectId);*/
|
||||
List<ApiTestCaseWithBLOBs> cases = new ArrayList<>();
|
||||
Map<String, String> repeatMap = new HashMap();
|
||||
ProjectMapper projectMapper = CommonBeanFactory.getBean(ProjectMapper.class);
|
||||
|
@ -52,7 +50,7 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefi
|
|||
ProjectConfig config = projectApplicationService.getSpecificTypeValue(project.getId(), ProjectApplicationType.URL_REPEATABLE.name());
|
||||
boolean urlRepeat = config.getUrlRepeatable();
|
||||
parseItem(postmanCollection.getItem(), variables, results,
|
||||
apiModule, apiModule.getName(), cases, repeatMap, urlRepeat);
|
||||
cases, repeatMap, urlRepeat);
|
||||
Collections.reverse(results); // 调整顺序
|
||||
Collections.reverse(cases);
|
||||
apiImport.setData(results);
|
||||
|
@ -61,13 +59,13 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefi
|
|||
}
|
||||
|
||||
protected void parseItem(List<PostmanItem> items, List<PostmanKeyValue> variables, List<ApiDefinitionWithBLOBs> results,
|
||||
ApiModule parentModule, String path, List<ApiTestCaseWithBLOBs> cases, Map<String, String> repeatMap, Boolean repeatable) {
|
||||
List<ApiTestCaseWithBLOBs> cases, Map<String, String> repeatMap, Boolean repeatable) {
|
||||
for (PostmanItem item : items) {
|
||||
List<PostmanItem> childItems = item.getItem();
|
||||
if (childItems != null) {
|
||||
ApiModule module = null;
|
||||
module = ApiDefinitionImportUtil.buildModule(parentModule, item.getName(), this.projectId);
|
||||
parseItem(childItems, variables, results, module, path + "/" + module.getName(), cases, repeatMap, repeatable);
|
||||
/*ApiModule module = null;
|
||||
module = ApiDefinitionImportUtil.buildModule(parentModule, item.getName(), this.projectId);*/
|
||||
parseItem(childItems, variables, results, cases, repeatMap, repeatable);
|
||||
} else {
|
||||
MsHTTPSamplerProxy msHTTPSamplerProxy = parsePostman(item);
|
||||
HttpResponse response = parsePostmanResponse(item);
|
||||
|
@ -76,14 +74,14 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefi
|
|||
request.setPath(msHTTPSamplerProxy.getPath());
|
||||
request.setRequest(JSON.toJSONString(msHTTPSamplerProxy));
|
||||
request.setResponse(JSON.toJSONString(response));
|
||||
if (parentModule != null) {
|
||||
/*if (parentModule != null) {
|
||||
request.setModuleId(parentModule.getId());
|
||||
if (StringUtils.isNotBlank(this.selectModulePath)) {
|
||||
request.setModulePath(this.selectModulePath + "/" + path);
|
||||
} else {
|
||||
request.setModulePath("/" + path);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
if (request != null) {
|
||||
if (repeatMap.keySet().contains(request.getMethod() + request.getPath())
|
||||
&& (repeatable == null || repeatable == false)) {
|
||||
|
|
|
@ -11,7 +11,6 @@ import io.metersphere.api.dto.scenario.Body;
|
|||
import io.metersphere.api.dto.scenario.KeyValue;
|
||||
import io.metersphere.api.dto.scenario.request.RequestType;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import io.metersphere.commons.constants.SwaggerParameterType;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
|
@ -115,14 +114,14 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
|||
|
||||
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
||||
|
||||
ApiModule selectModule = null;
|
||||
/*ApiModule selectModule = null;
|
||||
String selectModulePath = null;
|
||||
if (StringUtils.isNotBlank(importRequest.getModuleId())) {
|
||||
selectModule = ApiDefinitionImportUtil.getSelectModule(importRequest.getModuleId());
|
||||
if (selectModule != null) {
|
||||
selectModulePath = ApiDefinitionImportUtil.getSelectModulePath(selectModule.getName(), selectModule.getParentId());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
String basePath = swagger.getBasePath();
|
||||
for (String pathName : pathNames) {
|
||||
|
@ -142,7 +141,9 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
|||
}
|
||||
apiDefinition.setRequest(JSON.toJSONString(request));
|
||||
apiDefinition.setResponse(JSON.toJSONString(parseResponse(operation, operation.getResponses())));
|
||||
/*
|
||||
buildModule(selectModule, apiDefinition, operation.getTags(), selectModulePath);
|
||||
*/
|
||||
if (operation.isDeprecated() != null && operation.isDeprecated()) {
|
||||
apiDefinition.setTags("[\"Deleted\"]");
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ import io.metersphere.api.dto.scenario.KeyValue;
|
|||
import io.metersphere.api.dto.scenario.request.RequestType;
|
||||
import io.metersphere.api.service.ApiModuleService;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
|
@ -131,14 +130,14 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
|||
|
||||
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
||||
|
||||
ApiModule selectModule = null;
|
||||
/*ApiModule selectModule = null;
|
||||
String selectModulePath = null;
|
||||
if (StringUtils.isNotBlank(importRequest.getModuleId())) {
|
||||
selectModule = ApiDefinitionImportUtil.getSelectModule(importRequest.getModuleId());
|
||||
if (selectModule != null) {
|
||||
selectModulePath = ApiDefinitionImportUtil.getSelectModulePath(selectModule.getName(), selectModule.getParentId());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
for (String pathName : pathNames) {
|
||||
PathItem pathItem = paths.get(pathName);
|
||||
|
@ -167,7 +166,9 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
|||
} // 有数据的话,去掉 Kvs 里初始化的第一个全 null 的数据,否则有空行
|
||||
apiDefinition.setRequest(JSON.toJSONString(request));
|
||||
apiDefinition.setResponse(JSON.toJSONString(parseResponse(operation.getResponses())));
|
||||
/*
|
||||
buildModule(selectModule, apiDefinition, operation.getTags(), selectModulePath);
|
||||
*/
|
||||
if (operation.getDeprecated() != null && operation.getDeprecated()) {
|
||||
apiDefinition.setTags("[\"Deleted\"]");
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.metersphere.api.dto.*;
|
||||
import io.metersphere.api.dto.automation.*;
|
||||
import io.metersphere.api.dto.automation.parse.ApiScenarioImportUtil;
|
||||
|
@ -1249,7 +1251,7 @@ public class ApiAutomationService {
|
|||
}
|
||||
|
||||
private ApiScenarioWithBLOBs importCreate(ApiScenarioWithBLOBs request, ApiScenarioMapper batchMapper, ExtApiScenarioMapper extApiScenarioMapper,
|
||||
ApiTestImportRequest apiTestImportRequest, ApiTestCaseMapper apiTestCaseMapper, ApiDefinitionMapper apiDefinitionMapper) {
|
||||
ApiTestImportRequest apiTestImportRequest, List<ApiScenarioWithBLOBs> sameList, ApiTestCaseMapper apiTestCaseMapper, ApiDefinitionMapper apiDefinitionMapper) {
|
||||
final ApiScenarioWithBLOBs scenarioWithBLOBs = new ApiScenarioWithBLOBs();
|
||||
BeanUtils.copyBean(scenarioWithBLOBs, request);
|
||||
scenarioWithBLOBs.setCreateTime(System.currentTimeMillis());
|
||||
|
@ -1268,14 +1270,12 @@ public class ApiAutomationService {
|
|||
}
|
||||
scenarioWithBLOBs.setDescription(request.getDescription());
|
||||
|
||||
List<ApiScenarioWithBLOBs> sameRequest = getSameScenario(scenarioWithBLOBs);
|
||||
|
||||
Boolean openCustomNum = apiTestImportRequest.getOpenCustomNum();
|
||||
List<ApiScenario> list = new ArrayList<>();
|
||||
if (BooleanUtils.isTrue(openCustomNum)) {
|
||||
ApiScenarioExample example = new ApiScenarioExample();
|
||||
ApiScenarioExample.Criteria criteria = example.createCriteria();
|
||||
if (CollectionUtils.isEmpty(sameRequest)) {
|
||||
if (CollectionUtils.isEmpty(sameList)) {
|
||||
criteria.andCustomNumEqualTo(scenarioWithBLOBs.getCustomNum())
|
||||
.andProjectIdEqualTo(scenarioWithBLOBs.getProjectId());
|
||||
} else {
|
||||
|
@ -1283,7 +1283,7 @@ public class ApiAutomationService {
|
|||
criteria.andNameEqualTo(scenarioWithBLOBs.getName())
|
||||
.andCustomNumEqualTo(scenarioWithBLOBs.getCustomNum())
|
||||
.andProjectIdEqualTo(scenarioWithBLOBs.getProjectId())
|
||||
.andIdNotEqualTo(sameRequest.get(0).getId());
|
||||
.andIdNotEqualTo(sameList.get(0).getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1298,9 +1298,9 @@ public class ApiAutomationService {
|
|||
}
|
||||
|
||||
if (StringUtils.equals("fullCoverage", apiTestImportRequest.getModeId())) {
|
||||
_importCreate(sameRequest, batchMapper, extApiScenarioMapper, scenarioWithBLOBs, apiTestImportRequest, apiTestCaseMapper, apiDefinitionMapper);
|
||||
_importCreate(sameList, batchMapper, extApiScenarioMapper, scenarioWithBLOBs, apiTestImportRequest, apiTestCaseMapper, apiDefinitionMapper);
|
||||
} else if (StringUtils.equals("incrementalMerge", apiTestImportRequest.getModeId())) {
|
||||
if (CollectionUtils.isEmpty(sameRequest)) {
|
||||
if (CollectionUtils.isEmpty(sameList)) {
|
||||
scenarioWithBLOBs.setOrder(getImportNextOrder(request.getProjectId()));
|
||||
scenarioWithBLOBs.setId(UUID.randomUUID().toString());
|
||||
scenarioWithBLOBs.setRefId(scenarioWithBLOBs.getId());
|
||||
|
@ -1321,19 +1321,30 @@ public class ApiAutomationService {
|
|||
}
|
||||
|
||||
} else {
|
||||
_importCreate(sameRequest, batchMapper, extApiScenarioMapper, scenarioWithBLOBs, apiTestImportRequest, apiTestCaseMapper, apiDefinitionMapper);
|
||||
_importCreate(sameList, batchMapper, extApiScenarioMapper, scenarioWithBLOBs, apiTestImportRequest, apiTestCaseMapper, apiDefinitionMapper);
|
||||
}
|
||||
return scenarioWithBLOBs;
|
||||
}
|
||||
|
||||
private void editScenario(ApiTestImportRequest request, ScenarioImport apiImport) {
|
||||
ApiScenarioModuleService apiScenarioModuleService = CommonBeanFactory.getBean(ApiScenarioModuleService.class);
|
||||
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
ApiScenarioMapper batchMapper = sqlSession.getMapper(ApiScenarioMapper.class);
|
||||
ExtApiScenarioMapper extApiScenarioMapper = sqlSession.getMapper(ExtApiScenarioMapper.class);
|
||||
ApiTestCaseMapper apiTestCaseMapper = sqlSession.getMapper(ApiTestCaseMapper.class);
|
||||
ApiDefinitionMapper apiDefinitionMapper = sqlSession.getMapper(ApiDefinitionMapper.class);
|
||||
ApiScenarioModuleMapper apiScenarioModuleMapper = sqlSession.getMapper(ApiScenarioModuleMapper.class);
|
||||
|
||||
List<ApiScenarioWithBLOBs> data = apiImport.getData();
|
||||
currentScenarioOrder.remove();
|
||||
|
||||
UpdateScenarioModuleDTO updateScenarioModuleDTO = apiScenarioModuleService.checkScenarioModule(request.getModuleId(), request.getProjectId(), data, StringUtils.equals("fullCoverage", request.getModeId()), request.getCoverModule());
|
||||
List<ApiScenarioModule> moduleList = updateScenarioModuleDTO.getModuleList();
|
||||
List<ApiScenarioWithBLOBs> apiScenarioWithBLOBsList = updateScenarioModuleDTO.getApiScenarioWithBLOBsList();
|
||||
for (ApiScenarioModule apiScenarioModule : moduleList) {
|
||||
apiScenarioModuleMapper.insert(apiScenarioModule);
|
||||
}
|
||||
int num = 0;
|
||||
Project project = new Project();
|
||||
if (!CollectionUtils.isEmpty(data) && data.get(0) != null && data.get(0).getProjectId() != null) {
|
||||
|
@ -1345,11 +1356,9 @@ public class ApiAutomationService {
|
|||
String defaultVersion = extProjectVersionMapper.getDefaultVersion(request.getProjectId());
|
||||
request.setDefaultVersion(defaultVersion);
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
ApiScenarioWithBLOBs item = data.get(i);
|
||||
if (StringUtils.isBlank(item.getApiScenarioModuleId()) || "default-module".equals(item.getApiScenarioModuleId())) {
|
||||
replenishScenarioModuleIdPath(request.getProjectId(), apiScenarioModuleMapper, item);
|
||||
}
|
||||
|
||||
ApiScenarioWithBLOBs item = data.get(i);
|
||||
List<ApiScenarioWithBLOBs> sameList = apiScenarioWithBLOBsList.stream().filter(t -> t.getName().equals(item.getName())).collect(Collectors.toList());
|
||||
if (StringUtils.isBlank(item.getCreateUser())) {
|
||||
item.setCreateUser(SessionUtils.getUserId());
|
||||
}
|
||||
|
@ -1373,11 +1382,12 @@ public class ApiAutomationService {
|
|||
item.setUserId(SessionUtils.getUserId());
|
||||
item.setPrincipal(SessionUtils.getUserId());
|
||||
// 导入之后刷新latest
|
||||
importCreate(item, batchMapper, extApiScenarioMapper, request, apiTestCaseMapper, apiDefinitionMapper);
|
||||
importCreate(item, batchMapper, extApiScenarioMapper, request, sameList, apiTestCaseMapper, apiDefinitionMapper);
|
||||
if (i % 300 == 0) {
|
||||
sqlSession.flushStatements();
|
||||
}
|
||||
}
|
||||
|
||||
sqlSession.flushStatements();
|
||||
if (sqlSession != null && sqlSessionFactory != null) {
|
||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
|
@ -2142,4 +2152,39 @@ public class ApiAutomationService {
|
|||
}
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
public Boolean checkIsSynchronize(ApiScenarioWithBLOBs existApiScenario, ApiScenarioWithBLOBs apiScenario) {
|
||||
|
||||
ApiScenario exScenario;
|
||||
ApiScenario scenario;
|
||||
exScenario = existApiScenario;
|
||||
scenario = apiScenario;
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
String exScenarioString = null;
|
||||
String scenarioString = null;
|
||||
try {
|
||||
exScenarioString = objectMapper.writeValueAsString(exScenario);
|
||||
scenarioString = objectMapper.writeValueAsString(scenario);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//Compare the basic information of the APIScenario.
|
||||
|
||||
if (!StringUtils.equals(exScenario.getName(), scenario.getName())) {
|
||||
return true;
|
||||
}
|
||||
if (!StringUtils.equals(exScenarioString, scenarioString)) {
|
||||
return true;
|
||||
}
|
||||
if (!StringUtils.equals(existApiScenario.getEnvironmentJson(), apiScenario.getEnvironmentJson())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!StringUtils.equals(existApiScenario.getDescription(), apiScenario.getDescription())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return !StringUtils.equals(existApiScenario.getScenarioDefinition(), apiScenario.getScenarioDefinition());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,6 +76,8 @@ import java.util.*;
|
|||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class ApiDefinitionService {
|
||||
|
@ -143,6 +145,7 @@ public class ApiDefinitionService {
|
|||
@Resource
|
||||
private ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper;
|
||||
|
||||
|
||||
@Lazy
|
||||
@Resource
|
||||
private ApiModuleService apiModuleService;
|
||||
|
@ -700,7 +703,7 @@ public class ApiDefinitionService {
|
|||
// 创建新版是否关联依赖关系
|
||||
if (request.isNewVersionDeps()) {
|
||||
List<RelationshipEdgeDTO> pre = this.getRelationshipApi(oldApi.getId(), "PRE");
|
||||
List<String> targetIds = pre.stream().map(RelationshipEdgeKey::getTargetId).collect(Collectors.toList());
|
||||
List<String> targetIds = pre.stream().map(RelationshipEdgeKey::getTargetId).collect(toList());
|
||||
RelationshipEdgeRequest req = new RelationshipEdgeRequest();
|
||||
req.setTargetIds(targetIds);
|
||||
req.setType("API");
|
||||
|
@ -708,7 +711,7 @@ public class ApiDefinitionService {
|
|||
relationshipEdgeService.saveBatch(req);
|
||||
|
||||
List<RelationshipEdgeDTO> post = this.getRelationshipApi(oldApi.getId(), "POST");
|
||||
List<String> sourceIds = post.stream().map(RelationshipEdgeKey::getSourceId).collect(Collectors.toList());
|
||||
List<String> sourceIds = post.stream().map(RelationshipEdgeKey::getSourceId).collect(toList());
|
||||
RelationshipEdgeRequest req2 = new RelationshipEdgeRequest();
|
||||
req2.setSourceIds(sourceIds);
|
||||
req2.setType("API");
|
||||
|
@ -798,10 +801,10 @@ public class ApiDefinitionService {
|
|||
}
|
||||
}
|
||||
|
||||
private ApiDefinition importCreate(ApiDefinitionWithBLOBs apiDefinition, ApiDefinitionMapper batchMapper,
|
||||
ApiTestCaseMapper apiTestCaseMapper, ExtApiDefinitionMapper extApiDefinitionMapper,
|
||||
private ApiDefinition importCreate(ApiDefinitionWithBLOBs apiDefinition, ApiDefinitionMapper batchMapper, ApiTestCaseMapper apiTestCaseMapper,
|
||||
ExtApiDefinitionMapper extApiDefinitionMapper,
|
||||
ApiTestImportRequest apiTestImportRequest, List<ApiTestCaseWithBLOBs> cases, List<MockConfigImportDTO> mocks,
|
||||
Boolean repeatable) {
|
||||
List<ApiDefinitionWithBLOBs> updateList) {
|
||||
SaveApiDefinitionRequest saveReq = new SaveApiDefinitionRequest();
|
||||
BeanUtils.copyBean(saveReq, apiDefinition);
|
||||
apiDefinition.setCreateTime(System.currentTimeMillis());
|
||||
|
@ -814,27 +817,13 @@ public class ApiDefinitionService {
|
|||
} else {
|
||||
apiDefinition.setUserId(apiDefinition.getUserId());
|
||||
}
|
||||
if (apiDefinition.getModuleId() == null) {
|
||||
if (StringUtils.isEmpty(apiDefinition.getModuleId()) || "default-module".equals(apiDefinition.getModuleId())) {
|
||||
initModulePathAndId(apiDefinition.getProjectId(), apiDefinition);
|
||||
}
|
||||
}
|
||||
apiDefinition.setDescription(apiDefinition.getDescription());
|
||||
List<ApiDefinitionWithBLOBs> collect = updateList.stream().filter(t -> t.getId().equals(apiDefinition.getId())).collect(toList());
|
||||
|
||||
List<ApiDefinitionWithBLOBs> sameRequest;
|
||||
if (repeatable == null || !repeatable) {
|
||||
sameRequest = getSameRequest(saveReq);
|
||||
} else {
|
||||
// 如果勾选了允许重复,则判断更新要加上name字段
|
||||
sameRequest = getSameRequestWithName(saveReq);
|
||||
}
|
||||
if (CollectionUtils.isEmpty(sameRequest)) {
|
||||
sameRequest = getSameRequestById(apiDefinition.getId(), apiTestImportRequest.getProjectId());
|
||||
}
|
||||
if (StringUtils.equals("fullCoverage", apiTestImportRequest.getModeId())) {
|
||||
_importCreate(sameRequest, batchMapper, apiDefinition, apiTestCaseMapper, extApiDefinitionMapper, apiTestImportRequest, cases, mocks);
|
||||
_importCreate(collect, batchMapper, apiTestCaseMapper, apiDefinition, extApiDefinitionMapper, apiTestImportRequest, cases, mocks);
|
||||
} else if (StringUtils.equals("incrementalMerge", apiTestImportRequest.getModeId())) {
|
||||
if (CollectionUtils.isEmpty(sameRequest)) {
|
||||
if (CollectionUtils.isEmpty(collect)) {
|
||||
//postman 可能含有前置脚本,接口定义去掉脚本
|
||||
apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId()));
|
||||
String originId = apiDefinition.getId();
|
||||
|
@ -856,13 +845,13 @@ public class ApiDefinitionService {
|
|||
reSetImportCasesApiId(cases, originId, apiDefinition.getId());
|
||||
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
|
||||
apiDefinition.setRequest(requestStr);
|
||||
importApiCase(apiDefinition, apiTestImportRequest);
|
||||
importApiCase(apiDefinition, apiTestImportRequest, apiTestCaseMapper);
|
||||
} else {
|
||||
//不覆盖的接口,如果没有sameRequest则不导入。此时清空mock信息
|
||||
mocks.clear();
|
||||
}
|
||||
} else {
|
||||
_importCreate(sameRequest, batchMapper, apiDefinition, apiTestCaseMapper, extApiDefinitionMapper, apiTestImportRequest, cases, mocks);
|
||||
_importCreate(collect, batchMapper, apiTestCaseMapper, apiDefinition, extApiDefinitionMapper, apiTestImportRequest, cases, mocks);
|
||||
}
|
||||
|
||||
return apiDefinition;
|
||||
|
@ -888,8 +877,8 @@ public class ApiDefinitionService {
|
|||
return order;
|
||||
}
|
||||
|
||||
private void _importCreate(List<ApiDefinitionWithBLOBs> sameRequest, ApiDefinitionMapper batchMapper, ApiDefinitionWithBLOBs apiDefinition,
|
||||
ApiTestCaseMapper apiTestCaseMapper, ExtApiDefinitionMapper extApiDefinitionMapper,
|
||||
private void _importCreate(List<ApiDefinitionWithBLOBs> sameRequest, ApiDefinitionMapper batchMapper, ApiTestCaseMapper apiTestCaseMapper, ApiDefinitionWithBLOBs apiDefinition,
|
||||
ExtApiDefinitionMapper extApiDefinitionMapper,
|
||||
ApiTestImportRequest apiTestImportRequest, List<ApiTestCaseWithBLOBs> cases, List<MockConfigImportDTO> mocks) {
|
||||
String originId = apiDefinition.getId();
|
||||
|
||||
|
@ -913,7 +902,7 @@ public class ApiDefinitionService {
|
|||
batchMapper.insert(apiDefinition);
|
||||
String request = setImportHashTree(apiDefinition);
|
||||
apiDefinition.setRequest(request);
|
||||
importApiCase(apiDefinition, apiTestImportRequest);
|
||||
importApiCase(apiDefinition, apiTestImportRequest, apiTestCaseMapper);
|
||||
} else {
|
||||
if (StringUtils.equalsAnyIgnoreCase(apiDefinition.getProtocol(), RequestType.TCP)) {
|
||||
setImportTCPHashTree(apiDefinition);
|
||||
|
@ -969,14 +958,12 @@ public class ApiDefinitionService {
|
|||
//如果存在则修改
|
||||
apiDefinition.setId(existApi.getId());
|
||||
String request = setImportHashTree(apiDefinition);
|
||||
apiDefinition.setModuleId(existApi.getModuleId());
|
||||
apiDefinition.setModulePath(existApi.getModulePath());
|
||||
apiDefinition.setOrder(existApi.getOrder());
|
||||
apiDefinitionMapper.updateByPrimaryKeyWithBLOBs(apiDefinition);
|
||||
apiDefinition.setRequest(request);
|
||||
reSetImportCasesApiId(cases, originId, apiDefinition.getId());
|
||||
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
|
||||
importApiCase(apiDefinition, apiTestImportRequest);
|
||||
importApiCase(apiDefinition, apiTestImportRequest, apiTestCaseMapper);
|
||||
} else {
|
||||
apiDefinition.setId(existApi.getId());
|
||||
if (StringUtils.equalsAnyIgnoreCase(apiDefinition.getProtocol(), RequestType.TCP)) {
|
||||
|
@ -993,7 +980,7 @@ public class ApiDefinitionService {
|
|||
}
|
||||
}
|
||||
|
||||
private Boolean checkIsSynchronize(ApiDefinitionWithBLOBs existApi, ApiDefinitionWithBLOBs apiDefinition) {
|
||||
public Boolean checkIsSynchronize(ApiDefinitionWithBLOBs existApi, ApiDefinitionWithBLOBs apiDefinition) {
|
||||
|
||||
ApiDefinition exApi;
|
||||
ApiDefinition api;
|
||||
|
@ -1125,7 +1112,7 @@ public class ApiDefinitionService {
|
|||
}
|
||||
|
||||
private void importMsCase(ApiDefinitionImport apiImport, SqlSession sqlSession,
|
||||
ApiTestImportRequest request) {
|
||||
ApiTestImportRequest request, ApiTestCaseMapper apiTestCaseMapper) {
|
||||
List<ApiTestCaseWithBLOBs> cases = apiImport.getCases();
|
||||
if (CollectionUtils.isNotEmpty(cases)) {
|
||||
int batchCount = 0;
|
||||
|
@ -1135,7 +1122,7 @@ public class ApiDefinitionService {
|
|||
if (apiDefinitionWithBLOBs == null) {
|
||||
continue;
|
||||
}
|
||||
insertOrUpdateImportCase(item, request, apiDefinitionWithBLOBs);
|
||||
insertOrUpdateImportCase(item, request, apiDefinitionWithBLOBs, apiTestCaseMapper);
|
||||
}
|
||||
if (batchCount % 300 == 0) {
|
||||
sqlSession.flushStatements();
|
||||
|
@ -1147,7 +1134,7 @@ public class ApiDefinitionService {
|
|||
* 导入是插件或者postman时创建用例
|
||||
* postman考虑是否有前置脚本
|
||||
*/
|
||||
private void importApiCase(ApiDefinitionWithBLOBs apiDefinition, ApiTestImportRequest apiTestImportRequest) {
|
||||
private void importApiCase(ApiDefinitionWithBLOBs apiDefinition, ApiTestImportRequest apiTestImportRequest, ApiTestCaseMapper apiTestCaseMapper) {
|
||||
try {
|
||||
if (StringUtils.equalsAnyIgnoreCase(apiTestImportRequest.getPlatform(), ApiImportPlatform.Plugin.name(), ApiImportPlatform.Postman.name())) {
|
||||
ApiTestCaseWithBLOBs apiTestCase = new ApiTestCaseWithBLOBs();
|
||||
|
@ -1157,14 +1144,14 @@ public class ApiDefinitionService {
|
|||
if (apiTestCase.getName().length() > 255) {
|
||||
apiTestCase.setName(apiTestCase.getName().substring(0, 255));
|
||||
}
|
||||
insertOrUpdateImportCase(apiTestCase, apiTestImportRequest, apiDefinition);
|
||||
insertOrUpdateImportCase(apiTestCase, apiTestImportRequest, apiDefinition, apiTestCaseMapper);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error("导入创建用例异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void insertOrUpdateImportCase(ApiTestCaseWithBLOBs apiTestCase, ApiTestImportRequest apiTestImportRequest, ApiDefinitionWithBLOBs apiDefinition) {
|
||||
private void insertOrUpdateImportCase(ApiTestCaseWithBLOBs apiTestCase, ApiTestImportRequest apiTestImportRequest, ApiDefinitionWithBLOBs apiDefinition, ApiTestCaseMapper apiTestCaseMapper) {
|
||||
SaveApiTestCaseRequest checkRequest = new SaveApiTestCaseRequest();
|
||||
checkRequest.setName(apiTestCase.getName());
|
||||
checkRequest.setApiDefinitionId(apiTestCase.getApiDefinitionId());
|
||||
|
@ -1209,7 +1196,7 @@ public class ApiDefinitionService {
|
|||
apiTestFileMapper.deleteByExample(apiTestFileExample);
|
||||
|
||||
if (!CollectionUtils.isEmpty(ApiTestFiles)) {
|
||||
final List<String> fileIds = ApiTestFiles.stream().map(ApiTestFile::getFileId).collect(Collectors.toList());
|
||||
final List<String> fileIds = ApiTestFiles.stream().map(ApiTestFile::getFileId).collect(toList());
|
||||
fileService.deleteFileByIds(fileIds);
|
||||
}
|
||||
}
|
||||
|
@ -1357,9 +1344,9 @@ public class ApiDefinitionService {
|
|||
try {
|
||||
importApi(request, apiImport);
|
||||
if (CollectionUtils.isNotEmpty(apiImport.getData())) {
|
||||
List<String> names = apiImport.getData().stream().map(ApiDefinitionWithBLOBs::getName).collect(Collectors.toList());
|
||||
List<String> names = apiImport.getData().stream().map(ApiDefinitionWithBLOBs::getName).collect(toList());
|
||||
request.setName(String.join(",", names));
|
||||
List<String> ids = apiImport.getData().stream().map(ApiDefinitionWithBLOBs::getId).collect(Collectors.toList());
|
||||
List<String> ids = apiImport.getData().stream().map(ApiDefinitionWithBLOBs::getId).collect(toList());
|
||||
request.setId(JSON.toJSONString(ids));
|
||||
}
|
||||
// 发送通知
|
||||
|
@ -1390,14 +1377,18 @@ public class ApiDefinitionService {
|
|||
currentApiCaseOrder.remove();
|
||||
currentApiOrder.remove();
|
||||
List<ApiDefinitionWithBLOBs> data = apiImport.getData();
|
||||
data = this.initApiModuleId(data);
|
||||
ApiDefinitionMapper batchMapper = sqlSession.getMapper(ApiDefinitionMapper.class);
|
||||
ApiTestCaseMapper apiTestCaseMapper = sqlSession.getMapper(ApiTestCaseMapper.class);
|
||||
ExtApiDefinitionMapper extApiDefinitionMapper = sqlSession.getMapper(ExtApiDefinitionMapper.class);
|
||||
|
||||
Project project = projectMapper.selectByPrimaryKey(request.getProjectId());
|
||||
ProjectConfig config = projectApplicationService.getSpecificTypeValue(project.getId(), ProjectApplicationType.URL_REPEATABLE.name());
|
||||
boolean urlRepeat = config.getUrlRepeatable();
|
||||
|
||||
UpdateApiModuleDTO updateApiModuleDTO = apiModuleService.checkApiModule(request.getModuleId(), request.getProjectId(), apiImport.getProtocol(), data, StringUtils.equals("fullCoverage", request.getModeId()), request.getCoverModule(), urlRepeat);
|
||||
List<ApiDefinitionWithBLOBs> updateList = updateApiModuleDTO.getApiDefinitionWithBLOBsList();
|
||||
|
||||
ApiDefinitionMapper batchMapper = sqlSession.getMapper(ApiDefinitionMapper.class);
|
||||
ApiTestCaseMapper apiTestCaseMapper = sqlSession.getMapper(ApiTestCaseMapper.class);
|
||||
ExtApiDefinitionMapper extApiDefinitionMapper = sqlSession.getMapper(ExtApiDefinitionMapper.class);
|
||||
ApiModuleMapper apiModuleMapper = sqlSession.getMapper(ApiModuleMapper.class);
|
||||
int num = 0;
|
||||
if (!CollectionUtils.isEmpty(data) && data.get(0) != null && data.get(0).getProjectId() != null) {
|
||||
num = getNextNum(data.get(0).getProjectId());
|
||||
|
@ -1416,14 +1407,17 @@ public class ApiDefinitionService {
|
|||
String apiId = item.getId();
|
||||
EsbApiParamsWithBLOBs model = apiImport.getEsbApiParamsMap().get(apiId);
|
||||
request.setModeId("fullCoverage");//标准版ESB数据导入不区分是否覆盖,默认都为覆盖
|
||||
importCreate(item, batchMapper, apiTestCaseMapper, extApiDefinitionMapper, request, apiImport.getCases(), apiImport.getMocks(), urlRepeat);
|
||||
importCreate(item, batchMapper, apiTestCaseMapper, extApiDefinitionMapper, request, apiImport.getCases(), apiImport.getMocks(), updateList);
|
||||
if (model != null) {
|
||||
apiImport.getEsbApiParamsMap().remove(apiId);
|
||||
model.setResourceId(item.getId());
|
||||
apiImport.getEsbApiParamsMap().put(item.getId(), model);
|
||||
}
|
||||
} else {
|
||||
importCreate(item, batchMapper, apiTestCaseMapper, extApiDefinitionMapper, request, apiImport.getCases(), apiImport.getMocks(), urlRepeat);
|
||||
importCreate(item, batchMapper, apiTestCaseMapper, extApiDefinitionMapper, request, apiImport.getCases(), apiImport.getMocks(), updateList);
|
||||
}
|
||||
for (ApiModule apiModule : updateApiModuleDTO.getModuleList()) {
|
||||
apiModuleMapper.insert(apiModule);
|
||||
}
|
||||
if (i % 300 == 0) {
|
||||
sqlSession.flushStatements();
|
||||
|
@ -1453,7 +1447,7 @@ public class ApiDefinitionService {
|
|||
}
|
||||
|
||||
if (!CollectionUtils.isEmpty(apiImport.getCases())) {
|
||||
importMsCase(apiImport, sqlSession, request);
|
||||
importMsCase(apiImport, sqlSession, request, apiTestCaseMapper);
|
||||
}
|
||||
if (sqlSession != null && sqlSessionFactory != null) {
|
||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
|
@ -1632,7 +1626,7 @@ public class ApiDefinitionService {
|
|||
example.createCriteria().andRefIdEqualTo(api.getRefId());
|
||||
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(example);
|
||||
|
||||
List<String> apiIds = apiDefinitions.stream().map(ApiDefinition::getId).collect(Collectors.toList());
|
||||
List<String> apiIds = apiDefinitions.stream().map(ApiDefinition::getId).collect(toList());
|
||||
apiTestCaseService.deleteBatchByDefinitionId(apiIds);
|
||||
//
|
||||
apiDefinitionMapper.deleteByExample(example);
|
||||
|
@ -1658,8 +1652,8 @@ public class ApiDefinitionService {
|
|||
List<ApiDefinitionResult> resList = extApiDefinitionMapper.list(request);
|
||||
List<String> ids = new ArrayList<>(0);
|
||||
if (!resList.isEmpty()) {
|
||||
List<String> allIds = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList());
|
||||
ids = allIds.stream().filter(id -> !unSelectIds.contains(id)).collect(Collectors.toList());
|
||||
List<String> allIds = resList.stream().map(ApiDefinitionResult::getId).collect(toList());
|
||||
ids = allIds.stream().filter(id -> !unSelectIds.contains(id)).collect(toList());
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
@ -1708,7 +1702,7 @@ public class ApiDefinitionService {
|
|||
String count = String.valueOf(scenarioList.size());
|
||||
res.setScenarioTotal(count);
|
||||
String[] strings = new String[scenarioList.size()];
|
||||
String[] ids2 = scenarioList.stream().map(Scenario::getId).collect(Collectors.toList()).toArray(strings);
|
||||
String[] ids2 = scenarioList.stream().map(Scenario::getId).collect(toList()).toArray(strings);
|
||||
res.setIds(ids2);
|
||||
res.setScenarioType("scenario");
|
||||
});
|
||||
|
@ -1717,7 +1711,7 @@ public class ApiDefinitionService {
|
|||
|
||||
public void calculateResult(List<ApiDefinitionResult> resList, String projectId) {
|
||||
if (!resList.isEmpty()) {
|
||||
List<String> ids = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList());
|
||||
List<String> ids = resList.stream().map(ApiDefinitionResult::getId).collect(toList());
|
||||
List<ApiComputeResult> results = extApiDefinitionMapper.selectByIdsAndStatusIsNotTrash(ids, projectId);
|
||||
Map<String, ApiComputeResult> resultMap = results.stream().collect(Collectors.toMap(ApiComputeResult::getApiDefinitionId, Function.identity()));
|
||||
for (ApiDefinitionResult res : resList) {
|
||||
|
@ -1895,9 +1889,9 @@ public class ApiDefinitionService {
|
|||
((MsApiExportResult) apiExportResult).setProjectId(request.getProjectId());
|
||||
((MsApiExportResult) apiExportResult).setVersion(System.getenv("MS_VERSION"));
|
||||
if (CollectionUtils.isNotEmpty(((MsApiExportResult) apiExportResult).getData())) {
|
||||
List<String> names = ((MsApiExportResult) apiExportResult).getData().stream().map(ApiDefinitionWithBLOBs::getName).collect(Collectors.toList());
|
||||
List<String> names = ((MsApiExportResult) apiExportResult).getData().stream().map(ApiDefinitionWithBLOBs::getName).collect(toList());
|
||||
request.setName(String.join(",", names));
|
||||
List<String> ids = ((MsApiExportResult) apiExportResult).getData().stream().map(ApiDefinitionWithBLOBs::getId).collect(Collectors.toList());
|
||||
List<String> ids = ((MsApiExportResult) apiExportResult).getData().stream().map(ApiDefinitionWithBLOBs::getId).collect(toList());
|
||||
request.setId(JSON.toJSONString(ids));
|
||||
}
|
||||
} else { // 导出为 Swagger 格式
|
||||
|
@ -2006,7 +2000,7 @@ public class ApiDefinitionService {
|
|||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
example.createCriteria().andIdIn(ids);
|
||||
List<ApiDefinition> definitions = apiDefinitionMapper.selectByExample(example);
|
||||
List<String> names = definitions.stream().map(ApiDefinition::getName).collect(Collectors.toList());
|
||||
List<String> names = definitions.stream().map(ApiDefinition::getName).collect(toList());
|
||||
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(ids), definitions.get(0).getProjectId(), String.join(",", names), definitions.get(0).getCreateUser(), new LinkedList<>());
|
||||
return JSON.toJSONString(details);
|
||||
}
|
||||
|
@ -2040,7 +2034,7 @@ public class ApiDefinitionService {
|
|||
columns.add(column);
|
||||
});
|
||||
}
|
||||
List<String> names = definitions.stream().map(ApiDefinition::getName).collect(Collectors.toList());
|
||||
List<String> names = definitions.stream().map(ApiDefinition::getName).collect(toList());
|
||||
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(request.getIds()), request.getProjectId(), String.join(",", names), definitions.get(0).getCreateUser(), columns);
|
||||
return JSON.toJSONString(details);
|
||||
}
|
||||
|
@ -2053,7 +2047,7 @@ public class ApiDefinitionService {
|
|||
example.createCriteria().andApiDefinitionIdIn(request.getSelectIds());
|
||||
List<ApiTestCase> apiTestCases = apiTestCaseMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(apiTestCases)) {
|
||||
List<String> names = apiTestCases.stream().map(ApiTestCase::getName).collect(Collectors.toList());
|
||||
List<String> names = apiTestCases.stream().map(ApiTestCase::getName).collect(toList());
|
||||
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getPlanId());
|
||||
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(request.getSelectIds()), testPlan.getProjectId(), String.join(",", names), testPlan.getCreator(), new LinkedList<>());
|
||||
return JSON.toJSONString(details);
|
||||
|
@ -2145,7 +2139,7 @@ public class ApiDefinitionService {
|
|||
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(example);
|
||||
Map<String, ApiDefinition> apiMap = apiDefinitions.stream().collect(Collectors.toMap(ApiDefinition::getId, i -> i));
|
||||
List<RelationshipEdgeDTO> results = new ArrayList<>();
|
||||
Map<String, String> userNameMap = ServiceUtils.getUserNameMap(apiDefinitions.stream().map(ApiDefinition::getUserId).collect(Collectors.toList()));
|
||||
Map<String, String> userNameMap = ServiceUtils.getUserNameMap(apiDefinitions.stream().map(ApiDefinition::getUserId).collect(toList()));
|
||||
for (RelationshipEdge relationshipEdge : relationshipEdges) {
|
||||
RelationshipEdgeDTO relationshipEdgeDTO = new RelationshipEdgeDTO();
|
||||
BeanUtils.copyBean(relationshipEdgeDTO, relationshipEdge);
|
||||
|
@ -2177,7 +2171,7 @@ public class ApiDefinitionService {
|
|||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
example.createCriteria().andRefIdEqualTo(currentApi.getRefId());
|
||||
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(example);
|
||||
List<String> sameApiIds = apiDefinitions.stream().map(ApiDefinition::getId).collect(Collectors.toList());
|
||||
List<String> sameApiIds = apiDefinitions.stream().map(ApiDefinition::getId).collect(toList());
|
||||
List<String> relationshipIds = relationshipEdgeService.getRelationshipIds(request.getId());
|
||||
sameApiIds.addAll(relationshipIds);
|
||||
request.setNotInIds(sameApiIds);
|
||||
|
@ -2194,7 +2188,7 @@ public class ApiDefinitionService {
|
|||
ApiDefinitionFollowExample example = new ApiDefinitionFollowExample();
|
||||
example.createCriteria().andDefinitionIdEqualTo(definitionId);
|
||||
List<ApiDefinitionFollow> follows = apiDefinitionFollowMapper.selectByExample(example);
|
||||
return follows.stream().map(ApiDefinitionFollow::getFollowId).distinct().collect(Collectors.toList());
|
||||
return follows.stream().map(ApiDefinitionFollow::getFollowId).distinct().collect(toList());
|
||||
}
|
||||
|
||||
public List<DocumentElement> getDocument(String id, String type) {
|
||||
|
@ -2251,7 +2245,7 @@ public class ApiDefinitionService {
|
|||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
example.createCriteria().andRefIdEqualTo(refId).andVersionIdEqualTo(version);
|
||||
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(example);
|
||||
List<String> ids = apiDefinitions.stream().map(ApiDefinition::getId).collect(Collectors.toList());
|
||||
List<String> ids = apiDefinitions.stream().map(ApiDefinition::getId).collect(toList());
|
||||
|
||||
ApiTestCaseExample apiTestCaseExample = new ApiTestCaseExample();
|
||||
apiTestCaseExample.createCriteria().andApiDefinitionIdIn(ids);
|
||||
|
|
|
@ -2,10 +2,7 @@ package io.metersphere.api.service;
|
|||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionRequest;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.dto.definition.ApiModuleDTO;
|
||||
import io.metersphere.api.dto.definition.DragModuleRequest;
|
||||
import io.metersphere.api.dto.definition.*;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.ApiDefinitionMapper;
|
||||
import io.metersphere.base.mapper.ApiModuleMapper;
|
||||
|
@ -49,8 +46,6 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
@Resource
|
||||
private ExtApiDefinitionMapper extApiDefinitionMapper;
|
||||
@Resource
|
||||
private ApiDefinitionMapper apiDefinitionMapper;
|
||||
@Resource
|
||||
private TestPlanProjectService testPlanProjectService;
|
||||
@Resource
|
||||
private ProjectService projectService;
|
||||
|
@ -72,11 +67,16 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
return apiModuleMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
|
||||
public List<ApiModuleDTO> getApiModulesByProjectAndPro(String projectId, String protocol) {
|
||||
return extApiModuleMapper.getNodeTreeByProjectId(projectId, protocol);
|
||||
}
|
||||
|
||||
public List<ApiModuleDTO> getNodeTreeByProjectId(String projectId, String protocol, String versionId) {
|
||||
// 判断当前项目下是否有默认模块,没有添加默认模块
|
||||
this.getDefaultNode(projectId, protocol);
|
||||
List<ApiModuleDTO> apiModules = extApiModuleMapper.getNodeTreeByProjectId(projectId, protocol);
|
||||
ApiDefinitionRequest request = new ApiDefinitionRequest();
|
||||
List<ApiModuleDTO> apiModules = getApiModulesByProjectAndPro(projectId, protocol);
|
||||
request.setProjectId(projectId);
|
||||
request.setProtocol(protocol);
|
||||
List<String> list = new ArrayList<>();
|
||||
|
@ -162,7 +162,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
return addNodeWithoutValidate(node);
|
||||
}
|
||||
|
||||
private double getNextLevelPos(String projectId, int level, String parentId) {
|
||||
public double getNextLevelPos(String projectId, int level, String parentId) {
|
||||
List<ApiModule> list = getPos(projectId, level, parentId, "pos desc");
|
||||
if (!CollectionUtils.isEmpty(list) && list.get(0) != null && list.get(0).getPos() != null) {
|
||||
return list.get(0).getPos() + DEFAULT_POS;
|
||||
|
@ -219,7 +219,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
if (apiCases.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
List<ApiModuleDTO> testCaseNodes = extApiModuleMapper.getNodeTreeByProjectId(projectId, protocol);
|
||||
List<ApiModuleDTO> testCaseNodes = getApiModulesByProjectAndPro(projectId, protocol);
|
||||
|
||||
List<String> caseIds = apiCases.stream()
|
||||
.map(TestPlanApiCase::getApiCaseId)
|
||||
|
@ -453,31 +453,24 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
}
|
||||
}
|
||||
|
||||
public ApiModule getModuleByName(String projectId, String protocol) {
|
||||
public ApiModule getModuleByNameAndLevel(String projectId, String protocol, String name, Integer level) {
|
||||
ApiModuleExample example = new ApiModuleExample();
|
||||
ApiModuleExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andNameEqualTo("bug")
|
||||
.andProjectIdEqualTo(projectId).andProtocolEqualTo(protocol);
|
||||
example.createCriteria().andProjectIdEqualTo(projectId).andProtocolEqualTo(protocol).andNameEqualTo(name).andLevelEqualTo(level);
|
||||
List<ApiModule> modules = apiModuleMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(modules)) {
|
||||
return modules.get(0);
|
||||
} else {
|
||||
ApiModule node = new ApiModule();
|
||||
node.setName("bug");
|
||||
node.setLevel(1);
|
||||
node.setPos(0.0);
|
||||
node.setParentId(null);
|
||||
node.setProjectId(projectId);
|
||||
node.setProtocol(protocol);
|
||||
node.setCreateTime(System.currentTimeMillis());
|
||||
node.setUpdateTime(System.currentTimeMillis());
|
||||
node.setId(UUID.randomUUID().toString());
|
||||
node.setCreateUser(SessionUtils.getUserId());
|
||||
apiModuleMapper.insertSelective(node);
|
||||
return node;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<ApiModule> getMListByProAndProtocol(String projectId, String protocol) {
|
||||
ApiModuleExample example = new ApiModuleExample();
|
||||
example.createCriteria().andProjectIdEqualTo(projectId).andProtocolEqualTo(protocol);
|
||||
return apiModuleMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public String getLogDetails(List<String> ids) {
|
||||
ApiModuleExample example = new ApiModuleExample();
|
||||
ApiModuleExample.Criteria criteria = example.createCriteria();
|
||||
|
@ -603,4 +596,322 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
}
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件时对文件的模块进行检测
|
||||
*
|
||||
* @param moduleId 上传文件时选的模块ID
|
||||
* @param projectId
|
||||
* @param protocol
|
||||
* @param data
|
||||
* @param fullCoverage 是否覆盖接口
|
||||
* @param fullCoverageApi 是否更新当前接口所在模块 (如果开启url重复,可重复的是某一模块下的接口,注:只在这个模块下,不包含其子模块)
|
||||
* @return Return to the newly added module list and api list
|
||||
*/
|
||||
public UpdateApiModuleDTO checkApiModule(String moduleId, String projectId, String protocol, List<ApiDefinitionWithBLOBs> data, Boolean fullCoverage, Boolean fullCoverageApi, boolean urlRepeat) {
|
||||
Map<String, ApiModule> map = new HashMap<>();
|
||||
Map<String, ApiDefinitionWithBLOBs> updateApiMap = new HashMap<>();
|
||||
//获取当前项目的当前协议下的所有模块的Tree
|
||||
List<ApiModuleDTO> apiModules = this.getApiModulesByProjectAndPro(projectId, protocol);
|
||||
List<ApiModuleDTO> nodeTreeByProjectId = this.getNodeTrees(apiModules);
|
||||
|
||||
Map<String, List<ApiModule>> pidChildrenMap = new HashMap<>();
|
||||
Map<String, String> idPathMap = new HashMap<>();
|
||||
Map<String, ApiModuleDTO> idModuleMap = apiModules.stream().collect(Collectors.toMap(ApiModuleDTO::getId, apiModuleDTO -> apiModuleDTO));
|
||||
buildProcessData(nodeTreeByProjectId, pidChildrenMap, idPathMap);
|
||||
|
||||
Map<String, ApiDefinitionWithBLOBs> methodPathMap = data.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), apiDefinition -> apiDefinition));
|
||||
|
||||
//获取选中的模块
|
||||
ApiModuleDTO chooseModule = null;
|
||||
if (moduleId != null) {
|
||||
chooseModule = idModuleMap.get(moduleId);
|
||||
}
|
||||
List<ApiDefinitionWithBLOBs> repeatApiDefinitionWithBLOBs;
|
||||
|
||||
if (chooseModule != null) {
|
||||
repeatApiDefinitionWithBLOBs = extApiDefinitionMapper.selectRepeatByBLOBsSameUrl(data, chooseModule.getId());
|
||||
} else {
|
||||
repeatApiDefinitionWithBLOBs = extApiDefinitionMapper.selectRepeatByBLOBs(data);
|
||||
}
|
||||
|
||||
//允许接口重复
|
||||
if (urlRepeat) {
|
||||
//允许覆盖接口
|
||||
if (fullCoverage) {
|
||||
//允许覆盖模块
|
||||
if (fullCoverageApi) {
|
||||
coverApiModule(map, updateApiMap, pidChildrenMap, idPathMap, idModuleMap, methodPathMap, chooseModule, repeatApiDefinitionWithBLOBs);
|
||||
} else {
|
||||
//覆盖但不覆盖模块
|
||||
justCoverApi(map, updateApiMap, pidChildrenMap, idPathMap, idModuleMap, methodPathMap, chooseModule, repeatApiDefinitionWithBLOBs);
|
||||
}
|
||||
} else {
|
||||
//不覆盖接口,直接新增
|
||||
setModule(map, pidChildrenMap, idPathMap, idModuleMap, methodPathMap, chooseModule);
|
||||
}
|
||||
} else {
|
||||
//不允许接口重复
|
||||
if (fullCoverage) {
|
||||
if (fullCoverageApi) {
|
||||
coverApiModule(map, updateApiMap, pidChildrenMap, idPathMap, idModuleMap, methodPathMap, chooseModule, repeatApiDefinitionWithBLOBs);
|
||||
} else {
|
||||
//覆盖但不覆盖模块
|
||||
justCoverApi(map, updateApiMap, pidChildrenMap, idPathMap, idModuleMap, methodPathMap, chooseModule, repeatApiDefinitionWithBLOBs);
|
||||
}
|
||||
|
||||
} else {
|
||||
//不覆盖接口
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
Map<String, ApiDefinitionWithBLOBs> collect = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), apiDefinition -> apiDefinition));
|
||||
collect.forEach((k, v) -> {
|
||||
if (methodPathMap.get(k) != null) {
|
||||
methodPathMap.remove(k);
|
||||
}
|
||||
});
|
||||
}
|
||||
setModule(map, pidChildrenMap, idPathMap, idModuleMap, methodPathMap, chooseModule);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateApiModuleDTO updateApiModuleDTO = new UpdateApiModuleDTO();
|
||||
updateApiModuleDTO.setModuleList((List<ApiModule>) map.values());
|
||||
updateApiModuleDTO.setApiDefinitionWithBLOBsList((List<ApiDefinitionWithBLOBs>) updateApiMap.values());
|
||||
return updateApiModuleDTO;
|
||||
}
|
||||
|
||||
private void coverApiModule(Map<String, ApiModule> map, Map<String, ApiDefinitionWithBLOBs> updateApiMap, Map<String, List<ApiModule>> pidChildrenMap, Map<String, String> idPathMap, Map<String, ApiModuleDTO> idModuleMap, Map<String, ApiDefinitionWithBLOBs> methodPathMap, ApiModuleDTO chooseModule, List<ApiDefinitionWithBLOBs> repeatApiDefinitionWithBLOBs) {
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
Map<String, ApiDefinitionWithBLOBs> collect = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), apiDefinition -> apiDefinition));
|
||||
collect.forEach((k, v) -> {
|
||||
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = methodPathMap.get(k);
|
||||
if (apiDefinitionWithBLOBs != null) {
|
||||
//Check whether the content has changed, if not, do not change the creatoCover
|
||||
Boolean toCover = apiDefinitionService.checkIsSynchronize(v, apiDefinitionWithBLOBs);
|
||||
//需要更新
|
||||
if (toCover) {
|
||||
if (updateApiMap.get(k) != null) {
|
||||
apiDefinitionWithBLOBs.setId(v.getId());
|
||||
updateApiMap.put(k, apiDefinitionWithBLOBs);
|
||||
}
|
||||
} else {
|
||||
methodPathMap.remove(k);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
setModule(map, pidChildrenMap, idPathMap, idModuleMap, methodPathMap, chooseModule);
|
||||
}
|
||||
|
||||
private void justCoverApi(Map<String, ApiModule> map, Map<String, ApiDefinitionWithBLOBs> updateApiMap, Map<String, List<ApiModule>> pidChildrenMap, Map<String, String> idPathMap, Map<String, ApiModuleDTO> idModuleMap, Map<String, ApiDefinitionWithBLOBs> methodPathMap, ApiModuleDTO chooseModule, List<ApiDefinitionWithBLOBs> repeatApiDefinitionWithBLOBs) {
|
||||
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
|
||||
Map<String, ApiDefinitionWithBLOBs> collect = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), apiDefinition -> apiDefinition));
|
||||
collect.forEach((k, v) -> {
|
||||
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = methodPathMap.get(k);
|
||||
if (apiDefinitionWithBLOBs != null) {
|
||||
//Check whether the content has changed, if not, do not change the creatoCover
|
||||
Boolean toCover = apiDefinitionService.checkIsSynchronize(v, apiDefinitionWithBLOBs);
|
||||
//需要更新
|
||||
if (toCover) {
|
||||
if (updateApiMap.get(k) != null) {
|
||||
apiDefinitionWithBLOBs.setId(v.getId());
|
||||
updateApiMap.put(k, apiDefinitionWithBLOBs);
|
||||
}
|
||||
}
|
||||
methodPathMap.remove(k);
|
||||
}
|
||||
});
|
||||
}
|
||||
setModule(map, pidChildrenMap, idPathMap, idModuleMap, methodPathMap, chooseModule);
|
||||
}
|
||||
|
||||
private void setModule(Map<String, ApiModule> map, Map<String, List<ApiModule>> pidChildrenMap, Map<String, String> idPathMap, Map<String, ApiModuleDTO> idModuleMap, Map<String, ApiDefinitionWithBLOBs> methodPathMap, ApiModuleDTO chooseModule) {
|
||||
methodPathMap.forEach((methodPath, datum) -> {
|
||||
String[] pathTree;
|
||||
String modulePath = datum.getModulePath();
|
||||
ApiModule apiModule = map.get(modulePath);
|
||||
if (chooseModule != null) {
|
||||
if (chooseModule.getParentId() == null) {
|
||||
chooseModule.setParentId("root");
|
||||
}
|
||||
String chooseModuleParentId = chooseModule.getParentId();
|
||||
//导入时选了模块,且接口有模块的
|
||||
if (StringUtils.isNotBlank(modulePath)) {
|
||||
List<ApiModule> moduleList = pidChildrenMap.get(chooseModuleParentId);
|
||||
String s;
|
||||
if (chooseModuleParentId.equals("root")) {
|
||||
s = "/" + chooseModule.getName();
|
||||
} else {
|
||||
s = idPathMap.get(chooseModuleParentId);
|
||||
}
|
||||
pathTree = getPathTree(s + modulePath);
|
||||
|
||||
ApiModule chooseModuleOne = JSON.parseObject(JSON.toJSONString(chooseModule), ApiModule.class);
|
||||
ApiModule minModule = getMinModule(pathTree, moduleList, chooseModuleOne, pidChildrenMap, map, idPathMap, idModuleMap);
|
||||
String id = minModule.getId();
|
||||
datum.setModuleId(id);
|
||||
datum.setModulePath(idPathMap.get(id));
|
||||
} else {
|
||||
//导入时选了模块,且接口没有模块的
|
||||
datum.setModuleId(chooseModule.getId());
|
||||
datum.setModulePath(idPathMap.get(chooseModule.getId()));
|
||||
}
|
||||
} else {
|
||||
if (StringUtils.isNotBlank(modulePath)) {
|
||||
//导入时没选模块但接口有模块的,根据modulePath,和当前协议查询当前项目里是否有同名称模块,如果有,就在该模块下建立接口,否则新建模块
|
||||
pathTree = getPathTree(modulePath);
|
||||
if (apiModule != null) {
|
||||
datum.setModuleId(apiModule.getId());
|
||||
datum.setModulePath(modulePath);
|
||||
} else {
|
||||
List<ApiModule> moduleList = pidChildrenMap.get("root");
|
||||
ApiModule minModule = getMinModule(pathTree, moduleList, null, pidChildrenMap, map, idPathMap, idModuleMap);
|
||||
String id = minModule.getId();
|
||||
datum.setModuleId(id);
|
||||
datum.setModulePath(idPathMap.get(id));
|
||||
}
|
||||
} else {
|
||||
//导入时即没选中模块,接口自身也没模块的,直接返会当前项目,当前协议下的默认模块
|
||||
List<ApiModule> moduleList = pidChildrenMap.get("root");
|
||||
for (ApiModule module : moduleList) {
|
||||
if (module.getName().equals("未规划接口")) {
|
||||
datum.setModuleId(module.getId());
|
||||
datum.setModulePath("/" + module.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String[] getPathTree(String modulePath) {
|
||||
String substring = modulePath.substring(0, 1);
|
||||
if (substring.equals("/")) {
|
||||
modulePath = modulePath.substring(1);
|
||||
}
|
||||
if (modulePath.contains("/")) {
|
||||
//如果模块有层级,逐级查找,如果某一级不在当前项目了,则新建该层级的模块及其子集
|
||||
return modulePath.split("/");
|
||||
} else {
|
||||
return new String[]{modulePath};
|
||||
}
|
||||
}
|
||||
|
||||
private ApiModule getMinModule(String[] tagTree, List<ApiModule> moduleList, ApiModule parentModule, Map<String, List<ApiModule>> pidChildrenMap, Map<String, ApiModule> map, Map<String, String> idPathMap, Map<String, ApiModuleDTO> idModuleMap) {
|
||||
//如果parentModule==null 则证明需要创建根目录同级的模块
|
||||
ApiModule returnModule = null;
|
||||
for (int i = 0; i < tagTree.length; i++) {
|
||||
int finalI = i;
|
||||
List<ApiModule> collect = moduleList.stream().filter(t -> t.getName().equals(tagTree[finalI])).collect(Collectors.toList());
|
||||
if (collect.isEmpty()) {
|
||||
if (parentModule == null) {
|
||||
List<ApiModule> moduleList1 = pidChildrenMap.get("root");
|
||||
ApiModule apiModule = moduleList1.get(0);
|
||||
apiModule.setId("root");
|
||||
apiModule.setLevel(0);
|
||||
parentModule = apiModule;
|
||||
} else if (i > 0) {
|
||||
if (!moduleList.isEmpty()) {
|
||||
String parentId = moduleList.get(0).getParentId();
|
||||
ApiModuleDTO apiModuleDTO = idModuleMap.get(parentId);
|
||||
parentModule = JSON.parseObject(JSON.toJSONString(apiModuleDTO), ApiModule.class);
|
||||
}
|
||||
}
|
||||
return createModule(tagTree, i, parentModule, map, pidChildrenMap, idPathMap);
|
||||
} else {
|
||||
returnModule = collect.get(0);
|
||||
moduleList = pidChildrenMap.get(collect.get(0).getId());
|
||||
}
|
||||
}
|
||||
return returnModule;
|
||||
}
|
||||
|
||||
|
||||
private ApiModule createModule(String[] tagTree, int i, ApiModule parentModule, Map<String, ApiModule> map, Map<String, List<ApiModule>> pidChildrenMap, Map<String, String> idPathMap) {
|
||||
ApiModule returnModule = null;
|
||||
for (int i1 = i; i1 < tagTree.length; i1++) {
|
||||
String pathName = tagTree[i1];
|
||||
ApiModule newModule = this.getNewModule(pathName, parentModule.getProjectId(), parentModule.getLevel() + 1);
|
||||
String parentId;
|
||||
if (parentModule.getId().equals("root")) {
|
||||
parentId = null;
|
||||
} else {
|
||||
parentId = parentModule.getId();
|
||||
}
|
||||
double pos = this.getNextLevelPos(parentModule.getProjectId(), parentModule.getLevel() + 1, parentId);
|
||||
newModule.setPos(pos);
|
||||
newModule.setProtocol(parentModule.getProtocol());
|
||||
newModule.setParentId(parentId);
|
||||
List<ApiModule> moduleList = pidChildrenMap.get(parentModule.getId());
|
||||
if (moduleList != null) {
|
||||
moduleList.add(newModule);
|
||||
} else {
|
||||
moduleList = new ArrayList<>();
|
||||
moduleList.add(newModule);
|
||||
pidChildrenMap.put(parentModule.getId(), moduleList);
|
||||
}
|
||||
|
||||
String parentPath = idPathMap.get(parentModule.getId());
|
||||
String path;
|
||||
if (StringUtils.isNotBlank(parentPath)) {
|
||||
path = parentPath + "/" + pathName;
|
||||
} else {
|
||||
path = "/" + pathName;
|
||||
}
|
||||
idPathMap.put(newModule.getId(), path);
|
||||
map.putIfAbsent(path, newModule);
|
||||
parentModule = newModule;
|
||||
returnModule = newModule;
|
||||
}
|
||||
return returnModule;
|
||||
}
|
||||
|
||||
private void buildProcessData(List<ApiModuleDTO> nodeTreeByProjectId, Map<String, List<ApiModule>> pidChildrenMap, Map<String, String> idPathMap) {
|
||||
List<ApiModuleDTO> childrenList = new ArrayList<>();
|
||||
int i = 0;
|
||||
List<ApiModule> moduleList = new ArrayList<>();
|
||||
for (ApiModuleDTO apiModuleDTO : nodeTreeByProjectId) {
|
||||
if (apiModuleDTO.getPath() != null) {
|
||||
apiModuleDTO.setPath(apiModuleDTO.getPath() + "/" + apiModuleDTO.getName());
|
||||
} else {
|
||||
apiModuleDTO.setPath("/" + apiModuleDTO.getName());
|
||||
}
|
||||
idPathMap.put(apiModuleDTO.getId(), apiModuleDTO.getPath());
|
||||
if (StringUtils.isBlank(apiModuleDTO.getParentId())) {
|
||||
apiModuleDTO.setParentId("root");
|
||||
}
|
||||
ApiModule apiModule = buildModule(moduleList, apiModuleDTO);
|
||||
if (pidChildrenMap.get(apiModuleDTO.getParentId()) != null) {
|
||||
pidChildrenMap.get(apiModuleDTO.getParentId()).add(apiModule);
|
||||
} else {
|
||||
pidChildrenMap.put(apiModuleDTO.getParentId(), moduleList);
|
||||
}
|
||||
i = i + 1;
|
||||
if (apiModuleDTO.getChildren() != null) {
|
||||
childrenList.addAll(apiModuleDTO.getChildren());
|
||||
} else {
|
||||
childrenList.addAll(new ArrayList<>());
|
||||
if (i == nodeTreeByProjectId.size() && childrenList.size() == 0) {
|
||||
pidChildrenMap.put(apiModuleDTO.getId(), new ArrayList<>());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i == nodeTreeByProjectId.size() && nodeTreeByProjectId.size() > 0) {
|
||||
buildProcessData(childrenList, pidChildrenMap, idPathMap);
|
||||
}
|
||||
}
|
||||
|
||||
private ApiModule buildModule(List<ApiModule> moduleList, ApiModuleDTO apiModuleDTO) {
|
||||
ApiModule apiModule = new ApiModule();
|
||||
apiModule.setId(apiModuleDTO.getId());
|
||||
apiModule.setName(apiModuleDTO.getName());
|
||||
apiModule.setParentId(apiModuleDTO.getParentId());
|
||||
apiModule.setProjectId(apiModuleDTO.getProjectId());
|
||||
apiModule.setProtocol(apiModuleDTO.getProtocol());
|
||||
apiModule.setLevel(apiModuleDTO.getLevel());
|
||||
moduleList.add(apiModule);
|
||||
return apiModule;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,10 +2,7 @@ package io.metersphere.api.service;
|
|||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import io.metersphere.api.dto.automation.ApiScenarioDTO;
|
||||
import io.metersphere.api.dto.automation.ApiScenarioModuleDTO;
|
||||
import io.metersphere.api.dto.automation.ApiScenarioRequest;
|
||||
import io.metersphere.api.dto.automation.DragApiScenarioModuleRequest;
|
||||
import io.metersphere.api.dto.automation.*;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.ApiScenarioMapper;
|
||||
import io.metersphere.base.mapper.ApiScenarioModuleMapper;
|
||||
|
@ -88,21 +85,21 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
moduleIds = this.nodeList(nodes, node.getId(), moduleIds);
|
||||
moduleIds.add(node.getId());
|
||||
for (String moduleId : moduleIds) {
|
||||
if(!allModuleIdList.contains(moduleId)){
|
||||
if (!allModuleIdList.contains(moduleId)) {
|
||||
allModuleIdList.add(moduleId);
|
||||
}
|
||||
}
|
||||
}
|
||||
request.setModuleIds(allModuleIdList);
|
||||
List<Map<String,Object>> moduleCountList = extApiScenarioMapper.listModuleByCollection(request);
|
||||
Map<String,Integer> moduleCountMap = this.parseModuleCountList(moduleCountList);
|
||||
List<Map<String, Object>> moduleCountList = extApiScenarioMapper.listModuleByCollection(request);
|
||||
Map<String, Integer> moduleCountMap = this.parseModuleCountList(moduleCountList);
|
||||
nodes.forEach(node -> {
|
||||
List<String> moduleIds = new ArrayList<>();
|
||||
moduleIds = this.nodeList(nodes, node.getId(), moduleIds);
|
||||
moduleIds.add(node.getId());
|
||||
int countNum = 0;
|
||||
for (String moduleId : moduleIds) {
|
||||
if(moduleCountMap.containsKey(moduleId)){
|
||||
if (moduleCountMap.containsKey(moduleId)) {
|
||||
countNum += moduleCountMap.get(moduleId).intValue();
|
||||
}
|
||||
}
|
||||
|
@ -110,17 +107,18 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
});
|
||||
return getNodeTrees(nodes);
|
||||
}
|
||||
|
||||
private Map<String, Integer> parseModuleCountList(List<Map<String, Object>> moduleCountList) {
|
||||
Map<String,Integer> returnMap = new HashMap<>();
|
||||
for (Map<String, Object> map: moduleCountList){
|
||||
Map<String, Integer> returnMap = new HashMap<>();
|
||||
for (Map<String, Object> map : moduleCountList) {
|
||||
Object moduleIdObj = map.get("moduleId");
|
||||
Object countNumObj = map.get("countNum");
|
||||
if(moduleIdObj!= null && countNumObj != null){
|
||||
if (moduleIdObj != null && countNumObj != null) {
|
||||
String moduleId = String.valueOf(moduleIdObj);
|
||||
try {
|
||||
Integer countNumInteger = new Integer(String.valueOf(countNumObj));
|
||||
returnMap.put(moduleId,countNumInteger);
|
||||
}catch (Exception e){
|
||||
returnMap.put(moduleId, countNumInteger);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,7 +138,7 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
return list;
|
||||
}
|
||||
|
||||
private double getNextLevelPos(String projectId, int level, String parentId) {
|
||||
public double getNextLevelPos(String projectId, int level, String parentId) {
|
||||
List<ApiScenarioModule> list = getPos(projectId, level, parentId, "pos desc");
|
||||
if (!CollectionUtils.isEmpty(list) && list.get(0) != null && list.get(0).getPos() != null) {
|
||||
return list.get(0).getPos() + DEFAULT_POS;
|
||||
|
@ -465,9 +463,304 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
record.setProjectId(projectId);
|
||||
record.setCreateUser(SessionUtils.getUserId());
|
||||
apiScenarioModuleMapper.insert(record);
|
||||
return record;
|
||||
}else {
|
||||
return record;
|
||||
} else {
|
||||
return list.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件时对文件的模块进行检测
|
||||
*
|
||||
* @param moduleId 上传文件时选的模块ID
|
||||
* @param projectId
|
||||
* @param data
|
||||
* @param fullCoverage 是否覆盖接口
|
||||
* @param fullCoverageApi 是否更新当前接口所在模块
|
||||
* @return Return to the newly added module map
|
||||
*/
|
||||
public UpdateScenarioModuleDTO checkScenarioModule(String moduleId, String projectId, List<ApiScenarioWithBLOBs> data, Boolean fullCoverage, Boolean fullCoverageApi) {
|
||||
Map<String, ApiScenarioModule> map = new HashMap<>();
|
||||
Map<String, ApiScenarioWithBLOBs> updateMap = new HashMap<>();
|
||||
//获取当前项目的当前协议下的所有模块的Tree
|
||||
List<ApiScenarioModuleDTO> scenarioModules = extApiScenarioModuleMapper.getNodeTreeByProjectId(projectId);
|
||||
List<ApiScenarioModuleDTO> nodeTreeByProjectId = this.getNodeTrees(scenarioModules);
|
||||
Map<String, List<ApiScenarioModule>> pidChildrenMap = new HashMap<>();
|
||||
Map<String, String> idPathMap = new HashMap<>();
|
||||
Map<String, ApiScenarioModuleDTO> idModuleMap = scenarioModules.stream().collect(Collectors.toMap(ApiScenarioModuleDTO::getId, scenarioModuleDTO -> scenarioModuleDTO));
|
||||
buildProcessData(nodeTreeByProjectId, pidChildrenMap, idPathMap);
|
||||
|
||||
Map<String, ApiScenarioWithBLOBs> nameMap = data.stream().collect(Collectors.toMap(ApiScenario::getName, apiScenario -> apiScenario));
|
||||
|
||||
|
||||
ApiScenarioModuleDTO chooseModule = null;
|
||||
if (moduleId != null) {
|
||||
chooseModule = idModuleMap.get(moduleId);
|
||||
}
|
||||
List<ApiScenarioWithBLOBs> repeatApiScenarioWithBLOBs;
|
||||
|
||||
if (chooseModule != null) {
|
||||
repeatApiScenarioWithBLOBs = extApiScenarioMapper.selectRepeatByBLOBsSameUrl(data, chooseModule.getId());
|
||||
} else {
|
||||
repeatApiScenarioWithBLOBs = extApiScenarioMapper.selectRepeatByBLOBs(data);
|
||||
}
|
||||
|
||||
if (fullCoverage) {
|
||||
if (fullCoverageApi) {
|
||||
coverScenarioModule(updateMap, nameMap, repeatApiScenarioWithBLOBs);
|
||||
} else {
|
||||
//只覆盖场景
|
||||
justCoverScenario(updateMap, nameMap, repeatApiScenarioWithBLOBs);
|
||||
}
|
||||
} else {
|
||||
//不覆盖
|
||||
if (!repeatApiScenarioWithBLOBs.isEmpty()) {
|
||||
Map<String, ApiScenarioWithBLOBs> collect = repeatApiScenarioWithBLOBs.stream().collect(Collectors.toMap(ApiScenario::getName, scenario -> scenario));
|
||||
collect.forEach((k, v) -> {
|
||||
if (nameMap.get(k) != null) {
|
||||
nameMap.remove(k);
|
||||
}
|
||||
});
|
||||
}
|
||||
setModule(nameMap, map, pidChildrenMap, idPathMap, idModuleMap, chooseModule);
|
||||
}
|
||||
|
||||
UpdateScenarioModuleDTO updateScenarioModuleDTO = new UpdateScenarioModuleDTO();
|
||||
updateScenarioModuleDTO.setModuleList((List<ApiScenarioModule>) map.values());
|
||||
updateScenarioModuleDTO.setApiScenarioWithBLOBsList((List<ApiScenarioWithBLOBs>) nameMap.values());
|
||||
|
||||
return updateScenarioModuleDTO;
|
||||
}
|
||||
|
||||
private void coverScenarioModule(Map<String, ApiScenarioWithBLOBs> updateMap, Map<String, ApiScenarioWithBLOBs> nameMap, List<ApiScenarioWithBLOBs> repeatApiScenarioWithBLOBs) {
|
||||
if (!repeatApiScenarioWithBLOBs.isEmpty()) {
|
||||
Map<String, ApiScenarioWithBLOBs> collect = repeatApiScenarioWithBLOBs.stream().collect(Collectors.toMap(ApiScenario::getName, apiScenario -> apiScenario));
|
||||
collect.forEach((name, scenario) -> {
|
||||
ApiScenarioWithBLOBs apiScenarioWithBLOBs = nameMap.get(name);
|
||||
if (apiScenarioWithBLOBs != null) {
|
||||
//Check whether the content has changed, if not, do not change the creatoCover
|
||||
Boolean toCover = apiAutomationService.checkIsSynchronize(scenario, apiScenarioWithBLOBs);
|
||||
//需要更新
|
||||
if (toCover) {
|
||||
if (updateMap.get(name) != null) {
|
||||
apiScenarioWithBLOBs.setId(scenario.getId());
|
||||
updateMap.put(name, apiScenarioWithBLOBs);
|
||||
}
|
||||
} else {
|
||||
nameMap.remove(name);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void justCoverScenario(Map<String, ApiScenarioWithBLOBs> updateMap, Map<String, ApiScenarioWithBLOBs> nameMap, List<ApiScenarioWithBLOBs> repeatApiScenarioWithBLOBs) {
|
||||
if (!repeatApiScenarioWithBLOBs.isEmpty()) {
|
||||
Map<String, ApiScenarioWithBLOBs> collect = repeatApiScenarioWithBLOBs.stream().collect(Collectors.toMap(ApiScenario::getName, apiScenario -> apiScenario));
|
||||
collect.forEach((name, scenario) -> {
|
||||
ApiScenarioWithBLOBs apiScenarioWithBLOBs = nameMap.get(name);
|
||||
if (apiScenarioWithBLOBs != null) {
|
||||
//Check whether the content has changed, if not, do not change the creatoCover
|
||||
Boolean toCover = apiAutomationService.checkIsSynchronize(scenario, apiScenarioWithBLOBs);
|
||||
//需要更新
|
||||
if (toCover) {
|
||||
if (updateMap.get(name) != null) {
|
||||
apiScenarioWithBLOBs.setId(scenario.getId());
|
||||
updateMap.put(name, apiScenarioWithBLOBs);
|
||||
}
|
||||
}
|
||||
nameMap.remove(name);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void setModule(Map<String, ApiScenarioWithBLOBs> nameMap, Map<String, ApiScenarioModule> map, Map<String, List<ApiScenarioModule>> pidChildrenMap, Map<String, String> idPathMap, Map<String, ApiScenarioModuleDTO> idModuleMap, ApiScenarioModuleDTO chooseModule) {
|
||||
nameMap.forEach((k, datum) -> {
|
||||
StringBuilder path = new StringBuilder();
|
||||
path.append("/");
|
||||
String[] tagTree;
|
||||
String modulePath = datum.getModulePath();
|
||||
ApiScenarioModule scenarioModule = map.get(modulePath);
|
||||
if (chooseModule != null) {
|
||||
if (chooseModule.getParentId() == null) {
|
||||
chooseModule.setParentId("root");
|
||||
}
|
||||
String chooseModuleParentId = chooseModule.getParentId();
|
||||
//导入时选了模块,且接口有模块的
|
||||
if (StringUtils.isNotBlank(modulePath)) {
|
||||
List<ApiScenarioModule> moduleList = pidChildrenMap.get(chooseModuleParentId);
|
||||
String s;
|
||||
if (chooseModuleParentId.equals("root")) {
|
||||
s = "/" + chooseModule.getName();
|
||||
} else {
|
||||
s = idPathMap.get(chooseModuleParentId);
|
||||
}
|
||||
tagTree = getTagTree(s + modulePath);
|
||||
|
||||
ApiScenarioModule chooseModuleOne = JSON.parseObject(JSON.toJSONString(chooseModule), ApiScenarioModule.class);
|
||||
ApiScenarioModule minModule = getMinModule(tagTree, moduleList, chooseModuleOne, pidChildrenMap, map, idPathMap, idModuleMap);
|
||||
String id = minModule.getId();
|
||||
datum.setApiScenarioModuleId(id);
|
||||
datum.setModulePath(idPathMap.get(id));
|
||||
} else {
|
||||
//导入时选了模块,且接口没有模块的
|
||||
datum.setApiScenarioModuleId(chooseModule.getId());
|
||||
datum.setModulePath(idPathMap.get(chooseModule.getId()));
|
||||
}
|
||||
} else {
|
||||
if (StringUtils.isNotBlank(modulePath)) {
|
||||
//导入时没选模块但接口有模块的,根据modulePath,和当前协议查询当前项目里是否有同名称模块,如果有,就在该模块下建立接口,否则新建模块
|
||||
tagTree = getTagTree(modulePath);
|
||||
if (scenarioModule != null) {
|
||||
datum.setApiScenarioModuleId(scenarioModule.getId());
|
||||
datum.setModulePath(modulePath);
|
||||
} else {
|
||||
List<ApiScenarioModule> moduleList = pidChildrenMap.get("root");
|
||||
ApiScenarioModule minModule = getMinModule(tagTree, moduleList, null, pidChildrenMap, map, idPathMap, idModuleMap);
|
||||
String id = minModule.getId();
|
||||
datum.setApiScenarioModuleId(id);
|
||||
datum.setModulePath(idPathMap.get(id));
|
||||
}
|
||||
} else {
|
||||
//导入时即没选中模块,接口自身也没模块的,直接返会当前项目,当前协议下的默认模块
|
||||
List<ApiScenarioModule> moduleList = pidChildrenMap.get("root");
|
||||
for (ApiScenarioModule module : moduleList) {
|
||||
if (module.getName().equals("未规划接口")) {
|
||||
datum.setApiScenarioModuleId(module.getId());
|
||||
datum.setModulePath("/" + module.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String[] getTagTree(String modulePath) {
|
||||
String substring = modulePath.substring(0, 1);
|
||||
if (substring.equals("/")) {
|
||||
modulePath = modulePath.substring(1);
|
||||
}
|
||||
if (modulePath.contains("/")) {
|
||||
//如果模块有层级,逐级查找,如果某一级不在当前项目了,则新建该层级的模块及其子集
|
||||
return modulePath.split("/");
|
||||
} else {
|
||||
return new String[]{modulePath};
|
||||
}
|
||||
}
|
||||
|
||||
private ApiScenarioModule getMinModule(String[] tagTree, List<ApiScenarioModule> moduleList, ApiScenarioModule parentModule, Map<String, List<ApiScenarioModule>> pidChildrenMap, Map<String, ApiScenarioModule> map, Map<String, String> idPathMap, Map<String, ApiScenarioModuleDTO> idModuleMap) {
|
||||
//如果parentModule==null 则证明需要创建根目录同级的模块
|
||||
ApiScenarioModule returnModule = null;
|
||||
for (int i = 0; i < tagTree.length; i++) {
|
||||
int finalI = i;
|
||||
List<ApiScenarioModule> collect = moduleList.stream().filter(t -> t.getName().equals(tagTree[finalI])).collect(Collectors.toList());
|
||||
if (collect.isEmpty()) {
|
||||
if (parentModule == null) {
|
||||
List<ApiScenarioModule> moduleList1 = pidChildrenMap.get("root");
|
||||
ApiScenarioModule apiModule = moduleList1.get(0);
|
||||
apiModule.setId("root");
|
||||
apiModule.setLevel(0);
|
||||
parentModule = apiModule;
|
||||
} else if (i > 0) {
|
||||
if (!moduleList.isEmpty()) {
|
||||
String parentId = moduleList.get(0).getParentId();
|
||||
ApiScenarioModuleDTO apiScenarioModuleDTO = idModuleMap.get(parentId);
|
||||
parentModule = JSON.parseObject(JSON.toJSONString(apiScenarioModuleDTO), ApiScenarioModule.class);
|
||||
}
|
||||
}
|
||||
return createModule(tagTree, i, parentModule, map, pidChildrenMap, idPathMap);
|
||||
} else {
|
||||
returnModule = collect.get(0);
|
||||
moduleList = pidChildrenMap.get(collect.get(0).getId());
|
||||
}
|
||||
}
|
||||
return returnModule;
|
||||
}
|
||||
|
||||
|
||||
private ApiScenarioModule createModule(String[] tagTree, int i, ApiScenarioModule parentModule, Map<String, ApiScenarioModule> map, Map<String, List<ApiScenarioModule>> pidChildrenMap, Map<String, String> idPathMap) {
|
||||
|
||||
ApiScenarioModule returnModule = null;
|
||||
for (int i1 = i; i1 < tagTree.length; i1++) {
|
||||
String pathName = tagTree[i1];
|
||||
ApiScenarioModule newModule = this.getNewModule(pathName, parentModule.getProjectId(), parentModule.getLevel() + 1);
|
||||
String parentId;
|
||||
if (parentModule.getId().equals("root")) {
|
||||
parentId = null;
|
||||
} else {
|
||||
parentId = parentModule.getId();
|
||||
}
|
||||
double pos = this.getNextLevelPos(parentModule.getProjectId(), parentModule.getLevel() + 1, parentId);
|
||||
newModule.setPos(pos);
|
||||
newModule.setParentId(parentId);
|
||||
List<ApiScenarioModule> moduleList = pidChildrenMap.get(parentModule.getId());
|
||||
if (moduleList != null) {
|
||||
moduleList.add(newModule);
|
||||
} else {
|
||||
moduleList = new ArrayList<>();
|
||||
moduleList.add(newModule);
|
||||
pidChildrenMap.put(parentModule.getId(), moduleList);
|
||||
}
|
||||
|
||||
String parentPath = idPathMap.get(parentModule.getId());
|
||||
String path;
|
||||
if (StringUtils.isNotBlank(parentPath)) {
|
||||
path = parentPath + "/" + pathName;
|
||||
} else {
|
||||
path = "/" + pathName;
|
||||
}
|
||||
idPathMap.put(newModule.getId(), path);
|
||||
map.putIfAbsent(path, newModule);
|
||||
parentModule = newModule;
|
||||
returnModule = newModule;
|
||||
}
|
||||
return returnModule;
|
||||
}
|
||||
|
||||
private void buildProcessData(List<ApiScenarioModuleDTO> nodeTreeByProjectId, Map<String, List<ApiScenarioModule>> pidChildrenMap, Map<String, String> idPathMap) {
|
||||
List<ApiScenarioModuleDTO> childrenList = new ArrayList<>();
|
||||
int i = 0;
|
||||
List<ApiScenarioModule> moduleList = new ArrayList<>();
|
||||
for (ApiScenarioModuleDTO scenarioModuleDTO : nodeTreeByProjectId) {
|
||||
if (scenarioModuleDTO.getPath() != null) {
|
||||
scenarioModuleDTO.setPath(scenarioModuleDTO.getPath() + "/" + scenarioModuleDTO.getName());
|
||||
} else {
|
||||
scenarioModuleDTO.setPath("/" + scenarioModuleDTO.getName());
|
||||
}
|
||||
idPathMap.put(scenarioModuleDTO.getId(), scenarioModuleDTO.getPath());
|
||||
if (StringUtils.isBlank(scenarioModuleDTO.getParentId())) {
|
||||
scenarioModuleDTO.setParentId("root");
|
||||
}
|
||||
ApiScenarioModule scenarioModule = buildModule(moduleList, scenarioModuleDTO);
|
||||
if (pidChildrenMap.get(scenarioModuleDTO.getParentId()) != null) {
|
||||
pidChildrenMap.get(scenarioModuleDTO.getParentId()).add(scenarioModule);
|
||||
} else {
|
||||
pidChildrenMap.put(scenarioModuleDTO.getParentId(), moduleList);
|
||||
}
|
||||
i = i + 1;
|
||||
if (scenarioModuleDTO.getChildren() != null) {
|
||||
childrenList.addAll(scenarioModuleDTO.getChildren());
|
||||
} else {
|
||||
childrenList.addAll(new ArrayList<>());
|
||||
if (i == nodeTreeByProjectId.size() && childrenList.size() == 0) {
|
||||
pidChildrenMap.put(scenarioModuleDTO.getId(), new ArrayList<>());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i == nodeTreeByProjectId.size() && nodeTreeByProjectId.size() > 0) {
|
||||
buildProcessData(childrenList, pidChildrenMap, idPathMap);
|
||||
}
|
||||
}
|
||||
|
||||
private ApiScenarioModule buildModule(List<ApiScenarioModule> moduleList, ApiScenarioModuleDTO scenarioModuleDTO) {
|
||||
ApiScenarioModule scenarioModule = new ApiScenarioModule();
|
||||
scenarioModule.setId(scenarioModuleDTO.getId());
|
||||
scenarioModule.setName(scenarioModuleDTO.getName());
|
||||
scenarioModule.setParentId(scenarioModuleDTO.getParentId());
|
||||
scenarioModule.setProjectId(scenarioModuleDTO.getProjectId());
|
||||
scenarioModule.setLevel(scenarioModuleDTO.getLevel());
|
||||
moduleList.add(scenarioModule);
|
||||
return scenarioModule;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import io.metersphere.api.dto.scenario.Scenario;
|
|||
import io.metersphere.base.domain.ApiDefinition;
|
||||
import io.metersphere.base.domain.ApiDefinitionExample;
|
||||
import io.metersphere.base.domain.ApiDefinitionExampleWithOperation;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.controller.request.BaseQueryRequest;
|
||||
import io.metersphere.dto.RelationshipGraphData;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
@ -22,7 +23,7 @@ public interface ExtApiDefinitionMapper {
|
|||
|
||||
List<ApiDefinitionResult> list(@Param("request") ApiDefinitionRequest request);
|
||||
|
||||
List<ApiDefinitionResult> weekList(@Param("request") ApiDefinitionRequest request , @Param("startTimestamp") long startTimestamp );
|
||||
List<ApiDefinitionResult> weekList(@Param("request") ApiDefinitionRequest request, @Param("startTimestamp") long startTimestamp);
|
||||
|
||||
List<Scenario> scenarioList(@Param("apiDefinitionId") String apiDefinitionId);
|
||||
|
||||
|
@ -64,13 +65,13 @@ public interface ExtApiDefinitionMapper {
|
|||
|
||||
ApiDefinition selectUrlAndMethodById(String id);
|
||||
|
||||
int checkOriginalStatusByIds(@Param("ids")List<String> ids);
|
||||
int checkOriginalStatusByIds(@Param("ids") List<String> ids);
|
||||
|
||||
List<String> selectProjectIds();
|
||||
|
||||
List<String> getIdsOrderByUpdateTime(@Param("projectId") String projectId);
|
||||
|
||||
Long getPreOrder(@Param("projectId")String projectId, @Param("baseOrder") Long baseOrder);
|
||||
Long getPreOrder(@Param("projectId") String projectId, @Param("baseOrder") Long baseOrder);
|
||||
|
||||
Long getLastOrder(@Param("projectId") String projectId, @Param("baseOrder") Long baseOrder);
|
||||
|
||||
|
@ -90,6 +91,11 @@ public interface ExtApiDefinitionMapper {
|
|||
|
||||
String selectNameById(String testId);
|
||||
|
||||
int toBeUpdateApi(@Param("ids") List<String> ids,@Param("toBeUpdate") Boolean toBeUpdate);
|
||||
int toBeUpdateApi(@Param("ids") List<String> ids, @Param("toBeUpdate") Boolean toBeUpdate);
|
||||
|
||||
List<ApiDefinitionWithBLOBs> selectRepeatByBLOBs(@Param("blobs") List<ApiDefinitionWithBLOBs> blobs);
|
||||
|
||||
List<ApiDefinitionWithBLOBs> selectRepeatByBLOBsSameUrl(@Param("blobs") List<ApiDefinitionWithBLOBs> blobs, @Param("moduleId") String moduleId);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -81,15 +81,17 @@
|
|||
</where>
|
||||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
id, project_id, name,module_id,module_path,protocol ,path,method ,description, status, user_id, create_time, update_time
|
||||
</sql>
|
||||
id
|
||||
, project_id, name,module_id,module_path,protocol ,path,method ,description, status, user_id, create_time, update_time
|
||||
</sql>
|
||||
<sql id="Blob_Column_List">
|
||||
request
|
||||
</sql>
|
||||
|
||||
<select id="selectByIds" resultType="io.metersphere.api.dto.definition.ApiComputeResult">
|
||||
SELECT t1.api_definition_id apiDefinitionId,count(t1.id) caseTotal,
|
||||
SUM(case when t2.status ='success' then 1 else 0 end) as success ,SUM(case when t2.status ='error' then 1 else 0 end) as error,
|
||||
SUM(case when t2.status ='success' then 1 else 0 end) as success ,SUM(case when t2.status ='error' then 1 else 0
|
||||
end) as error,
|
||||
CONCAT(FORMAT(SUM(IF (t2.`status`='success',1,0))/COUNT(t1.id)*100,2),'%') passRate
|
||||
FROM api_test_case t1
|
||||
LEFT JOIN api_definition_exec_result t2 ON t1.last_result_id=t2.id
|
||||
|
@ -102,7 +104,8 @@
|
|||
|
||||
<select id="selectByIdsAndStatusIsNotTrash" resultType="io.metersphere.api.dto.definition.ApiComputeResult">
|
||||
SELECT t1.api_definition_id apiDefinitionId,count(t1.id) caseTotal,
|
||||
SUM(case when t2.status ='success' then 1 else 0 end) as success ,SUM(case when t2.status ='error' then 1 else 0 end) as error,
|
||||
SUM(case when t2.status ='success' then 1 else 0 end) as success ,SUM(case when t2.status ='error' then 1 else 0
|
||||
end) as error,
|
||||
CONCAT(FORMAT(SUM(IF (t2.`status`='success',1,0))/COUNT(t1.id)*100,2),'%') passRate
|
||||
FROM api_test_case t1
|
||||
LEFT JOIN api_definition_exec_result t2 ON t1.last_result_id=t2.id
|
||||
|
@ -253,10 +256,13 @@
|
|||
</sql>
|
||||
|
||||
<select id="list" resultType="io.metersphere.api.dto.definition.ApiDefinitionResult">
|
||||
select api_definition.id, api_definition.project_id, api_definition.num, api_definition.tags,api_definition.original_state,
|
||||
select api_definition.id, api_definition.project_id, api_definition.num,
|
||||
api_definition.tags,api_definition.original_state,
|
||||
api_definition.name,api_definition.protocol,api_definition.path,api_definition.module_id,api_definition.module_path,api_definition.method,
|
||||
api_definition.description,api_definition.request,api_definition.response,api_definition.environment_id,
|
||||
api_definition.status, api_definition.user_id, api_definition.create_time, api_definition.update_time, api_definition.delete_user_id, api_definition.create_user,api_definition.delete_time, api_definition.remark, api_definition.version_id,
|
||||
api_definition.status, api_definition.user_id, api_definition.create_time, api_definition.update_time,
|
||||
api_definition.delete_user_id, api_definition.create_user,api_definition.delete_time, api_definition.remark,
|
||||
api_definition.version_id,
|
||||
project_version.name as version_name, api_definition.ref_id, user.name as user_name
|
||||
from api_definition
|
||||
left join user on api_definition.user_id = user.id
|
||||
|
@ -279,12 +285,16 @@
|
|||
</select>
|
||||
|
||||
<select id="weekList" resultType="io.metersphere.api.dto.definition.ApiDefinitionResult">
|
||||
select api_definition.id, api_definition.project_id, api_definition.num, api_definition.tags,api_definition.original_state,
|
||||
select api_definition.id, api_definition.project_id, api_definition.num,
|
||||
api_definition.tags,api_definition.original_state,
|
||||
api_definition.name,api_definition.protocol,api_definition.path,api_definition.module_id,api_definition.module_path,api_definition.method,
|
||||
api_definition.description,api_definition.environment_id,
|
||||
api_definition.status, api_definition.user_id, api_definition.create_time, api_definition.update_time, project.name as
|
||||
project_name, user.name as user_name,deleteUser.name AS delete_user,api_definition.delete_time, api_definition.remark
|
||||
from (select * from api_definition where update_time >= #{startTimestamp} order by update_time desc)api_definition
|
||||
api_definition.status, api_definition.user_id, api_definition.create_time, api_definition.update_time,
|
||||
project.name as
|
||||
project_name, user.name as user_name,deleteUser.name AS delete_user,api_definition.delete_time,
|
||||
api_definition.remark
|
||||
from (select * from api_definition where update_time >= #{startTimestamp} order by update_time
|
||||
desc)api_definition
|
||||
left join project on api_definition.project_id = project.id
|
||||
left join user on api_definition.user_id = user.id
|
||||
left join user deleteUser on api_definition.delete_user_id = deleteUser.id
|
||||
|
@ -314,7 +324,8 @@
|
|||
from api_definition
|
||||
left join project on api_definition.project_id = project.id
|
||||
left join user on api_definition.user_id = user.id
|
||||
left join project_version on api_definition.project_id = project_version.project_id and api_definition.version_id = project_version.id
|
||||
left join project_version on api_definition.project_id = project_version.project_id and
|
||||
api_definition.version_id = project_version.id
|
||||
WHERE api_definition.id IN
|
||||
<foreach collection="ids" item="v" separator="," open="(" close=")">
|
||||
#{v}
|
||||
|
@ -358,33 +369,48 @@
|
|||
</update>
|
||||
|
||||
<select id="countProtocolByProjectID" resultType="io.metersphere.api.dto.datacount.ApiDataCountResult">
|
||||
SELECT protocol AS groupField,count(DISTINCT ref_id) AS countNumber
|
||||
SELECT protocol AS groupField, count(DISTINCT ref_id) AS countNumber
|
||||
FROM api_definition
|
||||
WHERE project_id = #{0}
|
||||
AND `status` != 'Trash'
|
||||
AND `status` != 'Trash'
|
||||
AND latest = 1
|
||||
GROUP BY protocol
|
||||
</select>
|
||||
<select id="countStateByProjectID" resultType="io.metersphere.api.dto.datacount.ApiDataCountResult">
|
||||
SELECT status AS groupField,count(id) AS countNumber FROM api_definition WHERE project_id = #{0} AND `status` != 'Trash' AND latest = 1 GROUP BY status
|
||||
SELECT status AS groupField, count(id) AS countNumber
|
||||
FROM api_definition
|
||||
WHERE project_id = #{0}
|
||||
AND `status` != 'Trash' AND latest = 1
|
||||
GROUP BY status
|
||||
</select>
|
||||
<select id="countByProjectIDAndCreateInThisWeek" resultType="java.lang.Long">
|
||||
SELECT count(id) AS countNumber FROM api_definition
|
||||
SELECT count(id) AS countNumber
|
||||
FROM api_definition
|
||||
WHERE project_id = #{projectId}
|
||||
AND create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp} AND `status` != 'Trash' AND latest = 1
|
||||
AND create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp}
|
||||
AND `status` != 'Trash' AND latest = 1
|
||||
</select>
|
||||
<select id="countApiCoverageByProjectID" resultType="io.metersphere.api.dto.datacount.ApiDataCountResult">
|
||||
SELECT count(api.id) AS countNumber, if(test_case_api.api_definition_id is null,"uncoverage","coverage") AS groupField FROM api_definition api left Join (
|
||||
SELECT count(api.id) AS countNumber,
|
||||
if(test_case_api.api_definition_id is null, "uncoverage", "coverage") AS groupField
|
||||
FROM api_definition api
|
||||
left Join (
|
||||
SELECT DISTINCT api_definition_id FROM api_test_case WHERE status is null or status != 'Trash'
|
||||
) test_case_api ON api.id = test_case_api.api_definition_id
|
||||
WHERE api.project_id = #{0} and api.`status` != 'Trash' and api.latest = 1
|
||||
WHERE api.project_id = #{0}
|
||||
and api.`status` != 'Trash' and api.latest = 1
|
||||
GROUP BY groupField
|
||||
</select>
|
||||
<select id="getNextNum" resultType="io.metersphere.base.domain.ApiDefinition">
|
||||
SELECT * FROM api_definition WHERE api_definition.project_id = #{projectId} ORDER BY num DESC LIMIT 1;
|
||||
SELECT *
|
||||
FROM api_definition
|
||||
WHERE api_definition.project_id = #{projectId}
|
||||
ORDER BY num DESC LIMIT 1;
|
||||
</select>
|
||||
<select id="selectUrlAndMethodById" resultType="io.metersphere.base.domain.ApiDefinition">
|
||||
SELECT method,path FROM api_definition WHERE id = #{0}
|
||||
SELECT method, path
|
||||
FROM api_definition
|
||||
WHERE id = #{0}
|
||||
</select>
|
||||
<select id="listRelevance" resultType="io.metersphere.api.dto.definition.ApiDefinitionResult">
|
||||
select
|
||||
|
@ -416,7 +442,8 @@
|
|||
api_definition.`order`,
|
||||
api_definition.ref_id
|
||||
from api_definition
|
||||
left join project_version on api_definition.project_id = project_version.project_id and api_definition.version_id = project_version.id
|
||||
left join project_version on api_definition.project_id = project_version.project_id and
|
||||
api_definition.version_id = project_version.id
|
||||
<where>
|
||||
<if test="request.combine != null">
|
||||
<include refid="combine">
|
||||
|
@ -611,9 +638,10 @@
|
|||
</select>
|
||||
|
||||
<select id="selectEffectiveIdByProjectId" resultType="io.metersphere.base.domain.ApiDefinition">
|
||||
select id,path,method
|
||||
select id, path, method
|
||||
from api_definition
|
||||
WHERE project_id = #{0} AND status != 'Trash' AND protocol = 'HTTP' AND latest = 1
|
||||
WHERE project_id = #{0}
|
||||
AND status != 'Trash' AND protocol = 'HTTP' AND latest = 1
|
||||
</select>
|
||||
|
||||
<select id="moduleCount" resultType="java.lang.Integer">
|
||||
|
@ -815,10 +843,14 @@
|
|||
</sql>
|
||||
|
||||
<select id="selectProjectIds" resultType="java.lang.String">
|
||||
select DISTINCT project_id from api_definition;
|
||||
select DISTINCT project_id
|
||||
from api_definition;
|
||||
</select>
|
||||
<select id="getIdsOrderByUpdateTime" resultType="java.lang.String">
|
||||
select id from api_definition where project_id = #{projectId} order by update_time ASC;
|
||||
select id
|
||||
from api_definition
|
||||
where project_id = #{projectId}
|
||||
order by update_time ASC;
|
||||
</select>
|
||||
|
||||
<select id="getLastOrder" resultType="java.lang.Long">
|
||||
|
@ -838,8 +870,10 @@
|
|||
</select>
|
||||
|
||||
<select id="countQuotedApiByProjectId" resultType="java.lang.Long">
|
||||
SELECT COUNT(id) FROM api_definition
|
||||
WHERE project_id = #{0} AND `status` != 'Trash'
|
||||
SELECT COUNT(id)
|
||||
FROM api_definition
|
||||
WHERE project_id = #{0}
|
||||
AND `status` != 'Trash'
|
||||
AND (
|
||||
id IN (
|
||||
SELECT reference_id FROM api_scenario_reference_id WHERE api_scenario_id in (
|
||||
|
@ -880,7 +914,8 @@
|
|||
and api_definition.status != 'Trash';
|
||||
</select>
|
||||
|
||||
<select id="countByExample" parameterType="io.metersphere.base.domain.ApiDefinitionExample" resultType="java.lang.Long">
|
||||
<select id="countByExample" parameterType="io.metersphere.base.domain.ApiDefinitionExample"
|
||||
resultType="java.lang.Long">
|
||||
select count(DISTINCT ref_id) from api_definition
|
||||
<if test="_parameter != null">
|
||||
<include refid="io.metersphere.base.mapper.ApiDefinitionMapper.Example_Where_Clause"/>
|
||||
|
@ -911,35 +946,36 @@
|
|||
|
||||
<update id="addLatestVersion">
|
||||
UPDATE api_definition
|
||||
INNER JOIN ((
|
||||
SELECT tmp.id
|
||||
FROM api_definition tmp
|
||||
JOIN project_version
|
||||
ON tmp.project_id = project_version.project_id AND
|
||||
tmp.version_id = project_version.id AND project_version.latest = TRUE
|
||||
WHERE ref_id = #{refId,jdbcType=VARCHAR}
|
||||
LIMIT 1
|
||||
)
|
||||
UNION ALL
|
||||
(
|
||||
SELECT tmp.id
|
||||
FROM api_definition tmp
|
||||
JOIN project_version
|
||||
ON tmp.project_id = project_version.project_id AND
|
||||
tmp.version_id = project_version.id
|
||||
AND NOT EXISTS(SELECT ref_id
|
||||
FROM api_definition tmp2
|
||||
JOIN project_version
|
||||
ON tmp2.project_id =
|
||||
project_version.project_id AND
|
||||
version_id =
|
||||
project_version.id AND
|
||||
project_version.latest = TRUE
|
||||
WHERE tmp.ref_id = tmp2.ref_id)
|
||||
WHERE tmp.ref_id = #{refId,jdbcType=VARCHAR}
|
||||
ORDER BY tmp.update_time DESC
|
||||
LIMIT 1)) AS t ON api_definition.id = t.id
|
||||
SET api_definition.latest = TRUE
|
||||
INNER JOIN ((
|
||||
SELECT tmp.id
|
||||
FROM api_definition tmp
|
||||
JOIN project_version
|
||||
ON tmp.project_id = project_version.project_id AND
|
||||
tmp.version_id = project_version.id AND project_version.latest = TRUE
|
||||
WHERE ref_id = #{refId,jdbcType=VARCHAR}
|
||||
LIMIT 1
|
||||
)
|
||||
UNION ALL
|
||||
(
|
||||
SELECT tmp.id
|
||||
FROM api_definition tmp
|
||||
JOIN project_version
|
||||
ON tmp.project_id = project_version.project_id AND
|
||||
tmp.version_id = project_version.id
|
||||
AND NOT EXISTS (SELECT ref_id
|
||||
FROM api_definition tmp2
|
||||
JOIN project_version
|
||||
ON tmp2.project_id =
|
||||
project_version.project_id AND
|
||||
version_id =
|
||||
project_version.id AND
|
||||
project_version.latest = TRUE
|
||||
WHERE tmp.ref_id = tmp2.ref_id)
|
||||
WHERE tmp.ref_id = #{refId,jdbcType=VARCHAR}
|
||||
ORDER BY tmp.update_time DESC
|
||||
LIMIT 1)) AS t
|
||||
ON api_definition.id = t.id
|
||||
SET api_definition.latest = TRUE
|
||||
WHERE ref_id = #{refId,jdbcType=VARCHAR}
|
||||
</update>
|
||||
|
||||
|
@ -957,13 +993,47 @@
|
|||
SELECT DISTINCT ref_id
|
||||
FROM api_definition
|
||||
WHERE ref_id NOT IN (
|
||||
SELECT DISTINCT ref_id
|
||||
FROM api_definition
|
||||
WHERE version_id = #{versionId} AND project_id = #{projectId}
|
||||
) AND project_id = #{projectId}
|
||||
SELECT DISTINCT ref_id
|
||||
FROM api_definition
|
||||
WHERE version_id = #{versionId}
|
||||
AND project_id = #{projectId}
|
||||
)
|
||||
AND project_id = #{projectId}
|
||||
</select>
|
||||
|
||||
<select id="selectNameById" resultType="java.lang.String">
|
||||
SELECT name FROM api_definition WHERE id = #{0}
|
||||
SELECT name
|
||||
FROM api_definition
|
||||
WHERE id = #{0}
|
||||
</select>
|
||||
|
||||
<select id="selectRepeatByBLOBs" resultType="io.metersphere.base.domain.ApiDefinitionWithBLOBs">
|
||||
SELECT * from api_definition
|
||||
<include refid="Same_Where_Clause"/>
|
||||
and status != 'TRASH'
|
||||
</select>
|
||||
<select id="selectRepeatByBLOBsSameUrl" resultType="io.metersphere.base.domain.ApiDefinitionWithBLOBs">
|
||||
SELECT * from api_definition
|
||||
<include refid="Same_Where_Clause"/>
|
||||
and status != 'TRASH'
|
||||
and module_id = #{moduleId}
|
||||
</select>
|
||||
<sql id="Same_Where_Clause">
|
||||
<where>
|
||||
<foreach collection="blobs" item="blob" separator="or">
|
||||
<trim prefix="(" prefixOverrides="and" suffix=")">
|
||||
<if test="blob.method">
|
||||
and api_definition.method = #{blob.method}
|
||||
</if>
|
||||
<if test="blob.path">
|
||||
and api_definition.path = #{blob.path}
|
||||
</if>
|
||||
<if test="blob.projectId">
|
||||
and api_definition.project_id = #{blob.projectId}
|
||||
</if>
|
||||
</trim>
|
||||
|
||||
</foreach>
|
||||
</where>
|
||||
</sql>
|
||||
</mapper>
|
||||
|
|
|
@ -90,4 +90,10 @@ public interface ExtApiScenarioMapper {
|
|||
List<String> selectRefIdsForVersionChange(@Param("versionId") String versionId, @Param("projectId") String projectId);
|
||||
|
||||
List<ApiScenarioWithBLOBs> selectByStatusIsNotTrash();
|
||||
|
||||
List<ApiScenarioWithBLOBs> selectRepeatByBLOBs(@Param("blobs") List<ApiScenarioWithBLOBs> blobs);
|
||||
|
||||
List<ApiScenarioWithBLOBs> selectRepeatByBLOBsSameUrl(@Param("blobs") List<ApiScenarioWithBLOBs> blobs, @Param("moduleId") String moduleId);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -771,4 +771,34 @@
|
|||
FROM api_scenario
|
||||
WHERE `status` != 'Trash' AND project_id IN (SELECT id FROM project);
|
||||
</select>
|
||||
<select id="selectRepeatByBLOBs" resultType="io.metersphere.base.domain.ApiScenarioWithBLOBs">
|
||||
SELECT * from api_scenario
|
||||
<include refid="Same_Where_Clause"/>
|
||||
and status != 'TRASH'
|
||||
</select>
|
||||
|
||||
<select id="selectRepeatByBLOBsSameUrl" resultType="io.metersphere.base.domain.ApiScenarioWithBLOBs">
|
||||
SELECT * from api_scenario
|
||||
<include refid="Same_Where_Clause"/>
|
||||
and status != 'TRASH'
|
||||
and api_scenario_module_id = #{moduleId}
|
||||
</select>
|
||||
|
||||
<sql id="Same_Where_Clause">
|
||||
<where>
|
||||
<foreach collection="blobs" item="blob" separator="or">
|
||||
<trim prefix="(" prefixOverrides="and" suffix=")">
|
||||
<if test="blob.name">
|
||||
and api_scenario.name = #{blob.name}
|
||||
</if>
|
||||
<if test="blob.projectId">
|
||||
and api_scenario.project_id = #{blob.projectId}
|
||||
</if>
|
||||
</trim>
|
||||
|
||||
</foreach>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
|
||||
|
|
|
@ -438,11 +438,6 @@ export default {
|
|||
param.saved = this.saved;
|
||||
param.model = this.model;
|
||||
if (this.currentModule) {
|
||||
if (!this.formData.moduleId || this.formData.moduleId.length === 0) {
|
||||
param.moduleId = this.currentModule[0].id;
|
||||
} else {
|
||||
param.moduleId = this.formData.moduleId
|
||||
}
|
||||
param.modeId = this.formData.modeId
|
||||
}
|
||||
param.projectId = this.projectId;
|
||||
|
@ -456,7 +451,7 @@ export default {
|
|||
// 设置 query 参数
|
||||
param.arguments = this.queryArguments;
|
||||
// 设置 BaseAuth 参数
|
||||
if (this.authConfig.authManager != undefined) {
|
||||
if (this.authConfig.authManager !== undefined) {
|
||||
this.authConfig.authManager.clazzName = TYPE_TO_C.get("AuthManager");
|
||||
param.authManager = this.authConfig.authManager;
|
||||
}
|
||||
|
@ -572,5 +567,4 @@ export default {
|
|||
height: 200px;
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
|
|
Loading…
Reference in New Issue