Changes for Checkstyle 8.32
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaProperty.java
index 38d5c09..25d2266 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP Policy Model
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 package org.onap.policy.models.tosca.simple.concepts;
 
 import java.util.ArrayList;
+import java.util.LinkedHashMap;
 import java.util.List;
-
+import java.util.Map;
+import java.util.Map.Entry;
 import javax.persistence.Column;
 import javax.persistence.ElementCollection;
 import javax.persistence.EmbeddedId;
@@ -33,13 +35,10 @@ import javax.persistence.Entity;
 import javax.persistence.Inheritance;
 import javax.persistence.InheritanceType;
 import javax.persistence.Table;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
-
 import org.apache.commons.lang3.ObjectUtils;
-import org.onap.policy.common.utils.validation.Assertions;
 import org.onap.policy.models.base.PfAuthorative;
 import org.onap.policy.models.base.PfConcept;
 import org.onap.policy.models.base.PfConceptKey;
@@ -83,15 +82,17 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaPr
     private String defaultValue;
 
     @Column
-    @NonNull
     private Status status = Status.SUPPORTED;
 
     @ElementCollection
-    private List<JpaToscaConstraint> constraints;
+    private List<JpaToscaConstraint> constraints = new ArrayList<>();
 
     @Column
     private JpaToscaEntrySchema entrySchema;
 
+    @ElementCollection
+    private Map<String, String> metadata = new LinkedHashMap<>();
+
     /**
      * The Default Constructor creates a {@link JpaToscaProperty} object with a null key.
      */
@@ -126,6 +127,16 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaPr
      */
     public JpaToscaProperty(final JpaToscaProperty copyConcept) {
         super(copyConcept);
+        this.key = new PfReferenceKey(copyConcept.key);
+        this.type = new PfConceptKey(copyConcept.type);
+        this.description = copyConcept.description;
+        this.required = copyConcept.required;
+        this.defaultValue = copyConcept.defaultValue;
+        this.status = copyConcept.status;
+        // Constraints are immutable
+        this.constraints = (copyConcept.constraints != null ? new ArrayList<>(copyConcept.constraints) : null);
+        this.entrySchema = (copyConcept.entrySchema != null ? new JpaToscaEntrySchema(copyConcept.entrySchema) : null);
+        this.metadata = (copyConcept.metadata != null ? new LinkedHashMap<>(copyConcept.metadata) : null);
     }
 
     /**
@@ -165,6 +176,10 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaPr
             toscaProperty.setEntrySchema(entrySchema.toAuthorative());
         }
 
+        if (metadata != null) {
+            toscaProperty.setMetadata(new LinkedHashMap<>(metadata));
+        }
+
         return toscaProperty;
     }
 
@@ -195,6 +210,12 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaPr
         if (toscaProperty.getEntrySchema() != null) {
             entrySchema = new JpaToscaEntrySchema(toscaProperty.getEntrySchema());
         }
+
+        // Add the property metadata if it doesn't exist already
+        if (toscaProperty.getMetadata() != null) {
+            metadata = new LinkedHashMap<>(toscaProperty.getMetadata());
+        }
+
     }
 
     @Override
@@ -227,6 +248,12 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaPr
         if (entrySchema != null) {
             entrySchema.clean();
         }
+
+        if (metadata != null) {
+            for (Entry<String, String> metadataEntry : metadata.entrySet()) {
+                metadataEntry.setValue(metadataEntry.getValue().trim());
+            }
+        }
     }
 
     @Override
@@ -287,7 +314,7 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaPr
             return 0;
         }
         if (getClass() != otherConcept.getClass()) {
-            return this.hashCode() - otherConcept.hashCode();
+            return getClass().getName().compareTo(otherConcept.getClass().getName());
         }
 
         final JpaToscaProperty other = (JpaToscaProperty) otherConcept;
@@ -335,31 +362,4 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaPr
 
         return entrySchema.compareTo(other.entrySchema);
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept target) {
-        Assertions.instanceOf(target, JpaToscaProperty.class);
-
-        final JpaToscaProperty copy = ((JpaToscaProperty) target);
-        copy.setKey(new PfReferenceKey(key));
-        copy.setType(new PfConceptKey(type));
-        copy.setDescription(description);
-        copy.setRequired(required);
-        copy.setDefaultValue(defaultValue);
-        copy.setStatus(status);
-
-        if (constraints == null) {
-            copy.setConstraints(null);
-        } else {
-            final List<JpaToscaConstraint> newConstraints = new ArrayList<>();
-            for (final JpaToscaConstraint constraint : constraints) {
-                newConstraints.add(constraint); // Constraints are immutable
-            }
-            copy.setConstraints(newConstraints);
-        }
-
-        copy.setEntrySchema(entrySchema != null ? new JpaToscaEntrySchema(entrySchema) : null);
-
-        return copy;
-    }
 }