import java.time.Instant;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.stream.Collectors;
import javax.ws.rs.core.Response;
import lombok.NonNull;
* @author Ning Xi (ning.xi@est.tech)
*/
public class PdpStatisticsProvider {
-
- /**
- * Get PDP statistics.
- *
- * @param dao the DAO to use to access the database
- * @param name the name of the PDP statistics to get, null to get all PDPs
- * @return the PDP statistics found
- * @throws PfModelException on errors getting PDP statistics
- */
- 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));
- }
- }
-
- /**
- * Get PDP statistics.
- *
- * @param dao the DAO to use to access the database
- * @param name the name of the PDP statistics to get, null to get all PDPs
- * @return the PDP statistics found
- * @throws PfModelException on errors getting PDP statistics
- */
- 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;
- }
-
- /**
- * Get filtered PDP statistics.
- *
- * @param dao the DAO to use to access the database
- * @param name the pdpInstance name for the PDP statistics to get
- * @param pdpGroupName pdpGroupName to filter statistics
- * @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 Instant startTimeStamp,
- final Instant endTimeStamp, final String sortOrder, final int getRecordNum) {
- Map<String, Object> filterMap = new HashMap<>();
- filterMap.put("pdpGroupName", pdpGroupName);
- if (pdpSubGroup != null) {
- filterMap.put("pdpSubGroupName", pdpSubGroup);
- }
-
- // @formatter:off
- return asPdpStatisticsList(
- dao.getFiltered(JpaPdpStatistics.class,
- PdpFilterParameters.builder()
- .name(name)
- .startTime(startTimeStamp)
- .endTime(endTimeStamp)
- .group(pdpGroupName)
- .subGroup(pdpSubGroup)
- .sortOrder(sortOrder)
- .recordNum(getRecordNum)
- .build()));
- // @formatter:on
- }
+ private static final int DEFAULT_RECORD_COUNT = 10;
+ private static final int MAX_RECORD_COUNT = 100;
/**
* Get filtered PDP statistics.
*/
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));
}