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 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 * SPDX-License-Identifier: Apache-2.0
21 * ============LICENSE_END=========================================================
24 package org.onap.policy.models.tosca.simple.concepts;
26 import com.google.gson.annotations.SerializedName;
27 import java.time.Duration;
28 import java.util.List;
29 import javax.persistence.Column;
30 import javax.persistence.EmbeddedId;
31 import javax.persistence.Entity;
32 import javax.persistence.Inheritance;
33 import javax.persistence.InheritanceType;
34 import javax.persistence.Table;
36 import lombok.EqualsAndHashCode;
37 import lombok.NonNull;
38 import org.apache.commons.lang3.ObjectUtils;
39 import org.onap.policy.common.parameters.annotations.Min;
40 import org.onap.policy.common.parameters.annotations.NotBlank;
41 import org.onap.policy.common.parameters.annotations.NotNull;
42 import org.onap.policy.common.parameters.annotations.Valid;
43 import org.onap.policy.models.base.PfConcept;
44 import org.onap.policy.models.base.PfKey;
45 import org.onap.policy.models.base.PfReferenceKey;
46 import org.onap.policy.models.base.validation.annotations.VerifyKey;
49 * Class to represent the trigger of policy type in TOSCA definition.
51 * @author Chenfei Gao (cgao@research.att.com)
52 * @author Liam Fallon (liam.fallon@est.tech)
55 @Table(name = "ToscaTrigger")
56 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
58 @EqualsAndHashCode(callSuper = false)
59 public class JpaToscaTrigger extends PfConcept {
60 private static final long serialVersionUID = -6515211640208986971L;
65 private PfReferenceKey key;
69 private String description;
72 @SerializedName("event_type")
75 private String eventType;
78 @SerializedName("schedule")
80 private JpaToscaTimeInterval schedule;
83 @SerializedName("target_filter")
85 private JpaToscaEventFilter targetFilter;
87 @Column(name = "toscaCondition")
89 private JpaToscaConstraint condition;
91 @Column(name = "toscaConstraint")
93 private JpaToscaConstraint constraint;
96 @SerializedName("period")
97 private Duration period;
101 private int evaluations = 0;
105 private String method;
110 private String action;
113 * The Default Constructor creates a {@link JpaToscaTrigger} object with a null key.
115 public JpaToscaTrigger() {
116 this(new PfReferenceKey());
120 * The Key Constructor creates a {@link JpaToscaTrigger} object with the given concept key.
124 public JpaToscaTrigger(@NonNull final PfReferenceKey key) {
129 * The full Constructor creates a {@link JpaToscaTrigger} object with all mandatory objects.
132 * @param eventType the event type
133 * @param action the trigger action
135 public JpaToscaTrigger(@NonNull final PfReferenceKey key, @NonNull final String eventType,
136 @NonNull final String action) {
138 this.eventType = eventType;
139 this.action = action;
145 * @param copyConcept the concept to copy from
147 public JpaToscaTrigger(final JpaToscaTrigger copyConcept) {
149 this.key = new PfReferenceKey(copyConcept.key);
150 this.description = copyConcept.description;
151 this.eventType = copyConcept.eventType;
152 this.schedule = (copyConcept.schedule != null ? new JpaToscaTimeInterval(copyConcept.schedule) : null);
154 (copyConcept.targetFilter != null ? new JpaToscaEventFilter(copyConcept.targetFilter) : null);
155 this.condition = copyConcept.condition;
156 this.constraint = copyConcept.constraint;
157 this.period = copyConcept.period;
158 this.evaluations = copyConcept.evaluations;
159 this.method = copyConcept.method;
160 this.action = copyConcept.action;
164 public List<PfKey> getKeys() {
165 final List<PfKey> keyList = getKey().getKeys();
166 if (schedule != null) {
167 keyList.addAll(schedule.getKeys());
169 if (targetFilter != null) {
170 keyList.addAll(targetFilter.getKeys());
176 public void clean() {
179 description = (description != null ? description.trim() : description);
180 eventType = eventType.trim();
182 if (schedule != null) {
185 if (targetFilter != null) {
186 targetFilter.clean();
189 method = (method != null ? method.trim() : method);
190 action = action.trim();
194 public int compareTo(final PfConcept otherConcept) {
195 if (otherConcept == null) {
198 if (this == otherConcept) {
201 if (getClass() != otherConcept.getClass()) {
202 return getClass().getName().compareTo(otherConcept.getClass().getName());
205 final JpaToscaTrigger other = (JpaToscaTrigger) otherConcept;
206 int result = key.compareTo(other.key);
211 return compareFields(other);
215 * Compare the fields of this ToscaTrigger object with the fields of the other ToscaProperty object.
217 * @param other the other ToscaTrigger object
219 private int compareFields(final JpaToscaTrigger other) {
220 int result = ObjectUtils.compare(description, other.description);
225 result = ObjectUtils.compare(eventType, other.eventType);
230 result = ObjectUtils.compare(schedule, other.schedule);
235 result = ObjectUtils.compare(targetFilter, other.targetFilter);
240 result = ObjectUtils.compare(condition, other.condition);
245 result = ObjectUtils.compare(constraint, other.constraint);
250 result = ObjectUtils.compare(period, other.period);
255 if (evaluations != other.evaluations) {
256 return evaluations - other.evaluations;
259 result = ObjectUtils.compare(method, other.method);
264 return ObjectUtils.compare(action, other.action);