diff options
4 files changed, 37 insertions, 29 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java index 06af688b0..1a29c8b01 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,13 +21,15 @@ package org.onap.policy.models.base; -import java.sql.Timestamp; import java.time.Instant; import java.util.Collections; +import java.util.Date; import java.util.List; import javax.persistence.Column; import javax.persistence.Embeddable; import javax.persistence.Embedded; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; @@ -41,15 +44,16 @@ import org.onap.policy.common.utils.validation.Assertions; @Embeddable @Data -@EqualsAndHashCode +@EqualsAndHashCode(callSuper = false) public class PfReferenceTimestampKey extends PfKey { private static final long serialVersionUID = 1130918285832617215L; private static final String TIMESTAMP_TOKEN = "timeStamp"; @Column(name = TIMESTAMP_TOKEN) + @Temporal(TemporalType.TIMESTAMP) @NotNull - private Timestamp timeStamp; + private Date timeStamp; @Embedded @Column @@ -60,7 +64,7 @@ public class PfReferenceTimestampKey extends PfKey { */ public PfReferenceTimestampKey() { this.referenceKey = new PfReferenceKey(); - this.timeStamp = new Timestamp(0); + this.timeStamp = new Date(0); } /** @@ -82,7 +86,7 @@ public class PfReferenceTimestampKey extends PfKey { */ public PfReferenceTimestampKey(final PfConceptKey pfConceptKey) { this.referenceKey = new PfReferenceKey(pfConceptKey); - this.timeStamp = new Timestamp(0); + this.timeStamp = new Date(0); } /** @@ -97,7 +101,7 @@ public class PfReferenceTimestampKey extends PfKey { */ public PfReferenceTimestampKey(final PfConceptKey pfConceptKey, final String localName, final Instant instant) { this.referenceKey = new PfReferenceKey(pfConceptKey, localName); - this.timeStamp = Timestamp.from(instant); + this.timeStamp = Date.from(instant); } /** @@ -113,7 +117,7 @@ public class PfReferenceTimestampKey extends PfKey { public PfReferenceTimestampKey(final PfReferenceKey parentReferenceKey, final String localName, final Instant instant) { this.referenceKey = new PfReferenceKey(parentReferenceKey, localName); - this.timeStamp = Timestamp.from(instant); + this.timeStamp = Date.from(instant); } /** @@ -132,7 +136,7 @@ public class PfReferenceTimestampKey extends PfKey { public PfReferenceTimestampKey(final PfConceptKey pfConceptKey, final String parentLocalName, final String localName, final Instant instant) { this.referenceKey = new PfReferenceKey(pfConceptKey, parentLocalName, localName); - this.timeStamp = Timestamp.from(instant); + this.timeStamp = Date.from(instant); } /** @@ -151,7 +155,7 @@ public class PfReferenceTimestampKey extends PfKey { public PfReferenceTimestampKey(final String parentKeyName, final String parentKeyVersion, final String localName, final Instant instant) { this.referenceKey = new PfReferenceKey(parentKeyName, parentKeyVersion, PfKey.NULL_KEY_NAME, localName); - this.timeStamp = Timestamp.from(instant); + this.timeStamp = Date.from(instant); } /** @@ -172,7 +176,7 @@ public class PfReferenceTimestampKey extends PfKey { public PfReferenceTimestampKey(final String parentKeyName, final String parentKeyVersion, final String parentLocalName, final String localName, final Instant instant) { this.referenceKey = new PfReferenceKey(parentKeyName, parentKeyVersion, parentLocalName, localName); - this.timeStamp = Timestamp.from(instant); + this.timeStamp = Date.from(instant); } @@ -183,7 +187,7 @@ public class PfReferenceTimestampKey extends PfKey { */ public PfReferenceTimestampKey(final String id) { this.referenceKey = new PfReferenceKey(id.substring(0, id.lastIndexOf(':'))); - this.timeStamp = new Timestamp(Long.parseLong(id.substring(id.lastIndexOf(':') + 1))); + this.timeStamp = new Date(Long.parseLong(id.substring(id.lastIndexOf(':') + 1))); } @@ -202,7 +206,7 @@ public class PfReferenceTimestampKey extends PfKey { } public void setInstant(final Instant instant) { - setTimeStamp(Timestamp.from(instant)); + setTimeStamp(Date.from(instant)); } /** diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java index 22d29f745..6e2271846 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java @@ -3,7 +3,7 @@ * ONAP Policy Model * ================================================================================ * Copyright (C) 2019-2021 Nordix Foundation. - * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,10 +23,12 @@ package org.onap.policy.models.base; -import java.sql.Timestamp; import java.time.Instant; +import java.util.Date; import javax.persistence.Column; import javax.persistence.Embeddable; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; @@ -50,8 +52,9 @@ public class PfTimestampKey extends PfKeyImpl { private String version; @Column(name = TIMESTAMP_TOKEN) + @Temporal(TemporalType.TIMESTAMP) @NonNull - private Timestamp timeStamp; + private Date timeStamp; /** @@ -81,7 +84,7 @@ public class PfTimestampKey extends PfKeyImpl { public PfTimestampKey(@NonNull final String name, @NonNull final String version, @NonNull final Instant instant) { super(name, version); - this.timeStamp = Timestamp.from(instant); + this.timeStamp = Date.from(instant); } /** @@ -91,7 +94,7 @@ public class PfTimestampKey extends PfKeyImpl { */ public PfTimestampKey(final String id) { super(id.substring(0, id.lastIndexOf(':'))); - this.timeStamp = new Timestamp(Long.parseLong(id.substring(id.lastIndexOf(':') + 1))); + this.timeStamp = new Date(Long.parseLong(id.substring(id.lastIndexOf(':') + 1))); } @Override @@ -113,7 +116,7 @@ public class PfTimestampKey extends PfKeyImpl { } public void setInstant(final Instant instant) { - setTimeStamp(Timestamp.from(instant)); + setTimeStamp(Date.from(instant)); } @Override diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceTimestampKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceTimestampKeyTest.java index 12b9e3509..4865eb904 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceTimestampKeyTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceTimestampKeyTest.java @@ -28,8 +28,8 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import java.sql.Timestamp; import java.time.Instant; +import java.util.Date; import org.junit.Test; public class PfReferenceTimestampKeyTest { @@ -51,7 +51,7 @@ public class PfReferenceTimestampKeyTest { assertEquals(LOCAL_NAME, new PfReferenceTimestampKey(new PfReferenceKey(), LOCAL_NAME, Instant.ofEpochSecond(timeStamp)) .getReferenceKey().getLocalName()); - assertEquals(Timestamp.from(Instant.ofEpochSecond(timeStamp)), new PfReferenceTimestampKey(new PfConceptKey(), + assertEquals(Date.from(Instant.ofEpochSecond(timeStamp)), new PfReferenceTimestampKey(new PfConceptKey(), PARENT_LOCAL_NAME, LOCAL_NAME, Instant.ofEpochSecond(timeStamp)).getTimeStamp()); assertThat(new PfReferenceTimestampKey("ParentKeyName", VERSION001, PARENT_LOCAL_NAME, LOCAL_NAME, @@ -99,8 +99,8 @@ public class PfReferenceTimestampKeyTest { testReferenceKey.getReferenceKey().setLocalName("LN"); assertEquals("LN", testReferenceKey.getReferenceKey().getLocalName()); - testReferenceKey.setTimeStamp(Timestamp.from(DEFAULT_TIMESTAMP)); - assertEquals(Timestamp.from(DEFAULT_TIMESTAMP), testReferenceKey.getTimeStamp()); + testReferenceKey.setTimeStamp(Date.from(DEFAULT_TIMESTAMP)); + assertEquals(Date.from(DEFAULT_TIMESTAMP), testReferenceKey.getTimeStamp()); assertThatThrownBy(() -> testReferenceKey.isCompatible(null)) @@ -116,7 +116,7 @@ public class PfReferenceTimestampKeyTest { PfReferenceTimestampKey clonedReferenceKey = new PfReferenceTimestampKey(testReferenceKey); - assertEquals("PfReferenceTimestampKey(timeStamp=" + Timestamp.from(Instant.EPOCH) + "," + assertEquals("PfReferenceTimestampKey(timeStamp=" + Date.from(Instant.EPOCH) + "," + " referenceKey=PfReferenceKey(parentKeyName=PKN, parentKeyVersion=0.0.1, " + "parentLocalName=ParentLocalName, localName=LN))", clonedReferenceKey.toString()); @@ -125,7 +125,7 @@ public class PfReferenceTimestampKeyTest { assertEquals(testReferenceKey, clonedReferenceKey); assertNotEquals(testReferenceKey, new PfReferenceTimestampKey("PKN", VERSION001, "PLN", "LN", Instant.ofEpochSecond(timeStamp))); - testReferenceKey.setTimeStamp(Timestamp.from(Instant.ofEpochSecond(timeStamp))); + testReferenceKey.setTimeStamp(Date.from(Instant.ofEpochSecond(timeStamp))); assertEquals(testReferenceKey, new PfReferenceTimestampKey("PKN", VERSION001, PARENT_LOCAL_NAME, "LN", Instant.ofEpochSecond(timeStamp))); @@ -152,7 +152,7 @@ public class PfReferenceTimestampKeyTest { assertThatThrownBy(() -> key1.isNewerThan((PfKey) null)).isInstanceOf(NullPointerException.class) .hasMessageMatching("^otherKey is marked .*on.*ull but is null$"); - key2.setTimeStamp(Timestamp.from(Instant.ofEpochSecond(timeStamp).plusSeconds(80))); + key2.setTimeStamp(Date.from(Instant.ofEpochSecond(timeStamp).plusSeconds(80))); assertTrue(key2.isNewerThan(key1)); } diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java index e6a998894..4afdadff3 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2021 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +26,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import java.sql.Timestamp; import java.time.Instant; +import java.util.Date; import org.junit.Test; public class PfTimestampKeyTest { @@ -41,7 +42,7 @@ public class PfTimestampKeyTest { PfTimestampKey someKey0 = new PfTimestampKey(); assertEquals(PfTimestampKey.getNullKey(), someKey0); assertTrue(someKey0.isNullKey()); - assertEquals("PfTimestampKey(name=NULL, version=0.0.0, timeStamp=" + Timestamp.from(Instant.EPOCH) + ")", + assertEquals("PfTimestampKey(name=NULL, version=0.0.0, timeStamp=" + Date.from(Instant.EPOCH) + ")", someKey0.toString()); PfTimestampKey someKey1 = new PfTimestampKey("my-name", VERSION001, Instant.ofEpochSecond(timeStamp)); @@ -51,7 +52,7 @@ public class PfTimestampKeyTest { assertEquals(someKey1, someKey3); assertFalse(someKey1.isNullVersion()); assertEquals("PfTimestampKey(name=my-name, version=0.0.1, timeStamp=" - + Timestamp.from(Instant.ofEpochSecond(timeStamp)) + ")", someKey1.toString()); + + Date.from(Instant.ofEpochSecond(timeStamp)) + ")", someKey1.toString()); assertEquals("my-name", someKey1.getName()); assertEquals(VERSION001, someKey1.getVersion()); @@ -79,7 +80,7 @@ public class PfTimestampKeyTest { assertFalse(someKey1.isNewerThan(someKey2)); assertThatThrownBy(() -> someKey1.isNewerThan((PfKey) null)).isInstanceOf(NullPointerException.class) .hasMessageMatching("^otherKey is marked .*on.*ull but is null$"); - someKey2.setTimeStamp(Timestamp.from(Instant.ofEpochSecond(timeStamp).plusMillis(90))); + someKey2.setTimeStamp(Date.from(Instant.ofEpochSecond(timeStamp).plusMillis(90))); assertTrue(someKey2.isNewerThan(someKey1)); someKey3.setName("my-name3"); assertTrue(someKey3.isNewerThan(someKey1)); |