diff --git a/Documentation/Examples/api-blueprints-change-edge b/Documentation/Examples/api-blueprints-change-edge new file mode 100644 index 0000000000..4f13b762c1 --- /dev/null +++ b/Documentation/Examples/api-blueprints-change-edge @@ -0,0 +1,21 @@ +> curl --data @- -X PUT --dump - http://localhost:8529/_api/blueprints/edge/edge1?graph=graph1 +{"optional2" : "val2"} + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "edge": { + "_id": "82564582/85317094", + "_rev": 85906918, + "_key": "85317094", + "_bidirectional": false, + "_from": "81778150/84989414", + "_to": "81778150/84792806", + "$label": null, + "$id": "edge1", + "optional2": "val2" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-change-vertex b/Documentation/Examples/api-blueprints-change-vertex new file mode 100644 index 0000000000..e6a65f6e63 --- /dev/null +++ b/Documentation/Examples/api-blueprints-change-vertex @@ -0,0 +1,17 @@ +> curl --data @- -X PUT --dump - http://localhost:8529/_api/blueprints/vertex/v1?graph=graph1 +{"optional1" : "val2"} + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "vertex": { + "_id": "39572966/42653158", + "_rev": 42849766, + "_key": "42653158", + "$id": "v1", + "optional1": "val2" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-create-edge b/Documentation/Examples/api-blueprints-create-edge new file mode 100644 index 0000000000..3fa55f2b28 --- /dev/null +++ b/Documentation/Examples/api-blueprints-create-edge @@ -0,0 +1,21 @@ +> curl --data @- -X POST --dump - http://localhost:8529/_api/blueprints/edge?graph=graph1 +{"$id" : "edge1", "_from" : "vert2", "_to" : "vert1", "optional1" : "val1"} + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "edge": { + "_id": "54842854/57595366", + "_rev": 57595366, + "_key": "57595366", + "_bidirectional": false, + "_from": "54056422/57267686", + "_to": "54056422/57071078", + "$label": null, + "$id": "edge1", + "optional1": "val1" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-create-graph b/Documentation/Examples/api-blueprints-create-graph new file mode 100644 index 0000000000..d6d9736d45 --- /dev/null +++ b/Documentation/Examples/api-blueprints-create-graph @@ -0,0 +1,20 @@ +> curl --data @- -X POST --dump - http://localhost:8529/_api/blueprints/graph +{"name" : "graph1", "verticesName" : "v", "edgesName" : "e"} + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "graph": { + "_id": "1849955/7686033", + "_rev": 7686033, + "_key": "7686033", + "vertices": 5523345, + "edges": 6309777, + "name": "graph1", + "verticesName": "v", + "edgesName": "e" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-create-vertex b/Documentation/Examples/api-blueprints-create-vertex new file mode 100644 index 0000000000..9cd8e82d8e --- /dev/null +++ b/Documentation/Examples/api-blueprints-create-vertex @@ -0,0 +1,18 @@ +> curl --data @- -X POST --dump - http://localhost:8529/_api/blueprints/vertex?graph=graph1 +{"$id" : "v1", "optional1" : "val1", "optional2" : "val2"} + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "vertex": { + "_id": "21186449/24332177", + "_rev": 24332177, + "_key": "24332177", + "$id": "v1", + "optional1": "val1", + "optional2": "val2" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-delete-edge b/Documentation/Examples/api-blueprints-delete-edge new file mode 100644 index 0000000000..5b85984b7e --- /dev/null +++ b/Documentation/Examples/api-blueprints-delete-edge @@ -0,0 +1,10 @@ +> curl -X DELETE --dump - http://localhost:8529/_api/blueprints/edge/edge1?graph=graph1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "deleted": true, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-delete-graph b/Documentation/Examples/api-blueprints-delete-graph new file mode 100644 index 0000000000..66de0e9652 --- /dev/null +++ b/Documentation/Examples/api-blueprints-delete-graph @@ -0,0 +1,10 @@ +> curl -X DELETE --dump - http://localhost:8529/_api/blueprints/graph/graph1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "deleted": true, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-delete-vertex b/Documentation/Examples/api-blueprints-delete-vertex new file mode 100644 index 0000000000..e8051499b9 --- /dev/null +++ b/Documentation/Examples/api-blueprints-delete-vertex @@ -0,0 +1,10 @@ +> curl -X DELETE --dump - http://localhost:8529/_api/blueprints/vertex/46519782/49599974?graph=graph1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "deleted": true, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-edge b/Documentation/Examples/api-blueprints-get-edge new file mode 100644 index 0000000000..8708affd06 --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-edge @@ -0,0 +1,20 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/edge/edge1?graph=graph1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "edge": { + "_id": "74569190/77321702", + "_rev": 77321702, + "_key": "77321702", + "_bidirectional": false, + "_from": "73782758/76994022", + "_to": "73782758/76797414", + "$label": null, + "$id": "edge1", + "optional1": "val1" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-edges b/Documentation/Examples/api-blueprints-get-edges new file mode 100644 index 0000000000..6eea62e8b1 --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-edges @@ -0,0 +1,33 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/edges?graph=graph1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "edges": [ + { + "_id": "94950886/97834470", + "_rev": 97834470, + "_key": "97834470", + "_bidirectional": false, + "_from": "94164454/97310182", + "_to": "94164454/97506790", + "$label": null, + "$id": "edge1", + "optional1": "val1a" + }, + { + "_id": "94950886/98227686", + "_rev": 98227686, + "_key": "98227686", + "_bidirectional": false, + "_from": "94164454/97506790", + "_to": "94164454/97572326", + "$label": null, + "$id": "edge2", + "optional1": "val1b" + } + ], + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-edges-by-vertex b/Documentation/Examples/api-blueprints-get-edges-by-vertex new file mode 100644 index 0000000000..54fc5fd9fe --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-edges-by-vertex @@ -0,0 +1,22 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/edges?graph=graph1&vertex=id1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "edges": [ + { + "_id": "99145190/102028774", + "_rev": 102028774, + "_key": "102028774", + "_bidirectional": false, + "_from": "98358758/101504486", + "_to": "98358758/101701094", + "$label": null, + "$id": "edge1", + "optional1": "val1a" + } + ], + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-graph b/Documentation/Examples/api-blueprints-get-graph new file mode 100644 index 0000000000..536bea3d49 --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-graph @@ -0,0 +1,19 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/graph/graph1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "graph": { + "_id": "1849955/16992145", + "_rev": 16992145, + "_key": "16992145", + "vertices": 15157137, + "edges": 15943569, + "name": "graph1", + "verticesName": "v", + "edgesName": "e" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-graph-by-id b/Documentation/Examples/api-blueprints-get-graph-by-id new file mode 100644 index 0000000000..6aad3db9e8 --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-graph-by-id @@ -0,0 +1,19 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/graph/1849955/16992145 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "graph": { + "_id": "1849955/16992145", + "_rev": 16992145, + "_key": "16992145", + "vertices": 15157137, + "edges": 15943569, + "name": "graph1", + "verticesName": "v", + "edgesName": "e" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-in-edges-by-vertex b/Documentation/Examples/api-blueprints-get-in-edges-by-vertex new file mode 100644 index 0000000000..66e5d36b46 --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-in-edges-by-vertex @@ -0,0 +1,22 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/edges?graph=graph1&vertex=id2&type=in + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "edges": [ + { + "_id": "103339494/106223078", + "_rev": 106223078, + "_key": "106223078", + "_bidirectional": false, + "_from": "102553062/105698790", + "_to": "102553062/105895398", + "$label": null, + "$id": "edge1", + "optional1": "val1a" + } + ], + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-out-edges-by-vertex b/Documentation/Examples/api-blueprints-get-out-edges-by-vertex new file mode 100644 index 0000000000..002531623d --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-out-edges-by-vertex @@ -0,0 +1,22 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/edges?graph=graph1&vertex=id2&type=out + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "edges": [ + { + "_id": "107533798/110810598", + "_rev": 110810598, + "_key": "110810598", + "_bidirectional": false, + "_from": "106747366/110089702", + "_to": "106747366/110155238", + "$label": null, + "$id": "edge2", + "optional1": "val1b" + } + ], + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-vertex b/Documentation/Examples/api-blueprints-get-vertex new file mode 100644 index 0000000000..eb98ca89af --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-vertex @@ -0,0 +1,17 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/vertex/v1?graph=graph1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "vertex": { + "_id": "28133265/31278993", + "_rev": 31278993, + "_key": "31278993", + "$id": "v1", + "optional1": "val1", + "optional2": "val2" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-vertex-by-id b/Documentation/Examples/api-blueprints-get-vertex-by-id new file mode 100644 index 0000000000..d8c9a4a4cf --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-vertex-by-id @@ -0,0 +1,17 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/vertex/28133265/31278993?graph=graph1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "vertex": { + "_id": "28133265/31278993", + "_rev": 31278993, + "_key": "31278993", + "$id": "v1", + "optional1": "val1", + "optional2": "val2" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-vertices b/Documentation/Examples/api-blueprints-get-vertices new file mode 100644 index 0000000000..cb4267400c --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-vertices @@ -0,0 +1,50 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/vertices?graph=graph1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "vertices": [ + { + "_id": "49927654/53401062", + "_rev": 53401062, + "_key": "53401062", + "$id": null, + "optional1": "val1", + "optional2": "val2" + }, + { + "_id": "49927654/53073382", + "_rev": 53073382, + "_key": "53073382", + "$id": null, + "optional1": "val1", + "optional2": "val2" + }, + { + "_id": "49927654/53335526", + "_rev": 53335526, + "_key": "53335526", + "$id": null, + "optional1": "val1", + "optional2": "val2" + }, + { + "_id": "49927654/53269990", + "_rev": 53269990, + "_key": "53269990", + "$id": null, + "optional1": "val1", + "optional2": "val2" + }, + { + "_id": "49927654/53532134", + "_rev": 53532134, + "_key": "53532134", + "$id": "id1", + "optional2": "val2" + } + ], + "error": false, + "code": 200 +} diff --git a/Documentation/Makefile.files b/Documentation/Makefile.files index 90f70da2ab..2b54393064 100644 --- a/Documentation/Makefile.files +++ b/Documentation/Makefile.files @@ -10,6 +10,7 @@ DOXYGEN = \ Doxygen/js/actions/system/api-collection.c \ + Doxygen/js/actions/system/api-blueprints.c \ Doxygen/js/actions/system/api-cursor.c \ Doxygen/js/actions/system/api-edges.c \ Doxygen/js/actions/system/api-explain.c \ @@ -46,6 +47,7 @@ WIKI = \ Graphs \ Home \ HttpBatch \ + HttpBlueprints \ HttpCollection \ HttpCursor \ HttpImport \ diff --git a/UnitTests/HttpInterface/api-blueprints-spec.rb b/UnitTests/HttpInterface/api-blueprints-spec.rb new file mode 100644 index 0000000000..641760a069 --- /dev/null +++ b/UnitTests/HttpInterface/api-blueprints-spec.rb @@ -0,0 +1,646 @@ +# coding: utf-8 + +require 'rspec' +require './arangodb.rb' + + +describe ArangoDB do + prefix = "api-blueprints" + + vertex_collection = "v" + edge_collection = "e" + graph_name = "graph1" + + context "testing blueprints methods:" do + + def truncate_collection (prefix, name) + cmd = "/_api/collection/#{name}/truncate" + ArangoDB.log_put("#{prefix}", cmd) + end + +################################################################################ +## checking graph responses +################################################################################ + + context "checks blueprints graph requests" do + before do + #ArangoDB.create_collection( edge_collection , 0, 3) + #ArangoDB.create_collection( vertex_collection , 0, 2) + truncate_collection(prefix, "_graphs") + end + + after do + truncate_collection(prefix, "_graphs") + ArangoDB.drop_collection( vertex_collection ) + ArangoDB.drop_collection( edge_collection ) + end + + it "checks create graph" do + cmd = "/_api/blueprints/graph" + body = "{\"name\" : \"#{graph_name}\", \"verticesName\" : \"#{vertex_collection}\", \"edgesName\" : \"#{edge_collection}\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['graph']['name'].should eq("#{graph_name}") + end + + it "checks create graph with wrong edges collection" do + ArangoDB.create_collection( edge_collection , 0, 2) + + cmd = "/_api/blueprints/graph" + body = "{\"name\" : \"#{graph_name}\", \"verticesName\" : \"#{vertex_collection}\", \"edgesName\" : \"#{edge_collection}\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(400) + doc.parsed_response['error'].should eq(true) + doc.parsed_response['code'].should eq(400) + doc.parsed_response['errorNum'].should eq(1902) + end + + it "checks (re)create graph" do + cmd = "/_api/blueprints/graph" + body = "{\"name\" : \"#{graph_name}\", \"verticesName\" : \"#{vertex_collection}\", \"edgesName\" : \"#{edge_collection}\"}" + doc1 = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc1.code.should eq(200) + + doc2 = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc2.code.should eq(200) + + doc1.parsed_response['graph']['_id'].should eq(doc2.parsed_response['graph']['_id']) + end + + it "checks create and get graph" do + cmd = "/_api/blueprints/graph" + body = "{\"name\" : \"#{graph_name}\", \"verticesName\" : \"#{vertex_collection}\", \"edgesName\" : \"#{edge_collection}\"}" + doc1 = ArangoDB.log_post("#{prefix}", cmd, :body => body) + g_id = doc1.parsed_response['graph']['_id'] + + doc1.code.should eq(200) + + cmd = "/_api/blueprints/graph/#{graph_name}" + doc2 = ArangoDB.log_get("#{prefix}", cmd) + + doc2.code.should eq(200) + doc2.parsed_response['graph']['_id'].should eq(g_id) + + cmd = "/_api/blueprints/graph/#{g_id}" + doc3 = ArangoDB.log_get("#{prefix}", cmd) + + doc3.code.should eq(200) + doc3.parsed_response['graph']['_id'].should eq(g_id) + end + + it "checks create and delete graph" do + # create + cmd = "/_api/blueprints/graph" + body = "{\"name\" : \"#{graph_name}\", \"verticesName\" : \"#{vertex_collection}\", \"edgesName\" : \"#{edge_collection}\"}" + doc1 = ArangoDB.log_post("#{prefix}", cmd, :body => body) + doc1.code.should eq(200) + + # delete + cmd = "/_api/blueprints/graph/#{graph_name}" + doc2 = ArangoDB.log_delete("#{prefix}", cmd) + doc2.code.should eq(200) + doc2.parsed_response['deleted'].should eq(true) + + # check + doc3 = ArangoDB.log_get("#{prefix}", cmd) + doc3.code.should eq(400) + end + + end + +################################################################################ +## checking vertex responses +################################################################################ + + context "checks blueprints vertex requests" do + before do + truncate_collection(prefix, "_graphs") + cmd = "/_api/blueprints/graph" + body = "{\"name\" : \"#{graph_name}\", \"verticesName\" : \"#{vertex_collection}\", \"edgesName\" : \"#{edge_collection}\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + end + + after do + truncate_collection(prefix, "_graphs") + ArangoDB.drop_collection( vertex_collection ) + ArangoDB.drop_collection( edge_collection ) + end + + it "checks create vertex with \$id" do + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{\"\$id\" : \"v1\", \"optional1\" : \"val1\", \"optional2\" : \"val2\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['vertex']['$id'].should eq("v1") + doc.parsed_response['vertex']['optional1'].should eq("val1") + end + + it "checks create second vertex with \$id" do + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{\"\$id\" : \"double_id\", \"optional1\" : \"val1\", \"optional2\" : \"val2\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + + doc2 = ArangoDB.log_post("#{prefix}", cmd, :body => body) + doc2.code.should eq(400) + doc2.parsed_response['error'].should eq(true) + doc2.parsed_response['code'].should eq(400) + end + + it "checks get vertex by \$id" do + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{\"\$id\" : \"v1\", \"optional1\" : \"val1\", \"optional2\" : \"val2\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['vertex']['$id'].should eq("v1") + doc.parsed_response['vertex']['optional1'].should eq("val1") + + cmd = "/_api/blueprints/vertex/v1?graph=#{graph_name}" + doc2 = ArangoDB.log_get("#{prefix}", cmd) + doc2.code.should eq(200) + doc2.parsed_response['error'].should eq(false) + doc2.parsed_response['code'].should eq(200) + doc2.parsed_response['vertex']['optional1'].should eq(doc.parsed_response['vertex']['optional1']) + + _id = doc2.parsed_response['vertex']['_id']; + cmd = "/_api/blueprints/vertex/#{_id}?graph=#{graph_name}" + doc3 = ArangoDB.log_get("#{prefix}", cmd) + doc3.code.should eq(200) + doc3.parsed_response['error'].should eq(false) + doc3.parsed_response['code'].should eq(200) + doc3.parsed_response['vertex']['optional1'].should eq(doc.parsed_response['vertex']['optional1']) + end + + it "checks get vertex by wrong \$id" do + cmd = "/_api/blueprints/vertex/vv11?graph=#{graph_name}" + doc = ArangoDB.log_get("#{prefix}", cmd) + doc.code.should eq(400) + doc.parsed_response['error'].should eq(true) + doc.parsed_response['code'].should eq(400) + end + + it "checks update vertex by \$id" do + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{\"\$id\" : \"v1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['vertex']['$id'].should eq("v1") + doc.parsed_response['vertex']['optional1'].should eq("val1") + + cmd = "/_api/blueprints/vertex/v1?graph=#{graph_name}" + doc2 = ArangoDB.log_get("#{prefix}", cmd) + doc2.code.should eq(200) + doc2.parsed_response['error'].should eq(false) + doc2.parsed_response['code'].should eq(200) + doc2.parsed_response['vertex']['optional1'].should eq(doc.parsed_response['vertex']['optional1']) + + _id = doc2.parsed_response['vertex']['_id']; + cmd = "/_api/blueprints/vertex/#{_id}?graph=#{graph_name}" + body = "{\"\$id\" : \"v1\", \"optional1\" : \"val2\"}" + doc3 = ArangoDB.log_put("#{prefix}", cmd, :body => body) + doc3.code.should eq(200) + doc3.parsed_response['error'].should eq(false) + doc3.parsed_response['code'].should eq(200) + doc3.parsed_response['vertex']['optional1'].should eq("val2") + + cmd = "/_api/blueprints/vertex/v1?graph=#{graph_name}" + doc2 = ArangoDB.log_get("#{prefix}", cmd) + doc2.code.should eq(200) + doc2.parsed_response['error'].should eq(false) + doc2.parsed_response['code'].should eq(200) + doc2.parsed_response['vertex']['optional1'].should eq("val2") + end + + it "checks update vertex" do + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{\"optional1\" : \"val1\", \"optional2\" : \"val2\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['vertex']['$id'].should eq(nil) + doc.parsed_response['vertex']['optional1'].should eq("val1") + doc.parsed_response['vertex']['optional2'].should eq("val2") + _id = doc.parsed_response['vertex']['_id']; + + cmd = "/_api/blueprints/vertex/#{_id}?graph=#{graph_name}" + doc2 = ArangoDB.log_get("#{prefix}", cmd) + doc2.code.should eq(200) + doc2.parsed_response['error'].should eq(false) + doc2.parsed_response['code'].should eq(200) + doc2.parsed_response['vertex']['optional1'].should eq(doc.parsed_response['vertex']['optional1']) + + cmd = "/_api/blueprints/vertex/#{_id}?graph=#{graph_name}" + body = "{\"optional1\" : \"val2\"}" + doc3 = ArangoDB.log_put("#{prefix}", cmd, :body => body) + doc3.code.should eq(200) + doc3.parsed_response['error'].should eq(false) + doc3.parsed_response['code'].should eq(200) + doc3.parsed_response['vertex']['optional1'].should eq("val2") + doc3.parsed_response['vertex']['optional2'].should eq(nil) + + cmd = "/_api/blueprints/vertex/#{_id}?graph=#{graph_name}" + doc4 = ArangoDB.log_get("#{prefix}", cmd) + doc4.code.should eq(200) + doc4.parsed_response['error'].should eq(false) + doc4.parsed_response['code'].should eq(200) + doc4.parsed_response['vertex']['optional1'].should eq("val2") + doc4.parsed_response['vertex']['optional2'].should eq(nil) + end + + it "checks delete vertex" do + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{\"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['vertex']['$id'].should eq(nil) + doc.parsed_response['vertex']['optional1'].should eq("val1") + _id = doc.parsed_response['vertex']['_id']; + + cmd = "/_api/blueprints/vertex/#{_id}?graph=#{graph_name}" + doc2 = ArangoDB.log_delete("#{prefix}", cmd) + doc2.code.should eq(200) + doc2.parsed_response['error'].should eq(false) + doc2.parsed_response['code'].should eq(200) + doc2.parsed_response['deleted'].should eq(true) + + cmd = "/_api/blueprints/vertex/#{_id}?graph=#{graph_name}" + doc3 = ArangoDB.log_get("#{prefix}", cmd) + doc3.code.should eq(400) + doc3.parsed_response['error'].should eq(true) + doc3.parsed_response['code'].should eq(400) + end + + end + +################################################################################ +## checking vertices responses +################################################################################ + + context "checks blueprints vertices requests" do + before do + truncate_collection(prefix, "_graphs") + cmd = "/_api/blueprints/graph" + body = "{\"name\" : \"#{graph_name}\", \"verticesName\" : \"#{vertex_collection}\", \"edgesName\" : \"#{edge_collection}\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + end + + after do + truncate_collection(prefix, "_graphs") + ArangoDB.drop_collection( vertex_collection ) + ArangoDB.drop_collection( edge_collection ) + end + + it "checks list of vertices" do + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{\"optional1\" : \"val1\", \"optional2\" : \"val2\"}" + ArangoDB.log_post("#{prefix}", cmd, :body => body) + ArangoDB.log_post("#{prefix}", cmd, :body => body) + ArangoDB.log_post("#{prefix}", cmd, :body => body) + ArangoDB.log_post("#{prefix}", cmd, :body => body) + + body = "{\"$id\" : \"id1\", \"optional2\" : \"val2\"}" + ArangoDB.log_post("#{prefix}", cmd, :body => body) + ArangoDB.log_post("#{prefix}", cmd, :body => body) + ArangoDB.log_post("#{prefix}", cmd, :body => body) + ArangoDB.log_post("#{prefix}", cmd, :body => body) + + cmd = "/_api/blueprints/vertices?graph=#{graph_name}" + doc = ArangoDB.log_get("#{prefix}", cmd) + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['vertices'].count.should eq(5) + end + + end + +################################################################################ +## checking edge responses +################################################################################ + + context "checks blueprints edge requests" do + before do + truncate_collection(prefix, "_graphs") + cmd = "/_api/blueprints/graph" + body = "{\"name\" : \"#{graph_name}\", \"verticesName\" : \"#{vertex_collection}\", \"edgesName\" : \"#{edge_collection}\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{\"$id\" : \"vert1\"}" + ArangoDB.log_post("#{prefix}", cmd, :body => body) + body = "{\"$id\" : \"vert2\"}" + ArangoDB.log_post("#{prefix}", cmd, :body => body) + body = "{\"$id\" : \"vert3\"}" + ArangoDB.log_post("#{prefix}", cmd, :body => body) + + end + + after do + truncate_collection(prefix, "_graphs") + ArangoDB.drop_collection( vertex_collection ) + ArangoDB.drop_collection( edge_collection ) + end + + it "checks create edge" do + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['edge']['$id'].should eq("edge1") + doc.parsed_response['edge']['optional1'].should eq("val1") + doc.parsed_response['edge']['$label'].should eq(nil) + end + + it "checks create second edge with same \$id" do + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['edge']['$id'].should eq("edge1") + doc.parsed_response['edge']['optional1'].should eq("val1") + doc.parsed_response['edge']['$label'].should eq(nil) + + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"optional1\" : \"val1\"}" + doc1 = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc1.code.should eq(400) + doc1.parsed_response['error'].should eq(true) + doc1.parsed_response['code'].should eq(400) + end + + it "checks create edge with unknown vertex" do + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"unknown\", \"_to\" : \"vert1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(400) + doc.parsed_response['error'].should eq(true) + doc.parsed_response['code'].should eq(400) + end + + it "checks create edge with \$label" do + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"$label\" : \"label1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['edge']['$id'].should eq("edge1") + doc.parsed_response['edge']['optional1'].should eq("val1") + doc.parsed_response['edge']['$label'].should eq("label1") + end + + it "checks create edge with _id of vertex" do + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + v_id1 = doc.parsed_response['vertex']['_id'] + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + v_id2 = doc.parsed_response['vertex']['_id'] + + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"#{v_id1}\", \"_to\" : \"#{v_id2}\", \"$label\" : \"label1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['edge']['$id'].should eq("edge1") + doc.parsed_response['edge']['optional1'].should eq("val1") + doc.parsed_response['edge']['_from'].should eq(v_id1) + doc.parsed_response['edge']['_to'].should eq(v_id2) + end + + it "checks get edge by $id" do + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + eid = doc.parsed_response['edge']['$id'] + e_id = doc.parsed_response['edge']['_id'] + + + cmd = "/_api/blueprints/edge/#{eid}?graph=#{graph_name}" + doc1 = ArangoDB.log_get("#{prefix}", cmd) + + doc1.code.should eq(200) + doc1.parsed_response['error'].should eq(false) + doc1.parsed_response['code'].should eq(200) + doc1.parsed_response['edge']['$id'].should eq(eid) + doc1.parsed_response['edge']['_id'].should eq(e_id) + doc1.parsed_response['edge']['optional1'].should eq("val1") + doc1.parsed_response['edge']['$label'].should eq(nil) + end + + it "checks get edge by _id" do + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + eid = doc.parsed_response['edge']['$id'] + e_id = doc.parsed_response['edge']['_id'] + + + cmd = "/_api/blueprints/edge/#{e_id}?graph=#{graph_name}" + doc1 = ArangoDB.log_get("#{prefix}", cmd) + + doc1.code.should eq(200) + doc1.parsed_response['error'].should eq(false) + doc1.parsed_response['code'].should eq(200) + doc1.parsed_response['edge']['$id'].should eq(eid) + doc1.parsed_response['edge']['_id'].should eq(e_id) + doc1.parsed_response['edge']['optional1'].should eq("val1") + doc1.parsed_response['edge']['$label'].should eq(nil) + end + + it "checks replace edge properties by _id" do + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['edge']['optional1'].should eq("val1") + doc.parsed_response['edge']['optional2'].should eq(nil) + doc.parsed_response['edge']['$label'].should eq(nil) + eid = doc.parsed_response['edge']['$id'] + e_id = doc.parsed_response['edge']['_id'] + e_to = doc.parsed_response['edge']['_to'] + + + cmd = "/_api/blueprints/edge/#{e_id}?graph=#{graph_name}" + body = "{\"$id\" : \"edge4711\", \"optional2\" : \"val2\", \"label\" : \"label1\", \"_to\" : \"to\"}" + doc1 = ArangoDB.log_put("#{prefix}", cmd, :body => body) + doc1.code.should eq(200) + doc1.parsed_response['error'].should eq(false) + doc1.parsed_response['code'].should eq(200) + doc1.parsed_response['edge']['$id'].should eq(eid) + doc1.parsed_response['edge']['_id'].should eq(e_id) + doc1.parsed_response['edge']['_to'].should eq(e_to) + doc1.parsed_response['edge']['nameEdges'].should eq(nil) + doc1.parsed_response['edge']['optional1'].should eq(nil) + doc1.parsed_response['edge']['optional2'].should eq("val2") + doc1.parsed_response['edge']['$label'].should eq(nil) + end + + it "checks delete edge by $id" do + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + eid = doc.parsed_response['edge']['$id'] + e_id = doc.parsed_response['edge']['_id'] + + + cmd = "/_api/blueprints/edge/#{eid}?graph=#{graph_name}" + doc1 = ArangoDB.log_delete("#{prefix}", cmd) + doc1.code.should eq(200) + doc1.parsed_response['error'].should eq(false) + doc1.parsed_response['code'].should eq(200) + + cmd = "/_api/blueprints/edge/#{eid}?graph=#{graph_name}" + doc2 = ArangoDB.log_get("#{prefix}", cmd) + doc2.code.should eq(400) + doc2.parsed_response['error'].should eq(true) + doc2.parsed_response['code'].should eq(400) + end + + it "checks delete edge by _id" do + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + eid = doc.parsed_response['edge']['$id'] + e_id = doc.parsed_response['edge']['_id'] + + cmd = "/_api/blueprints/edge/#{e_id}?graph=#{graph_name}" + doc1 = ArangoDB.log_delete("#{prefix}", cmd) + doc1.code.should eq(200) + doc1.parsed_response['error'].should eq(false) + doc1.parsed_response['code'].should eq(200) + + cmd = "/_api/blueprints/edge/#{eid}?graph=#{graph_name}" + doc2 = ArangoDB.log_get("#{prefix}", cmd) + doc2.code.should eq(400) + doc2.parsed_response['error'].should eq(true) + doc2.parsed_response['code'].should eq(400) + end + + end + +################################################################################ +## checking edges responses +################################################################################ + + context "checks blueprints edges requests" do + before do + truncate_collection(prefix, "_graphs") + cmd = "/_api/blueprints/graph" + body = "{\"name\" : \"#{graph_name}\", \"verticesName\" : \"#{vertex_collection}\", \"edgesName\" : \"#{edge_collection}\"}" + ArangoDB.post(cmd, :body => body) + + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{\"$id\" : \"id1\", \"optional1\" : \"val1a\", \"optional2\" : \"val2a\"}" + ArangoDB.post(cmd, :body => body) + body = "{\"$id\" : \"id2\", \"optional1\" : \"val1b\", \"optional2\" : \"val2b\"}" + ArangoDB.post(cmd, :body => body) + body = "{\"$id\" : \"id3\", \"optional1\" : \"val1c\", \"optional2\" : \"val2c\"}" + ArangoDB.post(cmd, :body => body) + + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body1 = "{\"$id\" : \"edge1\", \"_from\" : \"id1\", \"_to\" : \"id2\", \"optional1\" : \"val1a\"}" + ArangoDB.post(cmd, :body => body1) + + body2 = "{\"$id\" : \"edge2\", \"_from\" : \"id2\", \"_to\" : \"id3\", \"optional1\" : \"val1b\"}" + ArangoDB.post(cmd, :body => body2) + end + + after do + truncate_collection(prefix, "_graphs") + ArangoDB.drop_collection( vertex_collection ) + ArangoDB.drop_collection( edge_collection ) + end + + it "checks list of all edges" do + cmd = "/_api/blueprints/edges?graph=#{graph_name}" + doc = ArangoDB.log_get("#{prefix}", cmd) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['edges'].count.should eq(2) + end + + it "checks list of all edges of one vertex" do + cmd = "/_api/blueprints/edges?graph=#{graph_name}&vertex=id1" + doc = ArangoDB.log_get("#{prefix}", cmd) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['edges'].count.should eq(1) + doc.parsed_response['edges'][0]['$id'].should eq("edge1") + + cmd = "/_api/blueprints/edges?graph=#{graph_name}&vertex=id2" + doc2 = ArangoDB.log_get("#{prefix}", cmd) + + doc2.code.should eq(200) + doc2.parsed_response['error'].should eq(false) + doc2.parsed_response['code'].should eq(200) + doc2.parsed_response['edges'].count.should eq(2) + end + + it "checks list of all in edges of one vertex" do + cmd = "/_api/blueprints/edges?graph=#{graph_name}&vertex=id2&type=in" + doc = ArangoDB.log_get("#{prefix}", cmd) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['edges'].count.should eq(1) + doc.parsed_response['edges'][0]['$id'].should eq("edge1") + end + + it "checks list of all out edges of one vertex" do + cmd = "/_api/blueprints/edges?graph=#{graph_name}&vertex=id2&type=out" + doc = ArangoDB.log_get("#{prefix}", cmd) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['edges'].count.should eq(1) + doc.parsed_response['edges'][0]['$id'].should eq("edge2") + end + + end + + end + +end diff --git a/UnitTests/HttpInterface/run-tests b/UnitTests/HttpInterface/run-tests index 6e3036802b..6c6be73c8e 100755 --- a/UnitTests/HttpInterface/run-tests +++ b/UnitTests/HttpInterface/run-tests @@ -4,6 +4,7 @@ test -d logs || mkdir logs rspec --format d \ api-http-spec.rb \ api-batch-spec.rb \ + api-blueprints-spec.rb \ api-collection-spec.rb \ rest-create-document-spec.rb \ rest-read-document-spec.rb \ diff --git a/arangod/Documentation/api-blueprints.dox b/arangod/Documentation/api-blueprints.dox new file mode 100644 index 0000000000..e330ba30c5 --- /dev/null +++ b/arangod/Documentation/api-blueprints.dox @@ -0,0 +1,92 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief over the wire protocol +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2012 triagens GmbH, Cologne, Germany +/// +/// 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. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is triAGENS GmbH, Cologne, Germany +/// +/// @author Jan Steemann +/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +/// @page HttpBlueprints HTTP Interface for Blueprints implementations +/// +/// Blueprints is a property graph model interface with provided implementations. +/// Databases that implement the Blueprints interfaces automatically support +/// Blueprints-enabled applications. (http://tinkerpop.com/) +/// +/// @anchor A_JSF_POST_blueprints_graph +/// @copydetails JSF_POST_blueprints_graph +/// +/// @anchor A_JSF_GET_blueprints_graph +/// @copydetails JSF_GET_blueprints_graph +/// +/// @anchor A_JSF_DELETE_blueprints_graph +/// @copydetails JSF_DELETE_blueprints_graph +/// +/// +/// +/// +/// @anchor A_JSF_POST_blueprints_vertex +/// @copydetails JSF_POST_blueprints_vertex +/// +/// @anchor A_JSF_GET_blueprints_vertex +/// @copydetails JSF_GET_blueprints_vertex +/// +/// @anchor A_JSF_PUT_blueprints_vertex +/// @copydetails JSF_PUT_blueprints_vertex +/// +/// @anchor A_JSF_DELETE_blueprints_vertex +/// @copydetails JSF_DELETE_blueprints_vertex +/// +/// +/// +/// +/// @anchor A_JSF_GET_blueprints_vertices +/// @copydetails JSF_GET_blueprints_vertices +/// +/// +/// +/// +/// @anchor A_JSF_POST_blueprints_edge +/// @copydetails JSF_POST_blueprints_edge +/// +/// @anchor A_JSF_GET_blueprints_edge +/// @copydetails JSF_GET_blueprints_edge +/// +/// @anchor A_JSF_PUT_blueprints_edge +/// @copydetails JSF_PUT_blueprints_edge +/// +/// @anchor A_JSF_DELETE_blueprints_edge +/// @copydetails JSF_DELETE_blueprints_edge +/// +/// +/// +/// +/// @anchor A_JSF_GET_blueprints_edges +/// @copydetails JSF_GET_blueprints_edges +/// +////////////////////////////////////////////////////// + +// Local Variables: +// mode: c++ +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @\\}\\)" +// End: diff --git a/arangod/Documentation/implementor-manual.dox b/arangod/Documentation/implementor-manual.dox index f2147762b2..a3f0a788d4 100644 --- a/arangod/Documentation/implementor-manual.dox +++ b/arangod/Documentation/implementor-manual.dox @@ -95,6 +95,25 @@ /// /// /// +/// /// /// /// @endif diff --git a/js/actions/system/api-blueprint.js b/js/actions/system/api-blueprints.js similarity index 55% rename from js/actions/system/api-blueprint.js rename to js/actions/system/api-blueprints.js index 22e01e9739..3e39e1a843 100644 --- a/js/actions/system/api-blueprint.js +++ b/js/actions/system/api-blueprints.js @@ -1,5 +1,5 @@ //////////////////////////////////////////////////////////////////////////////// -/// @brief blueprint graph api +/// @brief blueprints graph api /// /// @file /// @@ -43,13 +43,100 @@ /// @brief url prefix //////////////////////////////////////////////////////////////////////////////// - var BLUEPRINT_URL = "_api/blueprint"; + var BLUEPRINTS_URL = "_api/blueprints"; //////////////////////////////////////////////////////////////////////////////// /// @brief context //////////////////////////////////////////////////////////////////////////////// - var BLUEPRINT_CONTEXT = "api"; + var BLUEPRINTS_CONTEXT = "api"; + +//////////////////////////////////////////////////////////////////////////////// +/// @} +//////////////////////////////////////////////////////////////////////////////// + +// ----------------------------------------------------------------------------- +// --SECTION-- private functions +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @addtogroup ArangoAPI +/// @{ +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +/// @brief get graph by request parameter (throws exception) +//////////////////////////////////////////////////////////////////////////////// + + function blueprints_graph_by_request_parameter (req) { + var name = req.parameters['graph']; + + if (name == undefined) { + throw "missing graph name"; + } + + return new graph.Graph(name); + } + +//////////////////////////////////////////////////////////////////////////////// +/// @brief get graph by request parameter (throws exception) +//////////////////////////////////////////////////////////////////////////////// + + function blueprints_graph_by_request (req) { + var id = req.suffix[0]; + + if (req.suffix.length > 1) { + id += "/" + req.suffix[1]; + } + + var g = new graph.Graph(id); + + if (g._properties == null) { + throw "no graph found for: " + id; + } + + return g; + } + +//////////////////////////////////////////////////////////////////////////////// +/// @brief get vertex by request (throws exception) +//////////////////////////////////////////////////////////////////////////////// + + function blueprints_vertex_by_request (graph, req) { + var id = req.suffix[0]; + + if (req.suffix.length > 1) { + id += "/" + req.suffix[1]; + } + + var vertex = graph.getVertex(id); + + if (vertex == undefined || vertex._properties == undefined) { + throw "no vertex found for: " + id; + } + + return vertex; + } + +//////////////////////////////////////////////////////////////////////////////// +/// @brief get edge by request (throws exception) +//////////////////////////////////////////////////////////////////////////////// + + function blueprints_edge_by_request (graph, req) { + var id = req.suffix[0]; + if (req.suffix.length > 1) { + id += "/" + req.suffix[1]; + } + + var edge = graph.getEdge(id); + + if (edge == undefined || edge._properties == undefined) { + throw "no edge found for: " + id; + } + + return edge; + } + //////////////////////////////////////////////////////////////////////////////// /// @} @@ -60,13 +147,38 @@ // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @brief create graph -/// -/// @REST{POST /_api/blueprint/graph} -/// {"name":"...","verticesName":"...","edgesName":"..."} +/// @addtogroup ArangoAPI +/// @{ //////////////////////////////////////////////////////////////////////////////// - function postGraph (req, res) { +//////////////////////////////////////////////////////////////////////////////// +/// @brief create a blueprint graph +/// +/// @RESTHEADER{POST /_api/blueprints/graph,create graph} +/// +/// @REST{POST /_api/blueprints/graph} +/// +//////////////////////////////////////////////////////////////////////////////// +/// +/// Creates a new graph. +/// +/// The call expects a JSON hash array as body with the following attributes: +/// +/// - @LIT{name}: The identifier or name of the new graph. +/// +/// - @LIT{verticesName}: The name of the vertices collection. +/// +/// - @LIT{edgesName}: The name of the egge collection. +/// +/// Returns an object with an attribute @LIT{graph} containing a +/// list of all graph properties. +/// +/// @EXAMPLES +/// +/// @verbinclude api-blueprints-create-graph +//////////////////////////////////////////////////////////////////////////////// + + function POST_blueprints_graph (req, res) { try { var json = actions.getJsonBody(req, res, actions.ERROR_GRAPH_COULD_NOT_CREATE_GRAPH); @@ -83,6 +195,7 @@ if (g._properties == null) { throw "no properties of graph found"; } + actions.resultOk(req, res, actions.HTTP_OK, { "graph" : g._properties} ); } catch (err) { @@ -91,29 +204,36 @@ } //////////////////////////////////////////////////////////////////////////////// -/// @brief get graph +/// @brief get blueprint graph properties /// -/// @REST{GET /_api/blueprint/graph/@FA{graph-identifier}} +/// @RESTHEADER{GET /_api/blueprints/graph/@FA{graph-identifier},get graph properties} +/// +/// @REST{GET /_api/blueprints/graph/@FA{graph-identifier}} +/// +//////////////////////////////////////////////////////////////////////////////// +/// +/// Returns an object with an attribute @LIT{graph} containing a +/// list of all graph properties. +// +/// @EXAMPLES +/// +/// get graph by name +/// +/// @verbinclude api-blueprints-get-graph +/// +/// get graph by document id +/// +/// @verbinclude api-blueprints-get-graph-by-id //////////////////////////////////////////////////////////////////////////////// - function getGraph (req, res) { + function GET_blueprints_graph (req, res) { if (req.suffix.length < 1) { actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_GRAPH, "graph not found"); return; } try { - var id = req.suffix[0]; - - if (req.suffix.length > 1) { - id += "/" + req.suffix[1]; - } - - var g = new graph.Graph(id); - - if (g._properties == null) { - throw "no properties of graph found"; - } + var g = blueprints_graph_by_request(req); actions.resultOk(req, res, actions.HTTP_OK, { "graph" : g._properties} ); } @@ -123,31 +243,31 @@ } //////////////////////////////////////////////////////////////////////////////// -/// @brief delete graph +/// @brief deletes a blueprint graph /// -/// @REST{DELETE /_api/blueprint/graph/@FA{graph-identifier}} +/// @RESTHEADER{DELETE /_api/blueprints/graph/@FA{graph-identifier},delete graph} +/// +/// @REST{DELETE /_api/blueprints/graph/@FA{graph-identifier}} +/// +/// Deletes graph, edges and vertices +/// +/// @EXAMPLES +/// +/// @verbinclude api-blueprints-delete-graph //////////////////////////////////////////////////////////////////////////////// - function deleteGraph (req, res) { + function DELETE_blueprints_graph (req, res) { if (req.suffix.length < 1) { actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_GRAPH, "graph not found"); return; } try { - var id = req.suffix[0]; - - if (req.suffix.length > 1) { - id += "/" + req.suffix[1]; - } + var g = blueprints_graph_by_request(req); - var g = new graph.Graph(id); + g.drop(); - if (g._properties == null) { - throw "no properties of graph found"; - } - - actions.resultOk(req, res, actions.HTTP_OK, { "graph" : g._properties} ); + actions.resultOk(req, res, actions.HTTP_OK, { "deleted" : true} ); } catch (err) { actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_GRAPH, err); @@ -159,22 +279,22 @@ //////////////////////////////////////////////////////////////////////////////// actions.defineHttp({ - url : BLUEPRINT_URL + "/graph", - context : BLUEPRINT_CONTEXT, + url : BLUEPRINTS_URL + "/graph", + context : BLUEPRINTS_CONTEXT, callback : function (req, res) { try { switch (req.requestType) { case (actions.POST) : - postGraph(req, res); + POST_blueprints_graph(req, res); break; case (actions.GET) : - getGraph(req, res); + GET_blueprints_graph(req, res); break; case (actions.DELETE) : - deleteGraph(req, res); + DELETE_blueprints_graph(req, res); break; default: @@ -191,33 +311,43 @@ /// @} //////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup ArangoAPI -/// @{ -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- vertex functions // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @brief create vertex -/// -/// @REST{POST /_api/blueprint/vertex?graph=@FA{graph-identifier}} -/// {"$id":"...","key1":"...","key2":"..."} +/// @addtogroup ArangoAPI +/// @{ //////////////////////////////////////////////////////////////////////////////// - function postVertex (req, res) { +//////////////////////////////////////////////////////////////////////////////// +/// @brief creates a blueprint graph vertex +/// +/// @RESTHEADER{POST /_api/blueprints/vertex?graph=@FA{graph-identifier},create vertex} +/// +/// @REST{POST /_api/blueprints/vertex?graph=@FA{graph-identifier}} +/// +//////////////////////////////////////////////////////////////////////////////// +/// +/// Creates a vertex in a graph. +/// +/// The call expects a JSON hash array as body with the vertex properties: +/// +/// - @LIT{$id}: The identifier or name of the vertex (optional). +/// +/// - further optional attributes. +/// +/// Returns an object with an attribute @LIT{vertex} containing a +/// list of all vertex properties. +/// +/// @EXAMPLES +/// +/// @verbinclude api-blueprints-create-vertex +//////////////////////////////////////////////////////////////////////////////// + + function POST_blueprints_vertex (req, res) { try { - // name/id of the graph - var name = req.parameters['graph']; - - if (name == undefined) { - throw "missing graph name"; - } - - var g = new graph.Graph(name); - + var g = blueprints_graph_by_request_parameter(req); var json = actions.getJsonBody(req, res); var id = undefined; @@ -239,38 +369,35 @@ } //////////////////////////////////////////////////////////////////////////////// -/// @brief get vertex +/// @brief get vertex properties /// -/// @REST{GET /_api/blueprint/vertex/@FA{vertex-identifier}?graph=@FA{graph-identifier}} +/// @RESTHEADER{GET /_api/blueprints/vertex/@FA{vertex-identifier}?graph=@FA{graph-identifier},get vertex} +/// +/// @REST{GET /_api/blueprints/vertex/@FA{vertex-identifier}?graph=@FA{graph-identifier}} +/// +/// Returns an object with an attribute @LIT{vertex} containing a +/// list of all vertex properties. +/// +/// @EXAMPLES +/// +/// get vertex properties by $id +/// +/// @verbinclude api-blueprints-get-vertex +/// +/// get vertex properties by document id +/// +/// @verbinclude api-blueprints-get-vertex-by-id //////////////////////////////////////////////////////////////////////////////// - function getVertex (req, res) { + function GET_blueprints_vertex (req, res) { if (req.suffix.length < 1) { actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, "vertex not found"); return; } try { - // name/id of the graph - var name = req.parameters['graph']; - - if (name == undefined) { - throw "missing graph name"; - } - - var g = new graph.Graph(name); - - var id = req.suffix[0]; - - if (req.suffix.length > 1) { - id += "/" + req.suffix[1]; - } - - var v = g.getVertex(id); - - if (v == undefined || v._properties == undefined) { - throw "no vertex found for: " + id; - } + var g = blueprints_graph_by_request_parameter(req); + var v = blueprints_vertex_by_request(g, req); actions.resultOk(req, res, actions.HTTP_OK, { "vertex" : v._properties} ); } @@ -282,36 +409,26 @@ //////////////////////////////////////////////////////////////////////////////// /// @brief delete vertex /// -/// @REST{DELETE /_api/blueprint/vertex/@FA{vertex-identifier}?graph=@FA{graph-identifier}} +/// @RESTHEADER{DELETE /_api/blueprints/vertex/@FA{vertex-identifier}?graph=@FA{graph-identifier},delete vertex} /// +/// @REST{DELETE /_api/blueprints/vertex/@FA{vertex-identifier}?graph=@FA{graph-identifier}} +/// +/// Deletes vertex and all in and out edges of the vertex +/// +/// @EXAMPLES +/// +/// @verbinclude api-blueprints-delete-vertex //////////////////////////////////////////////////////////////////////////////// - function deleteVertex (req, res) { + function DELETE_blueprints_vertex (req, res) { if (req.suffix.length < 1) { actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, "vertex not found"); return; } try { - // name/id of the graph - var name = req.parameters['graph']; - - if (name == undefined) { - throw "missing graph name"; - } - var g = new graph.Graph(name); - - var id = req.suffix[0]; - - if (req.suffix.length > 1) { - id += "/" + req.suffix[1]; - } - - var v = g.getVertex(id); - - if (v == undefined || v._properties == undefined) { - throw "no vertex found for: " + id; - } + var g = blueprints_graph_by_request_parameter(req); + var v = blueprints_vertex_by_request(g, req); g.removeVertex(v); @@ -323,40 +440,39 @@ } //////////////////////////////////////////////////////////////////////////////// -/// @brief change vertex +/// @brief updates a vertex /// -/// @REST{PUT /_api/blueprint/vertex/@FA{vertex-identifier}?graph=@FA{graph-identifier}} -/// {"$id":"...","key1":"...","key2":"..."} +/// @RESTHEADER{PUT /_api/blueprints/vertex/@FA{vertex-identifier}?graph=@FA{graph-identifier},update vertex} +/// +/// @REST{PUT /_api/blueprints/vertex/@FA{vertex-identifier}?graph=@FA{graph-identifier}} /// +//////////////////////////////////////////////////////////////////////////////// +/// +/// Replaces the vertex properties. +/// +/// The call expects a JSON hash array as body with the new vertex properties: +/// +/// - @LIT{$id}: The identifier or name of the vertex (not changeable). +/// +/// - further optional attributes. +/// +/// Returns an object with an attribute @LIT{vertex} containing a +/// list of all vertex properties. +/// +/// @EXAMPLES +/// +/// @verbinclude api-blueprints-change-vertex //////////////////////////////////////////////////////////////////////////////// - function putVertex (req, res) { + function PUT_blueprints_vertex (req, res) { if (req.suffix.length < 1) { actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX, "vertex not found"); return; } try { - // name/id of the graph - var name = req.parameters['graph']; - - if (name == undefined) { - throw "missing graph name"; - } - - var g = new graph.Graph(name); - - var id = req.suffix[0]; - - if (req.suffix.length > 1) { - id += "/" + req.suffix[1]; - } - - var v = g.getVertex(id); - - if (v == undefined || v._properties == undefined) { - throw "no vertex found for: " + id; - } + var g = blueprints_graph_by_request_parameter(req); + var v = blueprints_vertex_by_request(g, req); var json = actions.getJsonBody(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX); @@ -382,22 +498,26 @@ //////////////////////////////////////////////////////////////////////////////// actions.defineHttp({ - url : BLUEPRINT_URL + "/vertex", - context : BLUEPRINT_CONTEXT, + url : BLUEPRINTS_URL + "/vertex", + context : BLUEPRINTS_CONTEXT, callback : function (req, res) { try { switch (req.requestType) { case (actions.POST) : - postVertex(req, res); + POST_blueprints_vertex(req, res); + break; + + case (actions.DELETE) : + DELETE_blueprints_vertex(req, res); break; case (actions.GET) : - getVertex(req, res); + GET_blueprints_vertex(req, res); break; case (actions.PUT) : - putVertex(req, res); + PUT_blueprints_vertex(req, res); break; default: @@ -414,41 +534,41 @@ /// @} //////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup ArangoAPI -/// @{ -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- vertices functions // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @brief get vertices -/// -/// @REST{GET /_api/blueprint/vertices?graph=@FA{graph-identifier}} -/// +/// @addtogroup ArangoAPI +/// @{ //////////////////////////////////////////////////////////////////////////////// - function getVertices (req, res) { - try { - // name/id of the graph - var name = req.parameters['graph']; +//////////////////////////////////////////////////////////////////////////////// +/// @brief get all graph vertices +/// +/// @RESTHEADER{GET /_api/blueprints/vertices?graph=@FA{graph-identifier},get vertices} +/// +/// @REST{GET /_api/blueprints/vertices?graph=@FA{graph-identifier}} +/// +/// Returns an object with an attribute @LIT{vertices} containing a +/// list of all vertices. +/// +/// @EXAMPLES +/// +/// @verbinclude api-blueprints-get-vertices +//////////////////////////////////////////////////////////////////////////////// - if (name == undefined) { - throw "missing graph name"; + function GET_blueprints_vertices (req, res) { + try { + var g = blueprints_graph_by_request_parameter(req); + + var result = { + "vertices" : [] } - var g = new graph.Graph(name); - var v = g.getVertices(); - - var result = {}; - result["vertices"] = []; - while (v.hasNext()) { - var e = v.next(); - result["vertices"].push(e._properties); + result["vertices"].push(v.next()._properties); } actions.resultOk(req, res, actions.HTTP_OK, result); @@ -463,14 +583,14 @@ //////////////////////////////////////////////////////////////////////////////// actions.defineHttp({ - url : BLUEPRINT_URL + "/vertices", - context : BLUEPRINT_CONTEXT, + url : BLUEPRINTS_URL + "/vertices", + context : BLUEPRINTS_CONTEXT, callback : function (req, res) { try { switch (req.requestType) { case (actions.GET) : - getVertices(req, res); + GET_blueprints_vertices(req, res); break; default: @@ -487,33 +607,49 @@ /// @} //////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup ArangoAPI -/// @{ -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- edge functions // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @brief create edge -/// -/// @REST{POST /_api/blueprint/edge?graph=@FA{graph-identifier}} -/// {"$id":"...","_from":"...","_to":"...","$label":"...","data1":{...}} +/// @addtogroup ArangoAPI +/// @{ //////////////////////////////////////////////////////////////////////////////// - function postEdge (req, res) { +//////////////////////////////////////////////////////////////////////////////// +/// @brief creates a blueprint graph edge +/// +/// @RESTHEADER{POST /_api/blueprints/edge?graph=@FA{graph-identifier},create edge} +/// +/// @REST{POST /_api/blueprints/edge?graph=@FA{graph-identifier}} +/// +//////////////////////////////////////////////////////////////////////////////// +/// +/// Creates an edge in a graph. +/// +/// The call expects a JSON hash array as body with the edge properties: +/// +/// - @LIT{$id}: The identifier or name of the edge. +/// +/// - @LIT{_from}: The identifier or name of the from vertex. +/// +/// - @LIT{_to}: The identifier or name of the to vertex. +/// +/// - @LIT{$label}: A label for the edge (optional). +/// +/// - further optional attributes. +/// +/// Returns an object with an attribute @LIT{edge} containing the +/// list of all edge properties. +/// +/// @EXAMPLES +/// +/// @verbinclude api-blueprints-create-edge +//////////////////////////////////////////////////////////////////////////////// + + function POST_blueprints_edge (req, res) { try { - // name/id of the graph - var name = req.parameters['graph']; - - if (name == undefined) { - throw "missing graph name"; - } - - var g = new graph.Graph(name); - + var g = blueprints_graph_by_request_parameter(req); var json = actions.getJsonBody(req, res, actions.ERROR_GRAPH_COULD_NOT_CREATE_EDGE); if (json === undefined) { @@ -525,7 +661,7 @@ var ine = g.getVertex(json["_to"]); var label = json["$label"]; - var e = g.addEdge(id, out, ine, label, json); + var e = g.addEdge(out, ine, id, label, json); if (e == undefined || e._properties == undefined) { throw "could not create edge"; @@ -539,38 +675,29 @@ } //////////////////////////////////////////////////////////////////////////////// -/// @brief get edge +/// @brief get edge properties /// -/// @REST{GET /_api/blueprint/edge/@FA{edge-identifier}?graph=@FA{graph-identifier}} +/// @RESTHEADER{GET /_api/blueprints/edge/@FA{edge-identifier}?graph=@FA{graph-identifier},get edge} +/// +/// @REST{GET /_api/blueprints/edge/@FA{edge-identifier}?graph=@FA{graph-identifier}} +/// +/// Returns an object with an attribute @LIT{edge} containing a +/// list of all edge properties. +/// +/// @EXAMPLES +/// +/// @verbinclude api-blueprints-get-edge //////////////////////////////////////////////////////////////////////////////// - function getEdge (req, res) { + function GET_blueprints_edge (req, res) { if (req.suffix.length < 1) { actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_EDGE, "edge not found"); return; } try { - // name/id of the graph - var name = req.parameters['graph']; - - if (name == undefined) { - throw "missing graph name"; - } - - var g = new graph.Graph(name); - - var id = req.suffix[0]; - - if (req.suffix.length > 1) { - id += "/" + req.suffix[1]; - } - - var e = new graph.Edge(g, id); - - if (e == undefined || e._properties == undefined) { - throw "no edge found for: " + id; - } + var g = blueprints_graph_by_request_parameter(req); + var e = blueprints_edge_by_request(g, req); actions.resultOk(req, res, actions.HTTP_OK, { "edge" : e._properties} ); } @@ -580,38 +707,28 @@ } //////////////////////////////////////////////////////////////////////////////// -/// @brief delete edge +/// @brief deletes an edge /// -/// @REST{DELETE /_api/blueprint/edge/@FA{edge-identifier}?graph=@FA{graph-identifier}} +/// @RESTHEADER{DELETE /_api/blueprints/edge/@FA{edge-identifier}?graph=@FA{graph-identifier},delete edge} /// +/// @REST{DELETE /_api/blueprints/edge/@FA{edge-identifier}?graph=@FA{graph-identifier}} +/// +/// Deletes an edges of the graph +/// +/// @EXAMPLES +/// +/// @verbinclude api-blueprints-delete-edge //////////////////////////////////////////////////////////////////////////////// - function deleteEdge (req, res) { + function DELETE_blueprints_edge (req, res) { if (req.suffix.length < 1) { actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_EDGE, "edge not found"); return; } try { - // name/id of the graph - var name = req.parameters['graph']; - - if (name == undefined) { - throw "missing graph name"; - } - - var g = new graph.Graph(name); - - var id = req.suffix[0]; - if (req.suffix.length > 1) { - id += "/" + req.suffix[1]; - } - - var e = new graph.Edge(g, id); - - if (e == undefined || e._properties == undefined) { - throw "no edge found for: " + id; - } + var g = blueprints_graph_by_request_parameter(req); + var e = blueprints_edge_by_request(g, req); g.removeEdge(e); @@ -623,40 +740,35 @@ } //////////////////////////////////////////////////////////////////////////////// -/// @brief update edge data +/// @brief updates an edge /// -/// @REST{PUT /_api/blueprint/edge/@FA{edge-identifier}?graph=@FA{graph-identifier}} -/// {"$id":"...","_from":"...","_to":"...","$label":"...","data1":{...}} +/// @RESTHEADER{PUT /_api/blueprints/edge/@FA{edge-identifier}?graph=@FA{graph-identifier},update edge} +/// +/// @REST{PUT /_api/blueprints/edge/@FA{edge-identifier}?graph=@FA{graph-identifier}} /// +//////////////////////////////////////////////////////////////////////////////// +/// +/// Replaces the optional edge properties. +/// +/// The call expects a JSON hash array as body with the new edge properties. +/// +/// Returns an object with an attribute @LIT{edge} containing a +/// list of all edge properties. +/// +/// @EXAMPLES +/// +/// @verbinclude api-blueprints-change-edge //////////////////////////////////////////////////////////////////////////////// - function putEdge(req, res) { + function PUT_blueprints_edge(req, res) { if (req.suffix.length < 1) { actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_EDGE, "edge not found"); return; } try { - // name/id of the graph - var name = req.parameters['graph']; - - if (name == undefined) { - throw "missing graph name"; - } - - var g = new graph.Graph(name); - - var id = req.suffix[0]; - - if (req.suffix.length > 1) { - id += "/" + req.suffix[1]; - } - - var e = new graph.Edge(g, id); - - if (e == undefined || e._properties == undefined) { - throw "no edge found for: " + id; - } + var g = blueprints_graph_by_request_parameter(req); + var e = blueprints_edge_by_request(g, req); var json = actions.getJsonBody(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_EDGE); @@ -683,26 +795,26 @@ //////////////////////////////////////////////////////////////////////////////// actions.defineHttp({ - url : BLUEPRINT_URL + "/edge", - context : BLUEPRINT_CONTEXT, + url : BLUEPRINTS_URL + "/edge", + context : BLUEPRINTS_CONTEXT, callback : function (req, res) { try { switch (req.requestType) { case (actions.POST) : - postEdge(req, res); + POST_blueprints_edge(req, res); break; case (actions.GET) : - getEdge(req, res); + GET_blueprints_edge(req, res); break; case (actions.DELETE) : - deleteEdge(req, res); + DELETE_blueprints_edge(req, res); break; case (actions.PUT) : - putEdge(req, res); + PUT_blueprints_edge(req, res); break; default: @@ -729,36 +841,54 @@ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// -/// @brief get edges +/// @brief get all graph edges /// -/// Returns a list of all edges of a @FA{graph} +/// @RESTHEADER{GET /_api/blueprints/edges?graph=@FA{graph-identifier},get edges} /// -/// @REST{GET /_api/blueprint/edges?graph=@FA{graph-identifier}} +/// @REST{GET /_api/blueprints/edges?graph=@FA{graph-identifier}} /// -/// Returns a list of edges of a @FA{vertex} +/// Returns an object with an attribute @LIT{edges} containing a +/// list of all edges of the graph. /// -/// @REST{GET /_api/blueprint/edges?graph=@FA{graph-identifier}&vertex=@FA{vertex-identifier}} +/// @EXAMPLES /// -/// Returns a list of outbound edges of a @FA{vertex} +/// @verbinclude api-blueprints-get-edges +//////////////////////////////////////////////////////////////////////////////// /// -/// @REST{GET /_api/blueprint/edges?graph=@FA{graph-identifier}&vertex=@FA{vertex-identifier}&type=out} +/// @REST{GET /_api/blueprints/edges?graph=@FA{graph-identifier}&vertex=@FA{vertex-identifier}} /// -/// Returns a list of inbound edges of a @FA{vertex} +/// Returns an object with an attribute @LIT{edges} containing a +/// list of all inbound and outbound edges of a vertex. /// -/// @REST{GET /_api/blueprint/edges?graph=@FA{graph-identifier}&vertex=@FA{vertex-identifier}&type=in} +/// @EXAMPLES /// +/// @verbinclude api-blueprints-get-edges-by-vertex +//////////////////////////////////////////////////////////////////////////////// +/// +/// @REST{GET /_api/blueprints/edges?graph=@FA{graph-identifier}&vertex=@FA{vertex-identifier}&type=out} +/// +/// Returns an object with an attribute @LIT{edges} containing a +/// list of all outbound edges of a vertex. +/// +/// @EXAMPLES +/// +/// @verbinclude api-blueprints-get-out-edges-by-vertex +//////////////////////////////////////////////////////////////////////////////// +/// +/// @REST{GET /_api/blueprints/edges?graph=@FA{graph-identifier}&vertex=@FA{vertex-identifier}&type=in} +/// +/// Returns an object with an attribute @LIT{edges} containing a +/// list of all inbound edges of a vertex. +/// +/// @EXAMPLES +/// +/// @verbinclude api-blueprints-get-in-edges-by-vertex //////////////////////////////////////////////////////////////////////////////// - function getEdges(req, res) { - try { - // name/id of the graph - var name = req.parameters['graph']; - if (name == undefined) { - throw "missing graph name"; - } - - var g = new graph.Graph(name); - + function GET_blueprints_edges(req, res) { + try { + var g = blueprints_graph_by_request_parameter(req); + var result = { "edges" : [] } @@ -802,14 +932,14 @@ //////////////////////////////////////////////////////////////////////////////// actions.defineHttp({ - url : BLUEPRINT_URL + "/edges", - context : BLUEPRINT_CONTEXT, + url : BLUEPRINTS_URL + "/edges", + context : BLUEPRINTS_CONTEXT, callback : function (req, res) { try { switch (req.requestType) { case (actions.GET) : - getEdges(req, res); + GET_blueprints_edges(req, res); break; default: diff --git a/js/common/modules/graph.js b/js/common/modules/graph.js index 4a9893d60d..647e70e426 100644 --- a/js/common/modules/graph.js +++ b/js/common/modules/graph.js @@ -1105,7 +1105,6 @@ function Graph(name, vertices, edges) { if (graphProperties === null) { throw "no graph named '" + name + "' found"; } - throw "no graph named '" + name + "' found"; } vertices = internal.db._collection(graphProperties.vertices); @@ -1129,9 +1128,9 @@ function Graph(name, vertices, edges) { vertices = findOrCreateCollectionByName(vertices); edges = findOrCreateEdgeCollectionByName(edges); - // Currently buggy: - // edges.ensureUniqueConstraint("$id"); - // vertices.ensureUniqueConstraint("$id"); + // Currently buggy? + edges.ensureUniqueConstraint("$id"); + vertices.ensureUniqueConstraint("$id"); graphProperties = gdb.firstExample('name', name); @@ -1402,6 +1401,37 @@ Graph.prototype.getVertices = function () { return new Iterator(); }; +//////////////////////////////////////////////////////////////////////////////// +/// @brief returns an edge given its id +/// +/// @FUN{@FA{graph}.getEdge(@FA{id})} +/// +/// Returns the edge identified by @FA{id} or @LIT{null}. +/// +/// @EXAMPLES +/// +/// @verbinclude graph-graph-get-edge +//////////////////////////////////////////////////////////////////////////////// + +Graph.prototype.getEdge = function (id) { + var ref, + edge; + + ref = this._edges.firstExample('$id', id); + + if (ref !== null) { + edge = this.constructEdge(ref._id); + } else { + try { + edge = this.constructEdge(id); + } catch (e) { + edge = null; + } + } + + return edge; +}; + //////////////////////////////////////////////////////////////////////////////// /// @brief returns an iterator for all edges /// diff --git a/js/common/tests/shell-graph.js b/js/common/tests/shell-graph.js index fc96ea0502..108aa027a7 100644 --- a/js/common/tests/shell-graph.js +++ b/js/common/tests/shell-graph.js @@ -204,8 +204,7 @@ function GraphBasicsSuite() { v1 = graph.addVertex("vertex1"); v2 = graph.addVertex("vertex2"); - edge = graph.addEdge(v1, - v2); + edge = graph.addEdge(v1, v2); assertEqual(null, edge.getId()); }, @@ -367,9 +366,9 @@ function VertexSuite() { edge1, edge2; - v1 = graph.addVertex(graph); - v2 = graph.addVertex(graph); - v3 = graph.addVertex(graph); + v1 = graph.addVertex(); + v2 = graph.addVertex(); + v3 = graph.addVertex(); edge1 = v1.addInEdge(v2); edge2 = v1.addOutEdge(v3); @@ -389,8 +388,8 @@ function VertexSuite() { v2, edge; - v1 = graph.addVertex(graph); - v2 = graph.addVertex(graph); + v1 = graph.addVertex(); + v2 = graph.addVertex(); edge = graph.addEdge(v1, v2); @@ -412,8 +411,8 @@ function VertexSuite() { edge1, edge2; - v1 = graph.addVertex(graph); - v2 = graph.addVertex(graph); + v1 = graph.addVertex(); + v2 = graph.addVertex(); edge1 = graph.addEdge(v1, v2, null, "label_1"); edge2 = graph.addEdge(v1, v2, null, "label_2");