bes  Updated for version 3.20.5
BESXMLSetContainerCommand.cc
1 // BESXMLSetContainerCommand.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) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
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 University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 #include "config.h"
34 
35 #include "BESXMLSetContainerCommand.h"
36 #include "BESContainerStorageList.h"
37 #include "BESCatalog.h"
38 
39 #include "BESXMLUtils.h"
40 #include "BESUtil.h"
41 
42 #include "BESResponseNames.h"
43 #include "BESDataNames.h"
44 
45 #include "BESSyntaxUserError.h"
46 #include "BESInternalError.h"
47 #include "BESLog.h"
48 #include "BESDebug.h"
49 
50 BESXMLSetContainerCommand::BESXMLSetContainerCommand(const BESDataHandlerInterface &base_dhi) :
51  BESXMLCommand(base_dhi)
52 {
53 }
54 
64 {
65  string action; // name of the node, should be setContainer
66  // string name; // symbolic name of the container as name=""
67  // string storage; // storage of container, default is default, as space=
68  string value; // real name of the container, e.g. path
69 
70  map<string, string> props;
71  BESXMLUtils::GetNodeInfo(node, action, value, props);
72  if (action != SETCONTAINER_STR) {
73  throw BESInternalError(string("The specified command ").append(action).append(" is not a set container command."), __FILE__, __LINE__);
74  }
75 
76  if (value.empty())
77  throw BESSyntaxUserError(action + " command: container real name missing", __FILE__, __LINE__);
78 
79  // what is the symbolic name of this container
80  if (props["name"].empty())
81  throw BESSyntaxUserError(action + " command: name property missing", __FILE__, __LINE__);
82 
83  d_xmlcmd_dhi.data[SYMBOLIC_NAME] = props["name"];
84 
85  // Is the path (i.e., the 'value') of this command in a virtual directory?
86  // If so, use the corresponding catalog name as the value of the 'space'
87  // attribute, overriding what the client may have sent.
88  //
89  // @TODO Really? seems odd. I'd expect the opposite behavior - use what was given
90  // and set the space using the catalog name if 'space' was not provided. jhrg 1/7/19
91  BESCatalog *cat = BESUtil::separateCatalogFromPath(value);
92  if (cat) {
93  if (!props["space"].empty())
94  VERBOSE("SetContainer called with 'space=\"" << props["space"] << "\" but the pathname uses \"" << cat->get_catalog_name() << "\"");
95  props["space"] = cat->get_catalog_name();
96  }
97 
98  if (!props["space"].empty()) {
99  d_xmlcmd_dhi.data[STORE_NAME] = props["space"];
100  }
101  else {
102  d_xmlcmd_dhi.data[STORE_NAME] = CATALOG /* DEFAULT jhrg 12/27/18 */; // CATALOG == "catalog"; DEFAULT == "default"
103  }
104 
105  // 'type' can be empty (not used), so just set it this way
106  d_xmlcmd_dhi.data[CONTAINER_TYPE] = props["type"];
107 
108  // now that everything has passed tests, set the value in the dhi
109  d_xmlcmd_dhi.data[REAL_NAME] = value;
110 
111  d_xmlcmd_dhi.action = SETCONTAINER;
112 
113  d_cmd_log_info = (string) "set container in " + props["space"] + " values " + props["name"] + "," + value;
114  if (!props["type"].empty()) {
115  d_cmd_log_info += "," + props["type"];
116  }
117  d_cmd_log_info += ";";
118 
119  // now that we've set the action, go get the response handler for the action.
120  // The class the evaluates this command is dispatch/BESSetContainerresponseHandler.
122 }
123 
130 void BESXMLSetContainerCommand::dump(ostream &strm) const
131 {
132  strm << BESIndent::LMarg << "BESXMLSetContainerCommand::dump - (" << (void *) this << ")" << endl;
133  BESIndent::Indent();
134  BESXMLCommand::dump(strm);
135  BESIndent::UnIndent();
136 }
137 
139 BESXMLSetContainerCommand::CommandBuilder(const BESDataHandlerInterface &base_dhi)
140 {
141  return new BESXMLSetContainerCommand(base_dhi);
142 }
143 
BESXMLUtils::GetNodeInfo
static void GetNodeInfo(xmlNode *node, string &name, string &value, map< string, string > &props)
get the name, value if any, and any properties for the specified node
Definition: BESXMLUtils.cc:101
BESXMLCommand::d_cmd_log_info
std::string d_cmd_log_info
Used only for the log.
Definition: BESXMLCommand.h:74
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:58
BESCatalog::get_catalog_name
virtual std::string get_catalog_name() const
Get the name for this catalog.
Definition: BESCatalog.h:103
BESXMLSetContainerCommand::parse_request
virtual void parse_request(xmlNode *node)
parse a set container command.
Definition: BESXMLSetContainerCommand.cc:63
BESXMLCommand::dump
virtual void dump(ostream &strm) const
dumps information about this object
Definition: BESXMLCommand.cc:114
BESXMLSetContainerCommand
Parse the setContainer element in a request document.
Definition: BESXMLSetContainerCommand.h:54
BESSyntaxUserError
error thrown if there is a user syntax error in the request or any other user error
Definition: BESSyntaxUserError.h:41
BESXMLCommand
Base class for the BES's commands.
Definition: BESXMLCommand.h:63
BESInternalError
exception thrown if inernal error encountered
Definition: BESInternalError.h:43
BESDataHandlerInterface::action
string action
the response object requested, e.g. das, dds
Definition: BESDataHandlerInterface.h:83
BESCatalog
Catalogs provide a hierarchical organization for data.
Definition: BESCatalog.h:51
BESDataHandlerInterface::data
map< string, string > data
the map of string data that will be required for the current request.
Definition: BESDataHandlerInterface.h:94
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:60
BESXMLSetContainerCommand::dump
virtual void dump(ostream &strm) const
dumps information about this object
Definition: BESXMLSetContainerCommand.cc:130