* ============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.
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.
@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.
* @param key the key
*/
public JpaToscaTimeInterval(@NonNull final PfReferenceKey key) {
- this(key, new Date(0), new Date(0));
+ this(key, Instant.EPOCH, Instant.EPOCH);
}
/**
*
* @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);
}
/**
*/
public JpaToscaTimeInterval(final JpaToscaTimeInterval copyConcept) {
super(copyConcept);
+ this.key = new PfReferenceKey(copyConcept.key);
+ this.startTime = copyConcept.startTime;
+ this.endTime = copyConcept.endTime;
}
@Override
}
@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;
return 0;
}
if (getClass() != otherConcept.getClass()) {
- return this.hashCode() - otherConcept.hashCode();
+ return getClass().getName().compareTo(otherConcept.getClass().getName());
}
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;
- }
}