Migrate policy api startup & config, controller to springboot
[policy/api.git] / main / src / main / java / org / onap / policy / api / main / rest / ApiRestController.java
index eb60c5e..263345a 100644 (file)
@@ -5,7 +5,7 @@
  * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.\r
  * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.\r
  * Modifications Copyright (C) 2020 Nordix Foundation.\r
- * Modifications Copyright (C) 2020 Bell Canada.\r
+ * Modifications Copyright (C) 2020-2022 Bell Canada. All rights reserved.\r
  * ================================================================================\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
@@ -41,18 +41,8 @@ import io.swagger.annotations.SwaggerDefinition;
 import java.net.HttpURLConnection;\r
 import java.util.List;\r
 import java.util.UUID;\r
-import javax.ws.rs.Consumes;\r
-import javax.ws.rs.DELETE;\r
-import javax.ws.rs.DefaultValue;\r
-import javax.ws.rs.GET;\r
-import javax.ws.rs.HeaderParam;\r
-import javax.ws.rs.POST;\r
-import javax.ws.rs.Path;\r
-import javax.ws.rs.PathParam;\r
-import javax.ws.rs.Produces;\r
-import javax.ws.rs.QueryParam;\r
-import javax.ws.rs.core.Response;\r
 import javax.ws.rs.core.Response.Status;\r
+import org.onap.policy.api.main.exception.PolicyApiRuntimeException;\r
 import org.onap.policy.api.main.rest.provider.HealthCheckProvider;\r
 import org.onap.policy.api.main.rest.provider.PolicyProvider;\r
 import org.onap.policy.api.main.rest.provider.PolicyTypeProvider;\r
@@ -66,16 +56,29 @@ import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;\r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.http.HttpMethod;\r
+import org.springframework.http.HttpStatus;\r
+import org.springframework.http.ResponseEntity;\r
+import org.springframework.web.bind.annotation.DeleteMapping;\r
+import org.springframework.web.bind.annotation.ExceptionHandler;\r
+import org.springframework.web.bind.annotation.GetMapping;\r
+import org.springframework.web.bind.annotation.PathVariable;\r
+import org.springframework.web.bind.annotation.PostMapping;\r
+import org.springframework.web.bind.annotation.RequestBody;\r
+import org.springframework.web.bind.annotation.RequestHeader;\r
+import org.springframework.web.bind.annotation.RequestMapping;\r
+import org.springframework.web.bind.annotation.RequestParam;\r
+import org.springframework.web.bind.annotation.RestController;\r
 \r
 /**\r
  * Class to provide REST API services.\r
  *\r
  * @author Chenfei Gao (cgao@research.att.com)\r
  */\r
-@Path("/policy/api/v1")\r
+@RestController\r
+@RequestMapping(path = "/policy/api/v1", produces = { "application/json", "application/yaml" })\r
 @Api(value = "Policy Design API")\r
