QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgsserverogcapi.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsserverogcapi.h - QgsServerOgcApi
3 
4  ---------------------
5  begin : 10.7.2019
6  copyright : (C) 2019 by Alessandro Pasotti
7  email : elpaso at itopen dot it
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 #ifndef QGSSERVEROGCAPI_H
17 #define QGSSERVEROGCAPI_H
18 
19 #include "qgsserverapi.h"
20 #include "qgis_server.h"
21 
22 
24 
39 class SERVER_EXPORT QgsServerOgcApi : public QgsServerApi
40 {
41 
42  Q_GADGET
43 
44  public:
45 
46  // Note: non a scoped enum or qHash fails
48  enum Rel
49  {
50  // The following registered link relation types are used
54  item,
55  self,
58  prev,
59  next,
61  // In addition the following link relation types are used for which no applicable registered link relation type could be identified:
64  data
65  };
66  Q_ENUM( Rel )
67 
68  // Note: cannot be a scoped enum because qHash does not support them
71  {
75  HTML
76  };
77  Q_ENUM( ContentType )
78 
79 
87  QgsServerOgcApi( QgsServerInterface *serverIface,
88  const QString &rootPath,
89  const QString &name,
90  const QString &description = QString(),
91  const QString &version = QString() );
92 
93  // QgsServerApi interface
94  const QString name() const override { return mName; }
95  const QString description() const override { return mDescription; }
96  const QString version() const override { return mVersion; }
97  const QString rootPath() const override { return mRootPath ; }
98 
99  ~QgsServerOgcApi() override;
100 
104  virtual void executeRequest( const QgsServerApiContext &context ) const override SIP_THROW( QgsServerApiBadRequestException ) SIP_VIRTUALERRORHANDLER( serverapi_badrequest_exception_handler );
105 
110  static const QMap<QgsServerOgcApi::ContentType, QStringList> contentTypeMimes() SIP_SKIP;
111 
116  static const QHash<QgsServerOgcApi::ContentType, QList<QgsServerOgcApi::ContentType> > contentTypeAliases() SIP_SKIP;
117 
118  // Utilities
119 #ifndef SIP_RUN
120 
125  template<class T, typename... Args>
126  void registerHandler( Args... args )
127  {
128  mHandlers.emplace_back( std::make_shared<T>( args... ) );
129  }
130 #endif
131 
135  void registerHandler( QgsServerOgcApiHandler *handler SIP_TRANSFER );
136 
140  static QUrl sanitizeUrl( const QUrl &url );
141 
145  static std::string relToString( const QgsServerOgcApi::Rel &rel );
146 
150  static QString contentTypeToString( const QgsServerOgcApi::ContentType &ct );
151 
155  static std::string contentTypeToStdString( const QgsServerOgcApi::ContentType &ct );
156 
160  static QString contentTypeToExtension( const QgsServerOgcApi::ContentType &ct );
161 
165  static QgsServerOgcApi::ContentType contenTypeFromExtension( const std::string &extension );
166 
170  static std::string mimeType( const QgsServerOgcApi::ContentType &contentType );
171 
175  const std::vector<std::shared_ptr<QgsServerOgcApiHandler> > handlers() const SIP_SKIP;
176 
177  private:
178 
179  QString mRootPath;
180  QString mName;
181  QString mDescription;
182  QString mVersion;
183 
184  //Note: this cannot be unique because of SIP bindings
185  std::vector<std::shared_ptr<QgsServerOgcApiHandler>> mHandlers;
186 
188  static QMap<QgsServerOgcApi::ContentType, QStringList> sContentTypeMime;
189 
195  static QHash<QgsServerOgcApi::ContentType, QList<QgsServerOgcApi::ContentType>> sContentTypeAliases;
196 
197 };
198 
199 #endif // QGSSERVEROGCAPI_H
Server generic API endpoint abstract base class.
Definition: qgsserverapi.h:80
#define SIP_VIRTUALERRORHANDLER(name)
Definition: qgis_sip.h:177
const QString rootPath() const override
Returns the root path for the API.
Refers to a resource providing information about the link’s context.
void registerHandler(Args... args)
Registers an OGC API handler passing Args to the constructor.
The QgsServerOgcApiHandler abstract class represents a OGC API handler to be registered in QgsServerO...
Refers to a resource that is comprised of members of the collection represented by the link’s contex...
Identifies service documentation for the context that is primarily intended for human consumption...
Refers to a substitute for this context.
Indicates that the link’s context is a part of a series, and that the next in the series is the link...
const QString version() const override
Returns the version of the service.
QGIS Server OGC API endpoint.
The target IRI points to a resource that is a member of the collection represented by the context IRI...
ContentType
Media types used for content negotiation, insert more specific first.
const QString description() const override
Returns the API description.
#define SIP_SKIP
Definition: qgis_sip.h:126
Refers to a license associated with this context.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
const QString name() const override
Returns the API name.
The QgsServerApiContext class encapsulates the resources for a particular client request: the request...
Bad request error API exception.
Indicates that the link’s context is a part of a series, and that the previous in the series is the ...
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins...
Rel
Rel link types.
virtual void executeRequest(const QgsServerApiContext &context) const =0
Executes a request by passing the given context to the API handlers.
Conveys an identifier for the link’s context.
#define SIP_THROW(name)
Definition: qgis_sip.h:184
"application/openapi+json;version=3.0"
Identifies service description for the context that is primarily intended for consumption by machines...