replaced if else logic to switch case 07/56507/3
authorSandeep J <sandeejh@in.ibm.com>
Mon, 16 Jul 2018 11:57:52 +0000 (17:27 +0530)
committerTakamune Cho <tc012c@att.com>
Mon, 16 Jul 2018 18:00:34 +0000 (18:00 +0000)
Replaced the if else logic in decideExtension and populateExistinAction
method with switch case for better presentation of the code as part of
plan for reference dataform code refactor

Issue-ID: APPC-1085
Change-Id: I002e61d53585ba61b96e1e6cb0f12443498df6e9
Signed-off-by: Sandeep J <sandeejh@in.ibm.com>
src/app/vnfs/build-artifacts/reference-dataform/reference-dataform.component.ts

index acd99e0..e625ebd 100644 (file)
@@ -3,7 +3,8 @@
 ===================================================================
 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
 ===================================================================
-
+Copyright (C) 2018 IBM.
+===================================================================
 Unless otherwise specified, all software contained herein is licensed
 under the Apache License, Version 2.0 (the License);
 you may not use this software except in compliance with the License.
@@ -401,7 +402,7 @@ export class ReferenceDataformComponent implements OnInit {
     //Reference object to create reference data
     prepareReferenceObject(isSaving?: any) {
         let scopeName = this.resetParamsOnVnfcType();
-        let extension = this.decideExtension();
+        let extension = this.decideExtension(this.referenceDataObject);
         this.prepareArtifactList(scopeName, extension);
         if (this.referenceDataObject.action === 'OpenStack Actions') {
             this.referenceDataObject['template'] = 'N';
@@ -832,7 +833,7 @@ export class ReferenceDataformComponent implements OnInit {
             let obj = $.extend(true, {}, this.tempAllData[existAction]);
             this.referenceDataObject = obj;
             this.referenceDataObject.scope['vnf-type'] = obj['scope']['vnf-type'];
-            this.referenceDataObject.scope['vnfc-type'] = obj['scope']['vnfc-type'];
+            this.referenceDataObject.scope['vnfc-type-list'] = obj['scope']['vnfc-type-list'];
             this.referenceDataObject['device-protocol'] = obj['device-protocol'];
             this.refernceScopeObj['sourceType'] = obj['scopeType'];
         } else {
@@ -840,19 +841,34 @@ export class ReferenceDataformComponent implements OnInit {
             this.referenceDataObject.action = data;
         }
         //# iof healthCeck change deviceprotocol drp vaues
-        if (data == 'HealthCheck') {
-            this.deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'REST'];
-            this.actionHealthCheck = true;
-        } else if (data == 'UpgradeBackout' || data == 'ResumeTraffic' || data == 'QuiesceTraffic' || data == 'UpgradeBackup' || data == 'UpgradePostCheck' || data == 'UpgradePreCheck' || data == 'UpgradeSoftware' || data == 'ConfigBackup' || data == 'ConfigRestore' || data == 'StartApplication' || data == 'StopApplication' || data == 'GetRunningConfig') {
-            this.deviceProtocols = ['', 'CHEF', 'ANSIBLE'];
-        } else if (data == 'OpenStack Actions') {
-            this.deviceProtocols = ['', 'OpenStack'];
-        } else if (data == 'ConfigScaleOut') {
-            this.deviceProtocols = ['', 'CHEF', 'ANSIBLE', 'NETCONF-XML', 'RESTCONF'];
-        }
-        else {
-            this.deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'NETCONF-XML', 'RESTCONF', 'CLI'];
-            this.actionHealthCheck = false;
+        switch (data) {
+            case 'HealthCheck':
+                this.deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'REST'];
+                this.actionHealthCheck = true;
+                break;
+            case 'UpgradeBackout':
+            case 'ResumeTraffic':
+            case 'QuiesceTraffic':
+            case 'UpgradeBackup':
+            case 'UpgradePostCheck':
+            case 'UpgradePreCheck':
+            case 'UpgradeSoftware':
+            case 'ConfigRestore':
+            case 'StartApplication':
+            case 'StopApplication':
+            case 'GetRunningConfig':
+            case 'ConfigBackup':
+                this.deviceProtocols = ['', 'CHEF', 'ANSIBLE'];
+                break;
+            case 'OpenStack Actions':
+                this.deviceProtocols = ['', 'OpenStack'];
+                break;
+            case 'ConfigScaleOut':
+                this.deviceProtocols = ['', 'CHEF', 'ANSIBLE', 'NETCONF-XML', 'RESTCONF'];
+                break;
+            default:
+                this.deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'NETCONF-XML', 'RESTCONF', 'CLI'];
+                this.actionHealthCheck = false;
         }
     }
 
@@ -1175,15 +1191,21 @@ export class ReferenceDataformComponent implements OnInit {
         }
         return scopeName
     }
-    decideExtension() {
+    decideExtension(obj) {
         //marking the extension based on the device-protocol selected by the user 
-        let extension = 'json';
-        if (this.referenceDataObject['device-protocol'] == 'ANSIBLE' || this.referenceDataObject['device-protocol'] == 'CHEF' || this.referenceDataObject['device-protocol'] == 'CLI') {
-            extension = 'json';
-        } else if (this.referenceDataObject['device-protocol'] == 'NETCONF-XML' || this.referenceDataObject['device-protocol'] == 'REST') {
-            extension = 'xml';
+        let extension = '.json';
+        switch (obj['device-protocol']) {
+            case 'ANSIBLE':
+            case 'CHEF':
+            case 'CLI':
+                extension = '.json';
+                break;
+            case 'NETCONF-XML':
+            case 'REST':
+                extension = '.xml';
+                break;
         }
-        return extension
+        return extension;
     }
     prepareArtifactList(scopeName, extension) {
         this.referenceDataObject['artifact-list'] = [];