1
0
Fork 0

Merge branch 'devel' of https://github.com/triAGENS/ArangoDB into devel

Conflicts:
	js/common/modules/org/arangodb/general-graph.js
This commit is contained in:
gschwab 2014-05-16 16:12:40 +02:00
commit 55c494c81d
3 changed files with 229 additions and 113 deletions

View File

@ -79,22 +79,36 @@
expect(col.loglevel).toEqual(1);
});
it("should check if last page is active", function() {
col.page = 1;
col.pagesize = 10;
col.totalAmount = 14;
col.totalPages = 2;
expect(col.url()).toEqual('/_admin/log?upto=1&size=4&offset=0');
});
it("should check if totalAmount is set", function() {
col.totalAmount = 0;
col.url();
});
it("url with upto", function() {
col.initialize({upto : true, loglevel : 1});
col.page = 1;
col.pagesize = 1;
col.page = 2;
col.pagesize = 2;
col.totalAmount = 10;
expect(col.url()).toEqual('/_admin/log?upto=1&size=1&offset=0');
expect(col.url()).toEqual('/_admin/log?upto=1&size=2&offset=4');
});
it("url with no upto", function() {
col.initialize({upto : false, loglevel : 1});
col.upto = false;
col.page = 1;
col.pagesize = 1;
col.page = 2;
col.pagesize = 2;
col.totalAmount = 10;
expect(col.url()).toEqual('/_admin/log?level=1&size=1&offset=0');
expect(col.url()).toEqual('/_admin/log?level=1&size=2&offset=4');
});
});

View File

