BUG 1175 Unable to execute VNF-Level Primitives
[osm/NG-UI.git] / src / app / instances / ns-primitive / NSPrimitiveComponent.ts
index 4b9616b..1086f49 100644 (file)
@@ -115,6 +115,10 @@ export class NSPrimitiveComponent implements OnInit {
         this.activeModal = this.injector.get(NgbActiveModal);
         this.formBuilder = this.injector.get(FormBuilder);
         this.primitiveTypeList = [
+            {
+                title: this.translateService.instant('NSPRIMITIVE'),
+                value: 'NS_Primitive'
+            },
             {
                 title: this.translateService.instant('VNFPRIMITIVE'),
                 value: 'VNF_Primitive'
@@ -124,7 +128,6 @@ export class NSPrimitiveComponent implements OnInit {
                 value: 'VDU_Primitive'
             }
         ];
-        this.primitiveType = 'VNF_Primitive';
     }
 
     /**
@@ -137,9 +140,6 @@ export class NSPrimitiveComponent implements OnInit {
                 this.nsdId = event.identifier;
             }
         });
-        if (!isNullOrUndefined(this.params.nsConfig)) {
-            this.primitiveTypeList.push({ title: this.translateService.instant('NSPRIMITIVE'), value: 'NS_Primitive' });
-        }
         this.initializeForm();
     }
 
@@ -225,10 +225,14 @@ export class NSPrimitiveComponent implements OnInit {
         this.primitiveParameter = [];
         this.initializeForm();
         if (data.value === 'NS_Primitive') {
-            this.primitiveList = !isNullOrUndefined(this.params.nsConfig['config-primitive']) ?
-                this.params.nsConfig['config-primitive'] : [];
+            this.getNSInfo(this.params.name);
             this.getFormControl('vnf_member_index').setValidators([]);
+            this.getFormControl('vnf_member_index').updateValueAndValidity();
+            this.getFormControl('vdu_id').setValidators([]);
+            this.getFormControl('vdu_id').updateValueAndValidity();
+        } else if (data.value === 'VNF_Primitive') {
             this.getFormControl('vdu_id').setValidators([]);
+            this.getFormControl('vdu_id').updateValueAndValidity();
         }
     }
     /** Member index change event */
@@ -288,12 +292,13 @@ export class NSPrimitiveComponent implements OnInit {
         this.isLoadingResults = true;
         this.restService.getResource(apiUrl)
             .subscribe((vnfdInfo: {}) => {
-                if (vnfdInfo[0]['vnf-configuration']) {
+                if (vnfdInfo[0]['vnf-configuration'] !== undefined && vnfdInfo[0]['vnf-configuration']) {
                     this.getFormControl('vdu_id').setValidators([]);
                     this.primitiveList = vnfdInfo[0]['vnf-configuration']['config-primitive'];
                 }
                 if (getType === 'VDU_Primitive') {
                     this.vduList = [];
+                    this.primitiveList = [];
                     vnfdInfo[0].vdu.forEach((vduData: VDUPRIMITIVELEVEL) => {
                         if (vduData['vdu-configuration']) {
                             const vduDataObj: VDUPRIMITIVELEVEL = this.generateVDUData(vduData);
@@ -307,6 +312,27 @@ export class NSPrimitiveComponent implements OnInit {
                 this.restService.handleError(error, 'get');
             });
     }
+    /** Get primivitive actions from NSD data */
+    private getNSInfo(nsdRef: string): void {
+        this.primitiveList = [];
+        this.primitiveParameter = [];
+        this.getFormControl('primitive').setValue(null);
+        const apiUrl: string = environment.NSDESCRIPTORS_URL + '?short-name=' + nsdRef;
+        this.isLoadingResults = true;
+        this.restService.getResource(apiUrl)
+            .subscribe((nsdInfo: {}) => {
+                if (!isNullOrUndefined(nsdInfo[0]['ns-configuration'])) {
+                    this.primitiveList = !isNullOrUndefined(nsdInfo[0]['ns-configuration']['config-primitive']) ?
+                    nsdInfo[0]['ns-configuration']['config-primitive'] : [];
+                } else {
+                    this.primitiveList = [];
+                }
+                this.isLoadingResults = false;
+            }, (error: ERRORDATA) => {
+                this.isLoadingResults = false;
+                this.restService.handleError(error, 'get');
+            });
+    }
     /** Used to get the AbstractControl of controlName passed @private */
     private getFormControl(controlName: string): AbstractControl {
         return this.primitiveForm.controls[controlName];