Convert Date to Instant in TOSCA PoC 48/118148/2
authorliamfallon <liam.fallon@est.tech>
Mon, 22 Feb 2021 08:57:47 +0000 (08:57 +0000)
committerliamfallon <liam.fallon@est.tech>
Mon, 22 Feb 2021 09:01:02 +0000 (09:01 +0000)
Issue-ID: POLICY-3069
Change-Id: I9efbc42c4fcc97f79799f3e09ed3424dcc86a891
Signed-off-by: liamfallon <liam.fallon@est.tech>
12 files changed:
tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatistics.java
tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatistics.java
tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatistics.java
tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatistics.java
tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProvider.java
tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProvider.java
tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsTest.java
tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsTest.java
tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java
tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatisticsTest.java
tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProviderTest.java
tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProviderTest.java

index 1e264ef..ec96830 100644 (file)
@@ -21,7 +21,7 @@
 package org.onap.policy.clamp.controlloop.models.controlloop.concepts;
 
 import java.io.Serializable;
-import java.util.Date;
+import java.time.Instant;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.NonNull;
@@ -39,7 +39,7 @@ public class ClElementStatistics implements Serializable {
     private ToscaConceptIdentifier controlLoopElementId;
 
     @NonNull
-    private Date timeStamp;
+    private Instant timeStamp;
 
     @NonNull
     private ControlLoopState controlLoopState;
index 0b895d4..3a7b21f 100644 (file)
@@ -21,7 +21,7 @@
 package org.onap.policy.clamp.controlloop.models.controlloop.concepts;
 
 import java.io.Serializable;
-import java.util.Date;
+import java.time.Instant;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.NonNull;
@@ -39,7 +39,7 @@ public class ParticipantStatistics implements Serializable {
     private ToscaConceptIdentifier participantId;
 
     @NonNull
-    private Date timeStamp;
+    private Instant timeStamp;
 
     private ParticipantState state;
     private ParticipantHealthStatus healthStatus;
index badf020..abe0737 100644 (file)
 package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts;
 
 import java.io.Serializable;
-import java.util.Date;
 import java.util.List;
 import javax.persistence.AttributeOverride;
-import javax.persistence.AttributeOverrides;
 import javax.persistence.Column;
 import javax.persistence.EmbeddedId;
 import javax.persistence.Entity;
@@ -70,10 +68,8 @@ public class JpaClElementStatistics extends PfConcept implements PfAuthorative<C
     @VerifyKey
     @NotNull
     // @formatter:off
-    @AttributeOverrides({
-        @AttributeOverride(name = "name", column = @Column(name = "cl_element_name")),
-        @AttributeOverride(name = "version", column = @Column(name = "cl_element_version"))
-    })
+    @AttributeOverride(name = "name", column = @Column(name = "cl_element_name"))
+    @AttributeOverride(name = "version", column = @Column(name = "cl_element_version"))
     private PfConceptKey clElementId;
     // @formatter: on
 
@@ -127,12 +123,10 @@ public class JpaClElementStatistics extends PfConcept implements PfAuthorative<C
         this.fromAuthorative(authorativeConcept);
     }
 
-
-
     @Override
     public ClElementStatistics toAuthorative() {
         ClElementStatistics clElementStatistics = new ClElementStatistics();
-        clElementStatistics.setTimeStamp(new Date(key.getTimeStamp().getTime()));
+        clElementStatistics.setTimeStamp(key.getTimeStamp().toInstant());
         clElementStatistics.setControlLoopElementId(new ToscaConceptIdentifier(clElementId));
         clElementStatistics.setControlLoopState(state);
         clElementStatistics.setClElementUptime(clElementUptime);
index 1877d98..84c7f0d 100644 (file)
 package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts;
 
 import java.io.Serializable;
-import java.util.Date;
 import java.util.List;
 import javax.persistence.AttributeOverride;
-import javax.persistence.AttributeOverrides;
 import javax.persistence.Column;
 import javax.persistence.EmbeddedId;
 import javax.persistence.Entity;
@@ -60,8 +58,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 @Data
 @AllArgsConstructor
 @EqualsAndHashCode(callSuper = false)
-public class JpaParticipantStatistics extends PfConcept
-    implements PfAuthorative<ParticipantStatistics>, Serializable {
+public class JpaParticipantStatistics extends PfConcept implements PfAuthorative<ParticipantStatistics>, Serializable {
 
     private static final long serialVersionUID = -5992214428190133190L;
 
@@ -72,11 +69,8 @@ public class JpaParticipantStatistics extends PfConcept
 
     @VerifyKey
     @NotNull
-    @AttributeOverrides({
-        @AttributeOverride(name = "name",    column = @Column(name = "participant_name")),
-        @AttributeOverride(name = "version", column = @Column(name = "participant_version"))
-        }
-    )
+    @AttributeOverride(name = "name", column = @Column(name = "participant_name"))
+    @AttributeOverride(name = "version", column = @Column(name = "participant_version"))
     private PfConceptKey participantId;
 
     @Column
@@ -119,8 +113,8 @@ public class JpaParticipantStatistics extends PfConcept
      * @param key the key
      */
     public JpaParticipantStatistics(@NonNull final PfTimestampKey key) {
-        this(key, new PfConceptKey(), ParticipantState.PASSIVE, ParticipantHealthStatus.HEALTHY, 0L, 0L,
-            0.0d, 0L, 0L, 0L);
+        this(key, new PfConceptKey(), ParticipantState.PASSIVE, ParticipantHealthStatus.HEALTHY, 0L, 0L, 0.0d, 0L, 0L,
+                0L);
     }
 
 
@@ -196,7 +190,7 @@ public class JpaParticipantStatistics extends PfConcept
     @Override
     public ParticipantStatistics toAuthorative() {
         ParticipantStatistics participantStatistics = new ParticipantStatistics();
-        participantStatistics.setTimeStamp(new Date(key.getTimeStamp().getTime()));
+        participantStatistics.setTimeStamp(key.getTimeStamp().toInstant());
         participantStatistics.setParticipantId(new ToscaConceptIdentifier(participantId));
         participantStatistics.setState(state);
         participantStatistics.setHealthStatus(healthStatus);
@@ -214,8 +208,7 @@ public class JpaParticipantStatistics extends PfConcept
     public void fromAuthorative(@NonNull final ParticipantStatistics participantStatistics) {
         if (this.key == null || this.getKey().isNullKey()) {
             this.setKey(new PfTimestampKey(participantStatistics.getParticipantId().getName(),
-                participantStatistics.getParticipantId().getVersion(),
-                participantStatistics.getTimeStamp()));
+                    participantStatistics.getParticipantId().getVersion(), participantStatistics.getTimeStamp()));
         }
         this.setParticipantId(participantStatistics.getParticipantId().asConceptKey());
         this.setState(participantStatistics.getState());
@@ -241,4 +234,4 @@ public class JpaParticipantStatistics extends PfConcept
         key.clean();
         participantId.clean();
     }
-}
\ No newline at end of file
+}
index b1cdf62..1250dfc 100644 (file)
@@ -20,8 +20,8 @@
 
 package org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider;
 
+import java.time.Instant;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -115,7 +115,7 @@ public class ClElementStatisticsProvider extends AbstractModelsProvider {
      * @throws PfModelException on errors getting clElement statistics
      */
     public List<ClElementStatistics> getClElementStatistics(final String name, final String version,
-            final Date timestamp) throws PfModelException {
+            final Instant timestamp) throws PfModelException {
 
         if (name != null && version != null && timestamp != null) {
             List<ClElementStatistics> clElementStatistics = new ArrayList<>(1);
@@ -139,8 +139,8 @@ public class ClElementStatisticsProvider extends AbstractModelsProvider {
      * @throws PfModelException on errors getting policies
      */
     public List<ClElementStatistics> getFilteredClElementStatistics(final String name, final String version,
-            final Date startTimeStamp, final Date endTimeStamp, Map<String, Object> filterMap, final String sortOrder,
-            final int getRecordNum) {
+            final Instant startTimeStamp, final Instant endTimeStamp, Map<String, Object> filterMap,
+            final String sortOrder, final int getRecordNum) {
         return asClElementStatisticsList(getPfDao().getFiltered(JpaClElementStatistics.class, name, version,
                 startTimeStamp, endTimeStamp, filterMap, sortOrder, getRecordNum));
     }
index 5a0bb01..3cbe901 100644 (file)
@@ -20,8 +20,8 @@
 
 package org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider;
 
+import java.time.Instant;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -62,7 +62,7 @@ public class ParticipantStatisticsProvider extends AbstractModelsProvider {
      * @throws PfModelException on errors getting participant statistics
      */
     public List<ParticipantStatistics> getParticipantStatistics(final String name, final String version,
-            final Date timestamp) throws PfModelException {
+            final Instant timestamp) throws PfModelException {
 
         if (name != null && version != null && timestamp != null) {
             List<ParticipantStatistics> participantStatistics = new ArrayList<>(1);
@@ -87,8 +87,8 @@ public class ParticipantStatisticsProvider extends AbstractModelsProvider {
      * @throws PfModelException on errors getting policies
      */
     public List<ParticipantStatistics> getFilteredParticipantStatistics(final String name, final String version,
-            final Date startTimeStamp, final Date endTimeStamp, Map<String, Object> filterMap, final String sortOrder,
-            final int getRecordNum) {
+            final Instant startTimeStamp, final Instant endTimeStamp, Map<String, Object> filterMap,
+            final String sortOrder, final int getRecordNum) {
 
         return asParticipantStatisticsList(getPfDao().getFiltered(JpaParticipantStatistics.class, name, version,
                 startTimeStamp, endTimeStamp, filterMap, sortOrder, getRecordNum));
index 1fd304b..5318fcf 100644 (file)
@@ -26,7 +26,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 
-import java.util.Date;
+import java.time.Instant;
 import org.junit.Test;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 
@@ -44,7 +44,7 @@ public class ClElementStatisticsTest {
 
         ClElementStatistics cles1 = new ClElementStatistics();
         cles1.setControlLoopElementId(new ToscaConceptIdentifier("defName", "0.0.1"));
-        cles1.setTimeStamp(new Date(System.currentTimeMillis()));
+        cles1.setTimeStamp(Instant.now());
 
         assertThat(cles1.toString()).contains("ClElementStatistics(");
         assertEquals(false, cles1.hashCode() == 0);
index 6f69136..54eaca0 100644 (file)
@@ -26,7 +26,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 
-import java.util.Date;
+import java.time.Instant;
 import org.junit.Test;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 
@@ -44,7 +44,7 @@ public class ParticipantStatisticsTest {
 
         ParticipantStatistics ps1 = new ParticipantStatistics();
         ps1.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1"));
-        ps1.setTimeStamp(new Date(System.currentTimeMillis()));
+        ps1.setTimeStamp(Instant.now());
 
         assertThat(ps1.toString()).contains("ParticipantStatistics(");
         assertEquals(false, ps1.hashCode() == 0);
index 6f0b485..5c41d96 100644 (file)
@@ -27,7 +27,7 @@ import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Date;
+import java.time.Instant;
 import org.junit.Test;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
@@ -91,7 +91,7 @@ public class JpaClElementStatisticsTest {
         testJpaClElementStatisticsFa.setKey(PfTimestampKey.getNullKey());
         testJpaClElementStatisticsFa.fromAuthorative(cles);
         assertEquals(testJpaClElementStatistics, testJpaClElementStatisticsFa);
-        testJpaClElementStatisticsFa.setKey(new PfTimestampKey("elementName", "0.0.1", new Date(123456L)));
+        testJpaClElementStatisticsFa.setKey(new PfTimestampKey("elementName", "0.0.1", Instant.ofEpochMilli(123456L)));
         testJpaClElementStatisticsFa.fromAuthorative(cles);
         assertEquals(testJpaClElementStatistics, testJpaClElementStatisticsFa);
 
@@ -178,7 +178,7 @@ public class JpaClElementStatisticsTest {
     private ClElementStatistics createClElementStatisticsInstance() {
         ClElementStatistics clElementStatistics = new ClElementStatistics();
         clElementStatistics.setControlLoopElementId(new ToscaConceptIdentifier("elementName", "0.0.1"));
-        clElementStatistics.setTimeStamp(new Date(123456L));
+        clElementStatistics.setTimeStamp(Instant.ofEpochMilli(123456L));
         clElementStatistics.setControlLoopState(ControlLoopState.UNINITIALISED);
 
         return clElementStatistics;
index 464e97c..7eedd24 100644 (file)
@@ -27,7 +27,7 @@ import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Date;
+import java.time.Instant;
 import org.junit.Test;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus;
@@ -93,7 +93,8 @@ public class JpaParticipantStatisticsTest {
         testJpaParticipantStatisticsFa.setKey(PfTimestampKey.getNullKey());
         testJpaParticipantStatisticsFa.fromAuthorative(cles);
         assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa);
-        testJpaParticipantStatisticsFa.setKey(new PfTimestampKey("participantName", "0.0.1", new Date(123456L)));
+        testJpaParticipantStatisticsFa
+                .setKey(new PfTimestampKey("participantName", "0.0.1", Instant.ofEpochMilli(123456L)));
         testJpaParticipantStatisticsFa.fromAuthorative(cles);
         assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa);
 
@@ -183,7 +184,7 @@ public class JpaParticipantStatisticsTest {
     private ParticipantStatistics createParticipantStatisticsInstance() {
         ParticipantStatistics participantStatistics = new ParticipantStatistics();
         participantStatistics.setParticipantId(new ToscaConceptIdentifier("participantName", "0.0.1"));
-        participantStatistics.setTimeStamp(new Date(123456L));
+        participantStatistics.setTimeStamp(Instant.ofEpochMilli(123456L));
         participantStatistics.setState(ParticipantState.PASSIVE);
         participantStatistics.setHealthStatus(ParticipantHealthStatus.HEALTHY);
 
index c6304a0..1d2b991 100644 (file)
@@ -24,7 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 
-import java.util.Date;
+import java.time.Instant;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 import org.junit.After;
@@ -102,9 +102,9 @@ public class ClElementStatisticsProviderTest {
             .getClElementStatistics());
         ToscaConceptIdentifier identifier = inputClElementStats.getClElementStatistics().get(0)
             .getControlLoopElementId();
-        Date date = inputClElementStats.getClElementStatistics().get(0).getTimeStamp();
+        Instant instant = inputClElementStats.getClElementStatistics().get(0).getTimeStamp();
         assertEquals(1, clElementStatisticsProvider.getClElementStatistics(identifier.getName(),
-            identifier.getVersion(), date).size());
+            identifier.getVersion(), instant).size());
 
         assertEquals(1, clElementStatisticsProvider.getFilteredClElementStatistics("name2",
             "1.0.1", null, null, null,
index 3a4905b..d4bc977 100644 (file)
@@ -24,7 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 
-import java.util.Date;
+import java.time.Instant;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 import org.junit.After;
@@ -99,9 +99,9 @@ public class ParticipantStatisticsProviderTest {
 
         participantStatisticsProvider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList());
         ToscaConceptIdentifier identifier = inputParticipantStatistics.getStatisticsList().get(0).getParticipantId();
-        Date date = inputParticipantStatistics.getStatisticsList().get(0).getTimeStamp();
+        Instant instant = inputParticipantStatistics.getStatisticsList().get(0).getTimeStamp();
         assertEquals(1, participantStatisticsProvider
-                .getParticipantStatistics(identifier.getName(), identifier.getVersion(), date).size());
+                .getParticipantStatistics(identifier.getName(), identifier.getVersion(), instant).size());
 
         assertEquals(1, participantStatisticsProvider
                 .getFilteredParticipantStatistics("name2", "1.0.1", null, null, null, "DESC", 1).size());