aboutsummaryrefslogtreecommitdiffstats
path: root/models-pdp/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-07-21 17:30:32 -0400
committerJim Hahn <jrh3@att.com>2021-07-23 13:05:11 -0400
commit1d3521c4106d5ad96df4e26d31d50cfdbc4148a7 (patch)
tree7cda2fd450dc97f9c928d13b2e5027e60431c181 /models-pdp/src/main
parent4f963eabf3d7b62122301a1901450298612dcf8f (diff)
Limit the number of statistics records returned
Added limit of MAX records (100). Also, if unspecified, or negative, it defaults to MAX records. Issue-ID: POLICY-3511 Change-Id: I0170951cd79818af5944adf5d29480bad4de815b Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-pdp/src/main')
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpFilterParameters.java2
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java30
2 files changed, 16 insertions, 16 deletions
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpFilterParameters.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpFilterParameters.java
index 6cede2c39..775c15452 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpFilterParameters.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpFilterParameters.java
@@ -24,6 +24,7 @@ import java.time.Instant;
import java.util.Map;
import lombok.Builder;
import lombok.Getter;
+import lombok.Setter;
import org.onap.policy.models.dao.PfFilterParametersIntfc;
@Getter
@@ -34,6 +35,7 @@ public class PdpFilterParameters implements PfFilterParametersIntfc {
private Instant startTime;
private Instant endTime;
+ @Setter
private int recordNum;
@Builder.Default
private String sortOrder = "DESC";
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 195f51f2d..8e3f0128e 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
@@ -46,6 +46,8 @@ import org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics;
* @author Ning Xi (ning.xi@est.tech)
*/
public class PdpStatisticsProvider {
+ private static final int DEFAULT_RECORD_COUNT = 10;
+ private static final int MAX_RECORD_COUNT = 100;
/**
* Get PDP statistics.
@@ -57,12 +59,8 @@ public class PdpStatisticsProvider {
*/
public List<PdpStatistics> getPdpStatistics(@NonNull final PfDao dao, final String name, final Instant timeStamp)
throws PfModelException {
- if (name != null && timeStamp != null) {
- return asPdpStatisticsList(dao.getByTimestamp(JpaPdpStatistics.class,
- new PfGeneratedIdKey(name, PfKey.NULL_KEY_VERSION), timeStamp));
- } else {
- return asPdpStatisticsList(dao.getAll(JpaPdpStatistics.class));
- }
+ return asPdpStatisticsList(dao.getFiltered(JpaPdpStatistics.class, PdpFilterParameters.builder().name(name)
+ .startTime(timeStamp).endTime(timeStamp).recordNum(MAX_RECORD_COUNT).build()));
}
/**
@@ -75,16 +73,8 @@ public class PdpStatisticsProvider {
*/
public List<PdpStatistics> getPdpStatistics(@NonNull final PfDao dao, final String name)
throws PfModelException {
-
- List<PdpStatistics> pdpStatistics = new ArrayList<>();
- if (name != null) {
- pdpStatistics
- .add(dao.get(JpaPdpStatistics.class, new PfGeneratedIdKey(name, PfKey.NULL_KEY_VERSION))
- .toAuthorative());
- } else {
- return asPdpStatisticsList(dao.getAll(JpaPdpStatistics.class));
- }
- return pdpStatistics;
+ return asPdpStatisticsList(dao.getFiltered(JpaPdpStatistics.class,
+ PdpFilterParameters.builder().name(name).recordNum(MAX_RECORD_COUNT).build()));
}
/**
@@ -97,6 +87,14 @@ public class PdpStatisticsProvider {
*/
public List<PdpStatistics> getFilteredPdpStatistics(@NonNull final PfDao dao,
PdpFilterParameters filterParams) {
+
+ if (filterParams.getRecordNum() <= 0) {
+ filterParams.setRecordNum(DEFAULT_RECORD_COUNT);
+
+ } else if (filterParams.getRecordNum() > MAX_RECORD_COUNT) {
+ filterParams.setRecordNum(MAX_RECORD_COUNT);
+ }
+
return asPdpStatisticsList(dao.getFiltered(JpaPdpStatistics.class, filterParams));
}