Skip to content

Commit a2a901c

Browse files
author
a-brandt
committed
fixed sonarlint issue
1 parent 0ea0afd commit a2a901c

File tree

5 files changed

+59
-52
lines changed

5 files changed

+59
-52
lines changed

src/main/java/com/arangodb/entity/marker/MissingInstanceCreater.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public class MissingInstanceCreater {
3232
mapping.put(VertexEntity.class, DocumentEntity.class);
3333
}
3434

35+
private MissingInstanceCreater() {
36+
// this is a helper class
37+
}
38+
3539
@SuppressWarnings("unchecked")
3640
public static <T extends BaseEntity> Class<?> getMissingClass(Class<T> clazz) {
3741
Class<T> c = (Class<T>) mapping.get(clazz);

src/main/java/com/arangodb/impl/AnnotationHandler.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static class DocumentAttributes {
3232
}
3333

3434
public AnnotationHandler() {
35-
// nothing todo here
35+
// do nothing here
3636
}
3737

3838
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -91,7 +91,7 @@ private void setAttribute(Field field, Object o, Object value) {
9191
try {
9292
field.setAccessible(true);
9393
field.set(o, value);
94-
} catch (Throwable e) {
94+
} catch (Exception e) {
9595
logger.error("could not update document attribute of class " + value.getClass().getCanonicalName(), e);
9696
}
9797
}
@@ -122,12 +122,8 @@ private Field getFieldByAnnotationValue(Class<?> clazz, String value) {
122122
Annotation[] annotations = field.getAnnotations();
123123
for (Annotation annotation : annotations) {
124124

125-
if (annotation instanceof SerializedName) {
126-
SerializedName sn = (SerializedName) annotation;
127-
128-
if (value.equals(sn.value())) {
129-
return field;
130-
}
125+
if (annotation instanceof SerializedName && value.equals(((SerializedName) annotation).value())) {
126+
return field;
131127
}
132128
}
133129
}

src/main/java/com/arangodb/impl/InternalCollectionDriverImpl.java

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,31 @@
3333
public class InternalCollectionDriverImpl extends BaseArangoDriverImpl
3434
implements com.arangodb.InternalCollectionDriver {
3535

36+
private static final String API_COLLECTION = "/_api/collection";
37+
3638
InternalCollectionDriverImpl(ArangoConfigure configure, HttpManager httpManager) {
3739
super(configure, httpManager);
3840
}
3941

4042
@Override
4143
public CollectionEntity createCollection(String database, String name, CollectionOptions collectionOptions)
4244
throws ArangoException {
43-
if (collectionOptions == null) {
44-
collectionOptions = new CollectionOptions();
45+
CollectionOptions tmpCollectionOptions = collectionOptions;
46+
if (tmpCollectionOptions == null) {
47+
tmpCollectionOptions = new CollectionOptions();
4548
}
46-
HttpResponseEntity res = httpManager
47-
.doPost(createEndpointUrl(database, "/_api/collection"), null, EntityFactory
48-
.toJsonString(
49-
new MapBuilder().put("name", name).put("waitForSync", collectionOptions.getWaitForSync())
50-
.put("doCompact", collectionOptions.getDoCompact())
51-
.put("journalSize", collectionOptions.getJournalSize())
52-
.put("isSystem", collectionOptions.getIsSystem())
53-
.put("isVolatile", collectionOptions.getIsVolatile())
54-
.put("keyOptions", collectionOptions.getKeyOptions())
55-
.put("numberOfShards", collectionOptions.getNumberOfShards()).put("shardKeys",
56-
collectionOptions.getShardKeys())
57-
.put("type", collectionOptions.getType() == null ? null : collectionOptions.getType().getType())
49+
HttpResponseEntity res = httpManager.doPost(createEndpointUrl(database, API_COLLECTION), null,
50+
EntityFactory.toJsonString(
51+
new MapBuilder().put("name", name).put("waitForSync", tmpCollectionOptions.getWaitForSync())
52+
.put("doCompact", tmpCollectionOptions.getDoCompact())
53+
.put("journalSize", tmpCollectionOptions.getJournalSize())
54+
.put("isSystem", tmpCollectionOptions.getIsSystem())
55+
.put("isVolatile", tmpCollectionOptions.getIsVolatile())
56+
.put("keyOptions", tmpCollectionOptions.getKeyOptions())
57+
.put("numberOfShards", tmpCollectionOptions.getNumberOfShards())
58+
.put("shardKeys", tmpCollectionOptions.getShardKeys())
59+
.put("type", tmpCollectionOptions.getType() == null ? null
60+
: tmpCollectionOptions.getType().getType())
5861
.get()));
5962

6063
return createEntity(res, CollectionEntity.class);
@@ -65,7 +68,7 @@ public CollectionEntity createCollection(String database, String name, Collectio
6568
public CollectionEntity getCollection(String database, String name) throws ArangoException {
6669
validateCollectionName(name);
6770

68-
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/collection", name), null);
71+
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, API_COLLECTION, name), null);
6972

7073
return createEntity(res, CollectionEntity.class);
7174
}
@@ -75,7 +78,7 @@ public CollectionEntity getCollectionRevision(String database, String name) thro
7578

7679
validateCollectionName(name);
7780

78-
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/collection", name, "/revision"),
81+
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, API_COLLECTION, name, "/revision"),
7982
null);
8083

8184
return createEntity(res, CollectionEntity.class);
@@ -86,7 +89,7 @@ public CollectionEntity getCollectionProperties(String database, String name) th
8689

8790
validateCollectionName(name);
8891

89-
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/collection", name, "/properties"),
92+
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, API_COLLECTION, name, "/properties"),
9093
null);
9194

9295
return createEntity(res, CollectionEntity.class);
@@ -97,8 +100,7 @@ public CollectionEntity getCollectionCount(String database, String name) throws
97100

98101
validateCollectionName(name);
99102

100-
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/collection", name, "/count"),
101-
null);
103+
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, API_COLLECTION, name, "/count"), null);
102104

