Sonar fixes 35/38035/1
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Fri, 23 Mar 2018 10:12:50 +0000 (11:12 +0100)
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Fri, 23 Mar 2018 10:12:50 +0000 (11:12 +0100)
Rework the class due to sonar report

Issue-ID: CLAMP-81
Change-Id: I5f99728b3aa1c194d0bf7b2cf727e8dbdf99684f
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java

index f8fef39..d093626 100644 (file)
@@ -56,10 +56,14 @@ import org.openecomp.sdc.utils.DistributionStatusEnum;
 public class SdcSingleController {\r
 \r
     private static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcSingleController.class);\r
-    protected boolean isAsdcClientAutoManaged = false;\r
-    protected CsarInstaller csarInstaller;\r
-    protected ClampProperties refProp;\r
+    private boolean isAsdcClientAutoManaged = false;\r
+    private CsarInstaller csarInstaller;\r
+    private ClampProperties refProp;\r
     public static final String CONFIG_SDC_FOLDER = "sdc.csarFolder";\r
+    private int nbOfNotificationsOngoing = 0;\r
+    private SdcSingleControllerStatus controllerStatus = SdcSingleControllerStatus.STOPPED;\r
+    private SdcSingleControllerConfiguration sdcConfig;\r
+    private IDistributionClient distributionClient;\r
 \r
     /**\r
      * Inner class for Notification callback\r
@@ -88,14 +92,18 @@ public class SdcSingleController {
         }\r
     }\r
 \r
-    // ***** Controller STATUS code\r
-    protected int nbOfNotificationsOngoing = 0;\r
-\r
     public int getNbOfNotificationsOngoing() {\r
         return nbOfNotificationsOngoing;\r
     }\r
 \r
-    private SdcSingleControllerStatus controllerStatus = SdcSingleControllerStatus.STOPPED;\r
+    private void changeControllerStatusIdle() {\r
+        if (this.nbOfNotificationsOngoing > 1) {\r
+            --this.nbOfNotificationsOngoing;\r
+        } else {\r
+            this.nbOfNotificationsOngoing = 0;\r
+            this.controllerStatus = SdcSingleControllerStatus.IDLE;\r
+        }\r
+    }\r
 \r
     protected final synchronized void changeControllerStatus(SdcSingleControllerStatus newControllerStatus) {\r
         switch (newControllerStatus) {\r
@@ -104,12 +112,7 @@ public class SdcSingleController {
                 this.controllerStatus = newControllerStatus;\r
                 break;\r
             case IDLE:\r
-                if (this.nbOfNotificationsOngoing > 1) {\r
-                    --this.nbOfNotificationsOngoing;\r
-                } else {\r
-                    this.nbOfNotificationsOngoing = 0;\r
-                    this.controllerStatus = newControllerStatus;\r
-                }\r
+                this.changeControllerStatusIdle();\r
                 break;\r
             default:\r
                 this.controllerStatus = newControllerStatus;\r
@@ -121,10 +124,6 @@ public class SdcSingleController {
         return this.controllerStatus;\r
     }\r
 \r
-    // ***** END of Controller STATUS code\r
-    protected SdcSingleControllerConfiguration sdcConfig;\r
-    private IDistributionClient distributionClient;\r
-\r
     public SdcSingleController(ClampProperties clampProp, CsarInstaller csarInstaller,\r
             SdcSingleControllerConfiguration sdcSingleConfig, boolean isClientAutoManaged) {\r
         this.isAsdcClientAutoManaged = isClientAutoManaged;\r
@@ -234,10 +233,11 @@ public class SdcSingleController {
                     e.getMessage(), System.currentTimeMillis());\r
         } catch (CsarHandlerException e) {\r
             logger.error("CsarHandlerException exception caught during the notification processing", e);\r
-            this.sendASDCNotification(NotificationType.DOWNLOAD, csar.getArtifactElement().getArtifactURL(),\r
-                    sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.DOWNLOAD_ERROR,\r
-                    e.getMessage(), System.currentTimeMillis());\r
+            this.sendASDCNotification(NotificationType.DOWNLOAD, null, sdcConfig.getConsumerID(),\r
+                    iNotif.getDistributionID(), DistributionStatusEnum.DOWNLOAD_ERROR, e.getMessage(),\r
+                    System.currentTimeMillis());\r
         } catch (SdcToscaParserException e) {\r
+            logger.error("SdcToscaParserException exception caught during the notification processing", e);\r
             this.sendASDCNotification(NotificationType.DEPLOY, csar.getArtifactElement().getArtifactURL(),\r
                     sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.DEPLOY_ERROR,\r
                     e.getMessage(), System.currentTimeMillis());\r
@@ -291,19 +291,11 @@ public class SdcSingleController {
                     status, timestamp);\r
             switch (notificationType) {\r
                 case DOWNLOAD:\r
-                    if (errorReason != null) {\r
-                        this.distributionClient.sendDownloadStatus(message, errorReason);\r
-                    } else {\r
-                        this.distributionClient.sendDownloadStatus(message);\r
-                    }\r
+                    this.sendDownloadStatus(message, errorReason);\r
                     action = "sendDownloadStatus";\r
                     break;\r
                 case DEPLOY:\r
-                    if (errorReason != null) {\r
-                        this.distributionClient.sendDeploymentStatus(message, errorReason);\r
-                    } else {\r
-                        this.distributionClient.sendDeploymentStatus(message);\r
-                    }\r
+                    this.sendDeploymentStatus(message, errorReason);\r
                     action = "sendDeploymentdStatus";\r
                     break;\r
                 default:\r
@@ -314,4 +306,20 @@ public class SdcSingleController {
         }\r
         logger.info("Sdc Notification sent successfully(" + action + ")");\r
     }\r
+\r
+    private void sendDownloadStatus(IDistributionStatusMessage message, String errorReason) {\r
+        if (errorReason != null) {\r
+            this.distributionClient.sendDownloadStatus(message, errorReason);\r
+        } else {\r
+            this.distributionClient.sendDownloadStatus(message);\r
+        }\r
+    }\r
+\r
+    private void sendDeploymentStatus(IDistributionStatusMessage message, String errorReason) {\r
+        if (errorReason != null) {\r
+            this.distributionClient.sendDeploymentStatus(message, errorReason);\r
+        } else {\r
+            this.distributionClient.sendDeploymentStatus(message);\r
+        }\r
+    }\r
 }\r