Merge branch 'master' of https://github.com/metersphere/metersphere
# Conflicts: # frontend/src/business/components/api/automation/scenario/ApiScenarioModule.vue
This commit is contained in:
commit
dcb0714601
|
@ -90,7 +90,7 @@ public class ApiDefinitionController {
|
|||
}
|
||||
|
||||
@PostMapping("/deleteBatchByParams")
|
||||
public void deleteBatchByParams(@RequestBody ApiDefinitionBatchProcessingRequest request) {
|
||||
public void deleteBatchByParams(@RequestBody ApiBatchRequest request) {
|
||||
apiDefinitionService.deleteByParams(request);
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ public class ApiDefinitionController {
|
|||
|
||||
@PostMapping("/removeToGcByParams")
|
||||
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR)
|
||||
public void removeToGcByParams(@RequestBody ApiDefinitionBatchProcessingRequest request) {
|
||||
public void removeToGcByParams(@RequestBody ApiBatchRequest request) {
|
||||
apiDefinitionService.removeToGcByParams(request);
|
||||
}
|
||||
|
||||
|
@ -147,6 +147,13 @@ public class ApiDefinitionController {
|
|||
public ApiDefinitionImport testCaseImport(@RequestPart(value = "file", required = false) MultipartFile file, @RequestPart("request") ApiTestImportRequest request) {
|
||||
return apiDefinitionService.apiTestImport(file, request);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/export")
|
||||
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
||||
public ApiExportResult export(@RequestBody ApiBatchRequest request) {
|
||||
return apiDefinitionService.export(request);
|
||||
}
|
||||
|
||||
//定时任务创建
|
||||
@PostMapping(value = "/schedule/create")
|
||||
public void createSchedule(@RequestBody Schedule request) {
|
||||
|
|
|
@ -6,7 +6,6 @@ import lombok.Getter;
|
|||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
|
@ -14,25 +13,8 @@ public class ApiBatchRequest extends ApiDefinitionWithBLOBs {
|
|||
private List<String> ids;
|
||||
private List<OrderRequest> orders;
|
||||
private String projectId;
|
||||
|
||||
/**
|
||||
* isSelectAllDate:选择的数据是否是全部数据(全部数据是不受分页影响的数据)
|
||||
* filters: 数据状态
|
||||
* name:如果是全部数据,那么表格如果历经查询,查询参数是什么
|
||||
* moduleIds: 哪些模块的数据
|
||||
* unSelectIds:是否在页面上有未勾选的数据,有的话他们的ID是哪些。
|
||||
* filters/name/moduleIds/unSeelctIds 只在isSelectAllDate为true时需要。为了让程序能明确批量的范围。
|
||||
*/
|
||||
private boolean isSelectAllDate;
|
||||
|
||||
private Map<String, List<String>> filters;
|
||||
|
||||
private String name;
|
||||
|
||||
private List<String> moduleIds;
|
||||
|
||||
private List<String> unSelectIds;
|
||||
|
||||
private String moduleId;
|
||||
private String protocol;
|
||||
|
||||
private ApiDefinitionRequest condition;
|
||||
}
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 接口定义模块-批量处理请求类
|
||||
* @author song.tianyang
|
||||
* @Date 2020/12/29 4:13 下午
|
||||
* @Description
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class ApiDefinitionBatchProcessingRequest {
|
||||
/**
|
||||
* isSelectAllDate:选择的数据是否是全部数据(全部数据是不受分页影响的数据)
|
||||
* filters: 数据状态
|
||||
* name:如果是全部数据,那么表格如果历经查询,查询参数是什么
|
||||
* moduleIds: 哪些模块的数据
|
||||
* unSelectIds:是否在页面上有未勾选的数据,有的话他们的ID是哪些。
|
||||
* filters/name/moduleIds/unSeelctIds 只在isSelectAllDate为true时需要。为了让程序能明确批量的范围。
|
||||
*/
|
||||
private boolean isSelectAllDate;
|
||||
|
||||
private Map<String, List<String>> filters;
|
||||
|
||||
private String name;
|
||||
|
||||
private List<String> moduleIds;
|
||||
|
||||
private List<String> unSelectIds;
|
||||
|
||||
private String projectId;
|
||||
|
||||
private List<String> dataIds;
|
||||
|
||||
private String protocol;
|
||||
|
||||
}
|
|
@ -1,31 +1,21 @@
|
|||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import io.metersphere.controller.request.OrderRequest;
|
||||
import io.metersphere.controller.request.BaseQueryRequest;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ApiDefinitionRequest {
|
||||
public class ApiDefinitionRequest extends BaseQueryRequest {
|
||||
|
||||
private String id;
|
||||
private String excludeId;
|
||||
private String projectId;
|
||||
private String moduleId;
|
||||
private List<String> moduleIds;
|
||||
private String protocol;
|
||||
private String name;
|
||||
private String workspaceId;
|
||||
private String userId;
|
||||
private String planId;
|
||||
private boolean recent = false;
|
||||
private List<OrderRequest> orders;
|
||||
private Map<String, List<String>> filters;
|
||||
private Map<String, Object> combine;
|
||||
private List<String> ids;
|
||||
private boolean isSelectThisWeedData = false;
|
||||
private long createTime = 0;
|
||||
private String status;
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ApiExportResult {
|
||||
private String projectName;
|
||||
private String protocol;
|
||||
private List<ApiDefinitionWithBLOBs> data;
|
||||
private List<ApiTestCaseWithBLOBs> cases;
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package io.metersphere.api.dto.definition.parse;
|
||||
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -9,5 +10,8 @@ import java.util.List;
|
|||
public class ApiDefinitionImport {
|
||||
private String projectName;
|
||||
private String protocol;
|
||||
private List<ApiDefinitionResult> data;
|
||||
private List<ApiDefinitionWithBLOBs> data;
|
||||
|
||||
// 新版本带用例导出
|
||||
private List<ApiTestCaseWithBLOBs> cases;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package io.metersphere.api.parse;
|
||||
|
||||
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.dto.definition.ApiModuleDTO;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||
import io.metersphere.api.dto.scenario.Body;
|
||||
|
@ -9,6 +8,7 @@ import io.metersphere.api.dto.scenario.KeyValue;
|
|||
import io.metersphere.api.dto.scenario.Scenario;
|
||||
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.BeanUtils;
|
||||
|
@ -151,8 +151,8 @@ public abstract class ApiImportAbstractParser implements ApiImportParser {
|
|||
}
|
||||
}
|
||||
|
||||
protected ApiDefinitionResult buildApiDefinition(String id, String name, String path, String method, ApiTestImportRequest importRequest) {
|
||||
ApiDefinitionResult apiDefinition = new ApiDefinitionResult();
|
||||
protected ApiDefinitionWithBLOBs buildApiDefinition(String id, String name, String path, String method, ApiTestImportRequest importRequest) {
|
||||
ApiDefinitionWithBLOBs apiDefinition = new ApiDefinitionWithBLOBs();
|
||||
apiDefinition.setName(name);
|
||||
apiDefinition.setPath(formatPath(path));
|
||||
apiDefinition.setProtocol(RequestType.HTTP);
|
||||
|
|
|
@ -6,13 +6,16 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import com.alibaba.fastjson.parser.Feature;
|
||||
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.dto.definition.ApiExportResult;
|
||||
import io.metersphere.api.dto.definition.parse.ApiDefinitionImport;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||
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.api.service.ApiModuleService;
|
||||
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;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
|
@ -41,10 +44,14 @@ public class MsParser extends ApiImportAbstractParser {
|
|||
}
|
||||
|
||||
private ApiDefinitionImport parseMsFormat(String testStr, ApiTestImportRequest importRequest) {
|
||||
|
||||
ApiDefinitionImport apiDefinitionImport = JSON.parseObject(testStr, ApiDefinitionImport.class);
|
||||
List<ApiDefinitionResult> data = apiDefinitionImport.getData();
|
||||
data.forEach(apiDefinition -> {
|
||||
apiDefinitionImport.getData().forEach(apiDefinition -> {
|
||||
parseApiDefinition(apiDefinition, importRequest);
|
||||
});
|
||||
return apiDefinitionImport;
|
||||
}
|
||||
|
||||
private void parseApiDefinition(ApiDefinitionWithBLOBs apiDefinition, ApiTestImportRequest importRequest) {
|
||||
String id = UUID.randomUUID().toString();
|
||||
if (StringUtils.isBlank(apiDefinition.getModulePath())) {
|
||||
apiDefinition.setModuleId(null);
|
||||
|
@ -56,12 +63,10 @@ public class MsParser extends ApiImportAbstractParser {
|
|||
JSONObject requestObj = JSONObject.parseObject(request);
|
||||
requestObj.put("id", id);
|
||||
apiDefinition.setRequest(JSONObject.toJSONString(requestObj));
|
||||
});
|
||||
return apiDefinitionImport;
|
||||
}
|
||||
|
||||
private ApiDefinitionImport parsePluginFormat(JSONObject testObject, ApiTestImportRequest importRequest) {
|
||||
List<ApiDefinitionResult> results = new ArrayList<>();
|
||||
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
||||
ApiDefinitionImport apiImport = new ApiDefinitionImport();
|
||||
apiImport.setProtocol(RequestType.HTTP);
|
||||
apiImport.setData(results);
|
||||
|
@ -78,7 +83,7 @@ public class MsParser extends ApiImportAbstractParser {
|
|||
String method = requestObject.getString("method");
|
||||
|
||||
MsHTTPSamplerProxy request = buildRequest(requestName, path, method);
|
||||
ApiDefinitionResult apiDefinition = buildApiDefinition(request.getId(), requestName, path, method,importRequest);
|
||||
ApiDefinitionWithBLOBs apiDefinition = buildApiDefinition(request.getId(), requestName, path, method,importRequest);
|
||||
apiDefinition.setModuleId(module.getId());
|
||||
apiDefinition.setProjectId(this.projectId);
|
||||
parseBody(requestObject, request.getBody());
|
||||
|
@ -91,7 +96,7 @@ public class MsParser extends ApiImportAbstractParser {
|
|||
return apiImport;
|
||||
}
|
||||
|
||||
private void parsePath(MsHTTPSamplerProxy request, ApiDefinitionResult apiDefinition) {
|
||||
private void parsePath(MsHTTPSamplerProxy request, ApiDefinitionWithBLOBs apiDefinition) {
|
||||
if (StringUtils.isNotBlank(request.getPath())) {
|
||||
String[] split = request.getPath().split("\\?");
|
||||
String path = split[0];
|
||||
|
@ -160,7 +165,7 @@ public class MsParser extends ApiImportAbstractParser {
|
|||
}
|
||||
|
||||
|
||||
private void parseModule(ApiDefinitionResult apiDefinition, ApiTestImportRequest importRequest) {
|
||||
private void parseModule(ApiDefinitionWithBLOBs apiDefinition, ApiTestImportRequest importRequest) {
|
||||
String modulePath = apiDefinition.getModulePath();
|
||||
if (StringUtils.isBlank(modulePath)) {
|
||||
return;
|
||||
|
|
|
@ -3,7 +3,6 @@ package io.metersphere.api.parse;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.dto.definition.parse.ApiDefinitionImport;
|
||||
import io.metersphere.api.dto.definition.request.MsTestElement;
|
||||
import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor;
|
||||
|
@ -11,6 +10,7 @@ import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
|||
import io.metersphere.api.dto.parse.postman.*;
|
||||
import io.metersphere.api.dto.scenario.Body;
|
||||
import io.metersphere.api.dto.scenario.KeyValue;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import io.metersphere.commons.constants.MsRequestBodyType;
|
||||
import io.metersphere.commons.constants.PostmanRequestBodyMode;
|
||||
|
@ -32,20 +32,20 @@ public class PostmanParser extends ApiImportAbstractParser {
|
|||
PostmanCollection postmanCollection = JSON.parseObject(testStr, PostmanCollection.class);
|
||||
List<PostmanKeyValue> variables = postmanCollection.getVariable();
|
||||
ApiDefinitionImport apiImport = new ApiDefinitionImport();
|
||||
List<ApiDefinitionResult> results = new ArrayList<>();
|
||||
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
||||
parseItem(postmanCollection.getItem(), variables, results, buildModule(getSelectModule(request.getModuleId()), postmanCollection.getInfo().getName(), request.isSaved()), request.isSaved());
|
||||
apiImport.setData(results);
|
||||
return apiImport;
|
||||
}
|
||||
|
||||
private void parseItem(List<PostmanItem> items, List<PostmanKeyValue> variables, List<ApiDefinitionResult> results, ApiModule parentModule, boolean isSaved) {
|
||||
private void parseItem(List<PostmanItem> items, List<PostmanKeyValue> variables, List<ApiDefinitionWithBLOBs> results, ApiModule parentModule, boolean isSaved) {
|
||||
for (PostmanItem item : items) {
|
||||
List<PostmanItem> childItems = item.getItem();
|
||||
if (childItems != null) {
|
||||
ApiModule module = buildModule(parentModule, item.getName() , isSaved);
|
||||
parseItem(childItems, variables, results, module, isSaved);
|
||||
} else {
|
||||
ApiDefinitionResult request = parsePostman(item);
|
||||
ApiDefinitionWithBLOBs request = parsePostman(item);
|
||||
if (request != null) {
|
||||
results.add(request);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public class PostmanParser extends ApiImportAbstractParser {
|
|||
}
|
||||
}
|
||||
|
||||
private ApiDefinitionResult parsePostman(PostmanItem requestItem) {
|
||||
private ApiDefinitionWithBLOBs parsePostman(PostmanItem requestItem) {
|
||||
PostmanRequest requestDesc = requestItem.getRequest();
|
||||
if (requestDesc == null) {
|
||||
return null;
|
||||
|
@ -64,7 +64,7 @@ public class PostmanParser extends ApiImportAbstractParser {
|
|||
requestDesc.getAuth(); // todo 认证方式等待优化
|
||||
PostmanUrl url = requestDesc.getUrl();
|
||||
MsHTTPSamplerProxy request = buildRequest(requestItem.getName(), url.getRaw(), requestDesc.getMethod());
|
||||
ApiDefinitionResult apiDefinition =
|
||||
ApiDefinitionWithBLOBs apiDefinition =
|
||||
buildApiDefinition(request.getId(), requestItem.getName(), url.getRaw(), requestDesc.getMethod(),new ApiTestImportRequest());
|
||||
if (StringUtils.isNotBlank(request.getPath())) {
|
||||
String path = request.getPath().split("\\?")[0];
|
||||
|
|
|
@ -4,13 +4,13 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.dto.definition.parse.ApiDefinitionImport;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||
import io.metersphere.api.dto.definition.response.HttpResponse;
|
||||
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.swagger.models.*;
|
||||
|
@ -49,13 +49,13 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
|||
return definitionImport;
|
||||
}
|
||||
|
||||
private List<ApiDefinitionResult> parseRequests(Swagger swagger, ApiTestImportRequest importRequest) {
|
||||
private List<ApiDefinitionWithBLOBs> parseRequests(Swagger swagger, ApiTestImportRequest importRequest) {
|
||||
Map<String, Path> paths = swagger.getPaths();
|
||||
Set<String> pathNames = paths.keySet();
|
||||
|
||||
this.definitions = swagger.getDefinitions();
|
||||
|
||||
List<ApiDefinitionResult> results = new ArrayList<>();
|
||||
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
||||
|
||||
ApiModule parentNode = getSelectModule(importRequest.getModuleId());
|
||||
|
||||
|
@ -66,7 +66,7 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
|||
for (HttpMethod method : httpMethods) {
|
||||
Operation operation = operationMap.get(method);
|
||||
MsHTTPSamplerProxy request = buildRequest(operation, pathName, method.name());
|
||||
ApiDefinitionResult apiDefinition = buildApiDefinition(request.getId(), operation, pathName, method.name(),importRequest);
|
||||
ApiDefinitionWithBLOBs apiDefinition = buildApiDefinition(request.getId(), operation, pathName, method.name(),importRequest);
|
||||
parseParameters(operation, request);
|
||||
addBodyHeader(request);
|
||||
apiDefinition.setRequest(JSON.toJSONString(request));
|
||||
|
@ -80,7 +80,7 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
|||
return results;
|
||||
}
|
||||
|
||||
private ApiDefinitionResult buildApiDefinition(String id, Operation operation, String path, String method,ApiTestImportRequest importRequest) {
|
||||
private ApiDefinitionWithBLOBs buildApiDefinition(String id, Operation operation, String path, String method,ApiTestImportRequest importRequest) {
|
||||
String name = "";
|
||||
if (StringUtils.isNotBlank(operation.getSummary())) {
|
||||
name = operation.getSummary();
|
||||
|
|
|
@ -4,13 +4,13 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.dto.definition.parse.ApiDefinitionImport;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||
import io.metersphere.api.dto.definition.response.HttpResponse;
|
||||
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;
|
||||
|
@ -69,14 +69,14 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
|||
return definitionImport;
|
||||
}
|
||||
|
||||
private List<ApiDefinitionResult> parseRequests(OpenAPI openAPI, ApiTestImportRequest importRequest) {
|
||||
private List<ApiDefinitionWithBLOBs> parseRequests(OpenAPI openAPI, ApiTestImportRequest importRequest) {
|
||||
Paths paths = openAPI.getPaths();
|
||||
|
||||
Set<String> pathNames = paths.keySet();
|
||||
|
||||
this.components = openAPI.getComponents();
|
||||
|
||||
List<ApiDefinitionResult> results = new ArrayList<>();
|
||||
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
||||
|
||||
ApiModule parentNode = getSelectModule(importRequest.getModuleId());
|
||||
|
||||
|
@ -97,7 +97,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
|||
Operation operation = operationsMap.get(method);
|
||||
if (operation != null) {
|
||||
MsHTTPSamplerProxy request = buildRequest(operation, pathName, method);
|
||||
ApiDefinitionResult apiDefinition = buildApiDefinition(request.getId(), operation, pathName, method,importRequest);
|
||||
ApiDefinitionWithBLOBs apiDefinition = buildApiDefinition(request.getId(), operation, pathName, method,importRequest);
|
||||
parseParameters(operation, request);
|
||||
parseRequestBody(operation.getRequestBody(), request.getBody());
|
||||
addBodyHeader(request);
|
||||
|
@ -112,7 +112,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
|||
return results;
|
||||
}
|
||||
|
||||
private ApiDefinitionResult buildApiDefinition(String id, Operation operation, String path, String method,ApiTestImportRequest importRequest) {
|
||||
private ApiDefinitionWithBLOBs buildApiDefinition(String id, Operation operation, String path, String method,ApiTestImportRequest importRequest) {
|
||||
String name = "";
|
||||
if (StringUtils.isNotBlank(operation.getSummary())) {
|
||||
name = operation.getSummary();
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package io.metersphere.api.parse;
|
||||
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class SwaggerAbstractParser extends ApiImportAbstractParser {
|
||||
|
||||
protected void buildModule(ApiModule parentModule, ApiDefinitionResult apiDefinition, List<String> tags, boolean isSaved) {
|
||||
protected void buildModule(ApiModule parentModule, ApiDefinitionWithBLOBs apiDefinition, List<String> tags, boolean isSaved) {
|
||||
if (tags != null) {
|
||||
tags.forEach(tag -> {
|
||||
ApiModule module = buildModule(parentModule, tag, isSaved);
|
||||
|
|
|
@ -3,7 +3,6 @@ package io.metersphere.api.parse.old;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.dto.definition.parse.ApiDefinitionImport;
|
||||
import io.metersphere.api.dto.definition.request.MsTestElement;
|
||||
import io.metersphere.api.dto.definition.request.configurations.MsHeaderManager;
|
||||
|
@ -16,6 +15,7 @@ import io.metersphere.api.dto.scenario.Scenario;
|
|||
import io.metersphere.api.dto.scenario.request.HttpRequest;
|
||||
import io.metersphere.api.dto.scenario.request.Request;
|
||||
import io.metersphere.api.dto.scenario.request.RequestType;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.commons.constants.MsRequestBodyType;
|
||||
import io.metersphere.commons.constants.PostmanRequestBodyMode;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -54,20 +54,20 @@ public class PostmanParser extends ApiImportAbstractParser {
|
|||
PostmanCollection postmanCollection = JSON.parseObject(testStr, PostmanCollection.class);
|
||||
List<PostmanKeyValue> variables = postmanCollection.getVariable();
|
||||
ApiDefinitionImport apiImport = new ApiDefinitionImport();
|
||||
List<ApiDefinitionResult> requests = new ArrayList<>();
|
||||
List<ApiDefinitionWithBLOBs> requests = new ArrayList<>();
|
||||
|
||||
parseItem(postmanCollection.getItem(), variables, requests);
|
||||
apiImport.setData(requests);
|
||||
return apiImport;
|
||||
}
|
||||
|
||||
private void parseItem(List<PostmanItem> items, List<PostmanKeyValue> variables, List<ApiDefinitionResult> scenarios) {
|
||||
private void parseItem(List<PostmanItem> items, List<PostmanKeyValue> variables, List<ApiDefinitionWithBLOBs> scenarios) {
|
||||
for (PostmanItem item : items) {
|
||||
List<PostmanItem> childItems = item.getItem();
|
||||
if (childItems != null) {
|
||||
parseItem(childItems, variables, scenarios);
|
||||
} else {
|
||||
ApiDefinitionResult request = parsePostman(item);
|
||||
ApiDefinitionWithBLOBs request = parsePostman(item);
|
||||
if (request != null) {
|
||||
scenarios.add(request);
|
||||
}
|
||||
|
@ -75,13 +75,13 @@ public class PostmanParser extends ApiImportAbstractParser {
|
|||
}
|
||||
}
|
||||
|
||||
private ApiDefinitionResult parsePostman(PostmanItem requestItem) {
|
||||
private ApiDefinitionWithBLOBs parsePostman(PostmanItem requestItem) {
|
||||
PostmanRequest requestDesc = requestItem.getRequest();
|
||||
if (requestDesc == null) {
|
||||
return null;
|
||||
}
|
||||
PostmanUrl url = requestDesc.getUrl();
|
||||
ApiDefinitionResult request = new ApiDefinitionResult();
|
||||
ApiDefinitionWithBLOBs request = new ApiDefinitionWithBLOBs();
|
||||
request.setName(requestItem.getName());
|
||||
request.setPath(url.getRaw());
|
||||
request.setMethod(requestDesc.getMethod());
|
||||
|
|
|
@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.dto.definition.parse.ApiDefinitionImport;
|
||||
import io.metersphere.api.dto.definition.request.MsTestElement;
|
||||
import io.metersphere.api.dto.definition.request.configurations.MsHeaderManager;
|
||||
|
@ -16,6 +15,7 @@ import io.metersphere.api.dto.scenario.Scenario;
|
|||
import io.metersphere.api.dto.scenario.request.HttpRequest;
|
||||
import io.metersphere.api.dto.scenario.request.Request;
|
||||
import io.metersphere.api.dto.scenario.request.RequestType;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.commons.constants.MsRequestBodyType;
|
||||
import io.metersphere.commons.constants.SwaggerParameterType;
|
||||
import io.swagger.models.*;
|
||||
|
@ -54,13 +54,13 @@ public class Swagger2Parser extends ApiImportAbstractParser {
|
|||
return definitionImport;
|
||||
}
|
||||
|
||||
private List<ApiDefinitionResult> parseSwagger(ApiImport apiImport) {
|
||||
List<ApiDefinitionResult> results = new LinkedList<>();
|
||||
private List<ApiDefinitionWithBLOBs> parseSwagger(ApiImport apiImport) {
|
||||
List<ApiDefinitionWithBLOBs> results = new LinkedList<>();
|
||||
apiImport.getScenarios().forEach(item -> {
|
||||
item.getRequests().forEach(childItem -> {
|
||||
if (childItem instanceof HttpRequest) {
|
||||
HttpRequest res = (HttpRequest) childItem;
|
||||
ApiDefinitionResult request = new ApiDefinitionResult();
|
||||
ApiDefinitionWithBLOBs request = new ApiDefinitionWithBLOBs();
|
||||
request.setName(res.getName());
|
||||
request.setPath(res.getPath());
|
||||
request.setMethod(res.getMethod());
|
||||
|
|
|
@ -298,24 +298,23 @@ public class ApiDefinitionService {
|
|||
}
|
||||
}
|
||||
|
||||
private ApiDefinition importCreate(ApiDefinitionResult request, ApiDefinitionMapper batchMapper, ApiTestCaseMapper apiTestCaseMapper, ApiTestImportRequest apiTestImportRequest) {
|
||||
private ApiDefinition importCreate(ApiDefinitionWithBLOBs apiDefinition, ApiDefinitionMapper batchMapper,
|
||||
ApiTestCaseMapper apiTestCaseMapper, ApiTestImportRequest apiTestImportRequest, List<ApiTestCaseWithBLOBs> cases) {
|
||||
SaveApiDefinitionRequest saveReq = new SaveApiDefinitionRequest();
|
||||
BeanUtils.copyBean(saveReq, request);
|
||||
final ApiDefinitionWithBLOBs apiDefinition = new ApiDefinitionWithBLOBs();
|
||||
BeanUtils.copyBean(apiDefinition, request);
|
||||
BeanUtils.copyBean(saveReq, apiDefinition);
|
||||
apiDefinition.setCreateTime(System.currentTimeMillis());
|
||||
apiDefinition.setUpdateTime(System.currentTimeMillis());
|
||||
apiDefinition.setStatus(APITestStatus.Underway.name());
|
||||
if (request.getUserId() == null) {
|
||||
if (apiDefinition.getUserId() == null) {
|
||||
apiDefinition.setUserId(Objects.requireNonNull(SessionUtils.getUser()).getId());
|
||||
} else {
|
||||
apiDefinition.setUserId(request.getUserId());
|
||||
apiDefinition.setUserId(apiDefinition.getUserId());
|
||||
}
|
||||
apiDefinition.setDescription(request.getDescription());
|
||||
apiDefinition.setDescription(apiDefinition.getDescription());
|
||||
|
||||
List<ApiDefinition> sameRequest = getSameRequest(saveReq);
|
||||
if (StringUtils.equals("fullCoverage", apiTestImportRequest.getModeId())) {
|
||||
_importCreate(sameRequest, batchMapper, apiDefinition, apiTestCaseMapper, apiTestImportRequest);
|
||||
_importCreate(sameRequest, batchMapper, apiDefinition, apiTestCaseMapper, apiTestImportRequest, cases);
|
||||
} else if (StringUtils.equals("incrementalMerge", apiTestImportRequest.getModeId())) {
|
||||
if (CollectionUtils.isEmpty(sameRequest)) {
|
||||
//postman 可能含有前置脚本,接口定义去掉脚本
|
||||
|
@ -325,25 +324,34 @@ public class ApiDefinitionService {
|
|||
importApiCase(apiDefinition, apiTestCaseMapper, apiTestImportRequest, true);
|
||||
}
|
||||
} else {
|
||||
_importCreate(sameRequest, batchMapper, apiDefinition, apiTestCaseMapper, apiTestImportRequest);
|
||||
_importCreate(sameRequest, batchMapper, apiDefinition, apiTestCaseMapper, apiTestImportRequest, cases);
|
||||
}
|
||||
return apiDefinition;
|
||||
}
|
||||
|
||||
private void _importCreate(List<ApiDefinition> sameRequest, ApiDefinitionMapper batchMapper, ApiDefinitionWithBLOBs apiDefinition,
|
||||
ApiTestCaseMapper apiTestCaseMapper, ApiTestImportRequest apiTestImportRequest) {
|
||||
ApiTestCaseMapper apiTestCaseMapper, ApiTestImportRequest apiTestImportRequest, List<ApiTestCaseWithBLOBs> cases) {
|
||||
if (CollectionUtils.isEmpty(sameRequest)) {
|
||||
String request = setImportHashTree(apiDefinition);
|
||||
batchMapper.insert(apiDefinition);
|
||||
apiDefinition.setRequest(request);
|
||||
importApiCase(apiDefinition, apiTestCaseMapper, apiTestImportRequest, true);
|
||||
} else {
|
||||
String originId = apiDefinition.getId();
|
||||
//如果存在则修改
|
||||
apiDefinition.setId(sameRequest.get(0).getId());
|
||||
String request = setImportHashTree(apiDefinition);
|
||||
apiDefinitionMapper.updateByPrimaryKeyWithBLOBs(apiDefinition);
|
||||
apiDefinition.setRequest(request);
|
||||
importApiCase(apiDefinition, apiTestCaseMapper, apiTestImportRequest, false);
|
||||
// 如果是带用例导出,重新设置接口id
|
||||
if (CollectionUtils.isNotEmpty(cases)) {
|
||||
cases.forEach(item -> {
|
||||
if (StringUtils.equals(item.getApiDefinitionId(), originId)) {
|
||||
item.setApiDefinitionId(apiDefinition.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -356,6 +364,26 @@ public class ApiDefinitionService {
|
|||
return request;
|
||||
}
|
||||
|
||||
private void importMsCase(ApiDefinitionImport apiImport, SqlSession sqlSession, ApiTestCaseMapper apiTestCaseMapper) {
|
||||
List<ApiTestCaseWithBLOBs> cases = apiImport.getCases();
|
||||
if (CollectionUtils.isNotEmpty(cases)) {
|
||||
int batchCount = 0;
|
||||
cases.forEach(item -> {
|
||||
item.setId(UUID.randomUUID().toString());
|
||||
item.setCreateTime(System.currentTimeMillis());
|
||||
item.setUpdateTime(System.currentTimeMillis());
|
||||
item.setCreateUserId(SessionUtils.getUserId());
|
||||
item.setUpdateUserId(SessionUtils.getUserId());
|
||||
item.setProjectId(SessionUtils.getCurrentProjectId());
|
||||
item.setNum(getNextNum(item.getApiDefinitionId()));
|
||||
apiTestCaseMapper.insert(item);
|
||||
});
|
||||
if (batchCount % 300 == 0) {
|
||||
sqlSession.flushStatements();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入是插件或者postman时创建用例
|
||||
* postman考虑是否有前置脚本
|
||||
|
@ -372,6 +400,7 @@ public class ApiDefinitionService {
|
|||
apiTestCase.setUpdateTime(System.currentTimeMillis());
|
||||
apiTestCase.setCreateUserId(SessionUtils.getUserId());
|
||||
apiTestCase.setUpdateUserId(SessionUtils.getUserId());
|
||||
apiTestCase.setNum(getNextNum(apiTestCase.getApiDefinitionId()));
|
||||
apiTestCase.setPriority("P0");
|
||||
if (!isInsert) {
|
||||
apiTestCase.setName(apiTestCase.getName() + "_" + apiTestCase.getId().substring(0, 5));
|
||||
|
@ -497,20 +526,21 @@ public class ApiDefinitionService {
|
|||
|
||||
private void importApi(ApiTestImportRequest request, ApiDefinitionImport apiImport) {
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
List<ApiDefinitionWithBLOBs> data = apiImport.getData();
|
||||
ApiDefinitionMapper batchMapper = sqlSession.getMapper(ApiDefinitionMapper.class);
|
||||
ApiTestCaseMapper apiTestCaseMapper = sqlSession.getMapper(ApiTestCaseMapper.class);
|
||||
List<ApiDefinitionResult> data = apiImport.getData();
|
||||
int num = 0;
|
||||
if (!CollectionUtils.isEmpty(data) && data.get(0) != null && data.get(0).getProjectId() != null) {
|
||||
num = getNextNum(data.get(0).getProjectId());
|
||||
}
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
ApiDefinitionResult item = data.get(i);
|
||||
ApiDefinitionWithBLOBs item = data.get(i);
|
||||
if (item.getName().length() > 255) {
|
||||
item.setName(item.getName().substring(0, 255));
|
||||
}
|
||||
item.setNum(num++);
|
||||
importCreate(item, batchMapper, apiTestCaseMapper, request);
|
||||
importCreate(item, batchMapper, apiTestCaseMapper, request, apiImport.getCases());
|
||||
importMsCase(apiImport, sqlSession, apiTestCaseMapper);
|
||||
if (i % 300 == 0) {
|
||||
sqlSession.flushStatements();
|
||||
}
|
||||
|
@ -518,6 +548,7 @@ public class ApiDefinitionService {
|
|||
sqlSession.flushStatements();
|
||||
}
|
||||
|
||||
|
||||
public ReferenceDTO getReference(ApiScenarioRequest request) {
|
||||
ReferenceDTO dto = new ReferenceDTO();
|
||||
dto.setScenarioList(extApiScenarioMapper.selectReference(request));
|
||||
|
@ -539,20 +570,12 @@ public class ApiDefinitionService {
|
|||
}
|
||||
|
||||
public void editApiByParam(ApiBatchRequest request) {
|
||||
List<String> ids = request.getIds();
|
||||
if (request.isSelectAllDate()) {
|
||||
ids = this.getAllApiIdsByFontedSelect(request.getFilters(), request.getName(), request.getModuleIds(), request.getProjectId(), request.getUnSelectIds(),request.getProtocol());
|
||||
}
|
||||
//name在这里只是查询参数
|
||||
request.setName(null);
|
||||
|
||||
ApiDefinitionExample definitionExample = new ApiDefinitionExample();
|
||||
definitionExample.createCriteria().andIdIn(ids);
|
||||
|
||||
ApiDefinitionWithBLOBs definitionWithBLOBs = new ApiDefinitionWithBLOBs();
|
||||
BeanUtils.copyBean(definitionWithBLOBs, request);
|
||||
definitionWithBLOBs.setUpdateTime(System.currentTimeMillis());
|
||||
apiDefinitionMapper.updateByExampleSelective(definitionWithBLOBs, definitionExample);
|
||||
apiDefinitionMapper.updateByExampleSelective(definitionWithBLOBs, getBatchExample(request));
|
||||
}
|
||||
|
||||
public void testPlanRelevance(ApiCaseRelevanceRequest request) {
|
||||
|
@ -602,39 +625,22 @@ public class ApiDefinitionService {
|
|||
return apiDefinitionMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public void deleteByParams(ApiDefinitionBatchProcessingRequest request) {
|
||||
List<String> apiIds = request.getDataIds();
|
||||
if (request.isSelectAllDate()) {
|
||||
apiIds = this.getAllApiIdsByFontedSelect(request.getFilters(), request.getName(), request.getModuleIds(), request.getProjectId(), request.getUnSelectIds(),request.getProtocol());
|
||||
public void deleteByParams(ApiBatchRequest request) {
|
||||
apiDefinitionMapper.deleteByExample(getBatchExample(request));
|
||||
}
|
||||
|
||||
public ApiDefinitionExample getBatchExample(ApiBatchRequest request) {
|
||||
ServiceUtils.getSelectAllIds(request, request.getCondition(),
|
||||
(query) -> extApiDefinitionMapper.selectIds(query));
|
||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
example.createCriteria().andIdIn(apiIds);
|
||||
apiDefinitionMapper.deleteByExample(example);
|
||||
example.createCriteria().andIdIn(request.getIds());
|
||||
return example;
|
||||
}
|
||||
|
||||
private List<String> getAllApiIdsByFontedSelect(Map<String, List<String>> filters, String name, List<String> moduleIds, String projectId, List<String> unSelectIds,String protocol) {
|
||||
ApiDefinitionRequest request = new ApiDefinitionRequest();
|
||||
request.setFilters(filters);
|
||||
request.setName(name);
|
||||
request.setModuleIds(moduleIds);
|
||||
request.setProjectId(projectId);
|
||||
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
|
||||
request.setProtocol(protocol);
|
||||
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());
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
public void removeToGcByParams(ApiDefinitionBatchProcessingRequest request) {
|
||||
List<String> apiIds = request.getDataIds();
|
||||
if (request.isSelectAllDate()) {
|
||||
apiIds = this.getAllApiIdsByFontedSelect(request.getFilters(), request.getName(), request.getModuleIds(), request.getProjectId(), request.getUnSelectIds(),request.getProtocol());
|
||||
}
|
||||
extApiDefinitionMapper.removeToGc(apiIds);
|
||||
public void removeToGcByParams(ApiBatchRequest request) {
|
||||
ServiceUtils.getSelectAllIds(request, request.getCondition(),
|
||||
(query) -> extApiDefinitionMapper.selectIds(query));
|
||||
extApiDefinitionMapper.removeToGc(request.getIds());
|
||||
}
|
||||
|
||||
public List<ApiDefinitionResult> listRelevance(ApiDefinitionRequest request) {
|
||||
|
@ -732,4 +738,17 @@ public class ApiDefinitionService {
|
|||
private void addOrUpdateSwaggerImportCronJob(Schedule request) {
|
||||
scheduleService.addOrUpdateCronJob(request, SwaggerUrlImportJob.getJobKey(request.getResourceId()), SwaggerUrlImportJob.getTriggerKey(request.getResourceId()), SwaggerUrlImportJob.class);
|
||||
}
|
||||
|
||||
public ApiExportResult export(ApiBatchRequest request) {
|
||||
ServiceUtils.getSelectAllIds(request, request.getCondition(),
|
||||
(query) -> extApiDefinitionMapper.selectIds(query));
|
||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
example.createCriteria().andIdIn(request.getIds());
|
||||
ApiExportResult apiExportResult = new ApiExportResult();
|
||||
apiExportResult.setData(apiDefinitionMapper.selectByExampleWithBLOBs(example));
|
||||
apiExportResult.setCases(apiTestCaseService.selectCasesBydApiIds(request.getIds()));
|
||||
apiExportResult.setProjectName(request.getProjectId());
|
||||
apiExportResult.setProtocol(request.getProtocol());
|
||||
return apiExportResult;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -386,6 +386,12 @@ public class ApiTestCaseService {
|
|||
return apiTestCaseMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public List<ApiTestCaseWithBLOBs> selectCasesBydApiIds(List<String> apiIds) {
|
||||
ApiTestCaseExample example = new ApiTestCaseExample();
|
||||
example.createCriteria().andApiDefinitionIdIn(apiIds);
|
||||
return apiTestCaseMapper.selectByExampleWithBLOBs(example);
|
||||
}
|
||||
|
||||
public Map<String, String> getRequest(ApiTestCaseRequest request) {
|
||||
List<ApiTestCaseWithBLOBs> list = extApiTestCaseMapper.getRequest(request);
|
||||
return list.stream().collect(Collectors.toMap(ApiTestCaseWithBLOBs::getId, ApiTestCaseWithBLOBs::getRequest));
|
||||
|
|
|
@ -7,7 +7,7 @@ import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
|||
import io.metersphere.api.dto.definition.ApiSwaggerUrlDTO;
|
||||
import io.metersphere.base.domain.ApiDefinition;
|
||||
import io.metersphere.base.domain.ApiDefinitionExample;
|
||||
import io.metersphere.base.domain.ApiModuleExample;
|
||||
import io.metersphere.controller.request.BaseQueryRequest;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -36,4 +36,6 @@ public interface ExtApiDefinitionMapper {
|
|||
ApiDefinition getNextNum(@Param("projectId") String projectId);
|
||||
|
||||
List<ApiDefinitionResult> listRelevance(@Param("request")ApiDefinitionRequest request);
|
||||
|
||||
List<String> selectIds(@Param("request") BaseQueryRequest query);
|
||||
}
|
|
@ -210,85 +210,7 @@
|
|||
from api_definition
|
||||
left join project on api_definition.project_id = project.id
|
||||
left join user on api_definition.user_id = user.id
|
||||
<where>
|
||||
<if test="request.combine != null">
|
||||
<include refid="combine">
|
||||
<property name="condition" value="request.combine"/>
|
||||
<property name="name" value="request.name"/>
|
||||
</include>
|
||||
</if>
|
||||
<if test="request.name != null">
|
||||
and (api_definition.name like CONCAT('%', #{request.name},'%')
|
||||
or api_definition.tags like CONCAT('%', #{request.name},'%')
|
||||
or api_definition.num like CONCAT('%', #{request.name},'%'))
|
||||
</if>
|
||||
<if test="request.protocol != null">
|
||||
AND api_definition.protocol = #{request.protocol}
|
||||
</if>
|
||||
<if test="request.workspaceId != null">
|
||||
AND project.workspace_id = #{request.workspaceId}
|
||||
</if>
|
||||
<if test="request.projectId != null">
|
||||
AND project.id = #{request.projectId}
|
||||
</if>
|
||||
<if test="request.id != null">
|
||||
AND api_definition.id = #{request.id}
|
||||
</if>
|
||||
<if test="request.userId != null">
|
||||
AND api_definition.user_id = #{request.userId}
|
||||
</if>
|
||||
<if test="request.createTime >0">
|
||||
AND api_definition.create_time >= #{request.createTime}
|
||||
</if>
|
||||
<if test="request.moduleId != null">
|
||||
AND api_definition.module_id = #{request.moduleId}
|
||||
</if>
|
||||
<if test="request.projectId != null">
|
||||
AND api_definition.project_id = #{request.projectId}
|
||||
</if>
|
||||
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
|
||||
AND api_definition.module_id in
|
||||
<foreach collection="request.moduleIds" item="nodeId" separator="," open="(" close=")">
|
||||
#{nodeId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="request.filters != null and request.filters.size() > 0">
|
||||
<foreach collection="request.filters.entrySet()" index="key" item="values">
|
||||
<if test="values != null and values.size() > 0">
|
||||
<choose>
|
||||
<when test="key=='status'">
|
||||
and api_definition.status in
|
||||
<foreach collection="values" item="value" separator="," open="(" close=")">
|
||||
#{value}
|
||||
</foreach>
|
||||
</when>
|
||||
<when test="key=='method'">
|
||||
and api_definition.method in
|
||||
<foreach collection="values" item="value" separator="," open="(" close=")">
|
||||
#{value}
|
||||
</foreach>
|
||||
</when>
|
||||
<when test="key=='user_id'">
|
||||
and api_definition.user_id in
|
||||
<foreach collection="values" item="value" separator="," open="(" close=")">
|
||||
#{value}
|
||||
</foreach>
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="request.apiCaseCoverage == 'uncoverage' ">
|
||||
and api_definition.id not in
|
||||
(SELECT api_definition_id FROM api_test_case)
|
||||
</if>
|
||||
<if test="request.apiCaseCoverage == 'coverage' ">
|
||||
and api_definition.id in
|
||||
(SELECT api_definition_id FROM api_test_case)
|
||||
</if>
|
||||
|
||||
|
||||
</where>
|
||||
<include refid="queryWhereCondition"/>
|
||||
<if test="request.orders != null and request.orders.size() > 0">
|
||||
order by
|
||||
<foreach collection="request.orders" separator="," item="order">
|
||||
|
@ -446,4 +368,93 @@
|
|||
WHERE sch.`enable` = true
|
||||
AND apiScene.project_id = #{0,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<select id="selectIds" resultType="java.lang.String">
|
||||
select api_definition.id
|
||||
from api_definition
|
||||
left join project on api_definition.project_id = project.id
|
||||
<include refid="queryWhereCondition"/>
|
||||
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>
|
||||
</select>
|
||||
|
||||
<sql id="queryWhereCondition">
|
||||
<where>
|
||||
<if test="request.combine != null">
|
||||
<include refid="combine">
|
||||
<property name="condition" value="request.combine"/>
|
||||
<property name="name" value="request.name"/>
|
||||
</include>
|
||||
</if>
|
||||
<if test="request.name != null">
|
||||
and (api_definition.name like CONCAT('%', #{request.name},'%')
|
||||
or api_definition.tags like CONCAT('%', #{request.name},'%')
|
||||
or api_definition.num like CONCAT('%', #{request.name},'%'))
|
||||
</if>
|
||||
<if test="request.protocol != null">
|
||||
AND api_definition.protocol = #{request.protocol}
|
||||
</if>
|
||||
<if test="request.workspaceId != null">
|
||||
AND project.workspace_id = #{request.workspaceId}
|
||||
</if>
|
||||
<if test="request.projectId != null">
|
||||
AND project.id = #{request.projectId}
|
||||
</if>
|
||||
<if test="request.id != null">
|
||||
AND api_definition.id = #{request.id}
|
||||
</if>
|
||||
<if test="request.userId != null">
|
||||
AND api_definition.user_id = #{request.userId}
|
||||
</if>
|
||||
<if test="request.createTime >0">
|
||||
AND api_definition.create_time >= #{request.createTime}
|
||||
</if>
|
||||
<if test="request.moduleId != null">
|
||||
AND api_definition.module_id = #{request.moduleId}
|
||||
</if>
|
||||
<if test="request.projectId != null">
|
||||
AND api_definition.project_id = #{request.projectId}
|
||||
</if>
|
||||
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
|
||||
AND api_definition.module_id in
|
||||
<foreach collection="request.moduleIds" item="nodeId" separator="," open="(" close=")">
|
||||
#{nodeId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="request.filters != null and request.filters.size() > 0">
|
||||
<foreach collection="request.filters.entrySet()" index="key" item="values">
|
||||
<if test="values != null and values.size() > 0">
|
||||
<choose>
|
||||
<when test="key=='status'">
|
||||
and api_definition.status in
|
||||
<foreach collection="values" item="value" separator="," open="(" close=")">
|
||||
#{value}
|
||||
</foreach>
|
||||
</when>
|
||||
<when test="key=='method'">
|
||||
and api_definition.method in
|
||||
<foreach collection="values" item="value" separator="," open="(" close=")">
|
||||
#{value}
|
||||
</foreach>
|
||||
</when>
|
||||
<when test="key=='user_id'">
|
||||
and api_definition.user_id in
|
||||
<foreach collection="values" item="value" separator="," open="(" close=")">
|
||||
#{value}
|
||||
</foreach>
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="request.apiCaseCoverage == 'uncoverage' ">
|
||||
and api_definition.id not in
|
||||
(SELECT api_definition_id FROM api_test_case)
|
||||
</if>
|
||||
<if test="request.apiCaseCoverage == 'coverage' ">
|
||||
and api_definition.id in
|
||||
(SELECT api_definition_id FROM api_test_case)
|
||||
</if>
|
||||
|
||||
|
||||
</where>
|
||||
</sql>
|
||||
</mapper>
|
|
@ -1,8 +1,11 @@
|
|||
package io.metersphere.commons.utils;
|
||||
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.controller.request.BaseQueryRequest;
|
||||
import io.metersphere.controller.request.OrderRequest;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
@ -28,7 +31,7 @@ public class ServiceUtils {
|
|||
* @param func 查询id列表的数据库查询
|
||||
* @return
|
||||
*/
|
||||
public static void getSelectAllIds(BaseQueryRequest queryRequest, Function<BaseQueryRequest, List<String>> func) {
|
||||
public static<T> void getSelectAllIds( T batchRequest, BaseQueryRequest queryRequest, Function<BaseQueryRequest, List<String>> func) {
|
||||
if (queryRequest.isSelectAll()) {
|
||||
List<String> ids = func.apply(queryRequest);
|
||||
if (!ids.isEmpty()) {
|
||||
|
@ -37,6 +40,13 @@ public class ServiceUtils {
|
|||
.collect(Collectors.toList());
|
||||
}
|
||||
queryRequest.setIds(ids);
|
||||
try {
|
||||
Method setIds = batchRequest.getClass().getDeclaredMethod("setIds", List.class);
|
||||
setIds.invoke(batchRequest, ids);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
MSException.throwException("请求没有setIds方法");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,15 @@ public class BaseQueryRequest {
|
|||
|
||||
private List<String> nodeIds;
|
||||
|
||||
/**
|
||||
* selectAll:选择的数据是否是全部数据(全部数据是不受分页影响的数据)
|
||||
* filters: 数据状态
|
||||
* name:如果是全部数据,那么表格如果历经查询,查询参数是什么
|
||||
* moduleIds: 哪些模块的数据
|
||||
* unSelectIds:是否在页面上有未勾选的数据,有的话他们的ID是哪些。
|
||||
* filters/name/moduleIds/unSeelctIds 只在isSelectAllDate为true时需要。为了让程序能明确批量的范围。
|
||||
*/
|
||||
|
||||
/**
|
||||
* 是否选中所有数据
|
||||
*/
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package io.metersphere.track.controller;
|
||||
|
||||
import io.metersphere.base.domain.Issues;
|
||||
import io.metersphere.track.issue.PlatformUser;
|
||||
import io.metersphere.track.issue.ZentaoBuild;
|
||||
import io.metersphere.track.issue.domain.PlatformUser;
|
||||
import io.metersphere.track.issue.domain.ZentaoBuild;
|
||||
import io.metersphere.track.service.IssuesService;
|
||||
import io.metersphere.track.request.testcase.IssuesRequest;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.metersphere.track.issue;
|
||||
|
||||
import io.metersphere.base.domain.Issues;
|
||||
import io.metersphere.track.issue.domain.PlatformUser;
|
||||
import io.metersphere.track.request.testcase.IssuesRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
|
|
@ -7,6 +7,7 @@ import io.metersphere.commons.constants.IssuesManagePlatform;
|
|||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.EncryptUtils;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.track.issue.domain.PlatformUser;
|
||||
import io.metersphere.track.request.testcase.IssuesRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.commonmark.node.Node;
|
||||
|
|
|
@ -5,6 +5,7 @@ import io.metersphere.base.domain.TestCaseIssues;
|
|||
import io.metersphere.commons.constants.IssuesManagePlatform;
|
||||
import io.metersphere.commons.user.SessionUser;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.track.issue.domain.PlatformUser;
|
||||
import io.metersphere.track.request.testcase.IssuesRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
|
|
@ -7,9 +7,9 @@ import io.metersphere.base.domain.*;
|
|||
import io.metersphere.commons.constants.IssuesManagePlatform;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.commons.utils.RestTemplateUtils;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.controller.ResultHolder;
|
||||
import io.metersphere.track.issue.domain.PlatformUser;
|
||||
import io.metersphere.track.request.testcase.IssuesRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.HttpEntity;
|
||||
|
@ -194,9 +194,9 @@ public class TapdPlatform extends AbstractIssuePlatform {
|
|||
HttpHeaders header = auth(account, password);
|
||||
|
||||
if (httpMethod.equals(HttpMethod.GET)) {
|
||||
responseJson = RestTemplateUtils.get(url, header);
|
||||
responseJson = TapdRestUtils.get(url, header);
|
||||
} else {
|
||||
responseJson = RestTemplateUtils.post(url, params, header);
|
||||
responseJson = TapdRestUtils.post(url, params, header);
|
||||
}
|
||||
|
||||
ResultHolder result = JSON.parseObject(responseJson, ResultHolder.class);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package io.metersphere.commons.utils;
|
||||
package io.metersphere.track.issue;
|
||||
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
@ -8,7 +10,7 @@ import org.springframework.http.ResponseEntity;
|
|||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
public class RestTemplateUtils {
|
||||
public class TapdRestUtils {
|
||||
|
||||
private static RestTemplate restTemplate;
|
||||
|
|
@ -7,6 +7,8 @@ import io.metersphere.base.domain.*;
|
|||
import io.metersphere.commons.constants.IssuesManagePlatform;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.track.issue.domain.PlatformUser;
|
||||
import io.metersphere.track.issue.domain.ZentaoBuild;
|
||||
import io.metersphere.track.request.testcase.IssuesRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.HttpEntity;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.track.issue;
|
||||
package io.metersphere.track.issue.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.track.domain;
|
||||
package io.metersphere.track.issue.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.track.issue;
|
||||
package io.metersphere.track.issue.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package io.metersphere.track.request.testcase;
|
||||
|
||||
import io.metersphere.base.domain.TestCaseWithBLOBs;
|
||||
import io.metersphere.controller.request.BaseQueryRequest;
|
||||
import io.metersphere.controller.request.OrderRequest;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
@ -15,5 +14,5 @@ public class TestCaseBatchRequest extends TestCaseWithBLOBs {
|
|||
private List<OrderRequest> orders;
|
||||
private String projectId;
|
||||
|
||||
private BaseQueryRequest condition;
|
||||
private QueryTestCaseRequest condition;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ import io.metersphere.notice.service.NoticeSendService;
|
|||
import io.metersphere.service.IntegrationService;
|
||||
import io.metersphere.service.ProjectService;
|
||||
import io.metersphere.track.issue.*;
|
||||
import io.metersphere.track.issue.domain.PlatformUser;
|
||||
import io.metersphere.track.issue.domain.ZentaoBuild;
|
||||
import io.metersphere.track.request.testcase.IssuesRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.alibaba.excel.EasyExcelFactory;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.api.dto.definition.ApiBatchRequest;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.*;
|
||||
import io.metersphere.base.mapper.ext.ExtTestCaseMapper;
|
||||
|
@ -528,33 +529,25 @@ public class TestCaseService {
|
|||
|
||||
|
||||
public void editTestCaseBath(TestCaseBatchRequest request) {
|
||||
getSelectAllIds(request);
|
||||
TestCaseExample testCaseExample = new TestCaseExample();
|
||||
testCaseExample.createCriteria().andIdIn(request.getIds());
|
||||
|
||||
TestCaseExample example = this.getBatchExample(request);
|
||||
TestCaseWithBLOBs testCase = new TestCaseWithBLOBs();
|
||||
BeanUtils.copyBean(testCase, request);
|
||||
testCase.setUpdateTime(System.currentTimeMillis());
|
||||
testCaseMapper.updateByExampleSelective(
|
||||
testCase,
|
||||
testCaseExample);
|
||||
|
||||
testCaseMapper.updateByExampleSelective(testCase, example);
|
||||
}
|
||||
|
||||
public void deleteTestCaseBath(TestCaseBatchRequest request) {
|
||||
getSelectAllIds(request);
|
||||
TestCaseExample example = this.getBatchExample(request);
|
||||
deleteTestPlanTestCaseBath(request.getIds());
|
||||
TestCaseExample example = new TestCaseExample();
|
||||
example.createCriteria().andIdIn(request.getIds());
|
||||
testCaseMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
public void getSelectAllIds(TestCaseBatchRequest request) {
|
||||
if (request.getCondition().isSelectAll()) {
|
||||
ServiceUtils.getSelectAllIds(request.getCondition(),
|
||||
public TestCaseExample getBatchExample(TestCaseBatchRequest request) {
|
||||
ServiceUtils.getSelectAllIds(request, request.getCondition(),
|
||||
(query) -> extTestCaseMapper.selectIds(query));
|
||||
request.setIds(request.getCondition().getIds());
|
||||
}
|
||||
TestCaseExample example = new TestCaseExample();
|
||||
example.createCriteria().andIdIn(request.getIds());
|
||||
return example;
|
||||
}
|
||||
|
||||
public void deleteTestPlanTestCaseBath(List<String> caseIds) {
|
||||
|
|
|
@ -11,18 +11,12 @@
|
|||
@edit="edit"
|
||||
@drag="drag"
|
||||
@remove="remove"
|
||||
@refresh="list"
|
||||
@nodeSelectEvent="nodeChange"
|
||||
ref="nodeTree">
|
||||
|
||||
<template v-slot:header>
|
||||
<!--<el-input :placeholder="$t('test_track.module.search')" v-model="condition.filterText" size="small">-->
|
||||
<!--<template v-slot:append>-->
|
||||
<!--<el-button v-if="!isReadOnly" icon="el-icon-folder-add" @click="addScenario" v-tester/>-->
|
||||
<!--</template>-->
|
||||
<!--</el-input>-->
|
||||
|
||||
<el-input class="filter-input" :class="{'read-only': isReadOnly}" :placeholder="$t('test_track.module.search')" v-model="condition.filterText"
|
||||
size="small">
|
||||
<el-input :placeholder="$t('test_track.module.search')" v-model="condition.filterText" size="small">
|
||||
<template v-slot:append>
|
||||
<el-dropdown v-if="!isReadOnly" size="small" split-button type="primary" class="ms-api-button" @click="handleCommand('add-api')"
|
||||
v-tester
|
||||
|
@ -36,7 +30,6 @@
|
|||
</el-dropdown>
|
||||
</template>
|
||||
</el-input>
|
||||
|
||||
<module-trash-button v-if="!isReadOnly" :condition="condition" :exe="enableTrash"/>
|
||||
</template>
|
||||
|
||||
|
@ -49,9 +42,16 @@
|
|||
|
||||
<api-import ref="apiImport" :moduleOptions="moduleOptions" @refresh="$emit('refresh')"/>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import SelectMenu from "../../../track/common/SelectMenu";
|
||||
import MsAddBasisScenario from "@/business/components/api/automation/scenario/AddBasisScenario";
|
||||
import {getCurrentProjectID} from "@/common/js/utils";
|
||||
import MsNodeTree from "../../../track/common/NodeTree";
|
||||
import {buildNodePath} from "../../definition/model/NodeTree";
|
||||
import ModuleTrashButton from "../../definition/components/module/ModuleTrashButton";
|
||||
import SelectMenu from "../../../track/common/SelectMenu";
|
||||
import MsAddBasisScenario from "@/business/components/api/automation/scenario/AddBasisScenario";
|
||||
import {getCurrentProjectID} from "@/common/js/utils";
|
||||
|
|
|
@ -128,10 +128,9 @@
|
|||
import MsRunTestTcpPage from "./components/runtest/RunTestTCPPage";
|
||||
import MsRunTestSqlPage from "./components/runtest/RunTestSQLPage";
|
||||
import MsRunTestDubboPage from "./components/runtest/RunTestDubboPage";
|
||||
import {downloadFile, getCurrentUser, getUUID, getCurrentProjectID} from "@/common/js/utils";
|
||||
import {getCurrentProjectID, getCurrentUser, getUUID} from "@/common/js/utils";
|
||||
import MsApiModule from "./components/module/ApiModule";
|
||||
import ApiCaseSimpleList from "./components/list/ApiCaseSimpleList";
|
||||
import {PROJECT_NAME} from "../../../../common/js/constants";
|
||||
|
||||
export default {
|
||||
name: "ApiDefinition",
|
||||
|
@ -340,36 +339,7 @@
|
|||
this.$warning('用例列表暂不支持导出,请切换成接口列表');
|
||||
return;
|
||||
}
|
||||
let obj = {projectName: this.projectId, protocol: this.currentProtocol}
|
||||
if (this.$refs.apiList[0].selectRows && this.$refs.apiList[0].selectRows.size > 0) {
|
||||
let arr = Array.from(this.$refs.apiList[0].selectRows);
|
||||
obj.data = arr;
|
||||
this.buildApiPath(obj.data);
|
||||
downloadFile("Metersphere_Api_" + localStorage.getItem(PROJECT_NAME) + ".json", JSON.stringify(obj));
|
||||
} else {
|
||||
let condition = {};
|
||||
let url = "/api/definition/list/all";
|
||||
condition.filters = new Map(
|
||||
[
|
||||
["status", ["Prepare", "Underway", "Completed"]],
|
||||
]
|
||||
);
|
||||
condition.projectId = this.projectId;
|
||||
this.$post(url, condition, response => {
|
||||
obj.data = response.data;
|
||||
this.buildApiPath(obj.data);
|
||||
downloadFile("Metersphere_Api_" + localStorage.getItem(PROJECT_NAME) + ".json", JSON.stringify(obj));
|
||||
});
|
||||
}
|
||||
},
|
||||
buildApiPath(apis) {
|
||||
apis.forEach((api) => {
|
||||
this.moduleOptions.forEach(item => {
|
||||
if (api.moduleId === item.id) {
|
||||
api.modulePath = item.path;
|
||||
}
|
||||
});
|
||||
});
|
||||
this.$refs.apiList[0].exportApi();
|
||||
},
|
||||
refresh(data) {
|
||||
this.$refs.apiList[0].initTable(data);
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
import MsEditCompleteDubboApi from "./complete/EditCompleteDubboApi";
|
||||
import MsEditCompleteSqlApi from "./complete/EditCompleteSQLApi";
|
||||
|
||||
import {ResponseFactory, Body} from "../model/ApiTestModel";
|
||||
import {getUUID, getCurrentProjectID} from "@/common/js/utils";
|
||||
import {Body} from "../model/ApiTestModel";
|
||||
import {getUUID} from "@/common/js/utils";
|
||||
import {createComponent, Request} from "./jmeter/components";
|
||||
import Sampler from "./jmeter/components/sampler/sampler";
|
||||
import {WORKSPACE_ID} from '@/common/js/constants';
|
||||
|
|
|
@ -54,8 +54,7 @@
|
|||
import {CASE_ORDER} from "../../model/JsonData";
|
||||
import {API_CASE_CONFIGS} from "@/business/components/common/components/search/search-components";
|
||||
import MsBatchEdit from "../basis/BatchEdit";
|
||||
// import {CASE_PRIORITY, REQ_METHOD} from "../../model/JsonData";
|
||||
import {CASE_PRIORITY,API_METHOD_COLOUR, API_STATUS, REQ_METHOD, TCP_METHOD, SQL_METHOD, DUBBO_METHOD} from "../../model/JsonData";
|
||||
import {CASE_PRIORITY, REQ_METHOD, TCP_METHOD, SQL_METHOD, DUBBO_METHOD} from "../../model/JsonData";
|
||||
|
||||
export default {
|
||||
name: 'ApiCaseList',
|
||||
|
@ -270,10 +269,13 @@
|
|||
this.singleLoading = true;
|
||||
this.singleRunId = row.id;
|
||||
row.request.name = row.id;
|
||||
this.$get('/api/definition/get/' + row.request.id, response => {
|
||||
row.request.path = response.data.path; // 取的path是对应接口的path,因此查库以获得
|
||||
row.request.useEnvironment = this.environment.id;
|
||||
this.runData.push(row.request);
|
||||
/*触发执行操作*/
|
||||
this.reportId = getUUID().substring(0, 8);
|
||||
});
|
||||
},
|
||||
|
||||
batchRun() {
|
||||
|
|
|
@ -243,7 +243,6 @@ export default {
|
|||
Object.assign(param, this.formData);
|
||||
param.platform = this.selectedPlatformValue;
|
||||
param.saved = this.saved;
|
||||
console.log(this.formData.moduleId)
|
||||
if (this.currentModule) {
|
||||
param.moduleId = this.formData.moduleId
|
||||
this.moduleOptions.filter(item => {
|
||||
|
|
|
@ -188,8 +188,8 @@ import MsBottomContainer from "../BottomContainer";
|
|||
import ShowMoreBtn from "../../../../track/case/components/ShowMoreBtn";
|
||||
import MsBatchEdit from "../basis/BatchEdit";
|
||||
import {API_METHOD_COLOUR, API_STATUS, DUBBO_METHOD, REQ_METHOD, SQL_METHOD, TCP_METHOD} from "../../model/JsonData";
|
||||
import {getCurrentProjectID} from "@/common/js/utils";
|
||||
import {WORKSPACE_ID} from '@/common/js/constants';
|
||||
import {downloadFile, getCurrentProjectID} from "@/common/js/utils";
|
||||
import {PROJECT_NAME, WORKSPACE_ID} from '@/common/js/constants';
|
||||
import ApiListContainer from "./ApiListContainer";
|
||||
import MsTableHeaderSelectPopover from "@/business/components/common/components/table/MsTableHeaderSelectPopover";
|
||||
import ApiStatus from "@/business/components/api/definition/components/list/ApiStatus";
|
||||
|
@ -197,7 +197,14 @@ import MsTableAdvSearchBar from "@/business/components/common/components/search/
|
|||
import {API_DEFINITION_CONFIGS} from "@/business/components/common/components/search/search-components";
|
||||
import MsTipButton from "@/business/components/common/components/MsTipButton";
|
||||
import CaseBatchMove from "@/business/components/api/definition/components/basis/BatchMove";
|
||||
import {_filter, _sort} from "@/common/js/tableUtils";
|
||||
import {
|
||||
_filter,
|
||||
_handleSelect,
|
||||
_handleSelectAll,
|
||||
_sort,
|
||||
getSelectDataCounts, initCondition,
|
||||
setUnSelectIds, toggleAllSelection
|
||||
} from "@/common/js/tableUtils";
|
||||
|
||||
|
||||
export default {
|
||||
|
@ -277,8 +284,6 @@ export default {
|
|||
total: 0,
|
||||
screenHeight: document.documentElement.clientHeight - 270,//屏幕高度,
|
||||
environmentId: undefined,
|
||||
selectAll: false,
|
||||
unSelection: [],
|
||||
selectDataCounts: 0,
|
||||
}
|
||||
},
|
||||
|
@ -352,8 +357,7 @@ export default {
|
|||
},
|
||||
initTable() {
|
||||
this.selectRows = new Set();
|
||||
this.selectAll = false;
|
||||
this.unSelection = [];
|
||||
initCondition(this.condition);
|
||||
this.selectDataCounts = 0;
|
||||
this.condition.moduleIds = this.selectNodeIds;
|
||||
this.condition.projectId = getCurrentProjectID();
|
||||
|
@ -390,7 +394,6 @@ export default {
|
|||
this.genProtocalFilter(this.condition.protocol);
|
||||
this.total = response.data.itemCount;
|
||||
this.tableData = response.data.listObject;
|
||||
this.unSelection = response.data.listObject.map(s => s.id);
|
||||
this.tableData.forEach(item => {
|
||||
if (item.tags && item.tags.length > 0) {
|
||||
item.tags = JSON.parse(item.tags);
|
||||
|
@ -450,45 +453,21 @@ export default {
|
|||
});
|
||||
});
|
||||
},
|
||||
handleSelect(selection, row) {
|
||||
row.hashTree = [];
|
||||
if (this.selectRows.has(row)) {
|
||||
this.$set(row, "showMore", false);
|
||||
this.selectRows.delete(row);
|
||||
} else {
|
||||
this.$set(row, "showMore", true);
|
||||
this.selectRows.add(row);
|
||||
}
|
||||
let arr = Array.from(this.selectRows);
|
||||
// 选中1个以上的用例时显示更多操作
|
||||
if (this.selectRows.size === 1) {
|
||||
this.$set(arr[0], "showMore", true);
|
||||
} else if (this.selectRows.size === 2) {
|
||||
arr.forEach(row => {
|
||||
this.$set(row, "showMore", true);
|
||||
})
|
||||
}
|
||||
this.selectRowsCount(this.selectRows)
|
||||
},
|
||||
handleSelectAll(selection) {
|
||||
if (selection.length > 0) {
|
||||
if (selection.length === 1) {
|
||||
selection.hashTree = [];
|
||||
this.selectRows.add(selection[0]);
|
||||
} else {
|
||||
this.tableData.forEach(item => {
|
||||
item.hashTree = [];
|
||||
this.$set(item, "showMore", true);
|
||||
this.selectRows.add(item);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this.selectRows.clear();
|
||||
this.tableData.forEach(row => {
|
||||
this.$set(row, "showMore", false);
|
||||
})
|
||||
}
|
||||
this.selectRowsCount(this.selectRows)
|
||||
_handleSelectAll(this, selection, this.tableData, this.selectRows);
|
||||
setUnSelectIds(this.tableData, this.condition, this.selectRows);
|
||||
this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows);
|
||||
},
|
||||
handleSelect(selection, row) {
|
||||
_handleSelect(this, selection, row, this.selectRows);
|
||||
setUnSelectIds(this.tableData, this.condition, this.selectRows);
|
||||
this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows);
|
||||
},
|
||||
isSelectDataAll(data) {
|
||||
this.condition.selectAll = data;
|
||||
setUnSelectIds(this.tableData, this.condition, this.selectRows);
|
||||
this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows);
|
||||
toggleAllSelection(this.$refs.apiDefinitionTable, this.tableData, this.selectRows);
|
||||
},
|
||||
search() {
|
||||
this.changeSelectDataRangeAll();
|
||||
|
@ -520,14 +499,7 @@ export default {
|
|||
confirmButtonText: this.$t('commons.confirm'),
|
||||
callback: (action) => {
|
||||
if (action === 'confirm') {
|
||||
let deleteParam = {};
|
||||
let ids = Array.from(this.selectRows).map(row => row.id);
|
||||
deleteParam.dataIds = ids;
|
||||
deleteParam.projectId = getCurrentProjectID();
|
||||
deleteParam.selectAllDate = this.isSelectAllDate;
|
||||
deleteParam.unSelectIds = this.unSelection;
|
||||
deleteParam = Object.assign(deleteParam, this.condition);
|
||||
this.$post('/api/definition/deleteBatchByParams/', deleteParam, () => {
|
||||
this.$post('/api/definition/deleteBatchByParams/', this.buildBatchParam(), () => {
|
||||
this.selectRows.clear();
|
||||
this.initTable();
|
||||
this.$success(this.$t('commons.delete_success'));
|
||||
|
@ -540,14 +512,7 @@ export default {
|
|||
confirmButtonText: this.$t('commons.confirm'),
|
||||
callback: (action) => {
|
||||
if (action === 'confirm') {
|
||||
let ids = Array.from(this.selectRows).map(row => row.id);
|
||||
let deleteParam = {};
|
||||
deleteParam.dataIds = ids;
|
||||
deleteParam.projectId = getCurrentProjectID();
|
||||
deleteParam.selectAllDate = this.isSelectAllDate;
|
||||
deleteParam.unSelectIds = this.unSelection;
|
||||
deleteParam = Object.assign(deleteParam, this.condition);
|
||||
this.$post('/api/definition/removeToGcByParams/', deleteParam, () => {
|
||||
this.$post('/api/definition/removeToGcByParams/', this.buildBatchParam(), () => {
|
||||
this.selectRows.clear();
|
||||
this.initTable();
|
||||
this.$success(this.$t('commons.delete_success'));
|
||||
|
@ -571,31 +536,27 @@ export default {
|
|||
this.$refs.batchEdit.open();
|
||||
},
|
||||
batchEdit(form) {
|
||||
let arr = Array.from(this.selectRows);
|
||||
let ids = arr.map(row => row.id);
|
||||
let param = {};
|
||||
let param = this.buildBatchParam();
|
||||
param[form.type] = form.value;
|
||||
param.ids = ids;
|
||||
|
||||
param.projectId = getCurrentProjectID();
|
||||
param.selectAllDate = this.isSelectAllDate;
|
||||
param.unSelectIds = this.unSelection;
|
||||
param = Object.assign(param, this.condition);
|
||||
|
||||
this.$post('/api/definition/batch/editByParams', param, () => {
|
||||
this.$success(this.$t('commons.save_success'));
|
||||
this.initTable();
|
||||
});
|
||||
},
|
||||
buildBatchParam() {
|
||||
let param = {};
|
||||
param.ids = Array.from(this.selectRows).map(row => row.id);
|
||||
param.projectId = getCurrentProjectID();
|
||||
param.condition = this.condition;
|
||||
return param;
|
||||
},
|
||||
moveSave(param) {
|
||||
let arr = Array.from(this.selectRows);
|
||||
let ids = arr.map(row => row.id);
|
||||
param.ids = ids;
|
||||
param.projectId = getCurrentProjectID();
|
||||
param.selectAllDate = this.isSelectAllDate;
|
||||
param.unSelectIds = this.unSelection;
|
||||
param = Object.assign(param, this.condition);
|
||||
param.moduleId=param.nodeId;
|
||||
param.condition = this.condition;
|
||||
this.$post('/api/definition/batch/editByParams', param, () => {
|
||||
this.$success(this.$t('commons.save_success'));
|
||||
this.$refs.testCaseBatchMove.close();
|
||||
|
@ -646,26 +607,6 @@ export default {
|
|||
showExecResult(row) {
|
||||
this.$emit('showExecResult', row);
|
||||
},
|
||||
selectRowsCount(selection) {
|
||||
let selectedIDs = this.getIds(selection);
|
||||
let allIDs = this.tableData.map(s => s.id);
|
||||
this.unSelection = allIDs.filter(function (val) {
|
||||
return selectedIDs.indexOf(val) === -1
|
||||
});
|
||||
if (this.isSelectAllDate) {
|
||||
this.selectDataCounts = this.total - this.unSelection.length;
|
||||
} else {
|
||||
this.selectDataCounts = selection.size;
|
||||
}
|
||||
},
|
||||
isSelectDataAll(dataType) {
|
||||
this.isSelectAllDate = dataType;
|
||||
this.selectRowsCount(this.selectRows)
|
||||
//如果已经全选,不需要再操作了
|
||||
if (this.selectRows.size != this.tableData.length) {
|
||||
this.$refs.apiDefinitionTable.toggleAllSelection(true);
|
||||
}
|
||||
},
|
||||
//判断是否只显示本周的数据。 从首页跳转过来的请求会带有相关参数
|
||||
getSelectDataRange() {
|
||||
let dataRange = this.$route.params.dataSelectRange;
|
||||
|
@ -684,6 +625,25 @@ export default {
|
|||
let ids = rowArray.map(s => s.id);
|
||||
return ids;
|
||||
},
|
||||
exportApi() {
|
||||
let param = this.buildBatchParam();
|
||||
param.protocol = this.currentProtocol;
|
||||
this.result = this.$post("/api/definition/export", param, response => {
|
||||
let obj = response.data;
|
||||
obj.protocol = this.currentProtocol;
|
||||
this.buildApiPath(obj.data);
|
||||
downloadFile("Metersphere_Api_" + localStorage.getItem(PROJECT_NAME) + ".json", JSON.stringify(obj));
|
||||
});
|
||||
},
|
||||
buildApiPath(apis) {
|
||||
apis.forEach((api) => {
|
||||
this.moduleOptions.forEach(item => {
|
||||
if (api.moduleId === item.id) {
|
||||
api.modulePath = item.path;
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
sort(column) {
|
||||
// 每次只对一个字段排序
|
||||
if (this.condition.orders) {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
@edit="edit"
|
||||
@drag="drag"
|
||||
@remove="remove"
|
||||
@refresh="list"
|
||||
@nodeSelectEvent="nodeChange"
|
||||
ref="nodeTree">
|
||||
|
||||
|
@ -198,6 +199,7 @@
|
|||
},
|
||||
refresh() {
|
||||
this.list();
|
||||
this.$emit('refreshTable');
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import {downloadFile, getUUID} from "@/common/js/utils";
|
||||
import {getUUID, uuid} from "@/common/js/utils";
|
||||
import MsApiCaseList from "../case/ApiCaseList";
|
||||
import MsContainer from "../../../../common/components/MsContainer";
|
||||
import MsBottomContainer from "../BottomContainer";
|
||||
|
@ -161,12 +161,14 @@
|
|||
},
|
||||
saveAsApi() {
|
||||
let data = {};
|
||||
this.api.request.id = uuid();
|
||||
data.request = JSON.stringify(this.api.request);
|
||||
data.method = this.api.method;
|
||||
data.status = this.api.status;
|
||||
data.userId = this.api.userId;
|
||||
data.description = this.api.description;
|
||||
this.$emit('saveAsApi', data);
|
||||
this.$emit('refresh');
|
||||
},
|
||||
updateApi() {
|
||||
let url = "/api/definition/update";
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import {downloadFile, getUUID} from "@/common/js/utils";
|
||||
import {getUUID, uuid} from "@/common/js/utils";
|
||||
import MsApiCaseList from "../case/ApiCaseList";
|
||||
import MsContainer from "../../../../common/components/MsContainer";
|
||||
import MsBottomContainer from "../BottomContainer";
|
||||
|
@ -160,12 +160,14 @@
|
|||
},
|
||||
saveAsApi() {
|
||||
let data = {};
|
||||
this.api.request.id = uuid();
|
||||
data.request = JSON.stringify(this.api.request);
|
||||
data.method = this.api.method;
|
||||
data.status = this.api.status;
|
||||
data.userId = this.api.userId;
|
||||
data.description = this.api.description;
|
||||
this.$emit('saveAsApi', data);
|
||||
this.$emit('refresh');
|
||||
},
|
||||
updateApi() {
|
||||
let url = "/api/definition/update";
|
||||
|
@ -175,7 +177,7 @@
|
|||
if (this.syncTabs.indexOf(this.api.id) === -1) {
|
||||
this.syncTabs.push(this.api.id);
|
||||
}
|
||||
this.$emit('saveApi', this.api);
|
||||
this.$emit('refresh');
|
||||
});
|
||||
},
|
||||
selectTestCase(item) {
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
|
||||
<script>
|
||||
import MsApiRequestForm from "../request/http/ApiHttpRequestForm";
|
||||
import {downloadFile, getUUID, getCurrentProjectID} from "@/common/js/utils";
|
||||
import {getUUID, uuid} from "@/common/js/utils";
|
||||
import MsApiCaseList from "../case/ApiCaseList";
|
||||
import MsContainer from "../../../../common/components/MsContainer";
|
||||
import MsBottomContainer from "../BottomContainer";
|
||||
|
@ -173,12 +173,14 @@
|
|||
},
|
||||
saveAsApi() {
|
||||
let data = {};
|
||||
this.api.request.id = uuid();
|
||||
data.request = JSON.stringify(this.api.request);
|
||||
data.method = this.api.method;
|
||||
data.status = this.api.status;
|
||||
data.userId = this.api.userId;
|
||||
data.description = this.api.description;
|
||||
this.$emit('saveAsApi', data);
|
||||
this.$emit('refresh');
|
||||
},
|
||||
updateApi() {
|
||||
let url = "/api/definition/update";
|
||||
|
|
|
@ -202,7 +202,7 @@ import {
|
|||
_handleSelect,
|
||||
_handleSelectAll,
|
||||
_sort,
|
||||
getSelectDataCounts,
|
||||
getSelectDataCounts, initCondition,
|
||||
setUnSelectIds,
|
||||
toggleAllSelection
|
||||
} from "@/common/js/tableUtils";
|
||||
|
@ -335,8 +335,7 @@ export default {
|
|||
this.projectId = getCurrentProjectID();
|
||||
this.condition.planId = "";
|
||||
this.condition.nodeIds = [];
|
||||
this.condition.selectAll = false;
|
||||
this.condition.unSelectIds = [];
|
||||
initCondition(this.condition);
|
||||
this.selectDataCounts = 0;
|
||||
if (this.planId) {
|
||||
// param.planId = this.planId;
|
||||
|
|
|
@ -220,6 +220,10 @@ export default {
|
|||
if (dropType === "none" || dropType === undefined) {
|
||||
return;
|
||||
}
|
||||
if (dropNode.data.id === 'root' && dropType === 'before') {
|
||||
this.$emit('refresh');
|
||||
return false;
|
||||
}
|
||||
let param = this.buildParam(draggingNode, dropNode, dropType);
|
||||
let list = [];
|
||||
this.getNodeTree(this.treeNodes, draggingNode.data.id, list);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
@drag="drag"
|
||||
@remove="remove"
|
||||
@nodeSelectEvent="nodeChange"
|
||||
@refresh="list"
|
||||
ref="nodeTree"/>
|
||||
</template>
|
||||
|
||||
|
|
|
@ -101,6 +101,11 @@ export function _sort(column, condition) {
|
|||
}
|
||||
}
|
||||
|
||||
export function initCondition(condition) {
|
||||
condition.selectAll = false;
|
||||
condition.unSelectIds = [];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue