PolicyAudit creation when deploy/undeploy triggered.
[policy/pap.git] / main / src / main / java / org / onap / policy / pap / main / rest / PdpGroupDeployControllerV1.java
index 890d40b..d8fe8fe 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -50,8 +51,8 @@ public class PdpGroupDeployControllerV1 extends PapRestControllerV1 {
     public static final String POLICY_STATUS_URI = "/policy/pap/v1/policies/status";
 
     public static final String DEPLOYMENT_RESPONSE_MSG = "Use the policy status url to fetch the latest status. "
-        + "Kindly note that when a policy is successfully undeployed,"
-        + " it will no longer appear in policy status response.";
+            + "Kindly note that when a policy is successfully undeployed,"
+            + " it will no longer appear in policy status response.";
 
     private static final Logger logger = LoggerFactory.getLogger(PdpGroupDeployControllerV1.class);
 
@@ -90,10 +91,10 @@ public class PdpGroupDeployControllerV1 extends PapRestControllerV1 {
     // @formatter:on
 
     public Response updateGroupPolicies(
-                    @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
-                    @ApiParam(value = "List of PDP Group Deployments", required = true) DeploymentGroups groups) {
-
-        return doOperation(requestId, "update policy deployments failed", () -> provider.updateGroupPolicies(groups));
+            @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+            @ApiParam(value = "List of PDP Group Deployments", required = true) DeploymentGroups groups) {
+        return doOperation(requestId, "update policy deployments failed",
+                () -> provider.updateGroupPolicies(groups, getPrincipal()));
     }
 
     /**
@@ -129,10 +130,9 @@ public class PdpGroupDeployControllerV1 extends PapRestControllerV1 {
     // @formatter:on
 
     public Response deployPolicies(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
-                    @ApiParam(value = "PDP Policies; only the name is required",
-                                    required = true) PdpDeployPolicies policies) {
-
-        return doOperation(requestId, "deploy policies failed", () -> provider.deployPolicies(policies));
+            @ApiParam(value = "PDP Policies; only the name is required", required = true) PdpDeployPolicies policies) {
+        return doOperation(requestId, "deploy policies failed",
+                () -> provider.deployPolicies(policies, getPrincipal()));
     }
 
     /**
@@ -147,15 +147,14 @@ public class PdpGroupDeployControllerV1 extends PapRestControllerV1 {
         try {
             runnable.run();
             return addLoggingHeaders(addVersionControlHeaders(Response.status(Status.ACCEPTED)), requestId)
-                .entity(new PdpGroupDeployResponse(DEPLOYMENT_RESPONSE_MSG, POLICY_STATUS_URI))
-                .build();
+                    .entity(new PdpGroupDeployResponse(DEPLOYMENT_RESPONSE_MSG, POLICY_STATUS_URI)).build();
 
         } catch (PfModelException | PfModelRuntimeException e) {
             logger.warn(errmsg, e);
             var resp = new PdpGroupDeployResponse();
             resp.setErrorDetails(e.getErrorResponse().getErrorMessage());
             return addLoggingHeaders(addVersionControlHeaders(Response.status(e.getErrorResponse().getResponseCode())),
-                requestId).entity(resp).build();
+                    requestId).entity(resp).build();
         }
     }
 }