2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019-2021 Nordix Foundation.
7 * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * SPDX-License-Identifier: Apache-2.0
22 * ============LICENSE_END=========================================================
25 package org.onap.policy.models.tosca.simple.concepts;
27 import com.google.gson.annotations.SerializedName;
28 import java.time.Duration;
29 import java.util.List;
30 import javax.persistence.Column;
31 import javax.persistence.EmbeddedId;
33 import lombok.EqualsAndHashCode;
34 import lombok.NonNull;
35 import org.apache.commons.lang3.ObjectUtils;
36 import org.onap.policy.common.parameters.annotations.Min;
37 import org.onap.policy.common.parameters.annotations.NotBlank;
38 import org.onap.policy.common.parameters.annotations.NotNull;
39 import org.onap.policy.common.parameters.annotations.Valid;
40 import org.onap.policy.models.base.PfConcept;
41 import org.onap.policy.models.base.PfKey;
42 import org.onap.policy.models.base.PfReferenceKey;
43 import org.onap.policy.models.base.validation.annotations.VerifyKey;
46 * Class to represent the trigger of policy type in TOSCA definition.
48 * @author Chenfei Gao (cgao@research.att.com)
49 * @author Liam Fallon (liam.fallon@est.tech)
52 @EqualsAndHashCode(callSuper = false)
53 public class JpaToscaTrigger extends PfConcept {
54 private static final long serialVersionUID = -6515211640208986971L;
59 private PfReferenceKey key;
63 private String description;
66 @SerializedName("event_type")
69 private String eventType;
72 @SerializedName("schedule")
74 private JpaToscaTimeInterval schedule;
77 @SerializedName("target_filter")
79 private JpaToscaEventFilter targetFilter;
81 @Column(name = "toscaCondition")
83 private JpaToscaConstraint condition;
85 @Column(name = "toscaConstraint")
87 private JpaToscaConstraint constraint;
90 @SerializedName("period")
91 private Duration period;
95 private int evaluations = 0;
99 private String method;
104 private String action;
107 * The Default Constructor creates a {@link JpaToscaTrigger} object with a null key.
109 public JpaToscaTrigger() {
110 this(new PfReferenceKey());
114 * The Key Constructor creates a {@link JpaToscaTrigger} object with the given concept key.
118 public JpaToscaTrigger(@NonNull final PfReferenceKey key) {
123 * The full Constructor creates a {@link JpaToscaTrigger} object with all mandatory objects.
126 * @param eventType the event type
127 * @param action the trigger action
129 public JpaToscaTrigger(@NonNull final PfReferenceKey key, @NonNull final String eventType,
130 @NonNull final String action) {
132 this.eventType = eventType;
133 this.action = action;
139 * @param copyConcept the concept to copy from
141 public JpaToscaTrigger(final JpaToscaTrigger copyConcept) {
143 this.key = new PfReferenceKey(copyConcept.key);
144 this.description = copyConcept.description;
145 this.eventType = copyConcept.eventType;
146 this.schedule = (copyConcept.schedule != null ? new JpaToscaTimeInterval(copyConcept.schedule) : null);
148 (copyConcept.targetFilter != null ? new JpaToscaEventFilter(copyConcept.targetFilter) : null);
149 this.condition = copyConcept.condition;
150 this.constraint = copyConcept.constraint;
151 this.period = copyConcept.period;
152 this.evaluations = copyConcept.evaluations;
153 this.method = copyConcept.method;
154 this.action = copyConcept.action;
158 public List<PfKey> getKeys() {
159 final List<PfKey> keyList = getKey().getKeys();
160 if (schedule != null) {
161 keyList.addAll(schedule.getKeys());
163 if (targetFilter != null) {
164 keyList.addAll(targetFilter.getKeys());
170 public void clean() {
173 description = (description != null ? description.trim() : description);
174 eventType = eventType.trim();
176 if (schedule != null) {
179 if (targetFilter != null) {
180 targetFilter.clean();
183 method = (method != null ? method.trim() : method);
184 action = action.trim();
188 public int compareTo(final PfConcept otherConcept) {
189 if (otherConcept == null) {
192 if (this == otherConcept) {
195 if (getClass() != otherConcept.getClass()) {
196 return getClass().getName().compareTo(otherConcept.getClass().getName());
199 final JpaToscaTrigger other = (JpaToscaTrigger) otherConcept;
200 int result = key.compareTo(other.key);
205 return compareFields(other);
209 * Compare the fields of this ToscaTrigger object with the fields of the other ToscaProperty object.
211 * @param other the other ToscaTrigger object
213 private int compareFields(final JpaToscaTrigger other) {
214 int result = ObjectUtils.compare(description, other.description);
219 result = ObjectUtils.compare(eventType, other.eventType);
224 result = ObjectUtils.compare(schedule, other.schedule);
229 result = ObjectUtils.compare(targetFilter, other.targetFilter);
234 result = ObjectUtils.compare(condition, other.condition);
239 result = ObjectUtils.compare(constraint, other.constraint);
244 result = ObjectUtils.compare(period, other.period);
249 if (evaluations != other.evaluations) {
250 return evaluations - other.evaluations;
253 result = ObjectUtils.compare(method, other.method);
258 return ObjectUtils.compare(action, other.action);