Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit ee206d1

Browse files
author
Achim Brandt
committed
fixed some sonar issues
1 parent 498756b commit ee206d1

File tree

5 files changed

+103
-77
lines changed

5 files changed

+103
-77
lines changed

src/main/java/com/arangodb/blueprints/ArangoDBGraph.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,7 @@ public ArangoDBGraph(String host, int port, String name, String verticesCollecti
146146
public ArangoDBGraph(ArangoDBConfiguration configuration, String name, String verticesCollectionName,
147147
String edgesCollectionName) throws ArangoDBGraphException {
148148

149-
if (StringUtils.isBlank(name)) {
150-
throw new ArangoDBGraphException("graph name must not be null.");
151-
}
152-
153-
if (StringUtils.isBlank(verticesCollectionName)) {
154-
throw new ArangoDBGraphException("vertex collection name must not be null.");
155-
}
156-
157-
if (StringUtils.isBlank(edgesCollectionName)) {
158-
throw new ArangoDBGraphException("edge collection name must not be null.");
159-
}
149+
checkNames(name, verticesCollectionName, edgesCollectionName);
160150

161151
client = new ArangoDBSimpleGraphClient(configuration);
162152
try {
@@ -180,6 +170,21 @@ public ArangoDBGraph(ArangoDBConfiguration configuration, String name, String ve
180170
}
181171
}
182172

173+
private void checkNames(String name, String verticesCollectionName, String edgesCollectionName)
174+
throws ArangoDBGraphException {
175+
if (StringUtils.isBlank(name)) {
176+
throw new ArangoDBGraphException("graph name must not be null.");
177+
}
178+
179+
if (StringUtils.isBlank(verticesCollectionName)) {
180+
throw new ArangoDBGraphException("vertex collection name must not be null.");
181+
}
182+
183+
if (StringUtils.isBlank(edgesCollectionName)) {
184+
throw new ArangoDBGraphException("edge collection name must not be null.");
185+
}
186+
}
187+
183188
private boolean graphHasError(String verticesCollectionName, String edgesCollectionName, GraphEntity graph) {
184189
boolean error = false;
185190

@@ -190,7 +195,7 @@ private boolean graphHasError(String verticesCollectionName, String edgesCollect
190195
} else {
191196
EdgeDefinitionEntity edgeDefinitionEntity = edgeDefinitions.get(0);
192197
if (!edgesCollectionName.equals(edgeDefinitionEntity.getCollection())
193-
|| edgeDefinitionEntity.getFrom().size() != 1 || edgeDefinitionEntity.getTo().size() != 1
198+
|| hasOneFromAndTo(edgeDefinitionEntity)
194199
|| !verticesCollectionName.equals(edgeDefinitionEntity.getFrom().get(0))
195200
|| !verticesCollectionName.equals(edgeDefinitionEntity.getTo().get(0))) {
196201
error = true;
@@ -199,6 +204,10 @@ private boolean graphHasError(String verticesCollectionName, String edgesCollect
199204
return error;
200205
}
201206

207+
private boolean hasOneFromAndTo(EdgeDefinitionEntity edgeDefinitionEntity) {
208+
return edgeDefinitionEntity.getFrom().size() != 1 || edgeDefinitionEntity.getTo().size() != 1;
209+
}
210+
202211
@Override
203212
public Features getFeatures() {
204213
return FEATURES;

src/main/java/com/arangodb/blueprints/ArangoDBQuery.java

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -72,41 +72,47 @@ public ArangoDBQuery hasNot(String key, Object value) {
7272
public ArangoDBQuery has(String key, Predicate prdct, Object value) {
7373
if (prdct instanceof com.tinkerpop.blueprints.Compare) {
7474
com.tinkerpop.blueprints.Compare compare = (com.tinkerpop.blueprints.Compare) prdct;
75-
76-
switch (compare) {
77-
case EQUAL:
78-
propertyFilter.has(key, value, ArangoDBPropertyFilter.Compare.EQUAL);
79-
break;
80-
case NOT_EQUAL:
81-
propertyFilter.has(key, value, ArangoDBPropertyFilter.Compare.NOT_EQUAL);
82-
break;
83-
case GREATER_THAN:
84-
propertyFilter.has(key, value, ArangoDBPropertyFilter.Compare.GREATER_THAN);
85-
break;
86-
case LESS_THAN:
87-
propertyFilter.has(key, value, ArangoDBPropertyFilter.Compare.LESS_THAN);
88-
break;
89-
case GREATER_THAN_EQUAL:
90-
propertyFilter.has(key, value, ArangoDBPropertyFilter.Compare.GREATER_THAN_EQUAL);
91-
break;
92-
case LESS_THAN_EQUAL:
93-
propertyFilter.has(key, value, ArangoDBPropertyFilter.Compare.LESS_THAN_EQUAL);
94-
break;
95-
default:
96-
// do nothing
97-
}
75+
hasCompare(key, value, compare);
9876
} else if (prdct instanceof com.tinkerpop.blueprints.Contains) {
9977
com.tinkerpop.blueprints.Contains contains = (com.tinkerpop.blueprints.Contains) prdct;
100-
101-
if (contains == Contains.IN) {
102-
propertyFilter.has(key, value, ArangoDBPropertyFilter.Compare.IN);
103-
} else if (contains == Contains.NOT_IN) {
104-
propertyFilter.has(key, value, ArangoDBPropertyFilter.Compare.NOT_IN);
105-
}
78+
hasContains(key, contains, value);
10679
}
10780
return this;
10881
}
10982

83+
private void hasContains(String key, com.tinkerpop.blueprints.Contains contains, Object value) {
84+
if (contains == Contains.IN) {
85+
propertyFilter.has(key, value, ArangoDBPropertyFilter.Compare.IN);
86+
} else if (contains == Contains.NOT_IN) {
87+
propertyFilter.has(key, value, ArangoDBPropertyFilter.Compare.NOT_IN);
88+
}
89+
}
90+
91+
private void hasCompare(String key, Object value, com.tinkerpop.blueprints.Compare compare) {
92+
switch (compare) {
93+
case EQUAL:
94+
propertyFilter.has(key, value, ArangoDBPropertyFilter.Compare.EQUAL);
95+
break;
96+
case NOT_EQUAL:
97+
propertyFilter.has(key, value, ArangoDBPropertyFilter.Compare.NOT_EQUAL);
98+
break;
99+
case GREATER_THAN:
100+
propertyFilter.has(key, value, ArangoDBPropertyFilter.Compare.GREATER_THAN);
101+
break;
102+
case LESS_THAN:
103+
propertyFilter.has(key, value, ArangoDBPropertyFilter.Compare.LESS_THAN);
104+
break;
105+
case GREATER_THAN_EQUAL:
106+
propertyFilter.has(key, value, ArangoDBPropertyFilter.Compare.GREATER_THAN_EQUAL);
107+
break;
108+
case LESS_THAN_EQUAL:
109+
propertyFilter.has(key, value, ArangoDBPropertyFilter.Compare.LESS_THAN_EQUAL);
110+
break;
111+
default:
112+
// do nothing
113+
}
114+
}
115+
110116
public <T extends Comparable<?>> ArangoDBQuery interval(String key, T startValue, T endValue) {
111117
propertyFilter.has(key, startValue, ArangoDBPropertyFilter.Compare.GREATER_THAN_EQUAL);
112118
propertyFilter.has(key, endValue, ArangoDBPropertyFilter.Compare.LESS_THAN);

src/main/java/com/arangodb/blueprints/batch/ArangoDBBatchEdge.java

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,15 @@ private ArangoDBBatchEdge(ArangoDBBatchGraph graph, ArangoDBSimpleEdge edge, Ver
5454
this.inVertex = inVertex;
5555
}
5656

57-
static ArangoDBBatchEdge create(
57+
public static ArangoDBBatchEdge create(
5858
ArangoDBBatchGraph graph,
5959
Object id,
6060
Vertex outVertex,
6161
Vertex inVertex,
6262
String label) {
63+
64+
checkVertexCLass(outVertex, inVertex);
65+
6366
String key = (id != null) ? id.toString() : null;
6467

6568
if (key == null) {
@@ -68,38 +71,40 @@ static ArangoDBBatchEdge create(
6871

6972
Map<String, Object> properties = new HashMap<String, Object>();
7073

71-
if (outVertex instanceof ArangoDBBatchVertex && inVertex instanceof ArangoDBBatchVertex) {
72-
ArangoDBBatchVertex from = (ArangoDBBatchVertex) outVertex;
73-
ArangoDBBatchVertex to = (ArangoDBBatchVertex) inVertex;
74+
ArangoDBBatchVertex from = (ArangoDBBatchVertex) outVertex;
75+
ArangoDBBatchVertex to = (ArangoDBBatchVertex) inVertex;
7476

75-
properties.put(ArangoDBBaseDocument._REV, "");
76-
properties.put(ArangoDBBaseDocument._ID, "");
77-
properties.put(ArangoDBBaseDocument._KEY, key);
78-
if (label != null) {
79-
properties.put(StringFactory.LABEL, label);
80-
}
77+
properties.put(ArangoDBBaseDocument._REV, "");
78+
properties.put(ArangoDBBaseDocument._ID, "");
79+
properties.put(ArangoDBBaseDocument._KEY, key);
80+
if (label != null) {
81+
properties.put(StringFactory.LABEL, label);
82+
}
83+
84+
properties.put(ArangoDBSimpleEdge._FROM,
85+
graph.getRawGraph().getVertexCollection() + "/" + from.getRawVertex().getDocumentKey());
86+
properties.put(ArangoDBSimpleEdge._TO,
87+
graph.getRawGraph().getVertexCollection() + "/" + to.getRawVertex().getDocumentKey());
8188

82-
properties.put(ArangoDBSimpleEdge._FROM,
83-
graph.getRawGraph().getVertexCollection() + "/" + from.getRawVertex().getDocumentKey());
84-
properties.put(ArangoDBSimpleEdge._TO,
85-
graph.getRawGraph().getVertexCollection() + "/" + to.getRawVertex().getDocumentKey());
86-
87-
try {
88-
ArangoDBSimpleEdge v = new ArangoDBSimpleEdge(properties);
89-
return build(graph, v, outVertex, inVertex);
90-
} catch (ArangoDBException e) {
91-
if (e.errorNumber() == 1210) {
92-
throw ExceptionFactory.vertexWithIdAlreadyExists(id);
93-
}
94-
logger.warn("could not create batch edge", e);
95-
throw new IllegalArgumentException(e.getMessage());
89+
try {
90+
ArangoDBSimpleEdge v = new ArangoDBSimpleEdge(properties);
91+
return build(graph, v, outVertex, inVertex);
92+
} catch (ArangoDBException e) {
93+
if (e.errorNumber() == 1210) {
94+
throw ExceptionFactory.vertexWithIdAlreadyExists(id);
9695
}
96+
logger.warn("could not create batch edge", e);
97+
throw new IllegalArgumentException(e.getMessage());
9798
}
98-
throw new IllegalArgumentException("Wrong vertex class.");
99+
}
99100

101+
private static void checkVertexCLass(Vertex outVertex, Vertex inVertex) {
102+
if (!(outVertex instanceof ArangoDBBatchVertex) || !(inVertex instanceof ArangoDBBatchVertex)) {
103+
throw new IllegalArgumentException("Wrong vertex class.");
104+
}
100105
}
101106

102-
static ArangoDBBatchEdge load(ArangoDBBatchGraph graph, Object id) {
107+
public static ArangoDBBatchEdge load(ArangoDBBatchGraph graph, Object id) {
103108
if (id == null) {
104109
throw ExceptionFactory.edgeIdCanNotBeNull();
105110
}
@@ -121,7 +126,7 @@ static ArangoDBBatchEdge load(ArangoDBBatchGraph graph, Object id) {
121126
}
122127
}
123128

124-
static ArangoDBBatchEdge build(
129+
public static ArangoDBBatchEdge build(
125130
ArangoDBBatchGraph graph,
126131
ArangoDBSimpleEdge simpleEdge,
127132
Vertex outVertex,

src/main/java/com/arangodb/blueprints/batch/ArangoDBBatchGraph.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private boolean graphHasError(String verticesCollectionName, String edgesCollect
227227
} else {
228228
EdgeDefinitionEntity edgeDefinitionEntity = edgeDefinitions.get(0);
229229
if (!edgesCollectionName.equals(edgeDefinitionEntity.getCollection())
230-
|| edgeDefinitionEntity.getFrom().size() != 1 || edgeDefinitionEntity.getTo().size() != 1
230+
|| hasOneFromAndTo(edgeDefinitionEntity)
231231
|| !verticesCollectionName.equals(edgeDefinitionEntity.getFrom().get(0))
232232
|| !verticesCollectionName.equals(edgeDefinitionEntity.getTo().get(0))) {
233233
error = true;
@@ -236,6 +236,10 @@ private boolean graphHasError(String verticesCollectionName, String edgesCollect
236236
return error;
237237
}
238238

239+
private boolean hasOneFromAndTo(EdgeDefinitionEntity edgeDefinitionEntity) {
240+
return edgeDefinitionEntity.getFrom().size() != 1 || edgeDefinitionEntity.getTo().size() != 1;
241+
}
242+
239243
@Override
240244
public Features getFeatures() {
241245
return FEATURES;

src/main/java/com/arangodb/blueprints/client/ArangoDBBaseQuery.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,7 @@ public CursorResult<Map> getCursorResult() throws ArangoDBException {
108108
Map<String, Object> bindVars = new HashMap<String, Object>();
109109
bindVars.put("graphName", graph.getName());
110110
bindVars.put("options", options);
111-
112-
if (startVertex != null) {
113-
bindVars.put("vertexExample", startVertex.getDocumentId());
114-
} else {
115-
bindVars.put("vertexExample", new HashMap<String, String>());
116-
}
111+
bindVars.put("vertexExample", getVertexExample());
117112

118113
StringBuilder sb = new StringBuilder();
119114
String prefix = "i.";
@@ -127,11 +122,10 @@ public CursorResult<Map> getCursorResult() throws ArangoDBException {
127122
sb.append("for i in GRAPH_EDGES(@graphName , @vertexExample, @options)");
128123
break;
129124
case GRAPH_NEIGHBORS:
125+
default:
130126
sb.append("for i in GRAPH_EDGES(@graphName , @vertexExample, @options)");
131127
returnExp = " return DOCUMENT(" + getDocumentByDirection() + ")";
132128
break;
133-
default:
134-
break;
135129
}
136130

137131
List<String> andFilter = new ArrayList<String>();
@@ -172,6 +166,14 @@ public CursorResult<Map> getCursorResult() throws ArangoDBException {
172166
return client.executeAqlQuery(query, bindVars, aqlQueryOptions);
173167
}
174168

169+
private Object getVertexExample() {
170+
if (startVertex != null) {
171+
return startVertex.getDocumentId();
172+
} else {
173+
return new HashMap<String, String>();
174+
}
175+
}
176+
175177
private String getDirectionString() {
176178
if (direction != null) {
177179
if (direction == Direction.IN) {

0 commit comments

Comments
 (0)