fix: 非http接口导入报错 (#6371)
Co-authored-by: chenjianxing <jianxing.chen@fit2cloud.com>
This commit is contained in:
parent
49c1bd8816
commit
c33863e021
|
@ -346,13 +346,22 @@ public class ApiDefinitionService {
|
|||
|
||||
private List<ApiDefinition> getSameRequestWithName(SaveApiDefinitionRequest request) {
|
||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
example.createCriteria()
|
||||
.andMethodEqualTo(request.getMethod())
|
||||
.andStatusNotEqualTo("Trash")
|
||||
.andPathEqualTo(request.getPath())
|
||||
.andNameEqualTo(request.getName())
|
||||
.andProjectIdEqualTo(request.getProjectId())
|
||||
.andIdNotEqualTo(request.getId());
|
||||
if (request.getProtocol().equals(RequestType.HTTP)) {
|
||||
example.createCriteria()
|
||||
.andMethodEqualTo(request.getMethod())
|
||||
.andStatusNotEqualTo("Trash")
|
||||
.andPathEqualTo(request.getPath())
|
||||
.andNameEqualTo(request.getName())
|
||||
.andProjectIdEqualTo(request.getProjectId())
|
||||
.andIdNotEqualTo(request.getId());
|
||||
} else {
|
||||
example.createCriteria()
|
||||
.andStatusNotEqualTo("Trash")
|
||||
.andNameEqualTo(request.getName())
|
||||
.andProjectIdEqualTo(request.getProjectId())
|
||||
.andIdNotEqualTo(request.getId());
|
||||
}
|
||||
|
||||
return apiDefinitionMapper.selectByExample(example);
|
||||
|
||||
}
|
||||
|
@ -489,9 +498,12 @@ public class ApiDefinitionService {
|
|||
} else if (StringUtils.equals("incrementalMerge", apiTestImportRequest.getModeId())) {
|
||||
if (CollectionUtils.isEmpty(sameRequest)) {
|
||||
//postman 可能含有前置脚本,接口定义去掉脚本
|
||||
String requestStr = setImportHashTree(apiDefinition);
|
||||
apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId()));
|
||||
batchMapper.insert(apiDefinition);
|
||||
String originId = apiDefinition.getId();
|
||||
apiDefinition.setId(UUID.randomUUID().toString());
|
||||
String requestStr = setImportHashTree(apiDefinition);
|
||||
reSetImportCasesApiId(cases, originId, apiDefinition.getId());
|
||||
apiDefinition.setRequest(requestStr);
|
||||
importApiCase(apiDefinition, apiTestCaseMapper, apiTestImportRequest, true);
|
||||
}
|
||||
|
@ -526,19 +538,18 @@ public class ApiDefinitionService {
|
|||
ApiTestCaseMapper apiTestCaseMapper, ApiTestImportRequest apiTestImportRequest, List<ApiTestCaseWithBLOBs> cases) {
|
||||
String originId = apiDefinition.getId();
|
||||
if (CollectionUtils.isEmpty(sameRequest)) {
|
||||
apiDefinition.setId(UUID.randomUUID().toString());
|
||||
apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId()));
|
||||
reSetImportCasesApiId(cases, originId, apiDefinition.getId());
|
||||
if (StringUtils.equalsIgnoreCase(apiDefinition.getProtocol(), RequestType.HTTP)) {
|
||||
String request = setImportHashTree(apiDefinition);
|
||||
apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId()));
|
||||
apiDefinition.setId(UUID.randomUUID().toString());
|
||||
reSetImportCasesApiId(cases, originId, apiDefinition.getId());
|
||||
batchMapper.insert(apiDefinition);
|
||||
String request = setImportHashTree(apiDefinition);
|
||||
apiDefinition.setRequest(request);
|
||||
importApiCase(apiDefinition, apiTestCaseMapper, apiTestImportRequest, true);
|
||||
} else {
|
||||
if (StringUtils.equalsAnyIgnoreCase(apiDefinition.getProtocol(), RequestType.TCP)) {
|
||||
setImportTCPHashTree(apiDefinition);
|
||||
}
|
||||
apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId()));
|
||||
batchMapper.insert(apiDefinition);
|
||||
}
|
||||
|
||||
|
@ -649,7 +660,10 @@ public class ApiDefinitionService {
|
|||
checkRequest.setName(apiTestCase.getName());
|
||||
checkRequest.setApiDefinitionId(apiTestCase.getApiDefinitionId());
|
||||
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());
|
||||
if (sameCase == null) {
|
||||
apiTestCase.setId(UUID.randomUUID().toString());
|
||||
|
|
|
@ -279,6 +279,19 @@ public class ApiTestCaseService {
|
|||
}
|
||||
|
||||
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.Criteria criteria = example.createCriteria();
|
||||
criteria.andStatusNotEqualTo("Trash").andNameEqualTo(request.getName()).andApiDefinitionIdEqualTo(request.getApiDefinitionId());
|
||||
|
@ -287,14 +300,24 @@ public class ApiTestCaseService {
|
|||
}
|
||||
List<ApiTestCase> apiTestCases = apiTestCaseMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(apiTestCases)) {
|
||||
if (apiTestCases.get(0) != null) {
|
||||
MSException.throwException(Translator.get("load_test_already_exists"));
|
||||
};
|
||||
return apiTestCases.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ApiTestCase getImportSameCase(SaveApiTestCaseRequest request) {
|
||||
return extApiTestCaseMapper.selectSameCase(request);
|
||||
public ApiTestCase getSameCaseById(SaveApiTestCaseRequest 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) {
|
||||
|
|
|
@ -57,6 +57,4 @@ public interface ExtApiTestCaseMapper {
|
|||
Long getPreOrder(@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>
|
||||
order by `order` desc limit 1;
|
||||
</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 api_test_case
|
||||
set original_status=status,
|
||||
|
|
|
@ -248,7 +248,11 @@
|
|||
if (data.isCopy) {
|
||||
data.id = getUUID();
|
||||
} else {
|
||||
data.id = data.request.id;
|
||||
if (data.id) {
|
||||
data.request.id = data.id;
|
||||
} else {
|
||||
data.id = data.request.id;
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.method) {
|
||||
|
|
Loading…
Reference in New Issue