Removed db-based statistics feature
[policy/api.git] / main / src / main / java / org / onap / policy / api / main / rest / ApiRestController.java
index 7661c27..a1e6db2 100644 (file)
@@ -3,8 +3,9 @@
  * ONAP Policy API\r
  * ================================================================================\r
  * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.\r
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.\r
- * Modifications Copyright (C) 2020 Nordix Foundation.\r
+ * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.\r
+ * Modifications Copyright (C) 2020-2022 Nordix Foundation.\r
+ * Modifications Copyright (C) 2020-2023 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
 \r
 package org.onap.policy.api.main.rest;\r
 \r
-import io.swagger.annotations.Api;\r
-import io.swagger.annotations.ApiOperation;\r
-import io.swagger.annotations.ApiParam;\r
-import io.swagger.annotations.ApiResponse;\r
-import io.swagger.annotations.ApiResponses;\r
-import io.swagger.annotations.Authorization;\r
-import io.swagger.annotations.BasicAuthDefinition;\r
-import io.swagger.annotations.Extension;\r
-import io.swagger.annotations.ExtensionProperty;\r
-import io.swagger.annotations.Info;\r
-import io.swagger.annotations.ResponseHeader;\r
-import io.swagger.annotations.SecurityDefinition;\r
-import io.swagger.annotations.SwaggerDefinition;\r
-\r
+import java.util.List;\r
 import java.util.UUID;\r
-\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
-\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
-import org.onap.policy.api.main.rest.provider.StatisticsProvider;\r
+import javax.ws.rs.core.Response.Status;\r
+import lombok.RequiredArgsConstructor;\r
+import org.onap.policy.api.main.exception.PolicyApiRuntimeException;\r
+import org.onap.policy.api.main.rest.genapi.PolicyDesignApi;\r
+import org.onap.policy.api.main.rest.provider.healthcheck.HealthCheckProvider;\r
+import org.onap.policy.api.main.service.ToscaServiceTemplateService;\r
 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;\r
 import org.onap.policy.common.endpoints.report.HealthCheckReport;\r
 import org.onap.policy.common.endpoints.utils.NetLoggerUtil;\r
