Fix Sonar issues in policy-core 79/25179/1
authorCharles Cole <cc847m@att.com>
Tue, 28 Nov 2017 22:20:32 +0000 (16:20 -0600)
committerCharles Cole <cc847m@att.com>
Wed, 29 Nov 2017 19:55:29 +0000 (13:55 -0600)
Fixed the Sonar issues in policy-core that required minimal refactoring
of the code.

Issue-ID: POLICY-461
Change-Id: I3d0f7c4411855b2c75d5ae6968665753b50bde75
Signed-off-by: Charles Cole <cc847m@att.com>
policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java
policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java
policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureAPI.java

index 2da5346..7dc53ce 100644 (file)
@@ -47,10 +47,10 @@ public class PolicyContainer implements Startable
        // get an instance of logger 
   private static Logger logger = LoggerFactory.getLogger(PolicyContainer.class);       
   // 'KieServices' singleton
-  static private KieServices kieServices = KieServices.Factory.get();
+  private static KieServices kieServices = KieServices.Factory.get();
 
   // set of all 'PolicyContainer' instances
-  static private HashSet<PolicyContainer> containers =
+  private static HashSet<PolicyContainer> containers =
        new HashSet<>();
 
   // maps feature objects to per-PolicyContainer data
@@ -74,6 +74,8 @@ public class PolicyContainer implements Startable
   // indicates whether the scanner has been started
   // (it can block for a long time)
   private boolean scannerStarted = false;
+  
+  private static final String ERROR_STRING = "ERROR: Feature API: ";
 
   /**
    * uses 'groupId', 'artifactId' and 'version', and fetches the associated
@@ -288,7 +290,7 @@ public class PolicyContainer implements Startable
                                  }
                                catch (Exception e)
                                  {
-                                       logger.error("ERROR: Feature API: "
+                                       logger.error(ERROR_STRING
                                                                 + feature.getClass().getName(), e);
                                  }
                          }
@@ -316,7 +318,7 @@ public class PolicyContainer implements Startable
                                          }
                                        catch (Exception e)
                                          {
-                                               logger.error("ERROR: Feature API: "
+                                               logger.error(ERROR_STRING
                                                                         + feature.getClass().getName(), e);
                                          }
                                  }
@@ -412,7 +414,7 @@ public class PolicyContainer implements Startable
                          }
                        catch (Exception e)
                          {
-                               logger.error("ERROR: Feature API: "
+                               logger.error(ERROR_STRING
                                                         + feature.getClass().getName(), e);
                          }
                  }
@@ -518,7 +520,7 @@ public class PolicyContainer implements Startable
   public synchronized void startScanner(ReleaseId releaseId)
   {
        String version = releaseId.getVersion();
-       if (scannerStarted == false && scanner == null && version != null
+       if (!scannerStarted && scanner == null && version != null
                && ("LATEST".equals(version) || "RELEASE".equals(version)
                        || version.endsWith("-SNAPSHOT")))
          {
@@ -661,7 +663,7 @@ public class PolicyContainer implements Startable
                                  }
                                catch (Exception e)
                                  {
-                                       logger.error("ERROR: Feature API: "
+                                       logger.error(ERROR_STRING
                                                                 + feature.getClass().getName(), e);
                                  }
                          }
@@ -739,7 +741,7 @@ public class PolicyContainer implements Startable
                          }
                        catch (Exception e)
                          {
-                               logger.error("ERROR: Feature API: "
+                               logger.error(ERROR_STRING
                                                         + feature.getClass().getName(), e);
                          }
                  }
@@ -758,7 +760,7 @@ public class PolicyContainer implements Startable
   /**
    * This method is called when the host goes from the 'standby->active' state.
    */
