1 import {Injectable} from "@angular/core";
2 import {AaiService} from "../../../../services/aaiService/aai.service";
3 import {NgRedux} from "@angular-redux/store";
4 import {BasicControlGenerator} from "../basic.control.generator";
9 } 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 {SelectOption} from "../../../../models/selectOption";
15 import {VnfGroupModel} from "../../../../models/vnfGroupModel";
16 import * as _ from 'lodash';
17 import {Observable, of} from "rxjs";
20 export enum FormControlNames {
21 INSTANCE_NAME = 'instanceName',
22 ROLLBACK_ON_FAILURE = 'rollbackOnFailure',
26 ROLLBACK = "rollbackOnFailure"
30 export class VnfGroupControlGenerator {
31 aaiService: AaiService;
32 constructor(private _basicControlGenerator: BasicControlGenerator,
33 private store: NgRedux<AppState>,
34 private _aaiService: AaiService,
35 private _logService: LogService) {
36 this.aaiService = _aaiService;
39 getVnfGroupInstance = (serviceId: string, vnfGroupStoreKey: string): any => {
40 let vnfGroupInstance = null;
41 if (this.store.getState().service.serviceInstance[serviceId] && _.has(this.store.getState().service.serviceInstance[serviceId].vnfGroups, vnfGroupStoreKey)) {
42 vnfGroupInstance = Object.assign({}, this.store.getState().service.serviceInstance[serviceId].vnfGroups[vnfGroupStoreKey]);
44 return vnfGroupInstance;
47 getMacroFormControls(serviceId: string, vnfGroupStoreKey: string, vnfGroupName: string, dynamicInputs?: Array<any>): Array<FormControlModel> {
48 vnfGroupStoreKey = _.isNil(vnfGroupStoreKey) ? vnfGroupName : vnfGroupStoreKey;
50 if (_.isNil(serviceId) || _.isNil(vnfGroupStoreKey) || _.isNil(vnfGroupName)) {
51 this._logService.error('should provide serviceId, vnfGroupName, vnfGroupStoreKey', serviceId);
55 const vnfGroupInstance = this.getVnfGroupInstance(serviceId, vnfGroupStoreKey);
56 const vnfGroupModel = new VnfGroupModel(this.store.getState().service.serviceHierarchy[serviceId].vnfGroups[vnfGroupName]);
57 let result: FormControlModel[] = [];
59 if (!_.isNil(vnfGroupModel)) {
60 result.push(this.getInstanceName(vnfGroupInstance, serviceId, vnfGroupName, vnfGroupModel.isEcompGeneratedNaming));
65 getAlaCarteFormControls(serviceId: string, vnfGroupStoreKey: string, vnfGroupName: string, dynamicInputs?: any[]): FormControlModel[] {
66 vnfGroupStoreKey = _.isNil(vnfGroupStoreKey) ? vnfGroupName : vnfGroupStoreKey;
67 if (_.isNil(serviceId) || _.isNil(vnfGroupStoreKey) || _.isNil(vnfGroupName)) {
68 this._logService.error('should provide serviceId, vnfGroupName, vnfGroupStoreKey', serviceId);
72 let result: FormControlModel[] = [];
73 const vnfGroupInstance = this.getVnfGroupInstance(serviceId, vnfGroupStoreKey);
74 const vnfGroupModel = new VnfGroupModel(this.store.getState().service.serviceHierarchy[serviceId].vnfGroups[vnfGroupName]);
76 if (!_.isNil(vnfGroupModel)) {
77 result.push(this.getInstanceName(vnfGroupInstance, serviceId, vnfGroupName, vnfGroupModel.isEcompGeneratedNaming));
78 result.push(this.getRollbackOnFailureControl(vnfGroupInstance, result));
83 isInputShouldBeShown = (inputType: any): boolean => {
84 let vnfGroupInputs = [InputType.ROLLBACK];
85 return vnfGroupInputs.indexOf(inputType) > -1;
88 getDefaultInstanceName(instance : any, serviceId : string, vnfGroupName : string) : string {
89 const vnfGroupModel: VnfGroupModel = this.store.getState().service.serviceHierarchy[serviceId].vnfGroups[vnfGroupName];
90 return this._basicControlGenerator.getDefaultInstanceName(instance, vnfGroupModel);
93 getInstanceName(instance : any, serviceId : string, vnfGroupName : string, isEcompGeneratedNaming: boolean): FormControlModel {
94 const vnfGroupModel : VnfGroupModel = this.store.getState().service.serviceHierarchy[serviceId].vnfGroups[vnfGroupName];
95 return this._basicControlGenerator.getInstanceNameController(instance, serviceId, isEcompGeneratedNaming, vnfGroupModel);
98 getRollbackOnFailureControl = (instance: any, controls: FormControlModel[]): DropdownFormControl => {
99 return new DropdownFormControl({
100 type: FormControlType.DROPDOWN,
101 controlName: FormControlNames.ROLLBACK_ON_FAILURE,
102 displayName: 'Rollback on failure',
103 dataTestId: 'rollback',
104 placeHolder: 'Rollback on failure',
106 validations: [new ValidatorModel(ValidatorOptions.required, 'is required')],
107 value: instance ? instance.rollbackOnFailure : 'true',
108 onInit: this._basicControlGenerator.getSubscribeInitResult.bind(null, this.getRollBackOnFailureOptions)
112 getRollBackOnFailureOptions = (): Observable<SelectOption[]> => {
114 new SelectOption({id: 'true', name: 'Rollback'}),
115 new SelectOption({id: 'false', name: 'Don\'t Rollback'})