@@ -63,108 +40,40 @@ import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
 import org.onap.policy.models.base.PfModelException;\r
 import org.onap.policy.models.base.PfModelRuntimeException;\r
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
+import org.springframework.context.annotation.Profile;\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.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
-@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
-            + " policy types, policy type implementation and policies which can be recognized"\r
-            + " and executable by incorporated policy engines. It is an"\r
-            + " independent component running rest service that takes all policy design API calls"\r
-            + " from clients and then assign them to different API working functions. Besides"\r
-            + " that, API is also exposed for clients to retrieve healthcheck status of this API"\r
-            + " rest service and the statistics report including the counters of API invocation.",\r
-        version = "1.0.0", title = "Policy Design",\r
-        extensions = {@Extension(properties = {@ExtensionProperty(name = "planned-retirement-date", value = "tbd"),\r
-            @ExtensionProperty(name = "component", value = "Policy Framework")})}),\r
-    schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},\r
-    securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")}))\r
-public class ApiRestController extends CommonRestController {\r
-\r
-    private static final Logger LOGGER = LoggerFactory.getLogger(ApiRestController.class);\r
+@RestController\r
+@RequiredArgsConstructor\r
+@Profile("default")\r
+public class ApiRestController extends CommonRestController implements PolicyDesignApi {\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
-    @ApiOperation(value = "Perform a system healthcheck", notes = "Returns healthy status of the Policy API component",\r
-        response = HealthCheckReport.class,\r
-        responseHeaders = {\r
-            @ResponseHeader(name = "X-MinorVersion",\r
-                description = "Used to request or communicate a MINOR version back from the client"\r
-                    + " to the server, and from the server back to the client",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-PatchVersion",\r
-                description = "Used only to communicate a PATCH version in a response for"\r
-                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-ONAP-RequestID",\r
-                description = "Used to track REST transactions for logging purpose", response = UUID.class)},\r
-        authorizations = @Authorization(value = "basicAuth"), tags = {"HealthCheck",},\r
-        extensions = {\r
-            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),\r
-                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})\r
-    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),\r
-        @ApiResponse(code = 403, message = "Authorization Error"),\r
-        @ApiResponse(code = 500, message = "Internal Server Error")})\r
-    public Response\r
-        getHealthCheck(@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {\r
-\r
-        updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET);\r
-        return makeOkResponse(requestId, new HealthCheckProvider().performHealthCheck());\r
+    private enum Target {\r
+        POLICY,\r
+        POLICY_TYPE,\r
+        OTHER\r
     }\r
 \r
+    private final ToscaServiceTemplateService toscaServiceTemplateService;\r
+    private final HealthCheckProvider healthCheckProvider;\r
+\r
     /**\r
-     * Retrieves the statistics report of the API component.\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("/statistics")\r
-    @ApiOperation(value = "Retrieve current statistics",\r
-        notes = "Returns current statistics including the counters of API invocation",\r
-        response = StatisticsReport.class,\r
-        responseHeaders = {\r
-            @ResponseHeader(name = "X-MinorVersion",\r
-                description = "Used to request or communicate a MINOR version back from the client"\r
-                    + " to the server, and from the server back to the client",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-PatchVersion",\r
-                description = "Used only to communicate a PATCH version in a response for"\r
-                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-ONAP-RequestID",\r
-                description = "Used to track REST transactions for logging purpose", response = UUID.class)},\r
-        authorizations = @Authorization(value = "basicAuth"), tags = {"Statistics",},\r
-        extensions = {\r
-            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),\r
-                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})\r
-    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),\r
-        @ApiResponse(code = 403, message = "Authorization Error"),\r
-        @ApiResponse(code = 500, message = "Internal Server Error")})\r
-    public Response\r
-        getStatistics(@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {\r
-\r
-        updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET);\r
-\r
-        return makeOkResponse(requestId, new StatisticsProvider().fetchCurrentStatistics());\r
+    @Override\r
+    public ResponseEntity<HealthCheckReport> getHealthCheck(UUID requestId) {\r
+        final var report = healthCheckProvider.performHealthCheck();\r
+        return makeResponse(requestId, report, report.getCode());\r
     }\r
 \r
     /**\r
@@ -172,42 +81,14 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @GET\r
-    @Path("/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
-        responseHeaders = {\r
-            @ResponseHeader(name = "X-MinorVersion",\r
-                description = "Used to request or communicate a MINOR version back from the client"\r
-                    + " to the server, and from the server back to the client",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-PatchVersion",\r
-                description = "Used only to communicate a PATCH version in a response for"\r
-                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-ONAP-RequestID",\r
-                description = "Used to track REST transactions for logging purpose", response = UUID.class)},\r
-        authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},\r
-        extensions = {\r
-            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),\r
-                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})\r
-    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),\r
-        @ApiResponse(code = 403, message = "Authorization Error"),\r
-        @ApiResponse(code = 500, message = "Internal Server Error")})\r
-    public Response\r
-        getAllPolicyTypes(@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {\r
-\r
-        try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {\r
-            ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(null, null);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);\r
+    @Override\r
+    public ResponseEntity<ToscaServiceTemplate> getAllPolicyTypes(UUID requestId) {\r
+        try {\r
+            ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicyTypes(null, null);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.debug("GET /policytypes", pfme);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);\r
-            return makeErrorResponse(requestId, pfme);\r
+            final var msg = "GET /policytypes";\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -218,44 +99,16 @@ 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
-    @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
-        responseHeaders = {\r
-            @ResponseHeader(name = "X-MinorVersion",\r
-                description = "Used to request or communicate a MINOR version back from the client"\r
-                    + " to the server, and from the server back to the client",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-PatchVersion",\r
-                description = "Used only to communicate a PATCH version in a response for"\r
-                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-ONAP-RequestID",\r
-                description = "Used to track REST transactions for logging purpose", response = UUID.class)},\r
-        authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},\r
-        extensions = {\r
-            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),\r
-                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})\r
-    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),\r
-        @ApiResponse(code = 403, message = "Authorization Error"),\r
-        @ApiResponse(code = 404, message = "Resource Not Found"),\r
-        @ApiResponse(code = 500, message = "Internal Server Error")})\r
-    public Response getAllVersionsOfPolicyType(\r
-        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
-        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {\r
-\r
-        try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {\r
-            ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, null);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);\r
+    @Override\r
+    public ResponseEntity<ToscaServiceTemplate> getAllVersionsOfPolicyType(\r
+            String policyTypeId,\r
+            UUID requestId) {\r
+        try {\r
+            ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicyTypes(policyTypeId, null);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.debug("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
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -267,44 +120,18 @@ 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
-    @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
-            @ResponseHeader(name = "X-MinorVersion",\r
-                description = "Used to request or communicate a MINOR version back from the client"\r
-                    + " to the server, and from the server back to the client",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-PatchVersion",\r
-                description = "Used only to communicate a PATCH version in a response for"\r
-                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-ONAP-RequestID",\r
-                description = "Used to track REST transactions for logging purpose", response = UUID.class)},\r
-        authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},\r
-        extensions = {\r
-            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),\r
-                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})\r
-    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),\r
-        @ApiResponse(code = 403, message = "Authorization Error"),\r
-        @ApiResponse(code = 404, message = "Resource Not Found"),\r
-        @ApiResponse(code = 500, message = "Internal Server Error")})\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("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {\r
-\r
-        try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {\r
-            ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, versionId);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);\r
+    @Override\r
+    public ResponseEntity<ToscaServiceTemplate> getSpecificVersionOfPolicyType(\r
+            String policyTypeId,\r
+            String versionId,\r
+            UUID requestId) {\r
+        try {\r
+            ToscaServiceTemplate serviceTemplate =\r
+                toscaServiceTemplateService.fetchPolicyTypes(policyTypeId, versionId);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.debug("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
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -315,43 +142,16 @@ 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
-    @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
-            @ResponseHeader(name = "X-MinorVersion",\r
-                description = "Used to request or communicate a MINOR version back from the client"\r
-                    + " to the server, and from the server back to the client",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-PatchVersion",\r
-                description = "Used only to communicate a PATCH version in a response for"\r
-                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-ONAP-RequestID",\r
-                description = "Used to track REST transactions for logging purpose", response = UUID.class)},\r
-        authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},\r
-        extensions = {\r
-            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),\r
-                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})\r
-    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),\r
-        @ApiResponse(code = 403, message = "Authorization Error"),\r
-        @ApiResponse(code = 404, message = "Resource Not Found"),\r
-        @ApiResponse(code = 500, message = "Internal Server Error")})\r
-    public Response getLatestVersionOfPolicyType(\r
-        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
-        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {\r
-\r
-        try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {\r
-            ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchLatestPolicyTypes(policyTypeId);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);\r
+    @Override\r
+    public ResponseEntity<ToscaServiceTemplate> getLatestVersionOfPolicyType(\r
+            String policyTypeId,\r
+            UUID requestId) {\r
+        try {\r
+            ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchLatestPolicyTypes(policyTypeId);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.debug("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
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -362,48 +162,19 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @POST\r
-    @Path("/policytypes")\r
-    @ApiOperation(value = "Create a new policy type", notes = "Client should provide TOSCA body of the new policy type",\r
-        authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},\r
-        response = ToscaServiceTemplate.class,\r
-        responseHeaders = {\r
-            @ResponseHeader(name = "X-MinorVersion",\r
-                description = "Used to request or communicate a MINOR version back from the client"\r
-                    + " to the server, and from the server back to the client",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-PatchVersion",\r
-                description = "Used only to communicate a PATCH version in a response for"\r
-                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-ONAP-RequestID",\r
-                description = "Used to track REST transactions for logging purpose", response = UUID.class)},\r
-        extensions = {\r
-            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),\r
-                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})\r
-    @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid Body"),\r
-        @ApiResponse(code = 401, message = "Authentication Error"),\r
-        @ApiResponse(code = 403, message = "Authorization Error"),\r
-        @ApiResponse(code = 406, message = "Not Acceptable Payload"),\r
-        @ApiResponse(code = 500, message = "Internal Server Error")})\r
-    public Response createPolicyType(\r
-        @ApiParam(value = "Entity body of policy type", required = true) ToscaServiceTemplate body,\r
-        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {\r
-\r
+    @Override\r
+    public ResponseEntity<ToscaServiceTemplate> createPolicyType(\r
+            ToscaServiceTemplate body,\r
+            UUID requestId) {\r
         if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {\r
             NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body));\r
         }\r
-\r
-        try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {\r
-            ToscaServiceTemplate serviceTemplate = policyTypeProvider.createPolicyType(body);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.POST);\r
+        try {\r
+            ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.createPolicyType(body);\r
             return makeOkResponse(requestId, serviceTemplate);\r
-        } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.debug("POST /policytypes", pfme);\r
-            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.POST);\r
-            return makeErrorResponse(requestId, pfme);\r
+        } catch (PfModelRuntimeException pfme) {\r
+            final var msg = "POST /policytypes";\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -415,46 +186,18 @@ 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
-    @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
-            + "The parameterizing TOSCA policies must be deleted first;",\r
-        authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},\r
-        response = ToscaServiceTemplate.class,\r
-        responseHeaders = {\r
-            @ResponseHeader(name = "X-MinorVersion",\r
-                description = "Used to request or communicate a MINOR version back from the client"\r
-                    + " to the server, and from the server back to the client",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-PatchVersion",\r
-                description = "Used only to communicate a PATCH version in a response for"\r
-                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-ONAP-RequestID",\r
-                description = "Used to track REST transactions for logging purpose", response = UUID.class)},\r
-        extensions = {\r
-            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),\r
-                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})\r
-    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),\r
-        @ApiResponse(code = 403, message = "Authorization Error"),\r
-        @ApiResponse(code = 404, message = "Resource Not Found"),\r
-        @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),\r
-        @ApiResponse(code = 500, message = "Internal Server Error")})\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("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {\r
-\r
-        try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {\r
-            ToscaServiceTemplate serviceTemplate = policyTypeProvider.deletePolicyType(policyTypeId, versionId);\r
+    @Override\r
+    public ResponseEntity<ToscaServiceTemplate> deleteSpecificVersionOfPolicyType(\r
+            String policyTypeId,\r
+            String versionId,\r
+            UUID requestId) {\r
+        try {\r
+            ToscaServiceTemplate serviceTemplate =\r
+                toscaServiceTemplateService.deletePolicyType(policyTypeId, versionId);\r
             return makeOkResponse(requestId, serviceTemplate);\r
-        } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.debug("DELETE /policytypes/{}/versions/{}", policyTypeId, versionId, pfme);\r
-            return makeErrorResponse(requestId, pfme);\r
+        } catch (PfModelRuntimeException pfme) {\r
+            var msg = String.format("DELETE /policytypes/%s/versions/%s", policyTypeId, versionId);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -466,61 +209,21 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    // @formatter:off\r
-    @GET\r
-    @Path("/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
-        response = ToscaServiceTemplate.class,\r
-        responseHeaders = {\r
-            @ResponseHeader(name = "X-MinorVersion",\r
-                description = "Used to request or communicate a MINOR version back from the client"\r
-                    + " to the server, and from the server back to the client",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-PatchVersion",\r
-                description = "Used only to communicate a PATCH version in a response for"\r
-                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-ONAP-RequestID",\r
-                description = "Used to track REST transactions for logging purpose", response = UUID.class)},\r
-        authorizations = @Authorization(value = "basicAuth"), tags = {"Policy,"},\r
-        extensions = {\r
-            @Extension(name = "interface info", properties = {\r
-                @ExtensionProperty(name = "api-version", value = "1.0.0"),\r
-                @ExtensionProperty(name = "last-mod-release", value = "Dublin")\r
-            })\r
-        }\r
-    )\r
-    @ApiResponses(value = {\r
-        @ApiResponse(code = 401, message = "Authentication Error"),\r
-        @ApiResponse(code = 403, message = "Authorization Error"),\r
-        @ApiResponse(code = 404, message = "Resource Not Found"),\r
-        @ApiResponse(code = 500, message = "Internal Server Error")\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
-            required = true) String policyTypeVersion,\r
-        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") 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 (PolicyProvider policyProvider = new PolicyProvider()) {\r
+    @Override\r
+    public ResponseEntity<ToscaServiceTemplate> getAllPolicies(\r
+            String policyTypeId,\r
+            String policyTypeVersion,\r
+            PolicyFetchMode mode,\r
+            UUID requestId) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate =\r
-                policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, null, null, mode);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);\r
+                toscaServiceTemplateService.fetchPolicies(policyTypeId, policyTypeVersion, null, null, mode);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.debug("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
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
-    // @formatter:on\r
 \r
     /**\r
      * Retrieves all versions of a particular policy.\r
@@ -531,59 +234,23 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    // @formatter:off\r
-    @GET\r
-    @Path("/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
-            @ResponseHeader(name = "X-MinorVersion",\r
-                description = "Used to request or communicate a MINOR version back from the client"\r
-                    + " to the server, and from the server back to the client",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-PatchVersion",\r
-                description = "Used only to communicate a PATCH version in a response for"\r
-                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-ONAP-RequestID",\r
-                description = "Used to track REST transactions for logging purpose", response = UUID.class)},\r
-        authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},\r
-        extensions = {\r
-            @Extension(name = "interface info", properties = {\r
-                @ExtensionProperty(name = "api-version", value = "1.0.0"),\r
-                @ExtensionProperty(name = "last-mod-release", value = "Dublin")\r
-            })\r
-        }\r
-    )\r
-    @ApiResponses(value = {\r
-        @ApiResponse(code = 401, message = "Authentication Error"),\r
-        @ApiResponse(code = 403, message = "Authorization Error"),\r
-        @ApiResponse(code = 404, message = "Resource Not Found"),\r
-        @ApiResponse(code = 500, message = "Internal Server Error")\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
-            required = true) String policyTypeVersion,\r
-        @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,\r
-        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") 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 (PolicyProvider policyProvider = new PolicyProvider()) {\r
+    @Override\r
+    public ResponseEntity<ToscaServiceTemplate> getAllVersionsOfPolicy(\r
+            String policyId,\r
+            String policyTypeId,\r
+            String policyTypeVersion,\r
+            PolicyFetchMode mode,\r
+            UUID requestId) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate =\r
-                policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null, mode);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);\r
+                toscaServiceTemplateService.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null, mode);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.debug("/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
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
-    // @formatter:on\r
 \r
     /**\r
      * Retrieves the specified version of a particular policy.\r
@@ -595,62 +262,24 @@ public class ApiRestController extends CommonRestController {
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    // @formatter:off\r
-    @GET\r
-    @Path("/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
-        responseHeaders = {\r
-            @ResponseHeader(name = "X-MinorVersion",\r
-                description = "Used to request or communicate a MINOR version back from the client"\r
-                    + " to the server, and from the server back to the client",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-PatchVersion",\r
-                description = "Used only to communicate a PATCH version in a response for"\r
-                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-ONAP-RequestID",\r
-                description = "Used to track REST transactions for logging purpose", response = UUID.class)},\r
-        authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},\r
-        extensions = {\r
-            @Extension(name = "interface info", properties = {\r
-                @ExtensionProperty(name = "api-version", value = "1.0.0"),\r
-                @ExtensionProperty(name = "last-mod-release", value = "Dublin")\r
-            })\r
-        }\r
-    )\r
-    @ApiResponses(value = {\r
-        @ApiResponse(code = 401, message = "Authentication Error"),\r
-        @ApiResponse(code = 403, message = "Authorization Error"),\r
-        @ApiResponse(code = 404, message = "Resource Not Found"),\r
-        @ApiResponse(code = 500, message = "Internal Server Error")\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
-            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("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") 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 (PolicyProvider policyProvider = new PolicyProvider()) {\r
-            ToscaServiceTemplate serviceTemplate =\r
-                policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);\r
+    @Override\r
+    public ResponseEntity<ToscaServiceTemplate> getSpecificVersionOfPolicy(\r
+            String policyId,\r
+            String policyTypeId,\r
+            String policyTypeVersion,\r
+            String policyVersion,\r
+            PolicyFetchMode mode,\r
+            UUID requestId) {\r
+        try {\r
+            ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService\r
+                .fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.debug("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
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
-    // @formatter:on\r
 \r
     /**\r
      * Retrieves the latest version of a particular policy.\r
@@ -661,50 +290,21 @@ 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
-    @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
-            @ResponseHeader(name = "X-MinorVersion",\r
-                description = "Used to request or communicate a MINOR version back from the client"\r
-                    + " to the server, and from the server back to the client",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-PatchVersion",\r
-                description = "Used only to communicate a PATCH version in a response for"\r
-                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-ONAP-RequestID",\r
-                description = "Used to track REST transactions for logging purpose", response = UUID.class)},\r
-        authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},\r
-        extensions = {\r
-            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),\r
-                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})\r
-    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),\r
-        @ApiResponse(code = 403, message = "Authorization Error"),\r
-        @ApiResponse(code = 404, message = "Resource Not Found"),\r
-        @ApiResponse(code = 500, message = "Internal Server Error")})\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
-            required = true) String policyTypeVersion,\r
-        @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,\r
-        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") 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 (PolicyProvider policyProvider = new PolicyProvider()) {\r
+    @Override\r
+    public ResponseEntity<ToscaServiceTemplate> getLatestVersionOfPolicy(\r
+            String policyId,\r
+            String policyTypeId,\r
+            String policyTypeVersion,\r
+            PolicyFetchMode mode,\r
+            UUID requestId) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate =\r
-                policyProvider.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId, mode);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);\r
+                toscaServiceTemplateService.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId, mode);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.debug("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
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
@@ -717,242 +317,144 @@ 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
-    @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 = "basicAuth"), tags = {"Policy",}, response = ToscaServiceTemplate.class,\r
-        responseHeaders = {\r
-            @ResponseHeader(name = "X-MinorVersion",\r
-                description = "Used to request or communicate a MINOR version back from the client"\r
-                    + " to the server, and from the server back to the client",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-PatchVersion",\r
-                description = "Used only to communicate a PATCH version in a response for"\r
-                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-ONAP-RequestID",\r
-                description = "Used to track REST transactions for logging purpose", response = UUID.class)},\r
-        extensions = {\r
-            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),\r
-                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})\r
-    @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid Body"),\r
-        @ApiResponse(code = 401, message = "Authentication Error"),\r
-        @ApiResponse(code = 403, message = "Authorization Error"),\r
-        @ApiResponse(code = 404, message = "Resource Not Found"),\r
-        @ApiResponse(code = 406, message = "Not Acceptable Payload"),\r
-        @ApiResponse(code = 500, message = "Internal Server Error")})\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
-            required = true) String policyTypeVersion,\r
-        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,\r
-        @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {\r
-\r
+    @Override\r
+    public ResponseEntity<ToscaServiceTemplate> createPolicy(\r
+            String policyTypeId,\r
+            String policyTypeVersion,\r
+            ToscaServiceTemplate body,\r
+            UUID requestId) {\r
         if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {\r
             NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,\r
                 "/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body));\r
         }\r
-\r
-        try (PolicyProvider policyProvider = new PolicyProvider()) {\r
-            ToscaServiceTemplate serviceTemplate = policyProvider.createPolicy(policyTypeId, policyTypeVersion, body);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.POST);\r
+        try {\r
+            ToscaServiceTemplate serviceTemplate =\r
+                toscaServiceTemplateService.createPolicy(policyTypeId, policyTypeVersion, body);\r
             return makeOkResponse(requestId, serviceTemplate);\r
-        } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.debug("POST /policytypes/{}/versions/{}/policies", policyTypeId, policyTypeVersion, pfme);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.POST);\r
-            return makeErrorResponse(requestId, pfme);\r
+        } catch (PfModelRuntimeException pfme) {\r
+            var msg = String.format("POST /policytypes/%s/versions/%s/policies", policyTypeId, policyTypeVersion);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
     /**\r
-     * Creates one or more new policies in one call.\r
+     * Deletes the specified version of a particular policy.\r
      *\r
-     * @param body the body of policy following TOSCA definition\r
+     * @param policyTypeId the ID of specified policy type\r
+     * @param policyTypeVersion the version of specified policy type\r
+     * @param policyId the ID of specified policy\r
+     * @param policyVersion the version of specified policy\r
      *\r
      * @return the Response object containing the results of the API operation\r
      */\r
-    @POST\r
-    @Path("/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 = "basicAuth"), tags = {"Policy",}, response = ToscaServiceTemplate.class,\r
-        responseHeaders = {\r
-            @ResponseHeader(name = "X-MinorVersion",\r
-                description = "Used to request or communicate a MINOR version back from the client"\r
-                    + " to the server, and from the server back to the client",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-PatchVersion",\r
-                description = "Used only to communicate a PATCH version in a response for"\r
-                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-ONAP-RequestID",\r
-                description = "Used to track REST transactions for logging purpose", response = UUID.class)},\r
-        extensions = {\r
-            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),\r
-                @ExtensionProperty(name = "last-mod-release", value = "El Alto")})})\r
-    @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid Body"),\r
-        @ApiResponse(code = 401, message = "Authentication Error"),\r
-        @ApiResponse(code = 403, message = "Authorization Error"),\r
-        @ApiResponse(code = 404, message = "Resource Not Found"),\r
-        @ApiResponse(code = 406, message = "Not Acceptable Payload"),\r
-        @ApiResponse(code = 500, message = "Internal Server Error")})\r
-    public Response createPolicies(\r
-        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,\r
-        @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {\r
-\r
-        if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {\r
-            NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policies", toJson(body));\r
+    @Override\r
+    public ResponseEntity<ToscaServiceTemplate> deleteSpecificVersionOfPolicy(\r
+        String policyTypeId,\r
+        String policyTypeVersion,\r
+        String policyId,\r
+        String policyVersion,\r
+        UUID requestId) {\r
+        try {\r
+            ToscaServiceTemplate serviceTemplate =\r
+                toscaServiceTemplateService.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);\r
+            return makeOkResponse(requestId, serviceTemplate);\r
+        } catch (PfModelRuntimeException pfme) {\r
+            var msg = String.format("DELETE /policytypes/%s/versions/%s/policies/%s/versions/%s",\r
+                policyTypeId, policyTypeVersion, policyId, policyVersion);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
+    }\r
 \r
-        try (PolicyProvider policyProvider = new PolicyProvider()) {\r
-            ToscaServiceTemplate serviceTemplate = policyProvider.createPolicies(body);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.POST);\r
+    /**\r
+     * Retrieves all the available policies.\r
+     *\r
+     * @return the Response object containing the results of the API operation\r
+     */\r
+    @Override\r
+    public ResponseEntity<ToscaServiceTemplate> getPolicies(\r
+            PolicyFetchMode mode,\r
+            UUID requestId) {\r
+        try {\r
+            ToscaServiceTemplate serviceTemplate =\r
+                toscaServiceTemplateService.fetchPolicies(null, null, null, null, mode);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.debug("POST /policies", pfme);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.POST);\r
-            return makeErrorResponse(requestId, pfme);\r
+            final var msg = "GET /policies/ --";\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
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
     /**\r
-     * Deletes the specified version of a particular policy.\r
+     * Retrieves the specified version of a particular policy.\r
      *\r
-     * @param policyTypeId the ID of specified policy type\r
-     * @param policyTypeVersion the version of specified policy type\r
-     * @param policyId the ID of specified policy\r
+     * @param policyId the Name of specified policy\r
      * @param policyVersion the version of specified policy\r
      *\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
-    @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 = "basicAuth"), tags = {"Policy",}, response = ToscaServiceTemplate.class,\r
-        responseHeaders = {\r
-            @ResponseHeader(name = "X-MinorVersion",\r
-                description = "Used to request or communicate a MINOR version back from the client"\r
-                    + " to the server, and from the server back to the client",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-PatchVersion",\r
-                description = "Used only to communicate a PATCH version in a response for"\r
-                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",\r
-                response = String.class),\r
-            @ResponseHeader(name = "X-ONAP-RequestID",\r
-                description = "Used to track REST transactions for logging purpose", response = UUID.class)},\r
-        extensions = {\r
-            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),\r
-                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})\r
-    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),\r
-        @ApiResponse(code = 403, message = "Authorization Error"),\r
-        @ApiResponse(code = 404, message = "Resource Not Found"),\r
-        @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),\r
-        @ApiResponse(code = 500, message = "Internal Server Error")})\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
-            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("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {\r
-\r
-        try (PolicyProvider policyProvider = new PolicyProvider()) {\r
+    @Override\r
+    public ResponseEntity<ToscaServiceTemplate> getSpecificPolicy(\r
+            String policyId,\r
+            String policyVersion,\r
+            PolicyFetchMode mode,\r
+            UUID requestId) {\r
+        try {\r
             ToscaServiceTemplate serviceTemplate =\r
-                policyProvider.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);\r
+                toscaServiceTemplateService.fetchPolicies(null, null, policyId, policyVersion, mode);\r
             return makeOkResponse(requestId, serviceTemplate);\r
         } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.debug("DELETE /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId, policyTypeVersion,\r
-                policyId, policyVersion, pfme);\r
-            return makeErrorResponse(requestId, pfme);\r
+            var msg = String.format("GET /policies/%s/versions/%s", policyId, policyVersion);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\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
-    }\r
-\r
-    private void updateApiStatisticsCounter(Target target, Result result, HttpMethod http) {\r
-\r
-        ApiStatisticsManager.updateTotalApiCallCount();\r
-\r
-        switch (target) {\r
-            case POLICY:\r
-                updatePolicyStats(result, http);\r
-                break;\r
-            case POLICY_TYPE:\r
-                updatePolicyTypeStats(result, http);\r
-                break;\r
-            default:\r
-                ApiStatisticsManager.updateApiCallSuccessCount();\r
-                break;\r
+    /**\r
+     * Creates one or more new policies in one call.\r
+     *\r
+     * @param body the body of policy following TOSCA definition\r
+     *\r
+     * @return the Response object containing the results of the API operation\r
+     */\r
+    @Override\r
+    public ResponseEntity<ToscaServiceTemplate> createPolicies(\r
+        ToscaServiceTemplate body,\r
+        UUID requestId) {\r
+        if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {\r
+            NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policies", toJson(body));\r
         }\r
-    }\r
-\r
-    private void updatePolicyStats(Result result, HttpMethod http) {\r
-        if (result == Result.SUCCESS) {\r
-            if (http == HttpMethod.GET) {\r
-                ApiStatisticsManager.updateApiCallSuccessCount();\r
-                ApiStatisticsManager.updateTotalPolicyGetCount();\r
-                ApiStatisticsManager.updatePolicyGetSuccessCount();\r
-            } else if (http == HttpMethod.POST) {\r
-                ApiStatisticsManager.updateApiCallSuccessCount();\r
-                ApiStatisticsManager.updateTotalPolicyPostCount();\r
-                ApiStatisticsManager.updatePolicyPostSuccessCount();\r
-            }\r
-        } else {\r
-            if (http == HttpMethod.GET) {\r
-                ApiStatisticsManager.updateApiCallFailureCount();\r
-                ApiStatisticsManager.updateTotalPolicyGetCount();\r
-                ApiStatisticsManager.updatePolicyGetFailureCount();\r
-            } else {\r
-                ApiStatisticsManager.updateApiCallFailureCount();\r
-                ApiStatisticsManager.updateTotalPolicyPostCount();\r
-                ApiStatisticsManager.updatePolicyPostFailureCount();\r
-            }\r
+        try {\r
+            ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.createPolicies(body);\r
+            return makeOkResponse(requestId, serviceTemplate);\r
+        } catch (PfModelRuntimeException pfme) {\r
+            final var msg = "POST /policies";\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
 \r
-    private void updatePolicyTypeStats(Result result, HttpMethod http) {\r
-        if (result == Result.SUCCESS) {\r
-            if (http == HttpMethod.GET) {\r
-                ApiStatisticsManager.updateApiCallSuccessCount();\r
-                ApiStatisticsManager.updateTotalPolicyTypeGetCount();\r
-                ApiStatisticsManager.updatePolicyTypeGetSuccessCount();\r
-            } else if (http == HttpMethod.POST) {\r
-                ApiStatisticsManager.updateApiCallSuccessCount();\r
-                ApiStatisticsManager.updatePolicyTypePostSuccessCount();\r
-                ApiStatisticsManager.updatePolicyTypePostSuccessCount();\r
-            }\r
-        } else {\r
-            if (http == HttpMethod.GET) {\r
-                ApiStatisticsManager.updateApiCallFailureCount();\r
-                ApiStatisticsManager.updateTotalPolicyTypeGetCount();\r
-                ApiStatisticsManager.updatePolicyTypeGetFailureCount();\r
-            } else {\r
-                ApiStatisticsManager.updateApiCallFailureCount();\r
-                ApiStatisticsManager.updateTotalPolicyTypePostCount();\r
-                ApiStatisticsManager.updatePolicyTypePostFailureCount();\r
-            }\r
+    /**\r
+     * Deletes the specified version of a particular policy.\r
+     *\r
+     * @param policyId the ID of specified policy\r
+     * @param policyVersion the version of specified policy\r
+     *\r
+     * @return the Response object containing the results of the API operation\r
+     */\r
+    @Override\r
+    public ResponseEntity<ToscaServiceTemplate> deleteSpecificPolicy(\r
+        String policyId,\r
+        String policyVersion,\r
+        UUID requestId) {\r
+        try {\r
+            ToscaServiceTemplate serviceTemplate =\r
+                toscaServiceTemplateService.deletePolicy(null, null, policyId, policyVersion);\r
+            return makeOkResponse(requestId, serviceTemplate);\r
+        } catch (PfModelRuntimeException pfme) {\r
+            var msg = String.format("DELETE /policies/%s/versions/%s", policyId, policyVersion);\r
+            throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
         }\r
     }\r
-}
\ No newline at end of file
+}\r