fix: 非http接口导入报错 (#6371)
Co-authored-by: chenjianxing <jianxing.chen@fit2cloud.com>
This commit is contained in:
parent
49c1bd8816
commit
c33863e021
|
@ -346,6 +346,7 @@ public class ApiDefinitionService {
|
||||||
|
|
||||||
private List<ApiDefinition> getSameRequestWithName(SaveApiDefinitionRequest request) {
|
private List<ApiDefinition> getSameRequestWithName(SaveApiDefinitionRequest request) {
|
||||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||||
|
if (request.getProtocol().equals(RequestType.HTTP)) {
|
||||||
example.createCriteria()
|
example.createCriteria()
|
||||||
.andMethodEqualTo(request.getMethod())
|
.andMethodEqualTo(request.getMethod())
|
||||||
.andStatusNotEqualTo("Trash")
|
.andStatusNotEqualTo("Trash")
|
||||||
|
@ -353,6 +354,14 @@ public class ApiDefinitionService {
|
||||||
.andNameEqualTo(request.getName())
|
.andNameEqualTo(request.getName())
|
||||||
.andProjectIdEqualTo(request.getProjectId())
|
.andProjectIdEqualTo(request.getProjectId())
|
||||||
.andIdNotEqualTo(request.getId());
|
.andIdNotEqualTo(request.getId());
|
||||||
|
} else {
|
||||||
|
example.createCriteria()
|
||||||
|
.andStatusNotEqualTo("Trash")
|
||||||
|
.andNameEqualTo(request.getName())
|
||||||
|
.andProjectIdEqualTo(request.getProjectId())
|
||||||
|
.andIdNotEqualTo(request.getId());
|
||||||
|
}
|
||||||
|
|
||||||
return apiDefinitionMapper.selectByExample(example);
|
return apiDefinitionMapper.selectByExample(example);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -489,9 +498,12 @@ public class ApiDefinitionService {
|
||||||
} else if (StringUtils.equals("incrementalMerge", apiTestImportRequest.getModeId())) {
|
} else if (StringUtils.equals("incrementalMerge", apiTestImportRequest.getModeId())) {
|
||||||
if (CollectionUtils.isEmpty(sameRequest)) {
|
if (CollectionUtils.isEmpty(sameRequest)) {
|
||||||
//postman 可能含有前置脚本,接口定义去掉脚本
|
//postman 可能含有前置脚本,接口定义去掉脚本
|
||||||
String requestStr = setImportHashTree(apiDefinition);
|
|
||||||
apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId()));
|
apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId()));
|
||||||
batchMapper.insert(apiDefinition);
|
batchMapper.insert(apiDefinition);
|
||||||
|
String originId = apiDefinition.getId();
|
||||||
|
apiDefinition.setId(UUID.randomUUID().toString());
|
||||||
|
String requestStr = setImportHashTree(apiDefinition);
|
||||||
|
reSetImportCasesApiId(cases, originId, apiDefinition.getId());
|
||||||
apiDefinition.setRequest(requestStr);
|
apiDefinition.setRequest(requestStr);
|
||||||
importApiCase(apiDefinition, apiTestCaseMapper, apiTestImportRequest, true);
|
importApiCase(apiDefinition, apiTestCaseMapper, apiTestImportRequest, true);
|
||||||
}
|
}
|
||||||
|
@ -526,19 +538,18 @@ public class ApiDefinitionService {
|
||||||
ApiTestCaseMapper apiTestCaseMapper, ApiTestImportRequest apiTestImportRequest, List<ApiTestCaseWithBLOBs> cases) {
|
ApiTestCaseMapper apiTestCaseMapper, ApiTestImportRequest apiTestImportRequest, List<ApiTestCaseWithBLOBs> cases) {
|
||||||
String originId = apiDefinition.getId();
|
String originId = apiDefinition.getId();
|
||||||
if (CollectionUtils.isEmpty(sameRequest)) {
|
if (CollectionUtils.isEmpty(sameRequest)) {
|
||||||
if (StringUtils.equalsIgnoreCase(apiDefinition.getProtocol(), RequestType.HTTP)) {
|
|
||||||
String request = setImportHashTree(apiDefinition);
|
|
||||||
apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId()));
|
|
||||||
apiDefinition.setId(UUID.randomUUID().toString());
|
apiDefinition.setId(UUID.randomUUID().toString());
|
||||||
|
apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId()));
|
||||||
reSetImportCasesApiId(cases, originId, apiDefinition.getId());
|
reSetImportCasesApiId(cases, originId, apiDefinition.getId());
|
||||||
|
if (StringUtils.equalsIgnoreCase(apiDefinition.getProtocol(), RequestType.HTTP)) {
|
||||||
batchMapper.insert(apiDefinition);
|
batchMapper.insert(apiDefinition);
|
||||||
|
String request = setImportHashTree(apiDefinition);
|
||||||
apiDefinition.setRequest(request);
|
apiDefinition.setRequest(request);
|
||||||
importApiCase(apiDefinition, apiTestCaseMapper, apiTestImportRequest, true);
|
importApiCase(apiDefinition, apiTestCaseMapper, apiTestImportRequest, true);
|
||||||
} else {
|
} else {
|
||||||
if (StringUtils.equalsAnyIgnoreCase(apiDefinition.getProtocol(), RequestType.TCP)) {
|
if (StringUtils.equalsAnyIgnoreCase(apiDefinition.getProtocol(), RequestType.TCP)) {
|
||||||
setImportTCPHashTree(apiDefinition);
|
setImportTCPHashTree(apiDefinition);
|
||||||
}
|
}
|
||||||
apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId()));
|
|
||||||
batchMapper.insert(apiDefinition);
|
batchMapper.insert(apiDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -649,7 +660,10 @@ public class ApiDefinitionService {
|
||||||
checkRequest.setName(apiTestCase.getName());
|
checkRequest.setName(apiTestCase.getName());
|
||||||
checkRequest.setApiDefinitionId(apiTestCase.getApiDefinitionId());
|
checkRequest.setApiDefinitionId(apiTestCase.getApiDefinitionId());
|
||||||
checkRequest.setId(apiTestCase.getId());
|
checkRequest.setId(apiTestCase.getId());
|
||||||
ApiTestCase sameCase = apiTestCaseService.getImportSameCase(checkRequest);
|
ApiTestCase sameCase = apiTestCaseService.getSameCase(checkRequest);
|
||||||
|
if (sameCase == null) {
|
||||||
|
sameCase = apiTestCaseService.getSameCaseById(checkRequest);
|
||||||
|
}
|
||||||
apiTestCase.setUpdateUserId(SessionUtils.getUserId());
|
apiTestCase.setUpdateUserId(SessionUtils.getUserId());
|
||||||
if (sameCase == null) {
|
if (sameCase == null) {
|
||||||
apiTestCase.setId(UUID.randomUUID().toString());
|
apiTestCase.setId(UUID.randomUUID().toString());
|
||||||
|
|
|
@ -279,6 +279,19 @@ public class ApiTestCaseService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkNameExist(SaveApiTestCaseRequest request) {
|
public void checkNameExist(SaveApiTestCaseRequest request) {
|
||||||
|
if (hasSameCase(request)) {
|
||||||
|
MSException.throwException(Translator.get("load_test_already_exists"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean hasSameCase(SaveApiTestCaseRequest request) {
|
||||||
|
if (getSameCase(request) != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApiTestCase getSameCase(SaveApiTestCaseRequest request) {
|
||||||
ApiTestCaseExample example = new ApiTestCaseExample();
|
ApiTestCaseExample example = new ApiTestCaseExample();
|
||||||
ApiTestCaseExample.Criteria criteria = example.createCriteria();
|
ApiTestCaseExample.Criteria criteria = example.createCriteria();
|
||||||
criteria.andStatusNotEqualTo("Trash").andNameEqualTo(request.getName()).andApiDefinitionIdEqualTo(request.getApiDefinitionId());
|
criteria.andStatusNotEqualTo("Trash").andNameEqualTo(request.getName()).andApiDefinitionIdEqualTo(request.getApiDefinitionId());
|
||||||
|
@ -287,14 +300,24 @@ public class ApiTestCaseService {
|
||||||
}
|
}
|
||||||
List<ApiTestCase> apiTestCases = apiTestCaseMapper.selectByExample(example);
|
List<ApiTestCase> apiTestCases = apiTestCaseMapper.selectByExample(example);
|
||||||
if (CollectionUtils.isNotEmpty(apiTestCases)) {
|
if (CollectionUtils.isNotEmpty(apiTestCases)) {
|
||||||
if (apiTestCases.get(0) != null) {
|
return apiTestCases.get(0);
|
||||||
MSException.throwException(Translator.get("load_test_already_exists"));
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiTestCase getImportSameCase(SaveApiTestCaseRequest request) {
|
public ApiTestCase getSameCaseById(SaveApiTestCaseRequest request) {
|
||||||
return extApiTestCaseMapper.selectSameCase(request);
|
if (StringUtils.isNotBlank(request.getId())) {
|
||||||
|
ApiTestCaseExample example = new ApiTestCaseExample();
|
||||||
|
ApiTestCaseExample.Criteria criteria = example.createCriteria();
|
||||||
|
criteria.andStatusNotEqualTo("Trash")
|
||||||
|
.andApiDefinitionIdEqualTo(request.getApiDefinitionId());
|
||||||
|
criteria.andIdEqualTo(request.getId());
|
||||||
|
List<ApiTestCase> apiTestCases = apiTestCaseMapper.selectByExample(example);
|
||||||
|
if (CollectionUtils.isNotEmpty(apiTestCases)) {
|
||||||
|
return apiTestCases.get(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApiTestCase updateTest(SaveApiTestCaseRequest request) {
|
private ApiTestCase updateTest(SaveApiTestCaseRequest request) {
|
||||||
|
|
|
@ -57,6 +57,4 @@ public interface ExtApiTestCaseMapper {
|
||||||
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);
|
Long getLastOrder(@Param("projectId")String projectId, @Param("baseOrder") Long baseOrder);
|
||||||
|
|
||||||
ApiTestCase selectSameCase(@Param("request") SaveApiTestCaseRequest request);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -596,20 +596,6 @@
|
||||||
</if>
|
</if>
|
||||||
order by `order` desc limit 1;
|
order by `order` desc limit 1;
|
||||||
</select>
|
</select>
|
||||||
<select id="selectSameCase" resultType="io.metersphere.base.domain.ApiTestCase">
|
|
||||||
select id
|
|
||||||
from api_test_case
|
|
||||||
WHERE
|
|
||||||
api_definition_id = #{request.apiDefinitionId} and (`status` <> 'Trash' or `status` is null)
|
|
||||||
<if test="request.id != null and request.id != ''">
|
|
||||||
and id = #{request.id}
|
|
||||||
</if>
|
|
||||||
<if test="request.id == null or request.id == ''">
|
|
||||||
and name = #{request.name}
|
|
||||||
</if>
|
|
||||||
limit 1;
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<update id="deleteToGc" parameterType="io.metersphere.api.dto.definition.ApiTestCaseRequest">
|
<update id="deleteToGc" parameterType="io.metersphere.api.dto.definition.ApiTestCaseRequest">
|
||||||
update api_test_case
|
update api_test_case
|
||||||
set original_status=status,
|
set original_status=status,
|
||||||
|
|
|
@ -247,9 +247,13 @@
|
||||||
}
|
}
|
||||||
if (data.isCopy) {
|
if (data.isCopy) {
|
||||||
data.id = getUUID();
|
data.id = getUUID();
|
||||||
|
} else {
|
||||||
|
if (data.id) {
|
||||||
|
data.request.id = data.id;
|
||||||
} else {
|
} else {
|
||||||
data.id = data.request.id;
|
data.id = data.request.id;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!data.method) {
|
if (!data.method) {
|
||||||
data.method = this.currentProtocol;
|
data.method = this.currentProtocol;
|
||||||
|
|
Loading…
Reference in New Issue