diff options
author | KrupaNagabhushan <krupa.nagabhushan@est.tech> | 2021-07-14 14:21:47 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2021-07-21 14:13:29 +0000 |
commit | 0514ec6635a08cdbaac5d664c3a4f13bcb0cbf51 (patch) | |
tree | 8ece729ff236e5011b705c3c79536eb482a44a7c /catalog-dao | |
parent | a3da4a7625f75f719a0ef1ffe1c2bef87828d2f3 (diff) |
Consider component model when retrieving relationship types
Issue-ID: SDC-3640
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Change-Id: Ic06a9085b8aa2f44b8d33d7de12eadf691106131
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech>
Diffstat (limited to 'catalog-dao')
-rw-r--r-- | catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java | 61 |
1 files changed, 42 insertions, 19 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 c6ad5f2c26..b2492cdb1a 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 @@ -805,36 +805,59 @@ public class JanusGraphGenericDao { public <T extends GraphNode> Either<List<T>, JanusGraphOperationStatus> getByCriteria(NodeTypeEnum type, Map<String, Object> props, Class<T> clazz) { - Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph(); - if (graph.isLeft()) { - try { - JanusGraph tGraph = graph.left().value(); - JanusGraphQuery<? extends JanusGraphQuery> query = tGraph.query(); - query = query.has(GraphPropertiesDictionary.LABEL.getProperty(), type.getName()); - if (props != null && !props.isEmpty()) { - for (Map.Entry<String, Object> entry : props.entrySet()) { - query = query.has(entry.getKey(), entry.getValue()); - } - } - Iterable<JanusGraphVertex> vertices = query.vertices(); - if (vertices == null) { + return getByCriteriaForModel(type, props, null, clazz); + } + + public <T extends GraphNode> Either<List<T>, JanusGraphOperationStatus> getByCriteriaForModel(final NodeTypeEnum type, final Map<String, Object> props, + final String model, final Class<T> clazz) { + try { + final Either<Iterable<JanusGraphVertex>, JanusGraphOperationStatus> vertices = getVerticesByCriteria(type, props); + + if (vertices.isLeft()) { + final Predicate<? super JanusGraphVertex> filterPredicate = StringUtils.isEmpty(model) ? this::vertexNotConnectedToAnyModel : vertex -> vertexValidForModel(vertex, model); + final List<JanusGraphVertex> verticesForModel = StreamSupport.stream(vertices.left().value().spliterator(), false).filter(filterPredicate).collect(Collectors.toList()); + + if (CollectionUtils.isEmpty(verticesForModel)) { + log.debug("No vertex in graph for props ={} ", props); return Either.right(JanusGraphOperationStatus.NOT_FOUND); } - Iterator<JanusGraphVertex> iterator = vertices.iterator(); - List<T> result = new ArrayList<>(); + + final Iterator<JanusGraphVertex> iterator = verticesForModel.iterator(); + final List<T> result = new ArrayList<>(); while (iterator.hasNext()) { Vertex vertex = iterator.next(); Map<String, Object> newProp = getProperties(vertex); T element = GraphElementFactory.createElement(type.getName(), GraphElementTypeEnum.Node, newProp, clazz); result.add(element); } - if (log.isDebugEnabled()) { - log.debug("Number of fetced nodes in graph for criteria : from type = {} and properties = {} is {}", type, props, result.size()); + log.debug("Number of fetced nodes in graph for criteria : from type = {} and properties = {} is {}", type, props, result.size()); + return Either.left(result); + + } + return Either.right(vertices.right().value()); + } catch (Exception e) { + log.debug("Failed get by criteria for type = {} and properties = {}", type, props, e); + return Either.right(JanusGraphClient.handleJanusGraphException(e)); + } + } + + private Either<Iterable<JanusGraphVertex>, JanusGraphOperationStatus> getVerticesByCriteria(final NodeTypeEnum type, final Map<String, Object> props) { + final Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph(); + if (graph.isLeft()) { + try { + final JanusGraph tGraph = graph.left().value(); + JanusGraphQuery<? extends JanusGraphQuery> query = tGraph.query(); + query = query.has(GraphPropertiesDictionary.LABEL.getProperty(), type.getName()); + if (props != null && !props.isEmpty()) { + for (Map.Entry<String, Object> entry : props.entrySet()) { + query = query.has(entry.getKey(), entry.getValue()); + } } - if (result.size() == 0) { + final Iterable<JanusGraphVertex> vertices = query.vertices(); + if (vertices == null || !vertices.iterator().hasNext()) { return Either.right(JanusGraphOperationStatus.NOT_FOUND); } - return Either.left(result); + return Either.left(vertices); } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("Failed get by criteria for type = {} and properties = {}", type, props, e); |