X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=applications%2Fcommon%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpdp%2Fxacml%2Fapplication%2Fcommon%2FXacmlPolicyUtils.java;h=2a5f21f031326e2d03f90832360c3746059b11f9;hb=432cec9fa6f143dad324cd11f62fb052c7da32b7;hp=364b651913c83f882d29da79dfe6d95902a0bf77;hpb=4013653daa38a7fe1b9ffcae02e27d0bc411ac8f;p=policy%2Fxacml-pdp.git diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java index 364b6519..2a5f21f0 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java @@ -214,6 +214,50 @@ public class XacmlPolicyUtils { return properties; } + /** + * Removes a root policy from the Properties object. Both in the line + * that identifies the policy and the .file property that points to the path. + * + * @param properties Input Properties object to remove + * @param rootPolicyPath The policy file path + * @return Properties object + */ + public static Properties removeRootPolicy(Properties properties, Path rootPolicyPath) { + // + // Get the current set of referenced policy ids + // + StringJoiner join = new StringJoiner(","); + boolean found = false; + Set rootPolicies = XACMLProperties.getRootPolicyIDs(properties); + for (String refPolicy : rootPolicies) { + String refPolicyFile = refPolicy + DOT_FILE_SUFFIX; + // + // If the key and value match, then it will return true + // + if (properties.remove(refPolicyFile, rootPolicyPath.toString())) { + // + // Record that we actually removed it + // + found = true; + } else { + // + // Retain it + // + join.add(refPolicy); + } + } + // + // Did we remove it? + // + if (found) { + // + // Now update the list of referenced properties + // + properties.setProperty(XACMLProperties.PROP_ROOTPOLICIES, join.toString()); + } + return properties; + } + /** * Removes a referenced policy from the Properties object. Both in the line * that identifies the policy and the .file property that points to the path.