Fix for Push/Unpush Policy On GUI 59/106459/2
authoruj426b <uj426b@att.com>
Wed, 22 Apr 2020 16:46:19 +0000 (12:46 -0400)
committeruj426b <uj426b@att.com>
Wed, 22 Apr 2020 17:40:01 +0000 (13:40 -0400)
Issue-ID: POLICY-2518
Change-Id: Ie70fc5049f87b55384731900373884d8b25803bb
Signed-off-by: uj426b <uj426b@att.com>
ONAP-XACML/src/main/java/org/onap/policy/xacml/api/pap/PAPPolicyEngine.java
ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java
POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java
POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java
POLICY-SDK-APP/src/test/java/org/onap/policy/admin/RESTfulPAPEngineTest.java

index cfb1434..62255ff 100644 (file)
@@ -61,7 +61,7 @@ public interface PAPPolicyEngine {
             throws PAPException;
 
     // copy the given policy file into the group's directory, but do not include the policy in the group's policy set
-    public void copyPolicy(PDPPolicy policy, OnapPDPGroup group) throws PAPException;
+    public void copyPolicy(PDPPolicy policy, OnapPDPGroup group, String userId) throws PAPException;
 
     public void removePolicy(PDPPolicy policy, OnapPDPGroup group) throws PAPException;
 
index 1fb2518..d2d50a5 100644 (file)
@@ -550,7 +550,7 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
     }
 
     @Override
-    public void copyPolicy(PDPPolicy policy, OnapPDPGroup group) throws PAPException {
+    public void copyPolicy(PDPPolicy policy, OnapPDPGroup group, String userId) throws PAPException {
         //
         // Currently not used on the PAP side. This is done by ((StdPDPGroup) group).copyPolicyToFile
         //
index ff72e02..d89dd27 100644 (file)
@@ -270,7 +270,7 @@ public class RESTfulPAPEngine extends StdPDPItemSetChangeNotifier implements PAP
     public void publishPolicy(String id, String name, boolean isRoot, InputStream policy, OnapPDPGroup group)
             throws PAPException {
         // copy the (one) file into the target directory on the PAP servlet
-        copyFile(id, group, policy);
+        copyFile(id, group, policy, null);
 
         // adjust the local copy of the group to include the new policy
         PDPPolicy pdpPolicy = new StdPDPPolicy(id, isRoot, name);
@@ -289,10 +289,10 @@ public class RESTfulPAPEngine extends StdPDPItemSetChangeNotifier implements PAP
      * @param policy Input stream of policy
      * @throws PAPException exception
      */
-    public void copyFile(String policyId, OnapPDPGroup group, InputStream policy) throws PAPException {
+    public void copyFile(String policyId, OnapPDPGroup group, InputStream policy, String usrId) throws PAPException {
         // send the policy file to the PAP Servlet
         try {
-            sendToPap("POST", policy, null, null, GROUP_ID + group.getId(), "policyId=" + policyId);
+            sendToPap("POST", policy, null, null, GROUP_ID + group.getId(), "policyId=" + policyId, "userId=" + usrId );
         } catch (Exception e) {
             String message = UNABLE_MSG + policyId + EXCEPTION_MSG + e;
             LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + message, e);
@@ -301,12 +301,12 @@ public class RESTfulPAPEngine extends StdPDPItemSetChangeNotifier implements PAP
     }
 
     @Override
-    public void copyPolicy(PDPPolicy policy, OnapPDPGroup group) throws PAPException {
+    public void copyPolicy(PDPPolicy policy, OnapPDPGroup group, String userId) throws PAPException {
         if (policy == null || group == null) {
             throw new PAPException("Null input policy=" + policy + "  group=" + group);
         }
         try (InputStream is = new FileInputStream(new File(policy.getLocation()))) {
-            copyFile(policy.getId(), group, is);
+            copyFile(policy.getId(), group, is, userId);
         } catch (Exception e) {
             String message = UNABLE_MSG + policy.getId() + EXCEPTION_MSG + e;
             LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + message, e);
index e8217b9..dc342ee 100644 (file)
@@ -293,7 +293,7 @@ public class AutoPushController extends RestrictedBaseController {
                         }
                         // copy policy to PAP
                         try {
-                            controller.getPapEngine().copyPolicy(selectedPolicy, (StdPDPGroup) pdpDestinationGroupId);
+                            controller.getPapEngine().copyPolicy(selectedPolicy, (StdPDPGroup) pdpDestinationGroupId, userId);
                         } catch (PAPException e) {
                             logger.error("Exception Occured" + e);
                             return null;
@@ -390,7 +390,7 @@ public class AutoPushController extends RestrictedBaseController {
                 updatedGroupObject.setPipConfigs(group.getPipConfigs());
                 updatedGroupObject.setStatus(group.getStatus());
                 updatedGroupObject.setOperation("delete");
-                this.container.updateGroup(updatedGroupObject);
+                this.container.updateGroup(updatedGroupObject, userId);
             }
 
             response.setContentType(PolicyUtils.APPLICATION_JSON);
index ec2643f..0deb3d6 100644 (file)
@@ -51,6 +51,7 @@ public class RESTfulPAPEngineTest {
     private String policyType = "testType";
     private String policyContent = "testContent";
     private int jmxport = 0;
+    private String userId = "testId";
     OnapPDPGroup group = Mockito.mock(OnapPDPGroup.class);
     OnapPDPGroup newGroup = Mockito.mock(OnapPDPGroup.class);
     OnapPDP pdp = Mockito.mock(OnapPDP.class);
@@ -159,10 +160,10 @@ public class RESTfulPAPEngineTest {
             engine.publishPolicy(id, name, false, policy, newGroup)
         );
 
-        engine.copyFile(id, newGroup, policy);
+        engine.copyFile(id, newGroup, policy, userId);
         PDPPolicy pdpPolicy = Mockito.mock(PDPPolicy.class);
         assertThatExceptionOfType(PAPException.class).isThrownBy(() ->
-            engine.copyPolicy(pdpPolicy, newGroup)
+            engine.copyPolicy(pdpPolicy, newGroup, userId)
         );
 
         assertThatExceptionOfType(PAPException.class).isThrownBy(() ->
@@ -170,7 +171,7 @@ public class RESTfulPAPEngineTest {
         );
 
         assertThatExceptionOfType(PAPException.class).isThrownBy(() ->
-            engine.copyPolicy(null, null)
+            engine.copyPolicy(null, null, null)
         );
 
         //