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} from "../../../../models/formControlModels/formControl.model";
8 import {LogService} from "../../../../utils/log/log.service";
9 import {PNFModel} from "../../../../models/pnfModel";
10 import {AppState} from "../../../../store/reducers";
11 import * as _ from 'lodash';
12 import {SharedControllersService} from "../sharedControlles/shared.controllers.service";
15 export class PnfControlGenerator {
16 aaiService: AaiService;
17 constructor(private genericFormService: GenericFormService,
18 private _basicControlGenerator: ControlGeneratorUtil,
19 private _sharedControllersService : SharedControllersService,
20 private store: NgRedux<AppState>,
21 private http: HttpClient,
22 private _aaiService: AaiService,
23 private _logService: LogService) {
24 this.aaiService = _aaiService;
27 getPnfInstance = (serviceId: string, pnfStoreKey: string): any => {
28 let pnfInstance = null;
29 if (this.store.getState().service.serviceInstance[serviceId] && _.has(this.store.getState().service.serviceInstance[serviceId].pnfs, pnfStoreKey)) {
30 pnfInstance = Object.assign({}, this.store.getState().service.serviceInstance[serviceId].pnfs[pnfStoreKey]);
35 getMacroFormControls(serviceId: string, pnfStoreKey: string, pnfName: string, dynamicInputs?: any[]): FormControlModel[] {
36 pnfStoreKey = _.isNil(pnfStoreKey) ? pnfName : pnfStoreKey;
38 if (_.isNil(serviceId) || _.isNil(pnfStoreKey) || _.isNil(pnfName)) {
39 this._logService.error('should provide serviceId, pnfName, pnfStoreKey', serviceId);
42 const pnfInstance = this._basicControlGenerator.retrieveInstanceIfUpdateMode(this.store,this.getPnfInstance(serviceId, pnfStoreKey));
43 const pnfModel = new PNFModel(this.store.getState().service.serviceHierarchy[serviceId].pnfs[pnfName]);
44 let result: FormControlModel[] = [];
45 const flags = this.store.getState().global.flags;
47 if (!_.isNil(pnfModel)) {
48 const isPlatformMultiSelected = flags['FLAG_2002_PNF_PLATFORM_MULTI_SELECT'];
49 const isLobMultiSelected = flags['FLAG_2006_PNF_LOB_MULTI_SELECT'];
51 result.push(this.getInstanceName(pnfInstance, serviceId, pnfName, pnfModel.isEcompGeneratedNaming));
52 result.push(this._sharedControllersService.getProductFamilyControl(pnfInstance, result, true));
53 result.push(this._sharedControllersService.getPlatformMultiselectControl(pnfInstance, result, isPlatformMultiSelected));
54 result.push(this._sharedControllersService.getLobMultiselectControl(pnfInstance, isLobMultiSelected));
59 getAlaCarteFormControls(serviceId: string, pnfStoreKey: string, pnfName: string, dynamicInputs?: any[]): FormControlModel[] {
60 pnfStoreKey = _.isNil(pnfStoreKey) ? pnfName : pnfStoreKey;
61 if (_.isNil(serviceId) || _.isNil(pnfStoreKey) || _.isNil(pnfName)) {
62 this._logService.error('should provide serviceId, pnfName, pnfStoreKey', serviceId);
66 let result: FormControlModel[] = [];
67 const pnfInstance = this._basicControlGenerator.retrieveInstanceIfUpdateMode(this.store,this.getPnfInstance(serviceId, pnfStoreKey));
68 const pnfModel = new PNFModel(this.store.getState().service.serviceHierarchy[serviceId].pnfs[pnfName]);
69 const flags = this.store.getState().global.flags;
71 if (!_.isNil(pnfModel)) {
72 const isPlatformMultiSelected = flags['FLAG_2002_VNF_PLATFORM_MULTI_SELECT'];
73 const isLobMultiSelected = flags['FLAG_2006_VNF_LOB_MULTI_SELECT'];
74 result.push(this.getInstanceName(pnfInstance, serviceId, pnfName, pnfModel.isEcompGeneratedNaming));
75 result.push(this._sharedControllersService.getProductFamilyControl(pnfInstance, result, true));
76 result.push(this._sharedControllersService.getPlatformMultiselectControl(pnfInstance, result, isPlatformMultiSelected));
77 result.push(this._sharedControllersService.getLobMultiselectControl(pnfInstance,isLobMultiSelected));
78 result.push(this._sharedControllersService.getRollbackOnFailureControl(pnfInstance));
83 getInstanceName(instance : any, serviceId : string, pnfName : string, isEcompGeneratedNaming: boolean): FormControlModel {
84 const pnfModel : PNFModel = this.store.getState().service.serviceHierarchy[serviceId].pnfs[pnfName];
85 return this._sharedControllersService.getInstanceNameController(instance, serviceId, isEcompGeneratedNaming, pnfModel);