summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java3
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java33
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java16
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java8
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java22
-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-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SdncSimulatorJaxRs.java21
-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
18 files changed, 458 insertions, 79 deletions
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 e197e13a4..65a28cffe 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
@@ -170,6 +170,9 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex
if (incomingConceptEntry.getValue().getVersion() != null) {
conceptKey.setVersion(incomingConceptEntry.getValue().getVersion());
}
+ else {
+ conceptKey.setVersion(PfKey.NULL_KEY_VERSION);
+ }
// After all that, save the map entry
conceptMap.put(conceptKey, jpaConcept);
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 a377c24be..a7d8401f0 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
@@ -59,26 +59,31 @@ public interface PfObjectFilter<T extends Comparable<T>> {
* @return the filtered list
*/
public default List<T> latestVersionFilter(final List<T> originalList) {
- List<T> filteredList = new ArrayList<>();
- Collections.sort(filteredList);
+ if (originalList.size() <= 1) {
+ return originalList;
+ }
- List<T> filteredOutList = new ArrayList<>();
+ List<T> filteredList = new ArrayList<>(originalList);
+ Collections.sort(filteredList);
- for (int i = 1; i < filteredList.size(); i++) {
+ int icur = 0;
+ for (int j = 1; j < filteredList.size(); j++) {
// Get the current and last element
- T thisElement = filteredList.get(i);
- T lastElement = filteredList.get(i - 1);
+ T curElement = filteredList.get(icur);
+ T lastElement = filteredList.get(j);
- // The list is sorted so if the last element name is the same as the current element name, the last element
- // should be removed
- if (((PfNameVersion)thisElement).getName().equals(((PfNameVersion)lastElement).getName())) {
- filteredOutList.add(lastElement);
+ /*
+ * 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())) {
+ // have a new name - done comparing with the old "current"
+ ++icur;
}
- }
- // We can now remove these elements
- filteredList.removeAll(filteredOutList);
+ filteredList.set(icur, lastElement);
+ }
- return filteredList;
+ return new ArrayList<>(filteredList.subList(0, icur + 1));
}
}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
index 3ae7c4c9d..55f59f640 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
@@ -48,6 +48,7 @@ import org.onap.policy.models.base.testconcepts.DummyPfConceptSub;
*/
public class PfConceptContainerTest {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testConceptContainer() {
DummyPfConceptContainer container = new DummyPfConceptContainer();
@@ -63,6 +64,13 @@ public class PfConceptContainerTest {
assertNotNull(container);
try {
+ new PfConceptContainer((PfConceptKey) null, null);
+ fail("test should throw an exception here");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
container = new DummyPfConceptContainer((PfConceptKey) null, null);
fail("test should throw an exception here");
} catch (Exception exc) {
@@ -190,7 +198,7 @@ public class PfConceptContainerTest {
public void testAuthorative() {
Map<String, DummyAuthorativeConcept> dacMap = new LinkedHashMap<>();
dacMap.put("name0", new DummyAuthorativeConcept("name0", "1.2.3", "Hello"));
- dacMap.put("name1", new DummyAuthorativeConcept("name1", "1.2.3", "Hi"));
+ dacMap.put("name1", new DummyAuthorativeConcept(null, null, "Hi"));
dacMap.put("name2", new DummyAuthorativeConcept("name2", "1.2.3", "Howdy"));
List<Map<String, DummyAuthorativeConcept>> authorativeList = new ArrayList<>();
@@ -200,12 +208,14 @@ public class PfConceptContainerTest {
container.fromAuthorative(authorativeList);
assertEquals("Hello", container.getConceptMap().get(new PfConceptKey("name0:1.2.3")).getDescription());
- assertEquals("Hi", container.getConceptMap().get(new PfConceptKey("name1:1.2.3")).getDescription());
+ assertEquals("Hi", container.getConceptMap().get(new PfConceptKey("name1:0.0.0")).getDescription());
assertEquals("Howdy", container.getConceptMap().get(new PfConceptKey("name2:1.2.3")).getDescription());
List<Map<String, DummyAuthorativeConcept>> outMapList = container.toAuthorative();
- assertEquals(dacMap, outMapList.get(0));
+ assertEquals(dacMap.get("name0"), outMapList.get(0).get("name0"));
+ assertEquals(dacMap.get("name1").getDescription(), outMapList.get(0).get("name1").getDescription());
+ assertEquals(dacMap.get("name2"), outMapList.get(0).get("name2"));
DummyBadPfConceptContainer badContainer = new DummyBadPfConceptContainer();
assertThatThrownBy(() -> {
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java
index a4c504788..797dba0cf 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java
@@ -48,6 +48,13 @@ public class PfKeyTest {
e.getMessage());
}
+ try {
+ new PfConceptKey((PfConceptKey) null);
+ fail("This test should throw an exception");
+ } catch (Exception e) {
+ assertEquals("copyConcept is marked @NonNull but is null", e.getMessage());
+ }
+
PfConceptKey someKey0 = new PfConceptKey();
assertEquals(PfConceptKey.getNullKey(), someKey0);
@@ -56,6 +63,7 @@ public class PfKeyTest {
PfConceptKey someKey3 = new PfConceptKey(someKey1.getId());
assertEquals(someKey1, someKey2);
assertEquals(someKey1, someKey3);
+ assertFalse(someKey1.isNullVersion());
assertEquals(someKey2, someKey1.getKey());
assertEquals(1, someKey1.getKeys().size());
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java
index 72df28f04..68494309c 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java
@@ -1,4 +1,4 @@
-/*
+/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
* ================================================================================
@@ -41,7 +41,7 @@ public class PfKeyUseTest {
assertNotNull(new PfKeyUse(new PfReferenceKey()));
try {
- new PfKeyUse((PfKeyUse)null);
+ new PfKeyUse((PfKeyUse) null);
fail("test should throw an exception");
} catch (Exception exc) {
assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
@@ -56,6 +56,14 @@ public class PfKeyUseTest {
assertFalse(keyUse.isNullKey());
assertEquals(Compatibility.IDENTICAL, keyUse.getCompatibility(key));
+
+ try {
+ key.getCompatibility(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("otherKey is marked @NonNull but is null", exc.getMessage());
+ }
+
assertTrue(keyUse.isCompatible(key));
keyUse.clean();
@@ -132,6 +140,16 @@ public class PfKeyUseTest {
assertEquals("error copying concept key: Some error message", exc.getMessage());
}
+ try {
+ keyUse.isNewerThan(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("otherKey is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertEquals(false, testKeyUse.isNewerThan(keyUse));
+ assertEquals(false, testKeyUse.isNewerThan(testKeyUse));
+
assertEquals(0, testKeyUse.getMajorVersion());
assertEquals(0, testKeyUse.getMinorVersion());
assertEquals(0, testKeyUse.getPatchVersion());
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-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SdncSimulatorJaxRs.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SdncSimulatorJaxRs.java
index 1b40ae486..72106ff52 100644
--- a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SdncSimulatorJaxRs.java
+++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SdncSimulatorJaxRs.java
@@ -56,4 +56,25 @@ public class SdncSimulatorJaxRs {
response.setResponseOutput(responseOutput);
return Serialization.gsonPretty.toJson(response);
}
+
+
+ /**
+ * SDNC vnf topology operation.
+ *
+ * @return the response
+ */
+ @POST
+ @Path("/GENERIC-RESOURCE-API:vnf-topology-operation")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces("application/json")
+ public String sdncVnfTopologyOperation() {
+ final SdncResponse response = new SdncResponse();
+ response.setRequestId(UUID.randomUUID().toString());
+ SdncResponseOutput responseOutput = new SdncResponseOutput();
+ responseOutput.setResponseCode("200");
+ responseOutput.setAckFinalIndicator("Y");
+ responseOutput.setSvcRequestId(UUID.randomUUID().toString());
+ response.setResponseOutput(responseOutput);
+ return Serialization.gsonPretty.toJson(response);
+ }
}
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