summaryrefslogtreecommitdiffstats
path: root/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java')
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java390
1 files changed, 188 insertions, 202 deletions
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java
index bda3709d7d..3e10c7941d 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java
@@ -7,9 +7,9 @@
* 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.
@@ -17,16 +17,34 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.dao.jsongraph;
-import org.janusgraph.core.*;
-import org.janusgraph.graphdb.query.JanusGraphPredicate;
+import static org.apache.commons.collections.CollectionUtils.isEmpty;
+
import fj.data.Either;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.apache.tinkerpop.gremlin.structure.*;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
+import org.janusgraph.core.JanusGraph;
+import org.janusgraph.core.JanusGraphEdge;
+import org.janusgraph.core.JanusGraphQuery;
+import org.janusgraph.core.JanusGraphVertex;
+import org.janusgraph.core.JanusGraphVertexQuery;
+import org.janusgraph.core.PropertyKey;
+import org.janusgraph.graphdb.query.JanusGraphPredicate;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
@@ -43,17 +61,10 @@ import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Qualifier;
-import java.io.IOException;
-import java.util.*;
-import java.util.Map.Entry;
-
-import static org.apache.commons.collections.CollectionUtils.isEmpty;
-
-
public class JanusGraphDao {
- JanusGraphClient janusGraphClient;
private static Logger logger = Logger.getLogger(JanusGraphDao.class.getName());
+ JanusGraphClient janusGraphClient;
public JanusGraphDao(@Qualifier("janusgraph-client") JanusGraphClient janusGraphClient) {
this.janusGraphClient = janusGraphClient;
@@ -75,7 +86,6 @@ public class JanusGraphDao {
}
/**
- *
* @param graphVertex
* @return
*/
@@ -85,18 +95,14 @@ public class JanusGraphDao {
if (graph.isLeft()) {
try {
JanusGraph tGraph = graph.left().value();
-
JanusGraphVertex vertex = tGraph.addVertex();
-
setVertexProperties(vertex, graphVertex);
-
graphVertex.setVertex(vertex);
-
return Either.left(graphVertex);
-
} catch (Exception e) {
- logger.error(EcompLoggerErrorCode.DATA_ERROR, "JanusGraphDao",
- "Failed to create Node for ID '{}'", (Object) graphVertex.getUniqueId(), e);
+ logger
+ .error(EcompLoggerErrorCode.DATA_ERROR, "JanusGraphDao", "Failed to create Node for ID '{}'", (Object) graphVertex.getUniqueId(),
+ e);
return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
} else {
@@ -106,7 +112,6 @@ public class JanusGraphDao {
}
/**
- *
* @param name
* @param value
* @param label
@@ -117,7 +122,8 @@ public class JanusGraphDao {
}
public Either<GraphVertex, JanusGraphOperationStatus> getVertexByLabel(VertexTypeEnum label) {
- return janusGraphClient.getGraph().left().map(graph -> graph.query().has(GraphPropertyEnum.LABEL.getProperty(), label.getName()).vertices()).left().bind(janusGraphVertices -> getFirstFoundVertex(JsonParseFlagEnum.NoParse, janusGraphVertices));
+ return janusGraphClient.getGraph().left().map(graph -> graph.query().has(GraphPropertyEnum.LABEL.getProperty(), label.getName()).vertices())
+ .left().bind(janusGraphVertices -> getFirstFoundVertex(JsonParseFlagEnum.NoParse, janusGraphVertices));
}
private Either<GraphVertex, JanusGraphOperationStatus> getFirstFoundVertex(JsonParseFlagEnum parseFlag, Iterable<JanusGraphVertex> vertices) {
@@ -125,35 +131,30 @@ public class JanusGraphDao {
if (iterator.hasNext()) {
JanusGraphVertex vertex = iterator.next();
GraphVertex graphVertex = createAndFill(vertex, parseFlag);
-
return Either.left(graphVertex);
}
return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
/**
- *
* @param name
* @param value
* @param label
* @param parseFlag
* @return
*/
- public Either<GraphVertex, JanusGraphOperationStatus> getVertexByPropertyAndLabel(GraphPropertyEnum name, Object value, VertexTypeEnum label, JsonParseFlagEnum parseFlag) {
-
+ public Either<GraphVertex, JanusGraphOperationStatus> getVertexByPropertyAndLabel(GraphPropertyEnum name, Object value, VertexTypeEnum label,
+ JsonParseFlagEnum parseFlag) {
Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
try {
JanusGraph tGraph = graph.left().value();
-
- @SuppressWarnings("unchecked")
- Iterable<JanusGraphVertex> vertecies = tGraph.query().has(name.getProperty(), value).has(GraphPropertyEnum.LABEL.getProperty(), label.getName()).vertices();
-
+ @SuppressWarnings("unchecked") Iterable<JanusGraphVertex> vertecies = tGraph.query().has(name.getProperty(), value)
+ .has(GraphPropertyEnum.LABEL.getProperty(), label.getName()).vertices();
java.util.Iterator<JanusGraphVertex> iterator = vertecies.iterator();
if (iterator.hasNext()) {
JanusGraphVertex vertex = iterator.next();
GraphVertex graphVertex = createAndFill(vertex, parseFlag);
-
return Either.left(graphVertex);
}
if (logger.isDebugEnabled()) {
@@ -166,7 +167,6 @@ public class JanusGraphDao {
}
return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
-
} else {
if (logger.isDebugEnabled()) {
logger.debug("No vertex in graph for key ={} and value = {} label = {} error :{}", name, value, label, graph.right().value());
@@ -176,7 +176,6 @@ public class JanusGraphDao {
}
/**
- *
* @param id
* @return
*/
@@ -185,13 +184,11 @@ public class JanusGraphDao {
}
/**
- *
* @param id
* @param parseFlag
* @return
*/
public Either<GraphVertex, JanusGraphOperationStatus> getVertexById(String id, JsonParseFlagEnum parseFlag) {
-
Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (id == null) {
if (logger.isDebugEnabled()) {
@@ -202,10 +199,8 @@ public class JanusGraphDao {
if (graph.isLeft()) {
try {
JanusGraph tGraph = graph.left().value();
-
- @SuppressWarnings("unchecked")
- Iterable<JanusGraphVertex> vertecies = tGraph.query().has(GraphPropertyEnum.UNIQUE_ID.getProperty(), id).vertices();
-
+ @SuppressWarnings("unchecked") Iterable<JanusGraphVertex> vertecies = tGraph.query()
+ .has(GraphPropertyEnum.UNIQUE_ID.getProperty(), id).vertices();
java.util.Iterator<JanusGraphVertex> iterator = vertecies.iterator();
if (iterator.hasNext()) {
JanusGraphVertex vertex = iterator.next();
@@ -232,7 +227,6 @@ public class JanusGraphDao {
}
private void setVertexProperties(JanusGraphVertex vertex, GraphVertex graphVertex) throws IOException {
-
if (graphVertex.getMetadataProperties() != null) {
for (Map.Entry<GraphPropertyEnum, Object> entry : graphVertex.getMetadataProperties().entrySet()) {
if (entry.getValue() != null) {
@@ -241,12 +235,10 @@ public class JanusGraphDao {
}
}
vertex.property(GraphPropertyEnum.LABEL.getProperty(), graphVertex.getLabel().getName());
-
Map<String, ? extends ToscaDataDefinition> json = graphVertex.getJson();
if (json != null) {
String jsonStr = JsonParserUtils.toJson(json);
vertex.property(GraphPropertyEnum.JSON.getProperty(), jsonStr);
-
}
Map<String, Object> jsonMetadata = graphVertex.getMetadataJson();
if (jsonMetadata != null) {
@@ -277,35 +269,35 @@ public class JanusGraphDao {
for (Map.Entry<GraphPropertyEnum, Object> entry : properties.entrySet()) {
GraphPropertyEnum key = entry.getKey();
switch (key) {
- case UNIQUE_ID:
- graphVertex.setUniqueId((String) entry.getValue());
- break;
- case LABEL:
- graphVertex.setLabel(VertexTypeEnum.getByName((String) entry.getValue()));
- break;
- case COMPONENT_TYPE:
- String type = (String) entry.getValue();
- if (type != null) {
- graphVertex.setType(ComponentTypeEnum.valueOf(type));
- }
- break;
- case JSON:
- if (parseFlag == JsonParseFlagEnum.ParseAll || parseFlag == JsonParseFlagEnum.ParseJson) {
- String json = (String) entry.getValue();
- Map<String, ? extends ToscaDataDefinition> jsonObj = JsonParserUtils.toMap(json, label.getClassOfJson());
- graphVertex.setJson(jsonObj);
- }
- break;
- case METADATA:
- if (parseFlag == JsonParseFlagEnum.ParseAll || parseFlag == JsonParseFlagEnum.ParseMetadata) {
- String json = (String) entry.getValue();
- Map<String, Object> metadatObj = JsonParserUtils.toMap(json);
- graphVertex.setMetadataJson(metadatObj);
- }
- break;
- default:
- graphVertex.addMetadataProperty(key, entry.getValue());
- break;
+ case UNIQUE_ID:
+ graphVertex.setUniqueId((String) entry.getValue());
+ break;
+ case LABEL:
+ graphVertex.setLabel(VertexTypeEnum.getByName((String) entry.getValue()));
+ break;
+ case COMPONENT_TYPE:
+ String type = (String) entry.getValue();
+ if (type != null) {
+ graphVertex.setType(ComponentTypeEnum.valueOf(type));
+ }
+ break;
+ case JSON:
+ if (parseFlag == JsonParseFlagEnum.ParseAll || parseFlag == JsonParseFlagEnum.ParseJson) {
+ String json = (String) entry.getValue();
+ Map<String, ? extends ToscaDataDefinition> jsonObj = JsonParserUtils.toMap(json, label.getClassOfJson());
+ graphVertex.setJson(jsonObj);
+ }
+ break;
+ case METADATA:
+ if (parseFlag == JsonParseFlagEnum.ParseAll || parseFlag == JsonParseFlagEnum.ParseMetadata) {
+ String json = (String) entry.getValue();
+ Map<String, Object> metadatObj = JsonParserUtils.toMap(json);
+ graphVertex.setMetadataJson(metadatObj);
+ }
+ break;
+ default:
+ graphVertex.addMetadataProperty(key, entry.getValue());
+ break;
}
}
}
@@ -317,13 +309,13 @@ public class JanusGraphDao {
public JanusGraphOperationStatus createEdge(Vertex from, Vertex to, EdgeLabelEnum label, Map<EdgePropertyEnum, Object> properties) {
if (logger.isTraceEnabled()) {
logger.trace("Try to connect {} with {} label {} properties {}",
- from == null ? "NULL" : from.property(GraphPropertyEnum.UNIQUE_ID.getProperty()),
- to == null ? "NULL" : to.property(GraphPropertyEnum.UNIQUE_ID.getProperty()), label, properties);
+ from == null ? "NULL" : from.property(GraphPropertyEnum.UNIQUE_ID.getProperty()),
+ to == null ? "NULL" : to.property(GraphPropertyEnum.UNIQUE_ID.getProperty()), label, properties);
}
if (from == null || to == null) {
logger.trace("No JanusGraph vertex for id from {} or id to {}",
- from == null ? "NULL" : from.property(GraphPropertyEnum.UNIQUE_ID.getProperty()),
- to == null ? "NULL" : to.property(GraphPropertyEnum.UNIQUE_ID.getProperty()));
+ from == null ? "NULL" : from.property(GraphPropertyEnum.UNIQUE_ID.getProperty()),
+ to == null ? "NULL" : to.property(GraphPropertyEnum.UNIQUE_ID.getProperty()));
return JanusGraphOperationStatus.NOT_FOUND;
}
Edge edge = from.addEdge(label.name(), to);
@@ -332,24 +324,19 @@ public class JanusGraphDao {
setEdgeProperties(edge, properties);
status = JanusGraphOperationStatus.OK;
} catch (IOException e) {
- logger.error(EcompLoggerErrorCode.DATA_ERROR, "JanusGraphDao",
- "Failed to set properties on edge properties [{}]", properties, e);
+ logger.error(EcompLoggerErrorCode.DATA_ERROR, "JanusGraphDao", "Failed to set properties on edge properties [{}]", properties, e);
status = JanusGraphOperationStatus.GENERAL_ERROR;
}
return status;
}
public Map<GraphPropertyEnum, Object> getVertexProperties(Element element) {
-
Map<GraphPropertyEnum, Object> result = new HashMap<>();
-
if (element != null && element.keys() != null && element.keys().size() > 0) {
Map<String, Property> propertyMap = ElementHelper.propertyMap(element, element.keys().toArray(new String[element.keys().size()]));
-
for (Entry<String, Property> entry : propertyMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue().value();
-
GraphPropertyEnum valueOf = GraphPropertyEnum.getByProperty(key);
if (valueOf != null) {
result.put(valueOf, value);
@@ -361,16 +348,12 @@ public class JanusGraphDao {
}
public Map<EdgePropertyEnum, Object> getEdgeProperties(Element element) {
-
Map<EdgePropertyEnum, Object> result = new HashMap<>();
-
if (element != null && element.keys() != null && element.keys().size() > 0) {
Map<String, Property> propertyMap = ElementHelper.propertyMap(element, element.keys().toArray(new String[element.keys().size()]));
-
for (Entry<String, Property> entry : propertyMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue().value();
-
EdgePropertyEnum valueOf = EdgePropertyEnum.getByProperty(key);
if (valueOf != null) {
if (valueOf == EdgePropertyEnum.INSTANCES) {
@@ -386,9 +369,7 @@ public class JanusGraphDao {
}
public void setEdgeProperties(Element element, Map<EdgePropertyEnum, Object> properties) throws IOException {
-
if (properties != null && !properties.isEmpty()) {
-
Object[] propertyKeyValues = new Object[properties.size() * 2];
int i = 0;
for (Entry<EdgePropertyEnum, Object> entry : properties.entrySet()) {
@@ -409,17 +390,16 @@ public class JanusGraphDao {
return getByCriteria(type, props, JsonParseFlagEnum.ParseAll);
}
- public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(VertexTypeEnum type, Map<GraphPropertyEnum, Object> props, JsonParseFlagEnum parseFlag) {
+ public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(VertexTypeEnum type, Map<GraphPropertyEnum, Object> props,
+ JsonParseFlagEnum parseFlag) {
Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
try {
JanusGraph tGraph = graph.left().value();
-
JanusGraphQuery<? extends JanusGraphQuery> query = tGraph.query();
if (type != null) {
query = query.has(GraphPropertyEnum.LABEL.getProperty(), type.getName());
}
-
if (props != null && !props.isEmpty()) {
for (Map.Entry<GraphPropertyEnum, Object> entry : props.entrySet()) {
query = query.has(entry.getKey().getProperty(), entry.getValue());
@@ -429,25 +409,21 @@ public class JanusGraphDao {
if (vertices == null) {
return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
-
Iterator<JanusGraphVertex> iterator = vertices.iterator();
List<GraphVertex> result = new ArrayList<>();
-
while (iterator.hasNext()) {
JanusGraphVertex vertex = iterator.next();
-
Map<GraphPropertyEnum, Object> newProp = getVertexProperties(vertex);
GraphVertex graphVertex = createAndFill(vertex, parseFlag);
-
result.add(graphVertex);
}
if (logger.isDebugEnabled()) {
- logger.debug("Number of fetced nodes in graph for criteria : from type = {} and properties = {} is {}", type, props, result.size());
+ logger
+ .debug("Number of fetced nodes in graph for criteria : from type = {} and properties = {} is {}", type, props, result.size());
}
if (result.size() == 0) {
return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
-
return Either.left(result);
} catch (Exception e) {
if (logger.isDebugEnabled()) {
@@ -455,7 +431,6 @@ public class JanusGraphDao {
}
return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
-
} else {
if (logger.isDebugEnabled()) {
logger.debug("Failed get by criteria for type ={} and properties = {} error : {}", type, props, graph.right().value());
@@ -464,23 +439,25 @@ public class JanusGraphDao {
}
}
- public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(VertexTypeEnum type, Map<GraphPropertyEnum, Object> props, Map<GraphPropertyEnum, Object> hasNotProps, JsonParseFlagEnum parseFlag) {
+ public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(VertexTypeEnum type, Map<GraphPropertyEnum, Object> props,
+ Map<GraphPropertyEnum, Object> hasNotProps,
+ JsonParseFlagEnum parseFlag) {
return getByCriteria(type, props, hasNotProps, null, parseFlag);
}
-
+
public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(final VertexTypeEnum type,
- final Map<GraphPropertyEnum, Object> hasProps, final Map<GraphPropertyEnum, Object> hasNotProps,
- final Map<String, Entry<JanusGraphPredicate, Object>> predicates, final JsonParseFlagEnum parseFlag) {
+ final Map<GraphPropertyEnum, Object> hasProps,
+ final Map<GraphPropertyEnum, Object> hasNotProps,
+ final Map<String, Entry<JanusGraphPredicate, Object>> predicates,
+ final JsonParseFlagEnum parseFlag) {
Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
try {
JanusGraph tGraph = graph.left().value();
-
JanusGraphQuery<? extends JanusGraphQuery> query = tGraph.query();
if (type != null) {
query = query.has(GraphPropertyEnum.LABEL.getProperty(), type.getName());
}
-
if (hasProps != null && !hasProps.isEmpty()) {
for (Map.Entry<GraphPropertyEnum, Object> entry : hasProps.entrySet()) {
query = query.has(entry.getKey().getProperty(), entry.getValue());
@@ -506,14 +483,12 @@ public class JanusGraphDao {
if (vertices == null || !vertices.iterator().hasNext()) {
return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
-
List<GraphVertex> result = new ArrayList<>();
vertices.forEach(vertex -> result.add(createAndFill(vertex, parseFlag)));
-
if (logger.isDebugEnabled()) {
- logger.debug("Number of fetched nodes in graph for criteria : from type '{}' and properties '{}' is '{}'", type, hasProps, result.size());
+ logger.debug("Number of fetched nodes in graph for criteria : from type '{}' and properties '{}' is '{}'", type, hasProps,
+ result.size());
}
-
return Either.left(result);
} catch (Exception e) {
if (logger.isDebugEnabled()) {
@@ -521,7 +496,6 @@ public class JanusGraphDao {
}
return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
-
} else {
if (logger.isDebugEnabled()) {
logger.debug("Failed to get by criteria for type '{}' and properties '{}'. Error : '{}'", type, hasProps, graph.right().value());
@@ -535,7 +509,6 @@ public class JanusGraphDao {
if (graph.isLeft()) {
try {
JanusGraph tGraph = graph.left().value();
-
String name = isCatalog ? VertexTypeEnum.CATALOG_ROOT.getName() : VertexTypeEnum.ARCHIVE_ROOT.getName();
Iterable<JanusGraphVertex> vCatalogIter = tGraph.query().has(GraphPropertyEnum.LABEL.getProperty(), name).vertices();
if (vCatalogIter == null) {
@@ -549,7 +522,6 @@ public class JanusGraphDao {
}
String edgeLabel = isCatalog ? EdgeLabelEnum.CATALOG_ELEMENT.name() : EdgeLabelEnum.ARCHIVE_ELEMENT.name();
Iterator<Vertex> vertices = catalogV.vertices(Direction.OUT, edgeLabel);
-
return Either.left(vertices);
} catch (Exception e) {
if (logger.isDebugEnabled()) {
@@ -557,7 +529,6 @@ public class JanusGraphDao {
}
return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
-
} else {
if (logger.isDebugEnabled()) {
logger.debug("Failed get by criteria : ", graph.right().value());
@@ -574,13 +545,13 @@ public class JanusGraphDao {
}
/**
- *
* @param parentVertex
* @param edgeLabel
* @param parseFlag
* @return
*/
- public Either<GraphVertex, JanusGraphOperationStatus> getChildVertex(GraphVertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
+ public Either<GraphVertex, JanusGraphOperationStatus> getChildVertex(GraphVertex parentVertex, EdgeLabelEnum edgeLabel,
+ JsonParseFlagEnum parseFlag) {
Either<List<GraphVertex>, JanusGraphOperationStatus> childrenVertecies = getChildrenVertices(parentVertex, edgeLabel, parseFlag);
if (childrenVertecies.isRight()) {
return Either.right(childrenVertecies.right().value());
@@ -589,7 +560,6 @@ public class JanusGraphDao {
}
/**
- *
* @param parentVertex
* @param edgeLabel
* @param parseFlag
@@ -603,12 +573,13 @@ public class JanusGraphDao {
return Either.left(childrenVertecies.left().value().get(0));
}
- public Either<GraphVertex, JanusGraphOperationStatus> getParentVertex(GraphVertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
+ public Either<GraphVertex, JanusGraphOperationStatus> getParentVertex(GraphVertex parentVertex, EdgeLabelEnum edgeLabel,
+ JsonParseFlagEnum parseFlag) {
Either<List<GraphVertex>, JanusGraphOperationStatus> childrenVertecies = getParentVertices(parentVertex, edgeLabel, parseFlag);
if (childrenVertecies.isRight()) {
return Either.right(childrenVertecies.right().value());
}
- if (isEmpty(childrenVertecies.left().value())){
+ if (isEmpty(childrenVertecies.left().value())) {
return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
return Either.left(childrenVertecies.left().value().get(0));
@@ -616,35 +587,38 @@ public class JanusGraphDao {
public Either<Vertex, JanusGraphOperationStatus> getParentVertex(Vertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
Either<List<Vertex>, JanusGraphOperationStatus> childrenVertecies = getParentVertices(parentVertex, edgeLabel, parseFlag);
- if (childrenVertecies.isRight() ) {
+ if (childrenVertecies.isRight()) {
return Either.right(childrenVertecies.right().value());
}
- if (isEmpty(childrenVertecies.left().value())){
+ if (isEmpty(childrenVertecies.left().value())) {
return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
return Either.left(childrenVertecies.left().value().get(0));
}
/**
- *
* @param parentVertex
* @param edgeLabel
* @param parseFlag
* @return
*/
- public Either<List<GraphVertex>, JanusGraphOperationStatus> getChildrenVertices(GraphVertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
+ public Either<List<GraphVertex>, JanusGraphOperationStatus> getChildrenVertices(GraphVertex parentVertex, EdgeLabelEnum edgeLabel,
+ JsonParseFlagEnum parseFlag) {
return getAdjacentVertices(parentVertex, edgeLabel, parseFlag, Direction.OUT);
}
- public Either<List<GraphVertex>, JanusGraphOperationStatus> getParentVertices(GraphVertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
+ public Either<List<GraphVertex>, JanusGraphOperationStatus> getParentVertices(GraphVertex parentVertex, EdgeLabelEnum edgeLabel,
+ JsonParseFlagEnum parseFlag) {
return getAdjacentVertices(parentVertex, edgeLabel, parseFlag, Direction.IN);
}
- public Either<List<Vertex>, JanusGraphOperationStatus> getParentVertices(Vertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
+ public Either<List<Vertex>, JanusGraphOperationStatus> getParentVertices(Vertex parentVertex, EdgeLabelEnum edgeLabel,
+ JsonParseFlagEnum parseFlag) {
return getAdjacentVertices(parentVertex, edgeLabel, parseFlag, Direction.IN);
}
- private Either<List<Vertex>, JanusGraphOperationStatus> getAdjacentVertices(Vertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag, Direction direction) {
+ private Either<List<Vertex>, JanusGraphOperationStatus> getAdjacentVertices(Vertex parentVertex, EdgeLabelEnum edgeLabel,
+ JsonParseFlagEnum parseFlag, Direction direction) {
List<Vertex> list = new ArrayList<>();
try {
Either<JanusGraph, JanusGraphOperationStatus> graphRes = janusGraphClient.getGraph();
@@ -663,7 +637,6 @@ public class JanusGraphDao {
vertex = (JanusGraphVertex) edge.inVertex();
}
// GraphVertex graphVertex = createAndFill(vertex, parseFlag);
-
list.add(vertex);
}
}
@@ -674,57 +647,54 @@ public class JanusGraphDao {
logger.error("Failed to perform graph operation ", e);
Either.right(JanusGraphClient.handleJanusGraphException(e));
}
-
return Either.left(list);
}
/**
- *
* @param parentVertex
* @param edgeLabel
* @param parseFlag
* @return
*/
- public Either<List<Vertex>, JanusGraphOperationStatus> getChildrenVertices(Vertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
+ public Either<List<Vertex>, JanusGraphOperationStatus> getChildrenVertices(Vertex parentVertex, EdgeLabelEnum edgeLabel,
+ JsonParseFlagEnum parseFlag) {
return getAdjacentVertices(parentVertex, edgeLabel, parseFlag, Direction.OUT);
}
- private Either<List<GraphVertex>, JanusGraphOperationStatus> getAdjacentVertices(GraphVertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag, Direction direction) {
+ private Either<List<GraphVertex>, JanusGraphOperationStatus> getAdjacentVertices(GraphVertex parentVertex, EdgeLabelEnum edgeLabel,
+ JsonParseFlagEnum parseFlag, Direction direction) {
List<GraphVertex> list = new ArrayList<>();
-
- Either<List<Vertex>, JanusGraphOperationStatus> adjacentVerticies = getAdjacentVertices(parentVertex.getVertex(), edgeLabel, parseFlag, direction);
+ Either<List<Vertex>, JanusGraphOperationStatus> adjacentVerticies = getAdjacentVertices(parentVertex.getVertex(), edgeLabel, parseFlag,
+ direction);
if (adjacentVerticies.isRight()) {
return Either.right(adjacentVerticies.right().value());
}
adjacentVerticies.left().value().stream().forEach(vertex -> {
list.add(createAndFill((JanusGraphVertex) vertex, parseFlag));
});
-
return Either.left(list);
}
/**
* Searches Edge by received label and criteria
- *
+ *
* @param vertex
* @param label
* @param properties
* @return found edge or JanusGraphOperationStatus
*/
- public Either<Edge, JanusGraphOperationStatus> getBelongingEdgeByCriteria(GraphVertex vertex, EdgeLabelEnum label, Map<GraphPropertyEnum, Object> properties) {
-
+ public Either<Edge, JanusGraphOperationStatus> getBelongingEdgeByCriteria(GraphVertex vertex, EdgeLabelEnum label,
+ Map<GraphPropertyEnum, Object> properties) {
Either<Edge, JanusGraphOperationStatus> result = null;
Edge matchingEdge = null;
String notFoundMsg = "No edges in graph for criteria";
try {
JanusGraphVertexQuery<?> query = vertex.getVertex().query().labels(label.name());
-
if (properties != null && !properties.isEmpty()) {
for (Map.Entry<GraphPropertyEnum, Object> entry : properties.entrySet()) {
query = query.has(entry.getKey().getProperty(), entry.getValue());
}
}
-
Iterable<JanusGraphEdge> edges = query.edges();
if (edges == null) {
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, notFoundMsg);
@@ -742,24 +712,26 @@ public class JanusGraphDao {
result = Either.left(matchingEdge);
}
} catch (Exception e) {
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Exception occured during getting edge by criteria for component with id {}. {}", vertex.getUniqueId(), e);
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Exception occured during getting edge by criteria for component with id {}. {}",
+ vertex.getUniqueId(), e);
return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
return result;
}
- public Either<Edge, JanusGraphOperationStatus> getEdgeByChildrenVertexProperties(GraphVertex vertex, EdgeLabelEnum label, Map<GraphPropertyEnum, Object> properties) {
+ public Either<Edge, JanusGraphOperationStatus> getEdgeByChildrenVertexProperties(GraphVertex vertex, EdgeLabelEnum label,
+ Map<GraphPropertyEnum, Object> properties) {
Either<Edge, JanusGraphOperationStatus> result = null;
Edge matchingEdge = null;
String notFoundMsg = "No edges in graph for criteria";
try {
-
Iterator<Edge> edges = vertex.getVertex().edges(Direction.OUT, label.name());
while (edges.hasNext()) {
matchingEdge = edges.next();
Vertex childV = matchingEdge.inVertex();
Map<GraphPropertyEnum, Object> vertexProperties = getVertexProperties(childV);
- Optional<Entry<GraphPropertyEnum, Object>> findNotMatch = properties.entrySet().stream().filter(e -> vertexProperties.get(e.getKey()) == null || !vertexProperties.get(e.getKey()).equals(e.getValue())).findFirst();
+ Optional<Entry<GraphPropertyEnum, Object>> findNotMatch = properties.entrySet().stream()
+ .filter(e -> vertexProperties.get(e.getKey()) == null || !vertexProperties.get(e.getKey()).equals(e.getValue())).findFirst();
if (!findNotMatch.isPresent()) {
result = Either.left(matchingEdge);
}
@@ -770,7 +742,8 @@ public class JanusGraphDao {
result = Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
} catch (Exception e) {
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Exception occured during getting edge by criteria for component with id {}. {}", vertex.getUniqueId(), e);
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Exception occured during getting edge by criteria for component with id {}. {}",
+ vertex.getUniqueId(), e);
return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
return result;
@@ -778,26 +751,33 @@ public class JanusGraphDao {
/**
* Deletes Edge by received label and criteria
- *
+ *
* @param vertex
* @param label
* @param properties
* @return
*/
- public Either<Edge, JanusGraphOperationStatus> deleteBelongingEdgeByCriteria(GraphVertex vertex, EdgeLabelEnum label, Map<GraphPropertyEnum, Object> properties) {
+ public Either<Edge, JanusGraphOperationStatus> deleteBelongingEdgeByCriteria(GraphVertex vertex, EdgeLabelEnum label,
+ Map<GraphPropertyEnum, Object> properties) {
Either<Edge, JanusGraphOperationStatus> result = null;
try {
result = getBelongingEdgeByCriteria(vertex, label, properties);
if (result.isLeft()) {
Edge edge = result.left().value();
- CommonUtility.addRecordToLog(logger, LogLevelEnum.TRACE, "Going to delete an edge with the label {} belonging to the vertex {} ", label.name(), vertex.getUniqueId());
+ CommonUtility
+ .addRecordToLog(logger, LogLevelEnum.TRACE, "Going to delete an edge with the label {} belonging to the vertex {} ", label.name(),
+ vertex.getUniqueId());
edge.remove();
result = Either.left(edge);
} else {
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to find an edge with the label {} belonging to the vertex {} ", label.name(), vertex.getUniqueId());
+ CommonUtility
+ .addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to find an edge with the label {} belonging to the vertex {} ", label.name(),
+ vertex.getUniqueId());
}
} catch (Exception e) {
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Exception occured during deleting an edge by criteria for the component with id {}. {}", vertex == null ? "NULL" : vertex.getUniqueId(), e);
+ CommonUtility
+ .addRecordToLog(logger, LogLevelEnum.DEBUG, "Exception occured during deleting an edge by criteria for the component with id {}. {}",
+ vertex == null ? "NULL" : vertex.getUniqueId(), e);
return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
return result;
@@ -806,13 +786,12 @@ public class JanusGraphDao {
@SuppressWarnings("unchecked")
/**
* Deletes an edge between vertices fromVertex and toVertex according to received label
- *
+ *
* @param fromVertex
* @param toVertex
* @param label
* @return
*/
-
public Either<Edge, JanusGraphOperationStatus> deleteEdge(GraphVertex fromVertex, GraphVertex toVertex, EdgeLabelEnum label) {
return deleteEdge(fromVertex.getVertex(), toVertex.getVertex(), label, fromVertex.getUniqueId(), toVertex.getUniqueId(), false);
}
@@ -821,7 +800,8 @@ public class JanusGraphDao {
return deleteEdge(fromVertex.getVertex(), toVertex.getVertex(), label, fromVertex.getUniqueId(), toVertex.getUniqueId(), true);
}
- public Either<Edge, JanusGraphOperationStatus> deleteEdge(JanusGraphVertex fromVertex, JanusGraphVertex toVertex, EdgeLabelEnum label, String uniqueIdFrom, String uniqueIdTo, boolean deleteAll) {
+ public Either<Edge, JanusGraphOperationStatus> deleteEdge(JanusGraphVertex fromVertex, JanusGraphVertex toVertex, EdgeLabelEnum label,
+ String uniqueIdFrom, String uniqueIdTo, boolean deleteAll) {
Either<Edge, JanusGraphOperationStatus> result = null;
Vertex problemV = null;
try {
@@ -833,37 +813,38 @@ public class JanusGraphDao {
String currVertexUniqueId = null;
try {
currVertexUniqueId = edge.inVertex().value(GraphPropertyEnum.UNIQUE_ID.getProperty());
- }catch (Exception e){
+ } catch (Exception e) {
// AutoHealing procedure
- logger.info( "Corrupted vertex and edge were found and deleted {}",e);
- if ( problemV != null ) {
+ logger.info("Corrupted vertex and edge were found and deleted {}", e);
+ if (problemV != null) {
Map<GraphPropertyEnum, Object> props = getVertexProperties(problemV);
- logger.debug( "problematic Vertex properties:");
- logger.debug( "props size: {}", props.size());
+ logger.debug("problematic Vertex properties:");
+ logger.debug("props size: {}", props.size());
for (Map.Entry<GraphPropertyEnum, Object> entry : props.entrySet()) {
- logger.debug( "{}{}",entry.getKey() + ":" + entry.getValue());
+ logger.debug("{}{}", entry.getKey() + ":" + entry.getValue());
}
- Either<List<Vertex>, JanusGraphOperationStatus> childrenVertices = getChildrenVertices(problemV, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
- if(childrenVertices.isLeft()){
+ Either<List<Vertex>, JanusGraphOperationStatus> childrenVertices = getChildrenVertices(problemV, EdgeLabelEnum.VERSION,
+ JsonParseFlagEnum.NoParse);
+ if (childrenVertices.isLeft()) {
childrenVertices.left().value().size();
- logger.debug( "number of children that problematic Vertex has: {}", props.size());
+ logger.debug("number of children that problematic Vertex has: {}", props.size());
}
try {
edge.remove();
- }catch (Exception e1){
- logger.debug( "failed to remove problematic edge. {}", e1);
+ } catch (Exception e1) {
+ logger.debug("failed to remove problematic edge. {}", e1);
}
try {
problemV.remove();
- }catch (Exception e2){
- logger.debug( "failed to remove problematic vertex . {}", e2);
+ } catch (Exception e2) {
+ logger.debug("failed to remove problematic vertex . {}", e2);
}
}
continue;
}
-
if (currVertexUniqueId != null && currVertexUniqueId.equals(uniqueIdTo)) {
- CommonUtility.addRecordToLog(logger, LogLevelEnum.TRACE, "Going to delete an edge with the label {} between vertices {} and {}. ", label.name(), uniqueIdFrom, uniqueIdTo);
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.TRACE, "Going to delete an edge with the label {} between vertices {} and {}. ",
+ label.name(), uniqueIdFrom, uniqueIdTo);
edge.remove();
result = Either.left(edge);
if (!deleteAll) {
@@ -872,12 +853,14 @@ public class JanusGraphDao {
}
}
if (result == null) {
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to delete an edge with the label {} between vertices {} and {}. ", label.name(), uniqueIdFrom, uniqueIdTo);
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to delete an edge with the label {} between vertices {} and {}. ",
+ label.name(), uniqueIdFrom, uniqueIdTo);
result = Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
} catch (Exception e) {
-
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Exception occured during deleting an edge with the label {} between vertices {} and {}. {}", label.name(), uniqueIdFrom, uniqueIdTo, e);
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG,
+ "Exception occured during deleting an edge with the label {} between vertices {} and {}. {}", label.name(), uniqueIdFrom, uniqueIdTo,
+ e);
return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
return result;
@@ -886,7 +869,6 @@ public class JanusGraphDao {
public JanusGraphOperationStatus deleteEdgeByDirection(GraphVertex fromVertex, Direction direction, EdgeLabelEnum label) {
try {
Iterator<Edge> edges = fromVertex.getVertex().edges(direction, label.name());
-
while (edges.hasNext()) {
Edge edge = edges.next();
edge.remove();
@@ -900,7 +882,7 @@ public class JanusGraphDao {
/**
* Updates vertex properties. Note that graphVertex argument should contain updated data
- *
+ *
* @param graphVertex
* @return
*/
@@ -909,9 +891,9 @@ public class JanusGraphDao {
try {
graphVertex.updateMetadataJsonWithCurrentMetadataProperties();
setVertexProperties(graphVertex.getVertex(), graphVertex);
-
} catch (Exception e) {
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to update metadata of vertex with uniqueId {}. ", graphVertex.getUniqueId(), e);
+ CommonUtility
+ .addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to update metadata of vertex with uniqueId {}. ", graphVertex.getUniqueId(), e);
return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
return Either.left(graphVertex);
@@ -919,12 +901,12 @@ public class JanusGraphDao {
/**
* Fetches vertices by uniqueId according to received parse flag
- *
+ *
* @param verticesToGet
* @return
*/
- public Either<Map<String, GraphVertex>, JanusGraphOperationStatus> getVerticesByUniqueIdAndParseFlag(Map<String, ImmutablePair<GraphPropertyEnum, JsonParseFlagEnum>> verticesToGet) {
-
+ public Either<Map<String, GraphVertex>, JanusGraphOperationStatus> getVerticesByUniqueIdAndParseFlag(
+ Map<String, ImmutablePair<GraphPropertyEnum, JsonParseFlagEnum>> verticesToGet) {
Either<Map<String, GraphVertex>, JanusGraphOperationStatus> result = null;
Map<String, GraphVertex> vertices = new HashMap<>();
JanusGraphOperationStatus titatStatus;
@@ -933,16 +915,20 @@ public class JanusGraphDao {
if (entry.getValue().getKey() == GraphPropertyEnum.UNIQUE_ID) {
getVertexRes = getVertexById(entry.getKey(), entry.getValue().getValue());
} else if (entry.getValue().getKey() == GraphPropertyEnum.USERID) {
- getVertexRes = getVertexByPropertyAndLabel(entry.getValue().getKey(), entry.getKey(), VertexTypeEnum.USER, entry.getValue().getValue());
+ getVertexRes = getVertexByPropertyAndLabel(entry.getValue().getKey(), entry.getKey(), VertexTypeEnum.USER,
+ entry.getValue().getValue());
}
if (getVertexRes == null) {
titatStatus = JanusGraphOperationStatus.ILLEGAL_ARGUMENT;
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Invalid vertex type label {} has been received. ", entry.getValue().getKey(), titatStatus);
+ CommonUtility
+ .addRecordToLog(logger, LogLevelEnum.DEBUG, "Invalid vertex type label {} has been received. ", entry.getValue().getKey(),
+ titatStatus);
return Either.right(titatStatus);
}
if (getVertexRes.isRight()) {
titatStatus = getVertexRes.right().value();
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get vertex by id {} . Status is {}. ", entry.getKey(), titatStatus);
+ CommonUtility
+ .addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to get vertex by id {} . Status is {}. ", entry.getKey(), titatStatus);
result = Either.right(titatStatus);
break;
} else {
@@ -957,7 +943,7 @@ public class JanusGraphDao {
/**
* Creates edge between "from" and "to" vertices with specified label and properties extracted from received edge
- *
+ *
* @param from
* @param to
* @param label
@@ -968,10 +954,12 @@ public class JanusGraphDao {
return createEdge(from, to, label, getEdgeProperties(edgeToCopy));
}
- public JanusGraphOperationStatus replaceEdgeLabel(Vertex fromVertex, Vertex toVertex, Edge prevEdge, EdgeLabelEnum prevLabel, EdgeLabelEnum newLabel) {
- CommonUtility.addRecordToLog(logger, LogLevelEnum.TRACE, "Going to replace edge with label {} to {} between vertices {} and {}", prevLabel, newLabel, fromVertex!=null ? fromVertex.property(GraphPropertyEnum.UNIQUE_ID.getProperty()) : "NULL",
- toVertex!=null ? toVertex.property(GraphPropertyEnum.UNIQUE_ID.getProperty()) : "NULL");
-
+ public JanusGraphOperationStatus replaceEdgeLabel(Vertex fromVertex, Vertex toVertex, Edge prevEdge, EdgeLabelEnum prevLabel,
+ EdgeLabelEnum newLabel) {
+ CommonUtility
+ .addRecordToLog(logger, LogLevelEnum.TRACE, "Going to replace edge with label {} to {} between vertices {} and {}", prevLabel, newLabel,
+ fromVertex != null ? fromVertex.property(GraphPropertyEnum.UNIQUE_ID.getProperty()) : "NULL",
+ toVertex != null ? toVertex.property(GraphPropertyEnum.UNIQUE_ID.getProperty()) : "NULL");
JanusGraphOperationStatus result = createEdge(fromVertex, toVertex, newLabel, prevEdge);
if (result == JanusGraphOperationStatus.OK) {
prevEdge.remove();
@@ -981,22 +969,20 @@ public class JanusGraphDao {
/**
* Replaces previous label of edge with new label
- *
+ *
* @param fromVertex
* @param toVertex
* @param prevLabel
* @param newLabel
* @return
*/
- public JanusGraphOperationStatus replaceEdgeLabel(Vertex fromVertex, Vertex toVertex, EdgeLabelEnum prevLabel,
- EdgeLabelEnum newLabel) {
-
+ public JanusGraphOperationStatus replaceEdgeLabel(Vertex fromVertex, Vertex toVertex, EdgeLabelEnum prevLabel, EdgeLabelEnum newLabel) {
Iterator<Edge> prevEdgeIter = toVertex.edges(Direction.IN, prevLabel.name());
if (prevEdgeIter == null || !prevEdgeIter.hasNext()) {
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG,
- "Failed to replace edge with label {} to {} between vertices {} and {}", prevLabel, newLabel,
- fromVertex.property(GraphPropertyEnum.UNIQUE_ID.getProperty()),
- toVertex.property(GraphPropertyEnum.UNIQUE_ID.getProperty()));
+ CommonUtility
+ .addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to replace edge with label {} to {} between vertices {} and {}", prevLabel,
+ newLabel, fromVertex.property(GraphPropertyEnum.UNIQUE_ID.getProperty()),
+ toVertex.property(GraphPropertyEnum.UNIQUE_ID.getProperty()));
return JanusGraphOperationStatus.NOT_FOUND;
} else {
return replaceEdgeLabel(fromVertex, toVertex, prevEdgeIter.next(), prevLabel, newLabel);
@@ -1005,8 +991,7 @@ public class JanusGraphDao {
/**
* Updates metadata properties of vertex on graph. Json metadata property of the vertex will be updated with received properties too.
- *
- *
+ *
* @param vertex
* @param properties
* @return
@@ -1023,7 +1008,8 @@ public class JanusGraphDao {
vertex.property(GraphPropertyEnum.METADATA.getProperty(), JsonParserUtils.toJson(jsonMetadataMap));
}
} catch (Exception e) {
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Exception occurred during update vertex metadata properties with json{}. {}", vertex.property(GraphPropertyEnum.UNIQUE_ID.getProperty()), e.getMessage());
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Exception occurred during update vertex metadata properties with json{}. {}",
+ vertex.property(GraphPropertyEnum.UNIQUE_ID.getProperty()), e.getMessage());
return JanusGraphClient.handleJanusGraphException(e);
}
return JanusGraphOperationStatus.OK;
@@ -1032,7 +1018,6 @@ public class JanusGraphDao {
public JanusGraphOperationStatus disassociateAndDeleteLast(GraphVertex vertex, Direction direction, EdgeLabelEnum label) {
try {
Iterator<Edge> edges = vertex.getVertex().edges(direction, label.name());
-
while (edges.hasNext()) {
Edge edge = edges.next();
Vertex secondVertex;
@@ -1045,8 +1030,8 @@ public class JanusGraphDao {
reverseDirection = Direction.IN;
}
edge.remove();
- CommonUtility.addRecordToLog(logger, LogLevelEnum.TRACE, "Edge {} with direction {} was removed from {}", label.name(), direction, vertex.getVertex());
-
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.TRACE, "Edge {} with direction {} was removed from {}", label.name(), direction,
+ vertex.getVertex());
Iterator<Edge> restOfEdges = secondVertex.edges(reverseDirection, label.name());
if (!restOfEdges.hasNext()) {
secondVertex.remove();
@@ -1054,7 +1039,9 @@ public class JanusGraphDao {
}
}
} catch (Exception e) {
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Exception occured during deleting an edge with the label {} direction {} from vertex {}. {}", label.name(), direction, vertex.getUniqueId(), e);
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG,
+ "Exception occured during deleting an edge with the label {} direction {} from vertex {}. {}", label.name(), direction,
+ vertex.getUniqueId(), e);
return JanusGraphClient.handleJanusGraphException(e);
}
return JanusGraphOperationStatus.OK;
@@ -1077,13 +1064,11 @@ public class JanusGraphDao {
return value;
}
} catch (Exception e) {
-
}
return value;
}
/**
- *
* @param vertexA
* @param vertexB
* @param label
@@ -1108,7 +1093,8 @@ public class JanusGraphDao {
return JanusGraphOperationStatus.OK;
}
- public Either<Edge, JanusGraphOperationStatus> getBelongingEdgeByCriteria(String parentId, EdgeLabelEnum label, Map<GraphPropertyEnum, Object> properties) {
+ public Either<Edge, JanusGraphOperationStatus> getBelongingEdgeByCriteria(String parentId, EdgeLabelEnum label,
+ Map<GraphPropertyEnum, Object> properties) {
Either<GraphVertex, JanusGraphOperationStatus> getVertexRes = getVertexById(parentId, JsonParseFlagEnum.NoParse);
if (getVertexRes.isRight()) {
return Either.right(getVertexRes.right().value());