aboutsummaryrefslogtreecommitdiffstats
path: root/models-base
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-05-07 12:42:26 +0000
committerliamfallon <liam.fallon@est.tech>2019-05-07 12:42:26 +0000
commitf53879588a464c727ece62f87c7625b47e6de7f1 (patch)
tree980cddab937c38610587b50cc45a9c36540a2470 /models-base
parente936413c9082afed0fef4646b8f12d351c87800c (diff)
Set default and check existance of Policy Type
The TOSCA specification has a "bug" in that it does not have a field to specify the version of a policy type to use. We already had introduced the "type_version" field for this. This review introduces setting of the default version of a policy type to be be used by a policy as the latest version of the policy type in the database. As a side effect of this, we now have to check for existence of the policy type of a policy in the database. This means that creation/update of a policy with a non-existant policy type specified will now fail. Issue-ID: POLICY-1738 Change-Id: I27080cf6cd358948810dab6897c72dfe4d41fe91 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-base')
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConcept.java18
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java68
2 files changed, 86 insertions, 0 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConcept.java b/models-base/src/main/java/org/onap/policy/models/base/PfConcept.java
index c41b0de56..9a376feff 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfConcept.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfConcept.java
@@ -105,6 +105,24 @@ public abstract class PfConcept implements Serializable, Comparable<PfConcept> {
}
/**
+ * Gets the name of this concept.
+ *
+ * @return the name of this concept
+ */
+ public String getName() {
+ return getKey().getName();
+ }
+
+ /**
+ * Gets the version of this concept.
+ *
+ * @return the version of this concept
+ */
+ public String getVersion() {
+ return getKey().getVersion();
+ }
+
+ /**
* Checks if this key matches the given key ID.
*
* @param id the key ID to match against
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java
new file mode 100644
index 000000000..8a9fbc414
--- /dev/null
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.base;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import lombok.Builder;
+import lombok.Data;
+import lombok.NonNull;
+
+/**
+ * Filter class for searches for {@link ToscaPolicy} instances. If any fields are null, they are ignored.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Builder
+@Data
+public class PfConceptFilter implements PfObjectFilter<PfConcept> {
+ public static final String LATEST_VERSION = "LATEST";
+
+ // Exact expression
+ private String name;
+
+ // Exact match, set to LATEST_VERSION to get the latest version
+ private String version;
+
+ // version prefix
+ private String versionPrefix;
+
+ @Override
+ public List<PfConcept> filter(@NonNull final List<PfConcept> originalList) {
+
+ // @formatter:off
+ List<PfConcept> returnList = originalList.stream()
+ .filter(filterStringPred(name, PfConcept::getName))
+ .filter(filterStringPred((LATEST_VERSION.equals(version) ? null : version), PfConcept::getVersion))
+ .filter(filterPrefixPred(versionPrefix, PfConcept::getVersion))
+ .collect(Collectors.toList());
+ // @formatter:off
+
+ if (LATEST_VERSION.equals(version)) {
+ return this.latestVersionFilter(returnList);
+ }
+ else {
+ return returnList;
+ }
+ }
+}