1
0
Fork 0

changed the edges and vertices request.

This commit is contained in:
a-brandt 2012-11-16 13:56:24 +01:00
parent 66bc12901c
commit c20bc4f4d1
11 changed files with 507 additions and 189 deletions

View File

@ -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 content-type: application/json; charset=utf-8
{ {
"edges": [ "result": [
{ {
"_id": "94950886/97834470", "_id": "90051519/93328319",
"_rev": 97834470, "_rev": 93328319,
"_key": "97834470", "_key": "93328319",
"_bidirectional": false, "_bidirectional": false,
"_from": "94164454/97310182", "_from": "89265087/92607423",
"_to": "94164454/97506790", "_to": "89265087/92672959",
"$label": null,
"$id": "edge1",
"optional1": "val1a"
},
{
"_id": "94950886/98227686",
"_rev": 98227686,
"_key": "98227686",
"_bidirectional": false,
"_from": "94164454/97506790",
"_to": "94164454/97572326",
"$label": null, "$label": null,
"$id": "edge2", "$id": "edge2",
"optional1": "val1b" "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, "error": false,
"code": 200 "code": 201
} }

View File

@ -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 content-type: application/json; charset=utf-8
{ {
"edges": [ "result": [
{ {
"_id": "99145190/102028774", "_id": "94311359/97194943",
"_rev": 102028774, "_rev": 97194943,
"_key": "102028774", "_key": "97194943",
"_bidirectional": false, "_bidirectional": false,
"_from": "98358758/101504486", "_from": "93524927/96670655",
"_to": "98358758/101701094", "_to": "93524927/96867263",
"$label": null, "$label": null,
"$id": "edge1", "$id": "edge1",
"optional1": "val1a" "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, "error": false,
"code": 200 "code": 201
} }

View File

@ -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 content-type: application/json; charset=utf-8
{ {
"edges": [ "result": [
{ {
"_id": "103339494/106223078", "_id": "98636735/101520319",
"_rev": 106223078, "_rev": 101520319,
"_key": "106223078", "_key": "101520319",
"_bidirectional": false, "_bidirectional": false,
"_from": "102553062/105698790", "_from": "97850303/100996031",
"_to": "102553062/105895398", "_to": "97850303/101192639",
"$label": null, "$label": null,
"$id": "edge1", "$id": "edge1",
"optional1": "val1a" "optional1": "val1a"
} }
], ],
"hasMore": false,
"error": false, "error": false,
"code": 200 "code": 201
} }

View File

@ -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 content-type: application/json; charset=utf-8
{ {
"edges": [ "result": [
{ {
"_id": "107533798/110810598", "_id": "102896575/106173375",
"_rev": 110810598, "_rev": 106173375,
"_key": "110810598", "_key": "106173375",
"_bidirectional": false, "_bidirectional": false,
"_from": "106747366/110089702", "_from": "102110143/105452479",
"_to": "106747366/110155238", "_to": "102110143/105518015",
"$label": null, "$label": null,
"$id": "edge2", "$id": "edge2",
"optional1": "val1b" "optional1": "val1b"
} }
], ],
"hasMore": false,
"error": false, "error": false,
"code": 200 "code": 201
} }

View File

@ -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
}

View File

@ -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 content-type: application/json; charset=utf-8
{ {
"vertices": [ "result": [
{ {
"_id": "49927654/53401062", "_id": "44402657/47744993",
"_rev": 53401062, "_rev": 47744993,
"_key": "53401062", "_key": "47744993",
"$id": null, "optional2": 2,
"optional1": "val1", "$id": "id2",
"optional2": "val2" "optional1": "val1"
}, },
{ {
"_id": "49927654/53073382", "_id": "44402657/47810529",
"_rev": 53073382, "_rev": 47810529,
"_key": "53073382", "_key": "47810529",
"$id": null, "optional2": 2,
"optional1": "val1", "$id": "id3",
"optional2": "val2" "optional1": "val1"
}, },
{ {
"_id": "49927654/53335526", "_id": "44402657/47548385",
"_rev": 53335526, "_rev": 47548385,
"_key": "53335526", "_key": "47548385",
"$id": null, "optional2": 1,
"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", "$id": "id1",
"optional1": "val1"
},
{
"_id": "44402657/48007137",
"_rev": 48007137,
"_key": "48007137",
"$id": "id5",
"optional2": "val2" "optional2": "val2"
},
{
"_id": "44402657/47876065",
"_rev": 47876065,
"_key": "47876065",
"optional2": 3,
"$id": "id4",
"optional1": "val1"
} }
], ],
"hasMore": false,
"error": false, "error": false,
"code": 200 "code": 201
} }

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -315,24 +315,82 @@ describe ArangoDB do
it "checks list of vertices" do it "checks list of vertices" do
cmd = "/_api/blueprints/vertex?graph=#{graph_name}" 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) ArangoDB.log_post("#{prefix}", cmd, :body => body)
body = "{\"$id\" : \"id2\", \"optional1\" : \"val1\", \"optional2\" : 2}"
ArangoDB.log_post("#{prefix}", cmd, :body => body) ArangoDB.log_post("#{prefix}", cmd, :body => body)
body = "{\"$id\" : \"id3\", \"optional1\" : \"val1\", \"optional2\" : 2}"
ArangoDB.log_post("#{prefix}", cmd, :body => body) 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) ArangoDB.log_post("#{prefix}", cmd, :body => body)
body = "{\"$id\" : \"id1\", \"optional2\" : \"val2\"}" cmd = "/_api/blueprints/edge?graph=#{graph_name}"
ArangoDB.log_post("#{prefix}", cmd, :body => body) body = "{\"$id\" : \"edge1\", \"_from\" : \"id1\", \"_to\" : \"id2\", \"$label\" : \"l1\"}"
ArangoDB.log_post("#{prefix}", cmd, :body => body) doc = ArangoDB.log_post("#{prefix}", cmd, :body => body)
ArangoDB.log_post("#{prefix}", cmd, :body => body) body = "{\"$id\" : \"edge2\", \"_from\" : \"id2\", \"_to\" : \"id3\", \"$label\" : \"l2\"}"
ArangoDB.log_post("#{prefix}", cmd, :body => body) doc = ArangoDB.log_post("#{prefix}", cmd, :body => body)
cmd = "/_api/blueprints/vertices?graph=#{graph_name}" cmd = "/_api/blueprints/vertices?graph=#{graph_name}"
doc = ArangoDB.log_get("#{prefix}", cmd) body = "{\"batchSize\" : 100 }"
doc.code.should eq(200) doc = ArangoDB.log_post("#{prefix}", cmd, :body => body)
doc.code.should eq(201)
doc.parsed_response['error'].should eq(false) doc.parsed_response['error'].should eq(false)
doc.parsed_response['code'].should eq(200) doc.parsed_response['code'].should eq(201)
doc.parsed_response['vertices'].count.should eq(5) 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
end end
@ -590,53 +648,58 @@ describe ArangoDB do
it "checks list of all edges" do it "checks list of all edges" do
cmd = "/_api/blueprints/edges?graph=#{graph_name}" 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['error'].should eq(false)
doc.parsed_response['code'].should eq(200) doc.parsed_response['code'].should eq(201)
doc.parsed_response['edges'].count.should eq(2) doc.parsed_response['result'].count.should eq(2)
end end
it "checks list of all edges of one vertex" do it "checks list of all edges of one vertex" do
cmd = "/_api/blueprints/edges?graph=#{graph_name}&vertex=id1" cmd = "/_api/blueprints/edges?graph=#{graph_name}"
doc = ArangoDB.log_get("#{prefix}", cmd) 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['error'].should eq(false)
doc.parsed_response['code'].should eq(200) doc.parsed_response['code'].should eq(201)
doc.parsed_response['edges'].count.should eq(1) doc.parsed_response['result'].count.should eq(1)
doc.parsed_response['edges'][0]['$id'].should eq("edge1") doc.parsed_response['result'][0]['$id'].should eq("edge1")
cmd = "/_api/blueprints/edges?graph=#{graph_name}&vertex=id2" cmd = "/_api/blueprints/edges?graph=#{graph_name}"
doc2 = ArangoDB.log_get("#{prefix}", cmd) 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['error'].should eq(false)
doc2.parsed_response['code'].should eq(200) doc2.parsed_response['code'].should eq(201)
doc2.parsed_response['edges'].count.should eq(2) doc2.parsed_response['result'].count.should eq(2)
end end
it "checks list of all in edges of one vertex" do it "checks list of all in edges of one vertex" do
cmd = "/_api/blueprints/edges?graph=#{graph_name}&vertex=id2&type=in" cmd = "/_api/blueprints/edges?graph=#{graph_name}"
doc = ArangoDB.log_get("#{prefix}", cmd) 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['error'].should eq(false)
doc.parsed_response['code'].should eq(200) doc.parsed_response['code'].should eq(201)
doc.parsed_response['edges'].count.should eq(1) doc.parsed_response['result'].count.should eq(1)
doc.parsed_response['edges'][0]['$id'].should eq("edge1") doc.parsed_response['result'][0]['$id'].should eq("edge1")
end end
it "checks list of all out edges of one vertex" do it "checks list of all out edges of one vertex" do
cmd = "/_api/blueprints/edges?graph=#{graph_name}&vertex=id2&type=out" cmd = "/_api/blueprints/edges?graph=#{graph_name}"
doc = ArangoDB.log_get("#{prefix}", cmd) 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['error'].should eq(false)
doc.parsed_response['code'].should eq(200) doc.parsed_response['code'].should eq(201)
doc.parsed_response['edges'].count.should eq(1) doc.parsed_response['result'].count.should eq(1)
doc.parsed_response['edges'][0]['$id'].should eq("edge2") doc.parsed_response['result'][0]['$id'].should eq("edge2")
end end
end end

View File

@ -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 /// Returns a a cursor.
/// list of all vertices. ///
/// 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 /// @EXAMPLES
/// ///
/// Select all vertices
///
/// @verbinclude api-blueprints-get-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 { try {
var g = blueprints_graph_by_request_parameter(req); 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(); // filter key/value pairs labels
while (v.hasNext()) { if (json.key != undefined) {
result["vertices"].push(v.next()._properties); // 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) { catch (err) {
actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, err); actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, err);
@ -589,8 +694,8 @@
callback : function (req, res) { callback : function (req, res) {
try { try {
switch (req.requestType) { switch (req.requestType) {
case (actions.GET) : case (actions.POST) :
GET_blueprints_vertices(req, res); POST_blueprints_vertices(req, res);
break; break;
default: 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 /// - @LIT{vertex}: the identifier or name of a vertex. This selects inbound and
/// list of all edges of the graph. /// 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 /// @EXAMPLES
/// ///
/// Select all edges
///
/// @verbinclude api-blueprints-get-edges /// @verbinclude api-blueprints-get-edges
////////////////////////////////////////////////////////////////////////////////
/// ///
/// @REST{GET /_api/blueprints/edges?graph=@FA{graph-identifier}&vertex=@FA{vertex-identifier}} /// Select of all inbound and outbound edges of a vertex.
///
/// Returns an object with an attribute @LIT{edges} containing a
/// list of all inbound and outbound edges of a vertex.
///
/// @EXAMPLES
/// ///
/// @verbinclude api-blueprints-get-edges-by-vertex /// @verbinclude api-blueprints-get-edges-by-vertex
////////////////////////////////////////////////////////////////////////////////
/// ///
/// @REST{GET /_api/blueprints/edges?graph=@FA{graph-identifier}&vertex=@FA{vertex-identifier}&type=out} /// Select of all outbound edges of a vertex.
///
/// 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 /// @verbinclude api-blueprints-get-out-edges-by-vertex
////////////////////////////////////////////////////////////////////////////////
/// ///
/// @REST{GET /_api/blueprints/edges?graph=@FA{graph-identifier}&vertex=@FA{vertex-identifier}&type=in} /// Select of all edges of a vertex by a label.
///
/// 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 /// @verbinclude api-blueprints-get-in-edges-by-vertex
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
function GET_blueprints_edges(req, res) { function POST_blueprints_edges (req, res) {
try { 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 g = blueprints_graph_by_request_parameter(req);
var filter = "";
var result = { var bindVars = {"@edgeColl" : g._properties.edgesName};
"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);
if (json.vertex != undefined) {
// get edges of a vertex
var v = g.getVertex(json.vertex);
if (v == undefined || v._properties == undefined) { 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 (json.direction == "in") {
if (type === "in") { filter = " FILTER e._to == @id ";
result.edges = g._edges.inEdges(v._id);
} }
else if (type === "out") { else if (json.direction == "out") {
result.edges = g._edges.outEdges(v._id); filter = " FILTER e._from == @id ";
} }
else { 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) { 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 /// @brief actions gateway
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -938,8 +1076,8 @@
callback : function (req, res) { callback : function (req, res) {
try { try {
switch (req.requestType) { switch (req.requestType) {
case (actions.GET) : case (actions.POST) :
GET_blueprints_edges(req, res); POST_blueprints_edges(req, res);
break; break;
default: default: