40#include "CmrInternalError.h"
41#include "CmrNotFoundError.h"
48#define prolog std::string("Granule::").append(__func__).append("() - ")
148 setName(granule_json);
149 setSize(granule_json);
150 setDapServiceUrl(granule_json);
151 setDataGranuleUrl(granule_json);
152 setMetadataAccessUrl(granule_json);
153 setLastModifiedStr(granule_json);
157void Granule::setName(
const nlohmann::json& granule_json)
160 d_name = json.get_str_if_present(CMR_V2_TITLE_KEY, granule_json);
164void Granule::setId(
const nlohmann::json& granule_json)
167 d_id = json.get_str_if_present(CMR_GRANULE_ID_KEY, granule_json);
171void Granule::setSize(
const nlohmann::json& granule_json)
174 d_size_str = json.get_str_if_present(CMR_GRANULE_SIZE_KEY, granule_json);
182void Granule::setLastModifiedStr(
const nlohmann::json& granule_json)
185 d_last_modified_time = json.get_str_if_present(CMR_GRANULE_LMT_KEY, granule_json);
192const nlohmann::json& Granule::get_links_array(
const nlohmann::json& granule_json)
const
195 return json.qc_get_array(CMR_GRANULE_LINKS_KEY, granule_json);
203void Granule::setDataGranuleUrl(
const nlohmann::json& granule_json)
205 const auto& links = get_links_array(granule_json);
206 for(
auto &link : links){
207 string rel = link[CMR_GRANULE_LINKS_REL].get<
string>();
208 if(rel == CMR_GRANULE_LINKS_REL_DATA_ACCESS){
209 d_data_access_url = link[CMR_GRANULE_LINKS_HREF];
214 msg <<
"ERROR: Failed to locate granule data access link (";
215 msg << CMR_GRANULE_LINKS_REL_DATA_ACCESS <<
"), :(";
216 throw CmrInternalError(msg.str(), __FILE__, __LINE__);
222void Granule::setDapServiceUrl(
const nlohmann::json& granule_json)
225 BESDEBUG(MODULE, prolog <<
"JSON: " << endl << granule_json.dump(4) << endl);
226 const auto& links = get_links_array(granule_json);
227 for(
auto &link : links){
228 string rel = json.get_str_if_present(CMR_GRANULE_LINKS_REL,link);
229 if (rel == CMR_GRANULE_LINKS_REL_SERVICE) {
231 string title = json.get_str_if_present(CMR_V2_TITLE_KEY,link);
233 transform(title.begin(), title.end(), title.begin(), ::toupper);
234 if (title.find(
"OPENDAP") != string::npos) {
236 d_dap_service_url = json.get_str_if_present(CMR_GRANULE_LINKS_HREF, link);
242 msg <<
"Failed to locate DAP service link (";
243 msg << CMR_GRANULE_LINKS_REL_SERVICE <<
"), :(";
244 BESDEBUG(MODULE, prolog << msg.str() << endl);
251void Granule::setMetadataAccessUrl(
const nlohmann::json& granule_json)
253 const auto &links = get_links_array(granule_json);
254 for(
auto &link : links){
255 string rel = link[CMR_GRANULE_LINKS_REL].get<
string>();
256 if(rel == CMR_GRANULE_LINKS_REL_METADATA_ACCESS){
257 d_metadata_access_url = link[CMR_GRANULE_LINKS_HREF].get<
string>();
262 msg <<
"ERROR: Failed to locate granule metadata access link (";
263 msg << CMR_GRANULE_LINKS_REL_METADATA_ACCESS <<
"), :(";
264 throw CmrInternalError(msg.str(), __FILE__, __LINE__);
267size_t Granule::getSize()
const {
268 double value = strtod(getSizeStr().c_str(),
nullptr);
270 return static_cast<size_t>(value);
275bes::CatalogItem *Granule::getCatalogItem(
const BESCatalogUtils *d_catalog_utils)
const
277 auto *item =
new bes::CatalogItem();
278 item->set_type(bes::CatalogItem::leaf);
279 item->set_name(getName());
280 item->set_lmt(getLastModifiedStr());
281 item->set_size(getSize());
282 item->set_is_data(d_catalog_utils->
is_data(item->get_name()));
283 if(!getDapServiceUrl().empty()) {
284 item->set_dap_service_url(getDapServiceUrl());
bool is_data(const std::string &item) const
is there a handler that can process this
Granule(const nlohmann::json &granule_json)