bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
CatalogItem.cc
1// -*- mode: c++; c-basic-offset:4 -*-
2
3// This file is part of the OPeNDAP Back-End Server (BES)
4
5// Copyright (c) 2018 OPeNDAP, Inc.
6// Author: James Gallagher <jgallagher@opendap.org>
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Lesser General Public
10// License as published by the Free Software Foundation; either
11// version 2.1 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// Lesser General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public
19// License along with this library; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21//
22// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
23
24#include "config.h"
25
26#include <string>
27#include <ostream>
28#include <sstream>
29
30#include "BESDebug.h"
31#include "BESInfo.h"
32#include "BESIndent.h"
33
34#include "CatalogItem.h"
35
36using namespace bes;
37using namespace std;
38
39#define MODULE "cat"
40#define prolog std::string("CatalogItem::").append(__func__).append("() - ")
41
42#define CATALOG_NAME_KEY "name"
43#define CATALOG_TYPE_KEY "type"
44#define CATALOG_LMT_KEY "lastModified"
45#define CATALOG_SIZE_KEY "size"
46#define CATALOG_IS_DATA_KEY "isData"
47#define CATALOG_DAP_URL_KEY "dap_url"
48#define CATALOG_ITEM_TAG "item"
49#define CATALOG_DESCRIPTION_KEY "description"
50
66{
67 map<string, string, std::less<>> props;
68
69 props[CATALOG_NAME_KEY] = get_name();
70 props[CATALOG_TYPE_KEY] = get_type() == leaf ? "leaf": "node";
71 props[CATALOG_LMT_KEY] = get_lmt();
72 if (get_type() == leaf) {
73 ostringstream oss;
74 oss << get_size();
75 props[CATALOG_SIZE_KEY] = oss.str();
76 props[CATALOG_IS_DATA_KEY] = is_data() ? "true" : "false";
77 string dap_service_url = get_dap_service_url();
78 BESDEBUG(MODULE,prolog << "dap_service_url: " << dap_service_url << endl );
79 if(!dap_service_url.empty()){
80 props[CATALOG_DAP_URL_KEY] = dap_service_url;
81 }
82 }
83
84 info->begin_tag(CATALOG_ITEM_TAG, &props);
85 string description = get_description();
86 if(!description.empty()){
87 map<string, string, std::less<>> description_props;
88 info->begin_tag(CATALOG_DESCRIPTION_KEY, &description_props);
89 info->add_data(description);
90 info->end_tag(CATALOG_DESCRIPTION_KEY);
91 }
92
93 info->end_tag(CATALOG_ITEM_TAG);
94
95#if 0
96 // TODO Should we support the serviceRef element? jhrg 7/22/18
97 list<string> services = entry->get_service_list();
98 if (services.size()) {
99 list<string>::const_iterator si = services.begin();
100 list<string>::const_iterator se = services.end();
101 for (; si != se; si++) {
102 info->add_tag("serviceRef", (*si));
103 }
104 }
105#endif
106
107}
108
109
114void CatalogItem::dump(ostream &strm) const
115{
116 strm << BESIndent::LMarg << "CatalogItem::dump - (" << (void *) this << ")" << endl;
117 BESIndent::Indent();
118
119 strm << BESIndent::LMarg << "name: " << d_name << endl;
120 strm << BESIndent::LMarg << "size: " << d_size << endl;
121 strm << BESIndent::LMarg << "last modified time: " << d_lmt << endl;
122 strm << BESIndent::LMarg << "is_data: " << d_is_data << endl;
123 strm << BESIndent::LMarg << "type: " << d_type << endl;
124
125 BESIndent::UnIndent();
126}
informational response object
Definition BESInfo.h:63
virtual void add_data(const std::string &s)
add data to this informational object. If buffering is not set then the information is output directl...
Definition BESInfo.cc:151
void encode_item(BESInfo *info) const
Encode this CatalogItem in an info object.
std::string get_name() const
The name of this item in the node.
bool is_data() const
Is this item recognized as data?
size_t get_size() const
The size (bytes) of the item.
std::string get_dap_service_url() const
The DAP Dataset URL for an external DAP service.
virtual void dump(std::ostream &strm) const
std::string get_description() const
The descrtiption of this item.
std::string get_lmt() const
Get the last modified time for this item.
item_type get_type() const
Get the type of this item (unknown, node or leaf)
STL iterator class.