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 {VNFModel} from "../../../../models/vnfModel";
10 import {AppState} from "../../../../store/reducers";
11 import * as _ from 'lodash';
12 import {SharedControllersService} from "../sharedControlles/shared.controllers.service";
13 import {FeatureFlagsService, Features} from "../../../../services/featureFlag/feature-flags.service";
16 export class VnfControlGenerator {
17 aaiService: AaiService;
18 constructor(private genericFormService: GenericFormService,
19 private _basicControlGenerator: ControlGeneratorUtil,
20 private _sharedControllersService : SharedControllersService,
21 private _featureFlagsService: FeatureFlagsService,
22 private store: NgRedux<AppState>,
23 private http: HttpClient,
24 private _aaiService: AaiService,
25 private _logService: LogService) {
26 this.aaiService = _aaiService;
29 getVnfInstance = (serviceId: string, vnfStoreKey: string): any => {
30 let vnfInstance = null;
31 if (this.store.getState().service.serviceInstance[serviceId] && _.has(this.store.getState().service.serviceInstance[serviceId].vnfs, vnfStoreKey)) {
32 vnfInstance = Object.assign({}, this.store.getState().service.serviceInstance[serviceId].vnfs[vnfStoreKey]);
37 getMacroFormControls(serviceId: string, vnfStoreKey: string, vnfName: string, dynamicInputs?: any[]): FormControlModel[] {
38 vnfStoreKey = _.isNil(vnfStoreKey) ? vnfName : vnfStoreKey;
40 if (_.isNil(serviceId) || _.isNil(vnfStoreKey) || _.isNil(vnfName)) {
41 this._logService.error('should provide serviceId, vnfName, vnfStoreKey', serviceId);
44 const vnfInstance = this._basicControlGenerator.retrieveInstanceIfUpdateMode(this.store,this.getVnfInstance(serviceId, vnfStoreKey));
45 const vnfModel = new VNFModel(this.store.getState().service.serviceHierarchy[serviceId].vnfs[vnfName]);
46 let result: FormControlModel[] = [];
47 const flags = this.store.getState().global.flags;
49 if (!_.isNil(vnfModel)) {
50 result.push(this.getInstanceName(vnfInstance, serviceId, vnfName, vnfModel.isEcompGeneratedNaming));
51 result.push(this._sharedControllersService.getProductFamilyControl(vnfInstance, result, true));
52 result.push(this._sharedControllersService.getLcpRegionControl(serviceId, vnfInstance, result));
53 result.push(this._sharedControllersService.getLegacyRegion(vnfInstance));
54 result.push(this._sharedControllersService.getTenantControl(serviceId, vnfInstance));
55 result.push(this._sharedControllersService.getPlatformMultiselectControl(vnfInstance, result, flags['FLAG_2002_VNF_PLATFORM_MULTI_SELECT']));
56 result.push(this._sharedControllersService.getLineOfBusinessControl(vnfInstance));
61 getAlaCarteFormControls(serviceId: string, vnfStoreKey: string, vnfName: string, dynamicInputs?: any[]): FormControlModel[] {
62 vnfStoreKey = _.isNil(vnfStoreKey) ? vnfName : vnfStoreKey;
63 if (_.isNil(serviceId) || _.isNil(vnfStoreKey) || _.isNil(vnfName)) {
64 this._logService.error('should provide serviceId, vnfName, vnfStoreKey', serviceId);
68 let result: FormControlModel[] = [];
69 const vnfInstance = this._basicControlGenerator.retrieveInstanceIfUpdateMode(this.store,this.getVnfInstance(serviceId, vnfStoreKey));
70 const vnfModel = new VNFModel(this.store.getState().service.serviceHierarchy[serviceId].vnfs[vnfName]);
72 if (!_.isNil(vnfModel)) {
73 const isMultiSelected =
74 this._featureFlagsService.getFlagState(Features.FLAG_2002_VNF_PLATFORM_MULTI_SELECT);
75 const lcpRegionsByLineOFBusiness =
76 this._featureFlagsService.getFlagState(Features.FLAG_2006_LCP_REGIONS_BY_LINE_OF_BUSINESS);
78 result.push(this.getInstanceName(vnfInstance, serviceId, vnfName, vnfModel.isEcompGeneratedNaming));
79 result.push(this._sharedControllersService.getProductFamilyControl(vnfInstance, result, true));
81 if (lcpRegionsByLineOFBusiness) {
82 result.push(this._sharedControllersService.getLineOfBusinessByOwningEntityControl(vnfInstance, serviceId, result));
83 result.push(this._sharedControllersService.getLcpRegionByLineOfBusinessControl(serviceId, vnfInstance, result));
84 result.push(this._sharedControllersService.getLegacyRegion(vnfInstance));
85 result.push(this._sharedControllersService.getTenantByLcpRegionControl(serviceId, vnfInstance));
86 result.push(this._sharedControllersService.getPlatformMultiselectControl(vnfInstance, result, isMultiSelected));
88 result.push(this._sharedControllersService.getLcpRegionControl(serviceId, vnfInstance, result));
89 result.push(this._sharedControllersService.getLegacyRegion(vnfInstance));
90 result.push(this._sharedControllersService.getTenantControl(serviceId, vnfInstance));
91 result.push(this._sharedControllersService.getPlatformMultiselectControl(vnfInstance, result, isMultiSelected));
92 result.push(this._sharedControllersService.getLineOfBusinessControl(vnfInstance));
95 result.push(this._sharedControllersService.getRollbackOnFailureControl(vnfInstance));
100 getInstanceName(instance : any, serviceId : string, vnfName : string, isEcompGeneratedNaming: boolean): FormControlModel {
101 const vnfModel : VNFModel = this.store.getState().service.serviceHierarchy[serviceId].vnfs[vnfName];
102 return this._sharedControllersService.getInstanceNameController(instance, serviceId, isEcompGeneratedNaming, vnfModel);