Java 17 Upgrade
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaTrigger.java
index e307540..2b017ee 100644 (file)
@@ -3,7 +3,8 @@
  * ONAP Policy Model
  * ================================================================================
  * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * 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 com.google.gson.annotations.SerializedName;
+import jakarta.persistence.Column;
+import jakarta.persistence.EmbeddedId;
 import java.time.Duration;
 import java.util.List;
-import javax.persistence.Column;
-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.Min;
+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.PfConcept;
 import org.onap.policy.models.base.PfKey;
 import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.validation.annotations.VerifyKey;
 
 /**
  * Class to represent the trigger of policy type in TOSCA definition.
@@ -47,36 +48,42 @@ import org.onap.policy.models.base.PfReferenceKey;
  * @author Chenfei Gao (cgao@research.att.com)
  * @author Liam Fallon (liam.fallon@est.tech)
  */
-@Entity
-@Table(name = "ToscaTrigger")
-@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
 @EqualsAndHashCode(callSuper = false)
 public class JpaToscaTrigger extends PfConcept {
     private static final long serialVersionUID = -6515211640208986971L;
 
     @EmbeddedId
+    @VerifyKey
+    @NotNull
     private PfReferenceKey key;
 
     @Column
+    @NotBlank
     private String description;
 
     @Column
     @SerializedName("event_type")
+    @NotNull
+    @NotBlank
     private String eventType;
 
     @Column
     @SerializedName("schedule")
+    @Valid
     private JpaToscaTimeInterval schedule;
 
     @Column
     @SerializedName("target_filter")
+    @Valid
     private JpaToscaEventFilter targetFilter;
 
-    @Column
+    @Column(name = "toscaCondition")
+    @Valid
     private JpaToscaConstraint condition;
 
-    @Column
+    @Column(name = "toscaConstraint")
+    @Valid
     private JpaToscaConstraint constraint;
 
     @Column
@@ -84,12 +91,16 @@ public class JpaToscaTrigger extends PfConcept {
     private Duration period;
 
     @Column
+    @Min(0)
     private int evaluations = 0;
 
     @Column
+    @NotBlank
     private String method;
 
     @Column
+    @NotNull
+    @NotBlank
     private String action;
 
     /**
@@ -173,28 +184,6 @@ public class JpaToscaTrigger extends PfConcept {
         action = action.trim();
     }
 
-    @Override
-    public BeanValidationResult validate(@NonNull String fieldName) {
-        BeanValidationResult result = new BeanValidationResult(fieldName, this);
-
-        result.addResult(validateKeyNotNull("key", key));
-
-        result.addResult(validateNotBlank("description", description, false));
-        result.addResult(validateNotBlank("eventType", eventType, true));
-
-        validateOptional(result, "schedule", schedule);
-        validateOptional(result, "targetFilter", targetFilter);
-
-        if (evaluations < 0) {
-            addResult(result, "evaluations", evaluations, "is negative");
-        }
-
-        result.addResult(validateNotBlank("method", method, false));
-        result.addResult(validateNotBlank("action", action, true));
-
-        return result;
-    }
-
     @Override
     public int compareTo(final PfConcept otherConcept) {
         if (otherConcept == null) {