Revert "Provide tosca function capability to complex type fields in composition view"
[sdc.git] / catalog-ui / src / app / ng2 / pages / properties-assignment / tosca-function / tosca-function.component.ts
index 4eefbcb..34ed9a6 100644 (file)
  *  ============LICENSE_END=========================================================
  */
 
-import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
-import {ComponentMetadata, DataTypeModel, PropertyBEModel, PropertyModel} from 'app/models';
+import {Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges} from '@angular/core';
+import {ComponentMetadata, PropertyBEModel, PropertyDeclareAPIModel, DerivedFEProperty} from 'app/models';
 import {TopologyTemplateService} from "../../../services/component-services/topology-template.service";
 import {WorkspaceService} from "../../workspace/workspace.service";
-import {PropertiesService} from "../../../services/properties.service";
-import {PROPERTY_DATA, PROPERTY_TYPES} from "../../../../utils/constants";
-import {DataTypeService} from "../../../services/data-type.service";
 import {ToscaGetFunctionType} from "../../../../models/tosca-get-function-type";
-import {TranslateService} from "../../../shared/translator/translate.service";
-import {ComponentGenericResponse} from '../../../services/responses/component-generic-response';
-import {Observable} from 'rxjs/Observable';
-import {PropertySource} from "../../../../models/property-source";
 import {InstanceFeDetails} from "../../../../models/instance-fe-details";
 import {ToscaGetFunction} from "../../../../models/tosca-get-function";
-import {AbstractControl, FormControl, FormGroup, ValidationErrors, ValidatorFn} from "@angular/forms";
+import {FormControl, FormGroup, Validators} from "@angular/forms";
+import {ToscaFunctionType} from "../../../../models/tosca-function-type.enum";
+import {ToscaGetFunctionValidationEvent} from "./tosca-get-function/tosca-get-function.component";
+import {ToscaFunction} from "../../../../models/tosca-function";
+import {ToscaConcatFunctionValidationEvent} from "./tosca-concat-function/tosca-concat-function.component";
+import {ToscaCustomFunctionValidationEvent} from "./tosca-custom-function/tosca-custom-function.component";
+import {PROPERTY_TYPES} from "../../../../utils/constants";
+import {YamlFunctionValidationEvent} from "./yaml-function/yaml-function.component";
+import {ToscaConcatFunction} from "../../../../models/tosca-concat-function";
+import {ToscaCustomFunction} from "../../../../models/tosca-custom-function";
+import {YamlFunction} from "../../../../models/yaml-function";
+import {CustomToscaFunction} from "../../../../models/default-custom-functions";
 
 @Component({
     selector: 'tosca-function',
     templateUrl: './tosca-function.component.html',
     styleUrls: ['./tosca-function.component.less'],
 })
