Fix the Sonar Findings 07/35907/1
authorzhangcheng <zhang.cheng7@zte.com.cn>
Thu, 15 Mar 2018 06:51:36 +0000 (14:51 +0800)
committerzhangcheng <zhang.cheng7@zte.com.cn>
Thu, 15 Mar 2018 06:51:36 +0000 (14:51 +0800)
Issue-ID: HOLMES-121

Change-Id: I712b4bd4e7b0d63c43b05549d2cded13a4b29ea3
Signed-off-by: zhangcheng <zhang.cheng7@zte.com.cn>
rulemgt/pom.xml
rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java

index 705f927..1e63e09 100644 (file)
         <dependency>
             <groupId>com.fasterxml.jackson.core</groupId>
             <artifactId>jackson-databind</artifactId>
-            <version>2.6.2</version>
+            <version>2.8.9</version>
         </dependency>
         <dependency>
             <groupId>org.onap.msb.java-sdk</groupId>
             <artifactId>msb-java-sdk</artifactId>
+            <exclusions>
+              <exclusion>
+                <groupId>ch.qos.logback</groupId>
+                <artifactId>logback-classic</artifactId>
+              </exclusion>
+              <exclusion>
+                <groupId>com.fasterxml.jackson.core</groupId>
+                <artifactId>jackson-databind</artifactId>
+              </exclusion>
+              <exclusion>
+                <groupId>com.fasterxml.jackson.core</groupId>
+                <artifactId>jackson-core</artifactId>
+              </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>org.reflections</groupId>
                     <groupId>ch.qos.logback</groupId>
                     <artifactId>logback</artifactId>
                 </exclusion>
+                <exclusion>
+                    <groupId>ch.qos.logback</groupId>
+                    <artifactId>logback-classic</artifactId>
+                </exclusion>
                 <exclusion>
                     <artifactId>log4j-over-slf4j</artifactId>
                     <groupId>org.slf4j</groupId>
                 </exclusion>
+              <exclusion>
+                <groupId>com.fasterxml.jackson.core</groupId>
+                <artifactId>jackson-databind</artifactId>
+              </exclusion>
+              <exclusion>
+                <groupId>com.fasterxml.jackson.core</groupId>
+                <artifactId>jackson-core</artifactId>
+              </exclusion>
             </exclusions>
         </dependency>
-        <dependency>
+      <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <version>1.2.3</version>
+      </dependency>
+      <dependency>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
         </dependency>
         <dependency>
             <groupId>io.swagger</groupId>
             <artifactId>swagger-jersey2-jaxrs</artifactId>
+            <exclusions>
+              <exclusion>
+                <groupId>com.fasterxml.jackson.core</groupId>
+                <artifactId>jackson-databind</artifactId>
+              </exclusion>
+              <exclusion>
+                <groupId>com.fasterxml.jackson.core</groupId>
+                <artifactId>jackson-core</artifactId>
+              </exclusion>
+            </exclusions>
             <scope>provided</scope>
         </dependency>
 
             <artifactId>json-lib</artifactId>
             <version>2.4</version>
             <classifier>jdk15</classifier>
+            <exclusions>
+                <exclusion>
+                    <groupId>commons-collections</groupId>
+                    <artifactId>commons-collections</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>commons-beanutils</groupId>
+                    <artifactId>commons-beanutils</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
+        <dependency>
+            <groupId>commons-collections</groupId>
+            <artifactId>commons-collections</artifactId>
+            <version>3.2.2</version>
+        </dependency>
+      <dependency>
+        <groupId>com.alibaba</groupId>
+        <artifactId>fastjson</artifactId>
+        <version>1.1.23</version>
+      </dependency>
         <dependency>
             <groupId>org.glassfish.jersey.core</groupId>
             <artifactId>jersey-server</artifactId>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
             <version>19.0</version>
