Java 17 Upgrade
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaDataType.java
index 5157531..107fb3a 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP Policy Model
  * ================================================================================
  * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020, 2023 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 jakarta.persistence.ElementCollection;
+import jakarta.persistence.Entity;
+import jakarta.persistence.Inheritance;
+import jakarta.persistence.InheritanceType;
+import jakarta.persistence.Table;
+import java.io.Serial;
 import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
 import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import javax.persistence.ElementCollection;
-import javax.persistence.Entity;
-import javax.persistence.Inheritance;
-import javax.persistence.InheritanceType;
-import javax.persistence.Lob;
-import javax.persistence.Table;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
 import lombok.NonNull;
-import org.apache.commons.collections4.CollectionUtils;
 import org.onap.policy.common.parameters.annotations.NotNull;
 import org.onap.policy.common.parameters.annotations.Valid;
-import org.onap.policy.models.base.PfAuthorative;
 import org.onap.policy.models.base.PfConcept;
 import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfKey;
-import org.onap.policy.models.base.PfReferenceKey;
 import org.onap.policy.models.base.PfUtils;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
-import org.onap.policy.models.tosca.utils.ToscaUtils;
 
 /**
  * Class to represent custom data type in TOSCA definition.
@@ -64,23 +53,14 @@ import org.onap.policy.models.tosca.utils.ToscaUtils;
 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
 @EqualsAndHashCode(callSuper = true)
-public class JpaToscaDataType extends JpaToscaEntityType<ToscaDataType> implements PfAuthorative<ToscaDataType> {
+@NoArgsConstructor
+public class JpaToscaDataType extends JpaToscaWithToscaProperties<ToscaDataType> {
+    @Serial
     private static final long serialVersionUID = -3922690413436539164L;
 
     @ElementCollection
     private List<@NotNull @Valid JpaToscaConstraint> constraints;
 
-    @ElementCollection
-    @Lob
-    private Map<@NotNull String, @NotNull @Valid JpaToscaProperty> properties;
-
-    /**
-     * The Default Constructor creates a {@link JpaToscaDataType} object with a null key.
-     */
-    public JpaToscaDataType() {
-        this(new PfConceptKey());
-    }
-
     /**
      * The Key Constructor creates a {@link JpaToscaDataType} object with the given concept key.
      *
@@ -99,7 +79,6 @@ public class JpaToscaDataType extends JpaToscaEntityType<ToscaDataType> implemen
         super(copyConcept);
         // Constraints are immutable
         this.constraints = (copyConcept.constraints != null ? new ArrayList<>(copyConcept.constraints) : null);
-        this.properties = PfUtils.mapMap(copyConcept.properties, JpaToscaProperty::new);
     }
 
     /**
@@ -108,17 +87,16 @@ public class JpaToscaDataType extends JpaToscaEntityType<ToscaDataType> implemen
      * @param authorativeConcept the authorative concept to copy from
      */
     public JpaToscaDataType(final ToscaDataType authorativeConcept) {
-        this.fromAuthorative(authorativeConcept);
+        super(authorativeConcept);
     }
 
     @Override
     public ToscaDataType toAuthorative() {
-        ToscaDataType toscaDataType = new ToscaDataType();
+        var toscaDataType = new ToscaDataType();
         super.setToscaEntity(toscaDataType);
         super.toAuthorative();
 
         toscaDataType.setConstraints(PfUtils.mapList(constraints, JpaToscaConstraint::toAuthorative));
-        toscaDataType.setProperties(PfUtils.mapMap(properties, JpaToscaProperty::toAuthorative));
 
         return toscaDataType;
     }
@@ -128,89 +106,21 @@ public class JpaToscaDataType extends JpaToscaEntityType<ToscaDataType> implemen
         super.fromAuthorative(toscaDataType);
 
         constraints = PfUtils.mapList(toscaDataType.getConstraints(), JpaToscaConstraint::newInstance);
-
-        if (toscaDataType.getProperties() != null) {
-            properties = new LinkedHashMap<>();
-            for (Entry<String, ToscaProperty> toscaPropertyEntry : toscaDataType.getProperties().entrySet()) {
-                JpaToscaProperty jpaProperty = new JpaToscaProperty(toscaPropertyEntry.getValue());
-                jpaProperty.setKey(new PfReferenceKey(getKey(), toscaPropertyEntry.getKey()));
-                properties.put(toscaPropertyEntry.getKey(), jpaProperty);
-            }
-        }
-    }
-
-    @Override
-    public List<PfKey> getKeys() {
-        final List<PfKey> keyList = super.getKeys();
-
-        if (properties != null) {
-            for (JpaToscaProperty property : properties.values()) {
-                keyList.addAll(property.getKeys());
-            }
-        }
-
-        return keyList;
-    }
-
-    @Override
-    public void clean() {
-        super.clean();
-
-        if (properties != null) {
-            for (JpaToscaProperty property : properties.values()) {
-                property.clean();
-            }
-        }
     }
 
     @Override
     public int compareTo(final PfConcept otherConcept) {
-        if (otherConcept == null) {
-            return -1;
-        }
         if (this == otherConcept) {
             return 0;
         }
-        if (getClass() != otherConcept.getClass()) {
-            return getClass().getName().compareTo(otherConcept.getClass().getName());
-        }
-
-        final JpaToscaDataType other = (JpaToscaDataType) otherConcept;
-        int result = super.compareTo(other);
-        if (result != 0) {
-            return result;
-        }
 
-        result = PfUtils.compareCollections(constraints, other.constraints);
+        int result = super.compareTo(otherConcept);
         if (result != 0) {
             return result;
         }
 
-        return PfUtils.compareMaps(properties, other.properties);
-    }
-
-    /**
-     * Get the data types referenced in a data type.
-     *
-     * @return the data types referenced in a data type
-     */
-    public Collection<PfConceptKey> getReferencedDataTypes() {
-        if (properties == null) {
-            return CollectionUtils.emptyCollection();
-        }
-
-        Set<PfConceptKey> referencedDataTypes = new LinkedHashSet<>();
-
-        for (JpaToscaProperty property : properties.values()) {
-            referencedDataTypes.add(property.getType());
-
-            if (property.getEntrySchema() != null) {
-                referencedDataTypes.add(property.getEntrySchema().getType());
-            }
-        }
-
-        referencedDataTypes.removeAll(ToscaUtils.getPredefinedDataTypes());
+        final JpaToscaDataType other = (JpaToscaDataType) otherConcept;
 
-        return referencedDataTypes;
+        return PfUtils.compareCollections(constraints, other.constraints);
     }
 }