1
0
Fork 0

Added functions to list all graphs and all vertex/edge collections of a specific graph to http-api

This commit is contained in:
Michael Hackstein 2014-06-13 15:11:59 +02:00
parent 8e9ffb5950
commit 7541149200
4 changed files with 432 additions and 129 deletions

View File

@ -47,6 +47,19 @@ def delete_edge_definition (graph_name, definition_name)
return doc return doc
end 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) def create_vertex (graph_name, collection, body)
cmd = vertex_endpoint(graph_name, collection) cmd = vertex_endpoint(graph_name, collection)
doc = ArangoDB.post(cmd, :body => JSON.dump(body)) 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['error'].should eq(false)
doc.parsed_response['code'].should eq(201) doc.parsed_response['code'].should eq(201)
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']['_rev'].should eq(doc.headers['etag'])
doc.parsed_response['graph']['edgeDefinitions'].should eq(edge_definition) doc.parsed_response['graph']['edgeDefinitions'].should eq(edge_definition)
end end
@ -166,7 +179,7 @@ describe ArangoDB do
doc.parsed_response['error'].should eq(false) doc.parsed_response['error'].should eq(false)
doc.parsed_response['code'].should eq(201) doc.parsed_response['code'].should eq(201)
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']['_rev'].should eq(doc.headers['etag'])
doc.parsed_response['graph']['edgeDefinitions'].should eq(edge_definition) doc.parsed_response['graph']['edgeDefinitions'].should eq(edge_definition)
end end
@ -181,7 +194,7 @@ describe ArangoDB do
doc.code.should eq(200) doc.code.should eq(200)
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(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']['_rev'].should eq(doc.headers['etag'])
doc.parsed_response['graph']['edgeDefinitions'].should eq(edge_definition) doc.parsed_response['graph']['edgeDefinitions'].should eq(edge_definition)
end end
@ -196,10 +209,54 @@ describe ArangoDB do
doc.code.should eq(200) doc.code.should eq(200)
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(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']['_rev'].should eq(doc.headers['etag'])
doc.parsed_response['graph']['edgeDefinitions'].should eq(edge_definition) 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 end
it "can delete a graph again" do it "can delete a graph again" do

View File

@ -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 /// @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 /// @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(), var gdb = getGraphCollection(),
err, err,
graphAlreadyExists = true, graphAlreadyExists = true,
@ -1497,13 +1525,18 @@ var _create = function (graphName, edgeDefinitions) {
} }
collections = findOrCreateCollectionsByEdgeDefinitions(edgeDefinitions, false); collections = findOrCreateCollectionsByEdgeDefinitions(edgeDefinitions, false);
orphanCollections.forEach(
function(oC) {
findOrCreateCollectionByName(oC, ArangoCollection.TYPE_DOCUMENT);
}
);
gdb.save({ gdb.save({
'edgeDefinitions' : edgeDefinitions, 'edgeDefinitions' : edgeDefinitions,
'_key' : graphName '_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 /// @endDocuBlock
/// ///
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
var Graph = function(graphName, edgeDefinitions, vertexCollections, edgeCollections) { var Graph = function(graphName, edgeDefinitions, vertexCollections, edgeCollections, orphanCollections) {
if (!orphanCollections) {
orphanCollections = [];
}
var self = this; var self = this;
// Create Hidden Properties // Create Hidden Properties
createHiddenProperty(this, "__name", graphName); createHiddenProperty(this, "__name", graphName);
@ -1710,7 +1746,7 @@ var Graph = function(graphName, edgeDefinitions, vertexCollections, edgeCollecti
createHiddenProperty(this, "__edgeDefinitions", edgeDefinitions); createHiddenProperty(this, "__edgeDefinitions", edgeDefinitions);
createHiddenProperty(this, "__idsToRemove", []); createHiddenProperty(this, "__idsToRemove", []);
createHiddenProperty(this, "__collectionsToLock", []); createHiddenProperty(this, "__collectionsToLock", []);
createHiddenProperty(this, "__orphanCollections", []); createHiddenProperty(this, "__orphanCollections", orphanCollections);
// fills this.__idsToRemove and this.__collectionsToLock // fills this.__idsToRemove and this.__collectionsToLock
var removeEdge = function (edgeId, options) { var removeEdge = function (edgeId, options) {
@ -1903,7 +1939,7 @@ var Graph = function(graphName, edgeDefinitions, vertexCollections, edgeCollecti
var _graph = function(graphName) { var _graph = function(graphName) {
var gdb = getGraphCollection(), var gdb = getGraphCollection(),
g, collections; g, collections, orphanCollections;
try { try {
g = gdb.document(graphName); g = gdb.document(graphName);
@ -1919,8 +1955,12 @@ var _graph = function(graphName) {
} }
collections = findOrCreateCollectionsByEdgeDefinitions(g.edgeDefinitions, true); 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() { 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]; this.__edgeCollections[edgeDefinition.collection] = db[edgeDefinition.collection];
edgeDefinition.from.forEach( edgeDefinition.from.forEach(
function(vc) { 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) { if (self.__vertexCollections[vc] === undefined) {
self.__vertexCollections[vc] = db[vc]; self.__vertexCollections[vc] = db[vc];
} }
@ -2490,6 +2540,12 @@ Graph.prototype._extendEdgeDefinitions = function(edgeDefinition) {
); );
edgeDefinition.to.forEach( edgeDefinition.to.forEach(
function(vc) { 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) { if (self.__vertexCollections[vc] === undefined) {
self.__vertexCollections[vc] = db[vc]; self.__vertexCollections[vc] = db[vc];
} }
@ -2529,6 +2585,8 @@ Graph.prototype._editEdgeDefinitions = function(edgeDefinition, dropCollections)
var self = this; var self = this;
var dropCandidates; var dropCandidates;
var currentEdgeDefinition = {}; var currentEdgeDefinition = {};
var exOrphanCandidates = [];
var effectedGraphs = [];
//check, if in graphs edge definition //check, if in graphs edge definition
@ -2552,6 +2610,7 @@ Graph.prototype._editEdgeDefinitions = function(edgeDefinition, dropCollections)
eDs[id].from = edgeDefinition.from; eDs[id].from = edgeDefinition.from;
eDs[id].to = edgeDefinition.to; eDs[id].to = edgeDefinition.to;
db._graphs.update(graph._key, {edgeDefinitions: eDs}); db._graphs.update(graph._key, {edgeDefinitions: eDs});
effectedGraphs.push(graph._key);
if (graph._key === self.__name) { if (graph._key === self.__name) {
self.__edgeDefinitions[id].from = edgeDefinition.from; self.__edgeDefinitions[id].from = edgeDefinition.from;
self.__edgeDefinitions[id].to = edgeDefinition.to; self.__edgeDefinitions[id].to = edgeDefinition.to;
@ -2584,11 +2643,11 @@ Graph.prototype._editEdgeDefinitions = function(edgeDefinition, dropCollections)
); );
} }
//push "new" collections into vertexCollections //push "new" collections into vertexCollections
edgeDefinition.from.forEach( edgeDefinition.from.forEach(
function(vc) { function(vc) {
if (self.__vertexCollections[vc] === undefined) { if (self.__vertexCollections[vc] === undefined) {
exOrphanCandidates.push(vc);
self.__vertexCollections[vc] = db[vc]; self.__vertexCollections[vc] = db[vc];
} }
} }
@ -2596,6 +2655,7 @@ Graph.prototype._editEdgeDefinitions = function(edgeDefinition, dropCollections)
edgeDefinition.to.forEach( edgeDefinition.to.forEach(
function(vc) { function(vc) {
if (self.__vertexCollections[vc] === undefined) { if (self.__vertexCollections[vc] === undefined) {
exOrphanCandidates.push(vc);
self.__vertexCollections[vc] = db[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; throw err;
} }
this.__orphanCollections.splice(index, 1); this.__orphanCollections.splice(index, 1);
db._graphs.update(this.__name, {orphanCollections: this.__orphanCollections});
if (dropCollection !== false) { if (dropCollection !== false) {
var graphs = getGraphCollection().toArray(); var graphs = getGraphCollection().toArray();
@ -2851,6 +2932,7 @@ exports._extendEdgeDefinitions = _extendEdgeDefinitions;
exports._create = _create; exports._create = _create;
exports._drop = _drop; exports._drop = _drop;
exports._exists = _exists; exports._exists = _exists;
exports._list = _list;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE // --SECTION-- END-OF-FILE

View File

@ -36,11 +36,11 @@
actions = require("org/arangodb/actions"), actions = require("org/arangodb/actions"),
Model = require("org/arangodb/foxx").Model, Model = require("org/arangodb/foxx").Model,
Graph = require("org/arangodb/general-graph"), Graph = require("org/arangodb/general-graph"),
_ = require("underscore"),
errors = require("internal").errors, errors = require("internal").errors,
toId = function(c, k) { toId = function(c, k) {
return c + "/" + k; return c + "/" + k;
}, },
_ = require("underscore"),
setResponse = function (res, name, body, code) { setResponse = function (res, name, body, code) {
var obj = {}; var obj = {};
obj.error = false; obj.error = false;
@ -60,10 +60,272 @@
code = code || actions.HTTP_OK; code = code || actions.HTTP_OK;
setResponse(res, "graph", { setResponse(res, "graph", {
name: g.__name, name: g.__name,
edgeDefinitions: g.__edgeDefinitions edgeDefinitions: g.__edgeDefinitions,
orphanCollections: g._getOrphanCollections()
}, code); }, 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. /** Create a new vertex.
* *
* Stores a new vertex with the information contained * Stores a new vertex with the information contained
@ -229,76 +491,7 @@
} }
); );
///////////////////////////////////////////////// Edges ////////// //////////////////////////// Edge Operations //////////////////////////
/** 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
};
}
);
/** Create a new edge. /** 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
};
}
);

View File

@ -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 /// @brief create a list of edge definitions
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -2063,7 +2072,11 @@ Graph.prototype._edgeCollections = function() {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Graph.prototype._vertexCollections = 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._create = _create;
exports._drop = _drop; exports._drop = _drop;
exports._exists = _exists; exports._exists = _exists;
exports._list = _list;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE // --SECTION-- END-OF-FILE