bes  Updated for version 3.20.6
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 using std::endl;
51 using std::ostream;
52 using std::string;
53 using std::map;
54 
55 BESXMLSetContainerCommand::BESXMLSetContainerCommand(const BESDataHandlerInterface &base_dhi) :
56  BESXMLCommand(base_dhi)
57 {
58 }
59 
69 {
70  string action; // name of the node, should be setContainer
71  // string name; // symbolic name of the container as name=""
72  // string storage; // storage of container, default is default, as space=
73  string value; // real name of the container, e.g. path
74 
75  map<string, string> props;
76  BESXMLUtils::GetNodeInfo(node, action, value, props);
77  if (action != SETCONTAINER_STR) {
78  throw BESInternalError(string("The specified command ").append(action).append(" is not a set container command."), __FILE__, __LINE__);
79  }
80 
81  if (value.empty())
82  throw BESSyntaxUserError(action + " command: container real name missing", __FILE__, __LINE__);
83 
84  // what is the symbolic name of this container
85  if (props["name"].empty())
86  throw BESSyntaxUserError(action + " command: name property missing", __FILE__, __LINE__);
87 
88  d_xmlcmd_dhi.data[SYMBOLIC_NAME] = props["name"];
89 
90  // Is the path (i.e., the 'value') of this command in a virtual directory?
91  // If so, use the corresponding catalog name as the value of the 'space'
92  // attribute, overriding what the client may have sent.
93  //
94  // @TODO Really? seems odd. I'd expect the opposite behavior - use what was given
95  // and set the space using the catalog name if 'space' was not provided. jhrg 1/7/19
96  BESCatalog *cat = BESUtil::separateCatalogFromPath(value);
97  if (cat) {
98  if (!props["space"].empty())
99  VERBOSE("SetContainer called with 'space=\"" << props["space"] << "\" but the pathname uses \"" << cat->get_catalog_name() << "\"");
100  props["space"] = cat->get_catalog_name();
101  }
102 
103  if (!props["space"].empty()) {
104  d_xmlcmd_dhi.data[STORE_NAME] = props["space"];
105  }
106  else {
107  d_xmlcmd_dhi.data[STORE_NAME] = CATALOG /* DEFAULT jhrg 12/27/18 */; // CATALOG == "catalog"; DEFAULT == "default"
108  }
109 
110  // 'type' can be empty (not used), so just set it this way
111  d_xmlcmd_dhi.data[CONTAINER_TYPE] = props["type"];
112 
113  // now that everything has passed tests, set the value in the dhi
114  d_xmlcmd_dhi.data[REAL_NAME] = value;
115 
116  d_xmlcmd_dhi.action = SETCONTAINER;
117 
118  d_cmd_log_info = (string) "set container in " + props["space"] + " values " + props["name"] + "," + value;
119  if (!props["type"].empty()) {
120  d_cmd_log_info += "," + props["type"];
121  }
122  d_cmd_log_info += ";";
123 
124  // now that we've set the action, go get the response handler for the action.
125  // The class the evaluates this command is dispatch/BESSetContainerresponseHandler.
127 }
128 
135 void BESXMLSetContainerCommand::dump(ostream &strm) const
136 {
137  strm << BESIndent::LMarg << "BESXMLSetContainerCommand::dump - (" << (void *) this << ")" << endl;
138  BESIndent::Indent();
139  BESXMLCommand::dump(strm);
140  BESIndent::UnIndent();
141 }
142 
144 BESXMLSetContainerCommand::CommandBuilder(const BESDataHandlerInterface &base_dhi)
145 {
146  return new BESXMLSetContainerCommand(base_dhi);
147 }
148 
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
BESCatalog::get_catalog_name
virtual std::string get_catalog_name() const
Get the name for this catalog.
Definition: BESCatalog.h:103
BESXMLCommand::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESXMLCommand.cc:119
BESXMLSetContainerCommand::parse_request
virtual void parse_request(xmlNode *node)
parse a set container command.
Definition: BESXMLSetContainerCommand.cc:68
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
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
BESInternalError
exception thrown if internal error encountered
Definition: BESInternalError.h:43
BESXMLSetContainerCommand::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESXMLSetContainerCommand.cc:135
BESCatalog
Catalogs provide a hierarchical organization for data.
Definition: BESCatalog.h:51
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:56