diff --git a/UnitTests/HttpInterface/rest-update-document-spec.rb b/UnitTests/HttpInterface/rest-update-document-spec.rb index 63bcba5ea7..b7f0d57f03 100644 --- a/UnitTests/HttpInterface/rest-update-document-spec.rb +++ b/UnitTests/HttpInterface/rest-update-document-spec.rb @@ -128,6 +128,10 @@ describe ArangoDB do before do @cn = "UnitTestsCollectionBasics" @cid = ArangoDB.create_collection(@cn) + + cmd = "/_api/collection/#{@cid}/properties" + body = "{ \"waitForSync\" : true }" + doc = ArangoDB.put(cmd, :body => body) end after do @@ -152,7 +156,7 @@ describe ArangoDB do body = "{ \"World\" : \"Hallo\" }" doc = ArangoDB.log_put("#{prefix}", cmd, :body => body) - doc.code.should eq(200) + doc.code.should eq(201) doc.parsed_response['error'].should eq(false) doc.headers['content-type'].should eq("application/json; charset=utf-8") @@ -206,7 +210,7 @@ describe ArangoDB do body = "{ \"World\" : \"Hallo\" }" doc = ArangoDB.log_put("#{prefix}-if-match", cmd, :headers => hdr, :body => body) - doc.code.should eq(200) + doc.code.should eq(201) doc.headers['content-type'].should eq("application/json; charset=utf-8") doc.parsed_response['error'].should eq(false) @@ -218,6 +222,32 @@ describe ArangoDB do rev2.should be_kind_of(String) rev2.should_not eq(rev) + cmd = "/_api/collection/#{@cid}/properties" + body = "{ \"waitForSync\" : false }" + doc = ArangoDB.put(cmd, :body => body) + + # update document + cmd = "/_api/document/#{did}" + hdr = { "if-match" => "\"#{rev2}\"" } + body = "{ \"World\" : \"Hallo2\" }" + doc3 = ArangoDB.log_put("#{prefix}-if-match", cmd, :headers => hdr, :body => body) + + doc3.code.should eq(202) + doc3.headers['content-type'].should eq("application/json; charset=utf-8") + doc3.parsed_response['error'].should eq(false) + rev3 = doc3.parsed_response['_rev'] + + # update document + cmd = "/_api/document/#{did}?waitForSync=true" + hdr = { "if-match" => "\"#{rev3}\"" } + body = "{ \"World\" : \"Hallo3\" }" + doc4 = ArangoDB.log_put("#{prefix}-if-match", cmd, :headers => hdr, :body => body) + + doc4.code.should eq(201) + doc4.headers['content-type'].should eq("application/json; charset=utf-8") + doc4.parsed_response['error'].should eq(false) + rev4 = doc4.parsed_response['_rev'] + ArangoDB.delete(location) ArangoDB.size_collection(@cid).should eq(0) @@ -242,7 +272,7 @@ describe ArangoDB do body = "{ \"World\" : \"Hallo\" }" doc = ArangoDB.log_put("#{prefix}-if-match-other-last-write", cmd, :headers => hdr, :body => body) - doc.code.should eq(200) + doc.code.should eq(201) doc.headers['content-type'].should eq("application/json; charset=utf-8") doc.parsed_response['error'].should eq(false) @@ -275,7 +305,7 @@ describe ArangoDB do # update document, different revision cmd = "/_api/document/#{did}?rev=858976#{rev}" body = "{ \"World\" : \"Hallo\" }" - doc = ArangoDB.log_put("#{prefix}-rev-other", cmd, :body => body) + doc = ArangoDB.log_put("#{prefix}-rev-other", cmd, :body => body) doc.code.should eq(412) doc.parsed_response['error'].should eq(true) @@ -294,7 +324,7 @@ describe ArangoDB do body = "{ \"World\" : \"Hallo\" }" doc = ArangoDB.log_put("#{prefix}-rev", cmd, :body => body) - doc.code.should eq(200) + doc.code.should eq(201) doc.headers['content-type'].should eq("application/json; charset=utf-8") doc.parsed_response['error'].should eq(false) @@ -329,7 +359,7 @@ describe ArangoDB do body = "{ \"World\" : \"Hallo\" }" doc = ArangoDB.log_put("#{prefix}-rev-other-last-write", cmd, :body => body) - doc.code.should eq(200) + doc.code.should eq(201) doc.headers['content-type'].should eq("application/json; charset=utf-8") doc.parsed_response['error'].should eq(false) @@ -364,7 +394,7 @@ describe ArangoDB do body = "{ \"World\" : \"Hallo\" }" doc = ArangoDB.log_put("#{prefix}-sync-false", cmd, :body => body) - doc.code.should eq(200) + doc.code.should eq(201) doc.parsed_response['error'].should eq(false) doc.headers['content-type'].should eq("application/json; charset=utf-8") @@ -399,7 +429,7 @@ describe ArangoDB do body = "{ \"World\" : \"Hallo\" }" doc = ArangoDB.log_put("#{prefix}-sync-true", cmd, :body => body) - doc.code.should eq(200) + doc.code.should eq(201) doc.parsed_response['error'].should eq(false) doc.headers['content-type'].should eq("application/json; charset=utf-8") @@ -434,7 +464,7 @@ describe ArangoDB do body = "{ \"fox\" : \"Foxy\" }" doc = ArangoDB.log_patch("#{prefix}-patch", cmd, :body => body) - doc.code.should eq(200) + doc.code.should eq(201) doc.parsed_response['error'].should eq(false) doc.headers['content-type'].should eq("application/json; charset=utf-8") @@ -474,7 +504,7 @@ describe ArangoDB do body = "{ \"fox\" : \"Foxy\", \"Hallo\" : null }" doc = ArangoDB.log_patch("#{prefix}-patch", cmd, :body => body) - doc.code.should eq(200) + doc.code.should eq(201) doc.parsed_response['error'].should eq(false) doc.headers['content-type'].should eq("application/json; charset=utf-8") @@ -514,7 +544,7 @@ describe ArangoDB do body = "{ \"fox\" : \"Foxy\", \"Hallo\" : null }" doc = ArangoDB.log_patch("#{prefix}-patch", cmd, :body => body) - doc.code.should eq(200) + doc.code.should eq(201) doc.parsed_response['error'].should eq(false) doc.headers['content-type'].should eq("application/json; charset=utf-8") diff --git a/arangod/RestHandler/RestDocumentHandler.cpp b/arangod/RestHandler/RestDocumentHandler.cpp index e0b05475dd..a5294992e8 100644 --- a/arangod/RestHandler/RestDocumentHandler.cpp +++ b/arangod/RestHandler/RestDocumentHandler.cpp @@ -486,6 +486,22 @@ bool RestDocumentHandler::readDocument () { /// given etag. Otherwise a @LIT{HTTP 412} is returned. As an alternative /// you can supply the etag in an attribute @LIT{rev} in the URL. /// +/// @RESTRETURNCODES +/// +/// @RESTRETURNCODE{200} +/// is returned if the document was found +/// +/// @RESTRETURNCODE{404} +/// is returned if the document or collection was not found +/// +/// @RESTRETURNCODE{304} +/// is returned if the "If-None-Match" header is given and the document has +/// same version +/// +/// @RESTRETURNCODE{412} +/// is returned if a "If-Match" header or @LIT{rev} is given and the found +/// document has a different version +/// /// @EXAMPLES /// /// Use a document handle: @@ -748,8 +764,8 @@ bool RestDocumentHandler::checkDocument () { /// in the @LIT{rev} URL parameter above), ArangoDB will check that /// the revision id of the document found in the database is equal to the target /// revision id provided in the request. If there is a mismatch between the revision -/// id, then by default a @LIT{HTTP 409} conflict is returned and no replacement is -/// performed. ArangoDB will return an HTTP @LIT{412 precondition failed} response then. +/// id, then by default a @LIT{HTTP 412} conflict is returned and no replacement is +/// performed. /// /// The conditional update behavior can be overriden with the @FA{policy} URL parameter: /// @@ -763,6 +779,27 @@ bool RestDocumentHandler::checkDocument () { /// revision id found in the database does not match the target revision id specified /// in the request. You can use the @LIT{last} @FA{policy} to force replacements. /// +/// @RESTRETURNCODES +/// +/// @RESTRETURNCODE{201} +/// is returned if the document was created sucessfully and `waitForSync` was +/// `true`. +/// +/// @RESTRETURNCODE{202} +/// is returned if the document was created sucessfully and `waitForSync` was +/// `false`. +/// +/// @RESTRETURNCODE{400} +/// is returned if the body does not contain a valid JSON representation of a +/// document. The response body contains an error document in this case. +/// +/// @RESTRETURNCODE{404} +/// is returned if collection or the document was not found +/// +/// @RESTRETURNCODE{412} +/// is returned if a "If-Match" header or @LIT{rev} is given and the found +/// document has a different version +/// /// @EXAMPLES /// /// Using document handle: @@ -836,6 +873,27 @@ bool RestDocumentHandler::replaceDocument () { /// can use the @FA{policy} parameter. This is the same as when replacing /// documents (see replacing documents for details). /// +/// @RESTRETURNCODES +/// +/// @RESTRETURNCODE{201} +/// is returned if the document was created sucessfully and `waitForSync` was +/// `true`. +/// +/// @RESTRETURNCODE{202} +/// is returned if the document was created sucessfully and `waitForSync` was +/// `false`. +/// +/// @RESTRETURNCODE{400} +/// is returned if the body does not contain a valid JSON representation of a +/// document. The response body contains an error document in this case. +/// +/// @RESTRETURNCODE{404} +/// is returned if collection or the document was not found +/// +/// @RESTRETURNCODE{412} +/// is returned if a "If-Match" header or @LIT{rev} is given and the found +/// document has a different version +/// /// @EXAMPLES /// /// @verbinclude rest-patch-document @@ -971,7 +1029,12 @@ bool RestDocumentHandler::modifyDocument (bool isPatch) { } // generate result - generateUpdated(cid, (TRI_voc_key_t) key.c_str(), document._rid); + if (trx.synchronous()) { + generateCreated(cid, (TRI_voc_key_t) key.c_str(), document._rid); + } + else { + generateAccepted(cid, (TRI_voc_key_t) key.c_str(), document._rid); + } return true; } @@ -984,7 +1047,7 @@ bool RestDocumentHandler::modifyDocument (bool isPatch) { /// @REST{DELETE /_api/document/@FA{document-handle}} /// /// Deletes the document identified by @FA{document-handle}. If the document -/// exists and could be deleted, then a @LIT{HTTP 204} is returned. +/// exists and could be deleted, then a @LIT{HTTP 200} is returned. /// /// The body of the response contains a JSON object with the information about /// the handle and the revision. The attribute @LIT{_id} contains the known @@ -1011,6 +1074,24 @@ bool RestDocumentHandler::modifyDocument (bool isPatch) { /// synchronisation for collections that have a default @LIT{waitForSync} value /// of @LIT{true}. /// +/// @RESTRETURNCODES +/// +/// @RESTRETURNCODE{200} +/// is returned if the document was deleted sucessfully and `waitForSync` was +/// `true`. +/// +/// @RESTRETURNCODE{202} +/// is returned if the document was deleted sucessfully and `waitForSync` was +/// `false`. +/// +/// @RESTRETURNCODE{404} +/// is returned if the collection or the document was not found. +/// The response body contains an error document in this case. +/// +/// @RESTRETURNCODE{412} +/// is returned igf a "If-Match" header or @LIT{rev} is given and the current +/// document has a different version +/// /// @EXAMPLES /// /// Using document handle: @@ -1086,7 +1167,12 @@ bool RestDocumentHandler::deleteDocument () { return false; } - generateDeleted(cid, (TRI_voc_key_t) key.c_str(), rid); + if (trx.synchronous()) { + generateDeleted(cid, (TRI_voc_key_t) key.c_str(), rid); + } + else { + generateAccepted(cid, (TRI_voc_key_t) key.c_str(), rid); + } return true; }