Fixed Bugs Detected by SonarCloud 31/109131/1
authorGuangrongFu <fu.guangrong@zte.com.cn>
Sat, 13 Jun 2020 08:51:20 +0000 (16:51 +0800)
committerGuangrongFu <fu.guangrong@zte.com.cn>
Sat, 13 Jun 2020 08:51:20 +0000 (16:51 +0800)
Change-Id: Iaa0a6ce8c8aa4b88d59aad882f31135acf89cc26
Issue-ID: HOLMES-316
Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
holmes-actions/src/main/java/org/onap/holmes/common/api/stat/Alarm.java
holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java
holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java

index b6cfc06..6d9d602 100644 (file)
@@ -1,5 +1,5 @@
 /**\r
- * Copyright 2017 ZTE Corporation.\r
+ * Copyright 2017-2020 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
@@ -78,28 +78,6 @@ public class Alarm implements AplusData, Cloneable, Serializable {
         linkIdNodeIdxMap.put(linkId, index);\r
     }\r
 \r
-    /**\r
-     * Comparison of the location of different links: 999 the same link: the location of the node\r
-     * number less than otherIdIdx in the location of the number (in the otherIdIdx upstream):-1,\r
-     * the same link: the node position number is equal to the number of position in the otherIdIdx\r
-     * (in the same site otherIdIdx):0, the same link: the node location number is greater than the\r
-     * number of locations in otherIdIdx (otherIdIdx) with the site):1,\r
-     */\r
-    public int CompareLinkPosition(Map<Integer, Integer> otherIdIdx) {\r
-        Set<Integer> myIdSet = new HashSet<>();\r
-        myIdSet.addAll(this.linkIdNodeIdxMap.keySet());\r
-        myIdSet.retainAll(otherIdIdx.keySet());\r
-\r
-        if (myIdSet.isEmpty()) {\r
-            return 999;\r
-        }\r
-\r
-        for (int tempLinkId : myIdSet) {\r
-            return this.linkIdNodeIdxMap.get(tempLinkId) - otherIdIdx.get(tempLinkId);\r
-        }\r
-        return 999;\r
-    }\r
-\r
     public boolean containNode(int linkId, int index) {\r
        return linkIdNodeIdxMap.containsKey(linkId) && linkIdNodeIdxMap.get(linkId) == index;\r
     }\r
index 76e11ba..a88519a 100644 (file)
@@ -1,12 +1,12 @@
 /**\r
- * Copyright 2017 ZTE Corporation.\r
- *\r
+ * Copyright 2017-2020 ZTE Corporation.\r
+ * <p>\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
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
+ * <p>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p>\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
@@ -18,14 +18,15 @@ package org.onap.holmes.common.utils;
 import io.dropwizard.db.DataSourceFactory;\r
 import io.dropwizard.jdbi.DBIFactory;\r
 import io.dropwizard.setup.Environment;\r
-import javax.annotation.PostConstruct;\r
-import javax.inject.Inject;\r
-import javax.inject.Singleton;\r
 import lombok.extern.slf4j.Slf4j;\r
 import org.jvnet.hk2.annotations.Service;\r
 import org.skife.jdbi.v2.DBI;\r
 import org.skife.jdbi.v2.Handle;\r
 \r
+import javax.annotation.PostConstruct;\r
+import javax.inject.Inject;\r
+import javax.inject.Singleton;\r
+\r
 @Singleton\r
 @Service\r
 @Slf4j\r
@@ -40,13 +41,9 @@ public class DbDaoUtil {
     private DBIFactory factory = new DBIFactory();\r
 \r
     @PostConstruct\r
-    public void init() {\r
+    public synchronized void init() {\r
         if (jdbi == null) {\r
-            synchronized (DbDaoUtil.class) {\r
-                if (jdbi == null) {\r
-                    jdbi = factory.build(environmentProvider, dataSourceFactoryProvider, "mysql");\r
-                }\r
-            }\r
+            jdbi = factory.build(environmentProvider, dataSourceFactoryProvider, "postgres");\r
         }\r
     }\r
 \r
index d701f3d..6cf62d6 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2020 ZTE Corporation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,8 +19,7 @@ package org.onap.holmes.common.api.stat;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
+
 import java.util.Date;
 import static org.hamcrest.core.IsEqual.equalTo;
 import static org.junit.Assert.assertFalse;
@@ -52,20 +51,6 @@ public class AlarmTest {
     public void after() throws Exception {
     }
 
-    @Test
-    public void testCompareLinkPosition_isEmpty() throws Exception {
-        final Map<Integer, Integer> otherIdIdx = new HashMap<>();
-        assertThat(999, equalTo(alarm.CompareLinkPosition(otherIdIdx)));
-    }
-
-    @Test
-    public void testCompareLinkPosition_TempLinkId() throws Exception {
-        final Map<Integer, Integer> otherIdIdx = new HashMap<>();
-        otherIdIdx.put(1, 2);
-        alarm.addLinkIdNodeIdx(1, 3);
-        assertThat(1, equalTo(alarm.CompareLinkPosition(otherIdIdx)));
-    }
-
     @Test
     public void testContainNode_NoContainLink() throws Exception {
         alarm.addLinkIdNodeIdx(1, 2);