mirror of https://gitee.com/bigwinds/arangodb
less json
This commit is contained in:
parent
b209accf29
commit
66ee7e600d
|
@ -43,13 +43,16 @@ void RestBaseHandler::handleError(Exception const& ex) {
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief generates a result from JSON
|
||||
/// TODO: remove
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RestBaseHandler::generateResult(TRI_json_t const* json) {
|
||||
generateResult(HttpResponse::OK, json);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief generates a result from JSON
|
||||
/// TODO: remove
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RestBaseHandler::generateResult(HttpResponse::HttpResponseCode code,
|
||||
|
|
|
@ -57,6 +57,7 @@ class RestBaseHandler : public rest::HttpHandler {
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief generates a result from JSON
|
||||
/// TODO: remove
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual void generateResult(rest::HttpResponse::HttpResponseCode,
|
||||
|
@ -64,6 +65,7 @@ class RestBaseHandler : public rest::HttpHandler {
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief generates a result from VelocyPack
|
||||
/// TODO: remove
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual void generateResult(arangodb::velocypack::Slice const& slice);
|
||||
|
|
|
@ -22,13 +22,8 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RestEdgeHandler.h"
|
||||
#include "Basics/conversions.h"
|
||||
#include "Basics/VelocyPackHelper.h"
|
||||
#include "Cluster/ClusterMethods.h"
|
||||
#include "Cluster/ServerState.h"
|
||||
#include "Rest/HttpRequest.h"
|
||||
#include "VocBase/document-collection.h"
|
||||
#include "VocBase/edge-collection.h"
|
||||
|
||||
using namespace arangodb;
|
||||
using namespace arangodb::basics;
|
||||
|
@ -190,61 +185,3 @@ bool RestEdgeHandler::createDocument() {
|
|||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief creates a document (an edge), coordinator case in a cluster
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool RestEdgeHandler::createDocumentCoordinator(std::string const& collname,
|
||||
bool waitForSync,
|
||||
VPackSlice const& document,
|
||||
char const* from,
|
||||
char const* to) {
|
||||
std::string const& dbname = _request->databaseName();
|
||||
|
||||
arangodb::rest::HttpResponse::HttpResponseCode responseCode;
|
||||
std::map<std::string, std::string> resultHeaders;
|
||||
std::string resultBody;
|
||||
|
||||
std::unique_ptr<TRI_json_t> json(
|
||||
arangodb::basics::VelocyPackHelper::velocyPackToJson(document));
|
||||
int error = arangodb::createEdgeOnCoordinator(dbname, collname, waitForSync,
|
||||
json, from, to, responseCode,
|
||||
resultHeaders, resultBody);
|
||||
|
||||
if (error != TRI_ERROR_NO_ERROR) {
|
||||
generateTransactionError(collname, error, "");
|
||||
|
||||
return false;
|
||||
}
|
||||
// Essentially return the response we got from the DBserver, be it
|
||||
// OK or an error:
|
||||
createResponse(responseCode);
|
||||
arangodb::mergeResponseHeaders(_response, resultHeaders);
|
||||
_response->body().appendText(resultBody.c_str(), resultBody.size());
|
||||
|
||||
return responseCode >= arangodb::rest::HttpResponse::BAD;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief was docuBlock API_EDGE_READ
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief was docuBlock API_EDGE_READ_ALL
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief was docuBlock API_EDGE_READ_HEAD
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief was docuBlock API_EDGE_REPLACE
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief was docuBlock API_EDGE_UPDATES
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief was docuBlock API_EDGE_DELETE
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -53,13 +53,6 @@ class RestEdgeHandler : public RestDocumentHandler {
|
|||
|
||||
bool createDocument() override final;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief creates a document (an edge), coordinator case in a cluster
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool createDocumentCoordinator(std::string const& collname, bool waitForSync,
|
||||
VPackSlice const& document, char const* from,
|
||||
char const* to);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RestEdgesHandler.h"
|
||||
#include "Basics/JsonHelper.h"
|
||||
#include "Basics/ScopeGuard.h"
|
||||
#include "Cluster/ClusterMethods.h"
|
||||
#include "VocBase/Traverser.h"
|
||||
|
@ -191,6 +192,7 @@ bool RestEdgesHandler::readEdges(
|
|||
arangodb::rest::HttpResponse::HttpResponseCode responseCode;
|
||||
std::string contentType;
|
||||
arangodb::basics::Json resultDocument(arangodb::basics::Json::Object, 3);
|
||||
|
||||
int res = getFilteredEdgesOnCoordinator(
|
||||
_vocbase->_name, collectionName, vertexString, direction, expressions,
|
||||
responseCode, contentType, resultDocument);
|
||||
|
@ -242,19 +244,29 @@ bool RestEdgesHandler::readEdges(
|
|||
return false;
|
||||
}
|
||||
|
||||
arangodb::basics::Json result(arangodb::basics::Json::Object, 4);
|
||||
result("edges", documents);
|
||||
result("error", arangodb::basics::Json(false));
|
||||
result("code", arangodb::basics::Json(200));
|
||||
VPackBuilder resultBuilder;
|
||||
resultBuilder.openObject();
|
||||
// build edges
|
||||
resultBuilder.add(VPackValue("edges")); // only key
|
||||
|
||||
// temporarily use json (TODO: remove this)
|
||||
res = arangodb::basics::JsonHelper::toVelocyPack(documents.json(), resultBuilder);
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
generateTransactionError(collectionName, res, "");
|
||||
return false;
|
||||
}
|
||||
|
||||
resultBuilder.add("error", VPackValue(false));
|
||||
resultBuilder.add("code", VPackValue(200));
|
||||
resultBuilder.add("stats", VPackValue(VPackValueType::Object));
|
||||
resultBuilder.add("scannedIndex", VPackValue(scannedIndex));
|
||||
resultBuilder.add("filtered", VPackValue(filtered));
|
||||
resultBuilder.close(); // inner object
|
||||
resultBuilder.close();
|
||||
arangodb::basics::Json stats(arangodb::basics::Json::Object, 2);
|
||||
|
||||
stats("scannedIndex",
|
||||
arangodb::basics::Json(static_cast<int32_t>(scannedIndex)));
|
||||
stats("filtered", arangodb::basics::Json(static_cast<int32_t>(filtered)));
|
||||
result("stats", stats);
|
||||
|
||||
// and generate a response
|
||||
generateResult(result.json());
|
||||
generateResult(resultBuilder.slice());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -171,7 +171,6 @@ class VelocyPackHelper {
|
|||
|
||||
static int compare(VPackSlice const&, VPackSlice const&, bool);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Merges two VelocyPack Slices
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue