From 88fdc6dd75f1119ffa8e54dbfd721b6ed722b779 Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Wed, 23 Mar 2022 15:39:45 +0000 Subject: Fix Service/VF set value to list/map properties In the Service Property Assignment page, setting a value to a property of type list or map was having the type replaced by the schema type and the value incorrectly set. Add test cases to cover the problem. Include small refactors. Issue-ID: SDC-3926 Change-Id: I1257dbb02e18b103118672ec52d663707d53229c Signed-off-by: andre.schmid --- .../datatypes/elements/PropertyDataDefinition.java | 6 +++-- .../be/datatypes/elements/SchemaDefinition.java | 26 ++++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) (limited to 'common-be') diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java index 969d986c4d..c885dbcc46 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java @@ -84,14 +84,16 @@ public class PropertyDataDefinition extends ToscaDataDefinition { super(pr); } - public PropertyDataDefinition(PropertyDataDefinition propertyDataDefinition) { + public PropertyDataDefinition(final PropertyDataDefinition propertyDataDefinition) { super(); this.setUniqueId(propertyDataDefinition.getUniqueId()); this.setRequired(propertyDataDefinition.isRequired()); this.setDefaultValue(propertyDataDefinition.getDefaultValue()); this.setDefinition(propertyDataDefinition.getDefinition()); this.setDescription(propertyDataDefinition.getDescription()); - this.setSchema(propertyDataDefinition.getSchema()); + if (propertyDataDefinition.getSchema() != null) { + this.setSchema(new SchemaDefinition(propertyDataDefinition.getSchema())); + } this.setPassword(propertyDataDefinition.isPassword()); this.setType(propertyDataDefinition.getType()); this.setName(propertyDataDefinition.getName()); diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/SchemaDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/SchemaDefinition.java index 1e4fc58ffe..17e21f0cc7 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/SchemaDefinition.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/SchemaDefinition.java @@ -20,10 +20,14 @@ package org.openecomp.sdc.be.datatypes.elements; -import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition; - +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition; /** * Schema allows to create new types that can be used along TOSCA definitions. @@ -45,7 +49,25 @@ public class SchemaDefinition extends ToscaDataDefinition { this.setDerivedFrom(derivedFrom); this.setConstraints(constraints); this.setProperties(properties); + } + public SchemaDefinition(final SchemaDefinition schemaDefinition) { + if (schemaDefinition == null) { + return; + } + this.derivedFrom = schemaDefinition.getDerivedFrom(); + if (CollectionUtils.isNotEmpty(schemaDefinition.getConstraints())) { + this.constraints = new ArrayList<>(schemaDefinition.getConstraints()); + } + if (schemaDefinition.getProperty() != null) { + this.property = new PropertyDataDefinition(schemaDefinition.getProperty()); + } + if (MapUtils.isNotEmpty(schemaDefinition.getProperties())) { + this.properties = new HashMap<>(); + for (final Entry propertyEntry : schemaDefinition.getProperties().entrySet()) { + this.properties.put(propertyEntry.getKey(), new PropertyDataDefinition(propertyEntry.getValue())); + } + } } public String getDerivedFrom() { -- cgit 1.2.3-korg