@ -30,12 +30,11 @@
var arangodb = require("org/arangodb"),
ArangoCollection = arangodb.ArangoCollection,
db = arangodb.db,
ArangoCollection = arangodb.ArangoCollection,
db = arangodb.db,
_ = require("underscore");
// -----------------------------------------------------------------------------
// --SECTION-- module "org/arangodb/general-graph"
// -----------------------------------------------------------------------------
@ -50,10 +49,10 @@ var arangodb = require("org/arangodb"),
var stringToArray = function (x) {
if (typeof(x) === "string") {
return [x];
}
return x;
if (typeof(x) === "string") {
return [x];
}
return x;
};
////////////////////////////////////////////////////////////////////////////////
@ -63,16 +62,16 @@ var stringToArray = function (x) {
var isValidCollectionsParameter = function (x) {
if (!x) {
return false;
}
if (Array.isArray(x) && x.length === 0) {
return false;
}
if (typeof(x) !== "string" && !Array.isArray(x)) {
return false;
}
return true;
if (!x) {
return false;
}
if (Array.isArray(x) && x.length === 0) {
return false;
}
if (typeof(x) !== "string" && !Array.isArray(x)) {
return false;
}
return true;
};
////////////////////////////////////////////////////////////////////////////////
@ -80,20 +79,20 @@ var isValidCollectionsParameter = function (x) {
////////////////////////////////////////////////////////////////////////////////
var findOrCreateCollectionByName = function (name, type) {
var col = db._collection(name),res = false;
if (col === null) {
if (type === ArangoCollection.TYPE_DOCUMENT) {
col = db._create(name);
} else {
col = db._createEdgeCollection(name);
}
res = true;
} else if (!(col instanceof ArangoCollection) || col.type() !== type) {
throw "<" + name + "> must be a " +
(type === ArangoCollection.TYPE_DOCUMENT ? "document" : "edge")
+ " collection";
}
return res;
var col = db._collection(name),res = false;
if (col === null) {
if (type === ArangoCollection.TYPE_DOCUMENT) {
col = db._create(name);
} else {
col = db._createEdgeCollection(name);
}
res = true;
} else if (!(col instanceof ArangoCollection) || col.type() !== type) {
throw "<" + name + "> must be a " +
(type === ArangoCollection.TYPE_DOCUMENT ? "document" : "edge")
+ " collection";
}
return res;
};
// -----------------------------------------------------------------------------
@ -111,23 +110,23 @@ var findOrCreateCollectionByName = function (name, type) {
var _undirectedRelationDefinition = function (relationName, vertexCollections) {
if (arguments.length < 2) {
throw "method _undirectedRelationDefinition expects 2 arguments";
}
if (arguments.length < 2) {
throw "method _undirectedRelationDefinition expects 2 arguments";
}
if (typeof relationName !== "string" || relationName === "") {
throw "<relationName> must be a not empty string";
}
if (typeof relationName !== "string" || relationName === "") {
throw "<relationName> must be a not empty string";
}
if (!isValidCollectionsParameter(vertexCollections)) {
throw "<vertexCollections> must be a not empty string or array";
}
if (!isValidCollectionsParameter(vertexCollections)) {
throw "<vertexCollections> must be a not empty string or array";
}
return {
collection: "relationName",
from: stringToArray(vertexCollections),
to: stringToArray(vertexCollections)
};
return {
collection: "relationName",
from: stringToArray(vertexCollections),
to: stringToArray(vertexCollections)
};
};
@ -137,29 +136,29 @@ var _undirectedRelationDefinition = function (relationName, vertexCollections) {
var _directedRelationDefinition = function (
relationName, fromVertexCollections, toVertexCollections) {
relationName, fromVertexCollections, toVertexCollections) {
if (arguments.length < 3) {
throw "method _undirectedRelationDefinition expects 3 arguments";
}
if (arguments.length < 3) {
throw "method _undirectedRelationDefinition expects 3 arguments";
}
if (typeof relationName !== "string" || relationName === "") {
throw "<relationName> must be a not empty string";
}
if (typeof relationName !== "string" || relationName === "") {
throw "<relationName> must be a not empty string";
}
if (!isValidCollectionsParameter(fromVertexCollections)) {
throw "<fromVertexCollections> must be a not empty string or array";
}
if (!isValidCollectionsParameter(fromVertexCollections)) {
throw "<fromVertexCollections> must be a not empty string or array";
}
if (!isValidCollectionsParameter(toVertexCollections)) {
throw "<toVertexCollections> must be a not empty string or array";
}
if (!isValidCollectionsParameter(toVertexCollections)) {
throw "<toVertexCollections> must be a not empty string or array";
}
return {
collection: "relationName",
from: stringToArray(fromVertexCollections),
to: stringToArray(toVertexCollections)
};
return {
collection: "relationName",
from: stringToArray(fromVertexCollections),
to: stringToArray(toVertexCollections)
};
};
////////////////////////////////////////////////////////////////////////////////
@ -169,12 +168,12 @@ var _directedRelationDefinition = function (
var edgeDefinitions = function () {
var res = [], args = arguments;
Object.keys(args).forEach(function (x) {
res.push(args[x]);
});
var res = [], args = arguments;
Object.keys(args).forEach(function (x) {
res.push(args[x]);
});
return res;
return res;
};
@ -185,52 +184,51 @@ var edgeDefinitions = function () {
var _create = function (graphName, edgeDefinitions) {
var gdb = db._collection("_graphs"),
g,
graphAlreadyExists = true;
var gdb = db._collection("_graphs"),
g,
graphAlreadyExists = true;
if (gdb === null) {
throw "_graphs collection does not exist.";
}
if (gdb === null) {
throw "_graphs collection does not exist.";
}
if (!graphName) {
throw "a graph name is required to create a graph.";
}
if (!Array.isArray(edgeDefinitions) || edgeDefinitions.length === 0) {
throw "at least one edge definition is required to create a graph.";
}
if (!graphName) {
throw "a graph name is required to create a graph.";
}
if (!Array.isArray(edgeDefinitions) || edgeDefinitions.length === 0) {
throw "at least one edge definition is required to create a graph.";
}
try {
g = gdb.document(graphName);
} catch (e) {
if (e.errorNum !== 1202) {
throw e;
}
graphAlreadyExists = false;
}
try {
g = gdb.document(graphName);
} catch (e) {
if (e.errorNum !== 1202) {
throw e;
}
graphAlreadyExists = false;
}
if (graphAlreadyExists) {
throw "graph " + graphName + " already exists.";
}
if (graphAlreadyExists) {
throw "graph " + graphName + " already exists.";
}
var vertexCollections = {};
var edgeCollections = {};
edgeDefinitions.forEach(function (e) {
e.from.concat(e.to).forEach(function (v) {
findOrCreateCollectionByName(v, ArangoCollection.TYPE_DOCUMENT);
edgeDefinitions.forEach(function (e) {
e.from.concat(e.to).forEach(function (v) {
findOrCreateCollectionByName(v, ArangoCollection.TYPE_DOCUMENT);
vertexCollections[v] = db[v];
});
findOrCreateCollectionByName(e.collection, ArangoCollection.TYPE_EDGE);
findOrCreateCollectionByName(e.collection, ArangoCollection.TYPE_EDGE);
edgeCollections[e] = db[e];
});
});
gdb.save({
'edgeDefinitions' : edgeDefinitions,
'_key' : graphName
});
return new Graph(graphName, edgeDefinitions, vertexCollections, edgeCollections);
gdb.save({
'edgeDefinitions' : edgeDefinitions,
'_key' : graphName
});
return new Graph(graphName, edgeDefinitions, vertexCollections, edgeCollections);
};

View File

@ -24,7 +24,7 @@
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Florian Bartels
/// @author Florian Bartels, Michael Hackstein
/// @author Copyright 2014, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
@ -33,7 +33,7 @@ var jsunity = require("jsunity");
var arangodb = require("org/arangodb");
var console = require("console");
var graph = require("org/arangodb/general-graph")
var graph = require("org/arangodb/general-graph");
var print = arangodb.print;
@ -223,7 +223,6 @@ function GeneralGraphCreationSuite() {
}
/*test_create : function () {
@ -242,11 +241,115 @@ function GeneralGraphCreationSuite() {
}*/
}
};
}
// -----------------------------------------------------------------------------
// --SECTION-- Simple Queries
// -----------------------------------------------------------------------------
function GeneralGraphSimpleQueriesSuite() {
return {
////////////////////////////////////////////////////////////////////////////////
/// @brief test: restrict construct on edges
////////////////////////////////////////////////////////////////////////////////
test_restrictOnEdges: function() {
// Creation of a graph content
var inc = graph._directedRelationDefinition("included", ["v1"], ["v1", "v2"]);
var exc = graph._directedRelationDefinition("excluded", ["v1"], ["v3"]);
/*
var g = graph._create("graph", [inc, exc]);
var incEdge1 = g.included.save({
_from: "v1/1",
_to:"v2/1",
included: true
});
var incEdge2 = g.included.save({
_from: "v1/2",
_to:"v1/1",
included: true
});
var excEdge = g.excluded.save({
_from: "v1/1",
_to:"v3/1",
included: false
});
var result = g.edges().restrict("v1");
assertEqual(result.length, 2);
assertNotEqual(result.indexOf(incEdge1), -1);
assertNotEqual(result.indexOf(incEdge2), -1);
assertEqual(result.indexOf(excEdge), -1);
*/
},
test_restrictOnInEdges: function() {
// Creation of a graph content
var inc = graph._directedRelationDefinition("included", ["v1"], ["v1", "v2"]);
var exc = graph._directedRelationDefinition("excluded", ["v1"], ["v3"]);
/*
var g = graph._create("graph", [inc, exc]);
var excEdge1 = g.included.save({
_from: "v1/1",
_to:"v2/1",
included: true
});
var incEdge = g.included.save({
_from: "v1/2",
_to:"v1/1",
included: true
});
var excEdge2 = g.excluded.save({
_from: "v1/1",
_to:"v3/1",
included: false
});
var result = g.edges().restrict("v1");
assertEqual(result.length, 1);
assertEqual(result.indexOf(excEdge1), -1);
assertNotEqual(result.indexOf(incEdge), -1);
assertEqual(result.indexOf(excEdge2), -1);
*/
},
test_restrictOnOutEdges: function() {
// Creation of a graph content
var inc = graph._directedRelationDefinition("included", ["v1"], ["v1", "v2"]);
var exc = graph._directedRelationDefinition("excluded", ["v1"], ["v3"]);
/*
var g = graph._create("graph", [inc, exc]);
var incEdge = g.included.save({
_from: "v1/1",
_to:"v2/1",
included: true
});
var excEdge1 = g.included.save({
_from: "v1/2",
_to:"v1/1",
included: true
});
var excEdge2 = g.excluded.save({
_from: "v1/1",
_to:"v3/1",
included: false
});
var result = g.edges().restrict("v1");
assertEqual(result.length, 1);
assertNotEqual(result.indexOf(incEdge), -1);
assertEqual(result.indexOf(excEdge1), -1);
assertEqual(result.indexOf(excEdge2), -1);
*/
}
};
}
// -----------------------------------------------------------------------------
// --SECTION-- main
@ -257,6 +360,7 @@ function GeneralGraphCreationSuite() {
////////////////////////////////////////////////////////////////////////////////
jsunity.run(GeneralGraphCreationSuite);
jsunity.run(GeneralGraphSimpleQueriesSuite);
return jsunity.done();