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

Commit 8e14db1

Browse files
author
Achim Brandt
committed
fixed some sonar issues
1 parent e1583dd commit 8e14db1

File tree

7 files changed

+154
-148
lines changed

7 files changed

+154
-148
lines changed

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

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.TreeMap;
1616

1717
import org.apache.commons.lang3.StringUtils;
18+
import org.apache.log4j.Logger;
1819

1920
import com.arangodb.ErrorNums;
2021
import com.google.gson.Gson;
@@ -28,7 +29,12 @@
2829
* @author Jan Steemann (http://www.triagens.de)
2930
*/
3031

31-
abstract public class ArangoDBBaseDocument {
32+
public abstract class ArangoDBBaseDocument {
33+
34+
/**
35+
* the logger
36+
*/
37+
private static final Logger logger = Logger.getLogger(ArangoDBBaseDocument.class);
3238

3339
/**
3440
* document id attribute
@@ -158,48 +164,54 @@ public Set<String> getPropertyKeys() {
158164
* If the type is not supported
159165
*/
160166
public static Object toDocumentValue(Object value) throws ArangoDBException {
167+
Object result;
168+
161169
if (value instanceof Boolean) {
162-
return value;
170+
result = value;
163171
} else if (value instanceof Integer) {
164-
return new Double(((Integer) value).doubleValue());
172+
result = new Double(((Integer) value).doubleValue());
165173
} else if (value instanceof Long) {
166-
return new Double(((Long) value).doubleValue());
174+
result = new Double(((Long) value).doubleValue());
167175
} else if (value instanceof Float) {
168-
return new Double(((Float) value).doubleValue());
176+
result = new Double(((Float) value).doubleValue());
169177
} else if (value instanceof String) {
170-
return value;
178+
result = value;
171179
} else if (value instanceof Double) {
172-
return value;
180+
result = value;
173181
} else if (value instanceof Map) {
174-
Map<String, Object> result = new TreeMap<String, Object>();
175-
Map<?, ?> m = (Map<?, ?>) value;
176-
177-
for (Map.Entry<?, ?> entry : m.entrySet()) {
178-
if (entry.getKey() instanceof String) {
179-
result.put((String) entry.getKey(), toDocumentValue(entry.getValue()));
180-
} else {
181-
throw new ArangoDBException("a key of a Map has to be a String",
182-
ErrorNums.ERROR_GRAPH_INVALID_PARAMETER);
183-
}
184-
}
185-
186-
return result;
187-
182+
result = mapToDocumentValue((Map<?, ?>) value);
188183
} else if (value instanceof List) {
189-
List<?> l = (List<?>) value;
190-
191-
for (final Object k : l) {
192-
toDocumentValue(k);
193-
}
194-
195-
return value;
184+
result = listToDocumentValue((List<?>) value);
196185
} else {
197186
// TODO add more types
198187

199188
throw new ArangoDBException("class of value not supported: " + value.getClass().toString(),
200189
ErrorNums.ERROR_GRAPH_INVALID_PARAMETER);
201190
}
191+
return result;
192+
}
193+
194+
private static Object listToDocumentValue(List<?> value) throws ArangoDBException {
195+
for (final Object k : value) {
196+
toDocumentValue(k);
197+
}
202198

199+
return value;
200+
}
201+
202+
private static Object mapToDocumentValue(Map<?, ?> value) throws ArangoDBException {
203+
Map<String, Object> map = new TreeMap<String, Object>();
204+
205+
for (Map.Entry<?, ?> entry : value.entrySet()) {
206+
if (entry.getKey() instanceof String) {
207+
map.put((String) entry.getKey(), toDocumentValue(entry.getValue()));
208+
} else {
209+
throw new ArangoDBException("a key of a Map has to be a String",
210+
ErrorNums.ERROR_GRAPH_INVALID_PARAMETER);
211+
}
212+
}
213+
214+
return map;
203215
}
204216

205217
/**
@@ -291,6 +303,7 @@ public String getDocumentKey() {
291303
return getStringProperty(_KEY);
292304
}
293305

306+
@Override
294307
public String toString() {
295308
if (properties == null) {
296309
return "null";
@@ -332,6 +345,7 @@ private String serializeProperties(Map<String, Object> map) {
332345
try {
333346
return gson.toJson(map);
334347
} catch (Exception e) {
348+
logger.debug("could not create json object by map", e);
335349
return "";
336350
}
337351
}

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,6 @@ public CursorResult<Map> getCursorResult() throws ArangoDBException {
127127
sb.append("for i in GRAPH_EDGES(@graphName , @vertexExample, @options)");
128128
break;
129129
case GRAPH_NEIGHBORS:
130-
// version 2.5
131-
// sb.append("for i in GRAPH_NEIGHBORS(@graphName , @vertexExample,
132-
// @options)");
133-
// prefix = "i.path.edges[0].";
134-
// returnExp = " return i.vertex";
135130
sb.append("for i in GRAPH_EDGES(@graphName , @vertexExample, @options)");
136131
returnExp = " return DOCUMENT(" + getDocumentByDirection() + ")";
137132
break;
@@ -148,10 +143,10 @@ public CursorResult<Map> getCursorResult() throws ArangoDBException {
148143

149144
if (CollectionUtils.isNotEmpty(labelsFilter)) {
150145
List<String> orFilter = new ArrayList<String>();
151-
int count = 0;
146+
int tmpCount = 0;
152147
for (String label : labelsFilter) {
153-
orFilter.add(prefix + "label == @label" + count);
154-
bindVars.put("label" + count++, label);
148+
orFilter.add(prefix + "label == @label" + tmpCount);
149+
bindVars.put("label" + tmpCount++, label);
155150
}
156151
if (CollectionUtils.isNotEmpty(orFilter)) {
157152
andFilter.add("(" + StringUtils.join(orFilter, " OR ") + ")");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class ArangoDBConfiguration extends ArangoConfigure {
2929
*/
3030

3131
public ArangoDBConfiguration() {
32+
// using defaults (localhost:8529)
3233
}
3334

3435
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class ArangoDBException extends Exception {
2323

2424
private static final long serialVersionUID = -163216237496410756L;
2525

26-
private Integer errorNum = 0;
26+
private final Integer errorNum;
2727

2828
/**
2929
* Creates an exception

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

Lines changed: 74 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.Map;
1515

1616
import org.apache.commons.lang.StringUtils;
17+
import org.apache.log4j.Logger;
1718
import org.codehaus.jettison.json.JSONArray;
1819
import org.codehaus.jettison.json.JSONException;
1920
import org.codehaus.jettison.json.JSONObject;
@@ -29,8 +30,26 @@
2930

3031
public class ArangoDBPropertyFilter {
3132

33+
private static final String PROPERTY = "property";
34+
private static final String COMPARE = "compare";
35+
private static final String KEY = "key";
36+
private static final String VALUE = "value";
37+
/**
38+
* the logger
39+
*/
40+
private static final Logger logger = Logger.getLogger(ArangoDBPropertyFilter.class);
41+
3242
public enum Compare {
33-
EQUAL, NOT_EQUAL, GREATER_THAN, GREATER_THAN_EQUAL, LESS_THAN, LESS_THAN_EQUAL, HAS, HAS_NOT, IN, NOT_IN
43+
EQUAL,
44+
NOT_EQUAL,
45+
GREATER_THAN,
46+
GREATER_THAN_EQUAL,
47+
LESS_THAN,
48+
LESS_THAN_EQUAL,
49+
HAS,
50+
HAS_NOT,
51+
IN,
52+
NOT_IN
3453
};
3554

3655
private List<PropertyContainer> propertyContainers = new ArrayList<PropertyContainer>();
@@ -58,82 +77,88 @@ public ArangoDBPropertyFilter has(final String key, final Object value, final Co
5877
*
5978
* @throws ArangoDBException
6079
* if an error occurs
80+
* @deprecated
6181
*/
6282
@Deprecated
6383
public JSONArray getAsJSON() throws ArangoDBException {
6484
JSONArray result = new JSONArray();
6585
try {
6686

6787
for (final PropertyContainer container : propertyContainers) {
68-
JSONObject o = new JSONObject();
69-
o.put("key", container.key);
70-
o.put("value", container.value); // TODO check different value
71-
// types
72-
switch (container.compare) {
73-
case EQUAL:
74-
o.put("compare", "==");
75-
break;
76-
case NOT_EQUAL:
77-
o.put("compare", "!=");
78-
break;
79-
case GREATER_THAN:
80-
o.put("compare", ">");
81-
break;
82-
case LESS_THAN:
83-
o.put("compare", "<");
84-
break;
85-
case GREATER_THAN_EQUAL:
86-
o.put("compare", ">=");
87-
break;
88-
case LESS_THAN_EQUAL:
89-
o.put("compare", "<=");
90-
break;
91-
case HAS:
92-
o.put("compare", "HAS");
93-
break;
94-
case HAS_NOT:
95-
o.put("compare", "HAS_NOT");
96-
break;
97-
}
98-
result.put(o);
88+
addContainer(result, container);
9989
}
10090

10191
return result;
10292
} catch (JSONException e) {
103-
// TODO Auto-generated catch block
104-
e.printStackTrace();
93+
logger.debug("error in get in getAsJSON", e);
94+
10595
throw new ArangoDBException("JSON error: " + e.getMessage());
10696
}
10797
}
10898

99+
private void addContainer(JSONArray result, final PropertyContainer container) throws JSONException {
100+
JSONObject o = new JSONObject();
101+
o.put(KEY, container.key);
102+
o.put(VALUE, container.value);
103+
switch (container.compare) {
104+
case EQUAL:
105+
o.put(COMPARE, "==");
106+
break;
107+
case NOT_EQUAL:
108+
o.put(COMPARE, "!=");
109+
break;
110+
case GREATER_THAN:
111+
o.put(COMPARE, ">");
112+
break;
113+
case LESS_THAN:
114+
o.put(COMPARE, "<");
115+
break;
116+
case GREATER_THAN_EQUAL:
117+
o.put(COMPARE, ">=");
118+
break;
119+
case LESS_THAN_EQUAL:
120+
o.put(COMPARE, "<=");
121+
break;
122+
case HAS:
123+
o.put(COMPARE, "HAS");
124+
break;
125+
case HAS_NOT:
126+
o.put(COMPARE, "HAS_NOT");
127+
break;
128+
default:
129+
// do nothing
130+
}
131+
result.put(o);
132+
}
133+
109134
public void addProperties(String prefix, List<String> filter, Map<String, Object> bindVars) {
110135
int count = 0;
111136
for (final PropertyContainer container : propertyContainers) {
112137
String key = escapeKey(container.key);
113138
switch (container.compare) {
114139
case EQUAL:
115140
filter.add(prefix + key + " == @property" + count);
116-
bindVars.put("property" + count, container.value);
141+
bindVars.put(PROPERTY + count, container.value);
117142
break;
118143
case NOT_EQUAL:
119144
filter.add(prefix + key + " != @property" + count);
120-
bindVars.put("property" + count, container.value);
145+
bindVars.put(PROPERTY + count, container.value);
121146
break;
122147
case GREATER_THAN:
123148
filter.add(prefix + key + " > @property" + count);
124-
bindVars.put("property" + count, container.value);
149+
bindVars.put(PROPERTY + count, container.value);
125150
break;
126151
case LESS_THAN:
127152
filter.add(prefix + key + " < @property" + count);
128-
bindVars.put("property" + count, container.value);
153+
bindVars.put(PROPERTY + count, container.value);
129154
break;
130155
case GREATER_THAN_EQUAL:
131156
filter.add(prefix + key + " >= @property" + count);
132-
bindVars.put("property" + count, container.value);
157+
bindVars.put(PROPERTY + count, container.value);
133158
break;
134159
case LESS_THAN_EQUAL:
135160
filter.add(prefix + key + " <= @property" + count);
136-
bindVars.put("property" + count, container.value);
161+
bindVars.put(PROPERTY + count, container.value);
137162
break;
138163
case HAS:
139164
filter.add(prefix + container.key + " != null");
@@ -142,13 +167,15 @@ public void addProperties(String prefix, List<String> filter, Map<String, Object
142167
filter.add(prefix + container.key + " == null");
143168
break;
144169
case IN:
145-
filter.add(prefix + container.key + " IN [" + addArray(bindVars, "property" + count, container.value)
146-
+ "]");
170+
filter.add(
171+
prefix + container.key + " IN [" + addArray(bindVars, PROPERTY + count, container.value) + "]");
147172
break;
148173
case NOT_IN:
149-
filter.add(prefix + container.key + " NOT IN ["
150-
+ addArray(bindVars, "property" + count, container.value) + "]");
174+
filter.add(
175+
prefix + container.key + " NOT IN [" + addArray(bindVars, PROPERTY + count, container.value) + "]");
151176
break;
177+
default:
178+
// do nothing
152179
}
153180
count++;
154181
}
@@ -178,9 +205,9 @@ private String escapeKey(String key) {
178205
}
179206

180207
private class PropertyContainer {
181-
public String key;
182-
public Object value;
183-
public Compare compare;
208+
public final String key;
209+
public final Object value;
210+
public final Compare compare;
184211

185212
public PropertyContainer(final String key, final Object value, final Compare compare) {
186213
this.key = key;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public GraphEntity getGraphEntity() {
7373
return graphEntity;
7474
}
7575

76+
@Override
7677
public String toString() {
7778
return "{\"name\":\"" + getName() + "\",\"vertices\":\"" + getVertexCollection() + "\",\"edges\":\""
7879
+ getEdgeCollection() + "\"}";

0 commit comments

Comments
 (0)