36#include "BESStopWatch.h"
38#include "BESSyntaxUserError.h"
39#include "BESInternalError.h"
41#include "BESContextManager.h"
43#include "RemoteResource.h"
47#include "NgapBuildDmrppContainer.h"
49#define prolog std::string("NgapBuildDmrppContainer::").append(__func__).append("() - ")
66NgapBuildDmrppContainer::NgapBuildDmrppContainer(
const string &sym_name,
const string &real_name,
const string &type) :
67 BESContainer(sym_name, real_name, type) {
71void NgapBuildDmrppContainer::initialize()
73 BESDEBUG(MODULE, prolog <<
"BEGIN (obj_addr: "<< (
void *)
this <<
")" << endl);
75 BESDEBUG(MODULE, prolog <<
"real_name: "<<
get_real_name() << endl);
85 string uid = BESContextManager::TheManager()->get_context(EDL_UID_KEY, found);
86 BESDEBUG(MODULE, prolog <<
"EDL_UID_KEY(" << EDL_UID_KEY <<
"): " << uid << endl);
93 BESDEBUG(MODULE, prolog <<
"END (obj_addr: "<< (
void *)
this <<
")" << endl);
96NgapBuildDmrppContainer::NgapBuildDmrppContainer(
const NgapBuildDmrppContainer ©_from) :
97 BESContainer(copy_from), d_data_rresource(copy_from.d_data_rresource), d_real_name(copy_from.d_real_name) {
99 BESDEBUG(MODULE, prolog <<
"BEGIN object address: "<< (
void *)
this <<
" Copying from: " << (
void *) ©_from << endl);
101 if (d_data_rresource) {
102 throw BESInternalError(
"The Container has already been accessed, cannot create a copy of this container.",
105 BESDEBUG(MODULE, prolog <<
"object address: "<< (
void *)
this << endl);
113 BESDEBUG(MODULE, prolog <<
"BEGIN object address: "<< (
void *)
this <<
" Copying to: " << (
void *) ©_to << endl);
115 if (copy_to.d_data_rresource) {
116 throw BESInternalError(
"The Container has already been accessed, cannot duplicate this resource.",
122 copy_to.d_real_name = d_real_name;
123 copy_to.d_data_rresource = d_data_rresource;
128 auto container = make_unique<NgapBuildDmrppContainer>();
130 BESDEBUG(MODULE, prolog <<
"object address: "<< (
void *)
this <<
" to: " << container.get() << endl);
131 return container.release();
140 BESDEBUG(MODULE, prolog <<
"BEGIN (obj_addr: "<< (
void *)
this <<
")" << endl);
145 BESDEBUG(MODULE, prolog <<
" data_access_url: " << data_access_url_str << endl);
147 string href=
"href=\"";
148 string trusted_url_hack= R
"(" dmrpp:trust="true")";
150 string data_access_url_key = href + DATA_ACCESS_URL_KEY +
"\"";
151 BESDEBUG(MODULE, prolog <<
" data_access_url_key: " << data_access_url_key << endl);
153 string data_access_url_with_trusted_attr_str = href + data_access_url_str + trusted_url_hack;
154 BESDEBUG(MODULE, prolog <<
" data_access_url_with_trusted_attr_str: " << data_access_url_with_trusted_attr_str << endl);
156 if (!d_data_rresource) {
157 BESDEBUG(MODULE, prolog <<
"Building new RemoteResource (dmr++)." << endl);
158 map<string, string> content_filters;
160 auto data_url(std::make_shared<http::url>(data_access_url_str,
true));
162 d_data_rresource = std::make_shared<http::RemoteResource>(data_url);
163 BES_STOPWATCH_START(MODULE, prolog +
"DMR++ retrieval: " + data_url->str());
164 d_data_rresource->retrieve_resource();
166 BESDEBUG(MODULE, prolog <<
"Retrieved remote resource: " << data_url->str() << endl);
169 string tmp_filename = d_data_rresource->get_filename();
171 BESDEBUG(MODULE, prolog <<
"Using local cache file: " << tmp_filename << endl);
172 BESDEBUG(MODULE, prolog <<
"Done retrieving: " << data_access_url_str <<
" returning cached file " << tmp_filename << endl);
173 BESDEBUG(MODULE, prolog <<
"END (obj_addr: "<< (
void *)
this <<
")" << endl);
186 strm << BESIndent::LMarg <<
"NgapBuildDmrppContainer::dump - (" << (
void *)
this <<
")" << endl;
189 if (d_data_rresource) {
190 strm << BESIndent::LMarg <<
"RemoteResource.getCacheFileName(): " << d_data_rresource->get_filename()
193 strm << BESIndent::LMarg <<
"response not yet obtained" << endl;
195 BESIndent::UnIndent();
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
void dump(std::ostream &strm) const override
dumps information about this object
void set_real_name(const std::string &real_name)
set the real name for this container, such as a file name if reading a data file.
std::string get_container_type() const
retrieve the type of data this container holds, such as cedar or netcdf.
void _duplicate(BESContainer ©_to)
duplicate this instance into the passed container
std::string get_real_name() const
retrieve the real name for this container, such as a file name.
exception thrown if internal error encountered
void _duplicate(NgapBuildDmrppContainer ©_to)
Duplicate the contents of this instance into 'copy_to.'.
std::string access() override
access the remote target response by making the remote request
BESContainer * ptr_duplicate() override
pure abstract method to duplicate this instances of BESContainer
void dump(std::ostream &strm) const override
dumps information about this object
static std::string convert_ngap_resty_path_to_data_access_url(const std::string &restified_path)
Converts an NGAP restified granule path into a CMR metadata query for the granule.