+            <exclusions>
+              <exclusion>
+                <groupId>com.fasterxml.jackson.core</groupId>
+                <artifactId>jackson-core</artifactId>
+              </exclusion>
+            </exclusions>
         </dependency>
     </dependencies>
     <build>
                 <dependency>
                     <groupId>io.swagger</groupId>
                     <artifactId>swagger-jersey2-jaxrs</artifactId>
-                    <version>1.5.0</version>
+                    <version>1.5.3</version>
+                    <exclusions>
+                        <exclusion>
+                          <groupId>com.fasterxml.jackson.core</groupId>
+                          <artifactId>jackson-databind</artifactId>
+                        </exclusion>
+                        <exclusion>
+                          <groupId>com.fasterxml.jackson.core</groupId>
+                          <artifactId>jackson-core</artifactId>
+                        </exclusion>
+                    </exclusions>
                 </dependency>
             </dependencies>
             <build>
index 183e52f..18a326e 100644 (file)
  */\r
 package org.onap.holmes.rulemgt.bolt.enginebolt;\r
 \r
+import com.alibaba.fastjson.JSON;\r
+import com.alibaba.fastjson.JSONObject;\r
 import javax.inject.Inject;\r
 import lombok.extern.slf4j.Slf4j;\r
-import net.sf.json.JSONObject;\r
 import org.apache.http.HttpResponse;\r
 import org.jvnet.hk2.annotations.Service;\r
 import org.onap.holmes.common.utils.HttpsUtils;\r