-@Produces({"application/json", "application/yaml"})\r
-@Consumes({"application/json", "application/yaml"})\r
 @SwaggerDefinition(\r
     info = @Info(\r
         description = "Policy Design API is publicly exposed for clients to Create/Read/Update/Delete"\r
@@ -129,14 +132,33 @@ public class ApiRestController extends CommonRestController {
     private static final String INVALID_PAYLOAD_MESSAGE = "Not Acceptable Payload";\r
     private static final String HTTP_CONFLICT_MESSAGE = "Delete Conflict, Rule Violation";\r
 \r
+    private enum Target {\r
+        POLICY,\r
+        POLICY_TYPE,\r
+        OTHER\r
+    }\r
+\r
+    @Autowired\r
+    private PolicyProvider policyProvider;\r
+\r
+    @Autowired\r
+    private HealthCheckProvider healthCheckProvider;\r
+\r
+    @Autowired\r
+    private PolicyTypeProvider policyTypeProvider;\r
+\r
+    @Autowired\r
+    private ApiStatisticsManager mgr;\r
+\r
+    @Autowired\r
+    private StatisticsProvider statisticsProvider;\r
 \r
     /**\r
      * Retrieves the healthcheck status of the API component.\r
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @GET\r
-    @Path("/healthcheck")\r
+    @GetMapping("/healthcheck")\r
     @ApiOperation(value = "Perform a system healthcheck", notes = "Returns healthy status of the Policy API component",\r
         response = HealthCheckReport.class,\r
         responseHeaders = {\r
@@ -159,11 +181,11 @@ public class ApiRestController extends CommonRestController {
         @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})\r
-    public Response\r
-        getHealthCheck(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
-\r
-        updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET);\r
-        return makeOkResponse(requestId, new HealthCheckProvider().performHealthCheck());\r
+    public ResponseEntity<HealthCheckReport> getHealthCheck(\r
+        @RequestHeader(name = REQUEST_ID_NAME, required = false)\r
+        @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
+        updateApiStatisticsCounter(Target.OTHER, HttpStatus.OK, HttpMethod.GET);\r
+        return makeOkResponse(requestId, healthCheckProvider.performHealthCheck());\r
     }\r
 \r
     /**\r
@@ -171,8 +193,7 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @GET\r
-    @Path("/statistics")\r
+    @GetMapping("/statistics")\r
     @ApiOperation(value = "Retrieve current statistics",\r
         notes = "Returns current statistics including the counters of API invocation",\r
         response = StatisticsReport.class,\r
@@ -196,12 +217,11 @@ public class ApiRestController extends CommonRestController {
         @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})\r
-    public Response\r
-        getStatistics(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
-\r
-        updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET);\r
-\r
-        return makeOkResponse(requestId, new StatisticsProvider().fetchCurrentStatistics());\r
+    public ResponseEntity<StatisticsReport> getStatistics(\r
+        @RequestHeader(name = REQUEST_ID_NAME, required = false)\r
+        @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
+        updateApiStatisticsCounter(Target.OTHER, HttpStatus.OK, HttpMethod.GET);\r
+        return makeOkResponse(requestId, statisticsProvider.fetchCurrentStatistics());\r
     }\r
 \r
     /**\r
@@ -209,8 +229,7 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @GET\r
-    @Path("/policytypes")\r
+    @GetMapping("/policytypes")\r
     @ApiOperation(value = "Retrieve existing policy types",\r
         notes = "Returns a list of existing policy types stored in Policy Framework",\r
         response = ToscaServiceTemplate.class,\r
@@ -234,17 +253,18 @@ public class ApiRestController extends CommonRestController {
         @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})\r
-    public Response\r
-        getAllPolicyTypes(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
-\r
-        try (var policyTypeProvider = new PolicyTypeProvider()) {\r
+    public ResponseEntity<ToscaServiceTemplate> getAllPolicyTypes(\r
+        @RequestHeader(name = REQUEST_ID_NAME, required = false)\r
+        @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(null, null);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);\r
+            updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.warn("GET /policytypes", pfme);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);\r
-            return makeErrorResponse(requestId, pfme);\r
+            final var msg = "GET /policytypes";\r
+            updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
+                .getStatusCode()), HttpMethod.GET);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -255,8 +275,7 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @GET\r
-    @Path("/policytypes/{policyTypeId}")\r
+    @GetMapping("/policytypes/{policyTypeId}")\r
     @ApiOperation(value = "Retrieve all available versions of a policy type",\r
         notes = "Returns a list of all available versions for the specified policy type",\r
         response = ToscaServiceTemplate.class,\r
@@ -281,18 +300,19 @@ public class ApiRestController extends CommonRestController {
         @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})\r
-    public Response getAllVersionsOfPolicyType(\r
-        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
-        @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
-\r
-        try (var policyTypeProvider = new PolicyTypeProvider()) {\r
+    public ResponseEntity<ToscaServiceTemplate> getAllVersionsOfPolicyType(\r
+        @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
+        @RequestHeader(name = REQUEST_ID_NAME, required = false)\r
+        @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, null);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);\r
+            updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.warn("GET /policytypes/{}", policyTypeId, pfme);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);\r
-            return makeErrorResponse(requestId, pfme);\r
+            var msg = String.format("GET /policytypes/%s", policyTypeId);\r
+            updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
+                .getStatusCode()), HttpMethod.GET);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -304,8 +324,7 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @GET\r
-    @Path("/policytypes/{policyTypeId}/versions/{versionId}")\r
+    @GetMapping("/policytypes/{policyTypeId}/versions/{versionId}")\r
     @ApiOperation(value = "Retrieve one particular version of a policy type",\r
         notes = "Returns a particular version for the specified policy type", response = ToscaServiceTemplate.class,\r
         responseHeaders = {\r
@@ -329,19 +348,20 @@ public class ApiRestController extends CommonRestController {
         @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})\r
-    public Response getSpecificVersionOfPolicyType(\r
-        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
-        @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,\r
-        @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
-\r
-        try (var policyTypeProvider = new PolicyTypeProvider()) {\r
+    public ResponseEntity<ToscaServiceTemplate> getSpecificVersionOfPolicyType(\r
+        @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
+        @PathVariable("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,\r
+        @RequestHeader(name = REQUEST_ID_NAME, required = false)\r
+        @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, versionId);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);\r
+            updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.warn("GET /policytypes/{}/versions/{}", policyTypeId, versionId, pfme);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);\r
-            return makeErrorResponse(requestId, pfme);\r
+            var msg = String.format("GET /policytypes/%s/versions/%s", policyTypeId, versionId);\r
+            updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
+                .getStatusCode()), HttpMethod.GET);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -352,8 +372,7 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @GET\r
-    @Path("/policytypes/{policyTypeId}/versions/latest")\r
+    @GetMapping("/policytypes/{policyTypeId}/versions/latest")\r
     @ApiOperation(value = "Retrieve latest version of a policy type",\r
         notes = "Returns latest version for the specified policy type", response = ToscaServiceTemplate.class,\r
         responseHeaders = {\r
@@ -377,18 +396,19 @@ public class ApiRestController extends CommonRestController {
         @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})\r
-    public Response getLatestVersionOfPolicyType(\r
-        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
-        @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
-\r
-        try (var policyTypeProvider = new PolicyTypeProvider()) {\r
+    public ResponseEntity<ToscaServiceTemplate> getLatestVersionOfPolicyType(\r
+        @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
+        @RequestHeader(name = REQUEST_ID_NAME, required = false)\r
+        @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchLatestPolicyTypes(policyTypeId);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);\r
+            updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.warn("GET /policytypes/{}/versions/latest", policyTypeId, pfme);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);\r
-            return makeErrorResponse(requestId, pfme);\r
+            var msg = String.format("GET /policytypes/%s/versions/latest", policyTypeId);\r
+            updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
+                .getStatusCode()), HttpMethod.GET);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -399,8 +419,7 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @POST\r
-    @Path("/policytypes")\r
+    @PostMapping("/policytypes")\r
     @ApiOperation(value = "Create a new policy type", notes = "Client should provide TOSCA body of the new policy type",\r
         authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },\r
         response = ToscaServiceTemplate.class,\r
@@ -425,22 +444,22 @@ public class ApiRestController extends CommonRestController {
         @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = INVALID_PAYLOAD_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})\r
-    public Response createPolicyType(\r
-        @ApiParam(value = "Entity body of policy type", required = true) ToscaServiceTemplate body,\r
-        @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
-\r
+    public ResponseEntity<ToscaServiceTemplate> createPolicyType(\r
+        @RequestBody @ApiParam(value = "Entity body of policy type", required = true) ToscaServiceTemplate body,\r
+        @RequestHeader(name = REQUEST_ID_NAME, required = false)\r
+        @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
         if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {\r
             NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body));\r
         }\r
-\r
-        try (var policyTypeProvider = new PolicyTypeProvider()) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate = policyTypeProvider.createPolicyType(body);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.POST);\r
+            updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.POST);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.warn("POST /policytypes", pfme);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.POST);\r
-            return makeErrorResponse(requestId, pfme);\r
+            final var msg = "POST /policytypes";\r
+            updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
+                .getStatusCode()), HttpMethod.POST);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -452,8 +471,7 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @DELETE\r
-    @Path("/policytypes/{policyTypeId}/versions/{versionId}")\r
+    @DeleteMapping("/policytypes/{policyTypeId}/versions/{versionId}")\r
     @ApiOperation(value = "Delete one version of a policy type",\r
         notes = "Rule 1: pre-defined policy types cannot be deleted;"\r
             + "Rule 2: policy types that are in use (parameterized by a TOSCA policy) cannot be deleted."\r
@@ -481,19 +499,20 @@ public class ApiRestController extends CommonRestController {
         @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = HTTP_CONFLICT_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})\r
-    public Response deleteSpecificVersionOfPolicyType(\r
-        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
-        @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,\r
-        @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
-\r
-        try (var policyTypeProvider = new PolicyTypeProvider()) {\r
+    public ResponseEntity<ToscaServiceTemplate> deleteSpecificVersionOfPolicyType(\r
+        @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
+        @PathVariable("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,\r
+        @RequestHeader(name = REQUEST_ID_NAME, required = false)\r
+        @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate = policyTypeProvider.deletePolicyType(policyTypeId, versionId);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.DELETE);\r
+            updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.DELETE);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.warn("DELETE /policytypes/{}/versions/{}", policyTypeId, versionId, pfme);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.DELETE);\r
-            return makeErrorResponse(requestId, pfme);\r
+            var msg = String.format("DELETE /policytypes/%s/versions/%s", policyTypeId, versionId);\r
+            updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
+                .getStatusCode()), HttpMethod.DELETE);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -505,8 +524,7 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @GET\r
-    @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")\r
+    @GetMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")\r
     @ApiOperation(\r
         value = "Retrieve all versions of a policy created for a particular policy type version",\r
         notes = "Returns a list of all versions of specified policy created for the specified policy type version",\r
@@ -536,24 +554,24 @@ public class ApiRestController extends CommonRestController {
         @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)\r
     })\r
-    public Response getAllPolicies(\r
-        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
-        @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",\r
+    public ResponseEntity<ToscaServiceTemplate> getAllPolicies(\r
+        @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
+        @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",\r
             required = true) String policyTypeVersion,\r
-        @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,\r
-        @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"\r
-            + " REFERENCED for fully referenced policies") PolicyFetchMode mode\r
-    ) {\r
-\r
-        try (var policyProvider = new PolicyProvider()) {\r
+        @RequestHeader(name = REQUEST_ID_NAME, required = false)\r
+        @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,\r
+        @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, BARE for bare"\r
+            + " policies (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate =\r
                 policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, null, null, mode);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.warn("GET /policytypes/{}/versions/{}/policies", policyTypeId, policyTypeVersion, pfme);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);\r
-            return makeErrorResponse(requestId, pfme);\r
+            var msg = String.format("GET /policytypes/%s/versions/%s/policies", policyTypeId, policyTypeVersion);\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
+                .getStatusCode()), HttpMethod.GET);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -566,8 +584,7 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @GET\r
-    @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}")\r
+    @GetMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}")\r
     @ApiOperation(value = "Retrieve all version details of a policy created for a particular policy type version",\r
         notes = "Returns a list of all version details of the specified policy", response = ToscaServiceTemplate.class,\r
         responseHeaders = {\r
@@ -595,24 +612,26 @@ public class ApiRestController extends CommonRestController {
         @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)\r
     })\r
-    public Response getAllVersionsOfPolicy(\r
-        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
-        @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",\r
+    public ResponseEntity<ToscaServiceTemplate> getAllVersionsOfPolicy(\r
+        @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
+        @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",\r
             required = true) String policyTypeVersion,\r
-        @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,\r
-        @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,\r
-        @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"\r
-            + " REFERENCED for fully referenced policies") PolicyFetchMode mode\r
-    ) {\r
-        try (var policyProvider = new PolicyProvider()) {\r
+        @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,\r
+        @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,\r
+        @RequestParam(name = "mode", defaultValue = "bare")\r
+        @ApiParam("Fetch mode for policies, BARE for bare policies (default),"\r
+            + " REFERENCED for fully referenced policies") PolicyFetchMode mode) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate =\r
                 policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null, mode);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.warn("/policytypes/{}/versions/{}/policies/{}", policyTypeId, policyTypeVersion, policyId, pfme);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);\r
-            return makeErrorResponse(requestId, pfme);\r
+            var msg = String.format("/policytypes/%s/versions/$s/policies/%s",\r
+                policyTypeId, policyTypeVersion, policyId);\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
+                .getStatusCode()), HttpMethod.GET);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -626,8 +645,7 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @GET\r
-    @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")\r
+    @GetMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")\r
     @ApiOperation(value = "Retrieve one version of a policy created for a particular policy type version",\r
         notes = "Returns a particular version of specified policy created for the specified policy type version",\r
         response = ToscaServiceTemplate.class,\r
@@ -656,26 +674,27 @@ public class ApiRestController extends CommonRestController {
         @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)\r
     })\r
-    public Response getSpecificVersionOfPolicy(\r
-        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
-        @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",\r
+    public ResponseEntity<ToscaServiceTemplate> getSpecificVersionOfPolicy(\r
+        @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
+        @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",\r
             required = true) String policyTypeVersion,\r
-        @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,\r
-        @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,\r
-        @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,\r
-        @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"\r
-            + " REFERENCED for fully referenced policies") PolicyFetchMode mode\r
-    ) {\r
-        try (var policyProvider = new PolicyProvider()) {\r
+        @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,\r
+        @PathVariable("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,\r
+        @RequestHeader(name = REQUEST_ID_NAME, required = false)\r
+        @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,\r
+        @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, BARE for bare policies"\r
+            + "  (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate =\r
                 policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.warn("GET /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId, policyTypeVersion,\r
-                policyId, policyVersion, pfme);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);\r
-            return makeErrorResponse(requestId, pfme);\r
+            var msg = String.format("GET /policytypes/%s/versions/%s/policies/%s/versions/%s",\r
+                policyTypeId, policyTypeVersion, policyId, policyVersion);\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
+                .getStatusCode()), HttpMethod.GET);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -688,8 +707,7 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @GET\r
-    @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/latest")\r
+    @GetMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/latest")\r
     @ApiOperation(value = "Retrieve the latest version of a particular policy",\r
         notes = "Returns the latest version of specified policy", response = ToscaServiceTemplate.class,\r
         responseHeaders = {\r
@@ -713,25 +731,26 @@ public class ApiRestController extends CommonRestController {
         @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})\r
-    public Response getLatestVersionOfPolicy(\r
-        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
-        @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",\r
+    public ResponseEntity<ToscaServiceTemplate> getLatestVersionOfPolicy(\r
+        @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
+        @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",\r
             required = true) String policyTypeVersion,\r
-        @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,\r
-        @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,\r
-        @QueryParam("mode") @ApiParam("Fetch mode for policies, TERSE for bare policies (default), "\r
-            + "REFERENCED for fully referenced policies") PolicyFetchMode mode) {\r
-\r
-        try (var policyProvider = new PolicyProvider()) {\r
+        @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,\r
+        @RequestHeader(name = REQUEST_ID_NAME, required = false)\r
+        @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,\r
+        @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, TERSE for bare "\r
+            + "policies (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate =\r
                 policyProvider.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId, mode);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.warn("GET /policytypes/{}/versions/{}/policies/{}/versions/latest", policyTypeId, policyTypeVersion,\r
-                policyId, pfme);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);\r
-            return makeErrorResponse(requestId, pfme);\r
+            var msg = String.format("GET /policytypes/%s/versions/%s/policies/%s/versions/latest",\r
+                policyTypeId, policyTypeVersion, policyId);\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
+                .getStatusCode()), HttpMethod.GET);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -744,8 +763,7 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @POST\r
-    @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")\r
+    @PostMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")\r
     @ApiOperation(value = "Create a new policy for a policy type version",\r
         notes = "Client should provide TOSCA body of the new policy",\r
         authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },\r
@@ -772,26 +790,26 @@ public class ApiRestController extends CommonRestController {
         @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = INVALID_PAYLOAD_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})\r
-    public Response createPolicy(\r
-        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
-        @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",\r
+    public ResponseEntity<ToscaServiceTemplate> createPolicy(\r
+        @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
+        @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",\r
             required = true) String policyTypeVersion,\r
-        @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,\r
-        @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {\r
-\r
+        @RequestHeader(name = REQUEST_ID_NAME, required = false)\r
+        @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,\r
+        @RequestBody @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {\r
         if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {\r
             NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,\r
                 "/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body));\r
         }\r
-\r
-        try (var policyProvider = new PolicyProvider()) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate = policyProvider.createPolicy(policyTypeId, policyTypeVersion, body);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.POST);\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.POST);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.warn("POST /policytypes/{}/versions/{}/policies", policyTypeId, policyTypeVersion, pfme);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.POST);\r
-            return makeErrorResponse(requestId, pfme);\r
+            var msg = String.format("POST /policytypes/%s/versions/%s/policies", policyTypeId, policyTypeVersion);\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
+                .getStatusCode()), HttpMethod.POST);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -805,8 +823,8 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @DELETE\r
-    @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")\r
+    @DeleteMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/"\r
+        + "versions/{policyVersion}")\r
     @ApiOperation(value = "Delete a particular version of a policy",\r
         notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",\r
         authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },\r
@@ -832,24 +850,25 @@ public class ApiRestController extends CommonRestController {
         @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = HTTP_CONFLICT_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})\r
-    public Response deleteSpecificVersionOfPolicy(\r
-        @PathParam("policyTypeId") @ApiParam(value = "PolicyType ID", required = true) String policyTypeId,\r
-        @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",\r
+    public ResponseEntity<ToscaServiceTemplate> deleteSpecificVersionOfPolicy(\r
+        @PathVariable("policyTypeId") @ApiParam(value = "PolicyType ID", required = true) String policyTypeId,\r
+        @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",\r
             required = true) String policyTypeVersion,\r
-        @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,\r
-        @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,\r
-        @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
-\r
-        try (var policyProvider = new PolicyProvider()) {\r
+        @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,\r
+        @PathVariable("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,\r
+        @RequestHeader(name = REQUEST_ID_NAME, required = false)\r
+        @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate =\r
                 policyProvider.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.DELETE);\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.DELETE);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.warn("DELETE /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId, policyTypeVersion,\r
-                policyId, policyVersion, pfme);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.DELETE);\r
-            return makeErrorResponse(requestId, pfme);\r
+            var msg = String.format("DELETE /policytypes/%s/versions/%s/policies/%s/versions/%s",\r
+                policyTypeId, policyTypeVersion, policyId, policyVersion);\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
+                .getStatusCode()), HttpMethod.DELETE);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -858,8 +877,7 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @GET\r
-    @Path("/policies")\r
+    @GetMapping("/policies")\r
     @ApiOperation(value = "Retrieve all versions of available policies",\r
         notes = "Returns all version of available policies",\r
         response = ToscaServiceTemplate.class,\r
@@ -888,24 +906,25 @@ public class ApiRestController extends CommonRestController {
         @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)\r
     })\r
-    public Response getPolicies(\r
-        @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,\r
-        @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"\r
-            + " REFERENCED for fully referenced policies") PolicyFetchMode mode\r
-    ) {\r
-        try (var policyProvider = new PolicyProvider()) {\r
+    public ResponseEntity<ToscaServiceTemplate> getPolicies(\r
+        @RequestHeader(name = REQUEST_ID_NAME, required = false)\r
+        @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,\r
+        @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, BARE for bare"\r
+            + "  policies (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate =\r
                 policyProvider.fetchPolicies(null, null, null, null, mode);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.warn("GET /policies/ --", pfme);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);\r
+            final var msg = "GET /policies/ --";\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
+                .getStatusCode()), HttpMethod.GET);\r
             if (pfme.getErrorResponse().getResponseCode().equals(Status.NOT_FOUND)) {\r
                 pfme.getErrorResponse().setErrorMessage(ERROR_MESSAGE_NO_POLICIES_FOUND);\r
                 pfme.getErrorResponse().setErrorDetails(List.of(ERROR_MESSAGE_NO_POLICIES_FOUND));\r
             }\r
-            return makeErrorResponse(requestId, pfme);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -917,8 +936,7 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @GET\r
-    @Path("/policies/{policyId}/versions/{policyVersion}")\r
+    @GetMapping("/policies/{policyId}/versions/{policyVersion}")\r
     @ApiOperation(value = "Retrieve specific version of a specified policy",\r
         notes = "Returns a particular version of specified policy",\r
         response = ToscaServiceTemplate.class,\r
@@ -947,22 +965,23 @@ public class ApiRestController extends CommonRestController {
         @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)\r
     })\r
-    public Response getSpecificPolicy(\r
-        @PathParam("policyId") @ApiParam(value = "Name of policy", required = true) String policyId,\r
-        @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,\r
-        @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,\r
-        @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"\r
-            + " REFERENCED for fully referenced policies") PolicyFetchMode mode\r
-    ) {\r
-        try (var policyProvider = new PolicyProvider()) {\r
+    public ResponseEntity<ToscaServiceTemplate> getSpecificPolicy(\r
+        @PathVariable("policyId") @ApiParam(value = "Name of policy", required = true) String policyId,\r
+        @PathVariable("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,\r
+        @RequestHeader(name = REQUEST_ID_NAME, required = false)\r
+        @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,\r
+        @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, BARE for bare"\r
+            + "  policies (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate =\r
                 policyProvider.fetchPolicies(null, null, policyId, policyVersion, mode);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.warn("GET /policies/{}/versions/{}", policyId, policyVersion, pfme);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);\r
-            return makeErrorResponse(requestId, pfme);\r
+            var msg = String.format("GET /policies/%s/versions/%s", policyId, policyVersion);\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
+                .getStatusCode()), HttpMethod.GET);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -973,8 +992,7 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @POST\r
-    @Path("/policies")\r
+    @PostMapping("/policies")\r
     @ApiOperation(value = "Create one or more new policies",\r
         notes = "Client should provide TOSCA body of the new polic(ies)",\r
         authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },\r
@@ -1001,22 +1019,22 @@ public class ApiRestController extends CommonRestController {
         @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = INVALID_PAYLOAD_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})\r
-    public Response createPolicies(\r
-        @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,\r
-        @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {\r
-\r
+    public ResponseEntity<ToscaServiceTemplate> createPolicies(\r
+        @RequestHeader(name = REQUEST_ID_NAME, required = false)\r
+        @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,\r
+        @RequestBody @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {\r
         if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {\r
             NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policies", toJson(body));\r
         }\r
-\r
-        try (var policyProvider = new PolicyProvider()) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate = policyProvider.createPolicies(body);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.POST);\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.POST);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.warn("POST /policies", pfme);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.POST);\r
-            return makeErrorResponse(requestId, pfme);\r
+            final var msg = "POST /policies";\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
+                .getStatusCode()), HttpMethod.POST);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -1028,8 +1046,7 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @DELETE\r
-    @Path("/policies/{policyId}/versions/{policyVersion}")\r
+    @DeleteMapping("/policies/{policyId}/versions/{policyVersion}")\r
     @ApiOperation(value = "Delete a particular version of a policy",\r
         notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",\r
         authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },\r
@@ -1055,47 +1072,33 @@ public class ApiRestController extends CommonRestController {
         @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = HTTP_CONFLICT_MESSAGE),\r
         @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})\r
-    public Response deleteSpecificPolicy(\r
-        @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,\r
-        @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,\r
-        @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
-\r
-        try (var policyProvider = new PolicyProvider()) {\r
+    public ResponseEntity<ToscaServiceTemplate> deleteSpecificPolicy(\r
+        @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,\r
+        @PathVariable("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,\r
+        @RequestHeader(name = REQUEST_ID_NAME, required = false)\r
+        @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate =\r
                 policyProvider.deletePolicy(null, null, policyId, policyVersion);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.DELETE);\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.DELETE);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.warn("DELETE /policies/{}/versions/{}", policyId, policyVersion, pfme);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.DELETE);\r
-            return makeErrorResponse(requestId, pfme);\r
+            var msg = String.format("DELETE /policies/%s/versions/%s", policyId, policyVersion);\r
+            updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
+                .getStatusCode()), HttpMethod.DELETE);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
-\r
-\r
-    private enum Target {\r
-        POLICY,\r
-        POLICY_TYPE,\r
-        OTHER\r
-    }\r
-\r
-    private enum Result {\r
-        SUCCESS,\r
-        FAILURE\r
-    }\r
-\r
-    private enum HttpMethod {\r
-        POST,\r
-        GET,\r
-        DELETE\r
+    @ExceptionHandler(value = {PolicyApiRuntimeException.class})\r
+    protected ResponseEntity<Object> handleException(PolicyApiRuntimeException ex) {\r
+        LOGGER.warn(ex.getMessage(), ex.getCause());\r
+        return makeErrorResponse(ex.getRequestId(), ex.getErrorResponse(),\r
+            ex.getErrorResponse().getResponseCode().getStatusCode());\r
     }\r
 \r
-    private void updateApiStatisticsCounter(Target target, Result result, HttpMethod http) {\r
-\r
-        var mgr = ApiStatisticsManager.getInstance();\r
+    private void updateApiStatisticsCounter(Target target, HttpStatus result, HttpMethod http) {\r
         mgr.updateTotalApiCallCount();\r
-\r
         switch (target) {\r
             case POLICY:\r
                 updatePolicyStats(result, http);\r
@@ -1109,10 +1112,8 @@ public class ApiRestController extends CommonRestController {
         }\r
     }\r
 \r
-    private void updatePolicyStats(Result result, HttpMethod http) {\r
-        var mgr = ApiStatisticsManager.getInstance();\r
-\r
-        if (result == Result.SUCCESS) {\r
+    private void updatePolicyStats(HttpStatus result, HttpMethod http) {\r
+        if (result.equals(HttpStatus.OK)) {\r
             switch (http) {\r
                 case GET:\r
                     mgr.updateApiCallSuccessCount();\r
@@ -1157,10 +1158,8 @@ public class ApiRestController extends CommonRestController {
         }\r
     }\r
 \r
-    private void updatePolicyTypeStats(Result result, HttpMethod http) {\r
-        var mgr = ApiStatisticsManager.getInstance();\r
-\r
-        if (result == Result.SUCCESS) {\r
+    private void updatePolicyTypeStats(HttpStatus result, HttpMethod http) {\r
+        if (result.equals(HttpStatus.OK)) {\r
             switch (http) {\r
                 case GET:\r
                     mgr.updateApiCallSuccessCount();\r
@@ -1204,4 +1203,4 @@ public class ApiRestController extends CommonRestController {
             }\r
         }\r
     }\r
-}\r
+}
\ No newline at end of file