2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019-2021, 2023 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 jakarta.persistence.EmbeddedId;
28 import jakarta.persistence.Entity;
29 import jakarta.persistence.Inheritance;
30 import jakarta.persistence.InheritanceType;
31 import jakarta.persistence.Table;
32 import java.io.Serial;
33 import java.sql.Timestamp;
34 import java.time.Instant;
35 import java.util.List;
37 import lombok.EqualsAndHashCode;
38 import lombok.NonNull;
39 import org.onap.policy.common.parameters.BeanValidationResult;
40 import org.onap.policy.common.parameters.annotations.NotNull;
41 import org.onap.policy.models.base.PfConcept;
42 import org.onap.policy.models.base.PfKey;
43 import org.onap.policy.models.base.PfReferenceKey;
44 import org.onap.policy.models.base.PfUtils;
45 import org.onap.policy.models.base.validation.annotations.VerifyKey;
48 * Class to represent the TimeInterval in TOSCA definition.
50 * @author Chenfei Gao (cgao@research.att.com)
51 * @author Liam Fallon (liam.fallon@est.tech)
55 @Table(name = "ToscaTimeInterval")
56 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
58 @EqualsAndHashCode(callSuper = false)
59 public class JpaToscaTimeInterval extends PfConcept {
61 private static final long serialVersionUID = 9151467029611969980L;
66 private PfReferenceKey key;
68 @SerializedName("start_time")
69 private Timestamp startTime;
71 @SerializedName("end_time")
72 private Timestamp endTime;
75 * The Default Constructor creates a {@link JpaToscaTimeInterval} object with a null key.
77 public JpaToscaTimeInterval() {
78 this(new PfReferenceKey());
82 * The Key Constructor creates a {@link JpaToscaTimeInterval} object with the given concept key.
86 public JpaToscaTimeInterval(@NonNull final PfReferenceKey key) {
87 this(key, Instant.EPOCH, Instant.EPOCH);
91 * The full constructor creates a {@link JpaToscaTimeInterval} object with all fields.
95 public JpaToscaTimeInterval(@NonNull final PfReferenceKey key, @NonNull final Instant startTime,
96 @NonNull final Instant endTime) {
98 this.startTime = Timestamp.from(startTime);
99 this.endTime = Timestamp.from(endTime);
105 * @param copyConcept the concept to copy from
107 public JpaToscaTimeInterval(final JpaToscaTimeInterval copyConcept) {
109 this.key = new PfReferenceKey(copyConcept.key);
110 this.startTime = copyConcept.startTime;
111 this.endTime = copyConcept.endTime;
115 public List<PfKey> getKeys() {
116 return getKey().getKeys();
120 public void clean() {
125 public BeanValidationResult validate(@NonNull String fieldName) {
126 BeanValidationResult result = super.validate(fieldName);
128 if (startTime == null || startTime.getTime() == 0) {
129 addResult(result, "startTime", startTime, "is null or zero");
132 if (endTime == null || endTime.getTime() == 0) {
133 addResult(result, "endTime", endTime, "is null or zero");
136 if (startTime != null && endTime != null && endTime.before(startTime)) {
137 addResult(result, "endTime", endTime, "is before startTime");
144 public int compareTo(final PfConcept otherConcept) {
145 if (otherConcept == null) {
148 if (this == otherConcept) {
151 if (getClass() != otherConcept.getClass()) {
152 return getClass().getName().compareTo(otherConcept.getClass().getName());
155 final JpaToscaTimeInterval other = (JpaToscaTimeInterval) otherConcept;
156 int result = key.compareTo(other.key);
161 result = PfUtils.compareObjects(startTime, other.startTime);
166 return PfUtils.compareObjects(endTime, other.endTime);