From d1478709198c39e8e0d0f916385b296d39e22c20 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Fri, 14 Sep 2012 11:55:23 +0200 Subject: [PATCH 1/2] added cleanup --- 3rdParty/Makefile.all-in-one-libev | 1 + 3rdParty/Makefile.all-in-one-mruby | 1 + 3rdParty/Makefile.all-in-one-protobuf | 2 ++ 3rdParty/Makefile.all-in-one-v8 | 1 + 3rdParty/Makefile.all-in-one-zeromq | 2 ++ 5 files changed, 7 insertions(+) diff --git a/3rdParty/Makefile.all-in-one-libev b/3rdParty/Makefile.all-in-one-libev index 31b871a069..2081faa89b 100644 --- a/3rdParty/Makefile.all-in-one-libev +++ b/3rdParty/Makefile.all-in-one-libev @@ -9,6 +9,7 @@ ################################################################################ BUILT_SOURCES += @LIBEV_LIBS@ +CLEANUP += @srcdir@/.libev-build-@TRI_BITS@ @LIBEV_LIBS@: @srcdir@/.libev-build-@TRI_BITS@ diff --git a/3rdParty/Makefile.all-in-one-mruby b/3rdParty/Makefile.all-in-one-mruby index 5b98fe4c13..774b4da320 100644 --- a/3rdParty/Makefile.all-in-one-mruby +++ b/3rdParty/Makefile.all-in-one-mruby @@ -9,6 +9,7 @@ ################################################################################ BUILT_SOURCES += @MRUBY_LIBS@ +CLEANUP += @srcdir@/.mruby-build-@TRI_BITS@ @MRUBY_LIBS@: @srcdir@/.mruby-build-@TRI_BITS@ diff --git a/3rdParty/Makefile.all-in-one-protobuf b/3rdParty/Makefile.all-in-one-protobuf index 1b7b72aada..659be23647 100644 --- a/3rdParty/Makefile.all-in-one-protobuf +++ b/3rdParty/Makefile.all-in-one-protobuf @@ -9,6 +9,8 @@ ################################################################################ BUILT_SOURCES += @PROTOBUF_LIBS@ +CLEANUP += @srcdir@/.protobuf-build-@TRI_BITS@ + PROTOBUFDIR = @abs_top_srcdir@/3rdParty/protobuf-2.4.1/BUILD @PROTOBUF_LIBS@: @srcdir@/.protobuf-build-@TRI_BITS@ diff --git a/3rdParty/Makefile.all-in-one-v8 b/3rdParty/Makefile.all-in-one-v8 index 95dc0567d8..27aae0a534 100644 --- a/3rdParty/Makefile.all-in-one-v8 +++ b/3rdParty/Makefile.all-in-one-v8 @@ -9,6 +9,7 @@ ################################################################################ BUILT_SOURCES += @V8_LIBS@ +CLEANUP += @srcdir@/.v8-build-@TRI_BITS@ @V8_LIBS@: @srcdir@/.v8-build-@TRI_BITS@ diff --git a/3rdParty/Makefile.all-in-one-zeromq b/3rdParty/Makefile.all-in-one-zeromq index 8cfcfbfc23..3ca21077f1 100644 --- a/3rdParty/Makefile.all-in-one-zeromq +++ b/3rdParty/Makefile.all-in-one-zeromq @@ -9,6 +9,8 @@ ################################################################################ BUILT_SOURCES += @ZEROMQ_LIBS@ +CLEANUP += @srcdir@/.zeromq-build-@TRI_BITS@ @srcdir@/.czmq-build-@TRI_BITS@ + ZMQDIR = @abs_top_srcdir@/3rdParty/zeromq-2.2.0/BUILD @ZEROMQ_LIBS@: @srcdir@/.zeromq-build-@TRI_BITS@ @srcdir@/.czmq-build-@TRI_BITS@ From ac0076c66daa365e5fd4cc0e70fdf4af14cd2236 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Fri, 14 Sep 2012 12:58:47 +0200 Subject: [PATCH 2/2] put functions inside a anonymous function --- Makefile.in | 21 +- js/actions/system/api-blueprint.js | 968 +++++++++++++++-------------- js/actions/system/api-system.js | 6 +- 3 files changed, 511 insertions(+), 484 deletions(-) diff --git a/Makefile.in b/Makefile.in index e30e4b037f..eabf9cb65f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -274,10 +274,15 @@ DIST_COMMON = README $(am__configure_deps) $(dist_man_MANS) \ ################################################################################ @ENABLE_BISON_TRUE@am__append_22 = $(BISON_FILES) $(BISONXX_FILES) @ENABLE_ALL_IN_ONE_LIBEV_TRUE@am__append_23 = @LIBEV_LIBS@ -@ENABLE_ALL_IN_ONE_PROTOBUF_TRUE@am__append_24 = @PROTOBUF_LIBS@ -@ENABLE_ALL_IN_ONE_V8_TRUE@am__append_25 = @V8_LIBS@ -@ENABLE_MRUBY_TRUE@am__append_26 = @MRUBY_LIBS@ -@ENABLE_ZEROMQ_TRUE@am__append_27 = @ZEROMQ_LIBS@ +@ENABLE_ALL_IN_ONE_LIBEV_TRUE@am__append_24 = @srcdir@/.libev-build-@TRI_BITS@ +@ENABLE_ALL_IN_ONE_PROTOBUF_TRUE@am__append_25 = @PROTOBUF_LIBS@ +@ENABLE_ALL_IN_ONE_PROTOBUF_TRUE@am__append_26 = @srcdir@/.protobuf-build-@TRI_BITS@ +@ENABLE_ALL_IN_ONE_V8_TRUE@am__append_27 = @V8_LIBS@ +@ENABLE_ALL_IN_ONE_V8_TRUE@am__append_28 = @srcdir@/.v8-build-@TRI_BITS@ +@ENABLE_MRUBY_TRUE@am__append_29 = @MRUBY_LIBS@ +@ENABLE_MRUBY_TRUE@am__append_30 = @srcdir@/.mruby-build-@TRI_BITS@ +@ENABLE_ZEROMQ_TRUE@am__append_31 = @ZEROMQ_LIBS@ +@ENABLE_ZEROMQ_TRUE@am__append_32 = @srcdir@/.zeromq-build-@TRI_BITS@ @srcdir@/.czmq-build-@TRI_BITS@ subdir = . ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/acx_pthread.m4 \ @@ -1000,8 +1005,8 @@ BUILT_SOURCES = build.h $(JAVASCRIPT_HEADER) $(JAVASCRIPT_BROWSER) \ $(am__append_15) Doxygen/.setup-directories \ @builddir@/.setup-js-directories $(am__append_16) \ $(am__append_18) $(am__append_19) $(am__append_21) \ - $(PROTOBUF_FILES) $(am__append_23) $(am__append_24) \ - $(am__append_25) $(am__append_26) $(am__append_27) + $(PROTOBUF_FILES) $(am__append_23) $(am__append_25) \ + $(am__append_27) $(am__append_29) $(am__append_31) ################################################################################ ### @brief man pages to install @@ -1035,7 +1040,9 @@ CLEANUP = bin/arango-password bin/arango-upgrade bin/arango-dfdb \ $(DOXYGEN) $(addsuffix .md,$(addprefix Doxygen/xml/,$(WIKI))) \ $(addsuffix .md,$(addprefix Doxygen/wiki/,$(WIKI))) \ $(JAVASCRIPT_HEADER) .setup-js-directories $(am__append_17) \ - $(am__append_20) $(am__append_22) $(PROTOBUF_FILES) + $(am__append_20) $(am__append_22) $(PROTOBUF_FILES) \ + $(am__append_24) $(am__append_26) $(am__append_28) \ + $(am__append_30) $(am__append_32) ################################################################################ ### @brief flex files diff --git a/js/actions/system/api-blueprint.js b/js/actions/system/api-blueprint.js index d4d6da04f4..8c476c7e9a 100644 --- a/js/actions/system/api-blueprint.js +++ b/js/actions/system/api-blueprint.js @@ -26,164 +26,161 @@ /// @author Copyright 2012, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup ArangoAPI -/// @{ -//////////////////////////////////////////////////////////////////////////////// +(function() { + var actions = require("actions"); + var graph = require("graph"); // ----------------------------------------------------------------------------- // --SECTION-- global variables // ----------------------------------------------------------------------------- -var actions = require("actions"); -var graph = require("graph"); +//////////////////////////////////////////////////////////////////////////////// +/// @addtogroup ArangoAPI +/// @{ +//////////////////////////////////////////////////////////////////////////////// -var MY_URL = "_api/blueprint"; -var MY_CONTEXT = "api"; +//////////////////////////////////////////////////////////////////////////////// +/// @brief url prefix +//////////////////////////////////////////////////////////////////////////////// + + var BLUEPRINT_URL = "_api/blueprint"; + +//////////////////////////////////////////////////////////////////////////////// +/// @brief context +//////////////////////////////////////////////////////////////////////////////// + + var BLUEPRINT_CONTEXT = "api"; + +//////////////////////////////////////////////////////////////////////////////// +/// @} +//////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- -// --SECTION-- private functions +// --SECTION-- graph functions // ----------------------------------------------------------------------------- -shallowCopy = function (props) { - var shallow, - key; - - shallow = {}; - - for (key in props) { - if (props.hasOwnProperty(key) && key[0] !== '_' && key[0] !== '$') { - shallow[key] = props[key]; - } - } - - return shallow; -}; - //////////////////////////////////////////////////////////////////////////////// /// @brief create graph /// /// @REST{POST /_api/blueprint/graph} /// {"name":"...","verticesName":"...","edgesName":"..."} -/// //////////////////////////////////////////////////////////////////////////////// -function postGraph(req, res) { - try { - var json = actions.getJsonBody(req, res, actions.ERROR_GRAPH_COULD_NOT_CREATE_GRAPH); + function postGraph (req, res) { + try { + var json = actions.getJsonBody(req, res, actions.ERROR_GRAPH_COULD_NOT_CREATE_GRAPH); - if (json === undefined) { - return; + if (json === undefined) { + return; + } + + var name = json['name']; + var vertices = json['verticesName']; + var edges = json['edgesName']; + + var g = new graph.Graph(name, vertices, edges); + + if (g._properties == null) { + throw "no properties of graph found"; + } + actions.resultOk(req, res, actions.HTTP_OK, { "graph" : g._properties} ); } - - var name = json['name']; - var vertices = json['verticesName']; - var edges = json['edgesName']; - - var g = new graph.Graph(name, vertices, edges); - - if (g._properties == null) { - throw "no properties of graph found"; + catch (err) { + actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CREATE_GRAPH, err); } - actions.resultOk(req, res, actions.HTTP_OK, { "graph" : g._properties} ); } - catch (err) { - actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CREATE_GRAPH, err); - } -} //////////////////////////////////////////////////////////////////////////////// /// @brief get graph /// /// @REST{GET /_api/blueprint/graph/@FA{graph-identifier}} -/// //////////////////////////////////////////////////////////////////////////////// -function getGraph(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]; + function getGraph (req, res) { + if (req.suffix.length < 1) { + actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_GRAPH, "graph not found"); + return; } - var g = new graph.Graph(id); + try { + var id = req.suffix[0]; - if (g._properties == null) { - throw "no properties of graph found"; + 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"; + } + + actions.resultOk(req, res, actions.HTTP_OK, { "graph" : g._properties} ); + } + catch (err) { + actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_GRAPH, err); } - - actions.resultOk(req, res, actions.HTTP_OK, { "graph" : g._properties} ); } - catch (err) { - actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_GRAPH, err); - } -} //////////////////////////////////////////////////////////////////////////////// /// @brief delete graph /// /// @REST{DELETE /_api/blueprint/graph/@FA{graph-identifier}} -/// //////////////////////////////////////////////////////////////////////////////// -function deleteGraph(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]; + function deleteGraph (req, res) { + if (req.suffix.length < 1) { + actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_GRAPH, "graph not found"); + return; } - var g = new graph.Graph(id); + try { + var id = req.suffix[0]; - if (g._properties == null) { - throw "no properties of graph found"; + 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"; + } + + actions.resultOk(req, res, actions.HTTP_OK, { "graph" : g._properties} ); + } + catch (err) { + actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_GRAPH, err); } - - actions.resultOk(req, res, actions.HTTP_OK, { "graph" : g._properties} ); } - catch (err) { - actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_GRAPH, err); - } -} //////////////////////////////////////////////////////////////////////////////// /// @brief actions gateway //////////////////////////////////////////////////////////////////////////////// -actions.defineHttp({ - url : MY_URL + "/graph", - context : MY_CONTEXT, + actions.defineHttp({ + url : BLUEPRINT_URL + "/graph", + context : BLUEPRINT_CONTEXT, - callback : function (req, res) { - switch (req.requestType) { - case (actions.POST) : - postGraph(req, res); - break; + callback : function (req, res) { + switch (req.requestType) { + case (actions.POST) : + postGraph(req, res); + break; - case (actions.GET) : - getGraph(req, res); - break; + case (actions.GET) : + getGraph(req, res); + break; - case (actions.DELETE) : - deleteGraph(req, res); - break; + case (actions.DELETE) : + deleteGraph(req, res); + break; - default: - actions.resultUnsupported(req, res); + default: + actions.resultUnsupported(req, res); + } } - } -}); - + }); //////////////////////////////////////////////////////////////////////////////// /// @} @@ -195,7 +192,7 @@ actions.defineHttp({ //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- -// --SECTION-- private functions +// --SECTION-- vertex functions // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// @@ -203,76 +200,79 @@ actions.defineHttp({ /// /// @REST{POST /_api/blueprint/vertex?graph=@FA{graph-identifier}} /// {"$id":"...","key1":"...","key2":"..."} -/// //////////////////////////////////////////////////////////////////////////////// -function postVertex(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 postVertex (req, res) { + try { + // name/id of the graph + var name = req.parameters['graph']; - var json = actions.getJsonBody(req, res); - var id = undefined; - - if (json) { - id = json["$id"]; - } + if (name == undefined) { + throw "missing graph name"; + } - var v = g.addVertex(id, json); + var g = new graph.Graph(name); - if (v == undefined || v._properties == undefined) { - throw "could not create vertex"; + var json = actions.getJsonBody(req, res); + var id = undefined; + + if (json) { + id = json["$id"]; + } + + var v = g.addVertex(id, json); + + if (v == undefined || v._properties == undefined) { + throw "could not create vertex"; + } + + actions.resultOk(req, res, actions.HTTP_OK, { "vertex" : v._properties } ); + } + catch (err) { + actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CREATE_VERTEX, err); } - - actions.resultOk(req, res, actions.HTTP_OK, { "vertex" : v._properties } ); } - catch (err) { - actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CREATE_VERTEX, err); - } -} //////////////////////////////////////////////////////////////////////////////// /// @brief get vertex /// /// @REST{GET /_api/blueprint/vertex/@FA{vertex-identifier}?graph=@FA{graph-identifier}} -/// //////////////////////////////////////////////////////////////////////////////// -function getVertex(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]; + function getVertex (req, res) { + if (req.suffix.length < 1) { + actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, "vertex not found"); + return; } - - var v = g.getVertex(id); - if (v == undefined || v._properties == undefined) { - throw "no vertex found for: " + id; + 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; + } + + actions.resultOk(req, res, actions.HTTP_OK, { "vertex" : v._properties} ); + } + catch (err) { + actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, err); } - - actions.resultOk(req, res, actions.HTTP_OK, { "vertex" : v._properties} ); } - catch (err) { - actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, err); - } -} //////////////////////////////////////////////////////////////////////////////// /// @brief delete vertex @@ -281,39 +281,41 @@ function getVertex(req, res) { /// //////////////////////////////////////////////////////////////////////////////// -function deleteVertex(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"; + function deleteVertex (req, res) { + if (req.suffix.length < 1) { + actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, "vertex not found"); + return; } - 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); + try { + // name/id of the graph + var name = req.parameters['graph']; - if (v == undefined || v._properties == undefined) { - throw "no vertex found for: " + id; + 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; + } + + g.removeVertex(v); + + actions.resultOk(req, res, actions.HTTP_OK, { "deleted" : true} ); + } + catch (err) { + actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, err); } - - g.removeVertex(v); - - actions.resultOk(req, res, actions.HTTP_OK, { "deleted" : true} ); } - catch (err) { - actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, err); - } -} //////////////////////////////////////////////////////////////////////////////// /// @brief change vertex @@ -323,77 +325,80 @@ function deleteVertex(req, res) { /// //////////////////////////////////////////////////////////////////////////////// -function putVertex(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 json = actions.getJsonBody(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX); - - if (json === undefined) { + function putVertex (req, res) { + if (req.suffix.length < 1) { + actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX, "vertex not found"); return; } - var shallow = shallowCopy(json); - shallow.$id = v._properties.$id; + try { + // name/id of the graph + var name = req.parameters['graph']; - var id2 = g._vertices.replace(v._properties, shallow); - var result = g._vertices.document(id2); + if (name == undefined) { + throw "missing graph name"; + } - actions.resultOk(req, res, actions.HTTP_OK, { "vertex" : result} ); + 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 json = actions.getJsonBody(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX); + + if (json === undefined) { + return; + } + + var shallow = json.shallowCopy; + shallow.$id = v._properties.$id; + + var id2 = g._vertices.replace(v._properties, shallow); + var result = g._vertices.document(id2); + + actions.resultOk(req, res, actions.HTTP_OK, { "vertex" : result} ); + } + catch (err) { + actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX, err); + } } - catch (err) { - actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX, err); - } -} //////////////////////////////////////////////////////////////////////////////// /// @brief actions gateway //////////////////////////////////////////////////////////////////////////////// -actions.defineHttp({ - url : MY_URL + "/vertex", - context : MY_CONTEXT, + actions.defineHttp({ + url : BLUEPRINT_URL + "/vertex", + context : BLUEPRINT_CONTEXT, - callback : function (req, res) { - switch (req.requestType) { - case (actions.POST) : - postVertex(req, res); - break; + callback : function (req, res) { + switch (req.requestType) { + case (actions.POST) : + postVertex(req, res); + break; - case (actions.GET) : - getVertex(req, res); - break; + case (actions.GET) : + getVertex(req, res); + break; - case (actions.PUT) : - putVertex(req, res); - break; + case (actions.PUT) : + putVertex(req, res); + break; - default: - actions.resultUnsupported(req, res); + default: + actions.resultUnsupported(req, res); + } } - } -}); + }); //////////////////////////////////////////////////////////////////////////////// /// @} @@ -405,7 +410,7 @@ actions.defineHttp({ //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- -// --SECTION-- private functions +// --SECTION-- vertices functions // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// @@ -415,51 +420,53 @@ actions.defineHttp({ /// //////////////////////////////////////////////////////////////////////////////// -function getVertices(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 v = g.getVertices(); + function getVertices (req, res) { + try { + // name/id of the graph + var name = req.parameters['graph']; - var result = {}; - result["vertices"] = []; - - while (v.hasNext()) { - var e = v.next(); - result["vertices"].push(e._properties); + if (name == undefined) { + throw "missing graph name"; + } + + 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); + } + + actions.resultOk(req, res, actions.HTTP_OK, result); + } + catch (err) { + actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, err); } - - actions.resultOk(req, res, actions.HTTP_OK, result); } - catch (err) { - actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, err); - } -} //////////////////////////////////////////////////////////////////////////////// /// @brief actions gateway //////////////////////////////////////////////////////////////////////////////// -actions.defineHttp({ - url : MY_URL + "/vertices", - context : MY_CONTEXT, + actions.defineHttp({ + url : BLUEPRINT_URL + "/vertices", + context : BLUEPRINT_CONTEXT, - callback : function (req, res) { - switch (req.requestType) { - case (actions.GET) : - getVertices(req, res); - break; + callback : function (req, res) { + switch (req.requestType) { + case (actions.GET) : + getVertices(req, res); + break; - default: - actions.resultUnsupported(req, res); + default: + actions.resultUnsupported(req, res); + } } - } -}); + }); //////////////////////////////////////////////////////////////////////////////// /// @} @@ -471,7 +478,7 @@ actions.defineHttp({ //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- -// --SECTION-- private functions +// --SECTION-- edge functions // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// @@ -479,80 +486,83 @@ actions.defineHttp({ /// /// @REST{POST /_api/blueprint/edge?graph=@FA{graph-identifier}} /// {"$id":"...","_from":"...","_to":"...","$label":"...","data1":{...}} -/// //////////////////////////////////////////////////////////////////////////////// -function postEdge(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 postEdge (req, res) { + try { + // name/id of the graph + var name = req.parameters['graph']; - var json = actions.getJsonBody(req, res, actions.ERROR_GRAPH_COULD_NOT_CREATE_EDGE); - - if (json === undefined) { - return; - } - - var id = json["$id"]; - var out = g.getVertex(json["_from"]); - var ine = g.getVertex(json["_to"]); - var label = json["$label"]; + if (name == undefined) { + throw "missing graph name"; + } - var e = g.addEdge(id, out, ine, label, json); + var g = new graph.Graph(name); - if (e == undefined || e._properties == undefined) { - throw "could not create edge"; + var json = actions.getJsonBody(req, res, actions.ERROR_GRAPH_COULD_NOT_CREATE_EDGE); + + if (json === undefined) { + return; + } + + var id = json["$id"]; + var out = g.getVertex(json["_from"]); + var ine = g.getVertex(json["_to"]); + var label = json["$label"]; + + var e = g.addEdge(id, out, ine, label, json); + + if (e == undefined || e._properties == undefined) { + throw "could not create edge"; + } + + actions.resultOk(req, res, actions.HTTP_OK, { "edge" : e._properties } ); + } + catch (err) { + actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CREATE_EDGE, err); } - - actions.resultOk(req, res, actions.HTTP_OK, { "edge" : e._properties } ); } - catch (err) { - actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CREATE_EDGE, err); - } -} //////////////////////////////////////////////////////////////////////////////// /// @brief get edge /// /// @REST{GET /_api/blueprint/edge/@FA{edge-identifier}?graph=@FA{graph-identifier}} -/// //////////////////////////////////////////////////////////////////////////////// -function getEdge(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"; + function getEdge (req, res) { + if (req.suffix.length < 1) { + actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_EDGE, "edge not found"); + return; } - 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); + try { + // name/id of the graph + var name = req.parameters['graph']; - if (e == undefined || e._properties == undefined) { - throw "no edge found for: " + id; + 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; + } + + actions.resultOk(req, res, actions.HTTP_OK, { "edge" : e._properties} ); + } + catch (err) { + actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_EDGE, err); } - - actions.resultOk(req, res, actions.HTTP_OK, { "edge" : e._properties} ); } - catch (err) { - actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_EDGE, err); - } -} //////////////////////////////////////////////////////////////////////////////// /// @brief delete edge @@ -561,39 +571,41 @@ function getEdge(req, res) { /// //////////////////////////////////////////////////////////////////////////////// -function deleteEdge(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"; + function deleteEdge (req, res) { + if (req.suffix.length < 1) { + actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_EDGE, "edge not found"); + return; } - 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); + try { + // name/id of the graph + var name = req.parameters['graph']; - if (e == undefined || e._properties == undefined) { - throw "no edge found for: " + id; + 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; + } + + g.removeEdge(e); + + actions.resultOk(req, res, actions.HTTP_OK, { "deleted" : true} ); + } + catch (err) { + actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_EDGE, err); } - - g.removeEdge(e); - - actions.resultOk(req, res, actions.HTTP_OK, { "deleted" : true} ); } - catch (err) { - actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_EDGE, err); - } -} //////////////////////////////////////////////////////////////////////////////// /// @brief update edge data @@ -603,96 +615,99 @@ function deleteEdge(req, res) { /// //////////////////////////////////////////////////////////////////////////////// -function putEdge(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 json = actions.getJsonBody(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_EDGE); - - if (json === undefined) { + function putEdge(req, res) { + if (req.suffix.length < 1) { + actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_EDGE, "edge not found"); return; } - var shallow = shallowCopy(json); - shallow.$id = e._properties.$id; - shallow.$label = e._properties.$label; + try { + // name/id of the graph + var name = req.parameters['graph']; - var id2 = g._edges.replace(e._properties, shallow); - var result = g._edges.document(id2); + if (name == undefined) { + throw "missing graph name"; + } - actions.resultOk(req, res, actions.HTTP_OK, { "edge" : result} ); + 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 json = actions.getJsonBody(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_EDGE); + + if (json === undefined) { + return; + } + + var shallow = json.shallowCopy; + shallow.$id = e._properties.$id; + shallow.$label = e._properties.$label; + + var id2 = g._edges.replace(e._properties, shallow); + var result = g._edges.document(id2); + + actions.resultOk(req, res, actions.HTTP_OK, { "edge" : result} ); + } + catch (err) { + actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_EDGE, err); + } } - catch (err) { - actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_EDGE, err); - } -} //////////////////////////////////////////////////////////////////////////////// /// @brief actions gateway //////////////////////////////////////////////////////////////////////////////// -actions.defineHttp({ - url : MY_URL + "/edge", - context : MY_CONTEXT, + actions.defineHttp({ + url : BLUEPRINT_URL + "/edge", + context : BLUEPRINT_CONTEXT, - callback : function (req, res) { - switch (req.requestType) { - case (actions.POST) : - postEdge(req, res); - break; + callback : function (req, res) { + switch (req.requestType) { + case (actions.POST) : + postEdge(req, res); + break; - case (actions.GET) : - getEdge(req, res); - break; + case (actions.GET) : + getEdge(req, res); + break; - case (actions.DELETE) : - deleteEdge(req, res); - break; + case (actions.DELETE) : + deleteEdge(req, res); + break; - case (actions.PUT) : - putEdge(req, res); - break; + case (actions.PUT) : + putEdge(req, res); + break; - default: - actions.resultUnsupported(req, res); + default: + actions.resultUnsupported(req, res); + } } - } -}); + }); //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// +// ----------------------------------------------------------------------------- +// --SECTION-- edges functions +// ----------------------------------------------------------------------------- + //////////////////////////////////////////////////////////////////////////////// /// @addtogroup ArangoAPI /// @{ //////////////////////////////////////////////////////////////////////////////// -// ----------------------------------------------------------------------------- -// --SECTION-- private functions -// ----------------------------------------------------------------------------- - //////////////////////////////////////////////////////////////////////////////// /// @brief get edges /// @@ -714,78 +729,83 @@ actions.defineHttp({ /// //////////////////////////////////////////////////////////////////////////////// -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); - - 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); + function getEdges(req, res) { + try { + // name/id of the graph + var name = req.parameters['graph']; + if (name == undefined) { + throw "missing graph name"; + } - if (v == undefined || v._properties == undefined) { - throw "no vertex found for: " + vertex; + var g = new graph.Graph(name); + + var result = { + "edges" : [] } - - var type = req.parameters['type']; - if (type === "in") { - result.edges = g._edges.inEdges(v._id); - } - else if (type === "out") { - result.edges = g._edges.outEdges(v._id); + + var vertex = req.parameters['vertex']; + if (vertex == undefined) { + var e = g.getEdges(); + + while (e.hasNext()) { + result.edges.push(e.next()._properties); + } } else { - result.edges = g._edges.edges(v._id); - } + var v = g.getVertex(vertex); + + if (v == undefined || v._properties == undefined) { + throw "no vertex found for: " + vertex; + } + + var type = req.parameters['type']; + if (type === "in") { + result.edges = g._edges.inEdges(v._id); + } + else if (type === "out") { + result.edges = g._edges.outEdges(v._id); + } + else { + result.edges = g._edges.edges(v._id); + } + } + + actions.resultOk(req, res, actions.HTTP_OK, result); + } + catch (err) { + actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, err); } - - actions.resultOk(req, res, actions.HTTP_OK, result); } - catch (err) { - actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, err); - } -} //////////////////////////////////////////////////////////////////////////////// /// @brief actions gateway //////////////////////////////////////////////////////////////////////////////// -actions.defineHttp({ - url : MY_URL + "/edges", - context : MY_CONTEXT, + actions.defineHttp({ + url : BLUEPRINT_URL + "/edges", + context : BLUEPRINT_CONTEXT, - callback : function (req, res) { - switch (req.requestType) { - case (actions.GET) : - getEdges(req, res); - break; + callback : function (req, res) { + switch (req.requestType) { + case (actions.GET) : + getEdges(req, res); + break; - default: - actions.resultUnsupported(req, res); + default: + actions.resultUnsupported(req, res); + } } - } -}); + }); //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// +})(); + +// ----------------------------------------------------------------------------- +// --SECTION-- END-OF-FILE +// ----------------------------------------------------------------------------- // Local Variables: // mode: outline-minor diff --git a/js/actions/system/api-system.js b/js/actions/system/api-system.js index 8528e47e10..a1f1eefdaa 100644 --- a/js/actions/system/api-system.js +++ b/js/actions/system/api-system.js @@ -35,7 +35,7 @@ // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @addtogroup ActionsAdmin +/// @addtogroup ArangoAPI /// @{ //////////////////////////////////////////////////////////////////////////////// @@ -100,7 +100,7 @@ // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @addtogroup ActionsAdmin +/// @addtogroup ArangoAPI /// @{ //////////////////////////////////////////////////////////////////////////////// @@ -331,7 +331,7 @@ // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @addtogroup ActionsAdmin +/// @addtogroup ArangoAPI /// @{ ////////////////////////////////////////////////////////////////////////////////