34#include <libdap/DMR.h>
35#include <libdap/DataDDS.h>
37#include <libdap/mime_util.h>
38#include <libdap/D4BaseTypeFactory.h>
40#include "NCMLRequestHandler.h"
42#include <BESConstraintFuncs.h>
43#include <BESContainerStorage.h>
44#include <BESContainerStorageList.h>
45#include <BESDapNames.h>
46#include "BESDataDDSResponse.h"
47#include <BESDataNames.h>
48#include <BESDASResponse.h>
49#include <BESDDSResponse.h>
50#include <BESDMRResponse.h>
53#include "BESStopWatch.h"
54#include <BESInternalError.h>
55#include <BESDapError.h>
57#include <BESRequestHandlerList.h>
58#include <BESResponseHandler.h>
59#include <BESResponseNames.h>
60#include <BESServiceRegistry.h>
61#include <BESTextInfo.h>
63#include <BESVersionInfo.h>
64#include <TheBESKeys.h>
70#include "NCMLParser.h"
71#include "NCMLResponseNames.h"
72#include "SimpleLocationParser.h"
78bool NCMLRequestHandler::_global_attributes_container_name_set =
false;
79string NCMLRequestHandler::_global_attributes_container_name;
81NCMLRequestHandler::NCMLRequestHandler(
const string &name) :
84 add_method(DAS_RESPONSE, NCMLRequestHandler::ncml_build_das);
85 add_method(DDS_RESPONSE, NCMLRequestHandler::ncml_build_dds);
86 add_method(DATA_RESPONSE, NCMLRequestHandler::ncml_build_data);
88 add_method(DMR_RESPONSE, NCMLRequestHandler::ncml_build_dmr);
89 add_method(DAP4DATA_RESPONSE, NCMLRequestHandler::ncml_build_dmr);
91 add_method(VERS_RESPONSE, NCMLRequestHandler::ncml_build_vers);
92 add_method(HELP_RESPONSE, NCMLRequestHandler::ncml_build_help);
94 if (NCMLRequestHandler::_global_attributes_container_name_set ==
false) {
95 bool key_found =
false;
100 NCMLRequestHandler::_global_attributes_container_name_set =
true;
102 NCMLRequestHandler::_global_attributes_container_name = value;
107NCMLRequestHandler::~NCMLRequestHandler()
132 throw BESInternalError(
"couldn't find the catalog storage", __FILE__, __LINE__);
137 string new_sym = sym_name +
"_location1";
142 throw BESInternalError(
"couldn't find the container" + sym_name, __FILE__, __LINE__);
173 unique_ptr<BESDapResponse> loaded_bdds = parser.parse(filename, DDSLoader::eRT_RequestDDX);
183 DAS *das = bdas->get_das();
185 if (dds->get_dap_major() < 4)
186 NCMLUtil::hackGlobalAttributesForDAP2(dds->get_attr_table(),
187 NCMLRequestHandler::get_global_attributes_container_name());
206 unique_ptr<BESDapResponse> loaded_bdds(0);
210 loaded_bdds = parser.parse(filename, DDSLoader::eRT_RequestDDX);
212 if (!loaded_bdds.get()) {
213 throw BESInternalError(
"Null BESDDSResonse in ncml DDS handler.", __FILE__, __LINE__);
222 DDS *dds = bdds_out->
get_dds();
225 if (dds->get_dap_major() < 4)
226 NCMLUtil::hackGlobalAttributesForDAP2(dds->get_attr_table(),
227 NCMLRequestHandler::get_global_attributes_container_name());
241 dds->filename(name_path(filename));
242 dds->set_dataset_name(name_path(filename));
254 NCML_ASSERT_MSG(ddsResponse,
255 "NCMLRequestHandler::ncml_build_data(): expected BESDDSResponse* but didn't get it!!");
261 parser.parseInto(filename, DDSLoader::eRT_RequestDDX, ddsResponse);
264 DDS *dds = ddsResponse->
get_dds();
267 if (dds->get_dap_major() < 4)
268 NCMLUtil::hackGlobalAttributesForDAP2(dds->get_attr_table(),
269 NCMLRequestHandler::get_global_attributes_container_name());
276 dds->filename(name_path(filename));
277 dds->set_dataset_name(name_path(filename));
291 NCML_ASSERT_MSG(dataResponse,
292 "NCMLRequestHandler::ncml_build_data(): expected BESDataDDSResponse* but didn't get it!!");
298 parser.parseInto(filename, DDSLoader::eRT_RequestDataDDS, dataResponse);
313 dds->filename(name_path(filename));
314 dds->set_dataset_name(name_path(filename));
330 unique_ptr<BESDapResponse> loaded_bdds;
334 loaded_bdds = parser.parse(data_path, DDSLoader::eRT_RequestDDX);
335 if (!loaded_bdds.get())
throw BESInternalError(
"Null BESDDSResonse in the NCML DDS handler.", __FILE__, __LINE__);
338 dds->filename(data_path);
339 dds->set_dataset_name(data_path);
341 catch (InternalErr &e) {
342 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
345 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
351 throw BESDapError(
"Caught unknown error build ** DMR response",
true, unknown_error, __FILE__, __LINE__);
362 DMR *dmr = bdmr.get_dmr();
363 dmr->set_factory(
new D4BaseTypeFactory);
364 dmr->build_using_dds(*dds);
380 if (!info)
throw InternalErr(__FILE__, __LINE__,
"Expected a BESVersionInfo instance");
382 info->add_module(MODULE_NAME, MODULE_VERSION);
389 if (!info)
throw InternalErr(__FILE__, __LINE__,
"Expected a BESVersionInfo instance");
393 map<string, string> attrs;
394 attrs[
"name"] = MODULE_NAME;
395 attrs[
"version"] = MODULE_VERSION;
397 list<string> services;
399 if (services.size() > 0) {
401 attrs[
"handles"] = handles;
403 info->begin_tag(
"module", &attrs);
406 info->end_tag(
"module");
413 strm << BESIndent::LMarg <<
"NCMLRequestHandler::dump - (" << (
void *)
this <<
")" << endl;
416 BESIndent::UnIndent();
Provides a mechanism for accessing container information from different container stores registered w...
virtual BESContainerStorage * find_persistence(const std::string &persist_name)
find the persistence store with the given name
provides persistent storage for data storage information represented by a container.
virtual bool del_container(const std::string &s_name)=0
removes a container with the given symbolic name
virtual void add_container(const std::string &sym_name, const std::string &real_name, const std::string &type)=0
adds a container with the provided information
virtual BESContainer * look_for(const std::string &sym_name)=0
looks for a container in this persistent store
A container is something that holds data. E.G., a netcdf file or a database entry.
std::string get_symbolic_name() const
retrieve the symbolic name for this container
virtual std::string access()=0
returns the true name of this container
Represents an OPeNDAP DAS DAP2 data object within the BES.
Holds a DDS object within the BES.
Represents an OPeNDAP DMR DAP4 data object within the BES.
error object created from libdap error objects and can handle those errors
virtual void set_dap4_function(BESDataHandlerInterface &dhi)
set the constraint depending on the context
virtual void set_dap4_constraint(BESDataHandlerInterface &dhi)
set the constraint depending on the context
virtual void set_constraint(BESDataHandlerInterface &dhi)
set the constraint depending on the context
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
Structure storing information used by the BES to handle the request.
std::map< std::string, std::string > data
the map of string data that will be required for the current request.
BESContainer * container
pointer to current container in this interface
static bool IsSet(const std::string &flagName)
see if the debug context flagName is set to true
Base exception class for the BES with basic string message.
informational response object
virtual void add_data(const std::string &s)
add data to this informational object. If buffering is not set then the information is output directl...
exception thrown if internal error encountered
virtual void execute_current(BESDataHandlerInterface &dhi)
Execute a single method for the current container that will fill in the response object rather than i...
Represents a specific data type request handler.
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual BESResponseObject * get_response_object()
return the current response object
Abstract base class representing a specific set of information in response to a request to the BES.
virtual void services_handled(const std::string &handler, std::list< std::string > &services)
returns the list of servies provided by the handler in question
virtual bool start(std::string name)
static std::string implode(const std::list< std::string > &values, char delim)
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
static TheBESKeys * TheKeys()
virtual void dump(std::ostream &strm) const
dumps information about this object
static libdap::DDS * getDDSFromEitherResponse(BESDapResponse *response)
static void populateDASFromDDS(libdap::DAS *das, const libdap::DDS &dds_const)
static void copyVariablesAndAttributesInto(libdap::DDS *dds_out, const libdap::DDS &dds_in)
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...
static const std::string DOC_WIKI_URL
static const std::string NCML_NAME