@@ -43,7 +44,8 @@ public class EngineWrapper {
         if (response.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) {\r
             log.info("Succeeded in calling the rule deployment RESTful API from the engine management service.");\r
             try {\r
-                JSONObject json = JSONObject.fromObject(HttpsUtils.extractResponseEntity(response));\r
+               // JSONObject json = JSONObject.fromObject(HttpsUtils.extractResponseEntity(response));\r
+                JSONObject json=  JSON.parseObject(HttpsUtils.extractResponseEntity(response));\r
                 return json.get(RuleMgtConstant.PACKAGE).toString();\r
             } catch (Exception e) {\r
                 throw new CorrelationException("Failed to parse the value returned by the engine management service.", e);\r
index d3c01ae..8e5b7a0 100644 (file)
@@ -1,17 +1,15 @@
 /**\r
  * Copyright 2017 ZTE Corporation.\r
  *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
  *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
  */\r
 package org.onap.holmes.rulemgt.resources;\r
 \r
@@ -20,9 +18,6 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;\r
 import io.swagger.annotations.ApiParam;\r
 import io.swagger.annotations.SwaggerDefinition;\r
-import java.util.ArrayList;\r
-import java.util.Date;\r
-import java.util.List;\r
 import java.util.Locale;\r
 import javax.inject.Inject;\r
 import javax.servlet.http.HttpServletRequest;\r
@@ -37,7 +32,6 @@ import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Context;\r
 import javax.ws.rs.core.MediaType;\r
 import lombok.extern.slf4j.Slf4j;\r
-import net.sf.json.JSONObject;\r
 import org.jvnet.hk2.annotations.Service;\r
 import org.onap.holmes.common.exception.CorrelationException;\r
 import org.onap.holmes.common.utils.ExceptionUtil;\r
@@ -50,7 +44,6 @@ import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
 import org.onap.holmes.rulemgt.bean.request.RuleUpdateRequest;\r
 import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;\r
 import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;\r
-import org.onap.holmes.rulemgt.bean.response.RuleResult4API;\r
 import org.onap.holmes.rulemgt.constant.RuleMgtConstant;\r
 import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;\r
 \r
@@ -71,9 +64,10 @@ public class RuleMgtResources {
             response = RuleAddAndUpdateResponse.class)\r
     @Timed\r
     public RuleAddAndUpdateResponse addCorrelationRule(@Context HttpServletRequest request,\r
-            @ApiParam(value = "The request entity of the HTTP call, which comprises \"ruleName\"(required), "\r
-                    + "\"loopControlName\"(required), \"content\"(required), \"enabled\"(required) "\r
-                    + "and \"description\"(optional)", required = true)\r
+            @ApiParam(value =\r
+                    "The request entity of the HTTP call, which comprises \"ruleName\"(required), "\r
+                            + "\"loopControlName\"(required), \"content\"(required), \"enabled\"(required) "\r
+                            + "and \"description\"(optional)", required = true)\r
                     RuleCreateRequest ruleCreateRequest) {\r
         Locale locale = LanguageUtil.getLocale(request);\r
         RuleAddAndUpdateResponse ruleChangeResponse;\r
@@ -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)\r
     @Timed\r
     public RuleAddAndUpdateResponse updateCorrelationRule(@Context HttpServletRequest request,\r
-            @ApiParam(value = "The request entity of the HTTP call, which comprises \"ruleId\"(required), "\r
-                    + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true)\r
+            @ApiParam(value =\r
+                    "The request entity of the HTTP call, which comprises \"ruleId\"(required), "\r
+                            + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true)\r
                     RuleUpdateRequest ruleUpdateRequest) {\r
         Locale locale = LanguageUtil.getLocale(request);\r
         RuleAddAndUpdateResponse ruleChangeResponse;\r
         try {\r
-            ruleChangeResponse = ruleMgtWrapper.updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest);\r
+            ruleChangeResponse = ruleMgtWrapper\r
+                    .updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest);\r
             log.info("update rule:" + ruleUpdateRequest.getRuleId() + " successful");\r
             return ruleChangeResponse;\r
         } catch (CorrelationException e) {\r
@@ -131,9 +127,10 @@ public class RuleMgtResources {
     @ApiOperation(value = "Query rules using certain criteria.", response = RuleQueryListResponse.class)\r
     @Timed\r
     public RuleQueryListResponse getCorrelationRules(@Context HttpServletRequest request,\r
-            @ApiParam(value = "A JSON string used as a query parameter, which comprises \"ruleid\"(optional), "\r
-                    + "\"rulename\"(optional), \"creator\"(optional), "\r
-                    + "\"modifier\"(optional) and \"enabled\"(optional). E.g. {\"ruleid\":\"rule_1484727187317\"}",\r
+            @ApiParam(value =\r
+                    "A JSON string used as a query parameter, which comprises \"ruleid\"(optional), "\r
+                            + "\"rulename\"(optional), \"creator\"(optional), "\r
+                            + "\"modifier\"(optional) and \"enabled\"(optional). E.g. {\"ruleid\":\"rule_1484727187317\"}",\r
                     required = false) @QueryParam("queryrequest") String ruleQueryRequest) {\r
         Locale locale = LanguageUtil.getLocale(request);\r
         RuleQueryListResponse ruleQueryListResponse;\r
@@ -142,7 +139,7 @@ public class RuleMgtResources {
         try {\r
             ruleQueryListResponse = ruleMgtWrapper\r
                     .getCorrelationRuleByCondition(ruleQueryCondition);\r
-            log.info("query rule successful by condition:" + JSONObject.fromObject(ruleQueryCondition));\r
+            log.info("query rule successful by condition:" + ruleQueryCondition);\r
             return ruleQueryListResponse;\r
         } catch (CorrelationException e) {\r
             log.error("query rule failed,cause query condition conversion failure", e);\r
@@ -153,9 +150,10 @@ public class RuleMgtResources {
     private RuleQueryCondition getRuleQueryCondition(String queryRequest,\r
             HttpServletRequest request) {\r
         Locale locale = LanguageUtil.getLocale(request);\r
-        RuleQueryCondition ruleQueryCondition = GsonUtil.jsonToBean(queryRequest, RuleQueryCondition.class);\r
+        RuleQueryCondition ruleQueryCondition = GsonUtil\r
+                .jsonToBean(queryRequest, RuleQueryCondition.class);\r
         if (queryRequest == null) {\r
-            if(ruleQueryCondition==null){\r
+            if (ruleQueryCondition == null) {\r
                 ruleQueryCondition = new RuleQueryCondition();\r
             }\r
             ruleQueryCondition.setEnabled(RuleMgtConstant.STATUS_RULE_ALL);\r