36 #include <mime_util.h> 37 #include <D4BaseTypeFactory.h> 39 #include "NCMLRequestHandler.h" 41 #include <BESConstraintFuncs.h> 42 #include <BESContainerStorage.h> 43 #include <BESContainerStorageList.h> 44 #include <BESDapNames.h> 45 #include "BESDataDDSResponse.h" 46 #include <BESDataNames.h> 47 #include <BESDASResponse.h> 48 #include <BESDDSResponse.h> 49 #include <BESDMRResponse.h> 52 #include "BESStopWatch.h" 53 #include <BESInternalError.h> 54 #include <BESDapError.h> 56 #include <BESRequestHandlerList.h> 57 #include <BESResponseHandler.h> 58 #include <BESResponseNames.h> 59 #include <BESServiceRegistry.h> 60 #include <BESTextInfo.h> 62 #include <BESVersionInfo.h> 63 #include <TheBESKeys.h> 65 #include "DDSLoader.h" 67 #include "NCMLDebug.h" 69 #include "NCMLParser.h" 70 #include "NCMLResponseNames.h" 71 #include "SimpleLocationParser.h" 77 bool NCMLRequestHandler::_global_attributes_container_name_set =
false;
78 string NCMLRequestHandler::_global_attributes_container_name =
"";
80 NCMLRequestHandler::NCMLRequestHandler(
const string &name) :
83 add_method(DAS_RESPONSE, NCMLRequestHandler::ncml_build_das);
84 add_method(DDS_RESPONSE, NCMLRequestHandler::ncml_build_dds);
85 add_method(DATA_RESPONSE, NCMLRequestHandler::ncml_build_data);
87 add_method(DMR_RESPONSE, NCMLRequestHandler::ncml_build_dmr);
88 add_method(DAP4DATA_RESPONSE, NCMLRequestHandler::ncml_build_dmr);
90 add_method(VERS_RESPONSE, NCMLRequestHandler::ncml_build_vers);
91 add_method(HELP_RESPONSE, NCMLRequestHandler::ncml_build_help);
93 if (NCMLRequestHandler::_global_attributes_container_name_set ==
false) {
94 bool key_found =
false;
99 NCMLRequestHandler::_global_attributes_container_name_set =
true;
101 NCMLRequestHandler::_global_attributes_container_name = value;
106 NCMLRequestHandler::~NCMLRequestHandler()
131 throw BESInternalError(
"couldn't find the catalog storage", __FILE__, __LINE__);
136 string new_sym = sym_name +
"_location1";
141 throw BESInternalError(
"couldn't find the container" + sym_name, __FILE__, __LINE__);
164 if (BESISDEBUG(TIMING_LOG)) sw.
start(
"NCMLRequestHandler::ncml_build_das", dhi.
data[REQUEST_ID]);
172 auto_ptr<BESDapResponse> loaded_bdds = parser.parse(filename, DDSLoader::eRT_RequestDDX);
182 DAS *das = bdas->get_das();
184 if (dds->get_dap_major() < 4)
185 NCMLUtil::hackGlobalAttributesForDAP2(dds->get_attr_table(),
186 NCMLRequestHandler::get_global_attributes_container_name());
199 if (BESISDEBUG(TIMING_LOG)) sw.
start(
"NCMLRequestHandler::ncml_build_dds", dhi.
data[REQUEST_ID]);
205 auto_ptr<BESDapResponse> loaded_bdds(0);
209 loaded_bdds = parser.parse(filename, DDSLoader::eRT_RequestDDX);
211 if (!loaded_bdds.get()) {
212 throw BESInternalError(
"Null BESDDSResonse in ncml DDS handler.", __FILE__, __LINE__);
219 BESDDSResponse *bdds_out = dynamic_cast<BESDDSResponse *>(response);
221 DDS *dds = bdds_out->
get_dds();
224 if (dds->get_dap_major() < 4)
225 NCMLUtil::hackGlobalAttributesForDAP2(dds->get_attr_table(),
226 NCMLRequestHandler::get_global_attributes_container_name());
240 dds->filename(name_path(filename));
241 dds->set_dataset_name(name_path(filename));
247 if (BESISDEBUG(TIMING_LOG)) sw.
start(
"NCMLRequestHandler::ncml_build_dds", dhi.
data[REQUEST_ID]);
253 NCML_ASSERT_MSG(ddsResponse,
254 "NCMLRequestHandler::ncml_build_data(): expected BESDDSResponse* but didn't get it!!");
260 parser.parseInto(filename, DDSLoader::eRT_RequestDDX, ddsResponse);
263 DDS *dds = ddsResponse->
get_dds();
266 if (dds->get_dap_major() < 4)
267 NCMLUtil::hackGlobalAttributesForDAP2(dds->get_attr_table(),
268 NCMLRequestHandler::get_global_attributes_container_name());
275 dds->filename(name_path(filename));
276 dds->set_dataset_name(name_path(filename));
284 if (BESISDEBUG(TIMING_LOG)) sw.
start(
"NCMLRequestHandler::ncml_build_data", dhi.
data[REQUEST_ID]);
290 NCML_ASSERT_MSG(dataResponse,
291 "NCMLRequestHandler::ncml_build_data(): expected BESDataDDSResponse* but didn't get it!!");
297 parser.parseInto(filename, DDSLoader::eRT_RequestDataDDS, dataResponse);
312 dds->filename(name_path(filename));
313 dds->set_dataset_name(name_path(filename));
321 if (BESISDEBUG(TIMING_LOG)) sw.
start(
"NCMLRequestHandler::ncml_build_dmr", dhi.
data[REQUEST_ID]);
329 auto_ptr<BESDapResponse> loaded_bdds(0);
333 loaded_bdds = parser.parse(data_path, DDSLoader::eRT_RequestDDX);
334 if (!loaded_bdds.get())
throw BESInternalError(
"Null BESDDSResonse in ncml DDS handler.", __FILE__, __LINE__);
337 dds->filename(data_path);
338 dds->set_dataset_name(data_path);
340 catch (InternalErr &e) {
341 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
344 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
350 throw BESDapError(
"Caught unknown error build ** DMR response",
true, unknown_error, __FILE__, __LINE__);
361 DMR *dmr = bdmr.get_dmr();
362 dmr->set_factory(
new D4BaseTypeFactory);
363 dmr->build_using_dds(*dds);
379 if (!info)
throw InternalErr(__FILE__, __LINE__,
"Expected a BESVersionInfo instance");
381 info->add_module(MODULE_NAME, MODULE_VERSION);
388 if (!info)
throw InternalErr(__FILE__, __LINE__,
"Expected a BESVersionInfo instance");
392 map<string, string> attrs;
393 attrs[
"name"] = MODULE_NAME;
394 attrs[
"version"] = MODULE_VERSION;
396 list<string> services;
398 if (services.size() > 0) {
400 attrs[
"handles"] = handles;
402 info->begin_tag(
"module", &attrs);
405 info->end_tag(
"module");
412 strm << BESIndent::LMarg <<
"NCMLRequestHandler::dump - (" << (
void *)
this <<
")" << endl;
415 BESIndent::UnIndent();
static void copyVariablesAndAttributesInto(libdap::DDS *dds_out, const libdap::DDS &dds_in)
provides persistent storage for data storage information represented by a container.
exception thrown if inernal error encountered
static const std::string DOC_WIKI_URL
Holds a DDS object within the BES.
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...
virtual void set_dap4_constraint(BESDataHandlerInterface &dhi)
set the constraint depending on the context
static libdap::DDS * getDDSFromEitherResponse(BESDapResponse *response)
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
virtual bool start(string name)
virtual void dump(ostream &strm) const
dumps information about this object
virtual BESContainerStorage * find_persistence(const std::string &persist_name)
find the persistence store with the given name
virtual BESContainer * look_for(const std::string &sym_name)=0
looks for a container in this persistent store
virtual string access()=0
returns the true name of this container
virtual void set_dap4_function(BESDataHandlerInterface &dhi)
set the constraint depending on the context
informational response object
static string implode(const list< string > &values, char delim)
virtual BESResponseObject * get_response_object()
return the current response object
Abstract exception class for the BES with basic string message.
static TheBESKeys * TheKeys()
virtual bool del_container(const std::string &s_name)=0
removes a container with the given symbolic name
Provides a mechanism for accessing container information from different container stores registered w...
virtual void set_constraint(BESDataHandlerInterface &dhi)
set the constraint depending on the context
Represents an OPeNDAP DMR DAP4 data object within the BES.
error object created from libdap error objects and can handle those errors
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
Represents a specific data type request handler.
static void populateDASFromDDS(libdap::DAS *das, const libdap::DDS &dds_const)
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 void execute_current(BESDataHandlerInterface &dhi)
Execute a single method for the current container that will fill in the response object rather than i...
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 void add_data(const string &s)
add data to this informational object. If buffering is not set then the information is output directl...
Represents an OPeNDAP DAS DAP2 data object within the BES.
A container is something that holds data. E.G., a netcdf file or a database entry.
Abstract base class representing a specific set of information in response to a request to the BES.
static const std::string NCML_NAME
BESContainer * container
pointer to current container in this interface
virtual void services_handled(const string &handler, list< string > &services)
returns the list of servies provided by the handler in question
string get_symbolic_name() const
retrieve the symbolic name for this container