35#include "rjson_utils.h"
45#define prolog std::string("Granule::").append(__func__).append("() - ")
49string granule_LINKS_REL_DATA_ACCES =
"http://esipfed.org/ns/fedsearch/1.1/data#";
50string granule_LINKS_REL_METADATA_ACCESS =
"http://esipfed.org/ns/fedsearch/1.1/data#";
51string granule_LINKS =
"links";
52string granule_LINKS_REL=
"rel";
53string granule_LINKS_HREFLANG =
"hreflang";
54string granule_LINKS_HREF =
"href";
55string granule_SIZE =
"granule_size";
56string granule_LMT =
"updated";
58string granule_ID =
"id";
60string granule_NAME =
"title";
62Granule::Granule(
const rapidjson::Value& granule_obj){
66 setDataAccessUrl(granule_obj);
67 setMetadataAccessUrl(granule_obj);
68 setLastModifiedStr(granule_obj);
71void Granule::setName(
const rapidjson::Value& go){
73 this->d_name = rju.getStringValue(go, granule_NAME);
76void Granule::setId(
const rapidjson::Value& go){
78 this->d_id = rju.getStringValue(go, granule_ID);
81void Granule::setSize(
const rapidjson::Value& go){
83 this->d_size_str = rju.getStringValue(go, granule_SIZE);
89void Granule::setLastModifiedStr(
const rapidjson::Value& go){
91 this->d_last_modified_time = rju.getStringValue(go, granule_LMT);
97const rapidjson::Value& Granule::get_links_array(
const rapidjson::Value& go){
100 bool result = itr != go.MemberEnd();
101 string msg = prolog + (result?
"Located":
"FAILED to locate") +
" the value '"+granule_LINKS+
"' in object.";
102 BESDEBUG(MODULE, msg << endl);
104 throw CmrError(
"ERROR: Failed to located '"+granule_LINKS+
"' section for CMRGranule!",__FILE__,__LINE__);
106 const rapidjson::Value& links = itr->value;
108 throw CmrError(
"ERROR: The '"+granule_LINKS+
"' object is NOT an array!",__FILE__,__LINE__);
116void Granule::setDataAccessUrl(
const rapidjson::Value& go){
119 const rapidjson::Value& links = get_links_array(go);
120 for (rapidjson::SizeType i = 0; i < links.Size(); i++) {
121 const rapidjson::Value& link = links[i];
122 string rel = rju.getStringValue(link,granule_LINKS_REL);
123 if(rel == granule_LINKS_REL_DATA_ACCES){
124 this->d_data_access_url = rju.getStringValue(link,granule_LINKS_HREF);
128 throw CmrError(
"ERROR: Failed to locate granule data access link ("+granule_LINKS_REL_DATA_ACCES+
"). :(",__FILE__,__LINE__);
134void Granule::setMetadataAccessUrl(
const rapidjson::Value& go){
137 const rapidjson::Value& links = get_links_array(go);
138 for (rapidjson::SizeType i = 0; i < links.Size(); i++) {
139 const rapidjson::Value& link = links[i];
140 string rel = rju.getStringValue(link,granule_LINKS_REL);
141 if(rel == granule_LINKS_REL_METADATA_ACCESS){
142 this->d_metadata_access_url = rju.getStringValue(link,granule_LINKS_HREF);
146 throw CmrError(
"ERROR: Failed to locate granule metadata access link ("+granule_LINKS_REL_METADATA_ACCESS+
"). :(",__FILE__,__LINE__);
152 item->
set_type(bes::CatalogItem::leaf);
154 item->
set_lmt(getLastModifiedStr());
bool is_data(const std::string &item) const
is there a handler that can process this
(Constant) member iterator for a JSON object value
void set_name(std::string n)
Set the name of the item.
std::string get_name() const
The name of this item in the node.
void set_size(size_t s)
Set the size of the item.
void set_is_data(bool id)
Is this item data that the BES should interpret?
void set_lmt(std::string lmt)
Set the LMT for this item.
void set_type(item_type t)
Set the type for this item.