diff options
Diffstat (limited to 'vid-webpack-master/src')
3 files changed, 159 insertions, 109 deletions
diff --git a/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModule/vfModule.popuop.service.ts b/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModule/vfModule.popuop.service.ts index d0a68675c..9c900b77b 100644 --- a/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModule/vfModule.popuop.service.ts +++ b/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModule/vfModule.popuop.service.ts @@ -21,8 +21,7 @@ import {FormControlModel} from "../../../../models/formControlModels/formControl import * as _ from 'lodash'; import {createVFModuleInstance, updateVFModuleInstance} from "../../../../storeUtil/utils/vfModule/vfModule.actions"; -@Injectable() -export class VfModulePopuopService implements GenericPopupInterface { +export abstract class VfModulePopupServiceBase { dynamicInputs: any; instance: any; model: any; @@ -31,16 +30,27 @@ export class VfModulePopuopService implements GenericPopupInterface { uuidData: Object; closeDialogEvent: Subject<any> = new Subject<any>(); isUpdateMode: boolean; + storeVFModule = (that, formValues: any): void => { + formValues.modelInfo = new ModelInfo(that.model); + formValues.uuid = formValues.modelInfo.uuid; + formValues.isMissingData = false; + const vnf = that._store.getState().service.serviceInstance[that.uuidData.serviceId].vnfs[that.uuidData.vnfStoreKey]; + if (!that.uuidData.vFModuleStoreKey) { + this._store.dispatch(createVFModuleInstance(formValues, that.uuidData.modelName, that.uuidData.serviceId, 0, that.uuidData.vnfStoreKey)); + } else { + this._store.dispatch(updateVFModuleInstance(formValues, that.uuidData.modelName, that.uuidData.serviceId, that.uuidData.vFModuleStoreKey, that.uuidData.vnfStoreKey)); + } + }; - constructor(protected _basicControlGenerator: BasicControlGenerator, - protected _vfModuleControlGenerator: VfModuleControlGenerator, - protected _iframeService: IframeService, - protected _defaultDataGeneratorService: DefaultDataGeneratorService, - protected _aaiService: AaiService, - protected _basicPopupService : BasicPopupService, - protected _store: NgRedux<AppState>) { - + protected constructor( + protected _basicControlGenerator: BasicControlGenerator, + protected _vfModuleControlGenerator: VfModuleControlGenerator, + protected _iframeService: IframeService, + protected _defaultDataGeneratorService: DefaultDataGeneratorService, + protected _aaiService: AaiService, + protected _basicPopupService: BasicPopupService, + protected _store: NgRedux<AppState>) { } getInstance(serviceId: string, vnfStoreKey: string, vfModuleStoreKey: string): any { @@ -51,24 +61,58 @@ export class VfModulePopuopService implements GenericPopupInterface { return vfModules[this.uuidData['modelName']][vfModuleStoreKey]; } - getDynamicInputs(UUIDData : Object) : FormControlModel[]{ - let dynamic = this._defaultDataGeneratorService.getArbitraryInputs(this._store.getState().service.serviceHierarchy[UUIDData['serviceId']].vfModules[UUIDData['modelName']].inputs); - return this.getVFModuleDynamicInputs(dynamic, UUIDData); + getModelInformation(serviceId: string, modelName: string) { + this._aaiService.getServiceModelById(serviceId).subscribe((result: any) => { + this.serviceModel = new ServiceModel(result); + + this.model = this._basicPopupService.getModelFromResponse(result, 'vfModules', modelName); + const serviceInstance = this._store.getState().service.serviceInstance[serviceId]; + this.modelInformations = [ + new ModelInformationItem("Subscriber Name", "subscriberName", [this._basicPopupService.extractSubscriberNameBySubscriberId(serviceInstance.globalSubscriberId)], "", true), + new ModelInformationItem("Service Name", "serviceModelName", [this.serviceModel.name], "", true), + new ModelInformationItem("Service Instance Name", "serviceName", [serviceInstance.instanceName], "", false), + new ModelInformationItem("Model Name", "modelName", [this.model.name], "", true), + new ModelInformationItem("Model version", "modelVersion", [this.model.version], "", true), + new ModelInformationItem("Description", "description", [this.model.description]), + new ModelInformationItem("Category", "category", [this.model.category]), + new ModelInformationItem("Sub Category", "subCategory", [this.model.subCategory]), + new ModelInformationItem("UUID", "uuid", [this.model.uuid], Constants.ServicePopup.TOOLTIP_UUID, true), + new ModelInformationItem("Invariant UUID", "invariantUuid", [this.model.invariantUuid], Constants.ServicePopup.TOOLTIP_INVARIANT_UUID, true), + new ModelInformationItem("Service type", "serviceType", [this.serviceModel.serviceType]), + new ModelInformationItem("Service role", "serviceRole", [this.serviceModel.serviceRole]), + new ModelInformationItem("Minimum to instantiate", "min", this.model.min == undefined ? ['0'] : [this.model.min.toString()], "", true), + new ModelInformationItem("Maximum to instantiate", "max", this.model.max == undefined ? ['1'] : [this.model.max.toString()], "", true), + new ModelInformationItem("Recommended to instantiate", "initial", [this.model.initial]) + ]; + }); } - getVFModuleDynamicInputs(dynamicInputs : any, UUIDData : Object) : FormControlModel[] { - let result : FormControlModel[] = []; - if(dynamicInputs) { - let vfModuleInstance = null; - if (_.has(this._store.getState().service.serviceInstance[UUIDData['serviceId']].vnfs, UUIDData['vnfStoreKey']) && - _.has(this._store.getState().service.serviceInstance[UUIDData['serviceId']].vnfs[UUIDData['vnfStoreKey']].vfModules, UUIDData['modelName'])) { - vfModuleInstance = Object.assign({},this._store.getState().service.serviceInstance[UUIDData['serviceId']].vnfs[UUIDData['vnfStoreKey']].vfModules[UUIDData['modelName']][UUIDData['vfModuleStoreKey']]); + protected postSubmitIframeMessage(that) { + window.parent.postMessage({ + eventId: 'submitIframe', + data: { + serviceModelId: that.serviceModel.uuid } - result = this._basicControlGenerator.getDynamicInputs(dynamicInputs, vfModuleInstance); - } - return result; + }, "*"); + } + + onCancel(that, form) { + form.reset(); + that._iframeService.removeClassCloseModal('content'); + this.closeDialogEvent.next(that); } + getSubLeftTitle(): string { + return this.model.name; + } + + getSubRightTitle(): string { + return "Module (Heat stack) Instance Details"; + } + + abstract getTitle(isUpdateMode : boolean) : string; + abstract getControls(serviceId: string, vnfStoreKey: string, vfModuleStoreKey: string, isUpdateMode: boolean); + abstract getDynamicInputs(UUIDData : Object) : FormControlModel[]; getGenericFormPopupDetails(serviceId: string, vnfStoreKey: string, vfModuleStoreKey: string, node: ITreeNode, uuidData: Object, isUpdateMode: boolean): FormPopupDetails { @@ -85,37 +129,50 @@ export class VfModulePopuopService implements GenericPopupInterface { this.getControls(serviceId, vnfStoreKey, vfModuleStoreKey, isUpdateMode), this.getDynamicInputs(uuidData), this.modelInformations, - (that, form: FormGroup) => {that.onSubmit(that, form);}, - (that: any, form: FormGroup) => {that.onCancel(that, form); } + (that, form: FormGroup) => { + that.onSubmit(that, form); + }, + (that: any, form: FormGroup) => { + that.onCancel(that, form); + } ); } +} - getModelInformation(serviceId: string, modelName: string) { - this._aaiService.getServiceModelById(serviceId).subscribe((result: any) => { - this.serviceModel = new ServiceModel(result); +@Injectable() +export class VfModulePopuopService extends VfModulePopupServiceBase implements GenericPopupInterface { - this.model = this._basicPopupService.getModelFromResponse(result, 'vfModules', modelName); - const serviceInstance = this._store.getState().service.serviceInstance[serviceId]; - this.modelInformations = [ - new ModelInformationItem("Subscriber Name", "subscriberName", [this._basicPopupService.extractSubscriberNameBySubscriberId(serviceInstance.globalSubscriberId)], "", true), - new ModelInformationItem("Service Name", "serviceModelName", [this.serviceModel.name], "", true), - new ModelInformationItem("Service Instance Name", "serviceName", [serviceInstance.instanceName], "", false), - new ModelInformationItem("Model Name", "modelName", [this.model.name], "", true), - new ModelInformationItem("Model version", "modelVersion", [this.model.version], "", true), - new ModelInformationItem("Description", "description", [this.model.description]), - new ModelInformationItem("Category", "category", [this.model.category]), - new ModelInformationItem("Sub Category", "subCategory", [this.model.subCategory]), - new ModelInformationItem("UUID", "uuid", [this.model.uuid], Constants.ServicePopup.TOOLTIP_UUID, true), - new ModelInformationItem("Invariant UUID", "invariantUuid", [this.model.invariantUuid], Constants.ServicePopup.TOOLTIP_INVARIANT_UUID, true), - new ModelInformationItem("Service type", "serviceType", [this.serviceModel.serviceType]), - new ModelInformationItem("Service role", "serviceRole", [this.serviceModel.serviceRole]), - new ModelInformationItem("Minimum to instantiate", "min", this.model.min == undefined ? ['0'] : [this.model.min.toString()], "", true), - new ModelInformationItem("Maximum to instantiate", "max", this.model.max == undefined ? ['1'] : [this.model.max.toString()], "", true), - new ModelInformationItem("Recommended to instantiate", "initial", [this.model.initial]) - ]; - }); + + constructor(_basicControlGenerator: BasicControlGenerator, + _vfModuleControlGenerator: VfModuleControlGenerator, + _iframeService: IframeService, + _defaultDataGeneratorService: DefaultDataGeneratorService, + _aaiService: AaiService, + _basicPopupService : BasicPopupService, + _store: NgRedux<AppState>) { + super(_basicControlGenerator, _vfModuleControlGenerator, _iframeService, _defaultDataGeneratorService, _aaiService, _basicPopupService, _store); + + } + + getDynamicInputs(UUIDData : Object) : FormControlModel[]{ + let dynamic = this._defaultDataGeneratorService.getArbitraryInputs(this._store.getState().service.serviceHierarchy[UUIDData['serviceId']].vfModules[UUIDData['modelName']].inputs); + return this.getVFModuleDynamicInputs(dynamic, UUIDData); } + getVFModuleDynamicInputs(dynamicInputs : any, UUIDData : Object) : FormControlModel[] { + let result : FormControlModel[] = []; + if(dynamicInputs) { + let vfModuleInstance = null; + if (_.has(this._store.getState().service.serviceInstance[UUIDData['serviceId']].vnfs, UUIDData['vnfStoreKey']) && + _.has(this._store.getState().service.serviceInstance[UUIDData['serviceId']].vnfs[UUIDData['vnfStoreKey']].vfModules, UUIDData['modelName'])) { + vfModuleInstance = Object.assign({},this._store.getState().service.serviceInstance[UUIDData['serviceId']].vnfs[UUIDData['vnfStoreKey']].vfModules[UUIDData['modelName']][UUIDData['vfModuleStoreKey']]); + } + result = this._basicControlGenerator.getDynamicInputs(dynamicInputs, vfModuleInstance); + } + return result; + } + + getControls(serviceId: string, vnfStoreKey: string, vfModuleStoreKey: string, isUpdateMode: boolean) { if (this._store.getState().service.serviceHierarchy[serviceId].service.vidNotions.instantiationType === 'Macro') { return this._vfModuleControlGenerator.getMacroFormControls(serviceId, vnfStoreKey, vfModuleStoreKey, this.uuidData, isUpdateMode); @@ -145,44 +202,8 @@ export class VfModulePopuopService implements GenericPopupInterface { this.onCancel(that, form); } - - protected postSubmitIframeMessage(that) { - window.parent.postMessage({ - eventId: 'submitIframe', - data: { - serviceModelId: that.serviceModel.uuid - } - }, "*"); - } - - onCancel(that, form) { - form.reset(); - that._iframeService.removeClassCloseModal('content'); - this.closeDialogEvent.next(that); - } - - storeVFModule = (that, formValues: any): void => { - formValues.modelInfo = new ModelInfo(that.model); - formValues.uuid = formValues.modelInfo.uuid; - formValues.isMissingData = false; - const vnf = that._store.getState().service.serviceInstance[that.uuidData.serviceId].vnfs[that.uuidData.vnfStoreKey]; - - if (!that.uuidData.vFModuleStoreKey) { - this._store.dispatch(createVFModuleInstance(formValues, that.uuidData.modelName, that.uuidData.serviceId, 0, that.uuidData.vnfStoreKey)); - } else { - this._store.dispatch(updateVFModuleInstance(formValues, that.uuidData.modelName, that.uuidData.serviceId, that.uuidData.vFModuleStoreKey, that.uuidData.vnfStoreKey)); - } - }; - getTitle(isUpdateMode : boolean) : string { return isUpdateMode ? 'Edit Module (Heat stack)' : 'Set new Module (Heat stack)'; } - getSubLeftTitle(): string { - return this.model.name; - } - - getSubRightTitle(): string { - return "Module (Heat stack) Instance Details"; - } } diff --git a/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popuop.service.ts b/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popuop.service.ts index ff3f23ff4..b82074d9c 100644 --- a/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popuop.service.ts +++ b/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popuop.service.ts @@ -1,8 +1,7 @@ import {Injectable} from "@angular/core"; import {ITreeNode} from "angular-tree-component/dist/defs/api"; import {FormGroup} from "@angular/forms"; -import {VfModulePopuopService} from "../vfModule/vfModule.popuop.service"; -import {FormPopupDetails} from "../../../../models/formControlModels/formPopupDetails.model"; +import {VfModulePopupServiceBase} from "../vfModule/vfModule.popuop.service"; import {updateVFModuleField, upgradeVFModule} from "../../../../storeUtil/utils/vfModule/vfModule.actions"; import {SharedTreeService} from "../../../../../drawingBoard/service-planning/objectsToTree/shared.tree.service"; import {NgRedux} from "@angular-redux/store"; @@ -13,14 +12,17 @@ import {IframeService} from "../../../../utils/iframe.service"; import {DefaultDataGeneratorService} from "../../../../services/defaultDataServiceGenerator/default.data.generator.service"; import {AaiService} from "../../../../services/aaiService/aai.service"; import {BasicPopupService} from "../basic.popup.service"; -import { - FormControlModel -} from "../../../../models/formControlModels/formControl.model"; +import {FormControlModel} from "../../../../models/formControlModels/formControl.model"; import {CheckboxFormControl} from "../../../../models/formControlModels/checkboxFormControl.model"; import {FormControlType} from "../../../../models/formControlModels/formControlTypes.enum"; +export enum UpgradeFormControlNames { + RETAIN_VOLUME_GROUPS = 'retainVolumeGroups', + RETAIN_ASSIGNMENTS = 'retainAssignments', +} + @Injectable() -export class VfModuleUpgradePopupService extends VfModulePopuopService { +export class VfModuleUpgradePopupService extends VfModulePopupServiceBase { constructor(protected _basicControlGenerator: BasicControlGenerator, protected _vfModuleControlGenerator: VfModuleControlGenerator, protected _iframeService: IframeService, @@ -33,26 +35,15 @@ export class VfModuleUpgradePopupService extends VfModulePopuopService { } node: ITreeNode; - getGenericFormPopupDetails(serviceId: string, vnfStoreKey: string, vfModuleStoreKey: string, node: ITreeNode, uuidData: Object, isUpdateMode: boolean): FormPopupDetails { - return super.getGenericFormPopupDetails(serviceId, vnfStoreKey, vfModuleStoreKey, node, uuidData, isUpdateMode); - } - getDynamicInputs = () => []; - getControls = () : FormControlModel[] => { - return [ - new CheckboxFormControl({ - type: FormControlType.CHECKBOX, - controlName: 'retainAssignments', - displayName: 'Retain Assignments', - dataTestId: 'retainAssignments', - value: true, - validations: [] - }) - ]; + getControls(serviceId: string, vnfStoreKey: string, vfModuleStoreKey: string, isUpdateMode: boolean) { + let result: FormControlModel[] = []; + result.push(this.getRetainVolumeGroupsControl()); + result.push(this.getRetainAssignmentsControl()); + return result; }; - getTitle = (): string => 'Upgrade Module'; onSubmit(that, form: FormGroup) { @@ -61,10 +52,39 @@ export class VfModuleUpgradePopupService extends VfModulePopuopService { this._store.dispatch(upgradeVFModule(node.data.modelName, node.parent.data.vnfStoreKey, serviceInstanceId ,node.data.dynamicModelName)); this._sharedTreeService.upgradeBottomUp(node, serviceInstanceId); - this._store.dispatch(updateVFModuleField(node.data.modelName, node.parent.data.vnfStoreKey, serviceInstanceId ,node.data.dynamicModelName, 'retainAssignments', form.controls['retainAssignments'].value)); + + this.updateVFModuleField(UpgradeFormControlNames.RETAIN_VOLUME_GROUPS,node, serviceInstanceId, form); + this.updateVFModuleField(UpgradeFormControlNames.RETAIN_ASSIGNMENTS,node, serviceInstanceId, form); this.postSubmitIframeMessage(that); this.onCancel(that, form); } + private updateVFModuleField(fieldName: string, node, serviceInstanceId: string, form: FormGroup) { + this._store.dispatch(updateVFModuleField(node.data.modelName, node.parent.data.vnfStoreKey, serviceInstanceId, node.data.dynamicModelName, fieldName, form.controls[fieldName].value)); + } + + + getRetainVolumeGroupsControl = (): CheckboxFormControl => { + return new CheckboxFormControl({ + type: FormControlType.CHECKBOX, + controlName: UpgradeFormControlNames.RETAIN_VOLUME_GROUPS, + displayName: 'Retain Volume Groups', + dataTestId: UpgradeFormControlNames.RETAIN_VOLUME_GROUPS, + value: true, + validations: [] + }) + }; + + getRetainAssignmentsControl = (): CheckboxFormControl => { + return new CheckboxFormControl({ + type: FormControlType.CHECKBOX, + controlName: UpgradeFormControlNames.RETAIN_ASSIGNMENTS, + displayName: 'Retain Assignments', + dataTestId: UpgradeFormControlNames.RETAIN_ASSIGNMENTS, + value: true, + validations: [] + }) + }; + } diff --git a/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popup.service.spec.ts b/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popup.service.spec.ts index 5850d25f0..a7c8214b4 100644 --- a/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popup.service.spec.ts +++ b/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popup.service.spec.ts @@ -12,7 +12,7 @@ import {VfModuleControlGenerator} from "../../../genericForm/formControlsService import {SdcUiServices} from "onap-ui-angular"; import {FeatureFlagsService} from "../../../../services/featureFlag/feature-flags.service"; import {getTestBed, TestBed} from "@angular/core/testing"; -import {VfModuleUpgradePopupService} from "./vfModule.upgrade.popuop.service"; +import {UpgradeFormControlNames, VfModuleUpgradePopupService} from "./vfModule.upgrade.popuop.service"; import {SharedTreeService} from "../../../../../drawingBoard/service-planning/objectsToTree/shared.tree.service"; class MockModalService<T> { @@ -78,12 +78,21 @@ describe('VFModule popup service', () => { test('get controls should return retainAssignments control with false i', ()=> { const controls = service.getControls(); + expect(controls.length).toEqual(2); const retainAssignmentsControl = controls.find((control)=>{ - return control.controlName === 'retainAssignments'; + return control.controlName === UpgradeFormControlNames.RETAIN_ASSIGNMENTS; }); expect(retainAssignmentsControl).toBeDefined(); expect(retainAssignmentsControl.value).toBeTruthy(); + + + const retainVolumeGroup = controls.find((control)=>{ + return control.controlName === UpgradeFormControlNames.RETAIN_VOLUME_GROUPS; + }); + + expect(retainVolumeGroup).toBeDefined(); + expect(retainVolumeGroup.value).toBeTruthy(); }); }); |