1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
import {Injectable} from "@angular/core";
import {GenericFormService} from "../../generic-form.service";
import {AaiService} from "../../../../services/aaiService/aai.service";
import {NgRedux} from "@angular-redux/store";
import {HttpClient} from "@angular/common/http";
import {ControlGeneratorUtil} from "../control.generator.util.service";
import * as _ from 'lodash';
import {FormControlModel,} from "../../../../models/formControlModels/formControl.model";
import {LogService} from "../../../../utils/log/log.service";
import {AppState} from "../../../../store/reducers";
import {DropdownFormControl} from "../../../../models/formControlModels/dropdownFormControl.model";
import {FormControlType} from "../../../../models/formControlModels/formControlTypes.enum";
import {NetworkInstance} from "../../../../models/networkInstance";
import {NetworkModel} from "../../../../models/networkModel";
import {SharedControllersService} from "../sharedControlles/shared.controllers.service";
export enum FormControlNames {
INSTANCE_NAME = 'instanceName',
PRODUCT_FAMILY_ID = 'productFamilyId',
LCPCLOUD_REGION_ID = 'lcpCloudRegionId',
ROLLBACK_ON_FAILURE = 'rollbackOnFailure'
}
@Injectable()
export class NetworkControlGenerator {
aaiService: AaiService;
constructor(private genericFormService: GenericFormService,
private _basicControlGenerator: ControlGeneratorUtil,
private _sharedControllersService: SharedControllersService,
private store: NgRedux<AppState>,
private http: HttpClient,
private _aaiService: AaiService,
private _logService: LogService) {
this.aaiService = _aaiService;
}
getNetworkInstance = (serviceId: string, networkName: string, isUpdateMode: boolean): NetworkInstance => {
let networkInstance: NetworkInstance = null;
if (isUpdateMode && this.store.getState().service.serviceInstance[serviceId] && _.has(this.store.getState().service.serviceInstance[serviceId].networks, networkName)) {
networkInstance = Object.assign({}, this.store.getState().service.serviceInstance[serviceId].networks[networkName]);
}
return networkInstance;
};
getMacroFormControls(serviceId: string, networkStoreKey: string, networkName: string, isUpdateMode: boolean): FormControlModel[] {
networkStoreKey = _.isNil(networkStoreKey) ? networkName : networkStoreKey;
if (_.isNil(serviceId) || _.isNil(networkStoreKey) || _.isNil(networkName)) {
this._logService.error('should provide serviceId, networkName, networkStoreKey', serviceId);
return [];
}
const networkInstance = this._basicControlGenerator.retrieveInstanceIfUpdateMode(this.store, this.getNetworkInstance(serviceId, networkStoreKey, isUpdateMode));
const networkModel = new NetworkModel(this.store.getState().service.serviceHierarchy[serviceId].networks[networkName]);
let result: FormControlModel[] = [];
if (!_.isNil(networkModel)) {
result.push(this.getInstanceName(networkInstance, serviceId, networkName, networkModel.isEcompGeneratedNaming));
result.push(this._sharedControllersService.getProductFamilyControl(networkInstance, result, false));
result.push(this._sharedControllersService.getLcpRegionControl(serviceId, networkInstance, result));
result.push(this._sharedControllersService.getLegacyRegion(networkInstance));
result.push(this._sharedControllersService.getTenantControl(serviceId, networkInstance));
result.push(this.getPlatformControl(networkInstance));
result.push(this._sharedControllersService.getLineOfBusinessControl(networkInstance));
}
return result;
}
getAlaCarteFormControls(serviceId: string, networkStoreKey: string, networkName: string, isUpdateMode: boolean): FormControlModel[] {
networkStoreKey = _.isNil(networkStoreKey) ? networkName : networkStoreKey;
if (_.isNil(serviceId) || _.isNil(networkStoreKey) || _.isNil(networkName)) {
this._logService.error('should provide serviceId, networkName, networkStoreKey', serviceId);
return [];
}
let result: FormControlModel[] = [];
const networkInstance = this._basicControlGenerator.retrieveInstanceIfUpdateMode(this.store, this.getNetworkInstance(serviceId, networkStoreKey, isUpdateMode));
const networkModel = new NetworkModel(this.store.getState().service.serviceHierarchy[serviceId].networks[networkName]);
if (!_.isNil(networkModel)) {
result.push(this.getInstanceName(networkInstance, serviceId, networkName, networkModel.isEcompGeneratedNaming));
result.push(this._sharedControllersService.getProductFamilyControl(networkInstance, result, false));
result.push(this._sharedControllersService.getLcpRegionControl(serviceId, networkInstance, result));
result.push(this._sharedControllersService.getLegacyRegion(networkInstance));
result.push(this._sharedControllersService.getTenantControl(serviceId, networkInstance));
result.push(this.getPlatformControl(networkInstance));
result.push(this._sharedControllersService.getLineOfBusinessControl(networkInstance));
result.push(this._sharedControllersService.getRollbackOnFailureControl(networkInstance));
}
return result;
}
getInstanceName(instance: any, serviceId: string, networkName: string, isEcompGeneratedNaming: boolean): FormControlModel {
const networkModel: NetworkModel = this.store.getState().service.serviceHierarchy[serviceId].networks[networkName];
return this._sharedControllersService.getInstanceNameController(instance, serviceId, isEcompGeneratedNaming, networkModel);
}
getPlatformControl = (instance: any): DropdownFormControl => {
return new DropdownFormControl({
type: FormControlType.DROPDOWN,
controlName: 'platformName',
displayName: 'Platform',
dataTestId: 'platform',
placeHolder: 'Select Platform',
isDisabled: false,
name: "platform",
value: instance ? instance.platformName : null,
validations: [],
onInitSelectedField: ['platformList'],
onInit: this._basicControlGenerator.getSubscribeInitResult.bind(null, this._aaiService.getCategoryParameters)
})
};
}
|