cleaner way to handle swagger serialization issue
[policy/api.git] / main / src / main / java / org / onap / policy / api / main / rest / ApiStatisticsManager.java
index c40a38c..9109742 100644 (file)
@@ -2,8 +2,8 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy API
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Bell Canada.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020-2022 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.
 
 package org.onap.policy.api.main.rest;
 
-import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Component;
 
 /**
  * Class to hold statistical data for API access.
  *
  * @author Chenfei Gao (cgao@research.att.com)
  */
+@Component
+@RequiredArgsConstructor
 public class ApiStatisticsManager {
 
-    @Getter
-    private static long totalApiCallCount;
+    private final StatisticsReport report;
 
-    @Getter
-    private static long apiCallSuccessCount;
-
-    @Getter
-    private static long apiCallFailureCount;
-
-    @Getter
-    private static long totalPolicyGetCount;
-
-    @Getter
-    private static long totalPolicyPostCount;
-
-    @Getter
-    private static long totalPolicyDeleteCount;
-
-    @Getter
-    private static long totalPolicyTypeGetCount;
-
-    @Getter
-    private static long totalPolicyTypePostCount;
-
-    @Getter
-    private static long totalPolicyTypeDeleteCount;
-
-    @Getter
-    private static long policyGetSuccessCount;
-
-    @Getter
-    private static long policyGetFailureCount;
-
-    @Getter
-    private static long policyPostSuccessCount;
-
-    @Getter
-    private static long policyPostFailureCount;
-
-    @Getter
-    private static long policyDeleteSuccessCount;
-
-    @Getter
-    private static long policyDeleteFailureCount;
-
-    @Getter
-    private static long policyTypeGetSuccessCount;
-
-    @Getter
-    private static long policyTypeGetFailureCount;
-
-    @Getter
-    private static long policyTypePostSuccessCount;
-
-    @Getter
-    private static long policyTypePostFailureCount;
-
-    @Getter
-    private static long policyTypeDeleteSuccessCount;
-
-    @Getter
-    private static long policyTypeDeleteFailureCount;
-
-    private ApiStatisticsManager() {
-        throw new IllegalStateException("Instantiation of the class is not allowed");
-    }
+    private long totalPolicyDeleteCount;
+    private long totalPolicyTypeDeleteCount;
+    private long policyDeleteSuccessCount;
+    private long policyDeleteFailureCount;
+    private long policyTypeDeleteSuccessCount;
+    private long policyTypeDeleteFailureCount;
 
     /**
      * Method to update the total api call count.
      *
      * @return the updated value of totalApiCallCount
      */
-    public static long updateTotalApiCallCount() {
-        return ++totalApiCallCount;
+    public long updateTotalApiCallCount() {
+        return ++report.totalApiCallCount;
     }
 
     /**
@@ -113,8 +58,8 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of apiCallSuccessCount
      */
-    public static long updateApiCallSuccessCount() {
-        return ++apiCallSuccessCount;
+    public long updateApiCallSuccessCount() {
+        return ++report.apiCallSuccessCount;
     }
 
     /**
@@ -122,8 +67,8 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of apiCallFailureCount
      */
-    public static long updateApiCallFailureCount() {
-        return ++apiCallFailureCount;
+    public long updateApiCallFailureCount() {
+        return ++report.apiCallFailureCount;
     }
 
     /**
@@ -131,8 +76,8 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of totalPolicyGetCount
      */
-    public static long updateTotalPolicyGetCount() {
-        return ++totalPolicyGetCount;
+    public long updateTotalPolicyGetCount() {
+        return ++report.totalPolicyGetCount;
     }
 
     /**
@@ -140,8 +85,8 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of totalPolicyPostCount
      */
-    public static long updateTotalPolicyPostCount() {
-        return ++totalPolicyPostCount;
+    public long updateTotalPolicyPostCount() {
+        return ++report.totalPolicyPostCount;
     }
 
     /**
@@ -149,7 +94,7 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of  totalPolicyDeleteCount
      */
-    public static long updateTotalPolicyDeleteCount() {
+    public long updateTotalPolicyDeleteCount() {
         return ++totalPolicyDeleteCount;
     }
 
@@ -158,8 +103,8 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of totalPolicyTypeGetCount
      */
-    public static long updateTotalPolicyTypeGetCount() {
-        return ++totalPolicyTypeGetCount;
+    public long updateTotalPolicyTypeGetCount() {
+        return ++report.totalPolicyTypeGetCount;
     }
 
     /**
@@ -167,8 +112,8 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of totalPolicyTypePostCount
      */
-    public static long updateTotalPolicyTypePostCount() {
-        return ++totalPolicyTypePostCount;
+    public long updateTotalPolicyTypePostCount() {
+        return ++report.totalPolicyTypePostCount;
     }
 
     /**
@@ -176,7 +121,7 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of totalPolicyTypeDeleteCount
      */
-    public static long updateTotalPolicyTypeDeleteCount() {
+    public long updateTotalPolicyTypeDeleteCount() {
         return ++totalPolicyTypeDeleteCount;
     }
 
@@ -185,8 +130,8 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of policyGetSuccessCount
      */
-    public static long updatePolicyGetSuccessCount() {
-        return ++policyGetSuccessCount;
+    public long updatePolicyGetSuccessCount() {
+        return ++report.policyGetSuccessCount;
     }
 
     /**
@@ -194,8 +139,8 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of policyGetFailureCount
      */
-    public static long updatePolicyGetFailureCount() {
-        return ++policyGetFailureCount;
+    public long updatePolicyGetFailureCount() {
+        return ++report.policyGetFailureCount;
     }
 
     /**
@@ -203,8 +148,8 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of policyPostSuccessCount
      */
-    public static long updatePolicyPostSuccessCount() {
-        return ++policyPostSuccessCount;
+    public long updatePolicyPostSuccessCount() {
+        return ++report.policyPostSuccessCount;
     }
 
     /**
@@ -212,8 +157,8 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of policyPostFailureCount
      */
-    public static long updatePolicyPostFailureCount() {
-        return ++policyPostFailureCount;
+    public long updatePolicyPostFailureCount() {
+        return ++report.policyPostFailureCount;
     }
 
     /**
@@ -221,7 +166,7 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of policyDeleteSuccessCount
      */
-    public static long updatePolicyDeleteSuccessCount() {
+    public long updatePolicyDeleteSuccessCount() {
         return ++policyDeleteSuccessCount;
     }
 
@@ -230,7 +175,7 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of policyDeleteFailureCount
      */
-    public static long updatePolicyDeleteFailureCount() {
+    public long updatePolicyDeleteFailureCount() {
         return ++policyDeleteFailureCount;
     }
 
@@ -239,8 +184,8 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of policyTypeGetSuccessCount
      */
-    public static long updatePolicyTypeGetSuccessCount() {
-        return ++policyTypeGetSuccessCount;
+    public long updatePolicyTypeGetSuccessCount() {
+        return ++report.policyTypeGetSuccessCount;
     }
 
     /**
@@ -248,8 +193,8 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of policyTypeGetFailureCount
      */
-    public static long updatePolicyTypeGetFailureCount() {
-        return ++policyTypeGetFailureCount;
+    public long updatePolicyTypeGetFailureCount() {
+        return ++report.policyTypeGetFailureCount;
     }
 
     /**
@@ -257,8 +202,8 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of policyTypePostSuccessCount
      */
-    public static long updatePolicyTypePostSuccessCount() {
-        return ++policyTypePostSuccessCount;
+    public long updatePolicyTypePostSuccessCount() {
+        return ++report.policyTypePostSuccessCount;
     }
 
     /**
@@ -266,8 +211,8 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of policyTypePostFailureCount
      */
-    public static long updatePolicyTypePostFailureCount() {
-        return ++policyTypePostFailureCount;
+    public long updatePolicyTypePostFailureCount() {
+        return ++report.policyTypePostFailureCount;
     }
 
     /**
@@ -275,7 +220,7 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of policyTypeDeleteSuccessCount
      */
-    public static long updatePolicyTypeDeleteSuccessCount() {
+    public long updatePolicyTypeDeleteSuccessCount() {
         return ++policyTypeDeleteSuccessCount;
     }
 
@@ -284,36 +229,7 @@ public class ApiStatisticsManager {
      *
      * @return the updated value of policyTypePostFailureCount
      */
-    public static long updatePolicyTypeDeleteFailureCount() {
+    public long updatePolicyTypeDeleteFailureCount() {
         return ++policyTypeDeleteFailureCount;
     }
-
-    /**
-     * Reset all the statistics counts to 0.
-     */
-    public static void resetAllStatistics() {
-        totalApiCallCount = 0L;
-        apiCallSuccessCount = 0L;
-        apiCallFailureCount = 0L;
-        totalPolicyGetCount = 0L;
-        totalPolicyPostCount = 0L;
-        totalPolicyDeleteCount = 0L;
-        totalPolicyTypeGetCount = 0L;
-        totalPolicyTypePostCount = 0L;
-        totalPolicyTypeDeleteCount = 0L;
-        policyGetSuccessCount = 0L;
-        policyGetFailureCount = 0L;
-        policyPostSuccessCount = 0L;
-        policyPostFailureCount = 0L;
-        policyDeleteSuccessCount = 0L;
-        policyDeleteFailureCount = 0L;
-        policyTypeGetSuccessCount = 0L;
-        policyTypeGetFailureCount = 0L;
-        policyTypePostSuccessCount = 0L;
-        policyTypePostFailureCount = 0L;
-        policyTypeDeleteSuccessCount = 0L;
-        policyTypeDeleteFailureCount = 0L;
-
-    }
-
-}
+}
\ No newline at end of file