From 7541149200389966263ceaf85318e0d7c6b61b58 Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Fri, 13 Jun 2014 15:11:59 +0200 Subject: [PATCH] Added functions to list all graphs and all vertex/edge collections of a specific graph to http-api --- .../HttpInterface/api-general-graph-spec.rb | 67 ++- .../js/modules/org/arangodb/general-graph.js | 98 ++++- js/apps/system/gharial/gharial.js | 380 ++++++++++++------ .../modules/org/arangodb/general-graph.js | 16 +- 4 files changed, 432 insertions(+), 129 deletions(-) diff --git a/UnitTests/HttpInterface/api-general-graph-spec.rb b/UnitTests/HttpInterface/api-general-graph-spec.rb index c1e39e5462..441e78fb76 100644 --- a/UnitTests/HttpInterface/api-general-graph-spec.rb +++ b/UnitTests/HttpInterface/api-general-graph-spec.rb @@ -47,6 +47,19 @@ def delete_edge_definition (graph_name, definition_name) return doc end +def additional_vertex_collection (graph_name, collection_name) + cmd = URLPREFIX + "/" + graph_name + "/vertex" + body = { :collection => collection_name } + doc = ArangoDB.post(cmd, :body => JSON.dump(body)) + return doc +end + +def delete_vertex_collection (graph_name, collection_name) + cmd = vertex_endpoint(graph_name, collection_name) + doc = ArangoDB.delete(cmd) + return doc +end + def create_vertex (graph_name, collection, body) cmd = vertex_endpoint(graph_name, collection) doc = ArangoDB.post(cmd, :body => JSON.dump(body)) @@ -153,7 +166,7 @@ describe ArangoDB do doc.parsed_response['error'].should eq(false) doc.parsed_response['code'].should eq(201) doc.parsed_response['graph']['name'].should eq(graph_name) - # doc.parsed_response['graph']['_rev'].should eq(doc.headers['etag']) + doc.parsed_response['graph']['_rev'].should eq(doc.headers['etag']) doc.parsed_response['graph']['edgeDefinitions'].should eq(edge_definition) end @@ -166,7 +179,7 @@ describe ArangoDB do doc.parsed_response['error'].should eq(false) doc.parsed_response['code'].should eq(201) doc.parsed_response['graph']['name'].should eq(graph_name) - # doc.parsed_response['graph']['_rev'].should eq(doc.headers['etag']) + doc.parsed_response['graph']['_rev'].should eq(doc.headers['etag']) doc.parsed_response['graph']['edgeDefinitions'].should eq(edge_definition) end @@ -181,7 +194,7 @@ describe ArangoDB do doc.code.should eq(200) doc.parsed_response['error'].should eq(false) doc.parsed_response['code'].should eq(200) - doc.parsed_response['graph']['name'].should eq("#{graph_name}") + doc.parsed_response['graph']['name'].should eq(graph_name) doc.parsed_response['graph']['_rev'].should eq(doc.headers['etag']) doc.parsed_response['graph']['edgeDefinitions'].should eq(edge_definition) end @@ -196,10 +209,54 @@ describe ArangoDB do doc.code.should eq(200) doc.parsed_response['error'].should eq(false) doc.parsed_response['code'].should eq(200) - doc.parsed_response['graph']['name'].should eq("#{graph_name}") + doc.parsed_response['graph']['name'].should eq(graph_name) doc.parsed_response['graph']['_rev'].should eq(doc.headers['etag']) doc.parsed_response['graph']['edgeDefinitions'].should eq(edge_definition) - + end + + it "can delete an edge definition" do + first_def = { "collection" => friend_collection, "from" => [user_collection], "to" => [user_collection] } + edge_definition = [first_def] + create_graph( graph_name, edge_definition ) + doc = delete_edge_definition( graph_name, friend_collection ) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['graph']['name'].should eq(graph_name) + doc.parsed_response['graph']['_rev'].should eq(doc.headers['etag']) + doc.parsed_response['graph']['edgeDefinitions'].should eq([]) + end + + it "can add an additional orphan collection" do + first_def = { "collection" => friend_collection, "from" => [user_collection], "to" => [user_collection] } + edge_definition = [first_def] + create_graph( graph_name, edge_definition ) + doc = additional_vertex_collection( graph_name, product_collection ) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['graph']['name'].should eq(graph_name) + doc.parsed_response['graph']['_rev'].should eq(doc.headers['etag']) + doc.parsed_response['graph']['edgeDefinitions'].should eq(edge_definition) + doc.parsed_response['graph']['orphanCollections'].should eq([product_collection]) + end + + it "can delete an orphan collection" do + first_def = { "collection" => friend_collection, "from" => [user_collection], "to" => [user_collection] } + edge_definition = [first_def] + create_graph( graph_name, edge_definition ) + additional_vertex_collection( graph_name, product_collection ) + doc = delete_vertex_collection( graph_name, product_collection ) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['graph']['name'].should eq(graph_name) + doc.parsed_response['graph']['_rev'].should eq(doc.headers['etag']) + doc.parsed_response['graph']['edgeDefinitions'].should eq(edge_definition) + doc.parsed_response['graph']['orphanCollections'].should eq([]) end it "can delete a graph again" do diff --git a/js/apps/system/aardvark/frontend/js/modules/org/arangodb/general-graph.js b/js/apps/system/aardvark/frontend/js/modules/org/arangodb/general-graph.js index 9ca319f715..39c005ef33 100644 --- a/js/apps/system/aardvark/frontend/js/modules/org/arangodb/general-graph.js +++ b/js/apps/system/aardvark/frontend/js/modules/org/arangodb/general-graph.js @@ -120,6 +120,22 @@ var findOrCreateCollectionsByEdgeDefinitions = function (edgeDefinitions, noCrea ]; }; +//////////////////////////////////////////////////////////////////////////////// +/// @brief find or create a collection by name +//////////////////////////////////////////////////////////////////////////////// + +var findOrCreateOrphanCollections = function (graphName, orphanCollections, noCreate) { + var returnVals = []; + if (!orphanCollections) { + orphanCollections = []; + } + orphanCollections.forEach(function (e) { + findOrCreateCollectionByName(e, ArangoCollection.TYPE_DOCUMENT, noCreate); + returnVals.push(db[e]); + }); + return returnVals; +}; + //////////////////////////////////////////////////////////////////////////////// /// @brief internal function to get graphs collection //////////////////////////////////////////////////////////////////////////////// @@ -1387,6 +1403,15 @@ var _directedRelationDefinition = function ( }; }; +//////////////////////////////////////////////////////////////////////////////// +/// @brief create a list of all graph names +//////////////////////////////////////////////////////////////////////////////// + +var _list = function() { + var gdb = getGraphCollection(); + return _.pluck(gdb.toArray(), "_key"); +}; + //////////////////////////////////////////////////////////////////////////////// /// @brief create a list of edge definitions //////////////////////////////////////////////////////////////////////////////// @@ -1425,8 +1450,11 @@ var _extendEdgeDefinitions = function (edgeDefinition) { //////////////////////////////////////////////////////////////////////////////// -var _create = function (graphName, edgeDefinitions) { +var _create = function (graphName, edgeDefinitions, orphanCollections) { + if (!orphanCollections) { + orphanCollections = []; + } var gdb = getGraphCollection(), err, graphAlreadyExists = true, @@ -1497,13 +1525,18 @@ var _create = function (graphName, edgeDefinitions) { } collections = findOrCreateCollectionsByEdgeDefinitions(edgeDefinitions, false); + orphanCollections.forEach( + function(oC) { + findOrCreateCollectionByName(oC, ArangoCollection.TYPE_DOCUMENT); + } + ); gdb.save({ 'edgeDefinitions' : edgeDefinitions, '_key' : graphName }); - return new Graph(graphName, edgeDefinitions, collections[0], collections[1]); + return new Graph(graphName, edgeDefinitions, collections[0], collections[1], orphanCollections); }; @@ -1701,7 +1734,10 @@ var createHiddenProperty = function(obj, name, value) { /// @endDocuBlock /// //////////////////////////////////////////////////////////////////////////////// -var Graph = function(graphName, edgeDefinitions, vertexCollections, edgeCollections) { +var Graph = function(graphName, edgeDefinitions, vertexCollections, edgeCollections, orphanCollections) { + if (!orphanCollections) { + orphanCollections = []; + } var self = this; // Create Hidden Properties createHiddenProperty(this, "__name", graphName); @@ -1710,7 +1746,7 @@ var Graph = function(graphName, edgeDefinitions, vertexCollections, edgeCollecti createHiddenProperty(this, "__edgeDefinitions", edgeDefinitions); createHiddenProperty(this, "__idsToRemove", []); createHiddenProperty(this, "__collectionsToLock", []); - createHiddenProperty(this, "__orphanCollections", []); + createHiddenProperty(this, "__orphanCollections", orphanCollections); // fills this.__idsToRemove and this.__collectionsToLock var removeEdge = function (edgeId, options) { @@ -1903,7 +1939,7 @@ var Graph = function(graphName, edgeDefinitions, vertexCollections, edgeCollecti var _graph = function(graphName) { var gdb = getGraphCollection(), - g, collections; + g, collections, orphanCollections; try { g = gdb.document(graphName); @@ -1919,8 +1955,12 @@ var _graph = function(graphName) { } collections = findOrCreateCollectionsByEdgeDefinitions(g.edgeDefinitions, true); + orphanCollections = g.orphanCollections; + if (!orphanCollections) { + orphanCollections = []; + } - return new Graph(graphName, g.edgeDefinitions, collections[0], collections[1]); + return new Graph(graphName, g.edgeDefinitions, collections[0], collections[1], orphanCollections); }; //////////////////////////////////////////////////////////////////////////////// @@ -2033,7 +2073,11 @@ Graph.prototype._edgeCollections = function() { //////////////////////////////////////////////////////////////////////////////// Graph.prototype._vertexCollections = function() { - return _.values(this.__vertexCollections); + var orphans = []; + _.each(this.__orphanCollections, function(o) { + orphans.push(db[o]); + }); + return _.union(_.values(this.__vertexCollections), orphans); }; //////////////////////////////////////////////////////////////////////////////// @@ -2483,6 +2527,12 @@ Graph.prototype._extendEdgeDefinitions = function(edgeDefinition) { this.__edgeCollections[edgeDefinition.collection] = db[edgeDefinition.collection]; edgeDefinition.from.forEach( function(vc) { + //remove from __orphanCollections + var orphanIndex = self.__orphanCollections.indexOf(vc); + if (orphanIndex !== -1) { + self.__orphanCollections.splice(orphanIndex, 1); + } + //push into __vertexCollections if (self.__vertexCollections[vc] === undefined) { self.__vertexCollections[vc] = db[vc]; } @@ -2490,6 +2540,12 @@ Graph.prototype._extendEdgeDefinitions = function(edgeDefinition) { ); edgeDefinition.to.forEach( function(vc) { + //remove from __orphanCollections + var orphanIndex = self.__orphanCollections.indexOf(vc); + if (orphanIndex !== -1) { + self.__orphanCollections.splice(orphanIndex, 1); + } + //push into __vertexCollections if (self.__vertexCollections[vc] === undefined) { self.__vertexCollections[vc] = db[vc]; } @@ -2529,6 +2585,8 @@ Graph.prototype._editEdgeDefinitions = function(edgeDefinition, dropCollections) var self = this; var dropCandidates; var currentEdgeDefinition = {}; + var exOrphanCandidates = []; + var effectedGraphs = []; //check, if in graphs edge definition @@ -2552,6 +2610,7 @@ Graph.prototype._editEdgeDefinitions = function(edgeDefinition, dropCollections) eDs[id].from = edgeDefinition.from; eDs[id].to = edgeDefinition.to; db._graphs.update(graph._key, {edgeDefinitions: eDs}); + effectedGraphs.push(graph._key); if (graph._key === self.__name) { self.__edgeDefinitions[id].from = edgeDefinition.from; self.__edgeDefinitions[id].to = edgeDefinition.to; @@ -2584,11 +2643,11 @@ Graph.prototype._editEdgeDefinitions = function(edgeDefinition, dropCollections) ); } - //push "new" collections into vertexCollections edgeDefinition.from.forEach( function(vc) { if (self.__vertexCollections[vc] === undefined) { + exOrphanCandidates.push(vc); self.__vertexCollections[vc] = db[vc]; } } @@ -2596,6 +2655,7 @@ Graph.prototype._editEdgeDefinitions = function(edgeDefinition, dropCollections) edgeDefinition.to.forEach( function(vc) { if (self.__vertexCollections[vc] === undefined) { + exOrphanCandidates.push(vc); self.__vertexCollections[vc] = db[vc]; } } @@ -2622,6 +2682,26 @@ Graph.prototype._editEdgeDefinitions = function(edgeDefinition, dropCollections) } ); + //orphans treatment + effectedGraphs.forEach( + function(gN) { + var g; + if (gN === self.__name) { + g = self; + } else { + g = _graph(gN); + } + var orphans = g._getOrphanCollections(); + exOrphanCandidates.forEach( + function(eOC) { + if (orphans.indexOf(eOC) !== -1) { + g._removeOrphanCollection(eOC); + } + } + ); + } + ); + }; @@ -2813,6 +2893,7 @@ Graph.prototype._removeOrphanCollection = function(orphanCollectionName, dropCol throw err; } this.__orphanCollections.splice(index, 1); + db._graphs.update(this.__name, {orphanCollections: this.__orphanCollections}); if (dropCollection !== false) { var graphs = getGraphCollection().toArray(); @@ -2851,6 +2932,7 @@ exports._extendEdgeDefinitions = _extendEdgeDefinitions; exports._create = _create; exports._drop = _drop; exports._exists = _exists; +exports._list = _list; // ----------------------------------------------------------------------------- // --SECTION-- END-OF-FILE diff --git a/js/apps/system/gharial/gharial.js b/js/apps/system/gharial/gharial.js index d46ff2342f..4988071323 100644 --- a/js/apps/system/gharial/gharial.js +++ b/js/apps/system/gharial/gharial.js @@ -36,11 +36,11 @@ actions = require("org/arangodb/actions"), Model = require("org/arangodb/foxx").Model, Graph = require("org/arangodb/general-graph"), + _ = require("underscore"), errors = require("internal").errors, toId = function(c, k) { return c + "/" + k; }, - _ = require("underscore"), setResponse = function (res, name, body, code) { var obj = {}; obj.error = false; @@ -60,10 +60,272 @@ code = code || actions.HTTP_OK; setResponse(res, "graph", { name: g.__name, - edgeDefinitions: g.__edgeDefinitions + edgeDefinitions: g.__edgeDefinitions, + orphanCollections: g._getOrphanCollections() }, code); }; +////////////////////// Graph Creation ///////////////////////////////// + + /** List graphs + * + * Creates a list of all available graphs. + */ + controller.get("/", function(req, res) { + setResponse(res, "graphs", Graph._list()); + }); + + /** Creates a new graph + * + * Creates a new graph object + */ + controller.post("/", function(req, res) { + var infos = req.params("graph"); + var g = Graph._create(infos.get("name"), infos.get("edgeDefinitions")); + setGraphResponse(res, g, actions.HTTP_CREATED); + }).errorResponse( + ArangoError, actions.HTTP_CONFLICT, "Graph creation error.", function(e) { + return { + code: actions.HTTP_CONFLICT, + error: e.errorMessage + }; + } + ).bodyParam("graph", "The required information for a graph", Model); + + /** Drops an existing graph + * + * Drops an existing graph object by name. + * By default all collections not used by other graphs will be dropped as + * well. It can be optionally configured to not drop the collections. + */ + controller.del("/:graph", function(req, res) { + var name = req.params("graph"); + Graph._drop(name); + setResponse(res); + }) + .pathParam("graph", { + type: "string", + description: "Name of the graph." + }) + .errorResponse( + ArangoError, actions.HTTP_NOT_FOUND, "The graph does not exist.", function(e) { + return { + code: actions.HTTP_NOT_FOUND, + error: e.errorMessage + }; + } + ); + +/////////////////////// Definitions //////////////////////////////////// + + /** List all vertex collections. + * + * Gets the list of all vertex collections. + */ + controller.get("/:graph/vertex", function(req, res) { + var name = req.params("graph"); + var g = Graph._graph(name); + setResponse(res, "collections", _.map(g._vertexCollections(), function(c) { + return c.name(); + })); + }) + .pathParam("graph", { + type: "string", + description: "Name of the graph." + }) + .errorResponse( + ArangoError, actions.HTTP_NOT_FOUND, "The graph could not be found.", function(e) { + return { + code: actions.HTTP_NOT_FOUND, + error: e.errorMessage + }; + } + ); + + /** Create a new vertex collection. + * + * Stores a new vertex collection. + * This has to contain the vertex-collection name. + */ + controller.post("/:graph/vertex", function(req, res) { + var name = req.params("graph"); + var body = req.params("collection"); + var g = Graph._graph(name); + g._addOrphanCollection(body.get("collection")); + setGraphResponse(res, g); + }) + .pathParam("graph", { + type: "string", + description: "Name of the graph." + }) + .bodyParam( + "collection", "The vertex collection to be stored.", Model + ) + .errorResponse( + ArangoError, actions.HTTP_BAD, "The vertex collection is invalid.", function(e) { + return { + code: actions.HTTP_BAD, + error: e.errorMessage + }; + } + ); + + /** Delete a vertex collection. + * + * Removes a vertex collection from this graph. + * If this collection is used in one or more edge definitions + * All data stored in the collection is dropped as well as long + * as it is not used in other graphs. + */ + controller.del("/:graph/vertex/:collection", function(req, res) { + var name = req.params("graph"); + var def_name = req.params("collection"); + var g = Graph._graph(name); + g._removeOrphanCollection(def_name); + setGraphResponse(res, g); + }) + .pathParam("graph", { + type: "string", + description: "Name of the graph." + }) + .pathParam("collection", { + type: "string", + description: "Name of the vertex collection." + }) + .errorResponse( + ArangoError, actions.HTTP_NOT_FOUND, + "The collection is not found or part of an edge definition." + ); + + /** List all edge collections. + * + * Get the list of all edge collection. + */ + controller.get("/:graph/edge", function(req, res) { + var name = req.params("graph"); + var g = Graph._graph(name); + setResponse(res, "collections", _.map(g._edgeCollections(), function(c) { + return c.name(); + })); + }) + .pathParam("graph", { + type: "string", + description: "Name of the graph." + }) + .errorResponse( + ArangoError, actions.HTTP_NOT_FOUND, "The graph could not be found.", function(e) { + return { + code: actions.HTTP_NOT_FOUND, + error: e.errorMessage + }; + } + ); + + /** Create a new edge definition. + * + * Stores a new edge definition with the information contained + * within the body. + * This has to contain the edge-collection name, as well as set of from and to + * collections-names respectively. + */ + controller.post("/:graph/edge", function(req, res) { + var name = req.params("graph"); + var body = req.params("edgeDefinition"); + var g = Graph._graph(name); + g._extendEdgeDefinitions(body.forDB()); + setGraphResponse(res, g); + }) + .pathParam("graph", { + type: "string", + description: "Name of the graph." + }) + .bodyParam( + "edgeDefinition", "The edge definition to be stored.", Model + ) + .errorResponse( + ArangoError, actions.HTTP_BAD, "The edge definition is invalid.", function(e) { + return { + code: actions.HTTP_BAD, + error: e.errorMessage + }; + } + ); + + /** Replace an edge definition. + * + * Replaces an existing edge definition with the information contained + * within the body. + * This has to contain the edge-collection name, as well as set of from and to + * collections-names respectively. + * This will also change the edge definitions of all other graphs using this + * definition as well. + */ + controller.put("/:graph/edge/:definition", function(req, res) { + var name = req.params("graph"); + var def_name = req.params("definition"); + var body = req.params("edgeDefinition"); + var g = Graph._graph(name); + if (def_name !== body.get("collection")) { + var err = new ArangoError(); + err.errorNum = errors.ERROR_GRAPH_EDGE_COLLECTION_NOT_USED.code; + err.errorMessage = errors.ERROR_GRAPH_EDGE_COLLECTION_NOT_USED.message; + throw err; + } + g._editEdgeDefinitions(body.forDB()); + setGraphResponse(res, g); + }) + .pathParam("graph", { + type: "string", + description: "Name of the graph." + }) + .pathParam("definition", { + type: "string", + description: "Name of the edge collection in the definition." + }) + .bodyParam( + "edgeDefinition", "The edge definition to be stored.", Model + ) + .errorResponse( + ArangoError, actions.HTTP_BAD, "The edge definition is invalid.", function(e) { + return { + code: actions.HTTP_BAD, + error: e.errorMessage + }; + } + ); + + /** Delete an edge definition. + * + * Removes an existing edge definition from this graph. + * All data stored in the collections is dropped as well as long + * as it is not used in other graphs. + */ + controller.del("/:graph/edge/:definition", function(req, res) { + var name = req.params("graph"); + var def_name = req.params("definition"); + var g = Graph._graph(name); + g._deleteEdgeDefinition(def_name); + setGraphResponse(res, g); + }) + .pathParam("graph", { + type: "string", + description: "Name of the graph." + }) + .pathParam("definition", { + type: "string", + description: "Name of the edge collection in the definition." + }) + .errorResponse( + ArangoError, actions.HTTP_NOT_FOUND, "The edge definition is invalid.", function(e) { + return { + code: actions.HTTP_NOT_FOUND, + error: e.errorMessage + }; + } + ); + +////////////////////// Vertex Operations ///////////////////////////////// + /** Create a new vertex. * * Stores a new vertex with the information contained @@ -229,76 +491,7 @@ } ); - ///////////////////////////////////////////////// Edges ////////// - - /** Create a new edge definition. - * - * Stores a new edge definition with the information contained - * within the body. - * This has to contain the edge-collection name, as well as set of from and to - * collections-names respectively. - */ - controller.post("/:graph/edge", function(req, res) { - var name = req.params("graph"); - var body = req.params("edgeDefinition"); - var g = Graph._graph(name); - g._extendEdgeDefinitions(body.forDB()); - setGraphResponse(res, g); - }) - .pathParam("graph", { - type: "string", - description: "Name of the graph." - }) - .bodyParam( - "edgeDefinition", "The edge definition to be stored.", Model - ) - .errorResponse( - ArangoError, actions.HTTP_BAD, "The edge definition is invalid.", function(e) { - return { - code: actions.HTTP_BAD, - error: e.errorMessage - }; - } - ); - - /** Replace an edge definition. - * - * Replaces an existing edge definition with the information contained - * within the body. - * This has to contain the edge-collection name, as well as set of from and to - * collections-names respectively. - * This will also change the edge definitions of all other graphs using this - * definition as well. - */ - controller.put("/:graph/edge/:definition", function(req, res) { - var name = req.params("graph"); - var def_name = req.params("definition"); - var body = req.params("edgeDefinition"); - var g = Graph._graph(name); - if (def_name !== body.get("collection")) { - var err = new ArangoError(); - err.errorNum = errors.ERROR_GRAPH_EDGE_COLLECTION_NOT_USED.code; - err.errorMessage = errors.ERROR_GRAPH_EDGE_COLLECTION_NOT_USED.message; - throw err; - } - g._editEdgeDefinitions(body.forDB()); - setGraphResponse(res, g); - }) - .pathParam("graph", { - type: "string", - description: "Name of the graph." - }) - .bodyParam( - "edgeDefinition", "The edge definition to be stored.", Model - ) - .errorResponse( - ArangoError, actions.HTTP_BAD, "The edge definition is invalid.", function(e) { - return { - code: actions.HTTP_BAD, - error: e.errorMessage - }; - } - ); +//////////////////////////// Edge Operations ////////////////////////// /** Create a new edge. * @@ -485,49 +678,6 @@ } ); -///////////////// GRAPH ///////////////////////////////// - - /** Creates a new graph - * - * Creates a new graph object - */ - controller.post("/", function(req, res) { - var infos = req.params("graph"); - var g = Graph._create(infos.get("name"), infos.get("edgeDefinitions")); - setGraphResponse(res, g, actions.HTTP_CREATED); - }).errorResponse( - ArangoError, actions.HTTP_CONFLICT, "Graph creation error.", function(e) { - return { - code: actions.HTTP_CONFLICT, - error: e.errorMessage - }; - } - ).bodyParam("graph", "The required information for a graph", Model); - - /** Drops an existing graph - * - * Drops an existing graph object by name. - * By default all collections not used by other graphs will be dropped as - * well. It can be optionally configured to not drop the collections. - */ - controller.del("/:graph", function(req, res) { - var name = req.params("graph"); - Graph._drop(name); - setResponse(res); - }) - .pathParam("graph", { - type: "string", - description: "Name of the graph." - }) - .errorResponse( - ArangoError, actions.HTTP_NOT_FOUND, "The graph does not exist.", function(e) { - return { - code: actions.HTTP_NOT_FOUND, - error: e.errorMessage - }; - } - ); - diff --git a/js/common/modules/org/arangodb/general-graph.js b/js/common/modules/org/arangodb/general-graph.js index e1483319d9..7dfe5e5016 100644 --- a/js/common/modules/org/arangodb/general-graph.js +++ b/js/common/modules/org/arangodb/general-graph.js @@ -1402,6 +1402,15 @@ var _directedRelationDefinition = function ( }; }; +//////////////////////////////////////////////////////////////////////////////// +/// @brief create a list of all graph names +//////////////////////////////////////////////////////////////////////////////// + +var _list = function() { + var gdb = getGraphCollection(); + return _.pluck(gdb.toArray(), "_key"); +}; + //////////////////////////////////////////////////////////////////////////////// /// @brief create a list of edge definitions //////////////////////////////////////////////////////////////////////////////// @@ -2063,7 +2072,11 @@ Graph.prototype._edgeCollections = function() { //////////////////////////////////////////////////////////////////////////////// Graph.prototype._vertexCollections = function() { - return _.values(this.__vertexCollections); + var orphans = []; + _.each(this.__orphanCollections, function(o) { + orphans.push(db[o]); + }); + return _.union(_.values(this.__vertexCollections), orphans); }; //////////////////////////////////////////////////////////////////////////////// @@ -2918,6 +2931,7 @@ exports._extendEdgeDefinitions = _extendEdgeDefinitions; exports._create = _create; exports._drop = _drop; exports._exists = _exists; +exports._list = _list; // ----------------------------------------------------------------------------- // --SECTION-- END-OF-FILE