1 import {Injectable} from "@angular/core";
2 import {FormPopupDetails, PopupType} from "../../../../models/formControlModels/formPopupDetails.model";
3 import {ControlGeneratorUtil} from "../../../genericForm/formControlsServices/control.generator.util.service";
4 import {AppState} from "../../../../store/reducers";
5 import {NgRedux} from "@angular-redux/store";
6 import {ITreeNode} from "angular-tree-component/dist/defs/api";
7 import {ModelInformationItem} from "../../../model-information/model-information.component";
8 import {Constants} from "../../../../utils/constants";
9 import {AaiService} from "../../../../services/aaiService/aai.service";
10 import {ServiceModel} from "../../../../models/serviceModel";
11 import {FormGroup} from "@angular/forms";
12 import {ModelInfo} from "../../../../models/modelInfo";
13 import {IframeService} from "../../../../utils/iframe.service";
14 import {GenericPopupInterface} from "../generic-popup.interface";
15 import {Subject} from "rxjs/Subject";
16 import {DefaultDataGeneratorService} from "../../../../services/defaultDataServiceGenerator/default.data.generator.service";
17 import {BasicPopupService} from "../basic.popup.service";
18 import {VfModuleInstance} from "../../../../models/vfModuleInstance";
19 import {VfModuleControlGenerator} from "../../../genericForm/formControlsServices/vfModuleGenerator/vfModule.control.generator";
20 import {FormControlModel} from "../../../../models/formControlModels/formControl.model";
21 import * as _ from 'lodash';
22 import {createVFModuleInstance, updateVFModuleInstance} from "../../../../storeUtil/utils/vfModule/vfModule.actions";
23 import {SharedControllersService} from "../../../genericForm/formControlsServices/sharedControlles/shared.controllers.service";
24 import {SharedTreeService} from "../../../../../drawingBoard/service-planning/objectsToTree/shared.tree.service";
25 import {PauseStatus} from "../../../../models/serviceInstanceActions";
27 export abstract class VfModulePopupServiceBase {
31 serviceModel: ServiceModel;
32 modelInformations: ModelInformationItem[] = [];
34 closeDialogEvent: Subject<any> = new Subject<any>();
35 isUpdateMode: boolean;
36 storeVFModule = (that, formValues: any): void => {
37 formValues.pauseInstantiation = (formValues.pauseInstantiation || formValues.pauseInstantiation === PauseStatus.AFTER_COMPLETION)
38 ? PauseStatus.AFTER_COMPLETION : null;
39 formValues.modelInfo = new ModelInfo(that.model);
40 formValues.uuid = formValues.modelInfo.uuid;
41 formValues.isMissingData = false;
42 if (!that.uuidData.vFModuleStoreKey) {
43 let positionOfNextInstance = this._defaultDataGeneratorService.calculatePositionOfVfmodule(that.uuidData.serviceId);
44 this._store.dispatch(createVFModuleInstance(formValues, that.uuidData.modelName, that.uuidData.serviceId, !_.isNil(positionOfNextInstance)? positionOfNextInstance : null, that.uuidData.vnfStoreKey));
46 this._store.dispatch(updateVFModuleInstance(formValues, that.uuidData.modelName, that.uuidData.serviceId, that.uuidData.vFModuleStoreKey, that.uuidData.vnfStoreKey, this.getInstance(that.uuidData.serviceId, that.uuidData.vnfStoreKey, that.uuidData.vFModuleStoreKey).position));
50 protected constructor(
51 protected _basicControlGenerator: ControlGeneratorUtil,
52 protected _sharedControllersService : SharedControllersService,
53 protected _vfModuleControlGenerator: VfModuleControlGenerator,
54 protected _iframeService: IframeService,
55 protected _defaultDataGeneratorService: DefaultDataGeneratorService,
56 protected _aaiService: AaiService,
57 protected _basicPopupService: BasicPopupService,
58 protected _store: NgRedux<AppState>,
59 protected _sharedTreeService: SharedTreeService) {
62 getInstance(serviceId: string, vnfStoreKey: string, vfModuleStoreKey: string): any {
63 if (_.isNil(vnfStoreKey) || _.isNil(vfModuleStoreKey)) {
64 return new VfModuleInstance();
66 const vfModules = this._store.getState().service.serviceInstance[serviceId].vnfs[vnfStoreKey].vfModules;
67 return vfModules[this.uuidData['modelName']][vfModuleStoreKey];
70 getModelInformation(serviceId: string, modelName: string, vfModuleModeNode:ITreeNode) {
71 this._aaiService.getServiceModelById(serviceId).subscribe((result: any) => {
72 this.serviceModel = new ServiceModel(result);
73 this.model = this._basicPopupService.getModelFromResponse(result, 'vfModules', modelName);
74 const serviceInstance = this._store.getState().service.serviceInstance[serviceId];
75 this.modelInformations = [
76 new ModelInformationItem("Subscriber Name", "subscriberName", [this._basicPopupService.extractSubscriberNameBySubscriberId(serviceInstance.globalSubscriberId)], "", true),
77 new ModelInformationItem("Service Name", "serviceModelName", [this.serviceModel.name], "", true),
78 new ModelInformationItem("Service Instance Name", "serviceName", [serviceInstance.instanceName], "", false),
79 new ModelInformationItem("Model Name", "modelName", [this.model.name], "", true),
80 new ModelInformationItem("Model version", "modelVersion", [this._sharedTreeService.getModelVersionEitherFromInstanceOrFromHierarchy(vfModuleModeNode.data, this.model) ], "", true),
81 new ModelInformationItem("Description", "description", [this.model.description]),
82 new ModelInformationItem("Category", "category", [this.model.category]),
83 new ModelInformationItem("Sub Category", "subCategory", [this.model.subCategory]),
84 new ModelInformationItem("UUID", "uuid", [this._sharedTreeService.getModelVersionIdEitherFromInstanceOrFromHierarchy(vfModuleModeNode.data, this.model)], Constants.ServicePopup.TOOLTIP_UUID, true),
85 new ModelInformationItem("Invariant UUID", "invariantUuid", [this._sharedTreeService.getModelInvariantIdEitherFromInstanceOrFromHierarchy(vfModuleModeNode, this.model)], Constants.ServicePopup.TOOLTIP_INVARIANT_UUID, true),
86 new ModelInformationItem("Service type", "serviceType", [this.serviceModel.serviceType]),
87 new ModelInformationItem("Service role", "serviceRole", [this.serviceModel.serviceRole]),
88 new ModelInformationItem("Minimum to instantiate", "min", this.model.min == undefined ? ['0'] : [this.model.min.toString()], "", true),
89 this._basicPopupService.createMaximumToInstantiateModelInformationItem(this.model),
90 new ModelInformationItem("Recommended to instantiate", "initial", [this.model.initial])
95 protected postSubmitIframeMessage(that) {
96 window.parent.postMessage({
97 eventId: 'submitIframe',
99 serviceModelId: that.serviceModel.uuid
104 onCancel(that, form) {
106 that._iframeService.removeClassCloseModal('content');
107 this.closeDialogEvent.next(that);
110 getSubLeftTitle(): string {
111 return this.model.name;
114 getSubRightTitle(): string {
115 return "Module (Heat stack) Instance Details";
118 abstract getTitle(isUpdateMode : boolean) : string;
119 abstract getControls(serviceId: string, vnfStoreKey: string, vfModuleStoreKey: string, isUpdateMode: boolean);
120 abstract getDynamicInputs(UUIDData : Object) : FormControlModel[];
122 getGenericFormPopupDetails(serviceId: string, vnfStoreKey: string, vfModuleStoreKey: string, vfModuleNode: ITreeNode, uuidData: Object, isUpdateMode: boolean): FormPopupDetails {
124 this.uuidData = uuidData;
125 this.instance = this.getInstance(serviceId, vnfStoreKey, vfModuleStoreKey);
126 this.getModelInformation(serviceId, uuidData['modelName'], vfModuleNode);
128 return new FormPopupDetails(this,
131 this.getTitle(isUpdateMode),
132 this.getSubLeftTitle(),
133 this.getSubRightTitle(),
134 this.getControls(serviceId, vnfStoreKey, vfModuleStoreKey, isUpdateMode),
135 this.getDynamicInputs(uuidData),
136 this.modelInformations,
137 (that, form: FormGroup) => {
138 that.onSubmit(that, form);
140 (that: any, form: FormGroup) => {
141 that.onCancel(that, form);
146 updateFormValueWithSupplementaryFile(form: FormGroup, that) {
147 if (!_.isNil(form.controls['supplementaryFile_hidden_content']) && form.controls['supplementaryFile_hidden_content'].value) {
148 form.value['supplementaryFileContent'] = JSON.parse(form.controls['supplementaryFile_hidden_content'].value);
149 if (!_.isNil(form.controls['supplementaryFile_hidden'].value)) {
150 form.value['supplementaryFileName'] = form.controls['supplementaryFile_hidden'].value.name;
152 form.value['supplementaryFileName'] = that.instance.supplementaryFileName;
155 delete form.value['supplementaryFileContent'];
156 delete form.value['supplementaryFileName'];
162 export class VfModulePopupService extends VfModulePopupServiceBase implements GenericPopupInterface {
165 constructor(_basicControlGenerator: ControlGeneratorUtil,
166 _sharedControllersService : SharedControllersService,
167 _vfModuleControlGenerator: VfModuleControlGenerator,
168 _iframeService: IframeService,
169 _defaultDataGeneratorService: DefaultDataGeneratorService,
170 _aaiService: AaiService,
171 _basicPopupService : BasicPopupService,
172 _store: NgRedux<AppState>,
173 _sharedTreeService: SharedTreeService) {
174 super(_basicControlGenerator, _sharedControllersService, _vfModuleControlGenerator, _iframeService, _defaultDataGeneratorService, _aaiService, _basicPopupService, _store, _sharedTreeService);
178 getDynamicInputs(UUIDData : Object) : FormControlModel[]{
179 let dynamic = this._defaultDataGeneratorService.getArbitraryInputs(this._store.getState().service.serviceHierarchy[UUIDData['serviceId']].vfModules[UUIDData['modelName']].inputs);
180 return this.getVFModuleDynamicInputs(dynamic, UUIDData);
183 getVFModuleDynamicInputs(dynamicInputs : any, UUIDData : Object) : FormControlModel[] {
184 let result : FormControlModel[] = [];
186 let vfModuleInstance = null;
187 if (_.has(this._store.getState().service.serviceInstance[UUIDData['serviceId']].vnfs, UUIDData['vnfStoreKey']) &&
188 _.has(this._store.getState().service.serviceInstance[UUIDData['serviceId']].vnfs[UUIDData['vnfStoreKey']].vfModules, UUIDData['modelName'])) {
189 vfModuleInstance = Object.assign({},this._store.getState().service.serviceInstance[UUIDData['serviceId']].vnfs[UUIDData['vnfStoreKey']].vfModules[UUIDData['modelName']][UUIDData['vfModuleStoreKey']]);
191 result = this._basicControlGenerator.getDynamicInputs(dynamicInputs, vfModuleInstance);
197 getControls(serviceId: string, vnfStoreKey: string, vfModuleStoreKey: string, isUpdateMode: boolean) {
198 if (this._store.getState().service.serviceHierarchy[serviceId].service.vidNotions.instantiationType === 'Macro') {
199 return this._vfModuleControlGenerator.getMacroFormControls(serviceId, vnfStoreKey, vfModuleStoreKey, this.uuidData, isUpdateMode);
201 return this._vfModuleControlGenerator.getAlaCarteFormControls(serviceId, vnfStoreKey, vfModuleStoreKey, this.uuidData, isUpdateMode);
206 onSubmit(that, form: FormGroup) {
207 form.value['instanceParams'] = form.value['instanceParams'] && [form.value['instanceParams']];
208 this.updateFormValueWithSupplementaryFile(form, that);
209 that.storeVFModule(that, form.value);
210 this.postSubmitIframeMessage(that);
211 this.onCancel(that, form);
214 getTitle(isUpdateMode : boolean) : string {
215 return isUpdateMode ? 'Edit Module (Heat stack)' : 'Set new Module (Heat stack)';