aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/pnfGenerator/pnf.control.generator.ts
blob: 7e3381701bfb73fdec79d8e79a3e9ceaff26a0cd (plain)
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
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 {FormControlModel} from "../../../../models/formControlModels/formControl.model";
import {LogService} from "../../../../utils/log/log.service";
import {PNFModel} from "../../../../models/pnfModel";
import {AppState} from "../../../../store/reducers";
import * as _ from 'lodash';
import {SharedControllersService} from "../sharedControlles/shared.controllers.service";

@Injectable()
export class PnfControlGenerator {
  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;
  }

  getPnfInstance = (serviceId: string, pnfStoreKey: string): any => {
    let pnfInstance = null;
    if (this.store.getState().service.serviceInstance[serviceId] && _.has(this.store.getState().service.serviceInstance[serviceId].pnfs, pnfStoreKey)) {
      pnfInstance = Object.assign({}, this.store.getState().service.serviceInstance[serviceId].pnfs[pnfStoreKey]);
    }
    return pnfInstance;
  };

  getMacroFormControls(serviceId: string, pnfStoreKey: string, pnfName: string, dynamicInputs?: any[]): FormControlModel[] {
    pnfStoreKey = _.isNil(pnfStoreKey) ? pnfName : pnfStoreKey;

    if (_.isNil(serviceId) || _.isNil(pnfStoreKey) || _.isNil(pnfName)) {
      this._logService.error('should provide serviceId, pnfName, pnfStoreKey', serviceId);
      return [];
    }
    const pnfInstance = this._basicControlGenerator.retrieveInstanceIfUpdateMode(this.store,this.getPnfInstance(serviceId, pnfStoreKey));
    const pnfModel = new PNFModel(this.store.getState().service.serviceHierarchy[serviceId].pnfs[pnfName]);
    let result: FormControlModel[] = [];
    const flags = this.store.getState().global.flags;

    if (!_.isNil(pnfModel)) {
      const isPlatformMultiSelected = flags['FLAG_2002_PNF_PLATFORM_MULTI_SELECT'];
      const isLobMultiSelected = flags['FLAG_2006_PNF_LOB_MULTI_SELECT'];

      result.push(this.getInstanceName(pnfInstance, serviceId, pnfName, pnfModel.isEcompGeneratedNaming));
      result.push(this._sharedControllersService.getProductFamilyControl(pnfInstance, result, true));
      result.push(this._sharedControllersService.getPlatformMultiselectControl(pnfInstance, result, isPlatformMultiSelected));
      result.push(this._sharedControllersService.getLobMultiselectControl(pnfInstance, isLobMultiSelected));
    }
    return result;
  }

  getAlaCarteFormControls(serviceId: string, pnfStoreKey: string, pnfName: string, dynamicInputs?: any[]): FormControlModel[] {
    pnfStoreKey = _.isNil(pnfStoreKey) ? pnfName : pnfStoreKey;
    if (_.isNil(serviceId) || _.isNil(pnfStoreKey) || _.isNil(pnfName)) {
      this._logService.error('should provide serviceId, pnfName, pnfStoreKey', serviceId);
      return [];
    }

    let result: FormControlModel[] = [];
    const pnfInstance = this._basicControlGenerator.retrieveInstanceIfUpdateMode(this.store,this.getPnfInstance(serviceId, pnfStoreKey));
    const pnfModel = new PNFModel(this.store.getState().service.serviceHierarchy[serviceId].pnfs[pnfName]);
    const flags = this.store.getState().global.flags;

    if (!_.isNil(pnfModel)) {
      const isPlatformMultiSelected = flags['FLAG_2002_VNF_PLATFORM_MULTI_SELECT'];
      const isLobMultiSelected = flags['FLAG_2006_VNF_LOB_MULTI_SELECT'];
      result.push(this.getInstanceName(pnfInstance, serviceId, pnfName, pnfModel.isEcompGeneratedNaming));
      result.push(this._sharedControllersService.getProductFamilyControl(pnfInstance, result, true));
      result.push(this._sharedControllersService.getPlatformMultiselectControl(pnfInstance, result, isPlatformMultiSelected));
      result.push(this._sharedControllersService.getLobMultiselectControl(pnfInstance,isLobMultiSelected));
      result.push(this._sharedControllersService.getRollbackOnFailureControl(pnfInstance));
    }
    return result;
  }

  getInstanceName(instance : any, serviceId : string, pnfName : string, isEcompGeneratedNaming: boolean): FormControlModel {
    const pnfModel : PNFModel = this.store.getState().service.serviceHierarchy[serviceId].pnfs[pnfName];
    return this._sharedControllersService.getInstanceNameController(instance, serviceId, isEcompGeneratedNaming, pnfModel);
  }
}