QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
48 class SERVER_EXPORT QgsServerOgcApi : public QgsServerApi
49 {
50 
51  Q_GADGET
52 
53  public:
54 
55  // Note: non a scoped enum or qHash fails
57  enum Rel
58  {
59  // The following registered link relation types are used
63  item,
64  self,
67  prev,
68  next,
70  // In addition the following link relation types are used for which no applicable registered link relation type could be identified:
73  data
74  };
75  Q_ENUM( Rel )
76 
77  // Note: cannot be a scoped enum because qHash does not support them
80  {
85  XML
86  };
87  Q_ENUM( ContentType )
88 
89 
97  QgsServerOgcApi( QgsServerInterface *serverIface,
98  const QString &rootPath,
99  const QString &name,
100  const QString &description = QString(),
101  const QString &version = QString() );
102 
103  // QgsServerApi interface
104  const QString name() const override { return mName; }
105  const QString description() const override { return mDescription; }
106  const QString version() const override { return mVersion; }
107  const QString rootPath() const override { return mRootPath ; }
108 
109  ~QgsServerOgcApi() override;
110 
114  virtual void executeRequest( const QgsServerApiContext &context ) const override SIP_THROW( QgsServerApiBadRequestException ) SIP_VIRTUALERRORHANDLER( serverapi_badrequest_exception_handler );
115 
120  static const QMap<QgsServerOgcApi::ContentType, QStringList> contentTypeMimes() SIP_SKIP;
121 
126  static const QHash<QgsServerOgcApi::ContentType, QList<QgsServerOgcApi::ContentType> > contentTypeAliases() SIP_SKIP;
127 
128  // Utilities
129 #ifndef SIP_RUN
130 
135  template<class T, typename... Args>
136  void registerHandler( Args... args )
137  {
138  mHandlers.emplace_back( std::make_shared<T>( args... ) );
139  }
140 #endif
141 
145  void registerHandler( QgsServerOgcApiHandler *handler SIP_TRANSFER );
146 
151  static QUrl sanitizeUrl( const QUrl &url );
152 
156  static std::string relToString( const QgsServerOgcApi::Rel &rel );
157 
161  static QString contentTypeToString( const QgsServerOgcApi::ContentType &ct );
162 
166  static std::string contentTypeToStdString( const QgsServerOgcApi::ContentType &ct );
167 
171  static QString contentTypeToExtension( const QgsServerOgcApi::ContentType &ct );
172 
176  static QgsServerOgcApi::ContentType contenTypeFromExtension( const std::string &extension );
177 
181  static std::string mimeType( const QgsServerOgcApi::ContentType &contentType );
182 
186  const std::vector<std::shared_ptr<QgsServerOgcApiHandler> > handlers() const SIP_SKIP;
187 
188  private:
189 
190  QString mRootPath;
191  QString mName;
192  QString mDescription;
193  QString mVersion;
194 
195  //Note: this cannot be unique because of SIP bindings
196  std::vector<std::shared_ptr<QgsServerOgcApiHandler>> mHandlers;
197 
199  static QMap<QgsServerOgcApi::ContentType, QStringList> sContentTypeMime;
200 
206  static QHash<QgsServerOgcApi::ContentType, QList<QgsServerOgcApi::ContentType>> sContentTypeAliases;
207 
208 };
209 
210 #endif // QGSSERVEROGCAPI_H
QgsServerApiContext
The QgsServerApiContext class encapsulates the resources for a particular client request: the request...
Definition: qgsserverapicontext.h:38
QgsServerOgcApi::next
@ next
Indicates that the link’s context is a part of a series, and that the previous in the series is the l...
Definition: qgsserverogcapi.h:68
QgsServerOgcApi::service_doc
@ service_doc
Identifies service description for the context that is primarily intended for consumption by machines...
Definition: qgsserverogcapi.h:66
QgsServerOgcApi::version
const QString version() const override
Returns the version of the service.
Definition: qgsserverogcapi.h:106
QgsServerOgcApi::name
const QString name() const override
Returns the API name.
Definition: qgsserverogcapi.h:104
QgsServerOgcApi::registerHandler
void registerHandler(Args... args)
Registers an OGC API handler passing Args to the constructor.
Definition: qgsserverogcapi.h:136
QgsServerOgcApi
QGIS Server OGC API endpoint. QgsServerOgcApi provides the foundation for the new generation of REST-...
Definition: qgsserverogcapi.h:48
QgsServerOgcApi::service_desc
@ service_desc
Conveys an identifier for the link’s context.
Definition: qgsserverogcapi.h:65
QgsServerOgcApi::description
const QString description() const override
Returns the API description.
Definition: qgsserverogcapi.h:105
QgsServerOgcApi::prev
@ prev
Identifies service documentation for the context that is primarily intended for human consumption.
Definition: qgsserverogcapi.h:67
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsServerOgcApi::rootPath
const QString rootPath() const override
Returns the root path for the API.
Definition: qgsserverogcapi.h:107
SIP_THROW
#define SIP_THROW(name)
Definition: qgis_sip.h:198
QgsServerOgcApi::alternate
@ alternate
Definition: qgsserverogcapi.h:60
qgsserverapi.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsServerOgcApi::collection
@ collection
Refers to a resource providing information about the link’s context.
Definition: qgsserverogcapi.h:62
QgsServerOgcApi::item
@ item
The target IRI points to a resource that is a member of the collection represented by the context IRI...
Definition: qgsserverogcapi.h:63
QgsServerOgcApi::Rel
Rel
Rel link types.
Definition: qgsserverogcapi.h:57
QgsServerOgcApiHandler
The QgsServerOgcApiHandler abstract class represents a OGC API handler to be registered in QgsServerO...
Definition: qgsserverogcapihandler.h:94
QgsServerOgcApi::JSON
@ JSON
"application/openapi+json;version=3.0"
Definition: qgsserverogcapi.h:83
QgsServerOgcApi::OPENAPI3
@ OPENAPI3
Definition: qgsserverogcapi.h:82
QgsServerApi::executeRequest
virtual void executeRequest(const QgsServerApiContext &context) const =0
Executes a request by passing the given context to the API handlers.
QgsServerOgcApi::GEOJSON
@ GEOJSON
Definition: qgsserverogcapi.h:81
QgsServerOgcApi::describedBy
@ describedBy
Refers to a substitute for this context.
Definition: qgsserverogcapi.h:61
QgsServerApi
Server generic API endpoint abstract base class.
Definition: qgsserverapi.h:80
QgsServerOgcApi::license
@ license
Indicates that the link’s context is a part of a series, and that the next in the series is the link ...
Definition: qgsserverogcapi.h:69
QgsServerOgcApi::ContentType
ContentType
Media types used for content negotiation, insert more specific first.
Definition: qgsserverogcapi.h:79
QgsServerApiBadRequestException
Bad request error API exception.
Definition: qgsserverexception.h:244
QgsServerInterface
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
Definition: qgsserverinterface.h:60
QgsServerOgcApi::items
@ items
Refers to a license associated with this context.
Definition: qgsserverogcapi.h:71
QgsServerOgcApi::conformance
@ conformance
Refers to a resource that is comprised of members of the collection represented by the link’s context...
Definition: qgsserverogcapi.h:72
SIP_VIRTUALERRORHANDLER
#define SIP_VIRTUALERRORHANDLER(name)
Definition: qgis_sip.h:191
QgsServerOgcApi::HTML
@ HTML
Definition: qgsserverogcapi.h:84