Java 17 Upgrade
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaProperty.java
index a7156bb..0ef8ffb 100644 (file)
@@ -2,8 +2,9 @@
  * ============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-2021, 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2022 Bell Canada. 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.
 
 package org.onap.policy.models.tosca.simple.concepts;
 
+import jakarta.persistence.Column;
+import jakarta.persistence.ElementCollection;
+import jakarta.persistence.EmbeddedId;
+import java.io.Serial;
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-import javax.persistence.Column;
-import javax.persistence.ElementCollection;
-import javax.persistence.EmbeddedId;
-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.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.coder.YamlJsonTranslator;
 import org.onap.policy.models.base.PfAuthorative;
 import org.onap.policy.models.base.PfConcept;
@@ -46,7 +46,7 @@ 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.base.Validated;
+import org.onap.policy.models.base.validation.annotations.VerifyKey;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty.Status;
 
@@ -56,36 +56,41 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty.Status;
  * @author Chenfei Gao (cgao@research.att.com)
  * @author Liam Fallon (liam.fallon@est.tech)
  */
-@Entity
-@Table(name = "ToscaProperty")
-@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
 @EqualsAndHashCode(callSuper = false)
 public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaProperty> {
+    @Serial
     private static final long serialVersionUID = 1675770231921107988L;
 
     @EmbeddedId
+    @VerifyKey
+    @NotNull
     private PfReferenceKey key;
 
     @Column
+    @VerifyKey
+    @NotNull
     private PfConceptKey type;
 
     @Column
+    @NotBlank
     private String description;
 
     @Column
     private boolean required = false;
 
-    @Column(name = "default")
+    @Column
+    @NotBlank
     private String defaultValue;
 
     @Column
     private Status status = Status.SUPPORTED;
 
     @ElementCollection
-    private List<JpaToscaConstraint> constraints;
+    private List<@NotNull @Valid JpaToscaConstraint> constraints;
 
     @Column
+    @Valid
     private JpaToscaSchemaDefinition entrySchema;
 
     @ElementCollection
@@ -149,7 +154,7 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaPr
 
     @Override
     public ToscaProperty toAuthorative() {
-        ToscaProperty toscaProperty = new ToscaProperty();
+        var toscaProperty = new ToscaProperty();
 
         toscaProperty.setName(key.getLocalName());
 
@@ -240,25 +245,7 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaPr
     }
 
     @Override
-    public BeanValidationResult validate(@NonNull String fieldName) {
-        BeanValidationResult result = new BeanValidationResult(fieldName, this);
-
-        result.addResult(validateKeyNotNull("key", key));
-        result.addResult(validateKeyNotNull("type", type));
-        result.addResult(validateNotBlank("description", description, false));
-        result.addResult(validateNotBlank("defaultValue", defaultValue, false));
-
-        validateList(result, "constraints", constraints, Validated::validateNotNull);
-        validateOptional(result, "entrySchema", entrySchema);
-
-        return result;
-    }
-
-    @Override
-    public int compareTo(final PfConcept otherConcept) {
-        if (otherConcept == null) {
-            return -1;
-        }
+    public int compareTo(@NonNull final PfConcept otherConcept) {
         if (this == otherConcept) {
             return 0;
         }