mirror of https://gitee.com/bigwinds/arangodb
changed the edges and vertices request.
This commit is contained in:
parent
66bc12901c
commit
c20bc4f4d1
|
@ -1,33 +1,35 @@
|
|||
> curl -X GET --dump - http://localhost:8529/_api/blueprints/edges?graph=graph1
|
||||
> curl --data @- -X POST --dump - http://localhost:8529/_api/blueprints/edges?graph=graph1
|
||||
{"batchSize" : 100}
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
HTTP/1.1 201 Created
|
||||
content-type: application/json; charset=utf-8
|
||||
|
||||
{
|
||||
"edges": [
|
||||
"result": [
|
||||
{
|
||||
"_id": "94950886/97834470",
|
||||
"_rev": 97834470,
|
||||
"_key": "97834470",
|
||||
"_id": "90051519/93328319",
|
||||
"_rev": 93328319,
|
||||
"_key": "93328319",
|
||||
"_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",
|
||||
"_from": "89265087/92607423",
|
||||
"_to": "89265087/92672959",
|
||||
"$label": null,
|
||||
"$id": "edge2",
|
||||
"optional1": "val1b"
|
||||
},
|
||||
{
|
||||
"_id": "90051519/92935103",
|
||||
"_rev": 92935103,
|
||||
"_key": "92935103",
|
||||
"_bidirectional": false,
|
||||
"_from": "89265087/92410815",
|
||||
"_to": "89265087/92607423",
|
||||
"$label": null,
|
||||
"$id": "edge1",
|
||||
"optional1": "val1a"
|
||||
}
|
||||
],
|
||||
"hasMore": false,
|
||||
"error": false,
|
||||
"code": 200
|
||||
"code": 201
|
||||
}
|
||||
|
|
|
@ -1,22 +1,35 @@
|
|||
> curl -X GET --dump - http://localhost:8529/_api/blueprints/edges?graph=graph1&vertex=id1
|
||||
> curl --data @- -X POST --dump - http://localhost:8529/_api/blueprints/edges?graph=graph1
|
||||
{"batchSize" : 100, "vertex" : "id2"}
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
HTTP/1.1 201 Created
|
||||
content-type: application/json; charset=utf-8
|
||||
|
||||
{
|
||||
"edges": [
|
||||
"result": [
|
||||
{
|
||||
"_id": "99145190/102028774",
|
||||
"_rev": 102028774,
|
||||
"_key": "102028774",
|
||||
"_id": "94311359/97194943",
|
||||
"_rev": 97194943,
|
||||
"_key": "97194943",
|
||||
"_bidirectional": false,
|
||||
"_from": "98358758/101504486",
|
||||
"_to": "98358758/101701094",
|
||||
"_from": "93524927/96670655",
|
||||
"_to": "93524927/96867263",
|
||||
"$label": null,
|
||||
"$id": "edge1",
|
||||
"optional1": "val1a"
|
||||
},
|
||||
{
|
||||
"_id": "94311359/97588159",
|
||||
"_rev": 97588159,
|
||||
"_key": "97588159",
|
||||
"_bidirectional": false,
|
||||
"_from": "93524927/96867263",
|
||||
"_to": "93524927/96932799",
|
||||
"$label": null,
|
||||
"$id": "edge2",
|
||||
"optional1": "val1b"
|
||||
}
|
||||
],
|
||||
"hasMore": false,
|
||||
"error": false,
|
||||
"code": 200
|
||||
"code": 201
|
||||
}
|
||||
|
|
|
@ -1,22 +1,24 @@
|
|||
> curl -X GET --dump - http://localhost:8529/_api/blueprints/edges?graph=graph1&vertex=id2&type=in
|
||||
> curl --data @- -X POST --dump - http://localhost:8529/_api/blueprints/edges?graph=graph1
|
||||
{"batchSize" : 100, "vertex" : "id2", "direction" : "in"}
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
HTTP/1.1 201 Created
|
||||
content-type: application/json; charset=utf-8
|
||||
|
||||
{
|
||||
"edges": [
|
||||
"result": [
|
||||
{
|
||||
"_id": "103339494/106223078",
|
||||
"_rev": 106223078,
|
||||
"_key": "106223078",
|
||||
"_id": "98636735/101520319",
|
||||
"_rev": 101520319,
|
||||
"_key": "101520319",
|
||||
"_bidirectional": false,
|
||||
"_from": "102553062/105698790",
|
||||
"_to": "102553062/105895398",
|
||||
"_from": "97850303/100996031",
|
||||
"_to": "97850303/101192639",
|
||||
"$label": null,
|
||||
"$id": "edge1",
|
||||
"optional1": "val1a"
|
||||
}
|
||||
],
|
||||
"hasMore": false,
|
||||
"error": false,
|
||||
"code": 200
|
||||
"code": 201
|
||||
}
|
||||
|
|
|
@ -1,22 +1,24 @@
|
|||
> curl -X GET --dump - http://localhost:8529/_api/blueprints/edges?graph=graph1&vertex=id2&type=out
|
||||
> curl --data @- -X POST --dump - http://localhost:8529/_api/blueprints/edges?graph=graph1
|
||||
{"batchSize" : 100, "vertex" : "id2", "direction" : "out"}
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
HTTP/1.1 201 Created
|
||||
content-type: application/json; charset=utf-8
|
||||
|
||||
{
|
||||
"edges": [
|
||||
"result": [
|
||||
{
|
||||
"_id": "107533798/110810598",
|
||||
"_rev": 110810598,
|
||||
"_key": "110810598",
|
||||
"_id": "102896575/106173375",
|
||||
"_rev": 106173375,
|
||||
"_key": "106173375",
|
||||
"_bidirectional": false,
|
||||
"_from": "106747366/110089702",
|
||||
"_to": "106747366/110155238",
|
||||
"_from": "102110143/105452479",
|
||||
"_to": "102110143/105518015",
|
||||
"$label": null,
|
||||
"$id": "edge2",
|
||||
"optional1": "val1b"
|
||||
}
|
||||
],
|
||||
"hasMore": false,
|
||||
"error": false,
|
||||
"code": 200
|
||||
"code": 201
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
> curl --data @- -X POST --dump - http://localhost:8529/_api/blueprints/vertices?graph=graph1
|
||||
{"batchSize" : 100, "vertex" : "id2", "direction" : "out" }
|
||||
|
||||
HTTP/1.1 201 Created
|
||||
content-type: application/json; charset=utf-8
|
||||
|
||||
{
|
||||
"result": [
|
||||
{
|
||||
"_id": "44402657/47810529",
|
||||
"_rev": 47810529,
|
||||
"_key": "47810529",
|
||||
"optional2": 2,
|
||||
"$id": "id3",
|
||||
"optional1": "val1"
|
||||
}
|
||||
],
|
||||
"hasMore": false,
|
||||
"error": false,
|
||||
"code": 201
|
||||
}
|
||||
|
|
@ -1,50 +1,52 @@
|
|||
> curl -X GET --dump - http://localhost:8529/_api/blueprints/vertices?graph=graph1
|
||||
> curl --data @- -X POST --dump - http://localhost:8529/_api/blueprints/vertices?graph=graph1
|
||||
{"batchSize" : 100 }
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
HTTP/1.1 201 Created
|
||||
content-type: application/json; charset=utf-8
|
||||
|
||||
{
|
||||
"vertices": [
|
||||
"result": [
|
||||
{
|
||||
"_id": "49927654/53401062",
|
||||
"_rev": 53401062,
|
||||
"_key": "53401062",
|
||||
"$id": null,
|
||||
"optional1": "val1",
|
||||
"optional2": "val2"
|
||||
"_id": "44402657/47744993",
|
||||
"_rev": 47744993,
|
||||
"_key": "47744993",
|
||||
"optional2": 2,
|
||||
"$id": "id2",
|
||||
"optional1": "val1"
|
||||
},
|
||||
{
|
||||
"_id": "49927654/53073382",
|
||||
"_rev": 53073382,
|
||||
"_key": "53073382",
|
||||
"$id": null,
|
||||
"optional1": "val1",
|
||||
"optional2": "val2"
|
||||
"_id": "44402657/47810529",
|
||||
"_rev": 47810529,
|
||||
"_key": "47810529",
|
||||
"optional2": 2,
|
||||
"$id": "id3",
|
||||
"optional1": "val1"
|
||||
},
|
||||
{
|
||||
"_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": "44402657/47548385",
|
||||
"_rev": 47548385,
|
||||
"_key": "47548385",
|
||||
"optional2": 1,
|
||||
"$id": "id1",
|
||||
"optional1": "val1"
|
||||
},
|
||||
{
|
||||
"_id": "44402657/48007137",
|
||||
"_rev": 48007137,
|
||||
"_key": "48007137",
|
||||
"$id": "id5",
|
||||
"optional2": "val2"
|
||||
},
|
||||
{
|
||||
"_id": "44402657/47876065",
|
||||
"_rev": 47876065,
|
||||
"_key": "47876065",
|
||||
"optional2": 3,
|
||||
"$id": "id4",
|
||||
"optional1": "val1"
|
||||
}
|
||||
],
|
||||
"hasMore": false,
|
||||
"error": false,
|
||||
"code": 200
|
||||
"code": 201
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
> curl --data @- -X POST --dump - http://localhost:8529/_api/blueprints/vertices?graph=graph1
|
||||
{"batchSize" : 100, "key" : "optional2", "value" : 3 }
|
||||
|
||||
HTTP/1.1 201 Created
|
||||
content-type: application/json; charset=utf-8
|
||||
|
||||
{
|
||||
"result": [
|
||||
{
|
||||
"_id": "44402657/47876065",
|
||||
"_rev": 47876065,
|
||||
"_key": "47876065",
|
||||
"optional2": 3,
|
||||
"$id": "id4",
|
||||
"optional1": "val1"
|
||||
}
|
||||
],
|
||||
"hasMore": false,
|
||||
"error": false,
|
||||
"code": 201
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
> curl --data @- -X POST --dump - http://localhost:8529/_api/blueprints/vertices?graph=graph1
|
||||
{"batchSize" : 100, "vertex" : "id2", "labels" : ["l2"] }
|
||||
|
||||
HTTP/1.1 201 Created
|
||||
content-type: application/json; charset=utf-8
|
||||
|
||||
{
|
||||
"result": [
|
||||
{
|
||||
"_id": "44402657/47810529",
|
||||
"_rev": 47810529,
|
||||
"_key": "47810529",
|
||||
"optional2": 2,
|
||||
"$id": "id3",
|
||||
"optional1": "val1"
|
||||
}
|
||||
],
|
||||
"hasMore": false,
|
||||
"error": false,
|
||||
"code": 201
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
> curl --data @- -X POST --dump - http://localhost:8529/_api/blueprints/vertices?graph=graph1
|
||||
{"batchSize" : 100, "vertex" : "id2" }
|
||||
|
||||
HTTP/1.1 201 Created
|
||||
content-type: application/json; charset=utf-8
|
||||
|
||||
{
|
||||
"result": [
|
||||
{
|
||||
"_id": "44402657/47548385",
|
||||
"_rev": 47548385,
|
||||
"_key": "47548385",
|
||||
"optional2": 1,
|
||||
"$id": "id1",
|
||||
"optional1": "val1"
|
||||
},
|
||||
{
|
||||
"_id": "44402657/47810529",
|
||||
"_rev": 47810529,
|
||||
"_key": "47810529",
|
||||
"optional2": 2,
|
||||
"$id": "id3",
|
||||
"optional1": "val1"
|
||||
}
|
||||
],
|
||||
"hasMore": false,
|
||||
"error": false,
|
||||
"code": 201
|
||||
}
|
||||
|
|
@ -315,24 +315,82 @@ describe ArangoDB do
|
|||
|
||||
it "checks list of vertices" do
|
||||
cmd = "/_api/blueprints/vertex?graph=#{graph_name}"
|
||||
body = "{\"optional1\" : \"val1\", \"optional2\" : \"val2\"}"
|
||||
body = "{\"$id\" : \"id1\", \"optional1\" : \"val1\", \"optional2\" : 1}"
|
||||
ArangoDB.log_post("#{prefix}", cmd, :body => body)
|
||||
body = "{\"$id\" : \"id2\", \"optional1\" : \"val1\", \"optional2\" : 2}"
|
||||
ArangoDB.log_post("#{prefix}", cmd, :body => body)
|
||||
body = "{\"$id\" : \"id3\", \"optional1\" : \"val1\", \"optional2\" : 2}"
|
||||
ArangoDB.log_post("#{prefix}", cmd, :body => body)
|
||||
body = "{\"$id\" : \"id4\", \"optional1\" : \"val1\", \"optional2\" : 3}"
|
||||
ArangoDB.log_post("#{prefix}", cmd, :body => body)
|
||||
body = "{\"$id\" : \"id5\", \"optional2\" : \"val2\"}"
|
||||
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/edge?graph=#{graph_name}"
|
||||
body = "{\"$id\" : \"edge1\", \"_from\" : \"id1\", \"_to\" : \"id2\", \"$label\" : \"l1\"}"
|
||||
doc = ArangoDB.log_post("#{prefix}", cmd, :body => body)
|
||||
body = "{\"$id\" : \"edge2\", \"_from\" : \"id2\", \"_to\" : \"id3\", \"$label\" : \"l2\"}"
|
||||
doc = 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)
|
||||
body = "{\"batchSize\" : 100 }"
|
||||
doc = ArangoDB.log_post("#{prefix}", cmd, :body => body)
|
||||
doc.code.should eq(201)
|
||||
doc.parsed_response['error'].should eq(false)
|
||||
doc.parsed_response['code'].should eq(200)
|
||||
doc.parsed_response['vertices'].count.should eq(5)
|
||||
doc.parsed_response['code'].should eq(201)
|
||||
doc.parsed_response['result'].count.should eq(5)
|
||||
|
||||
cmd = "/_api/blueprints/vertices?graph=#{graph_name}"
|
||||
body = "{\"batchSize\" : 100, \"key\" : \"optional2\", \"value\" : 3 }"
|
||||
doc = ArangoDB.log_post("#{prefix}", cmd, :body => body)
|
||||
doc.code.should eq(201)
|
||||
doc.parsed_response['error'].should eq(false)
|
||||
doc.parsed_response['code'].should eq(201)
|
||||
doc.parsed_response['result'].count.should eq(1)
|
||||
|
||||
cmd = "/_api/blueprints/vertices?graph=#{graph_name}"
|
||||
body = "{\"batchSize\" : 100, \"key\" : \"optional2\", \"value\" : 2 }"
|
||||
doc = ArangoDB.log_post("#{prefix}", cmd, :body => body)
|
||||
doc.code.should eq(201)
|
||||
doc.parsed_response['error'].should eq(false)
|
||||
doc.parsed_response['code'].should eq(201)
|
||||
doc.parsed_response['result'].count.should eq(2)
|
||||
|
||||
cmd = "/_api/blueprints/vertices?graph=#{graph_name}"
|
||||
body = "{\"batchSize\" : 100, \"vertex\" : \"id2\" }"
|
||||
doc = ArangoDB.log_post("#{prefix}", cmd, :body => body)
|
||||
doc.code.should eq(201)
|
||||
doc.parsed_response['error'].should eq(false)
|
||||
doc.parsed_response['code'].should eq(201)
|
||||
doc.parsed_response['result'].count.should eq(2)
|
||||
|
||||
cmd = "/_api/blueprints/vertices?graph=#{graph_name}"
|
||||
body = "{\"batchSize\" : 100, \"vertex\" : \"id2\", \"direction\" : \"in\" }"
|
||||
doc = ArangoDB.log_post("#{prefix}", cmd, :body => body)
|
||||
doc.code.should eq(201)
|
||||
doc.parsed_response['error'].should eq(false)
|
||||
doc.parsed_response['code'].should eq(201)
|
||||
doc.parsed_response['result'].count.should eq(1)
|
||||
doc.parsed_response['result'][0]['$id'].should eq("id1")
|
||||
|
||||
cmd = "/_api/blueprints/vertices?graph=#{graph_name}"
|
||||
body = "{\"batchSize\" : 100, \"vertex\" : \"id2\", \"direction\" : \"out\" }"
|
||||
doc = ArangoDB.log_post("#{prefix}", cmd, :body => body)
|
||||
doc.code.should eq(201)
|
||||
doc.parsed_response['error'].should eq(false)
|
||||
doc.parsed_response['code'].should eq(201)
|
||||
doc.parsed_response['result'].count.should eq(1)
|
||||
doc.parsed_response['result'][0]['$id'].should eq("id3")
|
||||
|
||||
cmd = "/_api/blueprints/vertices?graph=#{graph_name}"
|
||||
body = "{\"batchSize\" : 100, \"vertex\" : \"id2\", \"labels\" : [\"l2\"] }"
|
||||
doc = ArangoDB.log_post("#{prefix}", cmd, :body => body)
|
||||
doc.code.should eq(201)
|
||||
doc.parsed_response['error'].should eq(false)
|
||||
doc.parsed_response['code'].should eq(201)
|
||||
doc.parsed_response['result'].count.should eq(1)
|
||||
doc.parsed_response['result'][0]['$id'].should eq("id3")
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -590,53 +648,58 @@ describe ArangoDB do
|
|||
|
||||
it "checks list of all edges" do
|
||||
cmd = "/_api/blueprints/edges?graph=#{graph_name}"
|
||||
doc = ArangoDB.log_get("#{prefix}", cmd)
|
||||
body = "{\"batchSize\" : 100}"
|
||||
doc = ArangoDB.log_post("#{prefix}", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(200)
|
||||
doc.code.should eq(201)
|
||||
doc.parsed_response['error'].should eq(false)
|
||||
doc.parsed_response['code'].should eq(200)
|
||||
doc.parsed_response['edges'].count.should eq(2)
|
||||
doc.parsed_response['code'].should eq(201)
|
||||
doc.parsed_response['result'].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)
|
||||
cmd = "/_api/blueprints/edges?graph=#{graph_name}"
|
||||
body = "{\"batchSize\" : 100, \"vertex\" : \"id1\"}"
|
||||
doc = ArangoDB.log_post("#{prefix}", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(200)
|
||||
doc.code.should eq(201)
|
||||
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")
|
||||
doc.parsed_response['code'].should eq(201)
|
||||
doc.parsed_response['result'].count.should eq(1)
|
||||
doc.parsed_response['result'][0]['$id'].should eq("edge1")
|
||||
|
||||
cmd = "/_api/blueprints/edges?graph=#{graph_name}&vertex=id2"
|
||||
doc2 = ArangoDB.log_get("#{prefix}", cmd)
|
||||
cmd = "/_api/blueprints/edges?graph=#{graph_name}"
|
||||
body = "{\"batchSize\" : 100, \"vertex\" : \"id2\"}"
|
||||
doc2 = ArangoDB.log_post("#{prefix}", cmd, :body => body)
|
||||
|
||||
doc2.code.should eq(200)
|
||||
doc2.code.should eq(201)
|
||||
doc2.parsed_response['error'].should eq(false)
|
||||
doc2.parsed_response['code'].should eq(200)
|
||||
doc2.parsed_response['edges'].count.should eq(2)
|
||||
doc2.parsed_response['code'].should eq(201)
|
||||
doc2.parsed_response['result'].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)
|
||||
cmd = "/_api/blueprints/edges?graph=#{graph_name}"
|
||||
body = "{\"batchSize\" : 100, \"vertex\" : \"id2\", \"direction\" : \"in\"}"
|
||||
doc = ArangoDB.log_post("#{prefix}", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(200)
|
||||
doc.code.should eq(201)
|
||||
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")
|
||||
doc.parsed_response['code'].should eq(201)
|
||||
doc.parsed_response['result'].count.should eq(1)
|
||||
doc.parsed_response['result'][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)
|
||||
cmd = "/_api/blueprints/edges?graph=#{graph_name}"
|
||||
body = "{\"batchSize\" : 100, \"vertex\" : \"id2\", \"direction\" : \"out\"}"
|
||||
doc = ArangoDB.log_post("#{prefix}", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(200)
|
||||
doc.code.should eq(201)
|
||||
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")
|
||||
doc.parsed_response['code'].should eq(201)
|
||||
doc.parsed_response['result'].count.should eq(1)
|
||||
doc.parsed_response['result'][0]['$id'].should eq("edge2")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -544,34 +544,139 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get all graph vertices
|
||||
/// @brief get graph vertices
|
||||
///
|
||||
/// @RESTHEADER{GET /_api/blueprints/vertices?graph=@FA{graph-identifier},get vertices}
|
||||
/// @RESTHEADER{POST /_api/blueprints/vertices?graph=@FA{graph-identifier},get vertices}
|
||||
///
|
||||
/// @REST{GET /_api/blueprints/vertices?graph=@FA{graph-identifier}}
|
||||
/// @REST{POST /_api/blueprints/vertices?graph=@FA{graph-identifier}}
|
||||
///
|
||||
/// Returns an object with an attribute @LIT{vertices} containing a
|
||||
/// list of all vertices.
|
||||
/// Returns a a cursor.
|
||||
///
|
||||
/// The call expects a JSON hash array as body to filter the edges:
|
||||
///
|
||||
/// - @LIT{vertex}: the identifier or name of a vertex. This selects inbound and
|
||||
/// outbound neighbors of a vertex. If a vertex is given the edge direction
|
||||
/// can be filterd by @LIT{direction} and labels of edges can be filterd by
|
||||
/// @LIT{labels}.
|
||||
///
|
||||
/// - @LIT{direction}: Filter for inbound (value "in") or outbound (value "out")
|
||||
/// neighbors. Default value is "any".
|
||||
///
|
||||
/// - @LIT{key}: filter the result vertices by a key value pair
|
||||
///
|
||||
/// - @LIT{value}: the value of the @LIT{key}
|
||||
///
|
||||
/// - @LIT{labels}: filter by an array of edge labels
|
||||
///
|
||||
/// - @LIT{batchSize}: the batch size of the returned cursor
|
||||
///
|
||||
/// @EXAMPLES
|
||||
///
|
||||
/// Select all vertices
|
||||
///
|
||||
/// @verbinclude api-blueprints-get-vertices
|
||||
///
|
||||
/// Select of all neighbors of a vertex.
|
||||
///
|
||||
/// @verbinclude api-blueprints-get-vertices2
|
||||
///
|
||||
/// Select of all outbound neighbors of a vertex.
|
||||
///
|
||||
/// @verbinclude api-blueprints-get-outbound-vertices
|
||||
//
|
||||
/// Select of all neighbors of a vertex by a edge label.
|
||||
///
|
||||
/// @verbinclude api-blueprints-get-vertices-label
|
||||
///
|
||||
/// Select of vertices by key value
|
||||
///
|
||||
/// @verbinclude api-blueprints-get-vertices-key
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function GET_blueprints_vertices (req, res) {
|
||||
function POST_blueprints_vertices (req, res) {
|
||||
if (req.suffix.length != 0) {
|
||||
actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, "vertex not found");
|
||||
return;
|
||||
}
|
||||
|
||||
var json = actions.getJsonBody(req, res);
|
||||
|
||||
if (json === undefined) {
|
||||
json = {};
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
var g = blueprints_graph_by_request_parameter(req);
|
||||
var selectEdge = "";
|
||||
var vertexFilter = "";
|
||||
var edgeFilter = "";
|
||||
var bindVars = {"@vertexColl" : g._properties.verticesName };
|
||||
|
||||
if (json.vertex != undefined) {
|
||||
// get neighbors
|
||||
var v = g.getVertex(json.vertex);
|
||||
|
||||
if (v == undefined || v._properties == undefined) {
|
||||
actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, "vertex not found");
|
||||
return;
|
||||
}
|
||||
selectEdge = "FOR e IN @@edgeColl";
|
||||
|
||||
// get inbound neighbors
|
||||
if (json.direction == "in") {
|
||||
edgeFilter = " FILTER e._to == @id";
|
||||
vertexFilter = " FILTER e._from == v._id";
|
||||
}
|
||||
// get outbound neighbors
|
||||
else if (json.direction == "out") {
|
||||
edgeFilter = " FILTER e._from == @id";
|
||||
vertexFilter = " FILTER e._to == v._id";
|
||||
}
|
||||
// get all neighbors
|
||||
else {
|
||||
vertexFilter = " FILTER ((e._from == @id && e._to == v._id) || (e._to == @id && e._from == v._id))";
|
||||
}
|
||||
|
||||
bindVars["@edgeColl"] = g._properties.edgesName;
|
||||
bindVars["id"] = v._id;
|
||||
|
||||
// filter edge labels
|
||||
if (json.labels != undefined && json.labels instanceof Array) {
|
||||
if (edgeFilter == "") { edgeFilter = " FILTER"; } else { edgeFilter += " &&";}
|
||||
edgeFilter += ' e["$label"] IN @labels';
|
||||
bindVars["labels"] = json.labels;
|
||||
}
|
||||
|
||||
var result = {
|
||||
"vertices" : []
|
||||
}
|
||||
|
||||
var v = g.getVertices();
|
||||
while (v.hasNext()) {
|
||||
result["vertices"].push(v.next()._properties);
|
||||
// filter key/value pairs labels
|
||||
if (json.key != undefined) {
|
||||
// get all with key=value
|
||||
if (vertexFilter == "") { vertexFilter = " FILTER"; } else { vertexFilter += " &&";}
|
||||
vertexFilter += " v[@key] == @value";
|
||||
bindVars["key"] = json.key;
|
||||
bindVars["value"] = json.value;
|
||||
}
|
||||
|
||||
actions.resultOk(req, res, actions.HTTP_OK, result);
|
||||
// build aql query
|
||||
var query = selectEdge + edgeFilter + " FOR v IN @@vertexColl" + vertexFilter + " RETURN v";
|
||||
|
||||
var cursor = AHUACATL_RUN(query,
|
||||
bindVars,
|
||||
(json.count != undefined ? json.count : false),
|
||||
json.batchSize,
|
||||
(json.batchSize == undefined));
|
||||
|
||||
// error occurred
|
||||
if (cursor instanceof ArangoError) {
|
||||
actions.resultBad(req, res, cursor.errorNum, cursor.errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
// this might dispose or persist the cursor
|
||||
actions.resultCursor(req, res, cursor, actions.HTTP_CREATED, { countRequested: json.count ? true : false });
|
||||
}
|
||||
catch (err) {
|
||||
actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, err);
|
||||
|
@ -589,8 +694,8 @@
|
|||
callback : function (req, res) {
|
||||
try {
|
||||
switch (req.requestType) {
|
||||
case (actions.GET) :
|
||||
GET_blueprints_vertices(req, res);
|
||||
case (actions.POST) :
|
||||
POST_blueprints_vertices(req, res);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -841,92 +946,125 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get all graph edges
|
||||
/// @brief get graph edges
|
||||
///
|
||||
/// @RESTHEADER{GET /_api/blueprints/edges?graph=@FA{graph-identifier},get edges}
|
||||
/// @RESTHEADER{POST /_api/blueprints/edges?graph=@FA{graph-identifier},get edges}
|
||||
///
|
||||
/// @REST{GET /_api/blueprints/edges?graph=@FA{graph-identifier}}
|
||||
/// @REST{POST /_api/blueprints/edges?graph=@FA{graph-identifier}}
|
||||
///
|
||||
/// Returns a a cursor.
|
||||
///
|
||||
/// The call expects a JSON hash array as body to filter the edges:
|
||||
///
|
||||
/// Returns an object with an attribute @LIT{edges} containing a
|
||||
/// list of all edges of the graph.
|
||||
/// - @LIT{vertex}: the identifier or name of a vertex. This selects inbound and
|
||||
/// outbound edges of a vertex. If a vertex is given the edge direction
|
||||
/// can be filterd by @LIT{direction}.
|
||||
///
|
||||
/// - @LIT{direction}: Filter for inbound (value "in") or outbound (value "out")
|
||||
/// edges. Default value is "any".
|
||||
///
|
||||
/// - @LIT{labels}: filter by an array of edge labels
|
||||
///
|
||||
/// - @LIT{key}: filter the by a key value pair
|
||||
///
|
||||
/// - @LIT{value}: the value of the @LIT{key}
|
||||
///
|
||||
/// - @LIT{batchSize}: the batch size of the returned cursor
|
||||
///
|
||||
/// @EXAMPLES
|
||||
///
|
||||
/// Select all edges
|
||||
///
|
||||
/// @verbinclude api-blueprints-get-edges
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// @REST{GET /_api/blueprints/edges?graph=@FA{graph-identifier}&vertex=@FA{vertex-identifier}}
|
||||
///
|
||||
/// Returns an object with an attribute @LIT{edges} containing a
|
||||
/// list of all inbound and outbound edges of a vertex.
|
||||
///
|
||||
/// @EXAMPLES
|
||||
/// Select of all inbound and outbound edges of a vertex.
|
||||
///
|
||||
/// @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
|
||||
/// Select of all outbound edges of a vertex.
|
||||
///
|
||||
/// @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
|
||||
/// Select of all edges of a vertex by a label.
|
||||
///
|
||||
/// @verbinclude api-blueprints-get-in-edges-by-vertex
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function GET_blueprints_edges(req, res) {
|
||||
try {
|
||||
function POST_blueprints_edges (req, res) {
|
||||
if (req.suffix.length != 0) {
|
||||
actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, "edges not found");
|
||||
return;
|
||||
}
|
||||
|
||||
var json = actions.getJsonBody(req, res);
|
||||
|
||||
if (json === undefined) {
|
||||
json = {};
|
||||
}
|
||||
|
||||
try {
|
||||
var g = blueprints_graph_by_request_parameter(req);
|
||||
|
||||
var result = {
|
||||
"edges" : []
|
||||
}
|
||||
|
||||
var vertex = req.parameters['vertex'];
|
||||
if (vertex == undefined) {
|
||||
var e = g.getEdges();
|
||||
|
||||
while (e.hasNext()) {
|
||||
result.edges.push(e.next()._properties);
|
||||
}
|
||||
}
|
||||
else {
|
||||
var v = g.getVertex(vertex);
|
||||
var filter = "";
|
||||
var bindVars = {"@edgeColl" : g._properties.edgesName};
|
||||
|
||||
if (json.vertex != undefined) {
|
||||
// get edges of a vertex
|
||||
var v = g.getVertex(json.vertex);
|
||||
|
||||
if (v == undefined || v._properties == undefined) {
|
||||
throw "no vertex found for: " + vertex;
|
||||
actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, "vertex not found");
|
||||
return;
|
||||
}
|
||||
|
||||
var type = req.parameters['type'];
|
||||
if (type === "in") {
|
||||
result.edges = g._edges.inEdges(v._id);
|
||||
if (json.direction == "in") {
|
||||
filter = " FILTER e._to == @id ";
|
||||
}
|
||||
else if (type === "out") {
|
||||
result.edges = g._edges.outEdges(v._id);
|
||||
else if (json.direction == "out") {
|
||||
filter = " FILTER e._from == @id ";
|
||||
}
|
||||
else {
|
||||
result.edges = g._edges.edges(v._id);
|
||||
}
|
||||
filter = " FILTER (e._from == @id || e._to == @id)";
|
||||
}
|
||||
|
||||
bindVars["id"] = v._id;
|
||||
}
|
||||
|
||||
actions.resultOk(req, res, actions.HTTP_OK, result);
|
||||
if (json.key != undefined) {
|
||||
// get all with key=value
|
||||
if (filter == "") {filter = " FILTER";} else {filter += " &&";}
|
||||
filter += " e[@key] == @value";
|
||||
bindVars["key"] = json.key;
|
||||
bindVars["value"] = json.value;
|
||||
}
|
||||
|
||||
if (json.labels != undefined && json.labels instanceof Array) {
|
||||
// get all with $lable=value
|
||||
if (filter == "") {filter = " FILTER";} else {filter += " &&";}
|
||||
filter += ' e["$label"] IN @labels';
|
||||
bindVars["labels"] = json.labels;
|
||||
}
|
||||
|
||||
var query = "FOR e IN @@edgeColl" + filter + " RETURN e";
|
||||
|
||||
var cursor = AHUACATL_RUN(query,
|
||||
bindVars,
|
||||
(json.count != undefined ? json.count : false),
|
||||
json.batchSize,
|
||||
(json.batchSize == undefined));
|
||||
|
||||
// error occurred
|
||||
if (cursor instanceof ArangoError) {
|
||||
actions.resultBad(req, res, cursor.errorNum, cursor.errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
// this might dispose or persist the cursor
|
||||
actions.resultCursor(req, res, cursor, actions.HTTP_CREATED, { countRequested: json.count ? true : false });
|
||||
}
|
||||
catch (err) {
|
||||
actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, err);
|
||||
actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, err + query);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief actions gateway
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -938,8 +1076,8 @@
|
|||
callback : function (req, res) {
|
||||
try {
|
||||
switch (req.requestType) {
|
||||
case (actions.GET) :
|
||||
GET_blueprints_edges(req, res);
|
||||
case (actions.POST) :
|
||||
POST_blueprints_edges(req, res);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue