diff options
Diffstat (limited to 'models-tosca')
3 files changed, 86 insertions, 6 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java index 496c62677..7781af236 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java @@ -20,11 +20,48 @@ package org.onap.policy.models.tosca.authorative.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; + /** * Filter class for searches for {@link ToscaPolicy} instances. + * If any fields are null, they are ignored. * * @author Liam Fallon (liam.fallon@est.tech) */ -public class ToscaPolicyFilter { +@Builder +@Data +public class ToscaPolicyFilter implements PfObjectFiler<ToscaPolicy> { + 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; + + // Regular expression + private String policyTypeName; + + // Regular Expression, set to LATEST_VERRSION to get the latest version + private String policyTypeVersion; + + @Override + public List<ToscaPolicy> filter(@NonNull final List<ToscaPolicy> originalList) { + // @formatter:off + return originalList.stream() + .filter(p -> name != null && p.getName() .matches(name)) + .filter(p -> version != null && p.getVersion() .matches(version)) + .filter(p -> policyTypeName != null && p.getType() .matches(policyTypeName)) + .filter(p -> policyTypeVersion != null && p.getTypeVersion().matches(policyTypeVersion)) + .collect(Collectors.toList()); + // @formatter:off + } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java index a77e1856b..baa95045c 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java @@ -20,11 +20,40 @@ package org.onap.policy.models.tosca.authorative.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; + /** * Filter class for searches for {@link ToscaPolicyType} instances. + * If any fields are null, they are ignored. * * @author Liam Fallon (liam.fallon@est.tech) */ -public class ToscaPolicyTypeFilter { +@Builder +@Data +public class ToscaPolicyTypeFilter implements PfObjectFiler<ToscaPolicyType> { + 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; + + @Override + public List<ToscaPolicyType> filter(@NonNull final List<ToscaPolicyType> originalList) { + // @formatter:off + return originalList.stream() + .filter(p -> name != null && p.getName() .matches(name)) + .filter(p -> version != null && p.getVersion().matches(version)) + .collect(Collectors.toList()); + // @formatter:off + } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestPojos.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestPojos.java index 7c813a625..96d82e7b3 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestPojos.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestPojos.java @@ -22,6 +22,7 @@ package org.onap.policy.models.tosca.authorative.concepts; +import com.openpojo.reflection.filters.FilterClassName; import com.openpojo.reflection.filters.FilterPackageInfo; import com.openpojo.validation.Validator; import com.openpojo.validation.ValidatorBuilder; @@ -44,9 +45,22 @@ public class TestPojos { @Test public void testPojos() { - final Validator validator = ValidatorBuilder.create().with(new ToStringTester()) - .with(new SetterMustExistRule()).with(new GetterMustExistRule()).with(new SetterTester()) - .with(new GetterTester()).build(); - validator.validate(POJO_PACKAGE, new FilterPackageInfo()); + // @formatter:off + final Validator validator = ValidatorBuilder + .create() + .with(new ToStringTester()) + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + validator.validate(POJO_PACKAGE, + new FilterPackageInfo(), + new FilterClassName( + org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter.class.getName()), + new FilterClassName( + org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter.class.getName()) + ); + // @formatter:on } } |