Fix for SONAR critical issues 05/11605/1
authorseshukm <seshu.kumar.m@huawei.com>
Mon, 11 Sep 2017 08:59:25 +0000 (14:29 +0530)
committerseshukm <seshu.kumar.m@huawei.com>
Mon, 11 Sep 2017 08:59:25 +0000 (14:29 +0530)
Issue Id : SO-117

Change-Id: I7774a2d35f46398c3c3d6a9b4da97a0a52ef941e
Signed-off-by: seshukm <seshu.kumar.m@huawei.com>
adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeAbstract.java
adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeAbstract.java
mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java

index 666509e..f40c7d9 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP - SO\r
  * ================================================================================\r
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.\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
@@ -23,9 +24,11 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;\r
 \r
 import org.openecomp.mso.cloud.authentication.AuthenticationWrapper;\r
+import org.openecomp.mso.logger.MsoLogger;\r
 \r
 public abstract class IdentityAuthenticationTypeAbstract {\r
 \r
+       private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH);\r
        // This map will prevent duplicates (as if it was an Enum).\r
        // Without this, using an instance specific field for the class could allow\r
        // different classes bound to the same entry name.\r
@@ -42,7 +45,7 @@ public abstract class IdentityAuthenticationTypeAbstract {
                        entries.put(identityType, this);\r
                        AuthenticationWrapper.register(this.toString(), wrapperClass);\r
                } catch (IllegalAccessException | InstantiationException e) {\r
-                       // Do not add the class if an exception occurs as we won't get the class anyway\r
+                       LOGGER.debug("Exception in Identity Authentication",e);\r
                }\r
        }\r
 \r
@@ -72,4 +75,12 @@ public abstract class IdentityAuthenticationTypeAbstract {
                return ((this.identityType != null) && (other != null) && (other instanceof IdentityAuthenticationTypeAbstract) && (this.identityType.equals(other.toString())));\r
        }\r
 \r
+       @Override\r
+       public int hashCode() {\r
+               final int prime = 31;\r
+               int result = 1;\r
+               result = prime * result + ((identityType == null) ? 0 : identityType.hashCode());\r
+               return result;\r
+       }\r
+\r
 }\r
index a4cd124..ad909a7 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP - SO\r
  * ================================================================================\r
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.\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
@@ -74,4 +75,11 @@ public abstract class IdentityServerTypeAbstract {
                return ((this.serverType != null) && (other != null) && (other instanceof IdentityServerTypeAbstract) && (this.serverType.equals(other.toString())));\r
        }\r
 \r
+       @Override\r
+       public int hashCode() {\r
+        final int prime = 31;\r
+        int result = 1;\r
+        result = prime * result + ((serverType == null) ? 0 : serverType.hashCode());\r
+        return result;\r
+    }\r
 }\r
index b950c1b..8db4548 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP - SO
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -519,9 +520,7 @@ public class RequestsDatabase {
             }
             session.getTransaction ().commit ();
         } finally {
-            if (session != null && session.isOpen ()) {
-                session.close ();
-            }
+            session.close ();
             msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "RequestDB", "updateSiteStatus", null);
         }
     }
@@ -588,9 +587,7 @@ public class RequestsDatabase {
             }
             session.getTransaction().commit();
         } finally {
-            if(session != null && session.isOpen()) {
-                session.close();
-            }
+            session.close();
             msoLogger.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
                     "Successfully", "RequestDB", "updateOperationStatus", null);
         }
@@ -663,9 +660,7 @@ public class RequestsDatabase {
             }
             session.getTransaction().commit();
         } finally {
-            if(session != null && session.isOpen()) {
-                session.close();
-            }
+            session.close();
             msoLogger.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
                     "Successfully", "RequestDB", "updateResOperStatus", null);
         }
@@ -720,9 +715,7 @@ public class RequestsDatabase {
             }
             updateOperationStatus(serviceOperStatus);
         } finally {
-            if(session != null && session.isOpen()) {
-                session.close();
-            }
+            session.close();
             msoLogger.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
                     "Successfully", "RequestDB", "updateResOperStatus", null);
         }