CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  bool ret = false;
89  m_status = cond::httpGet(url(), out);
90  if (m_status == 200 || m_status == 201) {
91  m_result = std::make_unique<OMSServiceResult>();
92  m_result->parseData(out);
93  ret = true;
94  }
95  return ret;
96  }
97 
98  unsigned long OMSServiceQuery::status() { return m_status; }
99 
101 
103 
104  OMSService::OMSService() : m_baseUrl() {}
105 
106  void OMSService::connect(const std::string& baseUrl) { m_baseUrl = baseUrl; }
107  std::unique_ptr<OMSServiceQuery> OMSService::query(const std::string& function) const {
108  return std::make_unique<OMSServiceQuery>(m_baseUrl, function);
109  }
110 } // namespace cond
persistency::Exception Exception
Definition: Exception.h:25
OMSServiceQuery & addOutputVars(const std::initializer_list< const char * > &varNames)
Definition: OMSAccess.cc:80
tuple ret
prodAgent to be discontinued
unsigned long status()
Definition: OMSAccess.cc:98
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::string m_url
Definition: OMSAccess.h:231
std::string m_filter
Definition: OMSAccess.h:232
constexpr char const * varNames[]
unsigned long m_status
Definition: OMSAccess.h:235
OMSServiceResultIterator begin() const
Definition: OMSAccess.cc:32
bool operator!=(const OMSServiceResultIterator &rhs)
Definition: OMSAccess.cc:28
size_t size() const
Definition: OMSAccess.cc:51
OMSServiceResult & result()
Definition: OMSAccess.cc:100
boost::property_tree::ptree::const_iterator m_iter
Definition: OMSAccess.h:139
std::string url()
Definition: OMSAccess.cc:102
bool empty() const
Definition: OMSAccess.cc:59
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
void addVar(const std::string &varName)
Definition: OMSAccess.cc:61
std::unique_ptr< OMSServiceResult > m_result
Definition: OMSAccess.h:234
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:106
boost::property_tree::ptree m_root
Definition: OMSAccess.h:160
OMSServiceResultIterator end() const
Definition: OMSAccess.cc:34
std::string m_varList
Definition: OMSAccess.h:233
std::string m_baseUrl
Definition: OMSAccess.h:247
std::unique_ptr< OMSServiceQuery > query(const std::string &function) const
Definition: OMSAccess.cc:107