33 #include "BESXMLDefineCommand.h" 34 #include "BESContainerStorageList.h" 35 #include "BESContainerStorage.h" 36 #include "BESXMLUtils.h" 38 #include "BESResponseNames.h" 39 #include "BESDataNames.h" 40 #include "BESSyntaxUserError.h" 44 BESXMLCommand(base_dhi), _default_constraint(
""), _default_dap4_constraint(
""), _default_dap4_function(
"")
71 map<string, string> props;
75 if (action != DEFINE_RESPONSE_STR) {
76 string err =
"The specified command " + action +
" is not a set context command";
80 _dhi.action = DEFINE_RESPONSE;
82 def_name = props[
"name"];
83 if (def_name.empty()) {
84 string err = action +
" command: definition name missing";
88 _dhi.data[DEF_NAME] = def_name;
89 _str_cmd = (string)
"define " + def_name;
91 def_space = props[
"space"];
92 if (!def_space.empty()) {
93 _str_cmd +=
" in " + def_space;
95 _dhi.data[STORE_NAME] = def_space;
97 int num_containers = 0;
103 if (child_name ==
"constraint") {
105 _default_constraint = child_value;
107 else if (child_name ==
"dap4constraint") {
109 _default_dap4_constraint = child_value;
111 else if (child_name ==
"dap4function") {
113 _default_dap4_function = child_value;
115 else if (child_name ==
"container") {
116 handle_container_element(action, child_node, child_value, props);
119 else if (child_name ==
"aggregate") {
120 handle_aggregate_element(action, child_node, child_value, props);
130 if (num_containers < 1) {
131 string err = action +
"The define element must contain at least " +
"one container element";
137 vector<string>::iterator i = _containers.begin();
138 vector<string>::iterator e = _containers.end();
139 for (; i != e; i++) {
140 if (!first) _str_cmd +=
",";
145 if (_constraints.size() || _dap4constraints.size() || _dap4functions.size() || _attributes.size()) {
146 _str_cmd +=
" with ";
148 i = _containers.begin();
149 e = _containers.end();
150 for (; i != e; i++) {
151 if (_constraints.count((*i))) {
152 if (!first) _str_cmd +=
",";
154 _str_cmd += (*i) +
".constraint=\"" + _constraints[(*i)] +
"\"";
156 if (_dap4constraints.count((*i))) {
157 if (!first) _str_cmd +=
",";
159 _str_cmd += (*i) +
".dap4constraint=\"" + _dap4constraints[(*i)] +
"\"";
161 if (_dap4functions.count((*i))) {
162 if (!first) _str_cmd +=
",";
164 _str_cmd += (*i) +
".dap4function=\"" + _dap4functions[(*i)] +
"\"";
166 if (_attributes.count((*i))) {
167 if (!first) _str_cmd +=
",";
169 _str_cmd += (*i) +
".attributes=\"" + _attributes[(*i)] +
"\"";
176 BESDEBUG(
"xml",
"BESXMLDefineCommand::parse_request() - _str_cmd: " << _str_cmd << endl);
197 void BESXMLDefineCommand::handle_container_element(
const string &action, xmlNode *node,
const string &,
198 map<string, string> &props)
200 string name = props[
"name"];
202 string err = action +
" command: container element missing name prop";
206 _containers.push_back(name);
208 string space = props[
"space"];
209 _stores[name] = space;
211 bool have_constraint =
false;
212 bool have_dap4constraint =
false;
213 bool have_dap4function =
false;
214 bool have_attributes =
false;
219 map<string, string> child_props;
222 if (child_name ==
"constraint") {
223 if (child_props.size()) {
224 string err = action +
" command: constraint element " +
"should not contain properties";
227 if (child_value.empty()) {
228 string err = action +
" command: constraint element " +
"missing value";
231 if (have_constraint) {
232 string err = action +
" command: container element " +
"contains multiple constraint elements";
235 have_constraint =
true;
236 _constraints[name] = child_value;
238 else if (child_name ==
"dap4constraint") {
239 if (child_props.size()) {
240 string err = action +
" command: constraint element " +
"should not contain properties";
243 if (child_value.empty()) {
244 string err = action +
" command: constraint element " +
"missing value";
247 if (have_dap4constraint) {
248 string err = action +
" command: container element " +
"contains multiple constraint elements";
251 have_dap4constraint =
true;
252 _dap4constraints[name] = child_value;
254 else if (child_name ==
"dap4function") {
255 if (child_props.size()) {
256 string err = action +
" command: dap4_function element " +
"should not contain properties";
259 if (child_value.empty()) {
260 string err = action +
" command: dap4_function element " +
"missing value";
263 if (have_dap4function) {
264 string err = action +
" command: container element " +
"contains multiple dap4_function elements";
267 have_dap4function =
true;
268 _dap4functions[name] = child_value;
270 else if (child_name ==
"attributes") {
271 if (child_props.size()) {
272 string err = action +
" command: attributes element " +
"should not contain properties";
275 if (child_value.empty()) {
276 string err = action +
" command: attributes element " +
"missing value";
279 if (have_attributes) {
280 string err = action +
" command: container element " +
"contains multiple attributes elements";
283 have_attributes =
true;
284 _attributes[name] = child_value;
306 void BESXMLDefineCommand::handle_aggregate_element(
const string &action, xmlNode *,
const string &,
307 map<string, string> &props)
309 string handler = props[
"handler"];
310 string cmd = props[
"cmd"];
311 if (handler.empty()) {
312 string err = action +
" command: must specify aggregation handler";
316 string err = action +
" command: must specify aggregation cmd";
320 _dhi.data[AGG_HANDLER] = handler;
321 _dhi.data[AGG_CMD] = cmd;
322 _str_cmd +=
" aggregate using " + handler +
" by " + cmd;
329 vector<string>::iterator i = _containers.begin();
330 vector<string>::iterator e = _containers.end();
331 for (; i != e; i++) {
336 string store = _stores[(*i)];
337 if (!store.empty()) {
342 c = BESContainerStorageList::TheList()->
look_for((*i));
354 throw BESSyntaxUserError(
string(
"Could not find the container ") + (*i), __FILE__, __LINE__);
357 string constraint = _constraints[(*i)];
358 if (constraint.empty()) constraint = _default_constraint;
362 string dap4constraint = _dap4constraints[(*i)];
363 if (dap4constraint.empty()) dap4constraint = _default_dap4_constraint;
367 string function = _dap4functions[(*i)];
368 if (
function.empty())
function = _default_dap4_function;
371 string attrs = _attributes[(*i)];
373 _dhi.containers.push_back(c);
375 BESDEBUG(
"xml",
"BESXMLDefineCommand::prep_request() - define using container: " << endl << *c << endl);
388 strm << BESIndent::LMarg <<
"BESXMLDefineCommand::dump - (" << (
void *)
this <<
")" << endl;
391 BESIndent::UnIndent();
provides persistent storage for data storage information represented by a container.
static xmlNode * GetFirstChild(xmlNode *node, string &child_name, string &child_value, map< string, string > &child_props)
get the first element child node for the given node
virtual BESContainerStorage * find_persistence(const string &persist_name)
find the persistence store with the given name
static xmlNode * GetNextChild(xmlNode *child_node, string &next_name, string &next_value, map< string, string > &next_props)
get the next element child node after the given child node
static void GetNodeInfo(xmlNode *node, string &name, string &value, map< string, string > &props)
get the name, value if any, and any properties for the specified node
virtual BESContainer * look_for(const string &sym_name)=0
looks for a container in this persistent store
error thrown if there is a user syntax error in the request or any other user error ...
virtual void parse_request(xmlNode *node)
parse a show command. No properties or children elements
virtual void set_response()
The request has been parsed, use the command action name to set the response handler.
virtual void prep_request()
prepare the define command by making sure the containers exist
void set_constraint(const string &s)
set the constraint for this container
void set_dap4_constraint(const string &s)
set the constraint for this container
void set_attributes(const string &attrs)
set desired attributes for this container
virtual void dump(ostream &strm) const
dumps information about this object
void set_dap4_function(const string &s)
set the constraint for this container
Structure storing information used by the BES to handle the request.
virtual BESContainer * look_for(const string &sym_name)
look for the specified container information in the list of persistent stores.
A container is something that holds data. I.E. a netcdf file or a database entry. ...
virtual void dump(ostream &strm) const
dumps information about this object