From fc297c8a98df155971e2fa485c7724a61b70c69c Mon Sep 17 00:00:00 2001 From: liamfallon Date: Thu, 4 Apr 2019 12:16:12 +0000 Subject: 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 --- .../policy/models/pdp/concepts/PdpGroupFilter.java | 30 ++++++++++++++ .../pdp/persistence/concepts/JpaPdpSubGroup.java | 1 - .../pdp/persistence/provider/PdpProvider.java | 46 ++++++++-------------- 3 files changed, 46 insertions(+), 31 deletions(-) create mode 100644 models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java (limited to 'models-pdp/src/main/java/org/onap') 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 getPdpGroups(@NonNull final PfDao dao, final String name, final String version) throws PfModelException { - List foundPdpGroups = dao.getFiltered(JpaPdpGroup.class, new PfConceptKey(name, version)); + List 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 getLatestPdpGroups(@NonNull final PfDao dao, final String name) throws PfModelException { - List returnList = new ArrayList<>(); + List 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 getFilteredPdpGroups(@NonNull final PfDao dao, final String pdpType, - @NonNull final List> supportedPolicyTypes) { - return new ArrayList<>(); + public List getFilteredPdpGroups(@NonNull final PfDao dao, @NonNull final PdpGroupFilter filter) + throws PfModelException { + + List jpaPdpGroupList = dao.getAll(JpaPdpGroup.class); + + return asPdpGroupList(jpaPdpGroupList); } /** @@ -307,19 +306,6 @@ public class PdpProvider { // Not implemented yet } - /** - * 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, List> getDeployedPolicyList(@NonNull final PfDao dao, - final String name) throws PfModelException { - return new LinkedHashMap<>(); - } - /** * Convert JPA PDP group list to an authorative PDP group list. * -- cgit 1.2.3-korg