diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java index 94c1b2b781..ebfbe2a747 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java @@ -194,9 +194,10 @@ public class ApiDefinitionService { /** * 工作台获取待应用管理设置的更新的条件 + * * @param request */ - public void getApplicationUpdateRule(ApiDefinitionRequest request){ + public void getApplicationUpdateRule(ApiDefinitionRequest request) { // 来自工作台条件 if (BooleanUtils.isTrue(request.getToBeUpdated())) { Long toBeUpdatedTime = apiTestCaseService.getToBeUpdatedTime(request.getProjectId()); @@ -208,7 +209,7 @@ public class ApiDefinitionService { public List selectByIds(ApiDefinitionRequest request) { if (request != null) { - return selectByIds(request.getIds()); + return selectByIds(request.getIds()); } return new ArrayList<>(); } @@ -542,10 +543,10 @@ public class ApiDefinitionService { if (CollectionUtils.isEmpty(apiIds)) { return; } - ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample(); + ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample(); apiDefinitionExample.createCriteria().andIdIn(apiIds); List apiDefinitions = apiDefinitionMapper.selectByExample(apiDefinitionExample); - if (CollectionUtils.isEmpty(apiDefinitions)){ + if (CollectionUtils.isEmpty(apiDefinitions)) { return; } List refIds = apiDefinitions.stream().map(ApiDefinition::getRefId).collect(Collectors.toList()); @@ -1300,9 +1301,9 @@ public class ApiDefinitionService { return exApiRequest != null || apiRequest != null; } - ListcompareProList = Arrays.asList(HEADERS,ARGUMENTS,REST); + List compareProList = Arrays.asList(HEADERS, ARGUMENTS, REST); - Map applicationMap = new HashMap<>(4); + Map applicationMap = new HashMap<>(4); applicationMap.put(HEADERS, apiSyncCaseRequest.getHeaders()); applicationMap.put(ARGUMENTS, apiSyncCaseRequest.getQuery()); applicationMap.put(REST, apiSyncCaseRequest.getRest()); @@ -1312,10 +1313,10 @@ public class ApiDefinitionService { for (String property : compareProList) { JsonNode exApiJsonNode = exApiRequest.get(property); JsonNode apiJsonNode = apiRequest.get(property); - if ( exApiJsonNode != null && apiJsonNode!= null) { + if (exApiJsonNode != null && apiJsonNode != null) { diffByNodes = getDiffByArrayNodes(apiRequest, exApiRequest, objectMapper, property); - if (diffByNodes){ - if (toUpdate && applicationMap.get(property)){ + if (diffByNodes) { + if (toUpdate && applicationMap.get(property)) { apiDefinition.setToBeUpdated(true); apiDefinition.setToBeUpdateTime(System.currentTimeMillis()); } @@ -1323,7 +1324,7 @@ public class ApiDefinitionService { } } } - if (diffByNodes){ + if (diffByNodes) { return true; } return delBody(apiDefinition, objectMapper, toUpdate, exApiRequest, apiRequest, applicationMap); @@ -1335,9 +1336,9 @@ public class ApiDefinitionService { if (exBodyNode != null && bodyNode != null) { JsonNode exRowNode = exBodyNode.get("raw"); JsonNode rowNode = bodyNode.get("raw"); - if (exRowNode != null && rowNode!= null){ - if (!StringUtils.equals(exRowNode.asText(),rowNode.asText())) { - if (applicationMap.get(BODY)){ + if (exRowNode != null && rowNode != null) { + if (!StringUtils.equals(exRowNode.asText(), rowNode.asText())) { + if (applicationMap.get(BODY)) { apiDefinition.setToBeUpdated(true); apiDefinition.setToBeUpdateTime(System.currentTimeMillis()); } @@ -1346,22 +1347,22 @@ public class ApiDefinitionService { } boolean diffByNodes = getDiffByArrayNodes(bodyNode, exBodyNode, objectMapper, "kvs"); - if (diffByNodes && toUpdate && applicationMap.get(BODY)){ + if (diffByNodes && toUpdate && applicationMap.get(BODY)) { apiDefinition.setToBeUpdated(true); apiDefinition.setToBeUpdateTime(System.currentTimeMillis()); } - if (diffByNodes){ + if (diffByNodes) { return true; } JsonNode exApiJsonSchema = exBodyNode.get(JSONSCHEMA); JsonNode apiJsonSchema = bodyNode.get(JSONSCHEMA); - if (exApiJsonSchema == null || apiJsonSchema==null) { + if (exApiJsonSchema == null || apiJsonSchema == null) { return false; } JsonNode exApiProperties = exApiJsonSchema.get(PROPERTIES); JsonNode apiProperties = apiJsonSchema.get(PROPERTIES); - if (exApiProperties == null || apiProperties==null) { + if (exApiProperties == null || apiProperties == null) { return false; } boolean diffJsonschema = replenishCaseProperties(exApiProperties, apiProperties); @@ -1379,21 +1380,18 @@ public class ApiDefinitionService { Iterator> apiFields = apiProperties.fields(); Iterator> exApiFields = exApiProperties.fields(); boolean diffProp = false; - while (apiFields.hasNext()){ + while (apiFields.hasNext()) { Map.Entry apiNode = apiFields.next(); - if (diffProp){ + if (diffProp) { break; } - if (exApiFields.hasNext()){ - Map.Entry exChildNode =null; - while (true){ - Map.Entry exNode = exApiFields.next(); - if (StringUtils.equalsIgnoreCase(apiNode.getKey(), exNode.getKey())) { - exChildNode =exNode; - } else { - diffProp = true; - } - break; + if (exApiFields.hasNext()) { + Map.Entry exChildNode = null; + Map.Entry exNode = exApiFields.next(); + if (StringUtils.equalsIgnoreCase(apiNode.getKey(), exNode.getKey())) { + exChildNode = exNode; + } else { + diffProp = true; } if (exChildNode == null) { continue; @@ -1405,8 +1403,8 @@ public class ApiDefinitionService { if (apiPropertiesNode == null || exApiPropertiesNode == null) { continue; } - replenishCaseProperties(exApiPropertiesNode,apiPropertiesNode); - }else { + replenishCaseProperties(exApiPropertiesNode, apiPropertiesNode); + } else { return true; } } @@ -1415,6 +1413,7 @@ public class ApiDefinitionService { /** * 比较导入的与系统中重复的两个api的基础信息 + * * @param existApi * @param apiDefinition * @param apiSyncCaseRequest @@ -1471,6 +1470,7 @@ public class ApiDefinitionService { /** * 比较导入的与系统中重复的两个api的响应体信息 + * * @param existApi * @param apiDefinition * @param objectMapper @@ -1531,16 +1531,16 @@ public class ApiDefinitionService { return null; } - private boolean getDiffByArrayNodes(JsonNode apiRequest, JsonNode exApiRequest, ObjectMapper objectMapper, String name){ + private boolean getDiffByArrayNodes(JsonNode apiRequest, JsonNode exApiRequest, ObjectMapper objectMapper, String name) { JsonNode apiNameNode = apiRequest.get(name); JsonNode caseNameNode = exApiRequest.get(name); - if(apiNameNode==null || caseNameNode==null){ + if (apiNameNode == null || caseNameNode == null) { return false; } Map apiMap = new HashMap<>(); - getKeyNameMap(apiNameNode, objectMapper, apiMap,"name"); + getKeyNameMap(apiNameNode, objectMapper, apiMap, "name"); Map exApiMap = new HashMap<>(); - getKeyNameMap(caseNameNode, objectMapper, exApiMap,"name"); + getKeyNameMap(caseNameNode, objectMapper, exApiMap, "name"); if (apiMap.size() != exApiMap.size()) { return true; } @@ -1553,7 +1553,7 @@ public class ApiDefinitionService { return false; } - public void getKeyNameMap(JsonNode apiNameNode, ObjectMapper objectMapper, Map nameMap,String nodeKey) { + public void getKeyNameMap(JsonNode apiNameNode, ObjectMapper objectMapper, Map nameMap, String nodeKey) { for (int i = 0; i < apiNameNode.size(); i++) { JsonNode apiName = apiNameNode.get(i); if (apiName.has(nodeKey)) { @@ -2126,7 +2126,7 @@ public class ApiDefinitionService { ApiDefinitionExample example = new ApiDefinitionExample(); example.createCriteria().andIdIn(ids); List apiDefinitionList = apiDefinitionMapper.selectByExample(example); - if (CollectionUtils.isEmpty(apiDefinitionList)){ + if (CollectionUtils.isEmpty(apiDefinitionList)) { return; } List refIds = apiDefinitionList.stream().map(ApiDefinition::getRefId).collect(Collectors.toList()); diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java index 2243c9e0eb..06d3a7fc6b 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java @@ -755,11 +755,10 @@ public class ApiTestCaseService { ApiTestCaseMapper batchMapper = sqlSession.getMapper(ApiTestCaseMapper.class); bloBs.forEach(apiTestCase -> { - MsHTTPSamplerProxy req = JSON.parseObject(apiTestCase.getRequest(), MsHTTPSamplerProxy.class); + JSONObject element = JSONUtil.parseObject(apiTestCase.getRequest()); + ElementUtil.dataFormatting(element); + MsHTTPSamplerProxy req = JSON.parseObject(element.toString(), MsHTTPSamplerProxy.class); try { - JSONObject element = JSONUtil.parseObject(apiTestCase.getRequest()); - ElementUtil.dataFormatting(element); - if (element != null && StringUtils.isNotEmpty(element.optString(ElementConstants.HASH_TREE))) { LinkedList elements = mapper.readValue(element.optString(ElementConstants.HASH_TREE), new TypeReference>() { }); @@ -1117,6 +1116,7 @@ public class ApiTestCaseService { /** * 工作台查询应用管理里设置的用例待更新条件 + * * @param request */ public void initRequestBySearch(ApiTestCaseRequest request) {