CMS 3D CMS Logo

OMSAccess.cc
Go to the documentation of this file.
4 
5 namespace cond {
6 
7  OMSServiceResultRef::OMSServiceResultRef(const boost::property_tree::ptree* row) : m_row(row) {}
8 
9  bool OMSServiceResultRef::empty() { return m_row == nullptr; }
10 
12  return m_row->get<std::string>(attributeName);
13  }
14 
15  OMSServiceResultIterator::OMSServiceResultIterator(boost::property_tree::ptree::const_iterator iter) : m_iter(iter) {}
16 
18  auto& attributeList = m_iter->second.get_child("attributes");
19  return OMSServiceResultRef(&attributeList);
20  }
21 
23  m_iter++;
24  return *this;
25  }
26 
29 
31 
33 
35 
37  auto& attributeList = m_data->front().second.get_child("attributes");
38  return OMSServiceResultRef(&attributeList);
39  }
40 
42  auto& attributeList = m_data->back().second.get_child("attributes");
43  return OMSServiceResultRef(&attributeList);
44  }
45 
47  m_data = nullptr;
48  std::stringstream sout;
49  sout << data;
50  try {
51  boost::property_tree::read_json(sout, m_root);
52  } catch (boost::property_tree::json_parser_error const& ex) {
53  throw cond::Exception(ex.what(), "OMSServiceResult::parseData");
54  }
55  if (!m_root.empty()) {
56  m_data = &m_root.get_child("data");
57  }
58  return m_root.size();
59  }
60 
61  size_t OMSServiceResult::size() const {
62  size_t ret = 0;
63  if (m_data) {
64  ret = m_data->size();
65  }
66  return ret;
67  }
68 
69  bool OMSServiceResult::empty() const { return size() == 0; }
70 
71  void OMSServiceQuery::addVar(const std::string& varName) {
72  std::stringstream varList;
73  if (m_varList.empty()) {
74  varList << "&fields=";
75  } else {
76  varList << m_varList << ",";
77  }
78  varList << varName;
79  m_varList = varList.str();
80  }
81 
82  OMSServiceQuery::OMSServiceQuery(const std::string& baseUrl, const std::string& function) {
83  m_url = baseUrl + "/" + function;
84  }
85 
87  addVar(varName);
88  return *this;
89  }
90  OMSServiceQuery& OMSServiceQuery::addOutputVars(const std::initializer_list<const char*>& varNames) {
91  for (auto v : varNames)
92  addVar(v);
93  return *this;
94  }
95 
97  std::stringstream pageLimit;
98  if (m_filter.empty()) {
99  pageLimit << "?";
100  } else {
101  pageLimit << "&";
102  }
103  pageLimit << "page[limit]=" << value;
104  m_limit = pageLimit.str();
105  return *this;
106  }
107 
109  bool ret = false;
112  if (m_status == 200 || m_status == 201) {
113  m_result = std::make_unique<OMSServiceResult>();
114  m_result->parseData(out);
115  ret = true;
116  }
117  return ret;
118  }
119 
120  unsigned long OMSServiceQuery::status() { return m_status; }
121 
123 
125 
126  OMSService::OMSService() : m_baseUrl() {}
127 
128  void OMSService::connect(const std::string& baseUrl) { m_baseUrl = baseUrl; }
129  std::unique_ptr<OMSServiceQuery> OMSService::query(const std::string& function) const {
130  return std::make_unique<OMSServiceQuery>(m_baseUrl, function);
131  }
132 } // namespace cond
persistency::Exception Exception
Definition: Exception.h:25
OMSServiceQuery & addOutputVars(const std::initializer_list< const char *> &varNames)
Definition: OMSAccess.cc:90
unsigned long status()
Definition: OMSAccess.cc:120
boost::property_tree::ptree * m_data
Definition: OMSAccess.h:170
std::string getAttribute(const std::string &attributeName)
Definition: OMSAccess.cc:11
OMSServiceQuery & addOutputVar(const std::string &varName)
Definition: OMSAccess.cc:86
OMSServiceResultRef operator*()
Definition: OMSAccess.cc:17
std::unique_ptr< OMSServiceQuery > query(const std::string &function) const
Definition: OMSAccess.cc:129
std::string m_url
Definition: OMSAccess.h:256
ret
prodAgent to be discontinued
bool empty() const
Definition: OMSAccess.cc:69
std::string m_filter
Definition: OMSAccess.h:257
OMSServiceResultRef front() const
Definition: OMSAccess.cc:36
constexpr char const * varNames[]
OMSServiceResultRef back() const
Definition: OMSAccess.cc:41
unsigned long m_status
Definition: OMSAccess.h:261
bool operator!=(const OMSServiceResultIterator &rhs)
Definition: OMSAccess.cc:28
OMSServiceResult & result()
Definition: OMSAccess.cc:122
boost::property_tree::ptree::const_iterator m_iter
Definition: OMSAccess.h:145
std::string url()
Definition: OMSAccess.cc:124
size_t size() const
Definition: OMSAccess.cc:61
Definition: value.py:1
const boost::property_tree::ptree * m_row
Definition: OMSAccess.h:129
bool operator==(const OMSServiceResultIterator &rhs)
Definition: OMSAccess.cc:27
unsigned long httpGet(const std::string &urlString, std::string &info)
Definition: WebUtils.cc:16
OMSServiceResultIterator & operator++()
Definition: OMSAccess.cc:22
std::string m_limit
Definition: OMSAccess.h:258
OMSServiceResultIterator end() const
Definition: OMSAccess.cc:34
void addVar(const std::string &varName)
Definition: OMSAccess.cc:71
std::unique_ptr< OMSServiceResult > m_result
Definition: OMSAccess.h:260
Definition: plugin.cc:23
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
size_t parseData(const std::string &data)
Definition: OMSAccess.cc:46
void connect(const std::string &baseUrl)
Definition: OMSAccess.cc:128
OMSServiceResultIterator begin() const
Definition: OMSAccess.cc:32
boost::property_tree::ptree m_root
Definition: OMSAccess.h:169
std::string m_varList
Definition: OMSAccess.h:259
std::string m_baseUrl
Definition: OMSAccess.h:273
OMSServiceQuery & limit(int value)
Definition: OMSAccess.cc:96