Support addition of scalar type constraints
[sdc.git] / catalog-ui / src / app / view-models / forms / property-forms / component-property-form / property-form-view-model.ts
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 'use strict';
22 import * as _ from "lodash";
23 import {FormState, PROPERTY_DATA, PROPERTY_TYPES, PROPERTY_VALUE_CONSTRAINTS, ValidationUtils} from "app/utils";
24 import {DataTypesService} from "app/services";
25 import {DataTypesMap, PropertyModel} from "app/models";
26 import {ComponentInstance} from "../../../../models/componentsInstances/componentInstance";
27 import {ComponentInstanceServiceNg2} from "app/ng2/services/component-instance-services/component-instance.service";
28 import {SdcUiCommon, SdcUiComponents, SdcUiServices} from "onap-ui-angular";
29 import {CompositionService} from "app/ng2/pages/composition/composition.service";
30 import {WorkspaceService} from "app/ng2/pages/workspace/workspace.service";
31 import {Observable} from "rxjs";
32 import {TopologyTemplateService} from "app/ng2/services/component-services/topology-template.service";
33 import {InstanceFeDetails} from "../../../../models/instance-fe-details";
34 import {ToscaGetFunction} from "../../../../models/tosca-get-function";
35 import {ToscaFunctionValidationEvent} from "../../../../ng2/pages/properties-assignment/tosca-function/tosca-function.component";
36
37 export interface IEditPropertyModel {
38     property:PropertyModel;
39     types:Array<string>;
40     simpleTypes:Array<string>;
41     hasGetFunctionValue: boolean;
42     isGetFunctionValid: boolean;
43 }
44
45 interface IPropertyFormViewModelScope extends ng.IScope {
46     forms:any;
47     editForm:ng.IFormController;
48     footerButtons:Array<any>;
49     isNew:boolean;
50     nameMaxLength:number;
51     isLoading:boolean;
52     componentMetadata: { isService: boolean, isVfc: boolean }
53     validationPattern:RegExp;
54     propertyNameValidationPattern:RegExp;
55     commentValidationPattern:RegExp;
56     editPropertyModel: IEditPropertyModel;
57     componentInstanceMap: Map<string, InstanceFeDetails>;
58     modalInstanceProperty:ng.ui.bootstrap.IModalServiceInstance;
59     currentPropertyIndex:number;
60     isLastProperty:boolean;
61     myValue:any;
62     nonPrimitiveTypes:Array<string>;
63     dataTypes:DataTypesMap;
64     isTypeDataType:boolean;
65     maxLength:number;
66     isViewOnly:boolean;
67     isPropertyValueOwner:boolean;
68     isVnfConfiguration:boolean;
69     constraints:string[];
70     modelNameFilter:string;
71     isGetFunctionValueType: boolean;
72     invalidMandatoryFields: boolean;
73
74     validateJson(json:string):boolean;
75     save(doNotCloseModal?:boolean):void;
76     getValidationPattern(type:string):RegExp;
77     validateIntRange(value:string):boolean;
78     close():void;
79     onValueChange():void;
80     onSchemaTypeChange():void;
81     onTypeChange(resetSchema:boolean):void;
82     showSchema():boolean;
83     delete(property:PropertyModel):void;
84     getPrev():void;
85     getNext():void;
86     isSimpleType(typeName:string):boolean;
87     getDefaultValue():any;
88     onValueTypeChange(): void;
89 }
90
91 export class PropertyFormViewModel {
92
93     static '$inject' = [
94         '$scope',
95         'Sdc.Services.DataTypesService',
96         '$uibModalInstance',
97         'property',
98         'ValidationPattern',
99         'PropertyNameValidationPattern',
100         'CommentValidationPattern',
101         'ValidationUtils',
102         // 'component',
103         '$filter',
104         'ModalServiceSdcUI',
105         'filteredProperties',
106         '$timeout',
107         'isViewOnly',
108         'isPropertyValueOwner',
109         'propertyOwnerType',
110         'propertyOwnerId',
111         'ComponentInstanceServiceNg2',
112         'TopologyTemplateService',
113         'CompositionService',
114         'workspaceService'
115     ];
116
117     private formState:FormState;
118
119     constructor(private $scope:IPropertyFormViewModelScope,
120                 private DataTypesService:DataTypesService,
121                 private $uibModalInstance:ng.ui.bootstrap.IModalServiceInstance,
122                 private property:PropertyModel,
123                 private ValidationPattern:RegExp,
124                 private PropertyNameValidationPattern:RegExp,
125                 private CommentValidationPattern:RegExp,
126                 private ValidationUtils:ValidationUtils,
127                 // private component:Component,
128                 private $filter:ng.IFilterService,
129                 private modalService:SdcUiServices.ModalService,
130                 private filteredProperties:Array<PropertyModel>,
131                 private $timeout:ng.ITimeoutService,
132                 private isViewOnly:boolean,
133                 private isPropertyValueOwner:boolean,
134                 private propertyOwnerType:string,
135                 private propertyOwnerId:string,
136                 private ComponentInstanceServiceNg2: ComponentInstanceServiceNg2,
137                 private topologyTemplateService: TopologyTemplateService,
138                 private compositionService: CompositionService,
139                 private workspaceService: WorkspaceService) {
140
141         this.formState = angular.isDefined(property.name) ? FormState.UPDATE : FormState.CREATE;
142         this.initScope();
143     }
144
145     private initResource = ():void => {
146         this.$scope.editPropertyModel.property = new PropertyModel(this.property);
147         this.$scope.editPropertyModel.property.type = this.property.type ? this.property.type : null;
148         this.$scope.constraints = this.property.constraints && this.property.constraints[0] ? this.property.constraints[0]["validValues"] : null;
149         this.initToscaGetFunction();
150         this.setMaxLength();
151     };
152
153     private initToscaGetFunction() {
154         this.$scope.editPropertyModel.hasGetFunctionValue = this.$scope.editPropertyModel.property.isToscaFunction();
155         this.$scope.editPropertyModel.isGetFunctionValid = true;
156     }
157
158     private initForNotSimpleType = ():void => {
159         const property = this.$scope.editPropertyModel.property;
160         this.$scope.isTypeDataType = this.DataTypesService.isDataTypeForPropertyType(this.$scope.editPropertyModel.property);
161         if (property.isToscaFunction()) {
162             this.initValueForGetFunction();
163             return;
164         }
165
166         if (this.isComplexType(property.type)) {
167             if (property.value || property.defaultValue) {
168                 this.$scope.myValue = JSON.parse(property.value || property.defaultValue);
169             } else {
170                 this.initEmptyComplexValue(property.type);
171             }
172         }
173     };
174
175     private initValueForGetFunction(): void {
176         const property = this.$scope.editPropertyModel.property;
177         if (property.defaultValue) {
178             this.$scope.myValue = JSON.parse(property.defaultValue);
179             return;
180         }
181         if (this.isComplexType(property.type)) {
182             this.initEmptyComplexValue(property.type);
183             return;
184         }
185
186         this.$scope.myValue = undefined;
187     }
188
189     private initComponentInstanceMap() {
190         this.$scope.componentInstanceMap = new Map<string, InstanceFeDetails>();
191         if (this.compositionService.componentInstances) {
192             this.compositionService.componentInstances.forEach(value => {
193                 this.$scope.componentInstanceMap.set(value.uniqueId, <InstanceFeDetails>{
194                     name: value.name
195                 });
196             });
197         }
198     }
199
200     private initEmptyComplexValue(type: string): any {
201         switch (type) {
202             case PROPERTY_TYPES.MAP:
203                 this.$scope.myValue = {'': null};
204                 break;
205             case PROPERTY_TYPES.LIST:
206                 this.$scope.myValue = [];
207                 break;
208             default:
209                 this.$scope.myValue = {};
210         }
211     }
212
213     private isComplexType(type: string): boolean {
214         if (!type) {
215             return false;
216         }
217         return PROPERTY_DATA.SIMPLE_TYPES.indexOf(type) == -1;
218     }
219
220     private setMaxLength = ():void => {
221         switch (this.$scope.editPropertyModel.property.type) {
222             case PROPERTY_TYPES.MAP:
223             case PROPERTY_TYPES.LIST:
224                 this.$scope.maxLength = this.$scope.editPropertyModel.property.schema.property.type == PROPERTY_TYPES.JSON ?
225                     PROPERTY_VALUE_CONSTRAINTS.JSON_MAX_LENGTH :
226                     PROPERTY_VALUE_CONSTRAINTS.MAX_LENGTH;
227                 break;
228             case PROPERTY_TYPES.JSON:
229                 this.$scope.maxLength = PROPERTY_VALUE_CONSTRAINTS.JSON_MAX_LENGTH;
230                 break;
231             default:
232                 this.$scope.maxLength =PROPERTY_VALUE_CONSTRAINTS.MAX_LENGTH;
233         }
234     };
235
236
237     private initScope = ():void => {
238
239         //scope properties
240         this.$scope.isViewOnly = this.isViewOnly;
241         this.$scope.isLoading = true;
242         this.$scope.forms = {};
243         this.$scope.validationPattern = this.ValidationPattern;
244         this.$scope.propertyNameValidationPattern = this.PropertyNameValidationPattern;
245         this.$scope.commentValidationPattern = this.CommentValidationPattern;
246         this.$scope.nameMaxLength = PROPERTY_VALUE_CONSTRAINTS.NAME_MAX_LENGTH;
247         this.$scope.isNew = (this.formState === FormState.CREATE);
248         this.$scope.componentMetadata = {
249             isService: this.workspaceService.metadata.isService(),
250             isVfc: this.workspaceService.metadata.isVfc()
251         }
252         this.$scope.modalInstanceProperty = this.$uibModalInstance;
253         this.$scope.currentPropertyIndex = _.findIndex(this.filteredProperties, i=> i.name == this.property.name);
254         this.$scope.isLastProperty = this.$scope.currentPropertyIndex == (this.filteredProperties.length - 1);
255         const property = new PropertyModel(this.property);
256         this.$scope.editPropertyModel = {
257             'property': property,
258             types: PROPERTY_DATA.TYPES,
259             simpleTypes: PROPERTY_DATA.SIMPLE_TYPES,
260             hasGetFunctionValue: property.isToscaFunction(),
261             isGetFunctionValid: true,
262         };
263         this.$scope.isPropertyValueOwner = this.isPropertyValueOwner;
264         this.$scope.propertyOwnerType = this.propertyOwnerType;
265         this.$scope.modelNameFilter = this.workspaceService.metadata.model;
266         //check if property of VnfConfiguration
267         this.$scope.isVnfConfiguration = false;
268         if(this.propertyOwnerType == "component" && angular.isArray(this.compositionService.componentInstances)) {
269             const componentPropertyOwner:ComponentInstance = this.compositionService.componentInstances.find((ci:ComponentInstance) => {
270                 return ci.uniqueId === this.property.resourceInstanceUniqueId;
271             });
272             if (componentPropertyOwner && componentPropertyOwner.componentName === 'vnfConfiguration') {
273                 this.$scope.isVnfConfiguration = true;
274             }
275         }
276         this.initResource();
277         this.initForNotSimpleType();
278         this.initComponentInstanceMap();
279
280         this.$scope.validateJson = (json:string):boolean => {
281             if (!json) {
282                 return true;
283             }
284             return this.ValidationUtils.validateJson(json);
285         };
286
287         this.DataTypesService.fetchDataTypesByModel(this.workspaceService.metadata.model).then(response => {
288             this.$scope.dataTypes = response.data as DataTypesMap;
289             this.$scope.nonPrimitiveTypes = _.filter(Object.keys(this.$scope.dataTypes), (type:string)=> {
290                 return this.$scope.editPropertyModel.types.indexOf(type) == -1;
291             });
292
293             this.$scope.isLoading = false;
294         });
295
296         //scope methods
297         this.$scope.save = (doNotCloseModal?:boolean):void => {
298             let property:PropertyModel = this.$scope.editPropertyModel.property;
299             this.$scope.editPropertyModel.property.description = this.ValidationUtils.stripAndSanitize(this.$scope.editPropertyModel.property.description);
300             //if read only - or no changes made - just closes the modal
301             //need to check for property.value changes manually to detect if map properties deleted
302             if ((this.$scope.editPropertyModel.property.readonly && !this.$scope.isPropertyValueOwner)
303                 || (!this.$scope.forms.editForm.$dirty && angular.equals(JSON.stringify(this.$scope.myValue), this.$scope.editPropertyModel.property.value))) {
304                 this.$uibModalInstance.close();
305                 return;
306             }
307
308             this.$scope.isLoading = true;
309
310             let onPropertyFailure = (response):void => {
311                 console.error('Failed to update property', response);
312                 this.$scope.isLoading = false;
313             };
314
315             let onPropertySuccess = (propertyFromBE:PropertyModel):void => {
316                 this.$scope.isLoading = false;
317                 this.filteredProperties[this.$scope.currentPropertyIndex] = propertyFromBE;
318                 if (!doNotCloseModal) {
319                     this.$uibModalInstance.close(propertyFromBE);
320                 } else {
321                     this.$scope.forms.editForm.$setPristine();
322                     this.$scope.editPropertyModel.property = new PropertyModel();
323                 }
324             };
325
326             //Not clean, but doing this as a temporary fix until we update the property right panel modals
327             if (this.propertyOwnerType === "group"){
328                 this.ComponentInstanceServiceNg2.updateComponentGroupInstanceProperties(this.workspaceService.metadata.componentType, this.workspaceService.metadata.uniqueId, this.propertyOwnerId, [property])
329                     .subscribe((propertiesFromBE) => { onPropertySuccess(<PropertyModel>propertiesFromBE[0])}, error => onPropertyFailure(error));
330             } else if (this.propertyOwnerType === "policy"){
331                 if (!this.$scope.editPropertyModel.property.simpleType &&
332                     !this.$scope.isSimpleType(this.$scope.editPropertyModel.property.type) &&
333                     !_.isNil(this.$scope.myValue)) {
334                     property.value = JSON.stringify(this.$scope.myValue);
335                 }
336                 this.ComponentInstanceServiceNg2.updateComponentPolicyInstanceProperties(this.workspaceService.metadata.componentType, this.workspaceService.metadata.uniqueId, this.propertyOwnerId, [property])
337                     .subscribe((propertiesFromBE) => { onPropertySuccess(<PropertyModel>propertiesFromBE[0])}, error => onPropertyFailure(error));
338             } else {
339                 //in case we have uniqueId we call update method
340                 if (this.$scope.isPropertyValueOwner) {
341                     if (!this.$scope.editPropertyModel.property.simpleType && !this.$scope.isSimpleType(property.type)) {
342                         property.value = JSON.stringify(this.$scope.myValue);
343                     }
344                     this.updateInstanceProperties(property.resourceInstanceUniqueId, [property]).subscribe((propertiesFromBE) => onPropertySuccess(propertiesFromBE[0]),
345                         error => onPropertyFailure(error));
346                 } else {
347                     if (!this.$scope.editPropertyModel.property.simpleType && !this.$scope.isSimpleType(property.type)) {
348                         property.defaultValue = JSON.stringify(this.$scope.myValue);
349                     } else {
350                         this.$scope.editPropertyModel.property.defaultValue = this.$scope.editPropertyModel.property.value;
351                     }
352                     this.addOrUpdateProperty(property).subscribe(onPropertySuccess, error => onPropertyFailure(error));
353                 }
354             }
355         };
356
357         this.$scope.getPrev = ():void=> {
358             this.property = this.filteredProperties[--this.$scope.currentPropertyIndex];
359             this.initResource();
360             this.initForNotSimpleType();
361             this.$scope.isLastProperty = false;
362         };
363
364         this.$scope.getNext = ():void=> {
365             this.property = this.filteredProperties[++this.$scope.currentPropertyIndex];
366             this.initResource();
367             this.initForNotSimpleType();
368             this.$scope.isLastProperty = this.$scope.currentPropertyIndex == (this.filteredProperties.length - 1);
369         };
370
371         this.$scope.isSimpleType = (typeName:string):boolean=> {
372             return typeName && this.$scope.editPropertyModel.simpleTypes.indexOf(typeName) != -1;
373         };
374
375         this.$scope.showSchema = ():boolean => {
376             return [PROPERTY_TYPES.LIST, PROPERTY_TYPES.MAP].indexOf(this.$scope.editPropertyModel.property.type) > -1;
377         };
378
379         this.$scope.getValidationPattern = (type:string):RegExp => {
380             return this.ValidationUtils.getValidationPattern(type);
381         };
382
383         this.$scope.validateIntRange = (value:string):boolean => {
384             return !value || this.ValidationUtils.validateIntRange(value);
385         };
386
387         this.$scope.close = ():void => {
388             this.$uibModalInstance.close();
389         };
390
391         // put default value when instance value is empty
392         this.$scope.onValueChange = ():void => {
393             if (!this.$scope.editPropertyModel.property.value) {
394                 if (this.$scope.isPropertyValueOwner) {
395                     this.$scope.editPropertyModel.property.value = this.$scope.editPropertyModel.property.defaultValue;
396                 }
397             }
398         };
399
400         // Add the done button at the footer.
401         this.$scope.footerButtons = [
402             {'name': 'Save', 'css': 'blue', 'callback': this.$scope.save},
403             {'name': 'Cancel', 'css': 'grey', 'callback': this.$scope.close}
404         ];
405
406         this.$scope.$watch("forms.editForm.$invalid", (newVal) => {
407             if (this.$scope.editPropertyModel.hasGetFunctionValue) {
408                 this.$scope.invalidMandatoryFields = !newVal || !this.$scope.editPropertyModel.property.toscaFunction || this.isViewOnly;
409                 this.$scope.footerButtons[0].disabled = this.$scope.invalidMandatoryFields;
410             } else {
411                 this.$scope.invalidMandatoryFields = !newVal || this.isViewOnly;
412                 this.$scope.footerButtons[0].disabled = this.$scope.invalidMandatoryFields;
413             }
414         });
415
416         this.$scope.$watch("forms.editForm.$valid", (newVal) => {
417             if (this.$scope.editPropertyModel.hasGetFunctionValue) {
418                 this.$scope.invalidMandatoryFields = !newVal || !this.$scope.editPropertyModel.property.toscaFunction || this.isViewOnly;
419                 this.$scope.footerButtons[0].disabled = this.$scope.invalidMandatoryFields;
420             } else {
421                 this.$scope.invalidMandatoryFields = !newVal || this.isViewOnly;
422                 this.$scope.footerButtons[0].disabled = this.$scope.invalidMandatoryFields;
423             }
424         });
425
426         this.$scope.getDefaultValue = ():any => {
427             return this.$scope.isPropertyValueOwner ? this.$scope.editPropertyModel.property.defaultValue : null;
428         };
429
430         this.$scope.onTypeChange = ():void => {
431             this.$scope.editPropertyModel.property.value = '';
432             this.$scope.editPropertyModel.property.defaultValue = '';
433             this.setMaxLength();
434             this.initForNotSimpleType();
435         };
436
437         this.$scope.onSchemaTypeChange = ():void => {
438             if (this.$scope.editPropertyModel.property.type == PROPERTY_TYPES.MAP) {
439                 this.$scope.myValue = {};
440             } else if (this.$scope.editPropertyModel.property.type == PROPERTY_TYPES.LIST) {
441                 this.$scope.myValue = [];
442             }
443             this.setMaxLength();
444         };
445
446         this.$scope.delete = (property:PropertyModel):void => {
447             let onOk: Function = ():void => {
448                 this.deleteProperty(property.uniqueId).subscribe(
449                     this.$scope.close
450                 );
451             };
452             let title:string = this.$filter('translate')("PROPERTY_VIEW_DELETE_MODAL_TITLE");
453             let message:string = this.$filter('translate')("PROPERTY_VIEW_DELETE_MODAL_TEXT", "{'name': '" + property.name + "'}");
454             const okButton = {testId: "OK", text: "OK", type: SdcUiCommon.ButtonType.info, callback: onOk, closeModal: true} as SdcUiComponents.ModalButtonComponent;
455             this.modalService.openInfoModal(title, message, 'delete-modal', [okButton]);
456         };
457
458         this.$scope.onValueTypeChange = (): void => {
459             this.setEmptyValue();
460             if (this.$scope.editPropertyModel.hasGetFunctionValue) {
461                 this.$scope.editPropertyModel.isGetFunctionValid = undefined;
462             } else {
463                 this.$scope.editPropertyModel.property.toscaFunction = undefined;
464                 this.$scope.editPropertyModel.isGetFunctionValid = true;
465             }
466         }
467
468         this.$scope.onConstraintChange = (constraints: any): void => {
469             if (!this.$scope.invalidMandatoryFields) {
470                 this.$scope.footerButtons[0].disabled = !constraints.valid;
471             } else {
472                 this.$scope.footerButtons[0].disabled = this.$scope.invalidMandatoryFields;
473             }
474             if (!constraints.constraints || constraints.constraints.length == 0) {
475                 this.$scope.editPropertyModel.property.propertyConstraints = null;
476                 this.$scope.editPropertyModel.property.constraints = null;
477                 return;
478             }
479             this.$scope.editPropertyModel.property.propertyConstraints = this.serializePropertyConstraints(constraints.constraints);
480             this.$scope.editPropertyModel.property.constraints = constraints.constraints;
481         }
482
483         this.$scope.onGetFunctionValidFunction = (toscaGetFunction: ToscaGetFunction): void => {
484             this.$scope.editPropertyModel.property.toscaFunction = toscaGetFunction;
485         }
486
487         this.$scope.onToscaFunctionValidityChange = (validationEvent: ToscaFunctionValidationEvent): void => {
488             if (validationEvent.isValid) {
489                 this.$scope.editPropertyModel.isGetFunctionValid = true;
490                 return;
491             }
492             this.$scope.editPropertyModel.isGetFunctionValid = undefined;
493         }
494     };
495
496     private serializePropertyConstraints(constraints: any[]): string[] {
497         if (constraints) {
498             let stringConstrsints = new Array();
499             constraints.forEach((constraint) => {
500                 stringConstrsints.push(JSON.stringify(constraint));
501             })
502             return stringConstrsints;
503         }
504         return null;
505     }
506
507     private setEmptyValue() {
508         const property1 = this.$scope.editPropertyModel.property;
509         property1.value = undefined;
510         if (this.isComplexType(property1.type)) {
511             this.initEmptyComplexValue(property1.type);
512             return;
513         }
514         this.$scope.myValue = '';
515     }
516
517     private updateInstanceProperties = (componentInstanceId:string, properties:PropertyModel[]):Observable<PropertyModel[]> => {
518
519         return this.ComponentInstanceServiceNg2.updateInstanceProperties(this.workspaceService.metadata.componentType, this.workspaceService.metadata.uniqueId, componentInstanceId, properties)
520             .map(newProperties => {
521                 newProperties.forEach((newProperty) => {
522                     if (!_.isNil(newProperty.path)) {
523                         if (newProperty.path[0] === newProperty.resourceInstanceUniqueId) newProperty.path.shift();
524                         // find exist instance property in parent component for update the new value ( find bu uniqueId & path)
525                         let existProperty: PropertyModel = <PropertyModel>_.find(this.compositionService.componentInstancesProperties[newProperty.resourceInstanceUniqueId], {
526                             uniqueId: newProperty.uniqueId,
527                             path: newProperty.path
528                         });
529                         let index = this.compositionService.componentInstancesProperties[newProperty.resourceInstanceUniqueId].indexOf(existProperty);
530                         this.compositionService.componentInstancesProperties[newProperty.resourceInstanceUniqueId][index] = newProperty;
531                     }
532                 });
533                 return newProperties;
534             });
535     };
536
537     private addOrUpdateProperty = (property: PropertyModel): Observable<PropertyModel> => {
538         if (!property.uniqueId) {
539             let onSuccess = (newProperty: PropertyModel): PropertyModel => {
540                 this.filteredProperties.push(newProperty);
541                 return newProperty;
542             };
543             return this.topologyTemplateService.addProperty(this.workspaceService.metadata.componentType, this.workspaceService.metadata.uniqueId, property)
544                 .map(onSuccess);
545         } else {
546             let onSuccess = (newProperty: PropertyModel): PropertyModel => {
547                 // find exist instance property in parent component for update the new value ( find bu uniqueId )
548                 let existProperty: PropertyModel = <PropertyModel>_.find(this.filteredProperties, {uniqueId: newProperty.uniqueId});
549                 let propertyIndex = this.filteredProperties.indexOf(existProperty);
550                 this.filteredProperties[propertyIndex] = newProperty;
551                 return newProperty;
552             };
553             return this.topologyTemplateService.updateProperty(this.workspaceService.metadata.componentType, this.workspaceService.metadata.uniqueId, property).map(onSuccess);
554         }
555     };
556
557     public deleteProperty = (propertyId:string):Observable<void> => {
558         let onSuccess = ():void => {
559             console.debug("Property deleted");
560             delete _.remove(this.filteredProperties, {uniqueId: propertyId})[0];
561         };
562         let onFailed = ():void => {
563             console.debug("Failed to delete property");
564         };
565         return this.topologyTemplateService.deleteProperty(this.workspaceService.metadata.componentType, this.workspaceService.metadata.uniqueId, propertyId).map(onSuccess, onFailed);
566     };
567
568 }