* ============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.
* @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
private Duration period;
@Column
+ @Min(0)
private int evaluations = 0;
@Column
+ @NotBlank
private String method;
@Column
+ @NotNull
+ @NotBlank
private String action;
/**
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) {