-export class ToscaFunctionComponent implements OnInit {
+export class ToscaFunctionComponent implements OnInit, OnChanges {
 
     @Input() property: PropertyBEModel;
+    @Input() overridingType: PROPERTY_TYPES;
+    @Input() inToscaFunction: ToscaFunction;
     @Input() componentInstanceMap: Map<string, InstanceFeDetails> = new Map<string, InstanceFeDetails>();
+    @Input() customToscaFunctions: Array<CustomToscaFunction> = [];
     @Input() allowClear: boolean = true;
+    @Input() compositionMap: boolean = false;
+    @Input() compositionMapKey: string = "";
     @Output() onValidFunction: EventEmitter<ToscaGetFunction> = new EventEmitter<ToscaGetFunction>();
-    @Output() onValidityChange: EventEmitter<boolean> = new EventEmitter<boolean>();
+    @Output() onValidityChange: EventEmitter<ToscaFunctionValidationEvent> = new EventEmitter<ToscaFunctionValidationEvent>();
 
-    toscaGetFunctionValidator: ValidatorFn = (control: AbstractControl): ValidationErrors | null => {
-        const toscaGetFunction: ToscaGetFunction = control.value;
-        const hasAnyValue = Object.keys(toscaGetFunction).find(key => toscaGetFunction[key]);
-        if (!hasAnyValue) {
-            return null;
-        }
-        const errors: ValidationErrors = {};
-        if (!toscaGetFunction.sourceName) {
-            errors.sourceName = { required: true };
-        }
-        if (!toscaGetFunction.functionType) {
-            errors.functionType = { required: true };
-        }
-        if (!toscaGetFunction.sourceUniqueId) {
-            errors.sourceUniqueId = { required: true };
-        }
-        if (!toscaGetFunction.sourceName) {
-            errors.sourceName = { required: true };
-        }
-        if (!toscaGetFunction.propertyPathFromSource) {
-            errors.propertyPathFromSource = { required: true };
-        }
-        if (!toscaGetFunction.propertyName) {
-            errors.propertyName = { required: true };
-        }
-        if (!toscaGetFunction.propertySource) {
-            errors.propertySource = { required: true };
-        }
-        return errors ? errors : null;
-    };
-
-    toscaGetFunctionForm: FormControl = new FormControl(new ToscaGetFunction(undefined), [this.toscaGetFunctionValidator]);
+    toscaFunctionForm: FormControl = new FormControl(undefined, [Validators.required]);
+    toscaFunctionTypeForm: FormControl = new FormControl(undefined, Validators.required);
     formGroup: FormGroup = new FormGroup({
-        'toscaGetFunction': this.toscaGetFunctionForm
+        'toscaFunction': this.toscaFunctionForm,
+        'toscaFunctionType': this.toscaFunctionTypeForm,
     });
 
-    TOSCA_FUNCTION_GET_PROPERTY = ToscaGetFunctionType.GET_PROPERTY;
-
-    selectedProperty: PropertyDropdownValue;
     isLoading: boolean = false;
-    propertyDropdownList: Array<PropertyDropdownValue> = [];
+    toscaFunction: ToscaFunction;
     toscaFunctions: Array<string> = [];
-    propertySourceList: Array<string> = [];
-    instanceNameAndIdMap: Map<string, string> = new Map<string, string>();
-    dropdownValuesLabel: string;
-    dropDownErrorMsg: string;
-    propertySource: string
-    toscaGetFunction: ToscaGetFunction = new ToscaGetFunction(undefined);
+    toscaCustomFunctions: Array<String> = [];
 
+    private isInitialized: boolean = false;
     private componentMetadata: ComponentMetadata;
 
     constructor(private topologyTemplateService: TopologyTemplateService,
-                private workspaceService: WorkspaceService,
-                private propertiesService: PropertiesService,
-                private dataTypeService: DataTypeService,
-                private translateService: TranslateService) {
+                private workspaceService: WorkspaceService) {
     }
 
     ngOnInit(): void {
         this.componentMetadata = this.workspaceService.metadata;
+        this.toscaFunction = this.inToscaFunction ? this.inToscaFunction : this.property.toscaFunction ? this.property.toscaFunction : undefined;
         this.loadToscaFunctions();
-        this.loadPropertySourceDropdown();
-        this.initToscaGetFunction();
-    }
-
-    private initToscaGetFunction(): void {
-        this.toscaGetFunctionForm.valueChanges.subscribe(toscaGetFunction => {
-            this.onValidityChange.emit(this.toscaGetFunctionForm.valid);
-            if (this.toscaGetFunctionForm.valid) {
-                this.onValidFunction.emit(toscaGetFunction);
+        this.formGroup.valueChanges.subscribe(() => {
+            if (!this.isInitialized) {
+                return;
             }
-        });
-        if (!this.property.isToscaGetFunction()) {
-            return;
-        }
-        this.toscaGetFunction = new ToscaGetFunction(this.property.toscaGetFunction);
-        this.toscaGetFunctionForm.setValue(this.toscaGetFunction);
-        if (this.toscaGetFunction.functionType === ToscaGetFunctionType.GET_PROPERTY) {
-            if (this.toscaGetFunction.propertySource === PropertySource.SELF) {
-                this.propertySource = PropertySource.SELF;
-            } else {
-                this.propertySource = this.toscaGetFunction.sourceName;
+            this.emitValidityChange();
+            if (this.formGroup.valid) {
+                this.onValidFunction.emit(this.toscaFunctionForm.value);
             }
-        }
-        if (this.toscaGetFunction.propertyName) {
-            this.loadPropertyDropdown(() => {
-                this.selectedProperty = this.propertyDropdownList.find(property => property.propertyName === this.toscaGetFunction.propertyName)
-            });
+        });
+        this.initToscaFunction();
+        this.emitValidityChange();
+        this.isInitialized = true;
+    }
+
+    ngOnChanges(changes: SimpleChanges): void {
+        if (changes.property) {
+            this.resetForm();
+            this.toscaFunction = this.inToscaFunction ? this.inToscaFunction : this.property.toscaFunction ? this.property.toscaFunction : undefined;
+            this.initToscaFunction();
+            this.loadToscaFunctions();
+            this.emitValidityChange();
         }
     }
 
-    private loadToscaFunctions(): void {
-        this.toscaFunctions.push(ToscaGetFunctionType.GET_INPUT);
-        this.toscaFunctions.push(ToscaGetFunctionType.GET_PROPERTY);
+    private validate(): boolean {
+        return (!this.toscaFunctionForm.value && !this.toscaFunctionTypeForm.value) || this.formGroup.valid;
     }
 
-    private loadPropertySourceDropdown(): void {
-        this.propertySourceList.push(PropertySource.SELF);
-        this.componentInstanceMap.forEach((value, key) => {
-            const instanceName = value.name;
-            this.instanceNameAndIdMap.set(instanceName, key);
-            if (instanceName !== PropertySource.SELF) {
-                this.addToPropertySource(instanceName);
-            }
-        });
-    }
+    private initToscaFunction(): void {
+        if (this.compositionMap && this.property.subPropertyToscaFunctions) {
+            let keyToFind = [this.compositionMapKey];
+            let subPropertyToscaFunction = this.property.subPropertyToscaFunctions.find(subPropertyToscaFunction => this.areEqual(subPropertyToscaFunction.subPropertyPath, keyToFind));
 
-    private addToPropertySource(source: string): void {
-        this.propertySourceList.push(source);
-        this.propertySourceList.sort((a, b) => {
-            if (a === PropertySource.SELF) {
-                return -1;
-            } else if (b === PropertySource.SELF) {
-                return 1;
+                if (subPropertyToscaFunction){
+                       this.toscaFunction = subPropertyToscaFunction.toscaFunction;
+                    this.toscaFunctionForm.setValue(this.toscaFunction);
+                    this.toscaFunctionTypeForm.setValue(this.toscaFunction.type);
+                }
+                return;
+        }
+           if (this.property instanceof PropertyDeclareAPIModel && this.property.subPropertyToscaFunctions && (<PropertyDeclareAPIModel> this.property).propertiesName){
+               let propertiesPath = (<PropertyDeclareAPIModel> this.property).propertiesName.split("#");
+            if (propertiesPath.length > 1){
+                let keyToFind = (<DerivedFEProperty>this.property.input).toscaPath;
+                let subPropertyToscaFunction = this.property.subPropertyToscaFunctions.find(subPropertyToscaFunction => this.areEqual(subPropertyToscaFunction.subPropertyPath, keyToFind.length > 0 ? keyToFind : propertiesPath.slice(1)));
+
+                if (subPropertyToscaFunction){
+                       this.toscaFunction = subPropertyToscaFunction.toscaFunction;
+                    this.toscaFunctionForm.setValue(this.toscaFunction);
+                    this.toscaFunctionTypeForm.setValue(this.toscaFunction.type);
+                }
+                return;
             }
-
-            return a.localeCompare(b);
-        });
-    }
-
-    onToscaFunctionChange(): void {
-        this.resetPropertySource();
-        this.resetPropertyDropdown();
-        if (this.isGetInputSelected()) {
-            this.setSelfPropertySource();
-            this.loadPropertyDropdown();
         }
-    }
+        if (!this.property.isToscaFunction()) {
+            return;
+        }
 
-    private loadPropertyDropdown(onComplete?: () => any): void  {
-        this.loadPropertyDropdownLabel();
-        this.loadPropertyDropdownValues(onComplete);
+        this.toscaFunctionForm.setValue(this.inToscaFunction ? this.inToscaFunction : this.property.toscaFunction);
+        let type = this.property.toscaFunction.type;
+        if (type == ToscaFunctionType.CUSTOM) {
+            let name = (this.property.toscaFunction as ToscaCustomFunction).name;
+            let customToscaFunc = this.customToscaFunctions.find(custToscFunc => _.isEqual(custToscFunc.name, name))
+            if (customToscaFunc) {
+                this.toscaFunctionTypeForm.setValue(name);
+            } else {
+                this.toscaFunctionTypeForm.setValue("other");
+            }
+        } else {
+            this.toscaFunctionTypeForm.setValue(this.inToscaFunction ? this.inToscaFunction.type : type);
+        }
     }
 
-    private resetForm(): void {
-        this.toscaGetFunction = new ToscaGetFunction();
-        this.toscaGetFunctionForm.setValue(new ToscaGetFunction());
-        this.propertySource = undefined;
-        this.selectedProperty = undefined;
+    private areEqual(array1: string[], array2: string[]): boolean {
+           return array1.length === array2.length && array1.every(function(value, index) { return value === array2[index]})
     }
 
-    private resetPropertySource(): void {
-        this.toscaGetFunction.propertyUniqueId = undefined;
-        this.toscaGetFunction.propertyName = undefined;
-        this.toscaGetFunction.propertySource = undefined;
-        this.toscaGetFunction.sourceUniqueId = undefined;
-        this.toscaGetFunction.sourceName = undefined;
-        this.toscaGetFunction.propertyPathFromSource = undefined;
-        this.propertySource = undefined;
-        this.selectedProperty = undefined;
-
-        const toscaGetFunction1 = new ToscaGetFunction(undefined);
-        toscaGetFunction1.functionType = this.toscaGetFunction.functionType;
-        this.toscaGetFunctionForm.setValue(toscaGetFunction1);
+    private loadToscaFunctions(): void {
+        this.toscaFunctions = [];
+        this.toscaFunctions.push(ToscaFunctionType.GET_ATTRIBUTE);
+        this.toscaFunctions.push(ToscaFunctionType.GET_INPUT);
+        this.toscaFunctions.push(ToscaFunctionType.GET_PROPERTY);
+        if ((this.property.type === PROPERTY_TYPES.STRING || this.property.type === PROPERTY_TYPES.ANY) && this.overridingType === undefined) {
+            this.toscaFunctions.push(ToscaFunctionType.CONCAT);
+        }
+        this.loadCustomToscaFunctions();
     }
 
-    private loadPropertyDropdownLabel(): void {
-        if (!this.toscaGetFunction.functionType) {
-            return;
+    private loadCustomToscaFunctions(): void {
+        if (!this.customToscaFunctions.find(custToscFunc => _.isEqual(custToscFunc.name, "other"))) {
+            let other = new CustomToscaFunction();
+            other.name = "other";
+            other.type = ToscaFunctionType.CUSTOM;
+            this.customToscaFunctions.push(other);
         }
-        if (this.isGetInputSelected()) {
-            this.dropdownValuesLabel = this.translateService.translate('INPUT_DROPDOWN_LABEL');
-        } else if (this.isGetPropertySelected()) {
-            this.dropdownValuesLabel = this.translateService.translate('TOSCA_FUNCTION_PROPERTY_DROPDOWN_LABEL');
+        this.toscaCustomFunctions = [];
+        for (let func of this.customToscaFunctions) {
+            this.toscaCustomFunctions.push(func.name);
         }
     }
 
-    private loadPropertyDropdownValues(onComplete?: () => any): void {
-        if (!this.toscaGetFunction.functionType) {
-            return;
-        }
-        this.resetPropertyDropdown();
-        this.fillPropertyDropdownValues(onComplete);
+    getCustomToscaFunction(): CustomToscaFunction {
+        let funcName = this.formGroup.get('toscaFunctionType').value;
+        return this.customToscaFunctions.find(custToscFunc => _.isEqual(custToscFunc.name, funcName));
     }
 
-    private resetPropertyDropdown(): void {
-        this.dropDownErrorMsg = undefined;
-        this.selectedProperty = undefined;
-        this.propertyDropdownList = [];
+    getCustomFunctionName():string {
+        let toscaFunctionType: CustomToscaFunction = this.getCustomToscaFunction();
+        let name = toscaFunctionType.name;
+        return name == 'other' ? '' : name;
     }
 
-    private fillPropertyDropdownValues(onComplete?: () => any): void {
-        this.startLoading();
-        const propertiesObservable: Observable<ComponentGenericResponse> = this.getPropertyObservable();
-        propertiesObservable.subscribe( (response: ComponentGenericResponse) => {
-            const properties: PropertyBEModel[] = this.extractProperties(response);
-            if (!properties || properties.length === 0) {
-                const msgCode = this.isGetInputSelected() ? 'TOSCA_FUNCTION_NO_INPUT_FOUND' : 'TOSCA_FUNCTION_NO_PROPERTY_FOUND';
-                this.dropDownErrorMsg = this.translateService.translate(msgCode, {type: this.propertyTypeToString()});
-                return;
-            }
-            this.addPropertiesToDropdown(properties);
-            if (this.propertyDropdownList.length == 0) {
-                const msgCode = this.isGetInputSelected() ? 'TOSCA_FUNCTION_NO_INPUT_FOUND' : 'TOSCA_FUNCTION_NO_PROPERTY_FOUND';
-                this.dropDownErrorMsg = this.translateService.translate(msgCode, {type: this.propertyTypeToString()});
-            }
-        }, (error) => {
-            console.error('An error occurred while loading properties.', error);
-        }, () => {
-            if (onComplete) {
-                onComplete();
-            }
-            this.stopLoading();
-        });
+    getCustomFunctionType():string {
+        let toscaFunctionType: CustomToscaFunction = this.getCustomToscaFunction();
+        return toscaFunctionType.type;
     }
 
-    private propertyTypeToString() {
-        if (this.property.schemaType) {
-            return `${this.property.type} of ${this.property.schemaType}`;
+    isDefaultCustomFunction(): boolean {
+        let toscaFunctionType: CustomToscaFunction = this.getCustomToscaFunction();
+        if (toscaFunctionType.name === "other") {
+            return false;
         }
-        return this.property.type;
+        return this.customToscaFunctions.filter(e => e.name === toscaFunctionType.name).length > 0;
     }
 
-    private extractProperties(componentGenericResponse: ComponentGenericResponse): PropertyBEModel[] {
-        if (this.isGetInputSelected()) {
-            return componentGenericResponse.inputs;
-        }
-        if (this.isGetPropertySelected()) {
-            if (this.propertySource === PropertySource.SELF) {
-                return componentGenericResponse.properties;
-            }
-            const componentInstanceProperties: PropertyModel[] = componentGenericResponse.componentInstancesProperties[this.instanceNameAndIdMap.get(this.propertySource)];
-            return this.removeSelectedProperty(componentInstanceProperties);
-        }
+    private resetForm(): void {
+        this.formGroup.reset();
+        this.toscaFunction = undefined;
     }
 
-    private getPropertyObservable(): Observable<ComponentGenericResponse> {
-        if (this.isGetInputSelected()) {
-            return this.topologyTemplateService.getComponentInputsValues(this.componentMetadata.componentType, this.componentMetadata.uniqueId);
-        }
-        if (this.isGetPropertySelected()) {
-            if (this.propertySource === PropertySource.SELF) {
-                return this.topologyTemplateService.findAllComponentProperties(this.componentMetadata.componentType, this.componentMetadata.uniqueId);
-            }
-            return this.topologyTemplateService.getComponentInstanceProperties(this.componentMetadata.componentType, this.componentMetadata.uniqueId);
-        }
+    private isGetPropertySelected(): boolean {
+        return this.formGroup.get('toscaFunctionType').value === ToscaGetFunctionType.GET_PROPERTY;
     }
 
-    private removeSelectedProperty(componentInstanceProperties: PropertyModel[]): PropertyModel[] {
-        if (!componentInstanceProperties) {
-            return [];
-        }
-        return componentInstanceProperties.filter(property =>
-            (property.uniqueId !== this.property.uniqueId) ||
-            (property.uniqueId === this.property.uniqueId && property.resourceInstanceUniqueId !== this.property.parentUniqueId)
-        );
+    private isGetAttributeSelected(): boolean {
+        return this.formGroup.get('toscaFunctionType').value === ToscaGetFunctionType.GET_ATTRIBUTE;
     }
 
-    private addPropertyToDropdown(propertyDropdownValue: PropertyDropdownValue): void {
-        this.propertyDropdownList.push(propertyDropdownValue);
-        this.propertyDropdownList.sort((a, b) => a.propertyLabel.localeCompare(b.propertyLabel));
+    private isGetInputSelected(): boolean {
+        return this.formGroup.get('toscaFunctionType').value === ToscaGetFunctionType.GET_INPUT;
     }
 
-    private addPropertiesToDropdown(properties: PropertyBEModel[]): void {
-        for (const property of properties) {
-            if (this.hasSameType(property)) {
-                this.addPropertyToDropdown({
-                    propertyName: property.name,
-                    propertyId: property.uniqueId,
-                    propertyLabel: property.name,
-                    propertyPath: [property.name]
-                });
-            } else if (this.isComplexType(property.type)) {
-                this.fillPropertyDropdownWithMatchingChildProperties(property);
-            }
-        }
+    isConcatSelected(): boolean {
+        return this.formGroup.get('toscaFunctionType').value === ToscaFunctionType.CONCAT;
     }
 
-    private fillPropertyDropdownWithMatchingChildProperties(inputProperty: PropertyBEModel, parentPropertyList: Array<PropertyBEModel> = []): void {
-        const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, inputProperty.type);
-        if (!dataTypeFound || !dataTypeFound.properties) {
-            return;
-        }
-        parentPropertyList.push(inputProperty);
-        dataTypeFound.properties.forEach(dataTypeProperty => {
-            if (this.hasSameType(dataTypeProperty)) {
-                this.addPropertyToDropdown({
-                    propertyName: dataTypeProperty.name,
-                    propertyId: parentPropertyList[0].uniqueId,
-                    propertyLabel: parentPropertyList.map(property => property.name).join('->') + '->' + dataTypeProperty.name,
-                    propertyPath: [...parentPropertyList.map(property => property.name), dataTypeProperty.name]
-                });
-            } else if (this.isComplexType(dataTypeProperty.type)) {
-                this.fillPropertyDropdownWithMatchingChildProperties(dataTypeProperty, [...parentPropertyList])
-            }
-        });
+    isCustomSelected(): boolean {
+        let toscaFunctionType: CustomToscaFunction = this.getCustomToscaFunction();
+        return toscaFunctionType && (toscaFunctionType.type === ToscaFunctionType.CUSTOM || toscaFunctionType.type === ToscaFunctionType.GET_INPUT);
     }
 
-    private hasSameType(property: PropertyBEModel) {
-        if (this.typeHasSchema(this.property.type)) {
-            if (!property.schema || !property.schema.property) {
-                return false;
-            }
-            return property.type === this.property.type && this.property.schema.property.type === property.schema.property.type;
-        }
-
-        return property.type === this.property.type;
+    isGetFunctionSelected(): boolean {
+        return this.isGetInputSelected() || this.isGetPropertySelected() || this.isGetAttributeSelected();
     }
 
-    private isGetPropertySelected(): boolean {
-        return this.toscaGetFunction.functionType === ToscaGetFunctionType.GET_PROPERTY;
+    isYamlFunctionSelected(): boolean {
+        return this.formGroup.get('toscaFunctionType').value === ToscaFunctionType.YAML;
     }
 
-    private isGetInputSelected(): boolean {
-        return this.toscaGetFunction.functionType === ToscaGetFunctionType.GET_INPUT;
-    }
-
-    private isComplexType(propertyType: string): boolean {
-        return PROPERTY_DATA.SIMPLE_TYPES.indexOf(propertyType) === -1;
+    onClearValues(): void {
+        this.resetForm();
     }
 
-    private typeHasSchema(propertyType: string): boolean {
-        return PROPERTY_TYPES.MAP === propertyType || PROPERTY_TYPES.LIST === propertyType;
+    showClearButton(): boolean {
+        return this.allowClear && this.toscaFunctionTypeForm.value;
     }
 
-    private stopLoading(): void {
-        this.isLoading = false;
+    onConcatFunctionValidityChange(validationEvent: ToscaConcatFunctionValidationEvent): void {
+        if (validationEvent.isValid) {
+            this.toscaFunctionForm.setValue(validationEvent.toscaConcatFunction);
+        } else {
+            this.toscaFunctionForm.setValue(undefined);
+        }
     }
 
-    private startLoading(): void {
-        this.isLoading = true;
+    onCustomFunctionValidityChange(validationEvent: ToscaCustomFunctionValidationEvent): void {
+        if (validationEvent.isValid) {
+            this.toscaFunctionForm.setValue(validationEvent.toscaCustomFunction);
+        } else {
+            this.toscaFunctionForm.setValue(undefined);
+        }
     }
 
-    showDropdown(): boolean {
-        if (this.toscaGetFunction.functionType === ToscaGetFunctionType.GET_PROPERTY) {
-            return this.toscaGetFunction.propertySource && !this.isLoading && !this.dropDownErrorMsg;
+    onGetFunctionValidityChange(validationEvent: ToscaGetFunctionValidationEvent): void {
+        if (validationEvent.isValid) {
+            this.toscaFunctionForm.setValue(validationEvent.toscaGetFunction);
+        } else {
+            this.toscaFunctionForm.setValue(undefined);
         }
-
-        return this.toscaGetFunction.functionType && !this.isLoading && !this.dropDownErrorMsg;
     }
 
-    onPropertySourceChange(): void {
-        if (!this.toscaGetFunction.functionType || !this.propertySource) {
-            return;
-        }
-        this.toscaGetFunction.propertyUniqueId = undefined;
-        this.toscaGetFunction.propertyName = undefined;
-        this.toscaGetFunction.propertyPathFromSource = undefined;
-        if (this.propertySource === PropertySource.SELF) {
-            this.setSelfPropertySource();
+    onYamlFunctionValidityChange(validationEvent: YamlFunctionValidationEvent): void {
+        if (validationEvent.isValid) {
+            this.toscaFunctionForm.setValue(validationEvent.value);
         } else {
-            this.toscaGetFunction.propertySource = PropertySource.INSTANCE;
-            this.toscaGetFunction.sourceName = this.propertySource;
-            this.toscaGetFunction.sourceUniqueId = this.instanceNameAndIdMap.get(this.propertySource);
+            this.toscaFunctionForm.setValue(undefined);
         }
-        this.toscaGetFunctionForm.setValue(this.toscaGetFunction);
-        this.loadPropertyDropdown();
     }
 
-    private setSelfPropertySource(): void {
-        this.toscaGetFunction.propertySource = PropertySource.SELF;
-        this.toscaGetFunction.sourceName = this.componentMetadata.name;
-        this.toscaGetFunction.sourceUniqueId = this.componentMetadata.uniqueId;
-        this.toscaGetFunctionForm.setValue(this.toscaGetFunction);
+    onFunctionTypeChange(): void {
+        this.toscaFunction = undefined;
+        this.toscaFunctionForm.reset();
     }
 
-    onPropertyChange(): void {
-        this.toscaGetFunction.propertyUniqueId = this.selectedProperty.propertyId;
-        this.toscaGetFunction.propertyName = this.selectedProperty.propertyName;
-        this.toscaGetFunction.propertyPathFromSource = this.selectedProperty.propertyPath;
-        this.toscaGetFunctionForm.setValue(this.toscaGetFunction);
+    private emitValidityChange(): void {
+        const isValid: boolean = this.validate();
+        this.onValidityChange.emit({
+            isValid: isValid,
+            toscaFunction: isValid ? this.buildFunctionFromForm() : undefined
+        });
     }
 
-    onClearValues() {
-        this.resetForm();
-    }
+    private buildFunctionFromForm(): ToscaFunction {
+        if (!this.toscaFunctionTypeForm.value) {
+            return undefined;
+        }
+        if (this.isConcatSelected()) {
+            return new ToscaConcatFunction(this.toscaFunctionForm.value);
+        }
+        if (this.isCustomSelected()) {
+            return new ToscaCustomFunction(this.toscaFunctionForm.value);
+        }
+        if (this.isGetFunctionSelected()) {
+            return new ToscaGetFunction(this.toscaFunctionForm.value);
+        }
+        if (this.isYamlFunctionSelected()) {
+            return new YamlFunction(this.toscaFunctionForm.value);
+        }
 
-    showClearButton(): boolean {
-        return this.allowClear && this.toscaGetFunction.functionType !== undefined;
+        console.error(`Function ${this.toscaFunctionTypeForm.value} not supported`);
     }
 }
 
-export interface PropertyDropdownValue {
-    propertyName: string;
-    propertyId: string;
-    propertyLabel: string;
-    propertyPath: Array<string>;
-}
+export class ToscaFunctionValidationEvent {
+    isValid: boolean;
+    toscaFunction: ToscaFunction;
+}
\ No newline at end of file