1
0
Fork 0
arangodb/RestHandler/RestVocbaseBaseHandler.h

377 lines
15 KiB
C++

////////////////////////////////////////////////////////////////////////////////
/// @brief abstract base request handler
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2010-2011 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 triAGENS GmbH, Cologne, Germany
///
/// @author Dr. Frank Celler
/// @author Copyright 2010-2011, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef TRIAGENS_AVOCADODB_RESTHANDLER_REST_VOCBASE_BASE_HANDLER_H
#define TRIAGENS_AVOCADODB_RESTHANDLER_REST_VOCBASE_BASE_HANDLER_H 1
#include <Admin/RestBaseHandler.h>
#include <Basics/Logger.h>
#include <Rest/HttpResponse.h>
#include <VocBase/document-collection.h>
////////////////////////////////////////////////////////////////////////////////
/// @page HttpInterface Lightweight HTTP Interface
///
/// The AvocadoDB has a REST interface for accessing the resources. It provides
/// a lightweight HTTP interface to execute actions. Actions are small
/// JavaScript functions which encapsulate business logic. Actions are
/// accessible via HTTP.
///
/// Next steps:
///
/// - learn more about the @ref RestInterface "REST Interface"
/// - learn more about the @ref CRUDDocument "REST Interface for Documents"
///
/// Advanced Topics:
///
/// - learn more about @ref Actions "Actions"
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @page RestInterface REST Interface
////////////////////////////////////////////////////////////////////////////////
///
/// Each resource has an identifier, which allows to access the given resource.
///
/// - collection:
/// A collection can be referenced using the collection identifier or the
/// collection name.
/// - document:
/// A document can be referenced using the collection identifier and the
/// document identifier. Alternativly you can use a document reference which
/// is a string of the form "collection-identifier:document-identifier".
/// - index:
/// An index can be referenced using the index identifier.
/// - revision:
/// Each document has a unique document identifier. However, it is possible
/// to update documents. In this case the document identifier stays the
/// same. Each new revision of such a document gets a new revision number.
/// - etag:
/// A revision of a document has an etag.
///
/// Next steps:
///
/// - learn more about the @ref CRUDDocument "REST Interface for Documents"
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- forward declarations
// -----------------------------------------------------------------------------
struct TRI_doc_collection_s;
struct TRI_result_set_s;
struct TRI_vocbase_col_s;
struct TRI_vocbase_s;
struct TRI_json_s;
// -----------------------------------------------------------------------------
// --SECTION-- REST_VOCBASE_BASE_HANDLER
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup AvocadoDB
/// @{
////////////////////////////////////////////////////////////////////////////////
namespace triagens {
namespace avocado {
////////////////////////////////////////////////////////////////////////////////
/// @brief abstract base request handler
////////////////////////////////////////////////////////////////////////////////
class RestVocbaseBaseHandler : public admin::RestBaseHandler {
private:
RestVocbaseBaseHandler (RestVocbaseBaseHandler const&);
RestVocbaseBaseHandler& operator= (RestVocbaseBaseHandler const&);
// -----------------------------------------------------------------------------
// --SECTION-- public constants
// -----------------------------------------------------------------------------
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief result RES-OK
////////////////////////////////////////////////////////////////////////////////
static basics::LoggerData::Extra const RES_OK;
////////////////////////////////////////////////////////////////////////////////
/// @brief result RES-ERR
////////////////////////////////////////////////////////////////////////////////
static basics::LoggerData::Extra const RES_ERR;
////////////////////////////////////////////////////////////////////////////////
/// @brief result RES-ERR
////////////////////////////////////////////////////////////////////////////////
static basics::LoggerData::Extra const RES_FAIL;
////////////////////////////////////////////////////////////////////////////////
/// @brief action path
////////////////////////////////////////////////////////////////////////////////
static string ACTION_PATH;
////////////////////////////////////////////////////////////////////////////////
/// @brief document path
////////////////////////////////////////////////////////////////////////////////
static string DOCUMENT_PATH;
////////////////////////////////////////////////////////////////////////////////
/// @brief collection path
////////////////////////////////////////////////////////////////////////////////
static string COLLECTION_PATH;
// -----------------------------------------------------------------------------
// --SECTION-- constructors and destructors
// -----------------------------------------------------------------------------
public:
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup AvocadoDB
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief constructor
////////////////////////////////////////////////////////////////////////////////
RestVocbaseBaseHandler (rest::HttpRequest* request, struct TRI_vocbase_s* vocbase);
////////////////////////////////////////////////////////////////////////////////
/// @brief destructor
////////////////////////////////////////////////////////////////////////////////
~RestVocbaseBaseHandler ();
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- protected methods
// -----------------------------------------------------------------------------
protected:
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup AvocadoDB
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief generates ok message without content
////////////////////////////////////////////////////////////////////////////////
void generateOk ();
////////////////////////////////////////////////////////////////////////////////
/// @brief generates ok message without content
////////////////////////////////////////////////////////////////////////////////
void generateOk (TRI_voc_cid_t, TRI_voc_did_t, TRI_voc_rid_t rid);
////////////////////////////////////////////////////////////////////////////////
/// @brief generates created message without content but a location header
////////////////////////////////////////////////////////////////////////////////
void generateCreated (TRI_voc_cid_t, TRI_voc_did_t, TRI_voc_rid_t);
////////////////////////////////////////////////////////////////////////////////
/// @brief generates collection not found error message
////////////////////////////////////////////////////////////////////////////////
void generateCollectionNotFound (string const& cid);
////////////////////////////////////////////////////////////////////////////////
/// @brief generates document not found error message
////////////////////////////////////////////////////////////////////////////////
void generateDocumentNotFound (string const& cid, string const& did);
////////////////////////////////////////////////////////////////////////////////
/// @brief generates conflict message
////////////////////////////////////////////////////////////////////////////////
void generateConflict (string const& cid, string const& did);
////////////////////////////////////////////////////////////////////////////////
/// @brief generates not implemented
////////////////////////////////////////////////////////////////////////////////
void generateNotImplemented (string const& path);
////////////////////////////////////////////////////////////////////////////////
/// @brief generates first entry from a result set
////////////////////////////////////////////////////////////////////////////////
void generateResultSetNext ();
////////////////////////////////////////////////////////////////////////////////
/// @brief splits a document reference into to parts
////////////////////////////////////////////////////////////////////////////////
vector<string> splitDocumentReference (string const& name);
////////////////////////////////////////////////////////////////////////////////
/// @brief extracts the revision
////////////////////////////////////////////////////////////////////////////////
TRI_voc_rid_t extractRevision ();
////////////////////////////////////////////////////////////////////////////////
/// @brief extracts the update policy
////////////////////////////////////////////////////////////////////////////////
TRI_doc_update_policy_e extractUpdatePolicy ();
////////////////////////////////////////////////////////////////////////////////
/// @brief sets the collection variable given a name or an identifier
////////////////////////////////////////////////////////////////////////////////
bool findCollection (string const& name);
////////////////////////////////////////////////////////////////////////////////
/// @brief creates or loads a collection
////////////////////////////////////////////////////////////////////////////////
bool loadCollection ();
////////////////////////////////////////////////////////////////////////////////
/// @brief parses the body
////////////////////////////////////////////////////////////////////////////////
struct TRI_json_s* parseJsonBody ();
////////////////////////////////////////////////////////////////////////////////
/// @brief sets the rest set, needs the collection
////////////////////////////////////////////////////////////////////////////////
void findDocument (string const& doc);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- protected variables
// -----------------------------------------------------------------------------
protected:
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup AvocadoDB
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief the vocbase
////////////////////////////////////////////////////////////////////////////////
struct TRI_vocbase_s* _vocbase;
////////////////////////////////////////////////////////////////////////////////
/// @brief a vocbase collection
////////////////////////////////////////////////////////////////////////////////
struct TRI_vocbase_col_s const* _collection;
////////////////////////////////////////////////////////////////////////////////
/// @brief corresponding loaded document collection
////////////////////////////////////////////////////////////////////////////////
struct TRI_doc_collection_s* _documentCollection;
////////////////////////////////////////////////////////////////////////////////
/// @brief a result set
////////////////////////////////////////////////////////////////////////////////
struct TRI_result_set_s* _resultSet;
////////////////////////////////////////////////////////////////////////////////
/// @brief timing data structure
////////////////////////////////////////////////////////////////////////////////
triagens::basics::LoggerTiming _timing;
////////////////////////////////////////////////////////////////////////////////
/// @brief timing result
////////////////////////////////////////////////////////////////////////////////
triagens::basics::LoggerData::Extra _timingResult;
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- HANDLER
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// --SECTION-- public methods
// -----------------------------------------------------------------------------
public:
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup AvocadoDB
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// {@inheritDoc}
////////////////////////////////////////////////////////////////////////////////
bool isDirect ();
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
};
}
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
#endif
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\)"
// End: