mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'spdvpk' of github.com:arangodb/arangodb into spdvpk
This commit is contained in:
commit
5e860c14da
|
@ -0,0 +1,84 @@
|
|||
ArangoDB API changes for Version 3.0
|
||||
====================================
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
### Breaking changes to existing API:
|
||||
|
||||
1. Cap-constraints are withdrawn
|
||||
|
||||
2. first() and last() are withdrawn
|
||||
|
||||
<collection>.first() and <collection>.last() are withdrawn
|
||||
|
||||
3. Automatic creation of collections with first use
|
||||
|
||||
4. Pre Version 1.4 API compatibility withdrawn
|
||||
|
||||
5. Query-parameters "policy" and "rev" withdrawn in replace()/update()
|
||||
|
||||
6. /_api/edge withdrawn
|
||||
|
||||
### New capabilities:
|
||||
|
||||
1. Babies for document queries.
|
||||
|
||||
2. _from and _to in edges can be changed.
|
||||
|
||||
3. _key, _from, _to can be indexed like normal attributes.
|
||||
|
||||
Explanations
|
||||
------------
|
||||
|
||||
### Breaking changes
|
||||
|
||||
1. Cap-constraints are withdrawn
|
||||
|
||||
For 3.1 we plan to implement full MVCC and then at the latest it is
|
||||
no longer well-defined what a cap constraint means. Furthermore, in
|
||||
cluster mode it is really hard to implement as defined.
|
||||
|
||||
2. <collection>.first() and <collection>.last() are withdrawn
|
||||
|
||||
Harmonization between single server and cluster. Cluster
|
||||
implementation would be very difficult and inefficient. Even the
|
||||
single server implementation simplifies without this (one doubly
|
||||
linked list less) and saves memory.
|
||||
|
||||
3. Automatic creation of collections with first use
|
||||
|
||||
Never worked in cluster, harmonization between single server and
|
||||
cluster, In cluster would be undefined, since number of shards,
|
||||
shard keys, replication factor and replication quorum would not be
|
||||
specified.
|
||||
|
||||
4. Pre Version 1.4 API compatibility withdrawn
|
||||
|
||||
5. Query-parameters "policy" and "rev" withdrawn in PUT /_api/document/<id>
|
||||
|
||||
"policy" was non-sensical (just do not specify "rev")
|
||||
|
||||
6. /_api/edge withdrawn
|
||||
|
||||
Works now all over /_api/document
|
||||
This is much cleaner and one can use the new baby-capabilities for
|
||||
edges. Less code, drivers can be adjusted relatively easily by switching
|
||||
to /_api/document.
|
||||
|
||||
|
||||
### New capabilities:
|
||||
|
||||
1. Babies for document queries.
|
||||
|
||||
Higher performance, necessary for synchronous replication, good for
|
||||
clean API abstraction for transactions.
|
||||
|
||||
2. _from and _to in edges can be changed.
|
||||
|
||||
Comes with the VelocyPack change.
|
||||
|
||||
3. _key, _from, _to can be indexed like normal attributes.
|
||||
|
||||
Comes with the VelocyPack change.
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
# coding: utf-8
|
||||
|
||||
require 'rspec'
|
||||
require 'uri'
|
||||
require 'arangodb.rb'
|
||||
|
||||
describe ArangoDB do
|
||||
prefix = "rest-edge"
|
||||
|
||||
context "creating an edge:" do
|
||||
|
||||
################################################################################
|
||||
## error handling
|
||||
################################################################################
|
||||
|
||||
context "error handling:" do
|
||||
it "returns an error if url is missing from" do
|
||||
cn = "UnitTestsCollectionEdge"
|
||||
cmd = "/_api/edge?collection=#{cn}&createCollection=true"
|
||||
body = "{}"
|
||||
doc = ArangoDB.log_post("#{prefix}-missing-from-to", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(400)
|
||||
doc.parsed_response['error'].should eq(true)
|
||||
doc.parsed_response['errorNum'].should eq(400)
|
||||
doc.parsed_response['code'].should eq(400)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
ArangoDB.drop_collection(cn)
|
||||
end
|
||||
|
||||
it "returns an error if from/to are malformed" do
|
||||
cn = "UnitTestsCollectionEdge"
|
||||
cmd = "/_api/edge?collection=#{cn}&createCollection=true&from=1&to=1"
|
||||
body = "{}"
|
||||
doc = ArangoDB.log_post("#{prefix}-bad-from-to", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(400)
|
||||
doc.parsed_response['error'].should eq(true)
|
||||
doc.parsed_response['errorNum'].should eq(1205)
|
||||
doc.parsed_response['code'].should eq(400)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
ArangoDB.drop_collection(cn)
|
||||
end
|
||||
|
||||
it "returns an error if from/to are incomplete" do
|
||||
cn = "UnitTestsCollectionEdge"
|
||||
cmd = "/_api/edge?collection=#{cn}&createCollection=true&from=test&to=test"
|
||||
body = "{}"
|
||||
doc = ArangoDB.log_post("#{prefix}-incomplete-from-to", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(400)
|
||||
doc.parsed_response['error'].should eq(true)
|
||||
doc.parsed_response['errorNum'].should eq(1205)
|
||||
doc.parsed_response['code'].should eq(400)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
ArangoDB.drop_collection(cn)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -17,8 +17,8 @@ describe ArangoDB do
|
|||
it "returns an error if collection does not exist" do
|
||||
cn = "UnitTestsCollectionEdge"
|
||||
ArangoDB.drop_collection(cn)
|
||||
cmd = "/_api/edge?collection=#{cn}&from=test&to=test"
|
||||
body = "{}"
|
||||
cmd = "/_api/document?collection=#{cn}"
|
||||
body = "{\"_from\":\"test\",\"_to\":\"test\"}"
|
||||
doc = ArangoDB.log_post("#{prefix}-no-collection", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(404)
|
||||
|
@ -27,21 +27,6 @@ describe ArangoDB do
|
|||
doc.parsed_response['code'].should eq(404)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
end
|
||||
|
||||
it "returns an error if document handler is used to create an edge" do
|
||||
cn = "UnitTestsCollectionEdge"
|
||||
ArangoDB.drop_collection(cn)
|
||||
ArangoDB.create_collection(cn, true, 3) # type 3 = edge collection
|
||||
cmd = "/_api/document?collection=#{cn}&from=test&to=test"
|
||||
body = "{}"
|
||||
doc = ArangoDB.log_post("#{prefix}-wrong-type", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(400)
|
||||
doc.parsed_response['error'].should eq(true)
|
||||
doc.parsed_response['errorNum'].should eq(1218)
|
||||
doc.parsed_response['code'].should eq(400)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
end
|
||||
end
|
||||
|
||||
################################################################################
|
||||
|
@ -93,8 +78,8 @@ describe ArangoDB do
|
|||
id2 = doc.parsed_response['_id']
|
||||
|
||||
# create edge
|
||||
cmd = "/_api/edge?collection=#{@ce}&from=#{id1}&to=#{id2}"
|
||||
body = "{}"
|
||||
cmd = "/_api/document?collection=#{@ce}"
|
||||
body = "{ \"_from\" : \"#{id1}\" , \"_to\" : \"#{id2}\" }"
|
||||
doc = ArangoDB.log_post("#{prefix}-create-edge", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(201)
|
||||
|
@ -106,7 +91,7 @@ describe ArangoDB do
|
|||
id3 = doc.parsed_response['_id']
|
||||
|
||||
# check edge
|
||||
cmd = "/_api/edge/#{id3}"
|
||||
cmd = "/_api/document/#{id3}"
|
||||
doc = ArangoDB.log_get("#{prefix}-read-edge", cmd)
|
||||
|
||||
doc.code.should eq(200)
|
||||
|
@ -116,8 +101,8 @@ describe ArangoDB do
|
|||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
# create another edge
|
||||
cmd = "/_api/edge?collection=#{@ce}&from=#{id1}&to=#{id2}"
|
||||
body = "{ \"e\" : 1 }"
|
||||
cmd = "/_api/document?collection=#{@ce}"
|
||||
body = "{ \"e\" : 1, \"_from\" : \"#{id1}\", \"_to\" : \"#{id2}\" }"
|
||||
doc = ArangoDB.log_post("#{prefix}-create-edge", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(201)
|
||||
|
@ -127,7 +112,7 @@ describe ArangoDB do
|
|||
id4 = doc.parsed_response['_id']
|
||||
|
||||
# check edge
|
||||
cmd = "/_api/edge/#{id4}"
|
||||
cmd = "/_api/document/#{id4}"
|
||||
doc = ArangoDB.log_get("#{prefix}-read-edge", cmd)
|
||||
|
||||
doc.code.should eq(200)
|
||||
|
@ -144,8 +129,8 @@ describe ArangoDB do
|
|||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
# create third edge
|
||||
cmd = "/_api/edge?collection=#{@ce}&from=#{id2}&to=#{id1}"
|
||||
body = "{ \"e\" : 2 }"
|
||||
cmd = "/_api/document?collection=#{@ce}"
|
||||
body = "{ \"e\" : 2, \"_from\" : \"#{id2}\", \"_to\" : \"#{id1}\" }"
|
||||
doc = ArangoDB.log_post("#{prefix}-create-edge", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(201)
|
||||
|
@ -157,7 +142,7 @@ describe ArangoDB do
|
|||
id5 = doc.parsed_response['_id']
|
||||
|
||||
# check edge
|
||||
cmd = "/_api/edge/#{id5}"
|
||||
cmd = "/_api/document/#{id5}"
|
||||
doc = ArangoDB.log_get("#{prefix}-read-edge", cmd)
|
||||
|
||||
doc.code.should eq(200)
|
||||
|
@ -192,8 +177,8 @@ describe ArangoDB do
|
|||
translated = URI.escape(id.gsub /^\d+\//, 'UnitTestsCollectionVertex/')
|
||||
|
||||
# create edge, using collection id
|
||||
cmd = "/_api/edge?collection=#{@ce}&from=#{id}&to=#{id}"
|
||||
body = "{}"
|
||||
cmd = "/_api/document?collection=#{@ce}"
|
||||
body = "{ \"_from\" : \"#{id}\", \"_to\" : \"#{id}\" }"
|
||||
doc = ArangoDB.log_post("#{prefix}-create-edge-named", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(201)
|
||||
|
@ -203,8 +188,8 @@ describe ArangoDB do
|
|||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
# create edge, using collection names
|
||||
cmd = "/_api/edge?collection=#{@ce}&from=#{translated}&to=#{translated}"
|
||||
body = "{}"
|
||||
cmd = "/_api/document?collection=#{@ce}"
|
||||
body = "{ \"_from\" : \"#{translated}\", \"_to\" : \"#{translated}\" }"
|
||||
doc = ArangoDB.log_post("#{prefix}-create-edge-named", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(201)
|
||||
|
@ -214,8 +199,8 @@ describe ArangoDB do
|
|||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
# create edge, using mix of collection names and ids
|
||||
cmd = "/_api/edge?collection=#{@ce}&from=#{translated}&to=#{id}"
|
||||
body = "{}"
|
||||
cmd = "/_api/document?collection=#{@ce}"
|
||||
body = "{ \"_from\" : \"#{translated}\", \"_to\" : \"#{id}\" }"
|
||||
doc = ArangoDB.log_post("#{prefix}-create-edge-named", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(201)
|
||||
|
@ -225,8 +210,8 @@ describe ArangoDB do
|
|||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
# turn parameters around
|
||||
cmd = "/_api/edge?collection=#{@ce}&from=#{id}&to=#{translated}"
|
||||
body = "{}"
|
||||
cmd = "/_api/document?collection=#{@ce}"
|
||||
body = "{ \"_from\" : \"#{id}\", \"_to\" : \"#{translated}\" }"
|
||||
doc = ArangoDB.log_post("#{prefix}-create-edge-named", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(201)
|
||||
|
@ -236,32 +221,6 @@ describe ArangoDB do
|
|||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
end
|
||||
|
||||
it "using invalid collection names" do
|
||||
cmd = "/_api/document?collection=#{@cv}"
|
||||
|
||||
# create a vertex
|
||||
body = "{ \"a\" : 1 }"
|
||||
doc = ArangoDB.log_post("#{prefix}-create-edge-invalid-name", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(201)
|
||||
doc.parsed_response['_id'].should be_kind_of(String)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
from = URI.escape("thefox/12345")
|
||||
to = URI.escape("thefox/13443466")
|
||||
|
||||
# create edge, using invalid collection names
|
||||
cmd = "/_api/edge?collection=#{@ce}&from=#{from}&to=#{to}"
|
||||
body = "{}"
|
||||
doc = ArangoDB.log_post("#{prefix}-create-edge-invalid-name", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(404)
|
||||
doc.parsed_response['error'].should eq(true)
|
||||
doc.parsed_response['errorNum'].should eq(1203)
|
||||
doc.parsed_response['code'].should eq(404)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
end
|
||||
|
||||
it "using collection ids in collection, from and to" do
|
||||
cmd = "/_api/document?collection=#{@vid}"
|
||||
|
||||
|
@ -280,8 +239,8 @@ describe ArangoDB do
|
|||
translated = URI.escape(id.gsub /UnitTestsCollectionVertex/, @vid)
|
||||
|
||||
# create edge, using collection id
|
||||
cmd = "/_api/edge?collection=#{@eid}&from=#{id}&to=#{id}"
|
||||
body = "{}"
|
||||
cmd = "/_api/document?collection=#{@eid}"
|
||||
body = "{ \"_from\" : \"#{id}\", \"_to\" : \"#{id}\" }"
|
||||
doc = ArangoDB.log_post("#{prefix}-create-edge-named", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(201)
|
||||
|
@ -325,8 +284,8 @@ describe ArangoDB do
|
|||
id2 = doc.parsed_response['_id']
|
||||
|
||||
# create edge
|
||||
cmd = "/_api/edge?collection=#{@ce}&from=#{id1}&to=#{id2}"
|
||||
body = "{ \"what\" : \"fred->john\", \"_key\" : \"edge1\" }"
|
||||
cmd = "/_api/document?collection=#{@ce}"
|
||||
body = "{ \"_from\" : \"#{id1}\", \"_to\" : \"#{id2}\", \"what\" : \"fred->john\", \"_key\" : \"edge1\" }"
|
||||
doc = ArangoDB.log_post("#{prefix}-create-edge-key", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(201)
|
||||
|
@ -339,7 +298,7 @@ describe ArangoDB do
|
|||
id3 = doc.parsed_response['_id']
|
||||
|
||||
# check edge
|
||||
cmd = "/_api/edge/#{id3}"
|
||||
cmd = "/_api/document/#{id3}"
|
||||
doc = ArangoDB.log_get("#{prefix}-create-edge-key", cmd)
|
||||
|
||||
doc.code.should eq(200)
|
||||
|
@ -379,19 +338,19 @@ describe ArangoDB do
|
|||
id2 = doc.parsed_response['_id']
|
||||
|
||||
# create edge, 1st try
|
||||
cmd = "/_api/edge?collection=#{@ce}&from=#{@cv}/rak/ov&to=#{@cv}/pj/otr"
|
||||
body = "{ }"
|
||||
cmd = "/_api/document?collection=#{@ce}"
|
||||
body = "{ \"_from\" : \"#{@cv}/rak/ov\", \"_to\" : \"#{@cv}/pj/otr\" }"
|
||||
doc = ArangoDB.log_post("#{prefix}-create-edge-key-invalid", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(400)
|
||||
doc.parsed_response['error'].should eq(true)
|
||||
doc.parsed_response['errorNum'].should eq(1205)
|
||||
doc.parsed_response['errorNum'].should eq(1233)
|
||||
doc.parsed_response['code'].should eq(400)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
# create edge, 2nd try
|
||||
cmd = "/_api/edge?collection=#{@ce}&from=#{@cv}/rakov&to=#{@cv}/pjotr"
|
||||
body = "{ \"_key\" : \"the fox\" }"
|
||||
cmd = "/_api/document?collection=#{@ce}"
|
||||
body = "{ \"_from\" : \"#{@cv}/rakov\", \"_to\" : \"#{@cv}/pjotr\", \"_key\" : \"the fox\" }"
|
||||
doc = ArangoDB.log_post("#{prefix}-create-edge-key-invalid", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(400)
|
||||
|
@ -443,8 +402,8 @@ describe ArangoDB do
|
|||
id2 = doc.parsed_response['_id']
|
||||
|
||||
# create edge
|
||||
cmd = "/_api/edge?collection=#{@ce}&from=#{id1}&to=#{id2}&waitForSync=false"
|
||||
body = "{}"
|
||||
cmd = "/_api/document?collection=#{@ce}&waitForSync=false"
|
||||
body = "{ \"_from\" : \"#{id1}\", \"_to\" : \"#{id2}\" }"
|
||||
doc = ArangoDB.log_post("#{prefix}-create-edge", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(202)
|
||||
|
@ -454,7 +413,7 @@ describe ArangoDB do
|
|||
id3 = doc.parsed_response['_id']
|
||||
|
||||
# check edge
|
||||
cmd = "/_api/edge/#{id3}"
|
||||
cmd = "/_api/document/#{id3}"
|
||||
doc = ArangoDB.log_get("#{prefix}-read-edge", cmd)
|
||||
|
||||
doc.code.should eq(200)
|
||||
|
@ -487,8 +446,8 @@ describe ArangoDB do
|
|||
id2 = doc.parsed_response['_id']
|
||||
|
||||
# create edge
|
||||
cmd = "/_api/edge?collection=#{@ce}&from=#{id1}&to=#{id2}&waitForSync=true"
|
||||
body = "{}"
|
||||
cmd = "/_api/document?collection=#{@ce}&waitForSync=true"
|
||||
body = "{ \"_from\" : \"#{id1}\", \"_to\" : \"#{id2}\" }"
|
||||
doc = ArangoDB.log_post("#{prefix}-create-edge", cmd, :body => body)
|
||||
|
||||
doc.code.should eq(201)
|
||||
|
@ -498,7 +457,7 @@ describe ArangoDB do
|
|||
id3 = doc.parsed_response['_id']
|
||||
|
||||
# check edge
|
||||
cmd = "/_api/edge/#{id3}"
|
||||
cmd = "/_api/document/#{id3}"
|
||||
doc = ArangoDB.log_get("#{prefix}-read-edge", cmd)
|
||||
|
||||
doc.code.should eq(200)
|
||||
|
|
|
@ -185,7 +185,6 @@ add_executable(${BIN_ARANGOD}
|
|||
RestHandler/RestCursorHandler.cpp
|
||||
RestHandler/RestDebugHandler.cpp
|
||||
RestHandler/RestDocumentHandler.cpp
|
||||
RestHandler/RestEdgeHandler.cpp
|
||||
RestHandler/RestEdgesHandler.cpp
|
||||
RestHandler/RestExportHandler.cpp
|
||||
RestHandler/RestImportHandler.cpp
|
||||
|
|
|
@ -1,189 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany
|
||||
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RestEdgeHandler.h"
|
||||
#include "Rest/HttpRequest.h"
|
||||
#include "Utils/SingleCollectionTransaction.h"
|
||||
#include "Utils/StandaloneTransactionContext.h"
|
||||
#include "VocBase/document-collection.h"
|
||||
|
||||
using namespace arangodb;
|
||||
using namespace arangodb::basics;
|
||||
using namespace arangodb::rest;
|
||||
|
||||
RestEdgeHandler::RestEdgeHandler(HttpRequest* request)
|
||||
: RestDocumentHandler(request) {}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief was docuBlock API_EDGE_CREATE
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool RestEdgeHandler::createDocument() {
|
||||
std::vector<std::string> const& suffix = _request->suffix();
|
||||
|
||||
if (!suffix.empty()) {
|
||||
generateError(HttpResponse::BAD, TRI_ERROR_HTTP_SUPERFLUOUS_SUFFICES,
|
||||
"superfluous suffix, expecting " + EDGE_PATH +
|
||||
"?collection=<identifier>");
|
||||
return false;
|
||||
}
|
||||
|
||||
// extract the from
|
||||
bool found;
|
||||
char const* from = _request->value("from", found);
|
||||
if (!found || *from == '\0') {
|
||||
generateError(
|
||||
HttpResponse::BAD, TRI_ERROR_HTTP_BAD_PARAMETER,
|
||||
"'from' is missing, expecting " + EDGE_PATH +
|
||||
"?collection=<identifier>&from=<from-handle>&to=<to-handle>");
|
||||
return false;
|
||||
}
|
||||
|
||||
// extract the to
|
||||
char const* to = _request->value("to", found);
|
||||
|
||||
if (!found || *to == '\0') {
|
||||
generateError(
|
||||
HttpResponse::BAD, TRI_ERROR_HTTP_BAD_PARAMETER,
|
||||
"'to' is missing, expecting " + EDGE_PATH +
|
||||
"?collection=<identifier>&from=<from-handle>&to=<to-handle>");
|
||||
return false;
|
||||
}
|
||||
|
||||
// extract the cid
|
||||
std::string const collection = _request->value("collection", found);
|
||||
|
||||
if (!found || collection.empty()) {
|
||||
generateError(HttpResponse::BAD,
|
||||
TRI_ERROR_ARANGO_COLLECTION_PARAMETER_MISSING,
|
||||
"'collection' is missing, expecting " + DOCUMENT_PATH +
|
||||
"?collection=<identifier>");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* TODO
|
||||
if (!checkCreateCollection(collection, getCollectionType())) {
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
try {
|
||||
bool parseSuccess = true;
|
||||
// copy the default options
|
||||
VPackOptions options = VPackOptions::Defaults;
|
||||
options.keepTopLevelOpen = true; // We need to insert _from and _to
|
||||
std::shared_ptr<VPackBuilder> parsedBody =
|
||||
parseVelocyPackBody(&options, parseSuccess);
|
||||
|
||||
if (!parseSuccess) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parsedBody->isOpenObject()) {
|
||||
generateTransactionError(collection,
|
||||
TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID, "");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add _from and _to
|
||||
parsedBody->add(TRI_VOC_ATTRIBUTE_FROM, VPackValue(from));
|
||||
parsedBody->add(TRI_VOC_ATTRIBUTE_TO, VPackValue(to));
|
||||
|
||||
parsedBody->close();
|
||||
|
||||
VPackSlice body = parsedBody->slice();
|
||||
|
||||
// find and load collection given by name or identifier
|
||||
SingleCollectionTransaction trx(StandaloneTransactionContext::Create(_vocbase),
|
||||
collection, TRI_TRANSACTION_WRITE);
|
||||
|
||||
trx.addHint(TRI_TRANSACTION_HINT_SINGLE_OPERATION, false);
|
||||
|
||||
int res = trx.begin();
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
generateTransactionError(collection, res, "");
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO Test if is edge collection
|
||||
/*
|
||||
TRI_document_collection_t* document = trx.documentCollection();
|
||||
|
||||
if (document->_info.type() != TRI_COL_TYPE_EDGE) {
|
||||
// check if we are inserting with the EDGE handler into a non-EDGE
|
||||
// collection
|
||||
generateError(HttpResponse::BAD,
|
||||
TRI_ERROR_ARANGO_COLLECTION_TYPE_INVALID);
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
arangodb::OperationOptions opOptions;
|
||||
opOptions.waitForSync = extractWaitForSync();
|
||||
|
||||
|
||||
arangodb::OperationResult result = trx.insert(collection, body, opOptions);
|
||||
|
||||
|
||||
// Will commit if no error occured.
|
||||
// or abort if an error occured.
|
||||
// result stays valid!
|
||||
res = trx.finish(result.code);
|
||||
|
||||
if (result.failed()) {
|
||||
// TODO correct errors for _from or _to invalid.
|
||||
/* wrongPart is either from or to
|
||||
if (res == TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND) {
|
||||
generateError(HttpResponse::NOT_FOUND, res,
|
||||
wrongPart + " does not point to a valid collection");
|
||||
} else {
|
||||
generateError(HttpResponse::BAD, res,
|
||||
wrongPart + " is not a document handle");
|
||||
}
|
||||
*/
|
||||
generateTransactionError(collection, result.code, "");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
generateTransactionError(collection, res, "");
|
||||
return false;
|
||||
}
|
||||
|
||||
generateSaved(result, collection, TRI_COL_TYPE_EDGE);
|
||||
|
||||
return true;
|
||||
} catch (arangodb::basics::Exception const& ex) {
|
||||
generateError(HttpResponse::responseCode(ex.code()), ex.code(), ex.what());
|
||||
} catch (std::bad_alloc const&) {
|
||||
generateError(HttpResponse::SERVER_ERROR, TRI_ERROR_OUT_OF_MEMORY);
|
||||
} catch (std::exception const& ex) {
|
||||
generateError(HttpResponse::SERVER_ERROR, TRI_ERROR_INTERNAL, ex.what());
|
||||
} catch (...) {
|
||||
generateError(HttpResponse::SERVER_ERROR, TRI_ERROR_INTERNAL);
|
||||
}
|
||||
// Only in error case
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany
|
||||
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef ARANGOD_REST_HANDLER_REST_EDGE_HANDLER_H
|
||||
#define ARANGOD_REST_HANDLER_REST_EDGE_HANDLER_H 1
|
||||
|
||||
#include "Basics/Common.h"
|
||||
#include "RestHandler/RestDocumentHandler.h"
|
||||
|
||||
namespace arangodb {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief collection request handler
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class RestEdgeHandler : public RestDocumentHandler {
|
||||
public:
|
||||
explicit RestEdgeHandler(rest::HttpRequest*);
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get collection type
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TRI_col_type_e getCollectionType() const override final {
|
||||
return TRI_COL_TYPE_EDGE;
|
||||
}
|
||||
|
||||
private:
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief creates an edge
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool createDocument() override final;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -70,7 +70,6 @@
|
|||
#include "RestHandler/RestCursorHandler.h"
|
||||
#include "RestHandler/RestDebugHandler.h"
|
||||
#include "RestHandler/RestDocumentHandler.h"
|
||||
#include "RestHandler/RestEdgeHandler.h"
|
||||
#include "RestHandler/RestEdgesHandler.h"
|
||||
#include "RestHandler/RestExportHandler.h"
|
||||
#include "RestHandler/RestHandlerCreator.h"
|
||||
|
@ -729,10 +728,6 @@ void ArangoServer::defineHandlers(HttpHandlerFactory* factory) {
|
|||
RestVocbaseBaseHandler::DOCUMENT_PATH,
|
||||
RestHandlerCreator<RestDocumentHandler>::createNoData);
|
||||
|
||||
// add "/edge" handler
|
||||
factory->addPrefixHandler(RestVocbaseBaseHandler::EDGE_PATH,
|
||||
RestHandlerCreator<RestEdgeHandler>::createNoData);
|
||||
|
||||
// add "/edges" handler
|
||||
factory->addPrefixHandler(RestVocbaseBaseHandler::EDGES_PATH,
|
||||
RestHandlerCreator<RestEdgesHandler>::createNoData);
|
||||
|
|
|
@ -690,10 +690,6 @@ OperationResult Transaction::insert(std::string const& collectionName,
|
|||
if (!TRI_ValidateDocumentIdKeyGenerator(docId.c_str(), &split)) {
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_INVALID_EDGE_ATTRIBUTE);
|
||||
}
|
||||
std::string cName = docId.substr(0, split);
|
||||
if (TRI_COL_TYPE_UNKNOWN == resolver()->getCollectionType(cName)) {
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND);
|
||||
}
|
||||
};
|
||||
|
||||
// Check _to
|
||||
|
@ -707,10 +703,6 @@ OperationResult Transaction::insert(std::string const& collectionName,
|
|||
if (!TRI_ValidateDocumentIdKeyGenerator(docId.c_str(), &split)) {
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_INVALID_EDGE_ATTRIBUTE);
|
||||
}
|
||||
std::string cName = docId.substr(0, split);
|
||||
if (TRI_COL_TYPE_UNKNOWN == resolver()->getCollectionType(cName)) {
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND);
|
||||
}
|
||||
};
|
||||
|
||||
if (value.isArray()) {
|
||||
|
|
Loading…
Reference in New Issue