Sonar fixes

Rework the class due to sonar report

Issue-ID: CLAMP-81
Change-Id: I5f99728b3aa1c194d0bf7b2cf727e8dbdf99684f
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java
index f8fef39..d093626 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java
@@ -56,10 +56,14 @@
 public class SdcSingleController {

 

     private static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcSingleController.class);

-    protected boolean isAsdcClientAutoManaged = false;

-    protected CsarInstaller csarInstaller;

-    protected ClampProperties refProp;

+    private boolean isAsdcClientAutoManaged = false;

+    private CsarInstaller csarInstaller;

+    private ClampProperties refProp;

     public static final String CONFIG_SDC_FOLDER = "sdc.csarFolder";

+    private int nbOfNotificationsOngoing = 0;

+    private SdcSingleControllerStatus controllerStatus = SdcSingleControllerStatus.STOPPED;

+    private SdcSingleControllerConfiguration sdcConfig;

+    private IDistributionClient distributionClient;

 

     /**

      * Inner class for Notification callback

@@ -88,14 +92,18 @@
         }

     }

 

-    // ***** Controller STATUS code

-    protected int nbOfNotificationsOngoing = 0;

-

     public int getNbOfNotificationsOngoing() {

         return nbOfNotificationsOngoing;

     }

 

-    private SdcSingleControllerStatus controllerStatus = SdcSingleControllerStatus.STOPPED;

+    private void changeControllerStatusIdle() {

+        if (this.nbOfNotificationsOngoing > 1) {

+            --this.nbOfNotificationsOngoing;

+        } else {

+            this.nbOfNotificationsOngoing = 0;

+            this.controllerStatus = SdcSingleControllerStatus.IDLE;

+        }

+    }

 

     protected final synchronized void changeControllerStatus(SdcSingleControllerStatus newControllerStatus) {

         switch (newControllerStatus) {

@@ -104,12 +112,7 @@
                 this.controllerStatus = newControllerStatus;

                 break;

             case IDLE:

-                if (this.nbOfNotificationsOngoing > 1) {

-                    --this.nbOfNotificationsOngoing;

-                } else {

-                    this.nbOfNotificationsOngoing = 0;

-                    this.controllerStatus = newControllerStatus;

-                }

+                this.changeControllerStatusIdle();

                 break;

             default:

                 this.controllerStatus = newControllerStatus;

@@ -121,10 +124,6 @@
         return this.controllerStatus;

     }

 

-    // ***** END of Controller STATUS code

-    protected SdcSingleControllerConfiguration sdcConfig;

-    private IDistributionClient distributionClient;

-

     public SdcSingleController(ClampProperties clampProp, CsarInstaller csarInstaller,

             SdcSingleControllerConfiguration sdcSingleConfig, boolean isClientAutoManaged) {

         this.isAsdcClientAutoManaged = isClientAutoManaged;

@@ -234,10 +233,11 @@
                     e.getMessage(), System.currentTimeMillis());

         } catch (CsarHandlerException e) {

             logger.error("CsarHandlerException exception caught during the notification processing", e);

-            this.sendASDCNotification(NotificationType.DOWNLOAD, csar.getArtifactElement().getArtifactURL(),

-                    sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.DOWNLOAD_ERROR,

-                    e.getMessage(), System.currentTimeMillis());

+            this.sendASDCNotification(NotificationType.DOWNLOAD, null, sdcConfig.getConsumerID(),

+                    iNotif.getDistributionID(), DistributionStatusEnum.DOWNLOAD_ERROR, e.getMessage(),

+                    System.currentTimeMillis());

         } catch (SdcToscaParserException e) {

+            logger.error("SdcToscaParserException exception caught during the notification processing", e);

             this.sendASDCNotification(NotificationType.DEPLOY, csar.getArtifactElement().getArtifactURL(),

                     sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.DEPLOY_ERROR,

                     e.getMessage(), System.currentTimeMillis());

@@ -291,19 +291,11 @@
                     status, timestamp);

             switch (notificationType) {

                 case DOWNLOAD:

-                    if (errorReason != null) {

-                        this.distributionClient.sendDownloadStatus(message, errorReason);

-                    } else {

-                        this.distributionClient.sendDownloadStatus(message);

-                    }

+                    this.sendDownloadStatus(message, errorReason);

                     action = "sendDownloadStatus";

                     break;

                 case DEPLOY:

-                    if (errorReason != null) {

-                        this.distributionClient.sendDeploymentStatus(message, errorReason);

-                    } else {

-                        this.distributionClient.sendDeploymentStatus(message);

-                    }

+                    this.sendDeploymentStatus(message, errorReason);

                     action = "sendDeploymentdStatus";

                     break;

                 default:

@@ -314,4 +306,20 @@
         }

         logger.info("Sdc Notification sent successfully(" + action + ")");

     }

+

+    private void sendDownloadStatus(IDistributionStatusMessage message, String errorReason) {

+        if (errorReason != null) {

+            this.distributionClient.sendDownloadStatus(message, errorReason);

+        } else {

+            this.distributionClient.sendDownloadStatus(message);

+        }

+    }

+

+    private void sendDeploymentStatus(IDistributionStatusMessage message, String errorReason) {

+        if (errorReason != null) {

+            this.distributionClient.sendDeploymentStatus(message, errorReason);

+        } else {

+            this.distributionClient.sendDeploymentStatus(message);

+        }

+    }

 }