Replace Eclipselink with Hibernate
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaTopologyTemplate.java
index 32c459c..629e14a 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2020 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Copyright (C) 2019-2020,2023 Nordix Foundation.
+ *  Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -43,14 +43,15 @@ import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
 import org.apache.commons.lang3.ObjectUtils;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+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.PfKey;
 import org.onap.policy.models.base.PfReferenceKey;
 import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.base.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.models.base.validation.annotations.VerifyKey;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaParameter;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
@@ -72,34 +73,36 @@ public class JpaToscaTopologyTemplate extends PfConcept implements PfAuthorative
     public static final String DEFAULT_LOCAL_NAME = "ToscaTopologyTemplateSimple";
 
     @EmbeddedId
+    @VerifyKey
+    @NotNull
     private PfReferenceKey key;
 
     @Column(name = "description")
+    @NotBlank
     private String description;
 
     // @formatter:off
     @ElementCollection
     @Lob
-    private Map<String, JpaToscaParameter> inputs;
+    private Map<@NotNull String, @NotNull @Valid JpaToscaParameter> inputs;
 
     @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
-    @JoinColumns(
-        {
-            @JoinColumn(name = "nodeTemplatesName", referencedColumnName = "name"),
-            @JoinColumn(name = "nodeTemplatessVersion", referencedColumnName = "version")
-        }
-    )
+    @JoinColumns({
+        @JoinColumn(name = "nodeTemplatesName", referencedColumnName = "name"),
+        @JoinColumn(name = "nodeTemplatessVersion", referencedColumnName = "version")
+    })
     @SerializedName("data_types")
+    @Valid
     private JpaToscaNodeTemplates nodeTemplates;
 
     @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
-    @JoinColumns(
-            {
-                @JoinColumn(name = "policyName",    referencedColumnName = "name"),
-                @JoinColumn(name = "policyVersion", referencedColumnName = "version")
-            }
-        )
+    @JoinColumns({
+        @JoinColumn(name = "policyName",    referencedColumnName = "name"),
+        @JoinColumn(name = "policyVersion", referencedColumnName = "version")
+
+    })
     // @formatter:on
+    @Valid
     private JpaToscaPolicies policies;
 
     /**
@@ -145,7 +148,7 @@ public class JpaToscaTopologyTemplate extends PfConcept implements PfAuthorative
 
     @Override
     public ToscaTopologyTemplate toAuthorative() {
-        final ToscaTopologyTemplate toscaTopologyTemplate = new ToscaTopologyTemplate();
+        final var toscaTopologyTemplate = new ToscaTopologyTemplate();
 
         toscaTopologyTemplate.setDescription(description);
 
@@ -181,7 +184,7 @@ public class JpaToscaTopologyTemplate extends PfConcept implements PfAuthorative
         if (toscaTopologyTemplate.getInputs() != null) {
             inputs = new LinkedHashMap<>();
             for (Map.Entry<String, ToscaParameter> toscaInputEntry : toscaTopologyTemplate.getInputs().entrySet()) {
-                JpaToscaParameter jpaInput = new JpaToscaParameter(toscaInputEntry.getValue());
+                var jpaInput = new JpaToscaParameter(toscaInputEntry.getValue());
                 jpaInput.setKey(new PfReferenceKey(getKey(), toscaInputEntry.getKey()));
                 inputs.put(toscaInputEntry.getKey(), jpaInput);
             }
@@ -240,58 +243,6 @@ public class JpaToscaTopologyTemplate extends PfConcept implements PfAuthorative
         }
     }
 
-    @Override
-    public PfValidationResult validate(PfValidationResult resultIn) {
-        PfValidationResult result = resultIn;
-
-        if (key.isNullKey()) {
-            result.addValidationMessage(
-                    new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
-        }
-
-        result = key.validate(result);
-
-        if (description != null && description.trim().length() == 0) {
-            result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
-                    "property description may not be blank"));
-        }
-
-        if (inputs != null) {
-            result = validateInputs(result);
-        }
-
-
-        if (nodeTemplates != null) {
-            result = nodeTemplates.validate(result);
-        }
-
-        if (policies != null) {
-            result = policies.validate(result);
-        }
-
-        return result;
-    }
-
-    /**
-     * Validate the inputs.
-     *
-     * @param resultIn The result of validations up to now
-     * @return the validation result
-     */
-    private PfValidationResult validateInputs(final PfValidationResult resultIn) {
-        PfValidationResult result = resultIn;
-
-        for (JpaToscaParameter input : inputs.values()) {
-            if (input == null) {
-                result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
-                        "topology template input may not be null "));
-            } else {
-                result = input.validate(result);
-            }
-        }
-        return result;
-    }
-
     @Override
     public int compareTo(final PfConcept otherConcept) {
         int result = compareToWithoutEntities(otherConcept);