Fix Bug 2121: NG-UI uses unmaintained Chokidar version
[osm/NG-UI.git] / src / app / instances / ns-primitive / NSPrimitiveComponent.ts
index bfbbe40..8f39a20 100644 (file)
@@ -18,6 +18,7 @@
 /**
  * @file NS Instance Primitive Component
  */
+import { isNullOrUndefined } from 'util';
 import { Component, Injector, Input, OnInit } from '@angular/core';
 import { AbstractControl, FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms';
 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
@@ -30,8 +31,8 @@ import { KDUPRIMITIVELEVEL, NSData, VDUPRIMITIVELEVEL, VNFPROFILE } from 'NSDMod
 import { NSPrimitiveParams } from 'NSInstanceModel';
 import { RestService } from 'RestService';
 import { SharedService } from 'SharedService';
-import { isNullOrUndefined } from 'util';
 import { CONFIGPRIMITIVE, DF, VDUCONFIG, VDUPROFILE, VNFCONFIG, VNFD } from 'VNFDModel';
+import { VNFInstanceDetails } from 'VNFInstanceModel';
 
 /**
  * Creating component
@@ -88,6 +89,15 @@ export class NSPrimitiveComponent implements OnInit {
     /** Contains list of KDU primitive lists @public */
     public kduList: {}[];
 
+    /** Array holds MemberVNFIndex values @public */
+    public memberVnfIndex: {}[] = [];
+
+    /** Array holds VNFR Data filtered with nsr ID @public */
+    public nsIdFilteredData: {}[] = [];
+
+    /** Items for the memberVNFIndex data @public */
+    public memberTypes: {}[];
+
     /** FormBuilder instance added to the formBuilder @private */
     private formBuilder: FormBuilder;
 
@@ -151,6 +161,7 @@ export class NSPrimitiveComponent implements OnInit {
                 this.nsdId = event.identifier;
             }
         });
+        this.getMemberVnfIndex();
         this.initializeForm();
     }
 
@@ -206,19 +217,19 @@ export class NSPrimitiveComponent implements OnInit {
             primitive_params: this.objectPrimitiveParams
         };
         if (this.primitiveType === 'VNF_Primitive') {
-            // tslint:disable-next-line: no-string-literal
+            // eslint-disable-next-line @typescript-eslint/dot-notation
             primitiveParamsPayLoads['member_vnf_index'] = this.primitiveForm.value.member_vnf_index;
         }
         if (this.primitiveType === 'VDU_Primitive') {
-            // tslint:disable-next-line: no-string-literal
+            // eslint-disable-next-line @typescript-eslint/dot-notation
             primitiveParamsPayLoads['member_vnf_index'] = this.primitiveForm.value.member_vnf_index;
-            // tslint:disable-next-line: no-string-literal
+            // eslint-disable-next-line @typescript-eslint/dot-notation
             primitiveParamsPayLoads['vdu_id'] = this.primitiveForm.value.vdu_id;
         }
         if (this.primitiveType === 'KDU_Primitive') {
-            // tslint:disable-next-line: no-string-literal
+            // eslint-disable-next-line @typescript-eslint/dot-notation
             primitiveParamsPayLoads['member_vnf_index'] = this.primitiveForm.value.member_vnf_index;
-            // tslint:disable-next-line: no-string-literal
+            // eslint-disable-next-line @typescript-eslint/dot-notation
             primitiveParamsPayLoads['kdu_name'] = this.primitiveForm.value.kdu_name;
         }
         const apiURLHeader: APIURLHEADER = {
@@ -234,6 +245,36 @@ export class NSPrimitiveComponent implements OnInit {
             this.restService.handleError(error, 'post');
         });
     }
