From 18aceb1795fc25fbe770b6d6bb6bbe68d4bf70fc Mon Sep 17 00:00:00 2001 From: zhangcheng Date: Thu, 15 Mar 2018 14:51:36 +0800 Subject: Fix the Sonar Findings Issue-ID: HOLMES-121 Change-Id: I712b4bd4e7b0d63c43b05549d2cded13a4b29ea3 Signed-off-by: zhangcheng --- rulemgt/pom.xml | 83 +++++++++++++++++++++- .../rulemgt/bolt/enginebolt/EngineWrapper.java | 6 +- .../holmes/rulemgt/resources/RuleMgtResources.java | 50 +++++++------ 3 files changed, 108 insertions(+), 31 deletions(-) diff --git a/rulemgt/pom.xml b/rulemgt/pom.xml index 705f927..1e63e09 100644 --- a/rulemgt/pom.xml +++ b/rulemgt/pom.xml @@ -32,11 +32,25 @@ com.fasterxml.jackson.core jackson-databind - 2.6.2 + 2.8.9 org.onap.msb.java-sdk msb-java-sdk + + + ch.qos.logback + logback-classic + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-core + + org.reflections @@ -76,13 +90,30 @@ ch.qos.logback logback + + ch.qos.logback + logback-classic + log4j-over-slf4j org.slf4j + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-core + - + + ch.qos.logback + logback-classic + 1.2.3 + + org.projectlombok lombok @@ -113,6 +144,16 @@ io.swagger swagger-jersey2-jaxrs + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-core + + provided @@ -172,7 +213,27 @@ json-lib 2.4 jdk15 + + + commons-collections + commons-collections + + + commons-beanutils + commons-beanutils + + + + commons-collections + commons-collections + 3.2.2 + + + com.alibaba + fastjson + 1.1.23 + org.glassfish.jersey.core jersey-server @@ -197,6 +258,12 @@ com.google.guava guava 19.0 + + + com.fasterxml.jackson.core + jackson-core + + @@ -277,7 +344,17 @@ io.swagger swagger-jersey2-jaxrs - 1.5.0 + 1.5.3 + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-core + + diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java index 183e52f..18a326e 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java @@ -15,9 +15,10 @@ */ package org.onap.holmes.rulemgt.bolt.enginebolt; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import javax.inject.Inject; import lombok.extern.slf4j.Slf4j; -import net.sf.json.JSONObject; import org.apache.http.HttpResponse; import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.utils.HttpsUtils; @@ -43,7 +44,8 @@ public class EngineWrapper { if (response.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) { log.info("Succeeded in calling the rule deployment RESTful API from the engine management service."); try { - JSONObject json = JSONObject.fromObject(HttpsUtils.extractResponseEntity(response)); + // JSONObject json = JSONObject.fromObject(HttpsUtils.extractResponseEntity(response)); + JSONObject json= JSON.parseObject(HttpsUtils.extractResponseEntity(response)); return json.get(RuleMgtConstant.PACKAGE).toString(); } catch (Exception e) { throw new CorrelationException("Failed to parse the value returned by the engine management service.", e); diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java index d3c01ae..8e5b7a0 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java @@ -1,17 +1,15 @@ /** * Copyright 2017 ZTE Corporation. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package org.onap.holmes.rulemgt.resources; @@ -20,9 +18,6 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.SwaggerDefinition; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; import java.util.Locale; import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; @@ -37,7 +32,6 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import lombok.extern.slf4j.Slf4j; -import net.sf.json.JSONObject; import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.exception.CorrelationException; import org.onap.holmes.common.utils.ExceptionUtil; @@ -50,7 +44,6 @@ import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition; import org.onap.holmes.rulemgt.bean.request.RuleUpdateRequest; import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse; import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse; -import org.onap.holmes.rulemgt.bean.response.RuleResult4API; import org.onap.holmes.rulemgt.constant.RuleMgtConstant; import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper; @@ -71,9 +64,10 @@ public class RuleMgtResources { response = RuleAddAndUpdateResponse.class) @Timed public RuleAddAndUpdateResponse addCorrelationRule(@Context HttpServletRequest request, - @ApiParam(value = "The request entity of the HTTP call, which comprises \"ruleName\"(required), " - + "\"loopControlName\"(required), \"content\"(required), \"enabled\"(required) " - + "and \"description\"(optional)", required = true) + @ApiParam(value = + "The request entity of the HTTP call, which comprises \"ruleName\"(required), " + + "\"loopControlName\"(required), \"content\"(required), \"enabled\"(required) " + + "and \"description\"(optional)", required = true) RuleCreateRequest ruleCreateRequest) { Locale locale = LanguageUtil.getLocale(request); RuleAddAndUpdateResponse ruleChangeResponse; @@ -93,13 +87,15 @@ public class RuleMgtResources { @ApiOperation(value = "Update an existing rule; deploy it to the Drools engine if it is enabled.", response = RuleAddAndUpdateResponse.class) @Timed public RuleAddAndUpdateResponse updateCorrelationRule(@Context HttpServletRequest request, - @ApiParam(value = "The request entity of the HTTP call, which comprises \"ruleId\"(required), " - + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true) + @ApiParam(value = + "The request entity of the HTTP call, which comprises \"ruleId\"(required), " + + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true) RuleUpdateRequest ruleUpdateRequest) { Locale locale = LanguageUtil.getLocale(request); RuleAddAndUpdateResponse ruleChangeResponse; try { - ruleChangeResponse = ruleMgtWrapper.updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest); + ruleChangeResponse = ruleMgtWrapper + .updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest); log.info("update rule:" + ruleUpdateRequest.getRuleId() + " successful"); return ruleChangeResponse; } catch (CorrelationException e) { @@ -131,9 +127,10 @@ public class RuleMgtResources { @ApiOperation(value = "Query rules using certain criteria.", response = RuleQueryListResponse.class) @Timed public RuleQueryListResponse getCorrelationRules(@Context HttpServletRequest request, - @ApiParam(value = "A JSON string used as a query parameter, which comprises \"ruleid\"(optional), " - + "\"rulename\"(optional), \"creator\"(optional), " - + "\"modifier\"(optional) and \"enabled\"(optional). E.g. {\"ruleid\":\"rule_1484727187317\"}", + @ApiParam(value = + "A JSON string used as a query parameter, which comprises \"ruleid\"(optional), " + + "\"rulename\"(optional), \"creator\"(optional), " + + "\"modifier\"(optional) and \"enabled\"(optional). E.g. {\"ruleid\":\"rule_1484727187317\"}", required = false) @QueryParam("queryrequest") String ruleQueryRequest) { Locale locale = LanguageUtil.getLocale(request); RuleQueryListResponse ruleQueryListResponse; @@ -142,7 +139,7 @@ public class RuleMgtResources { try { ruleQueryListResponse = ruleMgtWrapper .getCorrelationRuleByCondition(ruleQueryCondition); - log.info("query rule successful by condition:" + JSONObject.fromObject(ruleQueryCondition)); + log.info("query rule successful by condition:" + ruleQueryCondition); return ruleQueryListResponse; } catch (CorrelationException e) { log.error("query rule failed,cause query condition conversion failure", e); @@ -153,9 +150,10 @@ public class RuleMgtResources { private RuleQueryCondition getRuleQueryCondition(String queryRequest, HttpServletRequest request) { Locale locale = LanguageUtil.getLocale(request); - RuleQueryCondition ruleQueryCondition = GsonUtil.jsonToBean(queryRequest, RuleQueryCondition.class); + RuleQueryCondition ruleQueryCondition = GsonUtil + .jsonToBean(queryRequest, RuleQueryCondition.class); if (queryRequest == null) { - if(ruleQueryCondition==null){ + if (ruleQueryCondition == null) { ruleQueryCondition = new RuleQueryCondition(); } ruleQueryCondition.setEnabled(RuleMgtConstant.STATUS_RULE_ALL); -- cgit 1.2.3-korg