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 * as _ from 'lodash';
9 import {FormControlModel,} from "../../../../models/formControlModels/formControl.model";
10 import {LogService} from "../../../../utils/log/log.service";
11 import {AppState} from "../../../../store/reducers";
12 import {DropdownFormControl} from "../../../../models/formControlModels/dropdownFormControl.model";
13 import {FormControlType} from "../../../../models/formControlModels/formControlTypes.enum";
14 import {NetworkInstance} from "../../../../models/networkInstance";
15 import {NetworkModel} from "../../../../models/networkModel";
16 import {SharedControllersService} from "../sharedControlles/shared.controllers.service";
18 export enum FormControlNames {
19 INSTANCE_NAME = 'instanceName',
20 PRODUCT_FAMILY_ID = 'productFamilyId',
21 LCPCLOUD_REGION_ID = 'lcpCloudRegionId',
22 ROLLBACK_ON_FAILURE = 'rollbackOnFailure'
27 export class NetworkControlGenerator {
28 aaiService: AaiService;
30 constructor(private genericFormService: GenericFormService,
31 private _basicControlGenerator: ControlGeneratorUtil,
32 private _sharedControllersService: SharedControllersService,
33 private store: NgRedux<AppState>,
34 private http: HttpClient,
35 private _aaiService: AaiService,
36 private _logService: LogService) {
37 this.aaiService = _aaiService;
40 getNetworkInstance = (serviceId: string, networkName: string, isUpdateMode: boolean): NetworkInstance => {
41 let networkInstance: NetworkInstance = null;
42 if (isUpdateMode && this.store.getState().service.serviceInstance[serviceId] && _.has(this.store.getState().service.serviceInstance[serviceId].networks, networkName)) {
43 networkInstance = Object.assign({}, this.store.getState().service.serviceInstance[serviceId].networks[networkName]);
45 return networkInstance;
49 getMacroFormControls(serviceId: string, networkStoreKey: string, networkName: string, isUpdateMode: boolean): FormControlModel[] {
50 networkStoreKey = _.isNil(networkStoreKey) ? networkName : networkStoreKey;
52 if (_.isNil(serviceId) || _.isNil(networkStoreKey) || _.isNil(networkName)) {
53 this._logService.error('should provide serviceId, networkName, networkStoreKey', serviceId);
56 const networkInstance = this._basicControlGenerator.retrieveInstanceIfUpdateMode(this.store, this.getNetworkInstance(serviceId, networkStoreKey, isUpdateMode));
57 const networkModel = new NetworkModel(this.store.getState().service.serviceHierarchy[serviceId].networks[networkName]);
58 let result: FormControlModel[] = [];
60 if (!_.isNil(networkModel)) {
61 result.push(this.getInstanceName(networkInstance, serviceId, networkName, networkModel.isEcompGeneratedNaming));
62 result.push(this._sharedControllersService.getProductFamilyControl(networkInstance, result, false));
63 result.push(this._sharedControllersService.getLcpRegionControl(serviceId, networkInstance, result));
64 result.push(this._sharedControllersService.getLegacyRegion(networkInstance));
65 result.push(this._sharedControllersService.getTenantControl(serviceId, networkInstance));
66 result.push(this.getPlatformControl(networkInstance));
67 result.push(this._sharedControllersService.getLineOfBusinessControl(networkInstance));
73 getAlaCarteFormControls(serviceId: string, networkStoreKey: string, networkName: string, isUpdateMode: boolean): FormControlModel[] {
74 networkStoreKey = _.isNil(networkStoreKey) ? networkName : networkStoreKey;
75 if (_.isNil(serviceId) || _.isNil(networkStoreKey) || _.isNil(networkName)) {
76 this._logService.error('should provide serviceId, networkName, networkStoreKey', serviceId);
80 let result: FormControlModel[] = [];
81 const networkInstance = this._basicControlGenerator.retrieveInstanceIfUpdateMode(this.store, this.getNetworkInstance(serviceId, networkStoreKey, isUpdateMode));
82 const networkModel = new NetworkModel(this.store.getState().service.serviceHierarchy[serviceId].networks[networkName]);
84 if (!_.isNil(networkModel)) {
85 result.push(this.getInstanceName(networkInstance, serviceId, networkName, networkModel.isEcompGeneratedNaming));
86 result.push(this._sharedControllersService.getProductFamilyControl(networkInstance, result, false));
87 result.push(this._sharedControllersService.getLcpRegionControl(serviceId, networkInstance, result));
88 result.push(this._sharedControllersService.getLegacyRegion(networkInstance));
89 result.push(this._sharedControllersService.getTenantControl(serviceId, networkInstance));
90 result.push(this.getPlatformControl(networkInstance));
91 result.push(this._sharedControllersService.getLineOfBusinessControl(networkInstance));
92 result.push(this._sharedControllersService.getRollbackOnFailureControl(networkInstance));
98 getInstanceName(instance: any, serviceId: string, networkName: string, isEcompGeneratedNaming: boolean): FormControlModel {
99 const networkModel: NetworkModel = this.store.getState().service.serviceHierarchy[serviceId].networks[networkName];
100 return this._sharedControllersService.getInstanceNameController(instance, serviceId, isEcompGeneratedNaming, networkModel);
103 getPlatformControl = (instance: any): DropdownFormControl => {
104 return new DropdownFormControl({
105 type: FormControlType.DROPDOWN,
106 controlName: 'platformName',
107 displayName: 'Platform',
108 dataTestId: 'platform',
109 placeHolder: 'Select Platform',
112 value: instance ? instance.platformName : null,
114 onInitSelectedField: ['platformList'],
115 onInit: this._basicControlGenerator.getSubscribeInitResult.bind(null, this._aaiService.getCategoryParameters)