Fix various bugs related to tosca custom functions 10/134710/2
authorJvD_Ericsson <jeff.van.dam@est.tech>
Mon, 29 May 2023 08:48:42 +0000 (09:48 +0100)
committerMichael Morris <michael.morris@est.tech>
Mon, 29 May 2023 15:37:53 +0000 (15:37 +0000)
Issue-ID: SDC-4512
Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech>
Change-Id: Ia501b124ddf0c77c97ca0c14bbaa18be39b8f631

catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-custom-function/tosca-custom-function.component.ts
catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts
common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java

index 35f1649..ad72ada 100644 (file)
@@ -80,7 +80,7 @@ export class ToscaCustomFunctionComponent implements OnInit {
             this.parameters = [];
         }
         this.fillVariables();
-        if (this.name && this.isDefaultCustomFunction) {
+        if (this.name) {
             this.customFunctionFormName.setValue(this.name);
             this.emitOnValidityChange();
         } else {
index b955983..34ed9a6 100644 (file)
@@ -140,8 +140,8 @@ export class ToscaFunctionComponent implements OnInit, OnChanges {
         let type = this.property.toscaFunction.type;
         if (type == ToscaFunctionType.CUSTOM) {
             let name = (this.property.toscaFunction as ToscaCustomFunction).name;
-            let test = this.customToscaFunctions.find(custToscFunc => _.isEqual(custToscFunc.name, name))
-            if (test) {
+            let customToscaFunc = this.customToscaFunctions.find(custToscFunc => _.isEqual(custToscFunc.name, name))
+            if (customToscaFunc) {
                 this.toscaFunctionTypeForm.setValue(name);
             } else {
                 this.toscaFunctionTypeForm.setValue("other");
@@ -160,9 +160,6 @@ export class ToscaFunctionComponent implements OnInit, OnChanges {
         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.toscaFunctions.push(ToscaFunctionType.CUSTOM);
-        }
         if ((this.property.type === PROPERTY_TYPES.STRING || this.property.type === PROPERTY_TYPES.ANY) && this.overridingType === undefined) {
             this.toscaFunctions.push(ToscaFunctionType.CONCAT);
         }
@@ -189,7 +186,8 @@ export class ToscaFunctionComponent implements OnInit, OnChanges {
 
     getCustomFunctionName():string {
         let toscaFunctionType: CustomToscaFunction = this.getCustomToscaFunction();
-        return toscaFunctionType.name;
+        let name = toscaFunctionType.name;
+        return name == 'other' ? '' : name;
     }
 
     getCustomFunctionType():string {
index f77c6f9..e234a46 100644 (file)
@@ -37,6 +37,7 @@ import org.openecomp.sdc.be.datatypes.enums.PropertySource;
 import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.util.CollectionUtils;
 import org.yaml.snakeyaml.Yaml;
 
 public class ToscaFunctionJsonDeserializer extends StdDeserializer<ToscaFunction> {
@@ -150,23 +151,25 @@ public class ToscaFunctionJsonDeserializer extends StdDeserializer<ToscaFunction
         return jsonNode.asText();
     }
 
-    private List<Object> getNumberAsTextOrElseNull(final JsonNode node, final String fieldName, final DeserializationContext context) throws JsonMappingException{
+    private List<Object> getNumberAsTextOrElseNull(final JsonNode node, final String fieldName, final DeserializationContext context)
+        throws JsonMappingException {
         List<Object> toscaIndexList = new ArrayList<Object>();
         final JsonNode jsonNode = node.get(fieldName);
         if (jsonNode != null) {
             if (!jsonNode.isArray()) {
                 throw context.instantiationException(ToscaGetFunctionDataDefinition.class, "Expecting an array for toscaIndexList attribute");
             }
-            for (int index=0;index<jsonNode.size();index++) {
+            for (int index = 0; index < jsonNode.size(); index++) {
                 String textValue = jsonNode.get(index).asText();
-                if (index%2 == 0) {
+                if (index % 2 == 0) {
                     if (textValue.equalsIgnoreCase("INDEX")) {
                         toscaIndexList.add(textValue);
                     } else {
                         try {
                             toscaIndexList.add(Integer.parseInt(textValue));
-                        } catch(Exception e) {
-                            throw context.instantiationException(ToscaGetFunctionDataDefinition.class, "Expecting a valid value for toscaIndex attribute");
+                        } catch (Exception e) {
+                            throw context.instantiationException(ToscaGetFunctionDataDefinition.class,
+                                "Expecting a valid value for toscaIndex attribute");
                         }
                     }
                 } else {
@@ -205,7 +208,7 @@ public class ToscaFunctionJsonDeserializer extends StdDeserializer<ToscaFunction
     private ToscaFunctionType getCustomFunctionType(String name) {
         List<Configuration.CustomToscaFunction> customFunctions =
             ConfigurationManager.getConfigurationManager().getConfiguration().getDefaultCustomToscaFunctions();
-        if (customFunctions.isEmpty()) {
+        if (CollectionUtils.isEmpty(customFunctions)) {
             return ToscaFunctionType.CUSTOM;
         }
         Optional<Configuration.CustomToscaFunction> optionalFunc = customFunctions.stream().filter(func -> func.getName().equals(name)).findFirst();