-  static public void activate()
+  public static void activate()
   {
        // start all of the 'PolicyContainer' instances
        for (PolicyContainer container : containers)
@@ -777,7 +779,7 @@ public class PolicyContainer implements Startable
   /**
    * This method is called when the host goes from the 'active->standby' state.
    */
-  static public void deactivate()
+  public static void deactivate()
   {
        // deactivate all of the 'PolicyContainer' instances
        for (PolicyContainer container : containers)
@@ -805,7 +807,7 @@ public class PolicyContainer implements Startable
    *
    * @param args standard 'main' arguments, which are currently ignored
    */
-  public static void globalInit(String args[])
+  public static void globalInit(String[] args)
   {
        String configDir = "config";
        logger.info("PolicyContainer.main: configDir=" + configDir);
@@ -820,7 +822,7 @@ public class PolicyContainer implements Startable
                  }
                catch (Exception e)
                  {
-                       logger.error("ERROR: Feature API: "
+                       logger.error(ERROR_STRING
                                                 + feature.getClass().getName(), e);
                  }
          }
index 2a949c0..984ff47 100644 (file)
@@ -71,7 +71,7 @@ public class PolicySession
   private ThreadModel threadModel = null;
 
   // supports 'getCurrentSession()' method
-  static private ThreadLocal<PolicySession> policySession =
+  private static ThreadLocal<PolicySession> policySession =
        new ThreadLocal<>();
 
   /**
@@ -453,7 +453,7 @@ public class PolicySession
         * 'KieContainer.updateToVersion(...)' has been called (meaning the
         * full name of this session has changed).
         */
-       default public void updated() {}
+       public default void updated() {}
   }
 
   /* ============================================================ */
@@ -488,7 +488,7 @@ public class PolicySession
         */
        private String getThreadName()
        {
-         return("Session " + session.getFullName());
+         return "Session " + session.getFullName();
        }
 
        /***************************/
index 39377ab..867325c 100644 (file)
@@ -38,7 +38,7 @@ public interface PolicySessionFeatureAPI extends OrderedService
    * 'FeatureAPI.impl.getList()' returns an ordered list of objects
    * implementing the 'FeatureAPI' interface.
    */
-  static public OrderedServiceImpl<PolicySessionFeatureAPI> impl =
+  public static OrderedServiceImpl<PolicySessionFeatureAPI> impl =
        new OrderedServiceImpl<>(PolicySessionFeatureAPI.class);
 
   /**
@@ -48,7 +48,7 @@ public interface PolicySessionFeatureAPI extends OrderedService
    * @param args standard 'main' arguments, which are currently ignored
    * @param configDir the relative directory containing configuration files
    */
-  default public void globalInit(String args[], String configDir) {}
+  public default void globalInit(String[] args, String configDir) {}
 
   /**
    * This method is used to create a 'KieSession' as part of a
@@ -65,7 +65,7 @@ public interface PolicySessionFeatureAPI extends OrderedService
    *   (this depends on the capabilities and state of the object implementing
    *   this interface)
    */
-  default public KieSession activatePolicySession
+  public default KieSession activatePolicySession
        (PolicyContainer policyContainer, String name, String kieBaseName)
   {
        return null;
@@ -77,13 +77,13 @@ public interface PolicySessionFeatureAPI extends OrderedService
    *
    * @param policySession the new 'PolicySession' instance
    */
-  default public void newPolicySession(PolicySession policySession) {}
+  public default void newPolicySession(PolicySession policySession) {}
 
   /**
    * This method is called to select the 'ThreadModel' instance associated
    * with a 'PolicySession' instance.
    */
-  default public PolicySession.ThreadModel selectThreadModel
+  public default PolicySession.ThreadModel selectThreadModel
        (PolicySession session)
   {
        return null;
@@ -95,7 +95,7 @@ public interface PolicySessionFeatureAPI extends OrderedService
    * @param policySession the 'PolicySession' object that wrapped the
    *   'KieSession'
    */
-  default public void disposeKieSession(PolicySession policySession) {}
+  public default void disposeKieSession(PolicySession policySession) {}
 
   /**
    * This method is called after 'KieSession.destroy()' is called
@@ -103,5 +103,5 @@ public interface PolicySessionFeatureAPI extends OrderedService
    * @param policySession the 'PolicySession' object that wrapped the
    *   'KieSession'
    */
-  default public void destroyKieSession(PolicySession policySession) {}
+  public default void destroyKieSession(PolicySession policySession) {}
 }