Fix in rule management the sonar detected error
authoryoubowu <wu.youbo@zte.com.cn>
Thu, 2 Mar 2017 08:02:59 +0000 (16:02 +0800)
committer6092002067 <wu.youbo@zte.com.cn>
Thu, 2 Mar 2017 08:02:59 +0000 (16:02 +0800)
Issue-ID:HOLMES-50

Change-Id: Ic61e8137521617188fae1d149aad40c88b65e684
Signed-off-by: youbowu <wu.youbo@zte.com.cn>
rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleDao.java
rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDao.java
rulemgt/src/test/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java

index aa2cccc..f800f0c 100644 (file)
@@ -67,7 +67,7 @@ public abstract class CorrelationRuleDao {
             addRule(correlationRule);\r
             return correlationRule;\r
         } catch (Exception e) {\r
-            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR);\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR,e);\r
         }\r
     }\r
 \r
@@ -75,7 +75,7 @@ public abstract class CorrelationRuleDao {
         try {\r
             updateRuleByRid(correlationRule);\r
         } catch (Exception e) {\r
-            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR);\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR,e);\r
         }\r
     }\r
 \r
@@ -83,7 +83,7 @@ public abstract class CorrelationRuleDao {
         try {\r
             deleteRule2DbInner(correlationRule);\r
         } catch (Exception e) {\r
-            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR);\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR,e);\r
         }\r
     }\r
 \r
@@ -92,7 +92,7 @@ public abstract class CorrelationRuleDao {
         try {\r
             return queryRuleById(rid);\r
         } catch (Exception e) {\r
-            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR);\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR,e);\r
         }\r
     }\r
 \r
@@ -100,7 +100,7 @@ public abstract class CorrelationRuleDao {
         try {\r
             return queryRuleByName(name);\r
         } catch (Exception e) {\r
-            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR);\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR,e);\r
         }\r
     }\r
 }\r
index 075da00..d77cc09 100644 (file)
@@ -117,11 +117,8 @@ public class CorrelationRuleQueryDao {
                     }\r
                 }\r
             }\r
-            if (whereSql.indexOf("AND") > -1) {\r
-                whereSql = whereSql.trim();\r
-                return whereSql.substring(0, whereSql.length() - "AND".length());\r
-            }\r
-            return "";\r
+            whereSql = whereSql.trim();\r
+            return whereSql.substring(0, whereSql.length() - "AND".length());\r
         } catch (Exception e) {\r
             throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED, e);\r
         }\r
index 8df2074..f241484 100644 (file)
@@ -30,28 +30,24 @@ import org.junit.Before;
 import org.junit.Rule;\r
 import org.junit.Test;\r
 import org.junit.rules.ExpectedException;\r
-import org.junit.runner.RunWith;\r
 import org.openo.holmes.common.api.entity.CorrelationRule;\r
 import org.openo.holmes.common.exception.CorrelationException;\r
 import org.openo.holmes.common.utils.DbDaoUtil;\r
 import org.openo.holmes.common.utils.I18nProxy;\r
 import org.openo.holmes.rulemgt.bean.request.RuleQueryCondition;\r
 import org.powermock.api.easymock.PowerMock;\r
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;\r
-import org.powermock.modules.junit4.PowerMockRunner;\r
 import org.powermock.modules.junit4.rule.PowerMockRule;\r
 import org.powermock.reflect.Whitebox;\r
 import org.skife.jdbi.v2.Handle;\r
 import org.skife.jdbi.v2.Query;\r
 \r
 \r
-\r
 public class CorrelationRuleQueryDaoTest {\r
 \r
     @Rule\r
     public ExpectedException thrown = ExpectedException.none();\r
 \r
-           @Rule\r
+    @Rule\r
     public PowerMockRule powerMockRule = new PowerMockRule();\r
     private DbDaoUtil dbDaoUtil;\r
 \r