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