103105
return createEntity(res, CollectionEntity.class);
104106
}
@@ -108,8 +110,7 @@ public CollectionEntity getCollectionFigures(String database, String name) throw
108110

109111
validateCollectionName(name);
110112

111-
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/collection", name, "/figures"),
112-
null);
113+
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, API_COLLECTION, name, "/figures"), null);
113114

114115
return createEntity(res, CollectionEntity.class);
115116
}
@@ -119,7 +120,7 @@ public CollectionEntity getCollectionChecksum(String database, String name, Bool
119120
throws ArangoException {
120121

121122
validateCollectionName(name);
122-
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/collection", name, "/checksum"),
123+
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, API_COLLECTION, name, "/checksum"),
123124
new MapBuilder().put("withRevisions", withRevisions).put("withData", withData).get());
124125

125126
return createEntity(res, CollectionEntity.class);
@@ -129,7 +130,7 @@ public CollectionEntity getCollectionChecksum(String database, String name, Bool
129130
@Override
130131
public CollectionsEntity getCollections(String database, Boolean excludeSystem) throws ArangoException {
131132

132-
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/collection"), null,
133+
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, API_COLLECTION), null,
133134
new MapBuilder().put("excludeSystem", excludeSystem).get());
134135

135136
return createEntity(res, CollectionsEntity.class);
@@ -140,7 +141,7 @@ public CollectionsEntity getCollections(String database, Boolean excludeSystem)
140141
public CollectionEntity loadCollection(String database, String name, Boolean count) throws ArangoException {
141142

142143
validateCollectionName(name);
143-
HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/collection", name, "/load"), null,
144+
HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, API_COLLECTION, name, "/load"), null,
144145
EntityFactory.toJsonString(new MapBuilder("count", count).get()));
145146

146147
return createEntity(res, CollectionEntity.class);
@@ -163,8 +164,8 @@ public CollectionEntity truncateCollection(String database, String name) throws
163164

164165
validateCollectionName(name);
165166

166-
HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/collection", name, "/truncate"),
167-
null, null);
167+
HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, API_COLLECTION, name, "/truncate"), null,
168+
null);
168169

169170
return createEntity(res, CollectionEntity.class);
170171
}
@@ -177,7 +178,7 @@ public CollectionEntity setCollectionProperties(
177178
Long journalSize) throws ArangoException {
178179

179180
validateCollectionName(name);
180-
HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/collection", name, "/properties"),
181+
HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, API_COLLECTION, name, "/properties"),
181182
null, EntityFactory.toJsonString(
182183
new MapBuilder().put("waitForSync", newWaitForSync).put("journalSize", journalSize).get()));
183184

