diff options
Diffstat (limited to 'models-pdp/src/main/java/org/onap')
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)); } |