Bug fix on tosca function impact changes
[sdc.git] / catalog-ui / src / app / ng2 / pages / properties-assignment / tosca-function / tosca-get-function / tosca-get-function.component.ts
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 import {Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges} from '@angular/core';
21 import {AttributeBEModel, ComponentMetadata, DataTypeModel, PropertyBEModel, PropertyModel, PropertyDeclareAPIModel, DerivedFEProperty} from 'app/models';
22 import {TopologyTemplateService} from "../../../../services/component-services/topology-template.service";
23 import {WorkspaceService} from "../../../workspace/workspace.service";
24 import {PropertiesService} from "../../../../services/properties.service";
25 import {PROPERTY_DATA, PROPERTY_TYPES} from "../../../../../utils/constants";
26 import {DataTypeService} from "../../../../services/data-type.service";
27 import {ToscaGetFunctionType} from "../../../../../models/tosca-get-function-type";
28 import {TranslateService} from "../../../../shared/translator/translate.service";
29 import {ComponentGenericResponse} from '../../../../services/responses/component-generic-response';
30 import {Observable} from 'rxjs/Observable';
31 import {PropertySource} from "../../../../../models/property-source";
32 import {InstanceFeDetails} from "../../../../../models/instance-fe-details";
33 import {ToscaGetFunction} from "../../../../../models/tosca-get-function";
34 import {FormControl, FormGroup, Validators} from "@angular/forms";
35 import {ToscaGetFunctionTypeConverter} from "../../../../../models/tosca-get-function-type-converter";
36
37 @Component({
38     selector: 'app-tosca-get-function',
39     templateUrl: './tosca-get-function.component.html',
40     styleUrls: ['./tosca-get-function.component.less']
41 })
42 export class ToscaGetFunctionComponent implements OnInit, OnChanges {
43
44     @Input() property: PropertyBEModel;
45     @Input() overridingType: PROPERTY_TYPES;
46     @Input() toscaGetFunction: ToscaGetFunction;
47     @Input() componentInstanceMap: Map<string, InstanceFeDetails> = new Map<string, InstanceFeDetails>();
48     @Input() functionType: ToscaGetFunctionType;
49     @Input() compositionMap: boolean;
50     @Input() compositionMapKey: string;
51     @Output() onValidFunction: EventEmitter<ToscaGetFunction> = new EventEmitter<ToscaGetFunction>();
52     @Output() onValidityChange: EventEmitter<ToscaGetFunctionValidationEvent> = new EventEmitter<ToscaGetFunctionValidationEvent>();
53
54     formGroup: FormGroup = new FormGroup({
55         'selectedProperty': new FormControl(undefined, Validators.required),
56         'propertySource': new FormControl(undefined, Validators.required)
57     });
58
59     isLoading: boolean = false;
60     propertyDropdownList: Array<PropertyDropdownValue> = [];
61     propertySourceList: Array<string> = [];
62     instanceNameAndIdMap: Map<string, string> = new Map<string, string>();
63     dropdownValuesLabel: string;
64     dropDownErrorMsg: string;
65     indexListValues:Array<ToscaIndexObject>;
66     parentListTypeFlag : boolean;
67
68     private isInitialized: boolean = false;
69     private componentMetadata: ComponentMetadata;
70
71     constructor(private topologyTemplateService: TopologyTemplateService,
72                 private workspaceService: WorkspaceService,
73                 private propertiesService: PropertiesService,
74                 private dataTypeService: DataTypeService,
75                 private translateService: TranslateService) {
76     }
77
78     ngOnInit(): void {
79         this.componentMetadata = this.workspaceService.metadata;
80         this.indexListValues = [];
81         if (this.property != null) {
82             this.parentListTypeFlag = (this.property.type != PROPERTY_TYPES.LIST && (!this.isComplexType(this.property.type) || (this.isComplexType(this.property.type) 
83                                     && this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel> this.property).input instanceof DerivedFEProperty && this.property.input.type != PROPERTY_TYPES.LIST)));
84         }
85         this.formGroup.valueChanges.subscribe(() => {
86             this.formValidation();
87         });
88         this.loadPropertySourceDropdown();
89         this.loadPropertyDropdownLabel();
90         this.initToscaGetFunction().subscribe(() => {
91             this.isInitialized = true;
92         });
93     }
94
95     ngOnChanges(_changes: SimpleChanges): void {
96         if (!this.isInitialized) {
97             return;
98         }
99         this.isInitialized = false;
100         this.resetForm();
101         this.loadPropertySourceDropdown();
102         this.loadPropertyDropdownLabel();
103         this.initToscaGetFunction().subscribe(() => {
104             this.isInitialized = true;
105         });
106     }
107
108     private initToscaGetFunction(): Observable<void> {
109         return new Observable(subscriber => {
110             if (!this.toscaGetFunction) {
111                 if (this.isGetInput()) {
112                     this.setSelfPropertySource();
113                     this.loadPropertyDropdown();
114                 }
115                 subscriber.next();
116                 return;
117             }
118             if (this.toscaGetFunction.propertySource == PropertySource.SELF) {
119                 this.propertySource.setValue(PropertySource.SELF);
120             } else if (this.toscaGetFunction.propertySource == PropertySource.INSTANCE) {
121                 this.propertySource
122                 .setValue(this.propertySourceList.find(source => this.toscaGetFunction.sourceName === source));
123             }
124             if (this.propertySource.valid) {
125                 this.loadPropertyDropdown(() => {
126                     this.selectedProperty
127                     .setValue(this.propertyDropdownList.find(property => property.propertyName === this.toscaGetFunction.propertyName));
128                     if (this.toscaGetFunction.toscaIndexList.length > 0) {
129                         let tempSelectedProperty : PropertyDropdownValue = this.selectedProperty.value;
130                         this.toscaGetFunction.toscaIndexList.forEach((indexValue: string, index) => {
131                             let tempIndexFlag = false;
132                             let tempNestedFlag = false;
133                             let tempIndexValue = "0";
134                             let tempIndexProperty = tempSelectedProperty;
135                             let subPropertyDropdownList : Array<PropertyDropdownValue> = [];
136                             if (index%2 == 0) {
137                                 tempIndexFlag = true;
138                                 tempIndexValue = indexValue;
139                                 tempSelectedProperty = null;
140                                 if (this.toscaGetFunction.toscaIndexList[index+1]) {
141                                     tempNestedFlag = true;
142                                     if (tempIndexProperty.schemaType != null) {
143                                         const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, tempIndexProperty.schemaType);
144                                         this.addPropertiesToDropdown(dataTypeFound.properties, subPropertyDropdownList);
145                                         tempSelectedProperty = subPropertyDropdownList.find(property => property.propertyName === this.toscaGetFunction.toscaIndexList[index+1])
146                                     }
147                                 }
148                                 let tempIndexValueMap : ToscaIndexObject = {indexFlag : tempIndexFlag, nestedFlag : tempNestedFlag, indexValue: tempIndexValue, indexProperty: tempSelectedProperty, subPropertyArray: subPropertyDropdownList};
149                                 this.indexListValues.push(tempIndexValueMap);
150                             }
151                         });
152                     }
153                     subscriber.next();
154                 });
155             } else {
156                 subscriber.next();
157             }
158         });
159     }
160
161     private buildGetFunctionFromForm() {
162         const toscaGetFunction = new ToscaGetFunction();
163         toscaGetFunction.type = ToscaGetFunctionTypeConverter.convertToToscaFunctionType(this.functionType);
164         toscaGetFunction.functionType = this.functionType;
165         const propertySource = this.propertySource.value;
166         if (this.isPropertySourceSelf()) {
167             toscaGetFunction.propertySource = propertySource
168             toscaGetFunction.sourceName = this.componentMetadata.name;
169             toscaGetFunction.sourceUniqueId = this.componentMetadata.uniqueId;
170         } else {
171             toscaGetFunction.propertySource = PropertySource.INSTANCE;
172             toscaGetFunction.sourceName = propertySource;
173             toscaGetFunction.sourceUniqueId = this.instanceNameAndIdMap.get(propertySource);
174         }
175
176         const selectedProperty: PropertyDropdownValue = this.selectedProperty.value;
177         toscaGetFunction.propertyUniqueId = selectedProperty.propertyId;
178         toscaGetFunction.propertyName = selectedProperty.propertyName;
179         toscaGetFunction.propertyPathFromSource = selectedProperty.propertyPath;
180         if (this.indexListValues.length > 0) {
181             let indexAndProperty : Array<string> = [];
182             this.indexListValues.forEach((indexObject : ToscaIndexObject) => {
183                 indexAndProperty.push(indexObject.indexValue);
184                 if(indexObject.nestedFlag && indexObject.indexProperty != null) {
185                     indexAndProperty.push(indexObject.indexProperty.propertyName);
186                 }
187             });
188             toscaGetFunction.toscaIndexList = indexAndProperty;
189         }
190         return toscaGetFunction;
191     }
192
193     private loadPropertySourceDropdown(): void {
194         if (this.isGetInput()) {
195             return;
196         }
197         this.propertySourceList = [];
198         this.propertySourceList.push(PropertySource.SELF);
199         this.componentInstanceMap.forEach((value, key) => {
200             const instanceName = value.name;
201             this.instanceNameAndIdMap.set(instanceName, key);
202             if (instanceName !== PropertySource.SELF) {
203                 this.addToPropertySource(instanceName);
204             }
205         });
206     }
207
208     private addToPropertySource(source: string): void {
209         this.propertySourceList.push(source);
210         this.propertySourceList.sort((a, b) => {
211             if (a === PropertySource.SELF) {
212                 return -1;
213             } else if (b === PropertySource.SELF) {
214                 return 1;
215             }
216
217             return a.localeCompare(b);
218         });
219     }
220
221     private formValidation(): void {
222         if (!this.isInitialized) {
223             return;
224         }
225         let formGroupStatus : boolean = this.formGroup.valid;
226         const selectedProperty: PropertyDropdownValue = this.formGroup.value.selectedProperty;
227         if (selectedProperty != null && selectedProperty.isList && formGroupStatus && this.indexListValues.length > 0) {
228             this.indexListValues.forEach((indexObject : ToscaIndexObject, index) => {
229                 if (indexObject.indexValue == null) {
230                     formGroupStatus = false;
231                     return;
232                 }
233                 if (indexObject.nestedFlag && indexObject.indexProperty == null) {
234                     formGroupStatus = false;
235                     return;
236                 }
237             });
238         }
239         this.onValidityChange.emit({
240             isValid: formGroupStatus,
241             toscaGetFunction: this.formGroup.valid ? this.buildGetFunctionFromForm() : undefined
242         });
243         if (this.formGroup.valid) {
244             this.onValidFunction.emit(this.buildGetFunctionFromForm());
245         }
246     }
247
248     private loadPropertyDropdown(onComplete?: () => any): void  {
249         this.loadPropertyDropdownLabel();
250         this.loadPropertyDropdownValues(onComplete);
251     }
252
253     private resetForm(): void {
254         this.formGroup.reset();
255     }
256
257     private loadPropertyDropdownLabel(): void {
258         if (!this.functionType) {
259             return;
260         }
261         if (this.isGetInput()) {
262             this.dropdownValuesLabel = this.translateService.translate('INPUT_DROPDOWN_LABEL');
263         } else if (this.isGetProperty()) {
264             this.dropdownValuesLabel = this.translateService.translate('TOSCA_FUNCTION_PROPERTY_DROPDOWN_LABEL');
265         } else if (this.isGetAttribute()) {
266             this.dropdownValuesLabel = this.translateService.translate('TOSCA_FUNCTION_ATTRIBUTE_DROPDOWN_LABEL');
267         }
268     }
269
270     private loadPropertyDropdownValues(onComplete?: () => any): void {
271         if (!this.functionType) {
272             return;
273         }
274         this.resetPropertyDropdown();
275         this.fillPropertyDropdownValues(onComplete);
276     }
277
278     private resetPropertyDropdown(): void {
279         this.dropDownErrorMsg = undefined;
280         this.selectedProperty.reset();
281         this.indexListValues = [];
282         this.propertyDropdownList = [];
283     }
284
285     private fillPropertyDropdownValues(onComplete?: () => any): void {
286         this.startLoading();
287         const propertiesObservable: Observable<ComponentGenericResponse> = this.getPropertyObservable();
288         propertiesObservable.subscribe( (response: ComponentGenericResponse) => {
289             const properties: Array<PropertyBEModel | AttributeBEModel> = this.extractProperties(response);
290             if (!properties || properties.length === 0) {
291                 const msgCode = this.getNotFoundMsgCode();
292                 this.dropDownErrorMsg = this.translateService.translate(msgCode, {type: this.overridingType != undefined ? this.overridingType : this.propertyTypeToString()});
293                 return;
294             }
295             this.addPropertiesToDropdown(properties, this.propertyDropdownList);
296             if (this.propertyDropdownList.length == 0) {
297                 const msgCode = this.getNotFoundMsgCode();
298                 this.dropDownErrorMsg = this.translateService.translate(msgCode, {type: this.overridingType != undefined ? this.overridingType : this.propertyTypeToString()});
299             }
300         }, (error) => {
301             console.error('An error occurred while loading properties.', error);
302             this.stopLoading();
303         }, () => {
304             if (onComplete) {
305                 onComplete();
306             }
307             this.stopLoading();
308         });
309     }
310
311     private getNotFoundMsgCode(): string {
312         if (this.isGetInput()) {
313             return 'TOSCA_FUNCTION_NO_INPUT_FOUND';
314         }
315         if (this.isGetAttribute()) {
316             return 'TOSCA_FUNCTION_NO_ATTRIBUTE_FOUND';
317         }
318         if (this.isGetProperty()) {
319             return 'TOSCA_FUNCTION_NO_PROPERTY_FOUND';
320         }
321
322         return undefined;
323     }
324
325     private propertyTypeToString() {
326             if (this.isSubProperty()){
327             if ((this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel> this.property).input instanceof DerivedFEProperty)
328                 || this.compositionMap) {
329                 if(this.isComplexType(this.property.schemaType) && !this.compositionMap){
330                     let mapChildProp : DerivedFEProperty = (<DerivedFEProperty> (<PropertyDeclareAPIModel> this.property).input);
331                     let propertySchemaType = mapChildProp.type;
332                     if (this.property.type == PROPERTY_TYPES.MAP || propertySchemaType == PROPERTY_TYPES.MAP) {
333                         if (mapChildProp.mapKey != '' && mapChildProp.mapKey != null && mapChildProp.schema.property.type != null) {
334                             propertySchemaType = mapChildProp.schema.property.type;
335                         }
336                     }
337                     if ((propertySchemaType == PROPERTY_TYPES.MAP || (propertySchemaType == PROPERTY_TYPES.LIST && mapChildProp.schema.property.type == PROPERTY_TYPES.MAP))
338                         && mapChildProp.isChildOfListOrMap) {
339                         propertySchemaType = PROPERTY_TYPES.STRING;
340                     }
341                     return  propertySchemaType;
342                 }else{
343                     return this.property.schema.property.type;
344                 }
345             }
346                 return this.getType((<PropertyDeclareAPIModel>this.property).propertiesName.split("#").slice(1),  this.property.type);
347         }
348         if (this.property.schemaType) {
349             return `${this.property.type} of ${this.property.schemaType}`;
350         }
351         return this.property.type;
352     }
353
354     private isSubProperty(): boolean{
355             return this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel>this.property).propertiesName && (<PropertyDeclareAPIModel>this.property).propertiesName.length > 1;
356     }
357
358     private extractProperties(componentGenericResponse: ComponentGenericResponse): Array<PropertyBEModel | AttributeBEModel> {
359         if (this.isGetInput()) {
360             return componentGenericResponse.inputs;
361         }
362         const instanceId = this.instanceNameAndIdMap.get(this.propertySource.value);
363         if (this.isGetProperty()) {
364             if (this.isPropertySourceSelf()) {
365                 return componentGenericResponse.properties;
366             }
367             return this.removeSelectedProperty(componentGenericResponse.componentInstancesProperties[instanceId]);
368         }
369         if (this.isPropertySourceSelf()) {
370             return [...(componentGenericResponse.attributes || []), ...(componentGenericResponse.properties || [])];
371         }
372         return [...(componentGenericResponse.componentInstancesAttributes[instanceId] || []),
373             ...(componentGenericResponse.componentInstancesProperties[instanceId] || [])];
374     }
375
376     private isPropertySourceSelf() {
377         return this.propertySource.value === PropertySource.SELF;
378     }
379
380     private getPropertyObservable(): Observable<ComponentGenericResponse> {
381         if (this.isGetInput()) {
382             return this.topologyTemplateService.getComponentInputsValues(this.componentMetadata.componentType, this.componentMetadata.uniqueId);
383         }
384         if (this.isGetProperty()) {
385             if (this.isPropertySourceSelf()) {
386                 return this.topologyTemplateService.findAllComponentProperties(this.componentMetadata.componentType, this.componentMetadata.uniqueId);
387             }
388             return this.topologyTemplateService.getComponentInstanceProperties(this.componentMetadata.componentType, this.componentMetadata.uniqueId);
389         }
390         if (this.isGetAttribute()) {
391             if (this.isPropertySourceSelf()) {
392                 return this.topologyTemplateService.findAllComponentAttributesAndProperties(this.componentMetadata.componentType, this.componentMetadata.uniqueId);
393             }
394             return this.topologyTemplateService.getComponentInstanceAttributesAndProperties(this.componentMetadata.uniqueId, this.componentMetadata.componentType);
395         }
396     }
397
398     private removeSelectedProperty(componentInstanceProperties: PropertyModel[]): PropertyModel[] {
399         if (!componentInstanceProperties) {
400             return [];
401         }
402         return componentInstanceProperties.filter(property =>
403             (property.uniqueId !== this.property.uniqueId) ||
404             (property.uniqueId === this.property.uniqueId && property.resourceInstanceUniqueId !== this.property.parentUniqueId)
405         );
406     }
407
408     private addPropertyToDropdown(propertyDropdownValue: PropertyDropdownValue, propertyList: Array<PropertyDropdownValue>): void {
409         propertyList.push(propertyDropdownValue);
410         propertyList.sort((a, b) => a.propertyLabel.localeCompare(b.propertyLabel));
411     }
412
413     private addPropertiesToDropdown(properties: Array<PropertyBEModel | AttributeBEModel>, propertyList: Array<PropertyDropdownValue>): void {
414         for (const property of properties) {
415             if (this.hasSameType(property)) {
416                 this.addPropertyToDropdown({
417                     propertyName: property.name,
418                     propertyId: property.uniqueId,
419                     propertyLabel: property.name,
420                     propertyPath: [property.name],
421                     isList: property.type === PROPERTY_TYPES.LIST,
422                     schemaType: (property.type === PROPERTY_TYPES.LIST && this.isComplexType(property.schema.property.type)) ? property.schema.property.type : null
423                 },propertyList);
424             } else if (this.isComplexType(property.type)) {
425                 this.fillPropertyDropdownWithMatchingChildProperties(property,propertyList);
426             }
427         }
428     }
429
430     private fillPropertyDropdownWithMatchingChildProperties(inputProperty: PropertyBEModel | AttributeBEModel, propertyList: Array<PropertyDropdownValue>,
431                                                             parentPropertyList: Array<PropertyBEModel | AttributeBEModel> = []): void {
432         const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, inputProperty.type);
433         if (!dataTypeFound || !dataTypeFound.properties) {
434             return;
435         }
436         parentPropertyList.push(inputProperty);
437         dataTypeFound.properties.forEach(dataTypeProperty => {
438             if (this.hasSameType(dataTypeProperty)) {
439                 this.addPropertyToDropdown({
440                     propertyName: dataTypeProperty.name,
441                     propertyId: parentPropertyList[0].uniqueId,
442                     propertyLabel: parentPropertyList.map(property => property.name).join('->') + '->' + dataTypeProperty.name,
443                     propertyPath: [...parentPropertyList.map(property => property.name), dataTypeProperty.name],
444                     isList : dataTypeProperty.type === PROPERTY_TYPES.LIST,
445                     schemaType: (dataTypeProperty.type === PROPERTY_TYPES.LIST && this.isComplexType(dataTypeProperty.schema.property.type)) ? dataTypeProperty.schema.property.type : null
446                 }, propertyList);
447             } else if (this.isComplexType(dataTypeProperty.type)) {
448                 this.fillPropertyDropdownWithMatchingChildProperties(dataTypeProperty, propertyList, [...parentPropertyList])
449             }
450         });
451     }
452
453     private hasSameType(property: PropertyBEModel | AttributeBEModel): boolean {
454         if (this.overridingType != undefined) {
455             return property.type === this.overridingType;
456         }
457         if (this.property.type === PROPERTY_TYPES.ANY) {
458             return true;
459         }
460         let validPropertyType = (this.parentListTypeFlag && property.type === PROPERTY_TYPES.LIST) ? property.schema.property.type : property.type;
461         if (this.parentListTypeFlag && property.type === PROPERTY_TYPES.LIST && this.isComplexType(validPropertyType)) {
462             let returnFlag : boolean = false;
463             const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, validPropertyType);
464             if (dataTypeFound && dataTypeFound.properties) {
465                 dataTypeFound.properties.forEach(dataTypeProperty => {
466                     if (this.hasSameType(dataTypeProperty)) {
467                         returnFlag =  true;
468                     }
469                 });
470             }
471             return returnFlag;
472         }
473         if (this.typeHasSchema(this.property.type)) {
474             if ((this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel> this.property).input instanceof DerivedFEProperty) || this.compositionMap) {
475                 let childObject : DerivedFEProperty = (<DerivedFEProperty>(<PropertyDeclareAPIModel> this.property).input);
476                 let childSchemaType = this.property.schemaType != null ? this.property.schemaType : childObject.type;
477                 if(this.isComplexType(childSchemaType) && !this.compositionMap){
478                     if (childObject.type == PROPERTY_TYPES.MAP && childObject.isChildOfListOrMap) {
479                         return validPropertyType === PROPERTY_TYPES.STRING;
480                     }
481                     return validPropertyType === childObject.type;
482                 }else{
483                     return validPropertyType === this.property.schema.property.type;
484                 }
485             }
486             if (!property.schema || !property.schema.property) {
487                 return false;
488             }
489             return validPropertyType === this.property.type && this.property.schema.property.type === property.schema.property.type;
490         }
491         if (this.property.schema.property.isDataType && this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel>this.property).propertiesName){
492             let typeToMatch = (<PropertyDeclareAPIModel> this.property).input.type;
493             let childObject : DerivedFEProperty = (<DerivedFEProperty>(<PropertyDeclareAPIModel> this.property).input);
494             if (childObject.type == PROPERTY_TYPES.MAP && childObject.isChildOfListOrMap) {
495                 typeToMatch = PROPERTY_TYPES.STRING;
496             }
497             return validPropertyType === typeToMatch;
498         }
499
500         return validPropertyType === this.property.type;
501     }
502
503     private getType(propertyPath:string[], type: string): string {
504             const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, type);
505         let nestedProperty = dataTypeFound.properties.find(property => property.name === propertyPath[0]);
506         if (propertyPath.length === 1){
507                 return nestedProperty.type;
508         } 
509         return this.getType(propertyPath.slice(1), nestedProperty.type);
510     }
511
512     private isGetProperty(): boolean {
513         return this.functionType === ToscaGetFunctionType.GET_PROPERTY;
514     }
515
516     private isGetAttribute(): boolean {
517         return this.functionType === ToscaGetFunctionType.GET_ATTRIBUTE;
518     }
519
520     private isGetInput(): boolean {
521         return this.functionType === ToscaGetFunctionType.GET_INPUT;
522     }
523
524     private isComplexType(propertyType: string): boolean {
525         return PROPERTY_DATA.SIMPLE_TYPES.indexOf(propertyType) === -1;
526     }
527
528     private typeHasSchema(propertyType: string): boolean {
529         return PROPERTY_TYPES.MAP === propertyType || PROPERTY_TYPES.LIST === propertyType;
530     }
531
532     private stopLoading(): void {
533         this.isLoading = false;
534     }
535
536     private startLoading(): void {
537         this.isLoading = true;
538     }
539
540     showPropertyDropdown(): boolean {
541         if (this.isGetProperty() || this.isGetAttribute()) {
542             return this.propertySource.valid && !this.isLoading && !this.dropDownErrorMsg;
543         }
544
545         return this.functionType && !this.isLoading && !this.dropDownErrorMsg;
546     }
547
548     onPropertySourceChange(): void {
549         this.selectedProperty.reset();
550         this.indexListValues = [];
551         if (!this.functionType || !this.propertySource.valid) {
552             return;
553         }
554         this.loadPropertyDropdown();
555     }
556
557     onPropertyValueChange(): void {
558         let toscaIndexFlag = false;
559         let nestedToscaFlag = false;
560         this.indexListValues = [];
561         let subPropertyDropdownList : Array<PropertyDropdownValue> = [];
562         const selectedProperty: PropertyDropdownValue = this.selectedProperty.value;
563         if (this.parentListTypeFlag && selectedProperty.isList) {
564             toscaIndexFlag = true;
565             if (selectedProperty.schemaType != null) {
566                 nestedToscaFlag = true;
567                 const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, selectedProperty.schemaType);
568                 this.addPropertiesToDropdown(dataTypeFound.properties, subPropertyDropdownList);
569             }
570         }
571         if (toscaIndexFlag || nestedToscaFlag) {
572             let indexValueMap : ToscaIndexObject = {indexFlag : toscaIndexFlag, nestedFlag : nestedToscaFlag, indexValue: "0", indexProperty: null, subPropertyArray: subPropertyDropdownList};
573             this.indexListValues.push(indexValueMap);
574         }
575         this.formValidation();
576     }
577
578     onSubPropertyValueChange(indexObject : ToscaIndexObject, elementIndex: number): void {
579         let toscaIndexFlag = false;
580         let nestedToscaFlag = false;
581         let subPropertyDropdownList : Array<PropertyDropdownValue> = [];
582         let selectedProperty: PropertyDropdownValue = indexObject.indexProperty;
583         if (selectedProperty.isList) {
584             toscaIndexFlag = true;
585             if (selectedProperty.schemaType != null) {
586                 nestedToscaFlag = true;
587                 const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, selectedProperty.schemaType);
588                 this.addPropertiesToDropdown(dataTypeFound.properties, subPropertyDropdownList);
589             }
590         }
591         if (toscaIndexFlag || nestedToscaFlag) {
592             let indexValueMap : ToscaIndexObject = {indexFlag : toscaIndexFlag, nestedFlag : nestedToscaFlag, indexValue: "0", indexProperty: null, subPropertyArray: subPropertyDropdownList};
593             if(!this.indexListValues[elementIndex+1]) {
594                 this.indexListValues.push(indexValueMap);
595             } else {
596                 this.indexListValues[elementIndex+1] = indexValueMap;
597             }
598         } else {
599             if(this.indexListValues[elementIndex+1]) {
600                 this.indexListValues.splice((elementIndex+1),1);
601             }
602         }
603         this.formValidation();
604     }
605
606     indexTokenChange(indexObject : ToscaIndexObject): void {
607         if ((indexObject.indexValue).toLowerCase() === 'index') {
608             this.formValidation();
609             return;
610         }
611         let indexTokenValue = Number(indexObject.indexValue);
612         if (isNaN(indexTokenValue)) {
613             indexObject.indexValue = "0";
614             this.formValidation();
615             return;
616         }
617         this.formValidation();
618     }
619
620     showPropertySourceDropdown(): boolean {
621         return this.isGetProperty() || this.isGetAttribute();
622     }
623
624     private setSelfPropertySource(): void {
625         this.propertySource.setValue(PropertySource.SELF);
626     }
627
628     private get propertySource(): FormControl {
629         return this.formGroup.get('propertySource') as FormControl;
630     }
631
632     private get selectedProperty(): FormControl {
633         return this.formGroup.get('selectedProperty') as FormControl;
634     }
635
636 }
637
638 export interface PropertyDropdownValue {
639     propertyName: string;
640     propertyId: string;
641     propertyLabel: string;
642     propertyPath: Array<string>;
643     isList: boolean;
644     schemaType: string;
645 }
646
647 export interface ToscaIndexObject {
648     indexFlag: boolean;
649     nestedFlag: boolean;
650     indexValue: string;
651     indexProperty: PropertyDropdownValue;
652     subPropertyArray: Array<PropertyDropdownValue>;
653 }
654
655 export interface ToscaGetFunctionValidationEvent {
656     isValid: boolean,
657     toscaGetFunction: ToscaGetFunction,
658 }