|
25 | 25 | import com.arangodb.entity.CursorEntity; |
26 | 26 | import com.arangodb.entity.DefaultEntity; |
27 | 27 | import com.arangodb.entity.DocumentEntity; |
| 28 | +import com.arangodb.entity.EdgeEntity; |
28 | 29 | import com.arangodb.entity.EntityFactory; |
29 | 30 | import com.arangodb.http.HttpManager; |
30 | 31 | import com.arangodb.http.HttpResponseEntity; |
| 32 | +import com.arangodb.util.EdgeUtils; |
31 | 33 | import com.arangodb.util.MapBuilder; |
32 | 34 | import com.google.gson.JsonElement; |
| 35 | +import com.google.gson.JsonObject; |
33 | 36 |
|
34 | 37 | /** |
35 | 38 | * @author tamtam180 - kirscheless at gmail.com |
@@ -67,7 +70,7 @@ private <T> DocumentEntity<T> internalCreateDocument( |
67 | 70 | } |
68 | 71 |
|
69 | 72 | final HttpResponseEntity res = httpManager.doPost(createDocumentEndpointUrl(database), |
70 | | - new MapBuilder().put("collection", collectionName).put(WAIT_FOR_SYNC, waitForSync).get(), body); |
| 73 | + new MapBuilder().put(COLLECTION, collectionName).put(WAIT_FOR_SYNC, waitForSync).get(), body); |
71 | 74 |
|
72 | 75 | @SuppressWarnings("unchecked") |
73 | 76 | final DocumentEntity<T> result = createEntity(res, DocumentEntity.class); |
@@ -183,7 +186,7 @@ public DocumentEntity<String> updateDocumentRaw( |
183 | 186 | @Override |
184 | 187 | public List<String> getDocuments(final String database, final String collectionName) throws ArangoException { |
185 | 188 | final HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/simple/all-keys"), null, |
186 | | - EntityFactory.toJsonString(new MapBuilder().put("collection", collectionName).put("type", "id").get())); |
| 189 | + EntityFactory.toJsonString(new MapBuilder().put(COLLECTION, collectionName).put("type", "id").get())); |
187 | 190 |
|
188 | 191 | @SuppressWarnings("unchecked") |
189 | 192 | final CursorEntity<String> tmp = createEntity(res, CursorEntity.class, String.class); |
@@ -264,4 +267,36 @@ private Map<String, Object> createRevisionCheckHeader(final Long rev) { |
264 | 267 | } |
265 | 268 | return header; |
266 | 269 | } |
| 270 | + |
| 271 | + @Override |
| 272 | + public <T> EdgeEntity<T> createEdge( |
| 273 | + String database, |
| 274 | + String collectionName, |
| 275 | + String documentKey, |
| 276 | + T value, |
| 277 | + String fromHandle, |
| 278 | + String toHandle, |
| 279 | + Boolean waitForSync) throws ArangoException { |
| 280 | + |
| 281 | + validateCollectionName(collectionName); |
| 282 | + |
| 283 | + JsonObject obj = EdgeUtils.valueToEdgeJsonObject(documentKey, fromHandle, toHandle, value); |
| 284 | + |
| 285 | + final HttpResponseEntity res = httpManager.doPost(createDocumentEndpointUrl(database), |
| 286 | + new MapBuilder().put(COLLECTION, collectionName).put(WAIT_FOR_SYNC, waitForSync).get(), |
| 287 | + EntityFactory.toJsonString(obj)); |
| 288 | + |
| 289 | + @SuppressWarnings("unchecked") |
| 290 | + final EdgeEntity<T> entity = createEntity(res, EdgeEntity.class); |
| 291 | + |
| 292 | + if (value != null) { |
| 293 | + entity.setEntity(value); |
| 294 | + annotationHandler.updateDocumentAttributes(value, entity.getDocumentRevision(), entity.getDocumentHandle(), |
| 295 | + entity.getDocumentKey()); |
| 296 | + } |
| 297 | + |
| 298 | + entity.setFromVertexHandle(fromHandle); |
| 299 | + entity.setToVertexHandle(toHandle); |
| 300 | + return entity; |
| 301 | + } |
267 | 302 | } |
0 commit comments