Use spring boot actuator version 2.5.4
[policy/pap.git] / main / src / main / java / org / onap / policy / pap / main / rest / StatisticsRestProvider.java
index 27e3d7a..51f10fe 100644 (file)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2020-2021 Nordix Foundation.
  *  Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
+ *  Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,7 +22,6 @@
 
 package org.onap.policy.pap.main.rest;
 
-import java.time.Instant;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -31,22 +31,21 @@ import org.onap.policy.common.utils.services.Registry;
 import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.pdp.concepts.PdpStatistics;
+import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters;
 import org.onap.policy.models.provider.PolicyModelsProvider;
 import org.onap.policy.pap.main.PapConstants;
 import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper;
 import org.onap.policy.pap.main.startstop.PapActivator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
 
 /**
  * Class to fetch statistics of pap component.
  *
  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
  */
+@Service
 public class StatisticsRestProvider {
-    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 GET_STATISTICS_ERR_MSG = "database query failed";
 
     /**
      * Returns the current statistics of pap component.
@@ -73,35 +72,20 @@ public class StatisticsRestProvider {
     /**
      * Returns statistics of pdp component from database.
      *
-     * @param groupName name of the PDP group
-     * @param subType type of the sub PDP group
-     * @param pdpName the name of the PDP
-     * @param recordCount the count to query from database
+     * @param filter record filter
      * @return Report containing statistics of pdp component
      * @throws PfModelException when database can not found
      */
-    public Map<String, Map<String, List<PdpStatistics>>> fetchDatabaseStatistics(String groupName, String subType,
-            String pdpName, int recordCount) throws PfModelException {
+    public Map<String, Map<String, List<PdpStatistics>>> fetchDatabaseStatistics(PdpFilterParameters filter)
+                    throws PfModelException {
         final PolicyModelsProviderFactoryWrapper modelProviderWrapper =
-                Registry.get(PapConstants.REG_PAP_DAO_FACTORY, PolicyModelsProviderFactoryWrapper.class);
-        Map<String, Map<String, List<PdpStatistics>>> pdpStatisticsMap;
+                        Registry.get(PapConstants.REG_PAP_DAO_FACTORY, PolicyModelsProviderFactoryWrapper.class);
         try (PolicyModelsProvider databaseProvider = modelProviderWrapper.create()) {
-            Instant startTime = null;
-            Instant endTime = null;
+            return generatePdpStatistics(databaseProvider.getFilteredPdpStatistics(filter));
 
-            if (groupName == null) {
-                pdpStatisticsMap = generatePdpStatistics(databaseProvider.getPdpStatistics(pdpName, startTime));
-            } else {
-                pdpStatisticsMap = generatePdpStatistics(databaseProvider.getFilteredPdpStatistics(pdpName, groupName,
-                        subType, startTime, endTime, DESC_ORDER, recordCount));
-            }
         } 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);
+            throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, GET_STATISTICS_ERR_MSG);
         }
-        return pdpStatisticsMap;
     }
 
     /**
@@ -121,5 +105,3 @@ public class StatisticsRestProvider {
         return groupMap;
     }
 }
-
-