Java 17 Upgrade
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaTrigger.java
index 10a9d2f..2b017ee 100644 (file)
@@ -2,8 +2,9 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Model
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2020 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 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.utils.validation.ParameterValidationUtils;
+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.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;
 
 /**
  * Class to represent the trigger of policy type in TOSCA definition.
@@ -50,36 +48,42 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult;
  * @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
@@ -87,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;
 
     /**
@@ -176,62 +184,6 @@ public class JpaToscaTrigger extends PfConcept {
         action = action.trim();
     }
 
-    @Override
-    public PfValidationResult validate(@NonNull final 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,
-                    "trigger description may not be blank"));
-        }
-
-        if (!ParameterValidationUtils.validateStringParameter(eventType)) {
-            result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
-                    "event type on trigger must be defined"));
-        }
-
-        result = validateOptionalFields(result);
-
-        if (evaluations < 0) {
-            result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
-                    "evaluations on trigger must be zero or a positive integer"));
-        }
-
-        if (method != null && method.trim().length() == 0) {
-            result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
-                    "method on trigger may not be blank"));
-        }
-
-        if (!ParameterValidationUtils.validateStringParameter(action)) {
-            result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
-                    "action on trigger must be defined"));
-        }
-
-        return result;
-    }
-
-    /**
-     * Validate optional fields.
-     *
-     * @param resultIn the validation result so far
-     * @return the validation resutls including these fields
-     */
-    private PfValidationResult validateOptionalFields(final PfValidationResult resultIn) {
-        PfValidationResult result = resultIn;
-
-        result = (schedule != null ? schedule.validate(result) : result);
-        result = (targetFilter != null ? targetFilter.validate(result) : result);
-
-        return result;
-    }
-
     @Override
     public int compareTo(final PfConcept otherConcept) {
         if (otherConcept == null) {