37 #include <ConstraintEvaluator.h>
41 #include <D4ConstraintEvaluator.h>
43 #include <InternalErr.h>
46 #include <mime_util.h>
88 BESDEBUG(
"ascii",
"BESAsciiTransmit::send_base_ascii; modified" << endl);
92 ConstraintEvaluator &ce = bdds->
get_ce();
97 BESDEBUG(
"ascii",
"parsing constraint: " << constraint << endl);
107 BESDEBUG(
"ascii",
"BESAsciiTransmit::send_base_ascii - Found function(s) in CE: " << rb.
get_btp_func_ce() << endl);
112 ConstraintEvaluator func_eval;
116 if (responseCache()) {
117 BESDEBUG(
"ascii",
"BESAsciiTransmit::send_base_ascii - Using the cache for the server function CE" << endl);
121 BESDEBUG(
"ascii",
"BESAsciiTransmit::send_base_ascii - Cache not found; (re)calculating" << endl);
122 func_eval.parse_constraint(get_btp_func_ce(), dds);
123 fdds = func_eval.eval_function_clauses(dds);
127 DataDDS *fdds = func_eval.eval_function_clauses(*dds);
134 fdds->mark_all(
false);
136 ce.parse_constraint(rb.
get_ce(), *fdds);
138 fdds->tag_nested_sequences();
140 int response_size_limit = dds->get_response_limit();
141 if (response_size_limit != 0 && fdds->get_request_size(
true) > response_size_limit) {
142 string msg =
"The Request for " + long_to_string(fdds->get_request_size(
true) / 1024)
143 +
"KB is too large; requests for this user are limited to "
144 + long_to_string(response_size_limit / 1024) +
"KB.";
157 if (!store_dap2_result(data_stream, dds, eval)) {
158 serialize_dap2_data_dds(data_stream, *fdds, eval,
true );
161 if (responseCache()) responseCache()->unlock_and_close(cache_token);
165 BESDEBUG(
"ascii",
"BESAsciiTransmit::send_base_ascii - Simple constraint" << endl);
167 ce.parse_constraint(rb.
get_ce(), *dds);
169 dds->tag_nested_sequences();
171 if (dds->get_response_limit() != 0 && dds->get_request_size(
true) > dds->get_response_limit()) {
172 string msg =
"The Request for " + long_to_string(dds->get_request_size(
true) / 1024)
173 +
"KB is too large; requests for this user are limited to "
174 + long_to_string(dds->get_response_limit() / 1024) +
"KB.";
180 if (!store_dap2_result(data_stream, dds, eval)) {
181 serialize_dap2_data_dds(data_stream, dds, eval);
186 for (DDS::Vars_iter i = dds->var_begin(); i != dds->var_end(); i++) {
187 if ((*i)->send_p()) {
188 BESDEBUG(
"ascii",
"BESAsciiTransmit::send_base_ascii; call to intern_data() for '" << (*i)->name() <<
"'" << endl);
189 (*i)->intern_data(ce, *dds);
203 catch (InternalErr &e) {
204 throw BESDapError(
"Failed to get values as ascii: " + e.get_error_message(),
true, e.get_error_code(), __FILE__,
208 throw BESDapError(
"Failed to get values as ascii: " + e.get_error_message(),
false, e.get_error_code(),
212 throw BESInternalFatalError(
"Failed to get values as ascii: Unknown exception caught", __FILE__, __LINE__);
220 BESDEBUG(
"ascii",
"BESAsciiTransmit::send_base_ascii" << endl);
223 DataDDS *dds = bdds->
get_dds();
224 ConstraintEvaluator & ce = bdds->
get_ce();
229 BESDEBUG(
"ascii",
"parsing constraint: " << constraint << endl);
236 ce.parse_constraint(constraint, *dds);
238 catch (InternalErr &e) {
239 throw BESDapError(
"Failed to parse the constraint expression: " + e.get_error_message(),
true,
240 e.get_error_code(), __FILE__, __LINE__);
243 throw BESDapError(
"Failed to parse the constraint expression: " + e.get_error_message(),
false,
244 e.get_error_code(), __FILE__, __LINE__);
247 throw BESInternalFatalError(
"Failed to parse the constraint expression: Unknown exception caught", __FILE__,
251 dds->tag_nested_sequences();
257 if (ce.function_clauses()) {
258 BESDEBUG(
"ascii",
"processing a functional constraint clause(s)." << endl);
268 DataDDS *new_dds = ce.eval_function_clauses(*dds);
274 BESDEBUG(
"ascii",
"processing normal constraint." << endl);
277 for (DDS::Vars_iter i = dds->var_begin(); i != dds->var_end(); i++) {
278 if ((*i)->send_p()) {
279 (**i).intern_data(ce, *dds);
285 catch (InternalErr &e) {
286 throw BESDapError(
"Failed to read data: " + e.get_error_message(),
true, e.get_error_code(), __FILE__,
290 throw BESDapError(
"Failed to read data: " + e.get_error_message(),
false, e.get_error_code(), __FILE__,
307 catch (InternalErr &e) {
308 throw BESDapError(
"Failed to get values as ascii: " + e.get_error_message(),
true, e.get_error_code(), __FILE__,
312 throw BESDapError(
"Failed to get values as ascii: " + e.get_error_message(),
false, e.get_error_code(),
316 throw BESInternalFatalError(
"Failed to get values as ascii: Unknown exception caught", __FILE__, __LINE__);
326 BESDEBUG(
"ascii",
"BESAsciiTransmit::send_dap4_csv" << endl);
345 if (!dap4Constraint.empty()) {
346 D4ConstraintEvaluator d4ce(dmr);
347 d4ce.parse(dap4Constraint);
350 dmr->root()->set_send_p(
true);
356 catch (InternalErr &e) {
357 throw BESDapError(
"Failed to return values as ascii: " + e.get_error_message(),
true, e.get_error_code(),
361 throw BESDapError(
"Failed to return values as ascii: " + e.get_error_message(),
false, e.get_error_code(),
365 throw BESInternalFatalError(
"Failed to return values as ascii: Unknown exception caught", __FILE__, __LINE__);
368 BESDEBUG(
"ascii",
"Done BESAsciiTransmit::send_dap4_csv" << endl);
void get_data_values_as_ascii(DataDDS *dds, ostream &strm)
Using the AsciiOutput::print_ascii(), write the data values to an output file/stream as ASCII...
virtual std::string get_ce() const
Return the entire DAP2 constraint expression in a string.
void set_dds(DataDDS *ddsIn)
Set the response object's DDS.
exception thrown if an internal error is found and is fatal to the BES
virtual std::string get_btp_func_ce() const
virtual libdap::DDS * cache_dataset(libdap::DDS &dds, const std::string &constraint, BESDapResponseBuilder *rb, libdap::ConstraintEvaluator *eval, std::string &cache_token)
Get the cached DDS object.
ostream & get_output_stream()
virtual bool add_method(string method_name, p_transmitter trans_method)
static void send_basic_ascii(BESResponseObject *obj, BESDataHandlerInterface &dhi)
DataDDS * datadds_to_ascii_datadds(DataDDS *dds)
virtual BESDapResponseCache * responseCache()
Lazy getter for the ResponseCache.
virtual void split_ce(libdap::ConstraintEvaluator &eval, const std::string &expr="")
Split the CE so that the server functions that compute new values are separated into their own string...
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.
static void send_dap4_csv(BESResponseObject *obj, BESDataHandlerInterface &dhi)
Transmits DAP4 Data as Comma Separated Values.
ConstraintEvaluator & get_ce()
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.
This class is used to build responses for/by the BES.
void first_container()
set the container pointer to the first container in the containers list
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
void print_values_as_ascii(DMR *dmr, ostream &strm)
For each variable in the DMR, write out the CSV/ASCII representation for it's data.
Abstract base class representing a specific set of information in response to a request to the BES...