summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-04-06 05:19:43 +0000
committerliamfallon <liam.fallon@est.tech>2019-04-06 05:19:43 +0000
commit422412ec8f21017aff1641f133c2258f52f7d706 (patch)
tree414568b6815d92d70c75e9bab9c456968d0e2d2f
parent52229882d7ee3e934641de0bd2df74ed1268130e (diff)
Fix bugs on filters
Filters were not being invoked from providers. Filter for getting latest version was filtering out everything Filter on PDP state was not implemented. Issue-ID: POLICY-1095 Change-Id: If43ce48a57b010e05f75db8cfa80e63f2719ace1 Signed-off-by: liamfallon <liam.fallon@est.tech>
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfNameVersionTest.java63
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java108
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfNameVersion.java36
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObject.java54
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectFilter.java41
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java26
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java2
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java2
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java2
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java43
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchema.java10
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java47
12 files changed, 374 insertions, 60 deletions
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfNameVersionTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfNameVersionTest.java
new file mode 100644
index 000000000..7152b12f1
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfNameVersionTest.java
@@ -0,0 +1,63 @@
+/*-
+ * ============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.base;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.policy.models.base.testconcepts.DummyPfNameVersion;
+
+/**
+ * Test the {@link PfNameVersion} interface.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class PfNameVersionTest {
+
+ @Test
+ public void testPfNameVersion() {
+ DummyPfNameVersion dnv0 = new DummyPfNameVersion();
+ DummyPfNameVersion dnv1 = new DummyPfNameVersion();
+
+ assertEquals(0, dnv0.compareNameVersion(dnv0, dnv1));
+ assertEquals(0, dnv0.compareNameVersion(null, null));
+ assertEquals(-1, dnv0.compareNameVersion(dnv0, null));
+ assertEquals(1, dnv0.compareNameVersion(null, dnv1));
+
+ dnv1.setName("name1");
+ assertEquals(-1, dnv0.compareNameVersion(dnv0, dnv1));
+
+ dnv0.setName("name0");
+ assertEquals(-1, dnv0.compareNameVersion(dnv0, dnv1));
+
+ dnv1.setName("name0");
+ assertEquals(0, dnv0.compareNameVersion(dnv0, dnv1));
+
+ dnv1.setVersion("4.5.6");
+ assertEquals(1, dnv0.compareNameVersion(dnv0, dnv1));
+
+ dnv0.setVersion("1.2.3");
+ assertEquals(-1, dnv0.compareNameVersion(dnv0, dnv1));
+
+ dnv1.setVersion("1.2.3");
+ assertEquals(0, dnv0.compareNameVersion(dnv0, dnv1));
+ }
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java
new file mode 100644
index 000000000..c3ccb4aa5
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java
@@ -0,0 +1,108 @@
+/*-
+ * ============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.base;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+
+import org.onap.policy.models.base.testconcepts.DummyPfObject;
+import org.onap.policy.models.base.testconcepts.DummyPfObjectFilter;
+
+/**
+ * Test the {@link PfObjectFilter} interface.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class PfObjectFilterTest {
+
+ @Test
+ public void testPfObjectInterface() {
+ DummyPfObject do0 = new DummyPfObject();
+ do0.setName("name0");
+ do0.setVersion("1.0.0");
+ do0.setDescription("desc0 ");
+
+ DummyPfObject do1 = new DummyPfObject();
+ do1.setName("name0");
+ do1.setVersion("0.0.1");
+ do1.setDescription("Desc 1");
+
+ DummyPfObject do2 = new DummyPfObject();
+ do2.setName("name0");
+ do2.setVersion("0.0.2");
+ do2.setDescription("Desc 1");
+
+ DummyPfObject do3 = new DummyPfObject();
+ do3.setName("name1");
+ do3.setVersion("0.0.1");
+ do3.setDescription("desc0 ");
+
+ DummyPfObject do4 = new DummyPfObject();
+ do4.setName("name1");
+ do4.setVersion("0.1.2");
+ do4.setDescription("Desc 1");
+
+ DummyPfObject do5 = new DummyPfObject();
+ do5.setName("aaaaa");
+ do5.setVersion("0.0.2");
+ do5.setDescription("Desc 1");
+
+ List<DummyPfObject> doList = new ArrayList<>();
+ doList.add(do0);
+ doList.add(do1);
+ doList.add(do2);
+ doList.add(do3);
+ doList.add(do4);
+ doList.add(do5);
+
+ DummyPfObjectFilter dof = new DummyPfObjectFilter();
+ assertFalse(dof.filterOnRegexp("Hello", "Goodbye"));
+ assertTrue(dof.filterOnRegexp("Hello", "Hello"));
+
+ assertThatThrownBy(() -> {
+ dof.filterOnRegexp(null, null);
+ }).hasMessage("value is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ dof.filterOnRegexp("hello", null);
+ }).hasMessage("regexp is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ dof.filterOnRegexp(null, "hello");
+ }).hasMessage("value is marked @NonNull but is null");
+
+ List<DummyPfObject> latestVersionList = dof.latestVersionFilter(doList);
+ assertEquals(3, latestVersionList.size());
+ assertEquals("aaaaa", latestVersionList.get(0).getName());
+ assertEquals("0.0.2", latestVersionList.get(0).getVersion());
+ assertEquals("name0", latestVersionList.get(1).getName());
+ assertEquals("1.0.0", latestVersionList.get(1).getVersion());
+ assertEquals("name1", latestVersionList.get(2).getName());
+ assertEquals("0.1.2", latestVersionList.get(2).getVersion());
+ }
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfNameVersion.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfNameVersion.java
new file mode 100644
index 000000000..23179d7de
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfNameVersion.java
@@ -0,0 +1,36 @@
+/*-
+ * ============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.base.testconcepts;
+
+import lombok.Data;
+
+import org.onap.policy.models.base.PfNameVersion;
+
+/**
+ * Dummy implementation of the {@link PfNameVersion} interface.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Data
+public class DummyPfNameVersion implements PfNameVersion {
+ public String name;
+ public String version;
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObject.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObject.java
new file mode 100644
index 000000000..fcf4f7790
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObject.java
@@ -0,0 +1,54 @@
+/*-
+ * ============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.base.testconcepts;
+
+import lombok.Data;
+import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
+
+import org.apache.commons.lang3.ObjectUtils;
+import org.onap.policy.models.base.PfNameVersion;
+
+/**
+ * Dummy object for filtering using the {@link DummyPfObjectFilter} interface.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Data
+@RequiredArgsConstructor
+public class DummyPfObject implements PfNameVersion, Comparable<DummyPfObject> {
+ private String name;
+ private String version;
+ private String description;
+
+ @Override
+ public int compareTo(@NonNull final DummyPfObject otherObject) {
+ int result = ObjectUtils.compare(this.name, otherObject.name);
+ if (result != 0) {
+ return result;
+ }
+ result = ObjectUtils.compare(this.version, otherObject.version);
+ if (result != 0) {
+ return result;
+ }
+ return ObjectUtils.compare(this.description, otherObject.description);
+ }
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectFilter.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectFilter.java
new file mode 100644
index 000000000..a41c9dcdd
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectFilter.java
@@ -0,0 +1,41 @@
+/*-
+ * ============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.base.testconcepts;
+
+import java.util.List;
+
+import lombok.Data;
+
+import org.onap.policy.models.base.PfObjectFilter;
+
+/**
+ * Dummy implementation of the {@link PfObjectFilter} interface.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Data
+public class DummyPfObjectFilter implements PfObjectFilter<DummyPfObject> {
+ @Override
+ public List<DummyPfObject> filter(List<DummyPfObject> originalList) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
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
index c5c0bc541..5965b728d 100644
--- 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
@@ -68,11 +68,12 @@ public class PdpGroupFilter implements PfObjectFilter<PdpGroup> {
// @formatter:off
List<PdpGroup> returnList = originalList.stream()
.filter(p -> filterOnRegexp(p.getName(), name))
- .filter(p -> filterOnRegexp(p.getVersion(), version))
+ .filter(p -> version.equals(LATEST_VERSION) || filterOnRegexp(p.getVersion(), version))
.filter(p -> ObjectUtils.compare(p.getPdpGroupState(), groupState) == 0)
.filter(p -> filterOnPdpType(p, pdpType))
.filter(p -> filterOnPolicyType(p, policyType))
.filter(p -> filterOnPolicy(p, policy))
+ .filter(p -> filterOnPdpState(p, pdpState))
.collect(Collectors.toList());
// @formatter:off
@@ -151,4 +152,27 @@ public class PdpGroupFilter implements PfObjectFilter<PdpGroup> {
return false;
}
+
+ /**
+ * Filter PDP groups on PDP state.
+ *
+ * @param pdpGroup the PDP group to check
+ * @param policyFilter the policy regular expressions to check for
+ * @return true if the filter should let this PDP group through
+ */
+ private boolean filterOnPdpState(final PdpGroup pdpGroup, final PdpState pdpState) {
+ if (pdpState == null) {
+ return true;
+ }
+
+ for (PdpSubGroup pdpSubGroup: pdpGroup.getPdpSubgroups()) {
+ for (Pdp pdp : pdpSubGroup.getPdpInstances()) {
+ if (pdpState.equals(pdp.getPdpState())) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
}
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 a1eb97dd0..bef3f1547 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
@@ -111,7 +111,7 @@ public class PdpProvider {
List<JpaPdpGroup> jpaPdpGroupList = dao.getAll(JpaPdpGroup.class);
- return asPdpGroupList(jpaPdpGroupList);
+ return filter.filter(asPdpGroupList(jpaPdpGroupList));
}
/**
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java
index d29f303f2..b4d1b3ee3 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java
@@ -58,7 +58,7 @@ public class ToscaPolicyFilter implements PfObjectFilter<ToscaPolicy> {
// @formatter:off
List<ToscaPolicy> returnList = originalList.stream()
.filter(p -> filterOnRegexp(p.getName(), name))
- .filter(p -> filterOnRegexp(p.getVersion(), version))
+ .filter(p -> version.equals(LATEST_VERSION) || filterOnRegexp(p.getVersion(), version))
.filter(p -> filterOnRegexp(p.getType(), type))
.filter(p -> filterOnRegexp(p.getTypeVersion(), typeVersion))
.collect(Collectors.toList());
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java
index 097fb6139..041179513 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java
@@ -52,7 +52,7 @@ public class ToscaPolicyTypeFilter implements PfObjectFilter<ToscaPolicyType> {
// @formatter:off
List<ToscaPolicyType> returnList = originalList.stream()
.filter(p -> filterOnRegexp(p.getName(), name))
- .filter(p -> filterOnRegexp(p.getVersion(), version))
+ .filter(p -> version.equals(LATEST_VERSION) || filterOnRegexp(p.getVersion(), version))
.collect(Collectors.toList());
// @formatter:off
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
index a843711ee..4bf014644 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
@@ -22,6 +22,7 @@ package org.onap.policy.models.tosca.authorative.provider;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -30,6 +31,7 @@ import lombok.NonNull;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.dao.PfDao;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
@@ -85,7 +87,16 @@ public class AuthorativeToscaProvider {
*/
public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final PfDao dao,
@NonNull final ToscaPolicyTypeFilter filter) throws PfModelException {
- return new SimpleToscaProvider().getFilteredPolicyTypes(dao, filter).toAuthorative();
+
+ ToscaServiceTemplate serviceTemplate =
+ new SimpleToscaProvider().getPolicyTypes(dao, null, null).toAuthorative();
+
+ List<ToscaPolicyType> filteredPolicyTypes = asConceptList(serviceTemplate.getPolicyTypes());
+ filteredPolicyTypes = filter.filter(filteredPolicyTypes);
+
+ serviceTemplate.setPolicyTypes(asConceptMap(filteredPolicyTypes));
+
+ return serviceTemplate;
}
/**
@@ -99,8 +110,7 @@ public class AuthorativeToscaProvider {
public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final PfDao dao,
@NonNull final ToscaPolicyTypeFilter filter) throws PfModelException {
- return (asConceptList(
- new SimpleToscaProvider().getFilteredPolicyTypes(dao, filter).toAuthorative().getPolicyTypes()));
+ return filter.filter(getPolicyTypeList(dao, null, null));
}
/**
@@ -190,7 +200,14 @@ public class AuthorativeToscaProvider {
public ToscaServiceTemplate getFilteredPolicies(@NonNull final PfDao dao, @NonNull final ToscaPolicyFilter filter)
throws PfModelException {
- return new SimpleToscaProvider().getFilteredPolicies(dao, filter).toAuthorative();
+ ToscaServiceTemplate serviceTemplate = new SimpleToscaProvider().getPolicies(dao, null, null).toAuthorative();
+
+ List<ToscaPolicy> filteredPolicies = asConceptList(serviceTemplate.getToscaTopologyTemplate().getPolicies());
+ filteredPolicies = filter.filter(filteredPolicies);
+
+ serviceTemplate.getToscaTopologyTemplate().setPolicies(asConceptMap(filteredPolicies));
+
+ return serviceTemplate;
}
/**
@@ -204,8 +221,7 @@ public class AuthorativeToscaProvider {
public List<ToscaPolicy> getFilteredPolicyList(@NonNull final PfDao dao, @NonNull final ToscaPolicyFilter filter)
throws PfModelException {
- return asConceptList(new SimpleToscaProvider().getFilteredPolicies(dao, filter).toAuthorative()
- .getToscaTopologyTemplate().getPolicies());
+ return filter.filter(getPolicyList(dao, null, null));
}
/**
@@ -273,4 +289,19 @@ public class AuthorativeToscaProvider {
return returnList;
}
+
+ /**
+ * Return the contents of a list of concepts as a list of maps of concepts.
+ *
+ * @param comceptList the concept list
+ * @return the concept map
+ */
+ private <T extends ToscaEntity> List<Map<String, T>> asConceptMap(List<T> conceptList) {
+ Map<String, T> conceptMap = new LinkedHashMap<>();
+ for (T concept : conceptList) {
+ conceptMap.put(concept.getName(), concept);
+ }
+
+ return Collections.singletonList(conceptMap);
+ }
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchema.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchema.java
index 1177368b2..881d87c4b 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchema.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchema.java
@@ -59,8 +59,12 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaEntrySchema;
@NoArgsConstructor
public class JpaToscaEntrySchema
implements PfAuthorative<ToscaEntrySchema>, Serializable, Comparable<JpaToscaEntrySchema> {
+
private static final long serialVersionUID = 3645882081163287058L;
+ // Recurring string constants
+ private static final String ENTRY_SCHEMA = "EntrySchema";
+
@Column
private PfConceptKey type;
@@ -157,12 +161,12 @@ public class JpaToscaEntrySchema
PfValidationResult result = resultIn;
if (type == null || type.isNullKey()) {
- result.addValidationMessage(new PfValidationMessage(new PfConceptKey("EntrySchema", PfKey.NULL_KEY_VERSION),
+ result.addValidationMessage(new PfValidationMessage(new PfConceptKey(ENTRY_SCHEMA, PfKey.NULL_KEY_VERSION),
this.getClass(), ValidationResult.INVALID, "entry schema type may not be null"));
}
if (description != null && description.trim().length() == 0) {
- result.addValidationMessage(new PfValidationMessage(new PfConceptKey("EntrySchema", PfKey.NULL_KEY_VERSION),
+ result.addValidationMessage(new PfValidationMessage(new PfConceptKey(ENTRY_SCHEMA, PfKey.NULL_KEY_VERSION),
this.getClass(), ValidationResult.INVALID, "entry schema description may not be blank"));
}
@@ -171,7 +175,7 @@ public class JpaToscaEntrySchema
for (JpaToscaConstraint constraint : constraints) {
if (constraint == null) {
result.addValidationMessage(
- new PfValidationMessage(new PfConceptKey("EntrySchema", PfKey.NULL_KEY_VERSION),
+ new PfValidationMessage(new PfConceptKey(ENTRY_SCHEMA, PfKey.NULL_KEY_VERSION),
this.getClass(), ValidationResult.INVALID, "property constraint may not be null "));
}
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java
index 6c588a50c..a207c4267 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java
@@ -33,8 +33,6 @@ import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.dao.PfDao;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
@@ -82,28 +80,6 @@ public class SimpleToscaProvider {
}
/**
- * Get filtered policy types.
- *
- * @param dao the DAO to use to access the database
- * @param filter the filter for the policy types to get
- * @return the policy types found
- * @throws PfModelException on errors getting policy types
- */
- public JpaToscaServiceTemplate getFilteredPolicyTypes(@NonNull final PfDao dao,
- @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException {
-
- // Create the structure of the TOSCA service template to contain the policy type
- JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
- serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
-
- List<JpaToscaPolicyType> jpaPolicyTypeList = dao.getAll(JpaToscaPolicyType.class);
- // TODO: The actual filtering
-
- serviceTemplate.getPolicyTypes().getConceptMap().putAll(asConceptMap(jpaPolicyTypeList));
- return serviceTemplate;
- }
-
- /**
* Create policy types.
*
* @param dao the DAO to use to access the database
@@ -213,29 +189,6 @@ public class SimpleToscaProvider {
}
/**
- * Get filtered policies.
- *
- * @param dao the DAO to use to access the database
- * @param filter the filter for the policies to get
- * @return the policies found
- * @throws PfModelException on errors getting policies
- */
- public JpaToscaServiceTemplate getFilteredPolicies(@NonNull final PfDao dao,
- @NonNull final ToscaPolicyFilter filter) throws PfModelException {
-
- // Create the structure of the TOSCA service template to contain the policy type
- JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
- serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
- serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
-
- List<JpaToscaPolicy> jpaPolicyList = dao.getAll(JpaToscaPolicy.class);
- // TODO: Do the actual filtering
-
- serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().putAll(asConceptMap(jpaPolicyList));
- return serviceTemplate;
- }
-
- /**
* Create policies.
*
* @param dao the DAO to use to access the database