1 import {Injectable} from "@angular/core";
2 import {GenericFormService} from "../../generic-form.service";
3 import {AaiService} from "../../../../services/aaiService/aai.service";
4 import {NgRedux} from "@angular-redux/store";
5 import {HttpClient} from "@angular/common/http";
6 import {ControlGeneratorUtil} from "../control.generator.util.service";
7 import {FormControlModel, ValidatorModel, ValidatorOptions} from "../../../../models/formControlModels/formControl.model";
8 import {LogService} from "../../../../utils/log/log.service";
9 import {VNFModel} from "../../../../models/vnfModel";
10 import {AppState} from "../../../../store/reducers";
11 import {FormGroup} from "@angular/forms";
12 import {FormControlType} from "../../../../models/formControlModels/formControlTypes.enum";
13 import * as _ from 'lodash';
14 import {MultiselectFormControl} from "../../../../models/formControlModels/multiselectFormControl.model";
15 import {MultiSelectItem} from "../../../formControls/component/multiselect/multiselect.model";
16 import {SharedControllersService} from "../sharedControlles/shared.controllers.service";
19 export class VnfControlGenerator {
20 aaiService: AaiService;
21 constructor(private genericFormService: GenericFormService,
22 private _basicControlGenerator: ControlGeneratorUtil,
23 private _sharedControllersService : SharedControllersService,
24 private store: NgRedux<AppState>,
25 private http: HttpClient,
26 private _aaiService: AaiService,
27 private _logService: LogService) {
28 this.aaiService = _aaiService;
31 getVnfInstance = (serviceId: string, vnfStoreKey: string): any => {
32 let vnfInstance = null;
33 if (this.store.getState().service.serviceInstance[serviceId] && _.has(this.store.getState().service.serviceInstance[serviceId].vnfs, vnfStoreKey)) {
34 vnfInstance = Object.assign({}, this.store.getState().service.serviceInstance[serviceId].vnfs[vnfStoreKey]);
39 getMacroFormControls(serviceId: string, vnfStoreKey: string, vnfName: string, dynamicInputs?: any[]): FormControlModel[] {
40 vnfStoreKey = _.isNil(vnfStoreKey) ? vnfName : vnfStoreKey;
42 if (_.isNil(serviceId) || _.isNil(vnfStoreKey) || _.isNil(vnfName)) {
43 this._logService.error('should provide serviceId, vnfName, vnfStoreKey', serviceId);
46 const vnfInstance = this._basicControlGenerator.retrieveInstanceIfUpdateMode(this.store,this.getVnfInstance(serviceId, vnfStoreKey));
47 const vnfModel = new VNFModel(this.store.getState().service.serviceHierarchy[serviceId].vnfs[vnfName]);
48 let result: FormControlModel[] = [];
49 const flags = this.store.getState().global.flags;
51 if (!_.isNil(vnfModel)) {
52 result.push(this.getInstanceName(vnfInstance, serviceId, vnfName, vnfModel.isEcompGeneratedNaming));
53 result.push(this._sharedControllersService.getProductFamilyControl(vnfInstance, result, true));
54 result.push(this._sharedControllersService.getLcpRegionControl(serviceId, vnfInstance, result));
55 result.push(this._sharedControllersService.getLegacyRegion(vnfInstance));
56 result.push(this._sharedControllersService.getTenantControl(serviceId, vnfInstance));
57 result.push(this.getPlatformMultiselectControl(vnfInstance, result, flags['FLAG_2002_VNF_PLATFORM_MULTI_SELECT']));
58 result.push(this._sharedControllersService.getLineOfBusinessControl(vnfInstance));
63 getAlaCarteFormControls(serviceId: string, vnfStoreKey: string, vnfName: string, dynamicInputs?: any[]): FormControlModel[] {
64 vnfStoreKey = _.isNil(vnfStoreKey) ? vnfName : vnfStoreKey;
65 if (_.isNil(serviceId) || _.isNil(vnfStoreKey) || _.isNil(vnfName)) {
66 this._logService.error('should provide serviceId, vnfName, vnfStoreKey', serviceId);
70 let result: FormControlModel[] = [];
71 const vnfInstance = this._basicControlGenerator.retrieveInstanceIfUpdateMode(this.store,this.getVnfInstance(serviceId, vnfStoreKey));
72 const vnfModel = new VNFModel(this.store.getState().service.serviceHierarchy[serviceId].vnfs[vnfName]);
74 if (!_.isNil(vnfModel)) {
75 const flags = this.store.getState().global.flags;
76 result.push(this.getInstanceName(vnfInstance, serviceId, vnfName, vnfModel.isEcompGeneratedNaming));
77 result.push(this._sharedControllersService.getProductFamilyControl(vnfInstance, result, true));
78 result.push(this._sharedControllersService.getLcpRegionControl(serviceId, vnfInstance, result));
79 result.push(this._sharedControllersService.getLegacyRegion(vnfInstance));
80 result.push(this._sharedControllersService.getTenantControl(serviceId, vnfInstance));
81 result.push(this.getPlatformMultiselectControl(vnfInstance, result, flags['FLAG_2002_VNF_PLATFORM_MULTI_SELECT']));
82 result.push(this._sharedControllersService.getLineOfBusinessControl(vnfInstance));
83 result.push(this._sharedControllersService.getRollbackOnFailureControl(vnfInstance));
88 getInstanceName(instance : any, serviceId : string, vnfName : string, isEcompGeneratedNaming: boolean): FormControlModel {
89 const vnfModel : VNFModel = this.store.getState().service.serviceHierarchy[serviceId].vnfs[vnfName];
90 return this._sharedControllersService.getInstanceNameController(instance, serviceId, isEcompGeneratedNaming, vnfModel);
93 getPlatformMultiselectControl = (instance: any, controls: FormControlModel[], isMultiSelected: boolean) : MultiselectFormControl => {
94 return new MultiselectFormControl({
95 type: FormControlType.MULTI_SELECT ,
96 controlName: 'platformName',
97 displayName: 'Platform',
98 dataTestId: 'multi-selectPlatform',
99 selectedFieldName : 'name' ,
101 placeHolder: 'Select Platform',
104 value: instance ? instance.platformName : '',
105 limitSelection : isMultiSelected ? 1000 : 1,
106 validations: [new ValidatorModel(ValidatorOptions.required, 'is required')],
107 onInitSelectedField: ['platformList'],
108 onInit: this._basicControlGenerator.getSubscribeInitResult.bind(null, this._aaiService.getCategoryParameters),
109 onChange : (param: MultiSelectItem[], form: FormGroup) => {
110 form.controls['platformName'].setValue(param.map((multiSelectItem: MultiSelectItem)=>{
111 return multiSelectItem.itemName
114 convertOriginalDataToArray : (value?: string) => {
115 if(_.isNil(value)) return [];
116 return value.split(',');