bes  Updated for version 3.20.6
ShowNodeCommand.cc
1 // ShowNodeCommand.cc
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2018 OPeNDAP, Inc
7 // Author: James Gallagher <jgallagher@opendap.org>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24 
25 #include "config.h"
26 
27 #include "BESContainerStorageList.h"
28 
29 #include "BESNames.h"
30 #include "BESDataNames.h"
31 #include "BESXMLUtils.h"
32 #include "BESUtil.h"
33 #include "BESSyntaxUserError.h"
34 #include "BESDebug.h"
35 
36 #include "ShowNodeCommand.h"
37 
38 using std::endl;
39 using std::ostream;
40 using std::string;
41 using std::map;
42 
43 using namespace bes;
44 
45 ShowNodeCommand::ShowNodeCommand(const BESDataHandlerInterface &base_dhi) :
46  BESXMLCommand(base_dhi)
47 {
48 }
49 
71 void ShowNodeCommand::parse_request(xmlNode *node)
72 {
73  string name;
74  string value;
75  map<string, string> props;
76  BESXMLUtils::GetNodeInfo(node, name, value, props);
77  if (name != NODE_RESPONSE_STR) {
78  string err = "The specified command " + name + " is not a showNode command";
79  throw BESSyntaxUserError(err, __FILE__, __LINE__);
80  }
81 
82  // the action is the same for show catalog and show info
83  d_xmlcmd_dhi.action = NODE_RESPONSE;
84 
85  d_cmd_log_info = "show node";
86 
87  // node is an optional property, so could be empty string
88  d_xmlcmd_dhi.data[CONTAINER] = props["node"];
89 
90  if (!d_xmlcmd_dhi.data[CONTAINER].empty()) {
91  d_cmd_log_info.append(" for ").append(d_xmlcmd_dhi.data[CONTAINER]);
92  }
93 
94  // catalog is an optional property, so could be empty string
95  // Dropped this because the catalog name is going to be in the path. ndp 8/8/18
96  // d_xmlcmd_dhi.data[CATALOG] = props["catalog"];
97 
98  if (!d_xmlcmd_dhi.data[CATALOG].empty()) {
99  d_cmd_log_info.append(" in catalog ").append(d_xmlcmd_dhi.data[CATALOG]);
100  }
101 
102  d_cmd_log_info += ";";
103 
104  // Get the response handler for the action (dhi.action == show.node)
105  set_response();
106 }
107 
114 void ShowNodeCommand::dump(ostream &strm) const
115 {
116  strm << BESIndent::LMarg << "ShowNodeCommand::dump - (" << (void *) this << ")" << endl;
117  BESIndent::Indent();
118  BESXMLCommand::dump(strm);
119  BESIndent::UnIndent();
120 }
121 
131 {
132  return new ShowNodeCommand(base_dhi);
133 }
134 
bes::ShowNodeCommand
Definition: ShowNodeCommand.h:34
BESXMLCommand::d_cmd_log_info
std::string d_cmd_log_info
Used only for the log.
Definition: BESXMLCommand.h:74
BESDataHandlerInterface::action
std::string action
the response object requested, e.g. das, dds
Definition: BESDataHandlerInterface.h:79
BESXMLCommand::set_response
virtual void set_response()
The request has been parsed, use the command action name to set the response handler.
Definition: BESXMLCommand.cc:63
BESXMLUtils::GetNodeInfo
static void GetNodeInfo(xmlNode *node, std::string &name, std::string &value, std::map< std::string, std::string > &props)
get the name, value if any, and any properties for the specified node
Definition: BESXMLUtils.cc:105
bes::ShowNodeCommand::CommandBuilder
static BESXMLCommand * CommandBuilder(const BESDataHandlerInterface &base_dhi)
A command builder suitable for BESXMLCommand::add_command()
Definition: ShowNodeCommand.cc:130
BESXMLCommand::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESXMLCommand.cc:119
bes::ShowNodeCommand::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: ShowNodeCommand.cc:114
BESSyntaxUserError
error thrown if there is a user syntax error in the request or any other user error
Definition: BESSyntaxUserError.h:41
BESDataHandlerInterface::data
std::map< std::string, std::string > data
the map of string data that will be required for the current request.
Definition: BESDataHandlerInterface.h:90
BESXMLCommand
Base class for the BES's commands.
Definition: BESXMLCommand.h:63
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:56