diff --git a/CHANGELOG b/CHANGELOG index d22b2ded8f..0648366984 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,15 @@ v1.5.0 (XXXX-XX-XX) ------------------- +* issue #751: Create database through API should return HTTP status code 201 + + By default, the server now returns HTTP 201 (created) when creating a new + database successfully. To keep compatibility with older ArangoDB versions, the + startup parameter `--server.default-api-compatibility` can be set to a value + of `10400` to indicate API compatibility with ArangoDB 1.4. The compatibility + can also be enforced by setting the `X-Arango-Version` HTTP header in a + client request to this API on a per-request basis. + * issue #748: add vertex filtering to AQL's TRAVERSAL[_TREE]() function * allow direct access from the `db` object to collections whose names start @@ -114,6 +123,9 @@ v1.5.0 (XXXX-XX-XX) result of .getIndexes() for each index. This is currently only implemented for hash indices and skiplist indices. +v1.4.8 (xxxx-xx-xx) +------------------- + v1.4.7 (2014-01-23) ------------------- diff --git a/UnitTests/HttpInterface/api-database-spec.rb b/UnitTests/HttpInterface/api-database-spec.rb index aa6332b292..d667d6590e 100644 --- a/UnitTests/HttpInterface/api-database-spec.rb +++ b/UnitTests/HttpInterface/api-database-spec.rb @@ -66,12 +66,34 @@ describe ArangoDB do after do ArangoDB.delete(api + "/#{name}") end + + it "creates a new database, old return code" do + body = "{\"name\" : \"#{name}\" }" + doc = ArangoDB.log_post("#{prefix}-create", api, :body => body, :headers => { "X-Arango-Version" => "1.4" }) + + doc.code.should eq(200) + doc.headers['content-type'].should eq("application/json; charset=utf-8") + response = doc.parsed_response + response["result"].should eq(true) + response["error"].should eq(false) + end + + it "creates a new database, new return code" do + body = "{\"name\" : \"#{name}\" }" + doc = ArangoDB.log_post("#{prefix}-create", api, :body => body, :headers => { "X-Arango-Version" => "1.5" }) + + doc.code.should eq(201) + doc.headers['content-type'].should eq("application/json; charset=utf-8") + response = doc.parsed_response + response["result"].should eq(true) + response["error"].should eq(false) + end it "creates a new database" do body = "{\"name\" : \"#{name}\" }" doc = ArangoDB.log_post("#{prefix}-create", api, :body => body) - doc.code.should eq(200) + doc.code.should eq(201) doc.headers['content-type'].should eq("application/json; charset=utf-8") response = doc.parsed_response response["result"].should eq(true) @@ -115,7 +137,7 @@ describe ArangoDB do body = "{\"name\" : \"#{name}\" }" doc = ArangoDB.log_post("#{prefix}-re-create", api, :body => body) - doc.code.should eq(200) + doc.code.should eq(201) doc.headers['content-type'].should eq("application/json; charset=utf-8") doc = ArangoDB.log_post("#{prefix}-post", api, :body => body) @@ -132,7 +154,7 @@ describe ArangoDB do body = "{\"name\" : \"#{name}\" }" doc = ArangoDB.log_post("#{prefix}-drop", api, :body => body) - doc.code.should eq(200) + doc.code.should eq(201) doc.headers['content-type'].should eq("application/json; charset=utf-8") doc = ArangoDB.log_delete("#{prefix}-drop", cmd) @@ -158,7 +180,7 @@ describe ArangoDB do body = "{\"name\" : \"#{name}\" }" doc = ArangoDB.log_post("#{prefix}-create-properties", api, :body => body) - doc.code.should eq(200) + doc.code.should eq(201) doc.headers['content-type'].should eq("application/json; charset=utf-8") response = doc.parsed_response response["result"].should eq(true) @@ -206,7 +228,7 @@ describe ArangoDB do body = "{\"name\" : \"#{name}\", \"users\": [ { \"username\": \"admin\", \"password\": \"secret\", \"extra\": { \"gender\": \"m\" } }, { \"username\": \"foxx\", \"active\": false } ] }" doc = ArangoDB.log_post("#{prefix}-create-users", api, :body => body) - doc.code.should eq(200) + doc.code.should eq(201) doc.headers['content-type'].should eq("application/json; charset=utf-8") response = doc.parsed_response response["result"].should eq(true) @@ -268,7 +290,7 @@ describe ArangoDB do body = "{\"name\" : \"#{name}\", \"users\": [ { \"username\": \"\" } ] }" doc = ArangoDB.log_post("#{prefix}-create-users-invalid", api, :body => body) - doc.code.should eq(200) + doc.code.should eq(201) doc.headers['content-type'].should eq("application/json; charset=utf-8") response = doc.parsed_response response["result"].should eq(true) @@ -305,7 +327,7 @@ describe ArangoDB do body = "{\"name\" : \"#{name}\" }" doc = ArangoDB.log_post("#{prefix}-check-system", api, :body => body) - doc.code.should eq(200) + doc.code.should eq(201) doc.headers['content-type'].should eq("application/json; charset=utf-8") response = doc.parsed_response response["result"].should eq(true) diff --git a/UnitTests/HttpInterface/api-graph-spec.rb b/UnitTests/HttpInterface/api-graph-spec.rb index e4700a080f..4adf271eb4 100644 --- a/UnitTests/HttpInterface/api-graph-spec.rb +++ b/UnitTests/HttpInterface/api-graph-spec.rb @@ -1424,6 +1424,27 @@ describe ArangoDB do doc.parsed_response['result'].count.should eq(4) end + it "checks list of vertices of a vertex with HAS and HAS_NOT compare" do + + cmd = "/_api/graph/#{graph_name}/vertices" + body = "{\"batchSize\" : 100, \"filter\" : { \"properties\" : [ { \"key\" : \"optional1\", \"compare\" : \"HAS\" } ] } }" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + doc.code.should eq(201) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(201) + doc.parsed_response['result'].count.should eq(4) + + + cmd = "/_api/graph/#{graph_name}/vertices" + body = "{\"batchSize\" : 100, \"filter\" : { \"properties\" : [ { \"key\" : \"optional1\", \"compare\" : \"HAS_NOT\" } ] } }" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + doc.code.should eq(201) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(201) + doc.parsed_response['result'].count.should eq(1) + + end + end ################################################################################ diff --git a/js/actions/api-database.js b/js/actions/api-database.js index 59c722f185..ec75ea390c 100644 --- a/js/actions/api-database.js +++ b/js/actions/api-database.js @@ -240,7 +240,7 @@ function get_api_database (req, res) { /// /// @RESTRETURNCODES /// -/// @RESTRETURNCODE{200} +/// @RESTRETURNCODE{201} /// is returned if the database was created successfully. /// /// @RESTRETURNCODE{400} @@ -272,7 +272,7 @@ function get_api_database (req, res) { /// var response = logCurlRequest('POST', url, JSON.stringify(data)); /// /// db._dropDatabase(name); -/// assert(response.code === 200); +/// assert(response.code === 201); /// /// logJsonResponse(response); /// @END_EXAMPLE_ARANGOSH_RUN @@ -306,7 +306,7 @@ function get_api_database (req, res) { /// var response = logCurlRequest('POST', url, JSON.stringify(data)); /// /// db._dropDatabase(name); -/// assert(response.code === 200); +/// assert(response.code === 201); /// /// logJsonResponse(response); /// @END_EXAMPLE_ARANGOSH_RUN @@ -374,7 +374,8 @@ function post_api_database (req, res) { var result = arangodb.db._createDatabase(json.name || "", options, users); - actions.resultOk(req, res, actions.HTTP_OK, { result : result }); + var returnCode = (req.compatibility <= 10400 ? actions.HTTP_OK : actions.HTTP_CREATED); + actions.resultOk(req, res, returnCode, { result : result }); } //////////////////////////////////////////////////////////////////////////////// diff --git a/js/actions/api-endpoint.js b/js/actions/api-endpoint.js index 3e774b4625..b999d3648e 100644 --- a/js/actions/api-endpoint.js +++ b/js/actions/api-endpoint.js @@ -30,9 +30,6 @@ var arangodb = require("org/arangodb"); var actions = require("org/arangodb/actions"); - -var db = arangodb.db; - var internal = require("internal"); // ----------------------------------------------------------------------------- diff --git a/js/actions/api-explain.js b/js/actions/api-explain.js index 16368629d2..b6432ec153 100644 --- a/js/actions/api-explain.js +++ b/js/actions/api-explain.js @@ -30,7 +30,6 @@ var actions = require("org/arangodb/actions"); -var ArangoError = require("org/arangodb").ArangoError; var ERRORS = require("internal").errors; var EXPLAIN = require("internal").AQL_EXPLAIN; diff --git a/js/actions/api-graph.js b/js/actions/api-graph.js index 8e768af373..15a15473c6 100644 --- a/js/actions/api-graph.js +++ b/js/actions/api-graph.js @@ -1046,6 +1046,18 @@ function process_property_compare (compare) { //////////////////////////////////////////////////////////////////////////////// function process_property_filter (data, num, property, collname) { + if (property.key !== undefined && property.compare === "HAS") { + if (data.filter === "") { data.filter = " FILTER"; } else { data.filter += " &&";} + data.filter += " HAS(" + collname + ", @key" + num.toString() + ") "; + data.bindVars["key" + num.toString()] = property.key; + return; + } + if (property.key !== undefined && property.compare === "HAS_NOT") { + if (data.filter === "") { data.filter = " FILTER"; } else { data.filter += " &&";} + data.filter += " !HAS(" + collname + ", @key" + num.toString() + ") "; + data.bindVars["key" + num.toString()] = property.key; + return; + } if (property.key !== undefined && property.value !== undefined) { if (data.filter === "") { data.filter = " FILTER"; } else { data.filter += " &&";} data.filter += " " + collname + "[@key" + num.toString() + "] " + diff --git a/js/actions/api-simple.js b/js/actions/api-simple.js index 72eec5ba18..fb20a633c0 100644 --- a/js/actions/api-simple.js +++ b/js/actions/api-simple.js @@ -29,7 +29,6 @@ //////////////////////////////////////////////////////////////////////////////// var actions = require("org/arangodb/actions"); -var simple = require("org/arangodb/simple-query"); var db = require("org/arangodb").db; var ERRORS = require("internal").errors; diff --git a/js/actions/api-structure.js b/js/actions/api-structure.js index fb5c95110b..2efe566eab 100644 --- a/js/actions/api-structure.js +++ b/js/actions/api-structure.js @@ -40,7 +40,6 @@ var console = require("console"); var actions = require("org/arangodb/actions"); var arangodb = require("org/arangodb"); var db = arangodb.db; -var ERRORS = arangodb.errors; var DEFAULT_KEY = "default"; var API = "_api/structure"; diff --git a/js/actions/api-system.js b/js/actions/api-system.js index b4bad15406..ecab39568a 100644 --- a/js/actions/api-system.js +++ b/js/actions/api-system.js @@ -30,9 +30,6 @@ var arangodb = require("org/arangodb"); var actions = require("org/arangodb/actions"); - -var db = arangodb.db; - var internal = require("internal"); var console = require("console"); diff --git a/js/actions/api-user.js b/js/actions/api-user.js index 31d01886c1..743cdaae42 100644 --- a/js/actions/api-user.js +++ b/js/actions/api-user.js @@ -32,8 +32,6 @@ var arangodb = require("org/arangodb"); var actions = require("org/arangodb/actions"); var users = require("org/arangodb/users"); -var ArangoError = arangodb.ArangoError; - // ----------------------------------------------------------------------------- // --SECTION-- private functions // ----------------------------------------------------------------------------- @@ -163,7 +161,7 @@ function post_api_user (req, res) { return; } - var result = users.save(json.username, json.passwd, json.active, json.extra); + users.save(json.username, json.passwd, json.active, json.extra); users.reload(); actions.resultOk(req, res, actions.HTTP_CREATED, { }); @@ -251,7 +249,7 @@ function put_api_user (req, res) { } try { - var result = users.replace(username, json.passwd, json.active, json.extra); + users.replace(username, json.passwd, json.active, json.extra); users.reload(); actions.resultOk(req, res, actions.HTTP_OK, { }); @@ -350,7 +348,7 @@ function patch_api_user (req, res) { } try { - var result = users.update(username, json.passwd, json.active, json.extra); + users.update(username, json.passwd, json.active, json.extra); users.reload(); actions.resultOk(req, res, actions.HTTP_OK, { }); } @@ -419,7 +417,7 @@ function delete_api_user (req, res) { var username = decodeURIComponent(req.suffix[0]); try { - var result = users.remove(username); + users.remove(username); users.reload(); actions.resultOk(req, res, actions.HTTP_ACCEPTED, { }); } diff --git a/js/actions/key-value.js b/js/actions/key-value.js index 57cd0b3020..e6258c797f 100644 --- a/js/actions/key-value.js +++ b/js/actions/key-value.js @@ -39,7 +39,6 @@ // ----------------------------------------------------------------------------- var actions = require("org/arangodb/actions"); -var simple = require("org/arangodb/simple-query"); var db = require("org/arangodb").db; var internal = require("internal"); var arangodb = require("org/arangodb"); diff --git a/js/apps/system/aardvark/frontend/js/views/dbSelectionView.js b/js/apps/system/aardvark/frontend/js/views/dbSelectionView.js index df9debf6ac..5ff1505ece 100644 --- a/js/apps/system/aardvark/frontend/js/views/dbSelectionView.js +++ b/js/apps/system/aardvark/frontend/js/views/dbSelectionView.js @@ -11,7 +11,6 @@ }, initialize: function(opts) { - var self = this; this.current = opts.current; this.collection.fetch({ async: false diff --git a/js/apps/system/aardvark/frontend/js/views/footerView.js b/js/apps/system/aardvark/frontend/js/views/footerView.js index 194d4c3c97..973c910fcd 100644 --- a/js/apps/system/aardvark/frontend/js/views/footerView.js +++ b/js/apps/system/aardvark/frontend/js/views/footerView.js @@ -94,7 +94,6 @@ }, renderVersion: function () { - var self = this; if (this.system.hasOwnProperty('database') && this.system.hasOwnProperty('name')) { $(this.el).html(this.template.render({ name: this.system.name, @@ -116,7 +115,6 @@ }, render: function () { - var self = this; if (!this.system.version) { this.getVersion(); } diff --git a/js/apps/system/aardvark/lib/swagger.js b/js/apps/system/aardvark/lib/swagger.js index 5aba5fd84e..a75f5fe843 100644 --- a/js/apps/system/aardvark/lib/swagger.js +++ b/js/apps/system/aardvark/lib/swagger.js @@ -31,9 +31,7 @@ exports.Swagger = function () { "use strict"; - // Define the Repository - var Foxx = require("org/arangodb/foxx"), - db = require("internal").db, + var db = require("internal").db, _routing = db._collection("_routing"), _aal = db._collection("_aal"), _ = require("underscore"), diff --git a/lib/ProgramOptions/program-options.c b/lib/ProgramOptions/program-options.c index 8bdfa465e9..15271f208b 100644 --- a/lib/ProgramOptions/program-options.c +++ b/lib/ProgramOptions/program-options.c @@ -187,18 +187,21 @@ static char * FillVariables (const char* value) { if (v == NULL) { if (TRI_EqualString(k, "ROOTDIR")) { char* vv = TRI_LocateInstallDirectory(); - size_t lv = strlen(vv); - if (0 < lv) { - if (vv[lv - 1] == TRI_DIR_SEPARATOR_CHAR || vv[lv - 1] == '/') { - v = TRI_DuplicateString2(vv, lv - 1); - } - else { - v = TRI_DuplicateString2(vv, lv); + if (vv != NULL) { + size_t lv = strlen(vv); + + if (0 < lv) { + if (vv[lv - 1] == TRI_DIR_SEPARATOR_CHAR || vv[lv - 1] == '/') { + v = TRI_DuplicateString2(vv, lv - 1); + } + else { + v = TRI_DuplicateString2(vv, lv); + } } + + TRI_FreeString(TRI_CORE_MEM_ZONE, vv); } - - TRI_FreeString(TRI_CORE_MEM_ZONE, vv); } } else {