From b87e0242ce1a957740ee988bec3b82e3628adbed Mon Sep 17 00:00:00 2001 From: liamfallon Date: Thu, 17 Dec 2020 12:10:21 +0000 Subject: Add Service Template TOSCA handling Today we can only handle a single service template in the database. We should be able to handle multiple service templates and assign arbitrary policy types and policies to maned and versioned service templates. This review brings in the Java API in models provider for handling service templates in this way and uses a simplistic single-teplate implementation in models-tosca, that will work but still only handles a single service template under the hood. Issue-ID: POLICY-2900 Change-Id: Ia02dea8abe44b7f407e685090a4b8e0360889653 Signed-off-by: liamfallon --- .../onap/policy/models/base/PfConceptContainer.java | 4 ++-- .../org/onap/policy/models/base/PfNameVersion.java | 18 ++++++++++++++++++ .../org/onap/policy/models/base/PfObjectFilter.java | 15 ++++++--------- 3 files changed, 26 insertions(+), 11 deletions(-) (limited to 'models-base/src/main/java/org') 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 4c2cf0c4f..d2015eb7e 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 @@ -198,9 +198,9 @@ public class PfConceptContainer ex } incomingConceptEntry.getValue().setName(findConceptField(conceptKey, conceptKey.getName(), - incomingConceptEntry.getValue(), PfNameVersion::getName)); + incomingConceptEntry.getValue(), PfNameVersion::getDefinedName)); incomingConceptEntry.getValue().setVersion(findConceptField(conceptKey, conceptKey.getVersion(), - incomingConceptEntry.getValue(), PfNameVersion::getVersion)); + incomingConceptEntry.getValue(), PfNameVersion::getDefinedVersion)); C jpaConcept = getConceptNewInstance(); // This cast allows us to call the fromAuthorative method diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfNameVersion.java b/models-base/src/main/java/org/onap/policy/models/base/PfNameVersion.java index f9fde53e5..4e4177004 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfNameVersion.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfNameVersion.java @@ -37,6 +37,24 @@ public interface PfNameVersion { public void setVersion(final String version); + /** + * Get the defined name for a concept, return null if no name is defined. + * + * @return the defined name + */ + public default String getDefinedName() { + return getName(); + } + + /** + * Get the defined version for a concept, return null if no version is defined. + * + * @return the defined version + */ + public default String getDefinedVersion() { + return getVersion(); + } + /** * Compare two name version implementation objects. * diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java b/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java index f7e29f1b4..342fbab73 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java @@ -56,8 +56,7 @@ public interface PfObjectFilter { } /** - * Gets a predicate used to filter an item in a list by exactly matching an extracted value - * with some text. + * Gets a predicate used to filter an item in a list by exactly matching an extracted value with some text. * * @param text the desired text to check against, or {@code null} if to accept everything * @param extractor function to extract the value, to be matched, from a list item @@ -73,11 +72,9 @@ public interface PfObjectFilter { } /** - * Gets a predicate used to filter an item in a list by comparing the start of an - * extracted value with a prefix. + * Gets a predicate used to filter an item in a list by comparing the start of an extracted value with a prefix. * - * @param prefix the desired prefix to check against, or {@code null} if to accept - * everything + * @param prefix the desired prefix to check against, or {@code null} if to accept everything * @param extractor function to extract the value, to be matched, from a list item * @return a predicate to match a prefix with a value from a list item */ @@ -94,8 +91,7 @@ public interface PfObjectFilter { } /** - * Gets a predicate used to filter an item in a list by matching an extracted value - * with a regular expression. + * Gets a predicate used to filter an item in a list by matching an extracted value with a regular expression. * * @param pattern regular expression to match, or {@code null} if to accept everything * @param extractor function to extract the value, to be matched, from a list item @@ -140,7 +136,8 @@ public interface PfObjectFilter { * The list is sorted so if the last element name is the same as the current element name, the current * element should be removed. */ - if (!((PfNameVersion) curElement).getName().equals(((PfNameVersion) lastElement).getName())) { + if (PfUtils.compareObjects(((PfNameVersion) curElement).getName(), + ((PfNameVersion) lastElement).getName()) != 0) { // have a new name - done comparing with the old "current" ++icur; } -- cgit 1.2.3-korg