From ed54f1f94a43e9fc5e353eb2c7111dcc552be18e Mon Sep 17 00:00:00 2001 From: liamfallon Date: Sun, 7 Feb 2021 14:51:45 +0000 Subject: Make filters on TOSCA entities generic The classes PolicyTypeFilter and PolicyFilter only work on Policy types and policies. However they just filter on name/version/type/typeversion so there is no reason that the filters could not be applied to other entities. This commit adapts the PolicyTypeFilter to EntityFilter and PolicyFilter to TypedEntityFilter, so the filters can be applied to collections of any ToscaEntity class. Issue-ID: POLICY-2995 Change-Id: I8fcf76ee8c8497836b3286b35f928b0c341dac34 Signed-off-by: liamfallon --- .../models/provider/PolicyModelsProvider.java | 36 ++++++++++------------ .../impl/DatabasePolicyModelsProviderImpl.java | 29 ++++++++--------- .../impl/DummyPolicyModelsProviderImpl.java | 25 +++++++-------- 3 files changed, 45 insertions(+), 45 deletions(-) (limited to 'models-provider/src/main') diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java index e0cb44cb6..3bf81adf7 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -34,12 +34,11 @@ import org.onap.policy.models.pdp.concepts.PdpPolicyStatus; import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplateFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; /** * This interface describes the operations that are provided to users and components for reading objects from and @@ -76,8 +75,8 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the service templates found * @throws PfModelException on errors getting service templates */ - public List getFilteredServiceTemplateList(@NonNull final ToscaServiceTemplateFilter filter) - throws PfModelException; + public List getFilteredServiceTemplateList( + @NonNull final ToscaEntityFilter filter) throws PfModelException; /** * Create service template. @@ -137,7 +136,7 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the policy types found * @throws PfModelException on errors getting policy types */ - public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final ToscaPolicyTypeFilter filter) + public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final ToscaEntityFilter filter) throws PfModelException; /** @@ -147,7 +146,7 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the policy types found * @throws PfModelException on errors getting policy types */ - public List getFilteredPolicyTypeList(@NonNull final ToscaPolicyTypeFilter filter) + public List getFilteredPolicyTypeList(@NonNull final ToscaEntityFilter filter) throws PfModelException; /** @@ -208,7 +207,8 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the policies found * @throws PfModelException on errors getting policies */ - public ToscaServiceTemplate getFilteredPolicies(@NonNull final ToscaPolicyFilter filter) throws PfModelException; + public ToscaServiceTemplate getFilteredPolicies(@NonNull final ToscaTypedEntityFilter filter) + throws PfModelException; /** * Get filtered policies. @@ -217,7 +217,8 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the policies found * @throws PfModelException on errors getting policies */ - public List getFilteredPolicyList(@NonNull final ToscaPolicyFilter filter) throws PfModelException; + public List getFilteredPolicyList(@NonNull final ToscaTypedEntityFilter filter) + throws PfModelException; /** * Create policies. @@ -378,8 +379,7 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the deployments found * @throws PfModelException on errors getting PDP groups */ - public List getAllPolicyStatus() - throws PfModelException; + public List getAllPolicyStatus() throws PfModelException; /** * Gets all deployments for a policy. @@ -388,18 +388,16 @@ public interface PolicyModelsProvider extends AutoCloseable { * @throws PfModelException on errors getting PDP groups */ public List getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy) - throws PfModelException; + throws PfModelException; /** * Gets the policy deployments for a PDP group. * - * @param groupName the name of the PDP group of interest, null to get results for all - * PDP groups + * @param groupName the name of the PDP group of interest, null to get results for all PDP groups * @return the deployments found * @throws PfModelException on errors getting PDP groups */ - public List getGroupPolicyStatus(@NonNull final String groupName) - throws PfModelException; + public List getGroupPolicyStatus(@NonNull final String groupName) throws PfModelException; /** * Creates, updates, and deletes collections of policy status. @@ -408,6 +406,6 @@ public interface PolicyModelsProvider extends AutoCloseable { * @param updateObjs the objects to update * @param deleteObjs the objects to delete */ - public void cudPolicyStatus(Collection createObjs, - Collection updateObjs, Collection deleteObjs); + public void cudPolicyStatus(Collection createObjs, Collection updateObjs, + Collection deleteObjs); } diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java index 3094efc27..8c7c5122b 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java @@ -41,12 +41,11 @@ import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.provider.PolicyModelsProviderParameters; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplateFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider; /** @@ -74,8 +73,8 @@ public class DatabasePolicyModelsProviderImpl extends AbstractModelsProvider imp @Override - public List getFilteredServiceTemplateList(@NonNull ToscaServiceTemplateFilter filter) - throws PfModelException { + public List getFilteredServiceTemplateList( + @NonNull ToscaEntityFilter filter) throws PfModelException { assertInitialized(); return new AuthorativeToscaProvider().getFilteredServiceTemplateList(getPfDao(), filter); } @@ -115,13 +114,14 @@ public class DatabasePolicyModelsProviderImpl extends AbstractModelsProvider imp } @Override - public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull ToscaPolicyTypeFilter filter) throws PfModelException { + public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull ToscaEntityFilter filter) + throws PfModelException { assertInitialized(); return new AuthorativeToscaProvider().getFilteredPolicyTypes(getPfDao(), filter); } @Override - public List getFilteredPolicyTypeList(@NonNull ToscaPolicyTypeFilter filter) + public List getFilteredPolicyTypeList(@NonNull ToscaEntityFilter filter) throws PfModelException { assertInitialized(); return new AuthorativeToscaProvider().getFilteredPolicyTypeList(getPfDao(), filter); @@ -165,13 +165,15 @@ public class DatabasePolicyModelsProviderImpl extends AbstractModelsProvider imp } @Override - public ToscaServiceTemplate getFilteredPolicies(@NonNull ToscaPolicyFilter filter) throws PfModelException { + public ToscaServiceTemplate getFilteredPolicies(@NonNull ToscaTypedEntityFilter filter) + throws PfModelException { assertInitialized(); return new AuthorativeToscaProvider().getFilteredPolicies(getPfDao(), filter); } @Override - public List getFilteredPolicyList(@NonNull ToscaPolicyFilter filter) throws PfModelException { + public List getFilteredPolicyList(@NonNull ToscaTypedEntityFilter filter) + throws PfModelException { assertInitialized(); return new AuthorativeToscaProvider().getFilteredPolicyList(getPfDao(), filter); } @@ -288,21 +290,20 @@ public class DatabasePolicyModelsProviderImpl extends AbstractModelsProvider imp @Override public List getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy) - throws PfModelException { + throws PfModelException { assertInitialized(); return new PdpProvider().getAllPolicyStatus(getPfDao(), policy); } @Override - public List getGroupPolicyStatus(@NonNull String groupName) - throws PfModelException { + public List getGroupPolicyStatus(@NonNull String groupName) throws PfModelException { assertInitialized(); return new PdpProvider().getGroupPolicyStatus(getPfDao(), groupName); } @Override - public void cudPolicyStatus(Collection createObjs, - Collection updateObjs, Collection deleteObjs) { + public void cudPolicyStatus(Collection createObjs, Collection updateObjs, + Collection deleteObjs) { assertInitialized(); new PdpProvider().cudPolicyStatus(getPfDao(), createObjs, updateObjs, deleteObjs); } diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java index 0a9ea723f..1b91f07c6 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * ================================================================================ @@ -41,12 +41,11 @@ import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.provider.PolicyModelsProviderParameters; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplateFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; /** * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework. @@ -81,8 +80,8 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { } @Override - public List getFilteredServiceTemplateList(@NonNull ToscaServiceTemplateFilter filter) - throws PfModelException { + public List getFilteredServiceTemplateList( + @NonNull ToscaEntityFilter filter) throws PfModelException { return new ArrayList<>(); } @@ -115,12 +114,13 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { } @Override - public ToscaServiceTemplate getFilteredPolicyTypes(ToscaPolicyTypeFilter filter) throws PfModelException { + public ToscaServiceTemplate getFilteredPolicyTypes(ToscaEntityFilter filter) + throws PfModelException { return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json"); } @Override - public List getFilteredPolicyTypeList(ToscaPolicyTypeFilter filter) { + public List getFilteredPolicyTypeList(ToscaEntityFilter filter) { return new ArrayList<>(); } @@ -150,12 +150,13 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { } @Override - public ToscaServiceTemplate getFilteredPolicies(ToscaPolicyFilter filter) throws PfModelException { + public ToscaServiceTemplate getFilteredPolicies(ToscaTypedEntityFilter filter) + throws PfModelException { return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json"); } @Override - public List getFilteredPolicyList(ToscaPolicyFilter filter) throws PfModelException { + public List getFilteredPolicyList(ToscaTypedEntityFilter filter) throws PfModelException { return new ArrayList<>(); } @@ -249,7 +250,7 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { @Override public List getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy) - throws PfModelException { + throws PfModelException { // Not implemented return new ArrayList<>(); } @@ -262,7 +263,7 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { @Override public void cudPolicyStatus(Collection createObjs, Collection updateObjs, - Collection deleteObjs) { + Collection deleteObjs) { // Not implemented } -- cgit 1.2.3-korg