update Db provider to support query number
[policy/models.git] / models-pdp / src / main / java / org / onap / policy / models / pdp / persistence / provider / PdpStatisticsProvider.java
index f149a36..3b17180 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Model
  * ================================================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -52,6 +52,7 @@ public class PdpStatisticsProvider {
 
     // Recurring string constants
     private static final String NOT_VALID = "\" is not valid \n";
+    private static final String DESC_ORDER = "DESC";
 
     /**
      * Get PDP statistics.
@@ -84,12 +85,14 @@ public class PdpStatisticsProvider {
      * @param pdpSubGroup pdpSubGroupType name to filter statistics
      * @param startTimeStamp startTimeStamp to filter statistics
      * @param endTimeStamp endTimeStamp to filter statistics
+     * @param sortOrder sortOrder to query database
+     * @param getRecordNum Total query count from database
      * @return the PDP statistics found
      * @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 Date endTimeStamp, final String sortOrder, final int getRecordNum) {
         Map<String, Object> filterMap = new HashMap<>();
         filterMap.put("pdpGroupName", pdpGroupName);
         if (pdpSubGroup != null) {
@@ -97,7 +100,7 @@ public class PdpStatisticsProvider {
         }
 
         return asPdpStatisticsList(dao.getFiltered(JpaPdpStatistics.class, name, PfKey.NULL_KEY_VERSION, startTimeStamp,
-                endTimeStamp, filterMap));
+                endTimeStamp, filterMap, sortOrder, getRecordNum));
     }
 
     /**
@@ -187,8 +190,8 @@ public class PdpStatisticsProvider {
      */
     public List<PdpStatistics> deletePdpStatistics(@NonNull final PfDao dao, @NonNull final String name,
             final Date timestamp) {
-        List<PdpStatistics> pdpStatisticsListToDel = asPdpStatisticsList(
-                dao.getFiltered(JpaPdpStatistics.class, name, PfKey.NULL_KEY_VERSION, timestamp, timestamp, null));
+        List<PdpStatistics> pdpStatisticsListToDel = asPdpStatisticsList(dao.getFiltered(JpaPdpStatistics.class, name,
+                PfKey.NULL_KEY_VERSION, timestamp, timestamp, null, DESC_ORDER, 0));
 
         pdpStatisticsListToDel.stream().forEach(s -> dao.delete(JpaPdpStatistics.class,
                 new PfTimestampKey(s.getPdpInstanceId(), PfKey.NULL_KEY_VERSION, s.getTimeStamp())));