aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeleteProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeleteProvider.java')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeleteProvider.java40
1 files changed, 32 insertions, 8 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeleteProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeleteProvider.java
index 7a3190be..0ca32451 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeleteProvider.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeleteProvider.java
@@ -20,7 +20,9 @@
package org.onap.policy.pap.main.rest.depundep;
+import java.util.Iterator;
import java.util.function.BiFunction;
+import java.util.function.Predicate;
import javax.ws.rs.core.Response.Status;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pdp.concepts.PdpGroup;
@@ -117,20 +119,42 @@ public class PdpGroupDeleteProvider extends ProviderBase {
}
/**
- * Returns a function that will remove the specified policy from a subgroup.
+ * Returns a function that will remove the desired policy from a subgroup.
*/
@Override
- protected BiFunction<PdpGroup, PdpSubGroup, Boolean> makeUpdater(ToscaPolicy policy) {
- ToscaPolicyIdentifier desiredIdent = policy.getIdentifier();
+ protected BiFunction<PdpGroup, PdpSubGroup, Boolean> makeUpdater(ToscaPolicy policy,
+ ToscaPolicyIdentifierOptVersion desiredIdent) {
- // remove the policy from the subgroup
+ // construct a matcher based on whether or not the version was specified
+ Predicate<ToscaPolicyIdentifier> matcher;
+
+ if (desiredIdent.getVersion() != null) {
+ // version was specified - match the whole identifier
+ matcher = policy.getIdentifier()::equals;
+
+ } else {
+ // version was not specified - match the name only
+ String desnm = desiredIdent.getName();
+ matcher = ident -> ident.getName().equals(desnm);
+ }
+
+
+ // return a function that will remove the policy from the subgroup
return (group, subgroup) -> {
- boolean result = subgroup.getPolicies().remove(desiredIdent);
+ boolean result = false;
+
+ Iterator<ToscaPolicyIdentifier> iter = subgroup.getPolicies().iterator();
+ while (iter.hasNext()) {
+ ToscaPolicyIdentifier ident = iter.next();
- logger.info("remove policy {} {} from subgroup {} {} count={}", desiredIdent.getName(),
- desiredIdent.getVersion(), group.getName(), subgroup.getPdpType(),
- subgroup.getPolicies().size());
+ if (matcher.test(ident)) {
+ result = true;
+ iter.remove();
+ logger.info("remove policy {} {} from subgroup {} {} count={}", ident.getName(), ident.getVersion(),
+ group.getName(), subgroup.getPdpType(), subgroup.getPolicies().size());
+ }
+ }
return result;
};