From 13a3cdebc5885440ea28f021f5cd6bd3ecac389e Mon Sep 17 00:00:00 2001 From: liamfallon Date: Thu, 19 Mar 2020 15:28:49 +0000 Subject: Allow fetch of old policy type verisons Due to the problems with TOSCA and version handling, the filtering for policy types on old versions did not work. This change fixes that problem. Issue-ID: POLICY-2377 Change-Id: I462bd5710b9dea37475861d1021d28b2c7391a24 Signed-off-by: liamfallon --- .../policy/models/base/PfConceptContainer.java | 42 ++++++++++++++++++++-- .../policy/models/base/PfConceptContainerTest.java | 9 +++++ 2 files changed, 48 insertions(+), 3 deletions(-) (limited to 'models-base') diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java index b4d51d173..d259fa260 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java @@ -30,6 +30,7 @@ import java.util.Map.Entry; import java.util.NavigableMap; import java.util.Set; import java.util.TreeMap; +import java.util.TreeSet; import java.util.function.Function; import javax.persistence.CascadeType; @@ -153,7 +154,7 @@ public class PfConceptContainer ex public List> toAuthorative() { // The returned list is a list of map singletons with one map for each map // entry in the concept container - List> toscaPolicyMapList = new ArrayList<>(); + List> toscaConceptMapList = new ArrayList<>(); for (Entry conceptEntry : getConceptMap().entrySet()) { // Create a map to hold this entry @@ -165,10 +166,10 @@ public class PfConceptContainer ex toscaPolicyMap.put(conceptEntry.getKey().getName(), authoritiveImpl.toAuthorative()); // Add the map to the returned list - toscaPolicyMapList.add(toscaPolicyMap); + toscaConceptMapList.add(toscaPolicyMap); } - return toscaPolicyMapList; + return toscaConceptMapList; } @Override @@ -217,6 +218,21 @@ public class PfConceptContainer ex } } + /** + * Get an authorative list of the concepts in this container. + * + * @return the authorative list of concepts + */ + public List toAuthorativeList() { + List toscaConceptList = new ArrayList<>(); + + for (Map toscaConceptMap : toAuthorative()) { + toscaConceptList.addAll(toscaConceptMap.values()); + } + + return toscaConceptList; + } + @Override public void clean() { key.clean(); @@ -298,6 +314,26 @@ public class PfConceptContainer ex return 0; } + /** + * Get all the concepts that match the given name and version. + * + * @param conceptKeyName the name of the concept, if null, return all names + * @param conceptKeyVersion the version of the concept, if null, return all versions + * @return conceptKeyVersion + */ + public Set getAllNamesAndVersions(final String conceptKeyName, final String conceptKeyVersion) { + if (conceptKeyName == null || conceptKeyVersion == null) { + return getAll(conceptKeyName, conceptKeyVersion); + } else { + final Set returnSet = new TreeSet<>(); + C foundConcept = get(conceptKeyName, conceptKeyVersion); + if (foundConcept != null) { + returnSet.add(foundConcept); + } + return returnSet; + } + } + @Override public C get(final PfConceptKey conceptKey) { if (conceptKey.isNullVersion()) { diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java index 8234741f6..a00363627 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java @@ -216,6 +216,15 @@ public class PfConceptContainerTest { assertEquals(dacMap.get(NAME2), outMapList.get(2).get(NAME2)); assertEquals(dacMap.get(NAME3), outMapList.get(2).get(NAME3)); + List outConceptList = container.toAuthorativeList(); + assertEquals("Hello", outConceptList.get(0).getDescription()); + assertEquals("Hi", outConceptList.get(1).getDescription()); + assertEquals("Howdy", outConceptList.get(2).getDescription()); + assertEquals("Ciao", outConceptList.get(3).getDescription()); + assertEquals("name4", outConceptList.get(4).getName()); + assertEquals("1.2.3", outConceptList.get(4).getVersion()); + assertEquals("0.0.0", outConceptList.get(5).getVersion()); + DummyBadPfConceptContainer badContainer = new DummyBadPfConceptContainer(); assertThatThrownBy(() -> badContainer.fromAuthorative(authorativeList)) .hasMessage("failed to instantiate instance of container concept class"); -- cgit 1.2.3-korg