OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
config_cass2json_adapter.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef config_cass2json_adapter_h
6 #define config_cass2json_adapter_h
7 #include <map>
8 #include <set>
9 #include <vector>
10 
11 #include "rapidjson/document.h"
12 
13 #include "json_adapter_data.h"
14 
16 // The purpose of this class is to convert key-value pairs received from
17 // cassandra into one single json string.
18 // The user will pass a vector of key-value while creating the object. The
19 // constructor will create a json string, which will then be accessible via the
20 // doc_string() accessor.
22 public:
23  static const std::string fq_name_prefix;
24  static const std::string prop_prefix;
25  static const std::string list_prop_prefix;
26  static const std::string map_prop_prefix;
27  static const std::string ref_prefix;
28  static const std::string parent_prefix;
29  static const std::string parent_type_prefix;
30 
31  static const std::set<std::string> allowed_properties;
32 
33  ConfigCass2JsonAdapter(const std::string &uuid,
34  ConfigCassandraClient *cassandra_client,
35  const std::string &obj_type,
36  const CassColumnKVVec &cdvec);
37  ConfigCass2JsonAdapter(const std::string &uuid,
38  const std::string &type,
39  const contrail_rapidjson::Document &doc);
40 
41  const contrail_rapidjson::Document &document() const {
42  return json_document_;
43  }
45  static void set_assert_on_parse_error(bool flag) {
47  }
48  const std::string &uuid() const { return uuid_; }
49  const std::string &type() const { return type_; }
50 
51 private:
52  void CreateJsonString(const std::string &obj_type,
53  const CassColumnKVVec &cdvec);
54  void CreateJsonString(const std::string &value_str);
55  void AddOneEntry(contrail_rapidjson::Value *jsonObject,
56  const std::string &obj_type,
57  const JsonAdapterDataType &c,
58  contrail_rapidjson::Document::AllocatorType &a);
59  static std::string GetJsonString(
60  const contrail_rapidjson::Value &attr_value);
61 
63  std::string uuid_;
64  std::string type_;
65  contrail_rapidjson::Document json_document_;
67 };
68 
69 #endif // config_cass2json_adapter_h
static const std::string ref_prefix
static std::string GetJsonString(const contrail_rapidjson::Value &attr_value)
static const std::string list_prop_prefix
const std::string & type() const
const std::string & uuid() const
boost::uuids::uuid uuid
static const std::string prop_prefix
contrail_rapidjson::Document json_document_
static const std::set< std::string > allowed_properties
static const std::string parent_type_prefix
const contrail_rapidjson::Document & document() const
void AddOneEntry(contrail_rapidjson::Value *jsonObject, const std::string &obj_type, const JsonAdapterDataType &c, contrail_rapidjson::Document::AllocatorType &a)
ConfigCassandraClient * cassandra_client_
std::vector< JsonAdapterDataType > CassColumnKVVec
static const std::string fq_name_prefix
static void set_assert_on_parse_error(bool flag)
static const std::string parent_prefix
static const std::string map_prop_prefix
void CreateJsonString(const std::string &obj_type, const CassColumnKVVec &cdvec)
ConfigCass2JsonAdapter(const std::string &uuid, ConfigCassandraClient *cassandra_client, const std::string &obj_type, const CassColumnKVVec &cdvec)