Fix Service/VF set value to list/map properties
[sdc.git] / common-be / src / main / java / org / openecomp / sdc / be / datatypes / elements / SchemaDefinition.java
index 1e4fc58..17e21f0 100644 (file)
 
 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<String, PropertyDataDefinition> propertyEntry : schemaDefinition.getProperties().entrySet()) {
+                this.properties.put(propertyEntry.getKey(), new PropertyDataDefinition(propertyEntry.getValue()));
+            }
+        }
     }
 
     public String getDerivedFrom() {