diff options
Diffstat (limited to 'models-pdp/src')
-rw-r--r-- | models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java | 44 |
1 files changed, 43 insertions, 1 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 f06a34dbb..f7a47ccd7 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 @@ -20,11 +20,53 @@ package org.onap.policy.models.pdp.concepts; +import java.util.List; +import java.util.stream.Collectors; + +import lombok.Builder; +import lombok.Data; +import lombok.NonNull; + +import org.onap.policy.models.base.PfObjectFiler; +import org.onap.policy.models.pdp.enums.PdpState; + /** * Filter class for searches for {@link PdpGroup} instances. + * If any fields are null, they are ignored. * * @author Liam Fallon (liam.fallon@est.tech) */ -public class PdpGroupFilter { +@Builder +@Data +public class PdpGroupFilter implements PfObjectFiler<PdpGroup> { + public static final String LATEST_VERSION = "LATEST"; + + // Regular expression + private String name; + + // Regular Expression, set to LATEST_VERRSION to get the latest version + private String version; + + private PdpState groupState; + + // Regular expression + private String pdpType; + + // Set regular expressions on fields to match policy type names and versions + private ToscaPolicyTypeIdentifier policyType; + + // Set regular expressions on fields to match policy names and versions + private ToscaPolicyIdentifier policy; + + @Override + public List<PdpGroup> filter(@NonNull final List<PdpGroup> originalList) { + // @formatter:off + return originalList.stream() + .filter(p -> name != null && p.getName() .matches(name)) + .filter(p -> version != null && p.getVersion().matches(version)) + .filter(p -> groupState != null && p.getPdpGroupState().equals(groupState)) + .collect(Collectors.toList()); + // @formatter:off + } } |