Replace Eclipselink with Hibernate
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaTopologyTemplate.java
index 538680f..629e14a 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2020 Nordix Foundation.
- *  Modifications Copyright (C) 2019-2020 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,13 +43,15 @@ import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
 import org.apache.commons.lang3.ObjectUtils;
-import org.onap.policy.common.parameters.BeanValidationResult;
+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.Validated;
+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;
@@ -71,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;
 
     /**
@@ -144,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);
 
@@ -180,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);
             }
@@ -239,21 +243,6 @@ public class JpaToscaTopologyTemplate extends PfConcept implements PfAuthorative
         }
     }
 
-    @Override
-    public BeanValidationResult validate(@NonNull String fieldName) {
-        BeanValidationResult result = new BeanValidationResult(fieldName, this);
-
-        result.addResult(validateKeyNotNull("key", key));
-        result.addResult(validateNotBlank("description", description, false));
-
-        validateMap(result, "inputs", inputs, Validated::validateEntryValueNotNull);
-
-        validateOptional(result, "nodeTemplates", nodeTemplates);
-        validateOptional(result, "policies", policies);
-
-        return result;
-    }
-
     @Override
     public int compareTo(final PfConcept otherConcept) {
         int result = compareToWithoutEntities(otherConcept);