diff options
author | liamfallon <liam.fallon@est.tech> | 2019-04-06 05:19:43 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2019-04-06 05:19:43 +0000 |
commit | 422412ec8f21017aff1641f133c2258f52f7d706 (patch) | |
tree | 414568b6815d92d70c75e9bab9c456968d0e2d2f /models-pdp/src/main/java | |
parent | 52229882d7ee3e934641de0bd2df74ed1268130e (diff) |
Fix bugs on filters
Filters were not being invoked from providers.
Filter for getting latest version was filtering out everything
Filter on PDP state was not implemented.
Issue-ID: POLICY-1095
Change-Id: If43ce48a57b010e05f75db8cfa80e63f2719ace1
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-pdp/src/main/java')
-rw-r--r-- | models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java | 26 | ||||
-rw-r--r-- | models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java | 2 |
2 files changed, 26 insertions, 2 deletions
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java index c5c0bc541..5965b728d 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java @@ -68,11 +68,12 @@ public class PdpGroupFilter implements PfObjectFilter<PdpGroup> { // @formatter:off List<PdpGroup> returnList = originalList.stream() .filter(p -> filterOnRegexp(p.getName(), name)) - .filter(p -> filterOnRegexp(p.getVersion(), version)) + .filter(p -> version.equals(LATEST_VERSION) || filterOnRegexp(p.getVersion(), version)) .filter(p -> ObjectUtils.compare(p.getPdpGroupState(), groupState) == 0) .filter(p -> filterOnPdpType(p, pdpType)) .filter(p -> filterOnPolicyType(p, policyType)) .filter(p -> filterOnPolicy(p, policy)) + .filter(p -> filterOnPdpState(p, pdpState)) .collect(Collectors.toList()); // @formatter:off @@ -151,4 +152,27 @@ public class PdpGroupFilter implements PfObjectFilter<PdpGroup> { return false; } + + /** + * Filter PDP groups on PDP state. + * + * @param pdpGroup the PDP group to check + * @param policyFilter the policy regular expressions to check for + * @return true if the filter should let this PDP group through + */ + private boolean filterOnPdpState(final PdpGroup pdpGroup, final PdpState pdpState) { + if (pdpState == null) { + return true; + } + + for (PdpSubGroup pdpSubGroup: pdpGroup.getPdpSubgroups()) { + for (Pdp pdp : pdpSubGroup.getPdpInstances()) { + if (pdpState.equals(pdp.getPdpState())) { + return true; + } + } + } + + return false; + } } diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java index a1eb97dd0..bef3f1547 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java @@ -111,7 +111,7 @@ public class PdpProvider { List<JpaPdpGroup> jpaPdpGroupList = dao.getAll(JpaPdpGroup.class); - return asPdpGroupList(jpaPdpGroupList); + return filter.filter(asPdpGroupList(jpaPdpGroupList)); } /** |