aboutsummaryrefslogtreecommitdiffstats
path: root/models-pdp
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-04-04 12:16:12 +0000
committerliamfallon <liam.fallon@est.tech>2019-04-04 12:16:12 +0000
commitfc297c8a98df155971e2fa485c7724a61b70c69c (patch)
tree4ee7cd37b8535417b467d8680455f87c52d534be /models-pdp
parent162cb586fe139460dd3d0404274e85b3f4ead15b (diff)
Add filter obejcts for concepts
This review: - Fixes the bug in getting policies where the key fields were null - Removes complex version checks from DAO interface - Simplifies provider API by introducing filter objects for searches Issue-ID: POLICY-1095 Change-Id: I5ab7471c03e8b61849e7882ed18541acd627dc39 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-pdp')
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java30
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java1
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java46
3 files changed, 46 insertions, 31 deletions
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java
new file mode 100644
index 000000000..f06a34dbb
--- /dev/null
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.pdp.concepts;
+
+/**
+ * Filter class for searches for {@link PdpGroup} instances.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class PdpGroupFilter {
+
+}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java
index 7020b4596..2a9343902 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java
@@ -60,7 +60,6 @@ import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.pdp.concepts.ToscaPolicyIdentifier;
import org.onap.policy.models.pdp.concepts.ToscaPolicyTypeIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
/**
* Class to represent a PDP subgroup in the database.
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java
index 20553d788..a1eb97dd0 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java
@@ -21,15 +21,12 @@
package org.onap.policy.models.pdp.persistence.provider;
import java.util.ArrayList;
-import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
import javax.ws.rs.core.Response;
import lombok.NonNull;
-import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
@@ -38,12 +35,12 @@ import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.dao.PfDao;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpGroup;
+import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
import org.onap.policy.models.pdp.concepts.PdpStatistics;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.pdp.persistence.concepts.JpaPdp;
import org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup;
import org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -70,7 +67,7 @@ public class PdpProvider {
public List<PdpGroup> getPdpGroups(@NonNull final PfDao dao, final String name, final String version)
throws PfModelException {
- List<JpaPdpGroup> foundPdpGroups = dao.getFiltered(JpaPdpGroup.class, new PfConceptKey(name, version));
+ List<JpaPdpGroup> foundPdpGroups = dao.getFiltered(JpaPdpGroup.class, name, version);
if (foundPdpGroups != null) {
return asPdpGroupList(foundPdpGroups);
@@ -90,29 +87,31 @@ public class PdpProvider {
* @throws PfModelException on errors getting policies
*/
public List<PdpGroup> getLatestPdpGroups(@NonNull final PfDao dao, final String name) throws PfModelException {
- List<JpaPdpGroup> returnList = new ArrayList<>();
+ List<JpaPdpGroup> jpaPdpGroupList = new ArrayList<>();
if (name == null) {
- returnList.add(dao.getLatestVersion(JpaPdpGroup.class, name));
- }
- else {
- returnList.addAll(dao.getLatestVersions(JpaPdpGroup.class));
+ jpaPdpGroupList.addAll(dao.getAll(JpaPdpGroup.class));
+ } else {
+ jpaPdpGroupList.addAll(dao.getAllVersions(JpaPdpGroup.class, name));
}
- return asPdpGroupList(returnList);
+ return asPdpGroupList(jpaPdpGroupList);
}
/**
- * Get a filtered list of PDP groups, returns only active PDP groups.
+ * Get filtered PDP groups.
*
* @param dao the DAO to use to access the database
- * @param pdpType The PDP type filter for the returned PDP groups, null to get policy types across PDP subgroups
- * @param supportedPolicyTypes a list of policy type name/version pairs that the PDP groups must support.
+ * @param filter the filter for the PDP groups to get
* @return the PDP groups found
+ * @throws PfModelException on errors getting policies
*/
- public List<PdpGroup> getFilteredPdpGroups(@NonNull final PfDao dao, final String pdpType,
- @NonNull final List<Pair<String, String>> supportedPolicyTypes) {
- return new ArrayList<>();
+ public List<PdpGroup> getFilteredPdpGroups(@NonNull final PfDao dao, @NonNull final PdpGroupFilter filter)
+ throws PfModelException {
+
+ List<JpaPdpGroup> jpaPdpGroupList = dao.getAll(JpaPdpGroup.class);
+
+ return asPdpGroupList(jpaPdpGroupList);
}
/**
@@ -308,19 +307,6 @@ public class PdpProvider {
}
/**
- * Get deployed policies.
- *
- * @param dao the DAO to use to access the database
- * @param name the name of the policy to get deployed policies for, null to get all deployed policies
- * @return the policies deployed as a map of policy lists keyed by PDP group name and version
- * @throws PfModelException on errors getting policies
- */
- public Map<Pair<String, String>, List<ToscaPolicy>> getDeployedPolicyList(@NonNull final PfDao dao,
- final String name) throws PfModelException {
- return new LinkedHashMap<>();
- }
-
- /**
* Convert JPA PDP group list to an authorative PDP group list.
*
* @param foundPdpGroups the list to convert