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.sql.Timestamp;
28 import java.time.Instant;
29 import java.util.List;
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.onap.policy.common.parameters.BeanValidationResult;
39 import org.onap.policy.common.parameters.annotations.NotNull;
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.PfUtils;
44 import org.onap.policy.models.base.validation.annotations.VerifyKey;
47 * Class to represent the TimeInterval in TOSCA definition.
49 * @author Chenfei Gao (cgao@research.att.com)
50 * @author Liam Fallon (liam.fallon@est.tech)
54 @Table(name = "ToscaTimeInterval")
55 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
57 @EqualsAndHashCode(callSuper = false)
58 public class JpaToscaTimeInterval extends PfConcept {
59 private static final long serialVersionUID = 9151467029611969980L;
64 private PfReferenceKey key;
66 @SerializedName("start_time")
67 private Timestamp startTime;
69 @SerializedName("end_time")
70 private Timestamp endTime;
73 * The Default Constructor creates a {@link JpaToscaTimeInterval} object with a null key.
75 public JpaToscaTimeInterval() {
76 this(new PfReferenceKey());
80 * The Key Constructor creates a {@link JpaToscaTimeInterval} object with the given concept key.
84 public JpaToscaTimeInterval(@NonNull final PfReferenceKey key) {
85 this(key, Instant.EPOCH, Instant.EPOCH);
89 * The full constructor creates a {@link JpaToscaTimeInterval} object with all fields.
93 public JpaToscaTimeInterval(@NonNull final PfReferenceKey key, @NonNull final Instant startTime,
94 @NonNull final Instant endTime) {
96 this.startTime = Timestamp.from(startTime);
97 this.endTime = Timestamp.from(endTime);
103 * @param copyConcept the concept to copy from
105 public JpaToscaTimeInterval(final JpaToscaTimeInterval copyConcept) {
107 this.key = new PfReferenceKey(copyConcept.key);
108 this.startTime = copyConcept.startTime;
109 this.endTime = copyConcept.endTime;
113 public List<PfKey> getKeys() {
114 return getKey().getKeys();
118 public void clean() {
123 public BeanValidationResult validate(@NonNull String fieldName) {
124 BeanValidationResult result = super.validate(fieldName);
126 if (startTime == null || startTime.getTime() == 0) {
127 addResult(result, "startTime", startTime, "is null or zero");
130 if (endTime == null || endTime.getTime() == 0) {
131 addResult(result, "endTime", endTime, "is null or zero");
134 if (startTime != null && endTime != null && endTime.before(startTime)) {
135 addResult(result, "endTime", endTime, "is before startTime");
142 public int compareTo(final PfConcept otherConcept) {
143 if (otherConcept == null) {
146 if (this == otherConcept) {
149 if (getClass() != otherConcept.getClass()) {
150 return getClass().getName().compareTo(otherConcept.getClass().getName());
153 final JpaToscaTimeInterval other = (JpaToscaTimeInterval) otherConcept;
154 int result = key.compareTo(other.key);
159 result = PfUtils.compareObjects(startTime, other.startTime);
164 return PfUtils.compareObjects(endTime, other.endTime);