+    /** Getting MemberVnfIndex using VNFDescriptor API @public */
+    public getMemberVnfIndex(): void {
+        const vnfInstanceData: {}[] = [];
+        this.restService.getResource(environment.VNFINSTANCES_URL).subscribe((vnfInstancesData: VNFInstanceDetails[]): void => {
+            vnfInstancesData.forEach((vnfData: VNFInstanceDetails): void => {
+                const vnfDataObj: {} =
+                {
+                    'vnf-ref': vnfData['vnfd-ref'],
+                    'vnf-id': vnfData._id,
+                    'member-index': vnfData['member-vnf-index-ref']
+                };
+                vnfInstanceData.push(vnfDataObj);
+            });
+            for (const id of this.params.id) {
+                this.nsIdFilteredData = vnfInstanceData.filter((vnfdData: {}[]): boolean => vnfdData['vnf-id'] === id);
+                this.nsIdFilteredData.forEach((resVNF: {}[]): void => {
+                    const assignMemberIndex: {} = {
+                        id: resVNF['member-index'],
+                        'vnf-ref': resVNF['vnf-ref']
+                    };
+                    this.memberVnfIndex.push(assignMemberIndex);
+                });
+            }
+            this.memberTypes = this.memberVnfIndex;
+            this.isLoadingResults = false;
+        }, (error: ERRORDATA): void => {
+            this.restService.handleError(error, 'get');
+            this.isLoadingResults = false;
+        });
+    }
     /** Primitive type change event @public */
     public primitiveTypeChange(data: PRIMITIVETYPES): void {
         this.primitiveList = [];
@@ -254,8 +295,8 @@ export class NSPrimitiveComponent implements OnInit {
     public indexChange(data: VNFPROFILE, getType?: string): void {
         this.getFormControl('vdu_id').setValue(null);
         this.getFormControl('kdu_name').setValue(null);
-        if (data['vnfd-id'] !== null) {
-            this.getVnfdInfo(data['vnfd-id'], getType);
+        if (data['vnf-ref'] !== null) {
+            this.getVnfdInfo(data['vnf-ref'], getType);
         } else {
             this.primitiveList = [];
             this.getFormControl('primitive').setValue(null);
@@ -277,21 +318,19 @@ export class NSPrimitiveComponent implements OnInit {
         }
     }
     /** Generate vdu section @public */
-    public generateVDUData(vduData: VDUPROFILE, vduConfig: VDUCONFIG[]): VDUPROFILE {
-        const getVDUConfig: VDUCONFIG = vduConfig.filter((itemData: VDUCONFIG): boolean =>
-            itemData.id === vduData['vdu-configuration-id'])[0];
+    public generateVDUData(vduConfig: VDUCONFIG): VDUPROFILE {
         return {
-            id: vduData.id,
-            name: vduData.id,
-            'vdu-configuration': getVDUConfig
+            id: vduConfig.id,
+            name: vduConfig.id,
+            'vdu-configuration': vduConfig
         };
     }
     /** Generate kdu section @public */
-    public generateKDUData(kduData: KDUPRIMITIVELEVEL): KDUPRIMITIVELEVEL {
+    public generateKDUData(kduData: KDUPRIMITIVELEVEL, kduConfig: VDUCONFIG): KDUPRIMITIVELEVEL {
         return {
             name: kduData.name,
             'juju-bundle': kduData['juju-bundle'],
-            'kdu-configuration': kduData['kdu-configuration']
+            'kdu-configuration': kduConfig
         };
     }
     /** Used to set the validation and value and update the validation and value @public */
@@ -321,53 +360,61 @@ export class NSPrimitiveComponent implements OnInit {
         this.getFormControl('primitive').setValue(null);
         const apiUrl: string = environment.VNFPACKAGES_URL + '?id=' + vnfdRef;
         this.isLoadingResults = true;
-        this.restService.getResource(apiUrl)
-            .subscribe((vnfdInfo: VNFD[]): void => {
-                const vnfInstances: VNFD = vnfdInfo[0];
-                if (!isNullOrUndefined(vnfInstances.df) && !isNullOrUndefined(vnfInstances['vnf-configuration'])) {
-                    this.getFormControl('vdu_id').setValidators([]);
-                    this.getFormControl('kdu_name').setValidators([]);
-                    vnfInstances.df.forEach((df: DF): void => {
-                        if (df['vnf-configuration-id'] !== undefined) {
-                            const vnfprimitiveList: VNFCONFIG = vnfInstances['vnf-configuration']
-                                .filter((itemData: VNFCONFIG): boolean => itemData.id === df['vnf-configuration-id'])[0];
-                            this.primitiveList = vnfprimitiveList['config-primitive'];
-                        }
-                    });
-                }
-                if (getType === 'VDU_Primitive') {
-                    this.kduList = [];
-                    this.vduList = [];
-                    this.primitiveList = [];
-                    if (!isNullOrUndefined(vnfInstances.df) && !isNullOrUndefined(vnfInstances['vdu-configuration'])) {
-                        vnfInstances.df.forEach((df: DF): void => {
-                            if (df['vdu-profile'] !== undefined) {
-                                df['vdu-profile'].forEach((element: VDUPROFILE): void => {
-                                    const vduDataObj: VDUPROFILE = this.generateVDUData(element, vnfInstances['vdu-configuration']);
-                                    this.vduList.push(vduDataObj);
-                                });
+        this.restService.getResource(apiUrl).subscribe((vnfdInfo: VNFD[]): void => {
+            const vnfInstances: VNFD = vnfdInfo[0];
+            if (!isNullOrUndefined(vnfInstances.df)) {
+                this.getFormControl('vdu_id').setValidators([]);
+                this.getFormControl('kdu_name').setValidators([]);
+                vnfInstances.df.forEach((df: DF): void => {
+                    if (df['lcm-operations-configuration'] !== undefined) {
+                        if (df['lcm-operations-configuration']['operate-vnf-op-config'] !== undefined) {
+                            const day12Operation: VDUCONFIG[] = df['lcm-operations-configuration']['operate-vnf-op-config']['day1-2'];
+                            if (day12Operation !== undefined) {
+                                const vnfprimitiveList: VNFCONFIG = day12Operation
+                                    .filter((itemData: VNFCONFIG): boolean => itemData.id === vnfInstances.id)[0];
+                                if (vnfprimitiveList !== undefined) {
+                                    this.primitiveList = vnfprimitiveList['config-primitive'];
+                                }
+                                /** VDU Primitive */
+                                if (getType === 'VDU_Primitive') {
+                                    this.kduList = [];
+                                    this.vduList = [];
+                                    this.primitiveList = [];
+                                    df['vdu-profile'].forEach((vduProfile: VDUPROFILE): void => {
+                                        day12Operation.forEach((element: VDUCONFIG): void => {
+                                            if (element.id === vduProfile.id) {
+                                                const vduDataObj: VDUPROFILE = this.generateVDUData(element);
+                                                this.vduList.push(vduDataObj);
+                                            }
+                                        });
+                                    });
+                                }
+                                /** KDU Primitive */
+                                if (getType === 'KDU_Primitive') {
+                                    this.kduList = [];
+                                    this.vduList = [];
+                                    this.primitiveList = [];
+                                    if (!isNullOrUndefined(vnfInstances.kdu)) {
+                                        vnfInstances.kdu.forEach((kduData: KDUPRIMITIVELEVEL): void => {
+                                            day12Operation.forEach((element: VDUCONFIG): void => {
+                                                if (element.id === kduData.name) {
+                                                    const kduDataObj: KDUPRIMITIVELEVEL = this.generateKDUData(kduData, element);
+                                                    this.kduList.push(kduDataObj);
+                                                }
+                                            });
+                                        });
+                                    }
+                                }
                             }
-                        });
-                    }
-                }
-                if (getType === 'KDU_Primitive') {
-                    this.kduList = [];
-                    this.vduList = [];
-                    this.primitiveList = [];
-                    if (!isNullOrUndefined(vnfInstances.kdu)) {
-                        vnfInstances.kdu.forEach((kduData: KDUPRIMITIVELEVEL): void => {
-                            if (kduData['kdu-configuration']) {
-                                const kduDataObj: KDUPRIMITIVELEVEL = this.generateKDUData(kduData);
-                                this.kduList.push(kduDataObj);
-                            }
-                        });
+                        }
                     }
-                }
-                this.isLoadingResults = false;
-            }, (error: ERRORDATA): void => {
-                this.isLoadingResults = false;
-                this.restService.handleError(error, 'get');
-            });
+                });
+            }
+            this.isLoadingResults = false;
+        }, (error: ERRORDATA): void => {
+            this.isLoadingResults = false;
+            this.restService.handleError(error, 'get');
+        });
     }
     /** Get primivitive actions from NSD data */
     private getNSInfo(nsdRef: string): void {
@@ -392,6 +439,7 @@ export class NSPrimitiveComponent implements OnInit {
     }
     /** Used to get the AbstractControl of controlName passed @private */
     private getFormControl(controlName: string): AbstractControl {
+        // eslint-disable-next-line security/detect-object-injection
         return this.primitiveForm.controls[controlName];
     }
 }