Consider schema in filtering function properties 89/129589/4
authorandre.schmid <andre.schmid@est.tech>
Thu, 9 Jun 2022 17:12:20 +0000 (18:12 +0100)
committerMichael Morris <michael.morris@est.tech>
Mon, 13 Jun 2022 13:43:57 +0000 (13:43 +0000)
Considers the selected property/input schema, not only the type,
when searching for matching properties/inputs in the TOSCA function.

Change-Id: Ie6e3eb8991a1ff9233d8d32109217d59f82f403d
Issue-ID: SDC-4043
Signed-off-by: andre.schmid <andre.schmid@est.tech>
catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts

index 2d03732..81e5b47 100644 (file)
@@ -230,13 +230,13 @@ export class ToscaFunctionComponent implements OnInit {
             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.property.type});
+                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.property.type});
+                this.dropDownErrorMsg = this.translateService.translate(msgCode, {type: this.propertyTypeToString()});
             }
         }, (error) => {
             console.error('An error occurred while loading properties.', error);
@@ -248,6 +248,13 @@ export class ToscaFunctionComponent implements OnInit {
         });
     }
 
+    private propertyTypeToString() {
+        if (this.property.schemaType) {
+            return `${this.property.type} of ${this.property.schemaType}`;
+        }
+        return this.property.type;
+    }
+
     private extractProperties(componentGenericResponse: ComponentGenericResponse): PropertyBEModel[] {
         if (this.isGetInputSelected()) {
             return componentGenericResponse.inputs;
@@ -290,7 +297,7 @@ export class ToscaFunctionComponent implements OnInit {
 
     private addPropertiesToDropdown(properties: PropertyBEModel[]): void {
         for (const property of properties) {
-            if (this.property.type === property.type) {
+            if (this.hasSameType(property)) {
                 this.addPropertyToDropdown({
                     propertyName: property.name,
                     propertyId: property.uniqueId,
@@ -310,19 +317,29 @@ export class ToscaFunctionComponent implements OnInit {
         }
         parentPropertyList.push(inputProperty);
         dataTypeFound.properties.forEach(dataTypeProperty => {
-            if (dataTypeProperty.type === this.property.type) {
+            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 (PROPERTY_DATA.SIMPLE_TYPES.indexOf(dataTypeProperty.type) === -1) {
+            } else if (this.isComplexType(dataTypeProperty.type)) {
                 this.fillPropertyDropdownWithMatchingChildProperties(dataTypeProperty, [...parentPropertyList])
             }
         });
     }
 
+    private hasSameType(property: PropertyBEModel) {
+        if (this.property.schema && this.property.schema.property) {
+            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;
+    }
+
     private isGetPropertySelected(): boolean {
         return this.toscaGetFunction.functionType === ToscaGetFunctionType.GET_PROPERTY;
     }