diff options
author | liamfallon <liam.fallon@est.tech> | 2019-04-05 15:40:15 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2019-04-05 15:40:15 +0000 |
commit | 69bc7db0edc751d3936b92c4bdf1ee74dfa4da57 (patch) | |
tree | c101dc83cb3e135161dcd6445ca7bcd58e7d62e8 /models-tosca/src | |
parent | 38cc81922273039d2d32979123bb83a15c49debf (diff) |
Complete filters for Database Fetches
This review completes the implementaiton of the filters
for fetching policy types, policies, and PDP groups
from the database.
It also fixes bugs in Policy type creation.
Yaml in some of the policy type examples modified so that it is syntatically
correct.
Proeprties now stored as a blob in DB as they can be big.
Issue-ID: POLICY-1095
Change-Id: I6aef88ee2905afa58d778d82832f2b55d794fe9c
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-tosca/src')
11 files changed, 49 insertions, 31 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java index 9d327a2ca..e89b31635 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java @@ -30,6 +30,7 @@ import java.util.Map.Entry; import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; + import org.onap.policy.models.base.PfNameVersion; /** @@ -70,5 +71,4 @@ public class ToscaEntity implements PfNameVersion { } } } - } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicy.java index 9c6a375de..284e39c9b 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicy.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicy.java @@ -41,7 +41,7 @@ import lombok.ToString; @EqualsAndHashCode(callSuper = true) @NoArgsConstructor @ToString(callSuper = true) -public class ToscaPolicy extends ToscaEntity { +public class ToscaPolicy extends ToscaEntity implements Comparable<ToscaPolicy> { private String type; private String typeVersion; @@ -84,4 +84,9 @@ public class ToscaPolicy extends ToscaEntity { public ToscaPolicyTypeIdentifier getTypeIdentifier() { return new ToscaPolicyTypeIdentifier(getType(), getTypeVersion()); } + + @Override + public int compareTo(final ToscaPolicy other) { + return compareNameVersion(this, other); + } } 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 7781af236..d29f303f2 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 @@ -27,7 +27,7 @@ import lombok.Builder; import lombok.Data; import lombok.NonNull; -import org.onap.policy.models.base.PfObjectFiler; +import org.onap.policy.models.base.PfObjectFilter; /** * Filter class for searches for {@link ToscaPolicy} instances. @@ -37,7 +37,7 @@ import org.onap.policy.models.base.PfObjectFiler; */ @Builder @Data -public class ToscaPolicyFilter implements PfObjectFiler<ToscaPolicy> { +public class ToscaPolicyFilter implements PfObjectFilter<ToscaPolicy> { public static final String LATEST_VERSION = "LATEST"; // Regular expression @@ -47,21 +47,28 @@ public class ToscaPolicyFilter implements PfObjectFiler<ToscaPolicy> { private String version; // Regular expression - private String policyTypeName; + private String type; // Regular Expression, set to LATEST_VERRSION to get the latest version - private String policyTypeVersion; + private String typeVersion; @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)) + List<ToscaPolicy> returnList = originalList.stream() + .filter(p -> filterOnRegexp(p.getName(), name)) + .filter(p -> filterOnRegexp(p.getVersion(), version)) + .filter(p -> filterOnRegexp(p.getType(), type)) + .filter(p -> filterOnRegexp(p.getTypeVersion(), typeVersion)) .collect(Collectors.toList()); // @formatter:off + + if (LATEST_VERSION.equals(version)) { + return this.latestVersionFilter(returnList); + } + else { + return returnList; + } } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyType.java index d64a5facd..75f17ea5b 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyType.java @@ -36,6 +36,11 @@ import lombok.NoArgsConstructor; @Data @EqualsAndHashCode(callSuper = true) @NoArgsConstructor -public class ToscaPolicyType extends ToscaEntity { +public class ToscaPolicyType extends ToscaEntity implements Comparable<ToscaPolicyType> { private Map<String, ToscaProperty> properties; + + @Override + public int compareTo(final ToscaPolicyType other) { + return compareNameVersion(this, other); + } } 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 baa95045c..097fb6139 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 @@ -27,7 +27,7 @@ import lombok.Builder; import lombok.Data; import lombok.NonNull; -import org.onap.policy.models.base.PfObjectFiler; +import org.onap.policy.models.base.PfObjectFilter; /** * Filter class for searches for {@link ToscaPolicyType} instances. @@ -37,7 +37,7 @@ import org.onap.policy.models.base.PfObjectFiler; */ @Builder @Data -public class ToscaPolicyTypeFilter implements PfObjectFiler<ToscaPolicyType> { +public class ToscaPolicyTypeFilter implements PfObjectFilter<ToscaPolicyType> { public static final String LATEST_VERSION = "LATEST"; // Regular expression @@ -50,10 +50,17 @@ public class ToscaPolicyTypeFilter implements PfObjectFiler<ToscaPolicyType> { 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)) + List<ToscaPolicyType> returnList = originalList.stream() + .filter(p -> filterOnRegexp(p.getName(), name)) + .filter(p -> filterOnRegexp(p.getVersion(), version)) .collect(Collectors.toList()); // @formatter:off + + if (LATEST_VERSION.equals(version)) { + return this.latestVersionFilter(returnList); + } + else { + return returnList; + } } } 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 274130a71..a843711ee 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 @@ -157,8 +157,8 @@ public class AuthorativeToscaProvider { * @return the policies found * @throws PfModelException on errors getting policies */ - public ToscaServiceTemplate getPolicies(@NonNull final PfDao dao, @NonNull final String name, - @NonNull final String version) throws PfModelException { + public ToscaServiceTemplate getPolicies(@NonNull final PfDao dao, final String name, final String version) + throws PfModelException { return new SimpleToscaProvider().getPolicies(dao, name, version).toAuthorative(); } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java index f2ab2460f..a39515b49 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java @@ -143,7 +143,7 @@ public class JpaToscaEntityType<T extends ToscaEntity> extends PfConcept impleme @Override public void fromAuthorative(T toscaEntity) { - key = new PfConceptKey(); + key = new PfConceptKey(); if (toscaEntity.getName() != null) { key.setName(toscaEntity.getName()); @@ -158,8 +158,7 @@ public class JpaToscaEntityType<T extends ToscaEntity> extends PfConcept impleme // CHeck if the derived from field contains a name-version ID if (toscaEntity.getDerivedFrom().contains(":")) { derivedFrom = new PfConceptKey(toscaEntity.getDerivedFrom()); - } - else { + } else { derivedFrom = new PfConceptKey(toscaEntity.getDerivedFrom(), PfKey.NULL_KEY_VERSION); } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java index 67a833c94..671b5ccac 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java @@ -36,6 +36,7 @@ import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; +import javax.persistence.Lob; import javax.persistence.Table; import lombok.Data; @@ -79,7 +80,7 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P private PfConceptKey type; @ElementCollection - @Column(length = 10000) + @Lob private Map<String, String> properties; @ElementCollection diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java index fc982965c..a6bc835b4 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java @@ -33,6 +33,7 @@ import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; +import javax.persistence.Lob; import javax.persistence.Table; import lombok.Data; @@ -68,6 +69,7 @@ public class JpaToscaPolicyType extends JpaToscaEntityType<ToscaPolicyType> impl private static final long serialVersionUID = -563659852901842616L; @ElementCollection + @Lob private Map<String, JpaToscaProperty> properties; @ElementCollection diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java index 38d5c0938..e2b6e6f93 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java @@ -83,7 +83,6 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaPr private String defaultValue; @Column - @NonNull private Status status = Status.SUPPORTED; @ElementCollection diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java index 83100cc3c..b8766601b 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java @@ -200,13 +200,6 @@ public class JpaToscaPropertyTest { assertTrue(tp.validate(new PfValidationResult()).isValid()); try { - tp.setStatus(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("status is marked @NonNull but is null", exc.getMessage()); - } - - try { tp.validate(null); fail("test should throw an exception"); } catch (Exception exc) { |