Fix xacml pdp to accommodate Object values in policy metadata 76/127076/1
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>
Fri, 11 Feb 2022 08:53:57 +0000 (08:53 +0000)
committerRamesh Murugan Iyer <ramesh.murugan.iyer@est.tech>
Fri, 11 Feb 2022 09:29:32 +0000 (09:29 +0000)
Issue-ID: POLICY-3832
Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech>
Change-Id: I276bf28d3fdaad6e1d7cde315cdb049343cbde3f

applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java
applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java
applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java
applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java
applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java
tutorials/tutorial-xacml-application/src/main/java/org/onap/policy/tutorial/tutorial/TutorialTranslator.java

index 58bdafa..d1c6d38 100644 (file)
@@ -187,7 +187,7 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
      * @throws ToscaPolicyConversionException If there is something missing from the metadata
      */
     protected PolicyType fillMetadataSection(PolicyType policy,
-            Map<String, String> map) throws ToscaPolicyConversionException {
+            Map<String, Object> map) throws ToscaPolicyConversionException {
         //
         // Ensure the policy-id exists - we don't use it here. It
         // is saved in the TOSCA Policy Name field.
@@ -205,7 +205,7 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
         //
         // Add in the Policy Version
         //
-        policy.setVersion(map.get(POLICY_VERSION));
+        policy.setVersion(String.valueOf(map.get(POLICY_VERSION)));
         return policy;
     }
 
index 2a4574e..64a7db9 100644 (file)
@@ -69,7 +69,7 @@ public class StdCombinedPolicyResultsTranslator extends StdBaseTranslator {
         //
         // Get the policy Id
         //
-        String policyId = toscaPolicy.getMetadata().get(POLICY_ID);
+        String policyId = String.valueOf(toscaPolicy.getMetadata().get(POLICY_ID));
         //
         // Set it as the policy ID
         //
index e473de8..732542a 100644 (file)
@@ -251,7 +251,7 @@ public class StdMatchableTranslator  extends StdBaseTranslator implements Matcha
         //
         // Policy name should be at the root
         //
-        String policyName = toscaPolicy.getMetadata().get(POLICY_ID);
+        String policyName = String.valueOf(toscaPolicy.getMetadata().get(POLICY_ID));
         //
         // Set it as the policy ID
         //
index 6e60fe7..75af448 100644 (file)
@@ -254,7 +254,7 @@ public class StdBaseTranslatorTest {
     }
 
     private class TestTranslator extends StdBaseTranslator {
-        public Map<String, String> metadata = new HashMap<>();
+        public Map<String, Object> metadata = new HashMap<>();
 
         @Override
         protected void scanObligations(Collection<Obligation> obligations, DecisionResponse decisionResponse) {
index 3aae5fc..45caf21 100644 (file)
@@ -129,7 +129,7 @@ public class GuardTranslator implements ToscaPolicyTranslator {
         //
         // Policy name should be at the root
         //
-        String policyName = toscaPolicy.getMetadata().get("policy-id");
+        String policyName = String.valueOf(toscaPolicy.getMetadata().get("policy-id"));
         //
         // Set it as the policy ID
         //
@@ -275,14 +275,14 @@ public class GuardTranslator implements ToscaPolicyTranslator {
      * @param map The Metadata TOSCA Map
      * @return Same Policy Object
      */
-    protected PolicyType fillMetadataSection(PolicyType policy, Map<String, String> map) {
+    protected PolicyType fillMetadataSection(PolicyType policy, Map<String, Object> map) {
         //
         // NOTE: The models code ensures the metadata section ALWAYS exists
         //
         //
         // Add in the Policy Version
         //
-        policy.setVersion(map.get("policy-version"));
+        policy.setVersion(String.valueOf(map.get("policy-version")));
         return policy;
     }
 
index 327a507..b30dd94 100644 (file)
@@ -76,8 +76,8 @@ public class TutorialTranslator extends StdBaseTranslator {
         // Here is our policy with a version and default combining algo
         //
         var newPolicyType = new PolicyType();
-        newPolicyType.setPolicyId(toscaPolicy.getMetadata().get("policy-id"));
-        newPolicyType.setVersion(toscaPolicy.getMetadata().get("policy-version"));
+        newPolicyType.setPolicyId(String.valueOf(toscaPolicy.getMetadata().get("policy-id")));
+        newPolicyType.setVersion(String.valueOf(toscaPolicy.getMetadata().get("policy-version")));
         //
         // When choosing the rule combining algorithm, be sure to be mindful of the
         // setting xacml.att.policyFinderFactory.combineRootPolicies in the