aboutsummaryrefslogtreecommitdiffstats
path: root/models-pdp
diff options
context:
space:
mode:
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>2021-02-16 16:25:18 +0000
committerrameshiyer27 <ramesh.murugan.iyer@est.tech>2021-02-19 15:26:11 +0000
commit5a94ebda407e82a8df4abea1b8a916ea4f88d9cd (patch)
tree9372cfd5e716196ddd1bf908d4da5db7e64f93c0 /models-pdp
parent7e4f9950ed004042e36e7e1f6f78224d62888e74 (diff)
Refactor timestamp property in policy models to use Instant
Updated JPA classes to use java.sql.TImestamp rather than Instant. Issue-ID: POLICY-3069 Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech> Change-Id: If5b874ec96931d4b8dd142d46a9980e83a4708fc
Diffstat (limited to 'models-pdp')
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java8
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java8
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java12
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpEngineWorkerStatisticsTest.java4
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpStatisticsTest.java6
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatisticsTest.java8
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProviderTest.java8
7 files changed, 27 insertions, 27 deletions
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java
index 1ba983be2..f7a0e7d91 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
package org.onap.policy.models.pdp.concepts;
-import java.util.Date;
+import java.time.Instant;
import java.util.List;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -39,7 +39,7 @@ import org.onap.policy.models.base.PfUtils;
public class PdpStatistics {
private String pdpInstanceId;
- private Date timeStamp;
+ private Instant timeStamp;
private String pdpGroupName;
private String pdpSubGroupName;
private long policyDeployCount;
@@ -57,7 +57,7 @@ public class PdpStatistics {
*/
public PdpStatistics(@NonNull PdpStatistics source) {
this.pdpInstanceId = source.pdpInstanceId;
- this.timeStamp = source.timeStamp == null ? null : new Date(source.timeStamp.getTime());
+ this.timeStamp = source.timeStamp;
this.pdpGroupName = source.pdpGroupName;
this.pdpSubGroupName = source.pdpSubGroupName;
this.policyDeployCount = source.policyDeployCount;
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java
index 90cf4e468..c3329cfa4 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +24,7 @@
package org.onap.policy.models.pdp.persistence.concepts;
import java.io.Serializable;
-import java.util.Date;
+import java.time.Instant;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
@@ -167,7 +167,7 @@ public class JpaPdpStatistics extends PfConcept implements PfAuthorative<PdpStat
public PdpStatistics toAuthorative() {
PdpStatistics pdpStatistics = new PdpStatistics();
pdpStatistics.setPdpInstanceId(key.getName());
- pdpStatistics.setTimeStamp(new Date(key.getTimeStamp().getTime()));
+ pdpStatistics.setTimeStamp(key.getInstant());
pdpStatistics.setPdpGroupName(pdpGroupName);
pdpStatistics.setPdpSubGroupName(pdpSubGroupName);
pdpStatistics.setPolicyDeployCount(policyDeployCount);
@@ -185,7 +185,7 @@ public class JpaPdpStatistics extends PfConcept implements PfAuthorative<PdpStat
public void fromAuthorative(@NonNull final PdpStatistics pdpStatistics) {
if (this.key == null || this.getKey().isNullKey()) {
this.setKey(new PfTimestampKey(pdpStatistics.getPdpInstanceId(), PfKey.NULL_KEY_VERSION,
- new Date(pdpStatistics.getTimeStamp() == null ? 0 : pdpStatistics.getTimeStamp().getTime())));
+ pdpStatistics.getTimeStamp() == null ? Instant.EPOCH : pdpStatistics.getTimeStamp()));
}
this.setPdpGroupName(pdpStatistics.getPdpGroupName());
this.setPdpSubGroupName(pdpStatistics.getPdpSubGroupName());
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java
index 7901246d7..e030d089d 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,8 +23,8 @@
package org.onap.policy.models.pdp.persistence.provider;
+import java.time.Instant;
import java.util.ArrayList;
-import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -58,7 +58,7 @@ public class PdpStatisticsProvider {
* @return the PDP statistics found
* @throws PfModelException on errors getting PDP statistics
*/
- public List<PdpStatistics> getPdpStatistics(@NonNull final PfDao dao, final String name, final Date timestamp)
+ public List<PdpStatistics> getPdpStatistics(@NonNull final PfDao dao, final String name, final Instant timestamp)
throws PfModelException {
List<PdpStatistics> pdpStatistics = new ArrayList<>();
@@ -87,8 +87,8 @@ public class PdpStatisticsProvider {
* @throws PfModelException on errors getting policies
*/
public List<PdpStatistics> getFilteredPdpStatistics(@NonNull final PfDao dao, final String name,
- @NonNull final String pdpGroupName, final String pdpSubGroup, final Date startTimeStamp,
- final Date endTimeStamp, final String sortOrder, final int getRecordNum) {
+ @NonNull final String pdpGroupName, final String pdpSubGroup, final Instant startTimeStamp,
+ final Instant endTimeStamp, final String sortOrder, final int getRecordNum) {
Map<String, Object> filterMap = new HashMap<>();
filterMap.put("pdpGroupName", pdpGroupName);
if (pdpSubGroup != null) {
@@ -181,7 +181,7 @@ public class PdpStatisticsProvider {
* @throws PfModelException on errors deleting PDP statistics
*/
public List<PdpStatistics> deletePdpStatistics(@NonNull final PfDao dao, @NonNull final String name,
- final Date timestamp) {
+ final Instant timestamp) {
List<PdpStatistics> pdpStatisticsListToDel = asPdpStatisticsList(dao.getFiltered(JpaPdpStatistics.class, name,
PfKey.NULL_KEY_VERSION, timestamp, timestamp, null, DESC_ORDER, 0));
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpEngineWorkerStatisticsTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpEngineWorkerStatisticsTest.java
index c0d2ba6bf..b748b915c 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpEngineWorkerStatisticsTest.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpEngineWorkerStatisticsTest.java
@@ -23,7 +23,7 @@ package org.onap.policy.models.pdp.concepts;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
-import java.util.Date;
+import java.time.Instant;
import org.junit.Test;
import org.onap.policy.models.pdp.enums.PdpEngineWorkerState;
@@ -50,7 +50,7 @@ public class PdpEngineWorkerStatisticsTest {
PdpEngineWorkerStatistics stat = new PdpEngineWorkerStatistics();
stat.setEngineId("Engine0");
stat.setEngineWorkerState(PdpEngineWorkerState.READY);
- stat.setEngineTimeStamp(new Date().getTime());
+ stat.setEngineTimeStamp(Instant.now().getEpochSecond());
stat.setEventCount(1);
stat.setLastExecutionTime(100);
stat.setAverageExecutionTime(99);
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpStatisticsTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpStatisticsTest.java
index adf9b9f7c..4c099e6b5 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpStatisticsTest.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpStatisticsTest.java
@@ -3,7 +3,7 @@
* ONAP Policy Models
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2021 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,8 +24,8 @@ package org.onap.policy.models.pdp.concepts;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
+import java.time.Instant;
import java.util.ArrayList;
-import java.util.Date;
import org.junit.Test;
public class PdpStatisticsTest {
@@ -44,7 +44,7 @@ public class PdpStatisticsTest {
pdpStat.setPdpInstanceId("PDP0");
pdpStat.setPdpGroupName("PDPGroup0");
pdpStat.setPdpSubGroupName("PDPSubGroup0");
- pdpStat.setTimeStamp(new Date());
+ pdpStat.setTimeStamp(Instant.EPOCH);
pdpStat.setPolicyDeployCount(3);
pdpStat.setPolicyDeploySuccessCount(1);
pdpStat.setPolicyDeployFailCount(2);
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatisticsTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatisticsTest.java
index 83cf85b8f..405425e2c 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatisticsTest.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatisticsTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,8 +28,8 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.time.Instant;
import java.util.ArrayList;
-import java.util.Date;
import org.junit.Test;
import org.onap.policy.models.base.PfTimestampKey;
import org.onap.policy.models.pdp.concepts.PdpStatistics;
@@ -114,7 +114,7 @@ public class JpaPdpStatisticsTest {
assertEquals(pdpStat.getPdpInstanceId(), jpaPdpStat.getKey().getName());
assertEquals(pdpStat.getPdpGroupName(), jpaPdpStat.getPdpGroupName());
assertEquals(pdpStat.getPdpSubGroupName(), jpaPdpStat.getPdpSubGroupName());
- assertEquals(pdpStat.getTimeStamp(), jpaPdpStat.getKey().getTimeStamp());
+ assertEquals(pdpStat.getTimeStamp(), jpaPdpStat.getKey().getInstant());
assertEquals(pdpStat.getPolicyDeployCount(), jpaPdpStat.getPolicyDeployCount());
assertEquals(pdpStat.getPolicyDeploySuccessCount(), jpaPdpStat.getPolicyDeploySuccessCount());
assertEquals(pdpStat.getPolicyDeployFailCount(), jpaPdpStat.getPolicyDeployFailCount());
@@ -128,7 +128,7 @@ public class JpaPdpStatisticsTest {
pdpStat.setPdpInstanceId("PDP0");
pdpStat.setPdpGroupName("PDPGroup0");
pdpStat.setPdpSubGroupName("PDPSubGroup0");
- pdpStat.setTimeStamp(new Date());
+ pdpStat.setTimeStamp(Instant.EPOCH);
pdpStat.setPolicyDeployCount(3);
pdpStat.setPolicyDeploySuccessCount(1);
pdpStat.setPolicyDeployFailCount(2);
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProviderTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProviderTest.java
index d8eeab44f..a418f81cf 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProviderTest.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProviderTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation.
+ * Copyright (C) 2020-2021 Nordix Foundation.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,8 +25,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
+import java.time.Instant;
import java.util.ArrayList;
-import java.util.Date;
import java.util.List;
import java.util.Properties;
import org.eclipse.persistence.config.PersistenceUnitProperties;
@@ -48,8 +48,8 @@ public class PdpStatisticsProviderTest {
private static final String NAME = "name";
private static final String GROUP = "group";
private static final String SUBGROUP = "subgroup";
- private static final Date TIMESTAMP1 = new Date(1078884319);
- private static final Date TIMESTAMP2 = new Date(1078884350);
+ private static final Instant TIMESTAMP1 = Instant.ofEpochSecond(1078884319);
+ private static final Instant TIMESTAMP2 = Instant.ofEpochSecond(1078884350);
private static final String ORDER = "DESC";
private PfDao pfDao;