Java 17 Upgrade
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaSchemaDefinition.java
index bae3629..b417165 100644 (file)
@@ -2,8 +2,8 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Model
  * ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * 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.Column;
+import jakarta.persistence.ElementCollection;
+import java.io.Serial;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
-import javax.persistence.Column;
-import javax.persistence.ElementCollection;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NoArgsConstructor;
 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.common.utils.validation.Assertions;
 import org.onap.policy.models.base.PfAuthorative;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfKey;
 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.ToscaConstraint;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaSchemaDefinition;
 
@@ -55,16 +59,20 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaSchemaDefinition;
 public class JpaToscaSchemaDefinition extends Validated
         implements PfAuthorative<ToscaSchemaDefinition>, Serializable, Comparable<JpaToscaSchemaDefinition> {
 
+    @Serial
     private static final long serialVersionUID = 3645882081163287058L;
 
     @Column
+    @VerifyKey
+    @NotNull
     private PfConceptKey type;
 
     @Column
+    @NotBlank
     private String description;
 
     @ElementCollection
-    private List<JpaToscaConstraint> constraints;
+    private List<@NotNull @Valid JpaToscaConstraint> constraints;
 
     /**
      * The full constructor creates a {@link JpaToscaSchemaDefinition} object with mandatory fields.
@@ -95,7 +103,7 @@ public class JpaToscaSchemaDefinition extends Validated
 
     @Override
     public ToscaSchemaDefinition toAuthorative() {
-        ToscaSchemaDefinition toscaEntrySchema = new ToscaSchemaDefinition();
+        var toscaEntrySchema = new ToscaSchemaDefinition();
 
         toscaEntrySchema.setType(type.getName());
         toscaEntrySchema.setTypeVersion(type.getVersion());
@@ -143,18 +151,6 @@ public class JpaToscaSchemaDefinition extends Validated
         description = (description != null ? description.trim() : null);
     }
 
-    @Override
-    public BeanValidationResult validate(@NonNull String fieldName) {
-        BeanValidationResult result = new BeanValidationResult(fieldName, this);
-
-        result.addResult(validateKeyNotNull("type", type));
-        result.addResult(validateNotBlank("description", description, false));
-
-        validateList(result, "constraints", constraints, Validated::validateNotNull);
-
-        return result;
-    }
-
     @Override
     public int compareTo(final JpaToscaSchemaDefinition other) {
         if (other == null) {
@@ -186,10 +182,8 @@ public class JpaToscaSchemaDefinition extends Validated
         copy.setDescription(description);
 
         if (constraints != null) {
-            final List<JpaToscaConstraint> newConstraints = new ArrayList<>();
-            for (final JpaToscaConstraint constraint : constraints) {
-                newConstraints.add(constraint); // Constraints are immutable
-            }
+            // Constraints are immutable
+            final List<JpaToscaConstraint> newConstraints = new ArrayList<>(constraints);
             copy.setConstraints(newConstraints);
         }