@@ -189,8 +190,8 @@ public CollectionEntity renameCollection(String database, String name, String ne
189190

190191
validateCollectionName(newName);
191192

192-
HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/collection", name, "/rename"),
193-
null, EntityFactory.toJsonString(new MapBuilder("name", newName).get()));
193+
HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, API_COLLECTION, name, "/rename"), null,
194+
EntityFactory.toJsonString(new MapBuilder("name", newName).get()));
194195

195196
return createEntity(res, CollectionEntity.class);
196197
}
@@ -200,7 +201,7 @@ public CollectionEntity deleteCollection(String database, String name) throws Ar
200201

201202
validateCollectionName(name);
202203

203-
HttpResponseEntity res = httpManager.doDelete(createEndpointUrl(database, "/_api/collection", name), null);
204+
HttpResponseEntity res = httpManager.doDelete(createEndpointUrl(database, API_COLLECTION, name), null);
204205

205206
return createEntity(res, CollectionEntity.class);
206207
}

src/main/java/com/arangodb/impl/InternalDatabaseDriverImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
*/
3535
public class InternalDatabaseDriverImpl extends BaseArangoDriverImpl implements com.arangodb.InternalDatabaseDriver {
3636

37+
private static final String API_DATABASE = "/_api/database";
38+
3739
InternalDatabaseDriverImpl(ArangoConfigure configure, HttpManager httpManager) {
3840
super(configure, httpManager);
3941
}
@@ -50,7 +52,7 @@ public DatabaseEntity getCurrentDatabase() throws ArangoException {
5052
public StringsResultEntity getDatabases(boolean currentUserAccessableOnly, String username, String password)
5153
throws ArangoException {
5254
HttpResponseEntity res = httpManager.doGet(
53-
createEndpointUrl(null, "/_api/database", currentUserAccessableOnly ? "user" : null), null, null, username,
55+
createEndpointUrl(null, API_DATABASE, currentUserAccessableOnly ? "user" : null), null, null, username,
5456
password);
5557
return createEntity(res, StringsResultEntity.class);
5658

@@ -67,7 +69,7 @@ public BooleanResultEntity createDatabase(String database, UserEntity... users)
6769
body.put("users", users);
6870
}
6971

70-
HttpResponseEntity res = httpManager.doPost(createEndpointUrl(null, "/_api/database"), null,
72+
HttpResponseEntity res = httpManager.doPost(createEndpointUrl(null, API_DATABASE), null,
7173
EntityFactory.toJsonString(body));
7274

7375
return createEntity(res, BooleanResultEntity.class);
@@ -82,7 +84,7 @@ public BooleanResultEntity deleteDatabase(String database) throws ArangoExceptio
8284
TreeMap<String, Object> body = new TreeMap<String, Object>();
8385
body.put("name", database);
8486

85-
HttpResponseEntity res = httpManager.doDelete(createEndpointUrl(null, "/_api/database", database), null);
87+
HttpResponseEntity res = httpManager.doDelete(createEndpointUrl(null, API_DATABASE, database), null);
8688

8789
return createEntity(res, BooleanResultEntity.class);
8890

src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,20 +173,24 @@ public List<String> getDocuments(String database, String collectionName, boolean
173173
List<String> documents = CollectionUtils.safety(entity.getDocuments());
174174

175175
if (handleConvert && !documents.isEmpty()) {
176-
ListIterator<String> lit = documents.listIterator();
177-
while (lit.hasNext()) {
178-
String d = lit.next();
179-
if (d.startsWith(API_DOCUMENT_PREFIX)) {
180-
lit.set(d.substring(API_DOCUMENT_PREFIX.length()));
181-
} else {
182-
Matcher matcher = pattern.matcher(d);
183-
if (matcher.find()) {
184-
lit.set(matcher.group(1));
185-
}
176+
updateDocumentHandles(documents);
177+
}
178+
return documents;
179+
}
180+
181+
private void updateDocumentHandles(List<String> documents) {
182+
ListIterator<String> lit = documents.listIterator();
183+
while (lit.hasNext()) {
184+
String d = lit.next();
185+
if (d.startsWith(API_DOCUMENT_PREFIX)) {
186+
lit.set(d.substring(API_DOCUMENT_PREFIX.length()));
187+
} else {
188+
Matcher matcher = pattern.matcher(d);
189+
if (matcher.find()) {
190+
lit.set(matcher.group(1));
186191
}
187192
}
188193
}
189-
return documents;
190194
}
191195

192196
@Override

0 commit comments

Comments
 (0)