* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 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.Assertions;
-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;
/**
*/
public JpaToscaTrigger(final JpaToscaTrigger copyConcept) {
super(copyConcept);
+ this.key = new PfReferenceKey(copyConcept.key);
+ this.description = copyConcept.description;
+ this.eventType = copyConcept.eventType;
+ this.schedule = (copyConcept.schedule != null ? new JpaToscaTimeInterval(copyConcept.schedule) : null);
+ this.targetFilter =
+ (copyConcept.targetFilter != null ? new JpaToscaEventFilter(copyConcept.targetFilter) : null);
+ this.condition = copyConcept.condition;
+ this.constraint = copyConcept.constraint;
+ this.period = copyConcept.period;
+ this.evaluations = copyConcept.evaluations;
+ this.method = copyConcept.method;
+ this.action = copyConcept.action;
}
@Override
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) {
return 0;
}
if (getClass() != otherConcept.getClass()) {
- return this.hashCode() - otherConcept.hashCode();
+ return getClass().getName().compareTo(otherConcept.getClass().getName());
}
final JpaToscaTrigger other = (JpaToscaTrigger) otherConcept;
- if (!key.equals(other.key)) {
- return key.compareTo(other.key);
+ int result = key.compareTo(other.key);
+ if (result != 0) {
+ return result;
}
return compareFields(other);
}
/**
- * Compare the fields of this ToscaTrigger object with the fields of the other ToscaProperty
- * object.
+ * Compare the fields of this ToscaTrigger object with the fields of the other ToscaProperty object.
*
* @param other the other ToscaTrigger object
*/
return ObjectUtils.compare(action, other.action);
}
-
- @Override
- public PfConcept copyTo(@NonNull final PfConcept target) {
- Assertions.instanceOf(target, JpaToscaTrigger.class);
-
- final JpaToscaTrigger copy = ((JpaToscaTrigger) target);
- copy.setKey(new PfReferenceKey(key));
- copy.setDescription(description);
- copy.setEventType(eventType);
- copy.setSchedule(schedule != null ? new JpaToscaTimeInterval(schedule) : null);
- copy.setTargetFilter(targetFilter != null ? new JpaToscaEventFilter(targetFilter) : null);
- copy.setCondition(condition);
- copy.setConstraint(constraint);
- copy.setPeriod(period);
- copy.setEvaluations(evaluations);
- copy.setMethod(method);
- copy.setAction(action);
-
- return copy;
- }
}