bes  Updated for version 3.17.0
BESXMLGetCommand.cc
1 // BESXMLGetCommand.cc
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 #include "BESXMLGetCommand.h"
34 #include "BESDefinitionStorageList.h"
35 #include "BESDefinitionStorage.h"
36 #include "BESDefine.h"
37 #include "BESDataNames.h"
38 #include "BESResponseNames.h"
39 #include "BESDapNames.h"
40 #include "BESXMLUtils.h"
41 #include "BESUtil.h"
42 #include "BESSyntaxUserError.h"
43 #include "BESDebug.h"
44 
45 BESXMLGetCommand::BESXMLGetCommand(const BESDataHandlerInterface &base_dhi) :
46  BESXMLCommand(base_dhi), _sub_cmd(0)
47 {
48 }
49 
57 {
58  string name;
59  string value;
60  map<string, string> props;
61  BESXMLUtils::GetNodeInfo(node, name, value, props);
62  if (name != GET_RESPONSE) {
63  string err = "The specified command " + name + " is not a get command";
64  throw BESSyntaxUserError(err, __FILE__, __LINE__);
65  }
66 
67  // grab the type first and check to see if there is a registered command
68  // to handle get.<type> requests
69  string type = props["type"];
70  if (type.empty()) {
71  string err = name + " command: Must specify data product type";
72  throw BESSyntaxUserError(err, __FILE__, __LINE__);
73  }
74  string new_cmd = (string) GET_RESPONSE + "." + type;
75  p_xmlcmd_builder bldr = BESXMLCommand::find_command(new_cmd);
76  if (bldr) {
77  // the base dhi was copied to this instance's _dhi variable.
78  _sub_cmd = bldr(_dhi);
79  if (!_sub_cmd) {
80  string err = (string) "Failed to build command object for " + new_cmd;
81  throw BESInternalError(err, __FILE__, __LINE__);
82  }
83 
84  // parse the request given the current node
85  _sub_cmd->parse_request(node);
86 
87  // return from this sub command
88  return;
89  }
90 
91  parse_basic_get(node, name, type, value, props);
92  _str_cmd += ";";
93 
94  // now that we've set the action, go get the response handler for the
95  // action
97 }
98 
99 void BESXMLGetCommand::parse_basic_get(xmlNode */*node*/, const string &name, const string &type,
100  const string &/*value*/, map<string, string> &props)
101 {
102  _str_cmd = (string) "get " + type;
103  _definition = props["definition"];
104  if (_definition.empty()) {
105  string err = name + " command: Must specify definition";
106  throw BESSyntaxUserError(err, __FILE__, __LINE__);
107  }
108  _str_cmd += " for " + _definition;
109 
110  _space = props["space"];
111  if (!_space.empty()) _str_cmd += " in " + _space;
112 
113  string returnAs = props["returnAs"];
114  if (returnAs.empty()) {
115  returnAs = DAP2_FORMAT;
116  }
117  _dhi.data[RETURN_CMD] = returnAs;
118 
119  _dhi.data[STORE_RESULT] = props[STORE_RESULT];
120  _dhi.data[ASYNC] = props[ASYNC];
121 
122  _str_cmd += " return as " + returnAs;
123 
124  _dhi.action = "get.";
125  _dhi.action += BESUtil::lowercase(type);
126  BESDEBUG("besxml", "Converted xml element name to command " << _dhi.action << endl);
127 }
128 
137 {
138  if (_sub_cmd) return _sub_cmd->get_dhi();
139 
140  return _dhi;
141 }
142 
151 {
152  // if there is a sub command then execute the prep request on it
153  if (_sub_cmd) {
154  _sub_cmd->prep_request();
155  return;
156  }
157 
158  BESDefine *d = 0;
159 
160  if (!_space.empty()) {
161  BESDefinitionStorage *ds = BESDefinitionStorageList::TheList()->find_persistence(_space);
162  if (ds) {
163  d = ds->look_for(_definition);
164  }
165  }
166  else {
167  d = BESDefinitionStorageList::TheList()->look_for(_definition);
168  }
169 
170  if (!d) {
171  string s = (string) "Unable to find definition " + _definition;
172  throw BESSyntaxUserError(s, __FILE__, __LINE__);
173  }
174 
175  BESDefine::containers_citer i = d->first_container();
176  BESDefine::containers_citer ie = d->end_container();
177  while (i != ie) {
178  _dhi.containers.push_back(*i);
179  i++;
180  }
181 
182  _dhi.data[AGG_CMD] = d->get_agg_cmd();
183  _dhi.data[AGG_HANDLER] = d->get_agg_handler();
184 }
185 
192 void BESXMLGetCommand::dump(ostream &strm) const
193 {
194  strm << BESIndent::LMarg << "BESXMLGetCommand::dump - (" << (void *) this << ")" << endl;
195  BESIndent::Indent();
196  BESXMLCommand::dump(strm);
197  BESIndent::UnIndent();
198 }
199 
201 BESXMLGetCommand::CommandBuilder(const BESDataHandlerInterface &base_dhi)
202 {
203  return new BESXMLGetCommand(base_dhi);
204 }
205 
provides persistent storage for a specific view of different containers including contraints and aggr...
exception thrown if inernal error encountered
virtual BESDefine * look_for(const string &def_name)
look for the specified definition in the list of defintion stores.
static string lowercase(const string &s)
Definition: BESUtil.cc:184
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
Definition: BESXMLUtils.cc:99
virtual void parse_request(xmlNode *node)
parse a get command.
virtual BESDefinitionStorage * find_persistence(const string &persist_name)
find the persistence store with the given name
error thrown if there is a user syntax error in the request or any other user error ...
virtual void set_response()
The request has been parsed, use the command action name to set the response handler.
virtual void prep_request()
Prepare any information needed to execute the request of this get command.
virtual void dump(ostream &strm) const
dumps information about this object
Structure storing information used by the BES to handle the request.
map< string, string > data
the map of string data that will be required for the current request.
virtual BESDefine * look_for(const string &def_name)=0
looks for a definition in this persistent store with the given name
string action
the response object requested, e.g. das, dds
virtual BESDataHandlerInterface & get_dhi()
returns the BESDataHandlerInterface of either a sub command, if one exists, or this command&#39;s ...
virtual void dump(ostream &strm) const
dumps information about this object
static p_xmlcmd_builder find_command(const string &cmd_str)
Find the BESXMLCommand creation function with the given name.