Fix 'Changing VFC version on template wipes previously assigned property values based... 66/135766/2
authorvasraz <vasyl.razinkov@est.tech>
Thu, 17 Aug 2023 18:30:47 +0000 (19:30 +0100)
committerJEFF VAN DAM <jeff.van.dam@est.tech>
Fri, 18 Aug 2023 10:14:29 +0000 (10:14 +0000)
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: I51bbc92ea355dd36206746f96984d3593446f188
Issue-ID: SDC-4586

catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/DataForMergeHolder.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/DataDefinitionsValuesMergingBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyDataValueMergeBusinessLogic.java
common-be/src/main/java/org/openecomp/sdc/be/datatypes/tosca/ToscaDataDefinition.java

index ec7fe0c..01e87a1 100644 (file)
@@ -42,9 +42,9 @@ import java.util.UUID;
 import java.util.stream.Collectors;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.MapUtils;
-import org.apache.commons.text.StringEscapeUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.text.StringEscapeUtils;
 import org.json.JSONArray;
 import org.json.JSONObject;
 import org.onap.sdc.tosca.datatypes.model.PropertyType;
@@ -76,6 +76,7 @@ import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType;
 import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -1985,6 +1986,9 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
                 if (property.isToscaFunction()) {
                     toscaFunctionValidator.validate(property, containerComponent);
                     property.setValue(StringEscapeUtils.unescapeJava(property.getToscaFunction().getValue()));
+                    if (ToscaFunctionType.GET_INPUT == property.getToscaFunction().getType()) {
+                        property.setGetInputValues(Collections.singletonList(buildGetInputValue(property)));
+                    }
                 }
                 if (CollectionUtils.isNotEmpty(property.getSubPropertyToscaFunctions())) {
                     ToscaPropertyType type = ToscaPropertyType.isValidType(property.getType());
@@ -2047,6 +2051,14 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
         }
     }
 
+    private GetInputValueDataDefinition buildGetInputValue(final ComponentInstanceProperty property) {
+        final GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition();
+        getInputValueDataDefinition.setPropName(property.getName());
+        getInputValueDataDefinition.setInputName(((ToscaGetFunctionDataDefinition) property.getToscaFunction()).getPropertyName());
+        getInputValueDataDefinition.setInputId(((ToscaGetFunctionDataDefinition) property.getToscaFunction()).getPropertyUniqueId());
+        return getInputValueDataDefinition;
+    }
+
     private void addE(JSONArray jsonArray, List<String> path, String value) {
         Object objectForPath = jsonArray.opt(Integer.parseInt(path.get(0)));
         if (objectForPath == null) {
@@ -2548,7 +2560,8 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
             throw ToscaGetFunctionExceptionSupplier
                 .propertyTypeDiverge(toscaGetFunction.getType(), referredProperty.getType(), property.getType()).get();
         }
-        if (PropertyType.typeHasSchema(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getType()) && !"list".equalsIgnoreCase(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getSchemaType())) {
+        if (PropertyType.typeHasSchema(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getType())
+            && !"list".equalsIgnoreCase(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getSchemaType())) {
             throw ToscaGetFunctionExceptionSupplier
                 .propertySchemaDiverge(toscaGetFunction.getType(), referredProperty.getSchemaType(), property.getSchemaType()).get();
         }
index 21c7461..d838eb1 100644 (file)
@@ -122,6 +122,7 @@ public class DataForMergeHolder {
             propertyCopy.setDefaultValue(property.getDefaultValue());
             propertyCopy.setInputId(property.getInputId());
             propertyCopy.setGetInputValues(property.getGetInputValues());
+            propertyCopy.setToscaFunction(property.getToscaFunction());
             this.origComponentInstanceProperties.add(propertyCopy);
         });
     }
index 6f1a1e1..c64e2ef 100644 (file)
@@ -67,6 +67,9 @@ public class DataDefinitionsValuesMergingBusinessLogic {
     private void mergeInstanceDefinition(MergePropertyData mergeData) {
         if (isSameType(mergeData.getOldProp(), mergeData.getNewProp())) {
             propertyValueMergeBL.mergePropertyValue(mergeData.getOldProp(), mergeData.getNewProp(), mergeData.getGetInputNamesToMerge());
+            if (mergeData.getOldProp().isToscaFunction()) {
+                mergeData.getNewProp().setToscaFunction(mergeData.getOldProp().getToscaFunction());
+            }
         }
     }
 
index 272798f..7562dfe 100644 (file)
@@ -88,9 +88,7 @@ public class PropertyDataValueMergeBusinessLogic {
     }
 
     private Object convertPropertyStrValueToObject(PropertyDataDefinition propertyDataDefinition, Map<String, DataTypeDefinition> dataTypes) {
-        String propValue = propertyDataDefinition.getValue() == null ? "" : propertyDataDefinition.getValue();
-        String propertyType = propertyDataDefinition.getType();
-        String innerType = propertyDataDefinition.getSchemaType();
+        final String propValue = propertyDataDefinition.getValue() == null ? "" : propertyDataDefinition.getValue();
         return propertyConvertor.convertToToscaObject(propertyDataDefinition, propValue, dataTypes, true);
     }
 
index 0b142d5..95875d9 100644 (file)
@@ -34,12 +34,12 @@ public abstract class ToscaDataDefinition {
 
     protected Map<String, Object> toscaPresentation;
 
-    public ToscaDataDefinition() {
+    protected ToscaDataDefinition() {
         toscaPresentation = new HashMap<>();
     }
 
     @JsonCreator
-    public ToscaDataDefinition(Map<String, Object> art) {
+    protected ToscaDataDefinition(Map<String, Object> art) {
         toscaPresentation = art;
     }