/*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019-2020 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ *  Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
     private static final Logger LOGGER = LoggerFactory.getLogger(StatisticsRestControllerV1.class);
     private static final String GET_STATISTICS_ERR_MSG = "get pdpStatistics failed";
-    private static final int NO_COUNT_LIMIT = 0;
 
     /**
      * get statistics of PAP.
             @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
             @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
     public Response pdpStatistics(
-            @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId) {
+            @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
+            @ApiParam(value = "Record Count",
+                    required = false) @DefaultValue("0") @QueryParam("recordCount") final int recordCount) {
         try {
             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
-                    .entity(new StatisticsRestProvider().fetchDatabaseStatistics(null, null, null, NO_COUNT_LIMIT))
+                    .entity(new StatisticsRestProvider().fetchDatabaseStatistics(null, null, null, recordCount))
                     .build();
         } catch (final PfModelException exp) {
             LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
             @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
     public Response pdpGroupStatistics(
             @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
-            @ApiParam(value = "PDP Group Name", required = true) @PathParam("group") final String groupName) {
+            @ApiParam(value = "PDP Group Name", required = true) @PathParam("group") final String groupName,
+            @ApiParam(value = "Record Count",
+                    required = false) @DefaultValue("0") @QueryParam("recordCount") final int recordCount) {
         try {
             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
-                    .entity(new StatisticsRestProvider().fetchDatabaseStatistics(groupName, null, null, NO_COUNT_LIMIT))
+                    .entity(new StatisticsRestProvider().fetchDatabaseStatistics(groupName, null, null, recordCount))
                     .build();
         } catch (final PfModelException exp) {
             LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
     public Response pdpSubGroupStatistics(
             @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
             @ApiParam(value = "PDP Group Name", required = true) @PathParam("group") final String groupName,
-            @ApiParam(value = "PDP SubGroup type", required = true) @PathParam("type") final String subType) {
+            @ApiParam(value = "PDP SubGroup type", required = true) @PathParam("type") final String subType,
+            @ApiParam(value = "Record Count",
+                    required = false) @DefaultValue("0") @QueryParam("recordCount") final int recordCount) {
         try {
             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
                     .entity(new StatisticsRestProvider().fetchDatabaseStatistics(groupName, subType, null,
-                            NO_COUNT_LIMIT))
+                                    recordCount))
                     .build();
         } catch (final PfModelException exp) {
             LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
 
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2020-2021 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ *  Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
     private static final Logger LOGGER = LoggerFactory.getLogger(StatisticsRestProvider.class);
     private static final String GET_STATISTICS_ERR_MSG = "fetch database failed";
     private static final String DESC_ORDER = "DESC";
+    private static final String DEFAULT_GROUP = "defaultGroup";
+    private static final int MIN_RECORD_COUNT = 1;
+    private static final int MAX_RECORD_COUNT = 100;
 
     /**
      * Returns the current statistics of pap component.
             String pdpName, int recordCount) throws PfModelException {
         final PolicyModelsProviderFactoryWrapper modelProviderWrapper =
                 Registry.get(PapConstants.REG_PAP_DAO_FACTORY, PolicyModelsProviderFactoryWrapper.class);
-        Map<String, Map<String, List<PdpStatistics>>> pdpStatisticsMap;
         try (PolicyModelsProvider databaseProvider = modelProviderWrapper.create()) {
             Instant startTime = null;
             Instant endTime = null;
 
-            if (groupName == null) {
-                pdpStatisticsMap = generatePdpStatistics(databaseProvider.getPdpStatistics(pdpName, startTime));
-            } else {
-                pdpStatisticsMap = generatePdpStatistics(databaseProvider.getFilteredPdpStatistics(pdpName, groupName,
-                        subType, startTime, endTime, DESC_ORDER, recordCount));
-            }
+            /*
+             * getFilteredPdpStatistics() will throw an NPE if a group name is not specified, so we
+             * provide a default value
+             */
+            String grpnm = (groupName != null ? groupName : DEFAULT_GROUP);
+
+            int nrecords = Math.min(MAX_RECORD_COUNT, Math.max(MIN_RECORD_COUNT, recordCount));
+
+            return generatePdpStatistics(databaseProvider.getFilteredPdpStatistics(pdpName, grpnm,
+                            subType, startTime, endTime, DESC_ORDER, nrecords));
+
         } catch (final PfModelException exp) {
             String errorMessage = GET_STATISTICS_ERR_MSG + "groupName:" + groupName + "subType:" + subType + "pdpName:"
                     + pdpName + exp.getMessage();
             LOGGER.debug(errorMessage, exp);
             throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
         }
-        return pdpStatisticsMap;
     }
 
     /**