bes  Updated for version 3.19.1
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 "config.h"
34 
35 #include <sstream>
36 
37 #include "BESXMLGetCommand.h"
38 #include "BESDefinitionStorageList.h"
39 #include "BESDefinitionStorage.h"
40 #include "BESDefine.h"
41 #include "BESDataNames.h"
42 #include "BESResponseNames.h"
43 #include "BESDapNames.h"
44 
45 #include "BESXMLUtils.h"
46 #include "BESUtil.h"
47 #include "BESSyntaxUserError.h"
48 #include "BESLog.h"
49 #include "BESDebug.h"
50 
51 using namespace std;
52 
53 BESXMLGetCommand::BESXMLGetCommand(const BESDataHandlerInterface &base_dhi) :
54  BESXMLCommand(base_dhi), _sub_cmd(0)
55 {
56 }
57 
71 {
72  string name;
73  string value;
74  map<string, string> props;
75  BESXMLUtils::GetNodeInfo(node, name, value, props);
76 
77  if (name != GET_RESPONSE) {
78  string err = "The specified command " + name + " is not a get command";
79  throw BESSyntaxUserError(err, __FILE__, __LINE__);
80  }
81 
82  // grab the type first and check to see if there is a registered command
83  // to handle get.<type> requests
84  string type = props["type"];
85  if (type.empty()) {
86  string err = name + " command: Must specify data product type";
87  throw BESSyntaxUserError(err, __FILE__, __LINE__);
88  }
89  string new_cmd = (string) GET_RESPONSE + "." + type;
90  p_xmlcmd_builder bldr = BESXMLCommand::find_command(new_cmd);
91  if (bldr) {
92  // the base dhi was copied to this instance's _dhi variable.
93  _sub_cmd = bldr(d_xmlcmd_dhi);
94  if (!_sub_cmd) {
95  string err = (string) "Failed to build command object for " + new_cmd;
96  throw BESInternalError(err, __FILE__, __LINE__);
97  }
98 
99  // parse the request given the current node
100  _sub_cmd->parse_request(node);
101 
102  // return from this sub command
103  return;
104  }
105 
106  parse_basic_get(type, props);
107  d_cmd_log_info += ";";
108 
109  // now that we've set the action, go get the response handler for the
110  // action
112 }
113 
127 void BESXMLGetCommand::parse_basic_get(const string &type, map<string, string> &props)
128 {
129  d_cmd_log_info = "get "; // Remove any old value of this string
130  d_cmd_log_info.append(type);
131 
132  _definition = props["definition"];
133  if (_definition.empty())
134  throw BESSyntaxUserError("get command: Must specify definition", __FILE__, __LINE__);
135 
136  // TODO Lookup the definition and get the container. Then lookup the container and
137  // get the path and constraint. jhrg 11/14/17
138  d_cmd_log_info.append(" for ").append(_definition);
139 
140  _space = props["space"];
141 
142  if (!_space.empty()) d_cmd_log_info.append(" in ").append(_space);
143 
144  string returnAs = props["returnAs"];
145  if (returnAs.empty()) {
146  returnAs = DAP2_FORMAT;
147  }
148 
149  d_xmlcmd_dhi.data[RETURN_CMD] = returnAs;
150 
151  d_xmlcmd_dhi.data[STORE_RESULT] = props[STORE_RESULT];
152  d_xmlcmd_dhi.data[ASYNC] = props[ASYNC];
153 
154  d_cmd_log_info.append(" return as ").append(returnAs);
155 
156  d_xmlcmd_dhi.action = "get.";
157  d_xmlcmd_dhi.action.append(BESUtil::lowercase(type));
158 
159  BESDEBUG("besxml", "Converted xml element name to command " << d_xmlcmd_dhi.action << endl);
160 }
161 
170 {
171  if (_sub_cmd) return _sub_cmd->get_xmlcmd_dhi();
172 
173  return d_xmlcmd_dhi;
174 }
175 
184 {
185  // if there is a sub command then execute the prep request on it
186  if (_sub_cmd) {
187  _sub_cmd->prep_request();
188  return;
189  }
190 
191  BESDefine *d = 0;
192 
193  if (!_space.empty()) {
194  BESDefinitionStorage *ds = BESDefinitionStorageList::TheList()->find_persistence(_space);
195  if (ds) {
196  d = ds->look_for(_definition);
197  }
198  }
199  else {
200  d = BESDefinitionStorageList::TheList()->look_for(_definition);
201  }
202 
203  if (!d) {
204  string s = (string) "Unable to find definition " + _definition;
205  throw BESSyntaxUserError(s, __FILE__, __LINE__);
206  }
207 
208  BESDefine::containers_citer i = d->first_container();
209  BESDefine::containers_citer ie = d->end_container();
210  while (i != ie) {
211  d_xmlcmd_dhi.containers.push_back(*i);
212  i++;
213  }
214 
215  d_xmlcmd_dhi.data[AGG_CMD] = d->get_agg_cmd();
216  d_xmlcmd_dhi.data[AGG_HANDLER] = d->get_agg_handler();
217 }
218 
225 void BESXMLGetCommand::dump(ostream &strm) const
226 {
227  strm << BESIndent::LMarg << "BESXMLGetCommand::dump - (" << (void *) this << ")" << endl;
228  BESIndent::Indent();
229  BESXMLCommand::dump(strm);
230  BESIndent::UnIndent();
231 }
232 
234 BESXMLGetCommand::CommandBuilder(const BESDataHandlerInterface &base_dhi)
235 {
236  return new BESXMLGetCommand(base_dhi);
237 }
238 
provides persistent storage for a specific view of different containers including contraints and aggr...
exception thrown if inernal error encountered
virtual void dump(ostream &strm) const
dumps information about this object
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:189
virtual BESDataHandlerInterface & get_xmlcmd_dhi()
returns the BESDataHandlerInterface of either a sub command, if one exists, or this command's
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:101
virtual void parse_request(xmlNode *node)=0
Parse the XML request document beginning at the given node.
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.
static p_xmlcmd_builder find_command(const std::string &cmd_str)
Find the BESXMLCommand creation function with the given name.
virtual void dump(ostream &strm) const
dumps information about this object
virtual void prep_request()
Prepare any information needed to execute the request of this command.
Definition: BESXMLCommand.h:90
virtual void prep_request()
Prepare any information needed to execute the request of this get command.
virtual void parse_basic_get(const string &type, map< string, string > &props)
Extract information from the 'props' map.
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 BESDataHandlerInterface & get_xmlcmd_dhi()
Return the current BESDataHandlerInterface.
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
std::string d_cmd_log_info
Used only for the log.
Definition: BESXMLCommand.h:62