X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-tosca%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fmodels%2Ftosca%2Fsimple%2Fconcepts%2FJpaToscaTimeInterval.java;h=e54f11900ae0177e5e6af19a1847e0619e9ff213;hb=938005505883cf7a636a8840e20e3dc8a0ad9176;hp=a62affddd32acbae2ea23463b9477626dd587900;hpb=b7909b8e74c0bc5920f5d0397a4371988df9e8b2;p=policy%2Fmodels.git diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java index a62affddd..e54f11900 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java @@ -2,8 +2,8 @@ * ============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. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,28 +24,25 @@ package org.onap.policy.models.tosca.simple.concepts; import com.google.gson.annotations.SerializedName; - -import java.util.Date; +import jakarta.persistence.EmbeddedId; +import jakarta.persistence.Entity; +import jakarta.persistence.Inheritance; +import jakarta.persistence.InheritanceType; +import jakarta.persistence.Table; +import java.io.Serial; +import java.sql.Timestamp; +import java.time.Instant; import java.util.List; - -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.onap.policy.common.utils.validation.Assertions; +import org.onap.policy.common.parameters.BeanValidationResult; +import org.onap.policy.common.parameters.annotations.NotNull; 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.PfUtils; -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 TimeInterval in TOSCA definition. @@ -60,16 +57,19 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult; @Data @EqualsAndHashCode(callSuper = false) public class JpaToscaTimeInterval extends PfConcept { + @Serial private static final long serialVersionUID = 9151467029611969980L; @EmbeddedId + @VerifyKey + @NotNull private PfReferenceKey key; @SerializedName("start_time") - private Date startTime; + private Timestamp startTime; @SerializedName("end_time") - private Date endTime; + private Timestamp endTime; /** * The Default Constructor creates a {@link JpaToscaTimeInterval} object with a null key. @@ -84,7 +84,7 @@ public class JpaToscaTimeInterval extends PfConcept { * @param key the key */ public JpaToscaTimeInterval(@NonNull final PfReferenceKey key) { - this(key, new Date(0), new Date(0)); + this(key, Instant.EPOCH, Instant.EPOCH); } /** @@ -92,11 +92,11 @@ public class JpaToscaTimeInterval extends PfConcept { * * @param key the key */ - public JpaToscaTimeInterval(@NonNull final PfReferenceKey key, @NonNull final Date startTime, - @NonNull final Date endTime) { + public JpaToscaTimeInterval(@NonNull final PfReferenceKey key, @NonNull final Instant startTime, + @NonNull final Instant endTime) { this.key = key; - this.startTime = startTime; - this.endTime = endTime; + this.startTime = Timestamp.from(startTime); + this.endTime = Timestamp.from(endTime); } /** @@ -106,6 +106,9 @@ public class JpaToscaTimeInterval extends PfConcept { */ public JpaToscaTimeInterval(final JpaToscaTimeInterval copyConcept) { super(copyConcept); + this.key = new PfReferenceKey(copyConcept.key); + this.startTime = copyConcept.startTime; + this.endTime = copyConcept.endTime; } @Override @@ -119,30 +122,19 @@ public class JpaToscaTimeInterval extends PfConcept { } @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); + public BeanValidationResult validate(@NonNull String fieldName) { + BeanValidationResult result = super.validate(fieldName); if (startTime == null || startTime.getTime() == 0) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "start time on time interval may not be null or zero")); + addResult(result, "startTime", startTime, "is null or zero"); } if (endTime == null || endTime.getTime() == 0) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "end time on time interval may not be null or zero")); + addResult(result, "endTime", endTime, "is null or zero"); } if (startTime != null && endTime != null && endTime.before(startTime)) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "end time \"" + endTime.toString() + "\" on time interval may not be before start time \"" - + startTime.toString() + "\"")); + addResult(result, "endTime", endTime, "is before startTime"); } return result; @@ -161,28 +153,16 @@ public class JpaToscaTimeInterval extends PfConcept { } final JpaToscaTimeInterval other = (JpaToscaTimeInterval) otherConcept; - if (!key.equals(other.key)) { - return key.compareTo(other.key); + int result = key.compareTo(other.key); + if (result != 0) { + return result; } - int returnVal = PfUtils.compareObjects(startTime, other.startTime); - if (returnVal != 0) { - return returnVal; + result = PfUtils.compareObjects(startTime, other.startTime); + if (result != 0) { + return result; } return PfUtils.compareObjects(endTime, other.endTime); } - - @Override - public PfConcept copyTo(@NonNull final PfConcept target) { - final Object copyObject = target; - Assertions.instanceOf(copyObject, JpaToscaTimeInterval.class); - - final JpaToscaTimeInterval copy = ((JpaToscaTimeInterval) copyObject); - copy.setKey(new PfReferenceKey(key)); - copy.setStartTime(startTime); - copy.setEndTime(endTime); - - return copy; - } }