37#include "nlohmann/json.hpp"
44#include "CmrInternalError.h"
45#include "GranuleUMM.h"
51#define prolog std::string("GranuleUMM::").append(__func__).append("() - ")
62 BESDEBUG(MODULE, prolog <<
"BEGIN" << endl << granule_umm_json.dump(2) << endl);
63 setConceptId(granule_umm_json);
64 setName(granule_umm_json);
65 setSize(granule_umm_json);
66 setDapServiceUrl(granule_umm_json);
67 setDataGranuleUrl(granule_umm_json);
68 setLastModifiedStr(granule_umm_json);
69 setDescription(granule_umm_json);
73void GranuleUMM::setName(
const nlohmann::json& granule_umm_json)
76 const auto &umm_obj = json.
qc_get_object(CMR_UMM_UMM_KEY, granule_umm_json);
77 this->d_name = json.get_str_if_present(CMR_UMM_GRANULE_UR_KEY, umm_obj);
84void GranuleUMM::setDescription(
const nlohmann::json& )
89void GranuleUMM::setConceptId(
const nlohmann::json& granule_umm_json)
92 const auto &meta_obj = json.qc_get_object(CMR_UMM_META_KEY, granule_umm_json);
94 BESDEBUG(MODULE, prolog <<
"META OBJECT" << endl << json.probe_json(meta_obj) << endl);
96 this->d_id = json.get_str_if_present(CMR_UMM_CONCEPT_ID_KEY, meta_obj);
108void GranuleUMM::setSize(
const nlohmann::json& granule_umm_json)
111 const auto &umm_obj = json.qc_get_object(CMR_UMM_UMM_KEY, granule_umm_json);
112 const auto &data_granule_obj = json.qc_get_object(CMR_UMM_DATA_GRANULE_KEY, umm_obj);
113 BESDEBUG(MODULE, prolog << CMR_UMM_DATA_GRANULE_KEY << data_granule_obj.dump(2) << endl );
114 const auto &arch_and_info_array = json.qc_get_array(CMR_UMM_ARCHIVE_AND_DIST_INFO_KEY, data_granule_obj);
149 for(
const auto &entry : arch_and_info_array){
150 BESDEBUG(MODULE, prolog << CMR_UMM_ARCHIVE_AND_DIST_INFO_KEY << entry.dump(2) << endl );
151 string name = json.get_str_if_present(CMR_UMM_NAME_KEY,entry);
152 BESDEBUG(MODULE, prolog << CMR_UMM_NAME_KEY <<
": " << name << endl );
157 BESDEBUG(MODULE, prolog <<
"Detected MD5 hash file: " << name <<
" SKIPPING." << endl);
160 d_size_orig = json.qc_double(CMR_UMM_SIZE_KEY, entry);
161 BESDEBUG(MODULE, prolog <<
"d_size_orig: " << d_size_orig << endl );
163 d_size_units_str = json.get_str_if_present(CMR_UMM_SIZE_UNIT_KEY, entry).c_str();
164 std::transform(d_size_units_str.begin(), d_size_units_str.end(),d_size_units_str.begin(), ::toupper);
165 BESDEBUG(MODULE, prolog <<
"d_size_units_str: " << d_size_units_str << endl );
167 if(d_size_units_str.empty()){
168 BESDEBUG(MODULE, prolog <<
"Size content is incomplete. size: " << d_size_str <<
" units: " << d_size_units_str << endl );
175 if(d_size_units_str ==
"KB"){
178 if(d_size_units_str ==
"MB"){
179 size *= 1024ULL*1024ULL;
181 else if (d_size_units_str==
"GB"){
182 size *= 1024ULL*1024ULL*1024ULL;
184 else if (d_size_units_str==
"TB"){
185 size *= 1024ULL*1024ULL*1024ULL*1024ULL;
187 d_size =
static_cast<uint64_t
>(size);
189 BESDEBUG(MODULE, prolog <<
"d_size: " << d_size <<
" bytes" << endl );
200void GranuleUMM::setLastModifiedStr(
const nlohmann::json& granule_umm_json)
203 const auto &umm_obj = json.qc_get_object(CMR_UMM_META_KEY, granule_umm_json);
204 this->d_last_modified_time = json.get_str_if_present(CMR_UMM_REVISION_DATE_KEY, umm_obj);
211void GranuleUMM::setDataGranuleUrl(
const nlohmann::json& granule_umm_json)
214 const auto& umm_obj = json.qc_get_object(CMR_UMM_UMM_KEY, granule_umm_json);
215 const auto& related_urls = json.qc_get_array(CMR_UMM_RELATED_URLS_KEY, umm_obj);
216 for(
auto &url_obj : related_urls){
217 string url = json.get_str_if_present(CMR_UMM_URL_KEY, url_obj);
218 string type = json.get_str_if_present(CMR_UMM_TYPE_KEY, url_obj);
219 if(type == CMR_UMM_TYPE_GET_DATA_VALUE){
220 this->d_data_access_url = url;
225 msg <<
"ERROR: Failed to locate Data Granule URL (";
226 msg << CMR_UMM_RELATED_URLS_KEY <<
"). json: " << endl << related_urls.dump(2) << endl;
227 BESDEBUG(MODULE, prolog << msg.str() << endl);
248void GranuleUMM::setDapServiceUrl(
const nlohmann::json& granule_umm_json)
250 const std::string DAP2_HTML_SUFFIX(
".html");
251 const std::string DAP4_HTML_SUFFIX(
".dmr.html");
254 const auto& umm_obj = json.qc_get_object(CMR_UMM_UMM_KEY, granule_umm_json);
255 const auto& related_urls = json.qc_get_array(CMR_UMM_RELATED_URLS_KEY, umm_obj);
256 for(
auto &related_url_obj : related_urls){
257 string url = json.get_str_if_present(CMR_UMM_URL_KEY,related_url_obj);
258 string type = json.get_str_if_present(CMR_UMM_TYPE_KEY,related_url_obj);
259 string subtype = json.get_str_if_present(CMR_UMM_SUBTYPE_KEY,related_url_obj);
260 bool is_dap_service = ((type == CMR_UMM_TYPE_USE_SERVICE_API_VALUE || type == CMR_UMM_TYPE_GET_DATA_VALUE)
261 && subtype == CMR_UMM_SUBTYPE_KEY_OPENDAP_DATA_VALUE);
266 url = url.substr(0,url.length() - DAP2_HTML_SUFFIX.length());
269 url = url.substr(0,url.length() - DAP4_HTML_SUFFIX.length());
271 d_dap_service_url = url;
276 msg <<
"ERROR: Failed to locate DAP service URL (";
277 msg << CMR_UMM_RELATED_URLS_KEY <<
"). json: " << endl << related_urls.dump(2) << endl;
278 BESDEBUG(MODULE, prolog << msg.str() << endl);
289 item->set_type(bes::CatalogItem::leaf);
290 item->set_name(getName());
291 item->set_lmt(getLastModifiedStr());
292 item->set_size(getSize());
293 item->set_description(getDescription());
295 if(!getDapServiceUrl().empty()) {
296 item->set_dap_service_url(getDapServiceUrl());
298 bool is_data = d_catalog_utils->
is_data(item->get_name()) || !getDapServiceUrl().empty();
299 item->set_is_data(is_data);
bool is_data(const std::string &item) const
is there a handler that can process this
static bool endsWith(std::string const &fullString, std::string const &ending)
bes::CatalogItem * getCatalogItem(const BESCatalogUtils *d_catalog_utils)
GranuleUMM(const nlohmann::json &granule_umm_json)
const nlohmann::json & qc_get_object(const std::string &key, const nlohmann::json &json_obj) const