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  m_data = nullptr;
38  std::stringstream sout;
39  sout << data;
40  try {
41  boost::property_tree::read_json(sout, m_root);
42  } catch (boost::property_tree::json_parser_error const& ex) {
43  throw cond::Exception(ex.what(), "OMSServiceResult::parseData");
44  }
45  if (!m_root.empty()) {
46  m_data = &m_root.get_child("data");
47  }
48  return m_root.size();
49  }
50 
51  size_t OMSServiceResult::size() const {
52  size_t ret = 0;
53  if (m_data) {
54  ret = m_data->size();
55  }
56  return ret;
57  }
58 
59  bool OMSServiceResult::empty() const { return size() == 0; }
60 
61  void OMSServiceQuery::addVar(const std::string& varName) {
62  std::stringstream varList;
63  if (m_varList.empty()) {
64  varList << "&fields=";
65  } else {
66  varList << m_varList << ",";
67  }
68  varList << varName;
69  m_varList = varList.str();
70  }
71 
72  OMSServiceQuery::OMSServiceQuery(const std::string& baseUrl, const std::string& function) {
73  m_url = baseUrl + "/" + function;
74  }
75 
77  addVar(varName);
78  return *this;
79  }
80  OMSServiceQuery& OMSServiceQuery::addOutputVars(const std::initializer_list<const char*>& varNames) {
81  for (auto v : varNames)
82  addVar(v);
83  return *this;
84  }
85 
87  std::stringstream pageLimit;
88  if (m_filter.empty()) {
89  pageLimit << "?";
90  } else {
91  pageLimit << "&";
92  }
93  pageLimit << "page[limit]=" << value;
94  m_limit = pageLimit.str();
95  return *this;
96  }
97 
99  bool ret = false;
102  if (m_status == 200 || m_status == 201) {
103  m_result = std::make_unique<OMSServiceResult>();
104  m_result->parseData(out);
105  ret = true;
106  }
107  return ret;
108  }
109 
110  unsigned long OMSServiceQuery::status() { return m_status; }
111 
113 
115 
116  OMSService::OMSService() : m_baseUrl() {}
117 
118  void OMSService::connect(const std::string& baseUrl) { m_baseUrl = baseUrl; }
119  std::unique_ptr<OMSServiceQuery> OMSService::query(const std::string& function) const {
120  return std::make_unique<OMSServiceQuery>(m_baseUrl, function);
121  }
122 } // namespace cond
persistency::Exception Exception
Definition: Exception.h:25
OMSServiceQuery & addOutputVars(const std::initializer_list< const char *> &varNames)
Definition: OMSAccess.cc:80
unsigned long status()
Definition: OMSAccess.cc:110
boost::property_tree::ptree * m_data
Definition: OMSAccess.h:161
std::string getAttribute(const std::string &attributeName)
Definition: OMSAccess.cc:11
OMSServiceQuery & addOutputVar(const std::string &varName)
Definition: OMSAccess.cc:76
OMSServiceResultRef operator*()
Definition: OMSAccess.cc:17
std::unique_ptr< OMSServiceQuery > query(const std::string &function) const
Definition: OMSAccess.cc:119
std::string m_url
Definition: OMSAccess.h:247
ret
prodAgent to be discontinued
bool empty() const
Definition: OMSAccess.cc:59
std::string m_filter
Definition: OMSAccess.h:248
constexpr char const * varNames[]
unsigned long m_status
Definition: OMSAccess.h:252
bool operator!=(const OMSServiceResultIterator &rhs)
Definition: OMSAccess.cc:28
OMSServiceResult & result()
Definition: OMSAccess.cc:112
boost::property_tree::ptree::const_iterator m_iter
Definition: OMSAccess.h:139
std::string url()
Definition: OMSAccess.cc:114
size_t size() const
Definition: OMSAccess.cc:51
Definition: value.py:1
const boost::property_tree::ptree * m_row
Definition: OMSAccess.h:123
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:249
OMSServiceResultIterator end() const
Definition: OMSAccess.cc:34
void addVar(const std::string &varName)
Definition: OMSAccess.cc:61
std::unique_ptr< OMSServiceResult > m_result
Definition: OMSAccess.h:251
Definition: plugin.cc:23
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
size_t parseData(const std::string &data)
Definition: OMSAccess.cc:36
void connect(const std::string &baseUrl)
Definition: OMSAccess.cc:118
OMSServiceResultIterator begin() const
Definition: OMSAccess.cc:32
boost::property_tree::ptree m_root
Definition: OMSAccess.h:160
std::string m_varList
Definition: OMSAccess.h:250
std::string m_baseUrl
Definition: OMSAccess.h:264
OMSServiceQuery & limit(int value)
Definition: OMSAccess.cc:86