Manual for OpenFLUID 2.1.11

FluidHubAPIClient.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID 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
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 /**
33  @file FluidHubAPIClient.hpp
34 
35  @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
36  @author Armel THONI <armel.thoni@inrae.fr>
37 */
38 
39 
40 #ifndef __OPENFLUID_UTILS_FLUIDHUBAPICLIENT_HPP__
41 #define __OPENFLUID_UTILS_FLUIDHUBAPICLIENT_HPP__
42 
43 
44 #include <set>
45 
46 #include <QString>
47 
48 #include <openfluid/dllexport.hpp>
49 #include <openfluid/ware/TypeDefs.hpp>
51 
52 
53 namespace openfluid { namespace utils {
54 
55 
57 {
58  public:
59 
61  {
62  public:
63 
64  std::string ShortDescription;
65 
66  std::string GitUrl;
67 
68  std::vector<std::string> GitBranches;
69 
70  std::map<std::string,unsigned int> IssuesCounters;
71 
72  std::set<std::string> ROUsers;
73 
74  std::set<std::string> RWUsers;
75  };
76 
77  typedef std::map<openfluid::ware::WareType,std::set<openfluid::ware::WareID_t>> WaresListByType_t;
78 
79  typedef std::map<openfluid::ware::WareID_t,WareDetailedDescription> WaresDetailsByID_t;
80 
81 
82  private:
83 
84  RESTClient m_RESTClient;
85 
86  RESTClient::SSLConfiguration m_SSLConfig;
87 
88  QString m_HubName;
89 
90  QString m_HubStatus;
91 
92  QString m_HubAPIVersion;
93 
94  bool m_IsV0ofAPI = true;
95 
96  QString m_WareCapabilityName = "wareshub";
97 
98  std::set<QString> m_HubCapabilities;
99 
100  void reset();
101 
102  bool isCapable(const QString& Capacity) const;
103 
104  static QString wareTypeToString(openfluid::ware::WareType Type);
105 
106 
107  public:
108 
109  FluidHubAPIClient() = default;
110 
112  { }
113 
114  /**
115  Connects to the FluidHub given by the URL
116  @param[in] URL the URL of the FluidHub to connect to
117  @param[in] SSLConfig the SSL configuration for the connection (if needed)
118  @return true if the connection is OK, false otherwise
119  */
120  bool connect(const QString& URL, const RESTClient::SSLConfiguration& SSLConfig = RESTClient::SSLConfiguration());
121 
122  /**
123  Disconnects from the connected FluidHub
124  */
125  void disconnect();
126 
127  /**
128  Unsets the authentication informations
129  */
130  void logout();
131 
132  /**
133  Returns true if the client is currently connected
134  @return true if connected
135  */
136  bool isConnected() const
137  {
138  return !(m_RESTClient.getBaseURL().isEmpty());
139  }
140 
141  /**
142  Returns true if the serveur uses the deprecated API (old wareshub)
143  @return true if connected
144  */
145  bool isV0ofAPI() const
146  {
147  return m_IsV0ofAPI;
148  }
149 
150  /**
151  Returns the URL of the current FluidHub
152  @return the FluidHub URL
153  */
154  QString getHubURL() const
155  {
156  return m_RESTClient.getBaseURL();
157  }
158 
159  /**
160  Returns the API version of the current FluidHub
161  @return the FluidHub API version
162  */
163  QString getHubAPIVersion() const
164  {
165  return m_HubAPIVersion;
166  }
167 
168  /**
169  Returns the status of the current FluidHub
170  @return the FluidHub status
171  */
172  QString getHubStatus() const
173  {
174  return m_HubStatus;
175  }
176 
177  /**
178  Returns the name of the current FluidHub
179  @return the FluidHub name
180  */
181  QString getHubName() const
182  {
183  return m_HubName;
184  }
185 
186  /**
187  Returns the capabilities list of the current FluidHub ("news","wareshub", ...)
188  @return the FluidHub capabilities
189  */
190  std::set<QString> getHubCapabilities() const
191  {
192  return m_HubCapabilities;
193  }
194 
195  /**
196  Returns the corresponding user unixname if connected and not deprecated API
197  @return the connected user unixname
198  */
199  std::string getUserUnixname(std::string Email, std::string Password);
200 
201  /**
202  Returns the list of all available wares in the current FluidHub
203  @return the list of wares categorized by ware type
204  */
205  WaresListByType_t getAllAvailableWares() const;
206 
207  /**
208  Returns the detailed list of all available wares in the current FluidHub
209  @param[in] Type the type of wares to list
210  @param[in] Username Optional username used in returned git URL
211  @return the detailed list of wares of the give type
212  */
213  WaresDetailsByID_t getAvailableWaresWithDetails(openfluid::ware::WareType Type,
214  const QString& Username = "") const;
215 
216  /**
217  Returns the news as an RSS string content
218  @param[in] Lang Optional lang for news content
219  @return the RSS content
220  */
221  QString getNews(const QString& Lang = "") const;
222 
223 
224 };
225 
226 
227 } } // namespaces
228 
229 
230 #endif /* __OPENFLUID_UTILS_FLUIDHUBAPICLIENT_HPP__ */
openfluid::utils::FluidHubAPIClient
Definition: FluidHubAPIClient.hpp:56
openfluid::utils::FluidHubAPIClient::WareDetailedDescription::ROUsers
std::set< std::string > ROUsers
Definition: FluidHubAPIClient.hpp:72
openfluid::utils::RESTClient::SSLConfiguration
Definition: RESTClient.hpp:113
OPENFLUID_API
#define OPENFLUID_API
Definition: dllexport.hpp:86
openfluid::utils::FluidHubAPIClient::isV0ofAPI
bool isV0ofAPI() const
Definition: FluidHubAPIClient.hpp:145
openfluid::utils::RESTClient::getBaseURL
QString getBaseURL() const
Definition: RESTClient.hpp:152
openfluid::utils::FluidHubAPIClient::isConnected
bool isConnected() const
Definition: FluidHubAPIClient.hpp:136
openfluid::ware::WareType
WareType
Definition: TypeDefs.hpp:60
openfluid::utils::FluidHubAPIClient::WareDetailedDescription::GitUrl
std::string GitUrl
Definition: FluidHubAPIClient.hpp:66
openfluid::utils::FluidHubAPIClient::WareDetailedDescription::ShortDescription
std::string ShortDescription
Definition: FluidHubAPIClient.hpp:64
RESTClient.hpp
openfluid::utils::FluidHubAPIClient::WareDetailedDescription
Definition: FluidHubAPIClient.hpp:60
openfluid::utils::FluidHubAPIClient::getHubName
QString getHubName() const
Definition: FluidHubAPIClient.hpp:181
openfluid
Definition: ApplicationException.hpp:47
openfluid::utils::FluidHubAPIClient::WaresListByType_t
std::map< openfluid::ware::WareType, std::set< openfluid::ware::WareID_t > > WaresListByType_t
Definition: FluidHubAPIClient.hpp:77
openfluid::utils::FluidHubAPIClient::WareDetailedDescription::RWUsers
std::set< std::string > RWUsers
Definition: FluidHubAPIClient.hpp:74
openfluid::utils::FluidHubAPIClient::getHubStatus
QString getHubStatus() const
Definition: FluidHubAPIClient.hpp:172
openfluid::utils::FluidHubAPIClient::getHubCapabilities
std::set< QString > getHubCapabilities() const
Definition: FluidHubAPIClient.hpp:190
openfluid::utils::FluidHubAPIClient::WareDetailedDescription::IssuesCounters
std::map< std::string, unsigned int > IssuesCounters
Definition: FluidHubAPIClient.hpp:70
openfluid::utils::FluidHubAPIClient::~FluidHubAPIClient
~FluidHubAPIClient()
Definition: FluidHubAPIClient.hpp:111
openfluid::utils::FluidHubAPIClient::getHubAPIVersion
QString getHubAPIVersion() const
Definition: FluidHubAPIClient.hpp:163
openfluid::utils::FluidHubAPIClient::WaresDetailsByID_t
std::map< openfluid::ware::WareID_t, WareDetailedDescription > WaresDetailsByID_t
Definition: FluidHubAPIClient.hpp:79
dllexport.hpp
openfluid::utils::FluidHubAPIClient::getHubURL
QString getHubURL() const
Definition: FluidHubAPIClient.hpp:154
openfluid::utils::FluidHubAPIClient::WareDetailedDescription::GitBranches
std::vector< std::string > GitBranches
Definition: FluidHubAPIClient.hpp:68
openfluid::utils::RESTClient
Definition: RESTClient.hpp:62