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-tosca/src | |
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-tosca/src')
5 files changed, 46 insertions, 58 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 d29f303f2..b4d1b3ee3 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 @@ -58,7 +58,7 @@ public class ToscaPolicyFilter implements PfObjectFilter<ToscaPolicy> { // @formatter:off List<ToscaPolicy> 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 -> filterOnRegexp(p.getType(), type)) .filter(p -> filterOnRegexp(p.getTypeVersion(), typeVersion)) .collect(Collectors.toList()); 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 097fb6139..041179513 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 @@ -52,7 +52,7 @@ public class ToscaPolicyTypeFilter implements PfObjectFilter<ToscaPolicyType> { // @formatter:off List<ToscaPolicyType> 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)) .collect(Collectors.toList()); // @formatter:off diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java index a843711ee..4bf014644 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java @@ -22,6 +22,7 @@ package org.onap.policy.models.tosca.authorative.provider; import java.util.ArrayList; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -30,6 +31,7 @@ import lombok.NonNull; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.dao.PfDao; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; 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; @@ -85,7 +87,16 @@ public class AuthorativeToscaProvider { */ public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final PfDao dao, @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException { - return new SimpleToscaProvider().getFilteredPolicyTypes(dao, filter).toAuthorative(); + + ToscaServiceTemplate serviceTemplate = + new SimpleToscaProvider().getPolicyTypes(dao, null, null).toAuthorative(); + + List<ToscaPolicyType> filteredPolicyTypes = asConceptList(serviceTemplate.getPolicyTypes()); + filteredPolicyTypes = filter.filter(filteredPolicyTypes); + + serviceTemplate.setPolicyTypes(asConceptMap(filteredPolicyTypes)); + + return serviceTemplate; } /** @@ -99,8 +110,7 @@ public class AuthorativeToscaProvider { public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final PfDao dao, @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException { - return (asConceptList( - new SimpleToscaProvider().getFilteredPolicyTypes(dao, filter).toAuthorative().getPolicyTypes())); + return filter.filter(getPolicyTypeList(dao, null, null)); } /** @@ -190,7 +200,14 @@ public class AuthorativeToscaProvider { public ToscaServiceTemplate getFilteredPolicies(@NonNull final PfDao dao, @NonNull final ToscaPolicyFilter filter) throws PfModelException { - return new SimpleToscaProvider().getFilteredPolicies(dao, filter).toAuthorative(); + ToscaServiceTemplate serviceTemplate = new SimpleToscaProvider().getPolicies(dao, null, null).toAuthorative(); + + List<ToscaPolicy> filteredPolicies = asConceptList(serviceTemplate.getToscaTopologyTemplate().getPolicies()); + filteredPolicies = filter.filter(filteredPolicies); + + serviceTemplate.getToscaTopologyTemplate().setPolicies(asConceptMap(filteredPolicies)); + + return serviceTemplate; } /** @@ -204,8 +221,7 @@ public class AuthorativeToscaProvider { public List<ToscaPolicy> getFilteredPolicyList(@NonNull final PfDao dao, @NonNull final ToscaPolicyFilter filter) throws PfModelException { - return asConceptList(new SimpleToscaProvider().getFilteredPolicies(dao, filter).toAuthorative() - .getToscaTopologyTemplate().getPolicies()); + return filter.filter(getPolicyList(dao, null, null)); } /** @@ -273,4 +289,19 @@ public class AuthorativeToscaProvider { return returnList; } + + /** + * Return the contents of a list of concepts as a list of maps of concepts. + * + * @param comceptList the concept list + * @return the concept map + */ + private <T extends ToscaEntity> List<Map<String, T>> asConceptMap(List<T> conceptList) { + Map<String, T> conceptMap = new LinkedHashMap<>(); + for (T concept : conceptList) { + conceptMap.put(concept.getName(), concept); + } + + return Collections.singletonList(conceptMap); + } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchema.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchema.java index 1177368b2..881d87c4b 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchema.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchema.java @@ -59,8 +59,12 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaEntrySchema; @NoArgsConstructor public class JpaToscaEntrySchema implements PfAuthorative<ToscaEntrySchema>, Serializable, Comparable<JpaToscaEntrySchema> { + private static final long serialVersionUID = 3645882081163287058L; + // Recurring string constants + private static final String ENTRY_SCHEMA = "EntrySchema"; + @Column private PfConceptKey type; @@ -157,12 +161,12 @@ public class JpaToscaEntrySchema PfValidationResult result = resultIn; if (type == null || type.isNullKey()) { - result.addValidationMessage(new PfValidationMessage(new PfConceptKey("EntrySchema", PfKey.NULL_KEY_VERSION), + result.addValidationMessage(new PfValidationMessage(new PfConceptKey(ENTRY_SCHEMA, PfKey.NULL_KEY_VERSION), this.getClass(), ValidationResult.INVALID, "entry schema type may not be null")); } if (description != null && description.trim().length() == 0) { - result.addValidationMessage(new PfValidationMessage(new PfConceptKey("EntrySchema", PfKey.NULL_KEY_VERSION), + result.addValidationMessage(new PfValidationMessage(new PfConceptKey(ENTRY_SCHEMA, PfKey.NULL_KEY_VERSION), this.getClass(), ValidationResult.INVALID, "entry schema description may not be blank")); } @@ -171,7 +175,7 @@ public class JpaToscaEntrySchema for (JpaToscaConstraint constraint : constraints) { if (constraint == null) { result.addValidationMessage( - new PfValidationMessage(new PfConceptKey("EntrySchema", PfKey.NULL_KEY_VERSION), + new PfValidationMessage(new PfConceptKey(ENTRY_SCHEMA, PfKey.NULL_KEY_VERSION), this.getClass(), ValidationResult.INVALID, "property constraint may not be null ")); } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java index 6c588a50c..a207c4267 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java @@ -33,8 +33,6 @@ import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.dao.PfDao; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType; @@ -82,28 +80,6 @@ public class SimpleToscaProvider { } /** - * Get filtered policy types. - * - * @param dao the DAO to use to access the database - * @param filter the filter for the policy types to get - * @return the policy types found - * @throws PfModelException on errors getting policy types - */ - public JpaToscaServiceTemplate getFilteredPolicyTypes(@NonNull final PfDao dao, - @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException { - - // Create the structure of the TOSCA service template to contain the policy type - JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); - serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes()); - - List<JpaToscaPolicyType> jpaPolicyTypeList = dao.getAll(JpaToscaPolicyType.class); - // TODO: The actual filtering - - serviceTemplate.getPolicyTypes().getConceptMap().putAll(asConceptMap(jpaPolicyTypeList)); - return serviceTemplate; - } - - /** * Create policy types. * * @param dao the DAO to use to access the database @@ -213,29 +189,6 @@ public class SimpleToscaProvider { } /** - * Get filtered policies. - * - * @param dao the DAO to use to access the database - * @param filter the filter for the policies to get - * @return the policies found - * @throws PfModelException on errors getting policies - */ - public JpaToscaServiceTemplate getFilteredPolicies(@NonNull final PfDao dao, - @NonNull final ToscaPolicyFilter filter) throws PfModelException { - - // Create the structure of the TOSCA service template to contain the policy type - JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); - serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); - serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); - - List<JpaToscaPolicy> jpaPolicyList = dao.getAll(JpaToscaPolicy.class); - // TODO: Do the actual filtering - - serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().putAll(asConceptMap(jpaPolicyList)); - return serviceTemplate; - } - - /** * Create policies. * * @param dao the DAO to use to access the database |