Revert "VNF's LCP regions found by Line-of-business (and owning-entity)"
[vid.git] / vid-webpack-master / src / app / shared / components / genericForm / formControlsServices / vnfGenerator / vnf.control.generator.ts
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
14 @Injectable()
15 export class VnfControlGenerator {
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;
25   }
26
27   getVnfInstance = (serviceId: string, vnfStoreKey: string): any => {
28     let vnfInstance = null;
29     if (this.store.getState().service.serviceInstance[serviceId] && _.has(this.store.getState().service.serviceInstance[serviceId].vnfs, vnfStoreKey)) {
30       vnfInstance = Object.assign({}, this.store.getState().service.serviceInstance[serviceId].vnfs[vnfStoreKey]);
31     }
32     return vnfInstance;
33   };
34
35   getMacroFormControls(serviceId: string, vnfStoreKey: string, vnfName: string, dynamicInputs?: any[]): FormControlModel[] {
36     vnfStoreKey = _.isNil(vnfStoreKey) ? vnfName : vnfStoreKey;
37
38     if (_.isNil(serviceId) || _.isNil(vnfStoreKey) || _.isNil(vnfName)) {
39       this._logService.error('should provide serviceId, vnfName, vnfStoreKey', serviceId);
40       return [];
41     }
42     const vnfInstance = this._basicControlGenerator.retrieveInstanceIfUpdateMode(this.store,this.getVnfInstance(serviceId, vnfStoreKey));
43     const vnfModel = new VNFModel(this.store.getState().service.serviceHierarchy[serviceId].vnfs[vnfName]);
44     let result: FormControlModel[] = [];
45     const flags = this.store.getState().global.flags;
46
47     if (!_.isNil(vnfModel)) {
48       result.push(this.getInstanceName(vnfInstance, serviceId, vnfName, vnfModel.isEcompGeneratedNaming));
49       result.push(this._sharedControllersService.getProductFamilyControl(vnfInstance, result, true));
50       result.push(this._sharedControllersService.getLcpRegionControl(serviceId, vnfInstance, result));
51       result.push(this._sharedControllersService.getLegacyRegion(vnfInstance));
52       result.push(this._sharedControllersService.getTenantControl(serviceId, vnfInstance));
53       result.push(this._sharedControllersService.getPlatformMultiselectControl(vnfInstance, result, flags['FLAG_2002_VNF_PLATFORM_MULTI_SELECT']));
54       result.push(this._sharedControllersService.getLineOfBusinessControl(vnfInstance));
55     }
56     return result;
57   }
58
59   getAlaCarteFormControls(serviceId: string, vnfStoreKey: string, vnfName: string, dynamicInputs?: any[]): FormControlModel[] {
60     vnfStoreKey = _.isNil(vnfStoreKey) ? vnfName : vnfStoreKey;
61     if (_.isNil(serviceId) || _.isNil(vnfStoreKey) || _.isNil(vnfName)) {
62       this._logService.error('should provide serviceId, vnfName, vnfStoreKey', serviceId);
63       return [];
64     }
65
66     let result: FormControlModel[] = [];
67     const vnfInstance = this._basicControlGenerator.retrieveInstanceIfUpdateMode(this.store,this.getVnfInstance(serviceId, vnfStoreKey));
68     const vnfModel = new VNFModel(this.store.getState().service.serviceHierarchy[serviceId].vnfs[vnfName]);
69
70     if (!_.isNil(vnfModel)) {
71       const flags = this.store.getState().global.flags;
72       result.push(this.getInstanceName(vnfInstance, serviceId, vnfName, vnfModel.isEcompGeneratedNaming));
73       result.push(this._sharedControllersService.getProductFamilyControl(vnfInstance, result, true));
74       result.push(this._sharedControllersService.getLcpRegionControl(serviceId, vnfInstance, result));
75       result.push(this._sharedControllersService.getLegacyRegion(vnfInstance));
76       result.push(this._sharedControllersService.getTenantControl(serviceId, vnfInstance));
77       result.push(this._sharedControllersService.getPlatformMultiselectControl(vnfInstance, result, flags['FLAG_2002_VNF_PLATFORM_MULTI_SELECT']));
78       result.push(this._sharedControllersService.getLineOfBusinessControl(vnfInstance));
79       result.push(this._sharedControllersService.getRollbackOnFailureControl(vnfInstance));
80     }
81     return result;
82   }
83
84   getInstanceName(instance : any, serviceId : string, vnfName : string, isEcompGeneratedNaming: boolean): FormControlModel {
85     const vnfModel : VNFModel = this.store.getState().service.serviceHierarchy[serviceId].vnfs[vnfName];
86     return this._sharedControllersService.getInstanceNameController(instance, serviceId, isEcompGeneratedNaming, vnfModel);
87   }
88 }