aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-dao
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2021-06-24 11:19:45 +0100
committerMichael Morris <michael.morris@est.tech>2021-07-15 13:22:58 +0000
commit4f4f7fb796475bb4a332e798c80438b33ce7712a (patch)
tree88b0f7285acfa2e49c5ba3ad3cc4b04bf9c58dc7 /catalog-dao
parent53df976426f8845adf58e8ff9355764343a38549 (diff)
Allow only types from selected model in service creation
Issue-ID: SDC-3629 Signed-off-by: aribeiro <anderson.ribeiro@est.tech> Change-Id: I98edb8a1133b2df8d884782f3fb2758b42b94158
Diffstat (limited to 'catalog-dao')
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java8
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphUtils.java3
2 files changed, 7 insertions, 4 deletions
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java
index 19f78ced24..c6ad5f2c26 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java
@@ -851,7 +851,7 @@ public class JanusGraphGenericDao {
public <T extends GraphNode> Either<List<T>, JanusGraphOperationStatus> getByCriteriaWithPredicate(NodeTypeEnum type,
Map<String, Entry<JanusGraphPredicate, Object>> props,
- Class<T> clazz) {
+ Class<T> clazz, String modelName) {
Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
try {
@@ -871,7 +871,11 @@ public class JanusGraphGenericDao {
if (vertices == null) {
return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
- Iterator<JanusGraphVertex> iterator = vertices.iterator();
+ final Predicate<? super JanusGraphVertex> filterPredicate =
+ StringUtils.isEmpty(modelName) ? this::vertexNotConnectedToAnyModel : vertex -> vertexValidForModel(vertex, modelName);
+ final List<JanusGraphVertex> verticesForModel = StreamSupport.stream(vertices.spliterator(), false).filter(filterPredicate)
+ .collect(Collectors.toList());
+ Iterator<JanusGraphVertex> iterator = verticesForModel.iterator();
List<T> result = new ArrayList<>();
while (iterator.hasNext()) {
Vertex vertex = iterator.next();
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphUtils.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphUtils.java
index 1e62a952cf..941e13af6b 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphUtils.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphUtils.java
@@ -19,7 +19,6 @@
*/
package org.openecomp.sdc.be.dao.janusgraph;
-import static java.util.Collections.emptyMap;
import static org.apache.commons.collections.CollectionUtils.isEmpty;
import static org.janusgraph.core.attribute.Contain.NOT_IN;
@@ -36,7 +35,7 @@ public class JanusGraphUtils {
public static <T> Map<String, Entry<JanusGraphPredicate, Object>> buildNotInPredicate(String propKey, Collection<T> notInCollection) {
if (isEmpty(notInCollection)) {
- return emptyMap();
+ return new HashMap<>();
}
Map<String, Entry<JanusGraphPredicate, Object>> predicateCriteria = new HashMap<>();
predicateCriteria.put(propKey, new HashMap.SimpleEntry<>(NOT_IN, notInCollection));