Fix api sonar bugs - logging exceptions
[policy/api.git] / main / src / main / java / org / onap / policy / api / main / rest / LegacyApiRestController.java
index c3e7356..f668881 100644 (file)
@@ -50,6 +50,8 @@ import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Class to provide legacy REST API services.
@@ -62,6 +64,8 @@ import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
 @Consumes("application/json")
 public class LegacyApiRestController {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(LegacyApiRestController.class);
+
     /**
      * Retrieves all versions of a particular guard policy.
      *
@@ -70,7 +74,7 @@ public class LegacyApiRestController {
      * @return the Response object containing the results of the API operation
      */
     @GET
-    @Path("/policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies/{policyId}")
+    @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}")
     @ApiOperation(value = "Retrieve all versions of a particular guard policy",
             notes = "Returns a list of all versions of the specified guard policy",
             response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
@@ -114,6 +118,8 @@ public class LegacyApiRestController {
             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
                     .entity(policies).build();
         } catch (PfModelException | PfModelRuntimeException pfme) {
+            LOGGER.error("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}",
+                    policyId, pfme);
             return addLoggingHeaders(addVersionControlHeaders(
                     Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
                     .entity(pfme.getErrorResponse()).build();
@@ -129,7 +135,7 @@ public class LegacyApiRestController {
      * @return the Response object containing the results of the API operation
      */
     @GET
-    @Path("/policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies/{policyId}/versions/{policyVersion}")
+    @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}/versions/{policyVersion}")
     @ApiOperation(value = "Retrieve one version of a particular guard policy",
             notes = "Returns a particular version of a specified guard policy",
             response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
@@ -175,6 +181,8 @@ public class LegacyApiRestController {
             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
                     .entity(policies).build();
         } catch (PfModelException | PfModelRuntimeException pfme) {
+            LOGGER.error("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}/versions/{}",
+                    policyId, policyVersion, pfme);
             return addLoggingHeaders(addVersionControlHeaders(
                     Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
                     .entity(pfme.getErrorResponse()).build();
@@ -189,7 +197,7 @@ public class LegacyApiRestController {
      * @return the Response object containing the results of the API operation
      */
     @POST
-    @Path("/policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies")
+    @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies")
     @ApiOperation(value = "Create a new guard policy",
             notes = "Client should provide entity body of the new guard policy",
             authorizations = @Authorization(value = "basicAuth"),
@@ -233,6 +241,7 @@ public class LegacyApiRestController {
             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
                     .entity(policy).build();
         } catch (PfModelException | PfModelRuntimeException pfme) {
+            LOGGER.error("POST /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies", pfme);
             return addLoggingHeaders(addVersionControlHeaders(
                     Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
                     .entity(pfme.getErrorResponse()).build();
@@ -248,7 +257,7 @@ public class LegacyApiRestController {
      * @return the Response object containing the results of the API operation
      */
     @DELETE
-    @Path("/policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies/{policyId}/versions/{policyVersion}")
+    @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}/versions/{policyVersion}")
     @ApiOperation(value = "Delete a particular version of a guard policy",
             notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
             authorizations = @Authorization(value = "basicAuth"),
@@ -295,6 +304,8 @@ public class LegacyApiRestController {
             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
                     .entity(policies).build();
         } catch (PfModelException | PfModelRuntimeException pfme) {
+            LOGGER.error("DELETE /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}/versions/{}",
+                    policyId, policyVersion, pfme);
             return addLoggingHeaders(addVersionControlHeaders(
                     Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
                     .entity(pfme.getErrorResponse()).build();
@@ -309,7 +320,7 @@ public class LegacyApiRestController {
      * @return the Response object containing the results of the API operation
      */
     @GET
-    @Path("/policytypes/onap.policy.controlloop.operational/versions/1.0.0/policies/{policyId}")
+    @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/{policyId}")
     @ApiOperation(value = "Retrieve all versions of a particular operational policy",
             notes = "Returns a list of all versions of the specified operational policy",
             response = LegacyOperationalPolicy.class,
@@ -353,6 +364,8 @@ public class LegacyApiRestController {
             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
                     .entity(policy).build();
         } catch (PfModelException | PfModelRuntimeException pfme) {
+            LOGGER.error("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/{}",
+                    policyId, pfme);
             return addLoggingHeaders(addVersionControlHeaders(
                     Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
                     .entity(pfme.getErrorResponse()).build();
@@ -368,7 +381,7 @@ public class LegacyApiRestController {
      * @return the Response object containing the results of the API operation
      */
     @GET
-    @Path("/policytypes/onap.policy.controlloop.operational/versions/1.0.0/"
+    @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
          + "policies/{policyId}/versions/{policyVersion}")
     @ApiOperation(value = "Retrieve one version of a particular operational policy",
             notes = "Returns a particular version of a specified operational policy",
@@ -414,6 +427,8 @@ public class LegacyApiRestController {
             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
                     .entity(policy).build();
         } catch (PfModelException | PfModelRuntimeException pfme) {
+            LOGGER.error("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
+                + "policies/{}/versions/{}", policyId, policyVersion, pfme);
             return addLoggingHeaders(addVersionControlHeaders(
                     Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
                     .entity(pfme.getErrorResponse()).build();
@@ -428,7 +443,7 @@ public class LegacyApiRestController {
      * @return the Response object containing the results of the API operation
      */
     @POST
-    @Path("/policytypes/onap.policy.controlloop.operational/versions/1.0.0/policies")
+    @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies")
     @ApiOperation(value = "Create a new operational policy",
             notes = "Client should provide entity body of the new operational policy",
             authorizations = @Authorization(value = "basicAuth"),
@@ -472,6 +487,7 @@ public class LegacyApiRestController {
             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
                     .entity(policy).build();
         } catch (PfModelException | PfModelRuntimeException pfme) {
+            LOGGER.error("POST /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies", pfme);
             return addLoggingHeaders(addVersionControlHeaders(
                     Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
                     .entity(pfme.getErrorResponse()).build();
@@ -487,7 +503,7 @@ public class LegacyApiRestController {
      * @return the Response object containing the results of the API operation
      */
     @DELETE
-    @Path("/policytypes/onap.policy.controlloop.operational/versions/1.0.0/"
+    @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
          + "policies/{policyId}/versions/{policyVersion}")
     @ApiOperation(value = "Delete a particular version of a specified operational policy",
             notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
@@ -535,6 +551,8 @@ public class LegacyApiRestController {
             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
                     .entity(policy).build();
         } catch (PfModelException | PfModelRuntimeException pfme) {
+            LOGGER.error("DELETE /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
+                + "policies/{}/versions/{}", policyId, policyVersion, pfme);
             return addLoggingHeaders(addVersionControlHeaders(
                     Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
                     .entity(pfme.getErrorResponse()).build();