src/terralib/ws/ogc/wcs/dataaccess/DataSource.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/ws/ogc/wcs-dataaccess/DataSource.cpp
22 
23  \brief Data Source for WS OGC WCS
24 
25  \author Vinicius Campanha
26 */
27 
28 // TerraLib
29 #include "../../../../common/StringUtils.h"
30 #include "../../../../core/translator/Translator.h"
31 #include "../../../../core/uri/URI.h"
32 #include "../../../../core/uri/Utils.h"
33 #include "../../../../dataaccess/datasource/DataSourceTransactor.h"
34 #include "../../../core/Exception.h"
35 #include "DataSource.h"
36 #include "Exception.h"
37 #include "Transactor.h"
38 
39 
41 
43  : te::da::DataSource(connInfo),
44  m_isOpened(false)
45 {
46 }
47 
49  : te::da::DataSource(uri),
50  m_isOpened(false)
51 {
52 }
53 
55 
57 {
59 }
60 
61 std::unique_ptr<te::da::DataSourceTransactor> te::ws::ogc::wcs::da::DataSource::getTransactor()
62 {
63  if(!m_isOpened)
64  throw Exception(TE_TR("The data source is not opened!"));
65 
66  return std::unique_ptr<te::da::DataSourceTransactor>(new Transactor(m_wcs));
67 }
68 
70 {
71  if(m_isOpened)
72  return;
73 
75 
76  try
77  {
78  std::map<std::string, std::string> kvp = te::core::Expand(m_uri.query());
79 
80  m_wcs = std::shared_ptr<te::ws::ogc::WCSClient>(new te::ws::ogc::WCSClient(kvp["USERDATADIR"], kvp["URI"], kvp["VERSION"]));
81 
82  m_wcs->updateCapabilities();
83  }
84  catch(const te::ws::core::Exception&)
85  {
86  throw;
87  }
88  catch(...)
89  {
90  throw Exception(TE_TR("Unknow error!"));
91  }
92 
93  m_isOpened = true;
94 }
95 
97 {
98  m_isOpened = false;
99 }
100 
102 {
103  return m_isOpened;
104 }
105 
107 {
108  if(m_isOpened)
109  return true;
110 
111  try
112  {
114 
115  std::map<std::string, std::string> kvp = te::core::Expand(m_uri.query());
116 
117  te::ws::ogc::WCSClient wcs(kvp["USERDATADIR"], kvp["URI"], kvp["VERSION"]);
118 
119  wcs.updateCapabilities();
120  }
121  catch(...)
122  {
123  return false;
124  }
125 
126  return true;
127 }
128 
130 {
131  return sm_capabilities;
132 }
133 
135 {
137 }
138 
140 {
141  return nullptr;
142 }
143 
144 std::shared_ptr<te::ws::ogc::WCSClient> te::ws::ogc::wcs::da::DataSource::getWCSClient() const
145 {
146  return m_wcs;
147 }
148 
149 void te::ws::ogc::wcs::da::DataSource::create(const std::string& /*connInfo*/)
150 {
151  throw Exception(TE_TR("The create() method is not supported by the WCS driver!"));
152 }
153 
154 void te::ws::ogc::wcs::da::DataSource::drop(const std::string& /*connInfo*/)
155 {
156  throw Exception(TE_TR("The drop() method is not supported by the WCS driver!"));
157 }
158 
159 bool te::ws::ogc::wcs::da::DataSource::exists(const std::string& connInfo)
160 {
161  if (connInfo.empty())
162  return false;
163 
164  const te::core::URI aux(connInfo);
165  if (!aux.isValid())
166  return false;
167 
168  std::map<std::string, std::string> kvp = te::core::Expand(m_uri.query());
169  std::map<std::string, std::string>::const_iterator it = kvp.begin();
170  std::map<std::string, std::string>::const_iterator itend = kvp.end();
171  std::string usrDataDir, version, uri;
172 
173  it = kvp.find("USERDATADIR");
174  if (it == itend || it->second.empty())
175  return false;
176  else
177  usrDataDir = it->second;
178 
179  it = kvp.find("VERSION");
180  if (it == itend || it->second.empty())
181  return false;
182  else
183  version = it->second;
184 
185  it = kvp.find("URI");
186  if (it == itend || it->second.empty())
187  return false;
188  else
189  uri = it->second;
190 
191  try
192  {
194 
195  te::ws::ogc::WCSClient wcs(usrDataDir, uri, version);
196 
197  wcs.updateCapabilities();
198  }
199  catch(...)
200  {
201  return false;
202  }
203 
204  return true;
205 }
206 
207 std::vector<std::string> te::ws::ogc::wcs::da::DataSource::getDataSourceNames(const std::string& /*connInfo*/)
208 {
209  return std::vector<std::string>();
210 }
211 
212 std::vector<te::core::EncodingType> te::ws::ogc::wcs::da::DataSource::getEncodings(const std::string& /*connInfo*/)
213 {
214  return std::vector<te::core::EncodingType>();
215 }
216 
218 {
219  if(!m_uri.isValid())
220  throw Exception(TE_TR("The connection information is invalid!"));
221 
222  std::map<std::string, std::string> kvp = te::core::Expand(m_uri.query());
223  std::map<std::string, std::string>::const_iterator it = kvp.begin();
224  std::map<std::string, std::string>::const_iterator itend = kvp.end();
225 
226  it = kvp.find("URI");
227  if (it == itend || it->second.empty())
228  throw Exception(TE_TR("The connection information is invalid. Missing URI parameter!"));
229 
230  it = kvp.find("VERSION");
231  if (it == itend || it->second.empty())
232  throw Exception(TE_TR("The connection information is invalid. Missing VERSION parameter!"));
233 
234  it = kvp.find("USERDATADIR");
235  if (it == itend || it->second.empty())
236  throw Exception(TE_TR("The connection information is invalid. Missing USERDATADIR parameter!"));
237 }
Implementation of the data source for the WCS driver.
std::string getType() const
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS, or MYSQL.
bool exists(const std::string &connInfo)
Check the existence of a data source in a driver.
Base exception class for plugin module.
#define TE_OGC_WCS_DRIVER_IDENTIFIER
The OGC WCS driver identifier string.
Data Source for WS OGC WCS.
It represents the SQL query dialect accepted by a given data source.
Definition: SQLDialect.h:55
const te::da::DataSourceCapabilities & getCapabilities() const
It returns the known capabilities of the data source.
bool isValid() const
It checks if the data source is valid (available for using).
void create(const std::string &connInfo)
It creates a new data source.
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
bool isValid() const
Return if the given URI is valid or not.
Definition: URI.cpp:133
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
void open()
It opens the data source and makes it ready for using.
std::string query() const
Retrieving the query.
Definition: URI.cpp:123
std::shared_ptr< te::ws::ogc::WCSClient > getWCSClient() const
bool isOpened() const
It returns true if the data source is opened, otherwise it returns false.
void updateCapabilities()
Method to get the capabilities from a WCS server and store in m_capabilities member.
Definition: WCSClient.cpp:92
te::da::DataSourceCapabilities capabilities
URI C++ Library.
Definition: Attributes.h:37
void close()
It closes the data source and clears all the resources used by its internal communication channel...
A class to retrieve information and data from a Web Coverage Service.
Definition: WCSClient.h:58
static void setCapabilities(const te::da::DataSourceCapabilities &capabilities)
Base exception class for WS Core Runtime Library.
A class for representing an Uniform Resource Identifier (URI).
Definition: URI.h:49
std::vector< te::core::EncodingType > getEncodings(const std::string &connInfo)
te::core::URI m_uri
The URI used to describe the datasource connection;.
TECOREEXPORT std::map< std::string, std::string > Expand(const std::string &query_str)
Split a query string into its components.
Exception classes for the WS Core Runtime Library.
~DataSource()
Virtual destructor.
std::unique_ptr< te::da::DataSourceTransactor > getTransactor()
It returns the set of parameters used to set up the access channel to the underlying repository...
void drop(const std::string &connInfo)
It removes the data source with the connection information from a driver.
std::vector< std::string > getDataSourceNames(const std::string &connInfo)
It gets the data source names available in a driver.
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
Implementation of the transactor for the WCS driver.
Implementation of the transactor for the WS OGC WCS.