OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
CSVRequestHandler.cc
Go to the documentation of this file.
1 // CSVRequestHandler.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: Stephan Zednik <zednik@ucar.edu> and Patrick West <pwest@ucar.edu>
8 // and Jose Garcia <jgarcia@ucar.edu>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 // You can contact University Corporation for Atmospheric Research at
25 // 3080 Center Green Drive, Boulder, CO 80301
26 
27 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
28 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
29 //
30 // Authors:
31 // zednik Stephan Zednik <zednik@ucar.edu>
32 // pwest Patrick West <pwest@ucar.edu>
33 // jgarcia Jose Garcia <jgarcia@ucar.edu>
34 
35 #include "config.h"
36 
37 #include <DDS.h>
38 #include <DAS.h>
39 #include <BaseTypeFactory.h>
40 #include <Ancillary.h>
41 
42 #include <DMR.h>
43 #include <D4BaseTypeFactory.h>
44 #include <mime_util.h>
45 #include <InternalErr.h>
46 
47 #include <BESDASResponse.h>
48 #include <BESDDSResponse.h>
49 #include <BESDataDDSResponse.h>
50 #include <BESDMRResponse.h>
51 
52 #include <BESInfo.h>
53 #include <BESContainer.h>
54 #include <BESVersionInfo.h>
55 #include <BESDataNames.h>
56 #include <BESDapNames.h>
57 #include <BESResponseHandler.h>
58 #include <BESResponseNames.h>
59 #include <BESVersionInfo.h>
60 #include <BESTextInfo.h>
61 #include <BESConstraintFuncs.h>
62 #include <BESDapError.h>
63 #include <BESDebug.h>
64 
65 #include "CSVDDS.h"
66 #include "CSVDAS.h"
67 #include "CSVRequestHandler.h"
68 
70  BESRequestHandler(name)
71 {
75 
76  // We can use the same DMR object for both the metadata and data
77  // responses. jhrg 8/13/14
80 
83 }
84 
86 {
87 }
88 
90 {
91  string error;
92  bool ret = true;
94  BESDASResponse *bdas = dynamic_cast<BESDASResponse *>(response);
95  DAS *das = 0;
96  if (bdas)
97  das = bdas->get_das();
98  else
99  throw BESInternalError("cast error", __FILE__, __LINE__);
100 
101  try {
102  string accessed = dhi.container->access();
103  csv_read_attributes(*das, accessed);
104  Ancillary::read_ancillary_das(*das, accessed);
105  return ret;
106  }
107  catch (InternalErr &e) {
108  throw BESDapError(e.get_error_message(), true, e.get_error_code(), __FILE__, __LINE__);
109  }
110  catch (Error &e) {
111  throw BESDapError(e.get_error_message(), false, e.get_error_code(), __FILE__, __LINE__);
112  }
113  catch (...) {
114  throw BESDapError("Caught unknown error build CSV DAS response", true, unknown_error, __FILE__, __LINE__);
115  }
116 }
117 
119 {
120  bool ret = true;
122  BESDDSResponse *bdds = dynamic_cast<BESDDSResponse *>(response);
123  DDS *dds = 0;
124  if (bdds)
125  dds = bdds->get_dds();
126  else
127  throw BESInternalError("cast error", __FILE__, __LINE__);
128 
129  BaseTypeFactory *factory = new BaseTypeFactory;
130  dds->set_factory(factory);
131 
132  try {
133  string accessed = dhi.container->access();
134  dds->filename(accessed);
135  csv_read_descriptors(*dds, accessed);
136  Ancillary::read_ancillary_dds(*dds, accessed);
137 
138  DAS das;
139  csv_read_attributes(das, accessed);
140  Ancillary::read_ancillary_das(das, accessed);
141  dds->transfer_attributes(&das);
142 
143  bdds->set_constraint(dhi);
144  return ret;
145  }
146  catch (InternalErr &e) {
147  throw BESDapError(e.get_error_message(), true, e.get_error_code(), __FILE__, __LINE__);
148  }
149  catch (Error &e) {
150  throw BESDapError(e.get_error_message(), false, e.get_error_code(), __FILE__, __LINE__);
151  }
152  catch (...) {
153  throw BESDapError("Caught unknown error build CSV DDS response", true, unknown_error, __FILE__, __LINE__);
154  }
155 }
156 
158 {
159  bool ret = true;
161  BESDataDDSResponse *bdds = dynamic_cast<BESDataDDSResponse *>(response);
162  DataDDS *dds = 0;
163  if (bdds)
164  dds = bdds->get_dds();
165  else
166  throw BESInternalError("cast error", __FILE__, __LINE__);
167 
168  BaseTypeFactory *factory = new BaseTypeFactory;
169  dds->set_factory(factory);
170 
171  try {
172  string accessed = dhi.container->access();
173  dds->filename(accessed);
174  csv_read_descriptors(*dds, accessed);
175  Ancillary::read_ancillary_dds(*dds, accessed);
176 
177  DAS das;
178  csv_read_attributes(das, accessed);
179  Ancillary::read_ancillary_das(das, accessed);
180  dds->transfer_attributes(&das);
181 
182  bdds->set_constraint(dhi);
183  return ret;
184  }
185  catch (InternalErr &e) {
186  throw BESDapError(e.get_error_message(), true, e.get_error_code(), __FILE__, __LINE__);
187  }
188  catch (Error &e) {
189  throw BESDapError(e.get_error_message(), false, e.get_error_code(), __FILE__, __LINE__);
190  }
191  catch (...) {
192  throw BESDapError("Caught unknown error build CSV DataDDS response", true, unknown_error, __FILE__, __LINE__);
193  }
194 }
195 
205 {
206  // Because this code does not yet know how to build a DMR directly, use
207  // the DMR ctor that builds a DMR using a 'full DDS' (a DDS with attributes).
208  // First step, build the 'full DDS'
209  string data_path = dhi.container->access();
210 
211  BaseTypeFactory factory;
212  DDS dds(&factory, name_path(data_path), "3.2");
213  dds.filename(data_path);
214 
215  try {
216  csv_read_descriptors(dds, data_path);
217  // ancillary DDS objects never took off - this does nothing. jhrg 8/12/14
218  // Ancillary::read_ancillary_dds(*dds, data_path);
219 
220  DAS das;
221  csv_read_attributes(das, data_path);
222  Ancillary::read_ancillary_das(das, data_path);
223  dds.transfer_attributes(&das);
224  }
225  catch (InternalErr &e) {
226  throw BESDapError(e.get_error_message(), true, e.get_error_code(), __FILE__, __LINE__);
227  }
228  catch (Error &e) {
229  throw BESDapError(e.get_error_message(), false, e.get_error_code(), __FILE__, __LINE__);
230  }
231  catch (...) {
232  throw BESDapError("Caught unknown error build CSV DMR response", true, unknown_error, __FILE__, __LINE__);
233  }
234 
235  // Second step, make a DMR using the DDS
236 
237  // Extract the DMR Response object - this holds the DMR used by the
238  // other parts of the framework.
240  BESDMRResponse &bdmr = dynamic_cast<BESDMRResponse &>(*response);
241 
242  // Extract the DMR Response object - this holds the DMR used by the
243  // other parts of the framework.
244  DMR *dmr = bdmr.get_dmr();
245  dmr->set_factory(new D4BaseTypeFactory);
246  dmr->build_using_dds(dds);
247 
248  // Instead of fiddling with the internal storage of the DHI object,
249  // (by setting dhi.data[DAP4_CONSTRAINT], etc., directly) use these
250  // methods to set the constraints. But, why? Maybe setting data[]
251  // directly is better? jhrg 8/14/14
252  bdmr.set_dap4_constraint(dhi);
253  bdmr.set_dap4_function(dhi);
254 
255  // What about async and store_result? See BESDapTransmit::send_dap4_data()
256 
257  return true;
258 }
259 
261 {
262  bool ret = true;
263 
265  BESVersionInfo *info = dynamic_cast<BESVersionInfo *>(response);
266  if (!info) throw BESInternalError("cast error", __FILE__, __LINE__);
267 
268  info->add_module(MODULE_NAME, MODULE_VERSION);
269  return ret;
270 }
271 
273 {
274  bool ret = true;
275  BESInfo *info = dynamic_cast<BESInfo *>(dhi.response_handler->get_response_object());
276  if (!info) throw BESInternalError("cast error", __FILE__, __LINE__);
277 
278  map<string, string> attrs;
279  attrs["name"] = PACKAGE_NAME;
280  attrs["version"] = PACKAGE_VERSION;
281  string handles = (string) DAS_RESPONSE + "," + DDS_RESPONSE + "," + DATA_RESPONSE + "," + HELP_RESPONSE + ","
282  + VERS_RESPONSE;
283  attrs["handles"] = handles;
284  info->begin_tag("module", &attrs);
285  info->end_tag("module");
286 
287  return ret;
288 }
289 
290 void CSVRequestHandler::dump(ostream &strm) const
291 {
292  strm << BESIndent::LMarg << "CSVRequestHandler::dump - (" << (void *) this << ")" << endl;
296 }
297 
static bool csv_build_dds(BESDataHandlerInterface &dhi)
brief represents simple text information in a response object, such as version and help inforamtion...
#define DAP4DATA_RESPONSE
Definition: BESDapNames.h:86
exception thrown if inernal error encountered
#define DMR_RESPONSE
Definition: BESDapNames.h:81
CSVRequestHandler(string name)
Represents an OPeNDAP DDS DAP2 data object within the BES.
virtual void dump(ostream &strm) const
dumps information about this object
static bool csv_build_vers(BESDataHandlerInterface &dhi)
virtual void set_dap4_constraint(BESDataHandlerInterface &dhi)
set the constraint depending on the context
static void Indent()
Definition: BESIndent.cc:38
virtual string access()=0
returns the true name of this container
#define HELP_RESPONSE
virtual void set_dap4_function(BESDataHandlerInterface &dhi)
set the constraint depending on the context
informational response object
Definition: BESInfo.h:68
virtual BESResponseObject * get_response_object()
return the current response object
#define PACKAGE_NAME
Definition: config.h:244
#define DATA_RESPONSE
Definition: BESDapNames.h:70
BESResponseHandler * response_handler
static bool csv_build_dmr(BESDataHandlerInterface &dhi)
This method is used to respond to both the DMR and DAP requests because the DMR holds data (I did not...
virtual void set_constraint(BESDataHandlerInterface &dhi)
set the constraint depending on the context
virtual void begin_tag(const string &tag_name, map< string, string > *attrs=0)
Definition: BESInfo.cc:127
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
Represents an OPeNDAP DMR DAP4 data object within the BES.
error object created from libdap error objects and can handle those errors
Definition: BESDapError.h:51
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
void csv_read_attributes(DAS &das, const string &filename)
Definition: CSVDAS.cc:48
static bool csv_build_data(BESDataHandlerInterface &dhi)
Represents a specific data type request handler.
static bool csv_build_das(BESDataHandlerInterface &dhi)
void csv_read_descriptors(DDS &dds, const string &filename)
Definition: CSVDDS.cc:60
virtual ~CSVRequestHandler(void)
Structure storing information used by the BES to handle the request.
#define VERS_RESPONSE
virtual bool add_handler(const string &handler_name, p_request_handler handler_method)
add a handler method to the request handler that knows how to fill in a specific response object ...
#define PACKAGE_VERSION
Definition: config.h:256
Represents an OPeNDAP DAS DAP2 data object within the BES.
static void UnIndent()
Definition: BESIndent.cc:44
virtual void dump(ostream &strm) const
dumps information about this object
static bool csv_build_help(BESDataHandlerInterface &dhi)
virtual void add_module(const string &n, const string &v)
Abstract base class representing a specific set of information in response to a request to the BES...
#define DDS_RESPONSE
Definition: BESDapNames.h:60
BESContainer * container
pointer to current container in this interface
#define DAS_RESPONSE
Definition: BESDapNames.h:55
virtual void end_tag(const string &tag_name)
Definition: BESInfo.cc:132