X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Fapp%2Finstances%2Fns-primitive%2FNSPrimitiveComponent.ts;h=c8b7fed622f4d63de30159c6d5a808672d45053b;hb=4ae768c9496f8146e1e843e3294c780c0666737e;hp=d5cf56559af022aa7625c5578e3800eb6f9f0f16;hpb=1db2e54394d3400d264e07e15e288f46f33eff65;p=osm%2FNG-UI.git diff --git a/src/app/instances/ns-primitive/NSPrimitiveComponent.ts b/src/app/instances/ns-primitive/NSPrimitiveComponent.ts index d5cf565..c8b7fed 100644 --- a/src/app/instances/ns-primitive/NSPrimitiveComponent.ts +++ b/src/app/instances/ns-primitive/NSPrimitiveComponent.ts @@ -23,14 +23,15 @@ import { AbstractControl, FormArray, FormBuilder, FormGroup, Validators } from ' import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import { TranslateService } from '@ngx-translate/core'; import { NotifierService } from 'angular-notifier'; -import { APIURLHEADER, ERRORDATA, URLPARAMS } from 'CommonModel'; +import { APIURLHEADER, ERRORDATA, PRIMITIVEDATA, PRIMITIVETYPES, URLPARAMS } from 'CommonModel'; import { DataService } from 'DataService'; import { environment } from 'environment'; -import { KDUPRIMITIVELEVEL, NSData, VDUPRIMITIVELEVEL } from 'NSDModel'; +import { KDUPRIMITIVELEVEL, NSData, VDUPRIMITIVELEVEL, VNFPROFILE } from 'NSDModel'; 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'; /** * Creating component @@ -76,13 +77,13 @@ export class NSPrimitiveComponent implements OnInit { public primitiveList: {}[]; /** Contains objects that is used to hold types of primitive @public */ - public primitiveTypeList: {}[] = []; + public primitiveTypeList: PRIMITIVETYPES[] = []; /** Model value used to hold selected primitive type @public */ public primitiveType: string; /** Contains list of VDU primitive lists @public */ - public vduList: {}[]; + public vduList: VDUPROFILE[]; /** Contains list of KDU primitive lists @public */ public kduList: {}[]; @@ -137,12 +138,15 @@ export class NSPrimitiveComponent implements OnInit { ]; } + /** convenience getter for easy access to form fields */ + get f(): FormGroup['controls'] { return this.primitiveForm.controls; } + /** * Lifecyle Hooks the trigger before component is instantiate */ public ngOnInit(): void { /** Setting up initial value for NSD */ - this.dataService.currentMessage.subscribe((event: NSData) => { + this.dataService.currentMessage.subscribe((event: NSData): void => { if (event.identifier !== undefined || event.identifier !== '' || event.identifier !== null) { this.nsdId = event.identifier; } @@ -150,14 +154,11 @@ export class NSPrimitiveComponent implements OnInit { this.initializeForm(); } - /** convenience getter for easy access to form fields */ - get f(): FormGroup['controls'] { return this.primitiveForm.controls; } - /** initialize Forms @public */ public initializeForm(): void { this.primitiveForm = this.formBuilder.group({ primitive: [null, [Validators.required]], - vnf_member_index: [null, [Validators.required]], + member_vnf_index: [null, [Validators.required]], vdu_id: [null, [Validators.required]], kdu_name: [null, [Validators.required]], primitive_params: this.formBuilder.array([this.primitiveParamsBuilder()]) @@ -194,7 +195,7 @@ export class NSPrimitiveComponent implements OnInit { this.objectPrimitiveParams = {}; this.sharedService.cleanForm(this.primitiveForm); if (this.primitiveForm.invalid) { return; } // Proceed, onces form is valid - this.primitiveForm.value.primitive_params.forEach((params: NSPrimitiveParams) => { + this.primitiveForm.value.primitive_params.forEach((params: NSPrimitiveParams): void => { if (params.primitive_params_name !== null && params.primitive_params_value !== '') { this.objectPrimitiveParams[params.primitive_params_name] = params.primitive_params_value; } @@ -206,17 +207,17 @@ export class NSPrimitiveComponent implements OnInit { }; if (this.primitiveType === 'VNF_Primitive') { // tslint:disable-next-line: no-string-literal - primitiveParamsPayLoads['vnf_member_index'] = this.primitiveForm.value.vnf_member_index; + primitiveParamsPayLoads['member_vnf_index'] = this.primitiveForm.value.member_vnf_index; } if (this.primitiveType === 'VDU_Primitive') { // tslint:disable-next-line: no-string-literal - primitiveParamsPayLoads['vnf_member_index'] = this.primitiveForm.value.vnf_member_index; + primitiveParamsPayLoads['member_vnf_index'] = this.primitiveForm.value.member_vnf_index; // tslint:disable-next-line: no-string-literal primitiveParamsPayLoads['vdu_id'] = this.primitiveForm.value.vdu_id; } if (this.primitiveType === 'KDU_Primitive') { // tslint:disable-next-line: no-string-literal - primitiveParamsPayLoads['vnf_member_index'] = this.primitiveForm.value.vnf_member_index; + primitiveParamsPayLoads['member_vnf_index'] = this.primitiveForm.value.member_vnf_index; // tslint:disable-next-line: no-string-literal primitiveParamsPayLoads['kdu_name'] = this.primitiveForm.value.kdu_name; } @@ -224,23 +225,23 @@ export class NSPrimitiveComponent implements OnInit { url: environment.NSDINSTANCES_URL + '/' + this.nsdId + '/action' }; this.isLoadingResults = true; - this.restService.postResource(apiURLHeader, primitiveParamsPayLoads).subscribe((result: {}) => { + this.restService.postResource(apiURLHeader, primitiveParamsPayLoads).subscribe((result: {}): void => { this.activeModal.dismiss(); this.notifierService.notify('success', this.translateService.instant('PAGE.NSPRIMITIVE.EXECUTEDSUCCESSFULLY')); this.isLoadingResults = false; - }, (error: ERRORDATA) => { + }, (error: ERRORDATA): void => { this.isLoadingResults = false; this.restService.handleError(error, 'post'); }); } /** Primitive type change event @public */ - public primitiveTypeChange(data: { value: string }): void { + public primitiveTypeChange(data: PRIMITIVETYPES): void { this.primitiveList = []; this.primitiveParameter = []; this.initializeForm(); if (data.value === 'NS_Primitive') { this.getNSInfo(this.params.name); - this.setUpdateValueandValidation('vnf_member_index'); + this.setUpdateValueandValidation('member_vnf_index'); } if (data.value === 'VNF_Primitive' || data.value === 'KDU_Primitive' || data.value === 'NS_Primitive') { this.setUpdateValueandValidation('vdu_id'); @@ -250,11 +251,11 @@ export class NSPrimitiveComponent implements OnInit { } } /** Member index change event */ - public indexChange(data: {}, getType?: string): void { + public indexChange(data: VNFPROFILE, getType?: string): void { this.getFormControl('vdu_id').setValue(null); this.getFormControl('kdu_name').setValue(null); - if (data) { - this.getVnfdInfo(data['vnfd-id-ref'], getType); + if (data['vnfd-id'] !== null) { + this.getVnfdInfo(data['vnfd-id'], getType); } else { this.primitiveList = []; this.getFormControl('primitive').setValue(null); @@ -266,7 +267,7 @@ export class NSPrimitiveComponent implements OnInit { this.primitiveList = data[selectedType + '-configuration']['config-primitive']; } /** Primivtive change event */ - public primitiveChange(data: { parameter: {}[] }): void { + public primitiveChange(data: PRIMITIVEDATA): void { this.primitiveParameter = []; const formArr: FormArray = this.getFormControl('primitive_params') as FormArray; formArr.controls = []; @@ -276,19 +277,19 @@ export class NSPrimitiveComponent implements OnInit { } } /** Generate vdu section @public */ - public generateVDUData(vduData: VDUPRIMITIVELEVEL): VDUPRIMITIVELEVEL { + public generateVDUData(vduConfig: VDUCONFIG): VDUPROFILE { return { - id: vduData.id, - name: vduData.name, - 'vdu-configuration': vduData['vdu-configuration'] + 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 */ @@ -297,13 +298,13 @@ export class NSPrimitiveComponent implements OnInit { this.getFormControl(formName).updateValueAndValidity(); } /** Update primitive value based on parameter */ - private updatePrimitive(primitive: { parameter: {}[] }): void { + private updatePrimitive(primitive: PRIMITIVEDATA): void { if (primitive.parameter) { this.primitiveParameter = primitive.parameter; } else { this.primitiveParameter = []; const formArr: AbstractControl[] = this.getControls(); - formArr.forEach((formGp: FormGroup) => { + formArr.forEach((formGp: FormGroup): void => { formGp.controls.primitive_params_name.setValidators([]); formGp.controls.primitive_params_name.updateValueAndValidity(); formGp.controls.primitive_params_value.setValidators([]); @@ -316,43 +317,60 @@ export class NSPrimitiveComponent implements OnInit { this.primitiveList = []; this.primitiveParameter = []; this.getFormControl('primitive').setValue(null); - const apiUrl: string = environment.VNFPACKAGES_URL + '?short-name=' + vnfdRef; + const apiUrl: string = environment.VNFPACKAGES_URL + '?id=' + vnfdRef; this.isLoadingResults = true; - this.restService.getResource(apiUrl) - .subscribe((vnfdInfo: {}) => { - if (vnfdInfo[0]['vnf-configuration'] !== undefined && vnfdInfo[0]['vnf-configuration']) { + 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([]); - this.primitiveList = vnfdInfo[0]['vnf-configuration']['config-primitive']; - } - if (getType === 'VDU_Primitive') { - this.kduList = []; - this.vduList = []; - this.primitiveList = []; - if (!isNullOrUndefined(vnfdInfo[0].vdu)) { - vnfdInfo[0].vdu.forEach((vduData: VDUPRIMITIVELEVEL) => { - if (vduData['vdu-configuration']) { - const vduDataObj: VDUPRIMITIVELEVEL = this.generateVDUData(vduData); - this.vduList.push(vduDataObj); - } - }); - } - } - if (getType === 'KDU_Primitive') { - this.kduList = []; - this.vduList = []; - this.primitiveList = []; - if (!isNullOrUndefined(vnfdInfo[0].kdu)) { - vnfdInfo[0].kdu.forEach((kduData: KDUPRIMITIVELEVEL) => { - if (kduData['kdu-configuration']) { - const kduDataObj: KDUPRIMITIVELEVEL = this.generateKDUData(kduData); - this.kduList.push(kduDataObj); + 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); + } + }); + }); + } + } + } } - }); - } + } + }); } this.isLoadingResults = false; - }, (error: ERRORDATA) => { + }, (error: ERRORDATA): void => { this.isLoadingResults = false; this.restService.handleError(error, 'get'); }); @@ -362,10 +380,10 @@ export class NSPrimitiveComponent implements OnInit { this.primitiveList = []; this.primitiveParameter = []; this.getFormControl('primitive').setValue(null); - const apiUrl: string = environment.NSDESCRIPTORS_URL + '?short-name=' + nsdRef; + const apiUrl: string = environment.NSDESCRIPTORS_URL + '?id=' + nsdRef; this.isLoadingResults = true; this.restService.getResource(apiUrl) - .subscribe((nsdInfo: {}) => { + .subscribe((nsdInfo: {}): void => { if (!isNullOrUndefined(nsdInfo[0]['ns-configuration'])) { this.primitiveList = !isNullOrUndefined(nsdInfo[0]['ns-configuration']['config-primitive']) ? nsdInfo[0]['ns-configuration']['config-primitive'] : []; @@ -373,7 +391,7 @@ export class NSPrimitiveComponent implements OnInit { this.primitiveList = []; } this.isLoadingResults = false; - }, (error: ERRORDATA) => { + }, (error: ERRORDATA): void => { this.isLoadingResults = false; this.restService.handleError(error, 'get'); });