QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
qgsserverogcapihandler.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsserverogcapihandler.h - QgsServerOgcApiHandler
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 QGSSERVEROGCAPIHANDLER_H
17 #define QGSSERVEROGCAPIHANDLER_H
18 
19 #include <QRegularExpression>
20 #include "qgis_server.h"
22 #include "qgsserverogcapi.h"
23 #include "nlohmann/json_fwd.hpp"
24 #include "inja/inja.hpp"
25 
26 #ifndef SIP_RUN
27 using namespace nlohmann;
28 #endif
29 
31 
92 class SERVER_EXPORT QgsServerOgcApiHandler
93 {
94 
95  public:
96 
97  virtual ~QgsServerOgcApiHandler();
98 
99  // /////////////////////////////////////////////
100  // MAIN Section (operational)
101 
111  virtual QRegularExpression path() const = 0;
112 
114  virtual std::string operationId() const = 0;
115 
122  virtual QList<QgsServerQueryStringParameter> parameters( const QgsServerApiContext &context ) const { Q_UNUSED( context ); return { }; }
123 
124  // /////////////////////////////////////////////
125  // METADATA Sections (informative)
126 
128  virtual std::string summary() const = 0;
129 
131  virtual std::string description() const = 0;
132 
134  virtual std::string linkTitle() const = 0;
135 
137  virtual QgsServerOgcApi::Rel linkType() const = 0;
138 
140  virtual QStringList tags() const { return {}; }
141 
148  virtual QgsServerOgcApi::ContentType defaultContentType() const;
149 
156  QList<QgsServerOgcApi::ContentType> contentTypes() const SIP_SKIP;
157 
166  virtual void handleRequest( const QgsServerApiContext &context ) const SIP_THROW( QgsServerApiBadRequestException ) SIP_VIRTUALERRORHANDLER( serverapi_badrequest_exception_handler );
167 
187  virtual QVariantMap values( const QgsServerApiContext &context ) const SIP_THROW( QgsServerApiBadRequestException );
188 
193  QString contentTypeForAccept( const QString &accept ) const;
194 
195  // /////////////////////////////////////////////////////
196  // Utility methods: override should not be required
197 
198 #ifndef SIP_RUN // Skip SIP
199 
222  void write( json &data, const QgsServerApiContext &context, const json &htmlMetadata = nullptr ) const;
223 
230  void jsonDump( json &data, const QgsServerApiContext &context, const QString &contentType = QStringLiteral( "application/json" ) ) const;
231 
238  void htmlDump( const json &data, const QgsServerApiContext &context ) const;
239 
247  virtual json schema( const QgsServerApiContext &context ) const;
248 
258  json link( const QgsServerApiContext &context,
259  const QgsServerOgcApi::Rel &linkType = QgsServerOgcApi::Rel::self,
260  const QgsServerOgcApi::ContentType contentType = QgsServerOgcApi::ContentType::JSON,
261  const std::string &title = "" ) const;
262 
271  json links( const QgsServerApiContext &context ) const;
272 
273 
283  QgsVectorLayer *layerFromContext( const QgsServerApiContext &context ) const;
284 
285 #endif // SIP skipped
286 
307  void write( QVariant &data, const QgsServerApiContext &context, const QVariantMap &htmlMetadata = QVariantMap() ) const SIP_THROW( QgsServerApiBadRequestException );
308 
316  std::string href( const QgsServerApiContext &context, const QString &extraPath = QString(), const QString &extension = QString() ) const;
317 
326  virtual const QString templatePath( const QgsServerApiContext &context ) const;
327 
333  virtual const QString staticPath( const QgsServerApiContext &context ) const;
334 
344  QgsServerOgcApi::ContentType contentTypeFromRequest( const QgsServerRequest *request ) const;
345 
349  static QString parentLink( const QUrl &url, int levels = 1 );
350 
355  static QgsVectorLayer *layerFromCollectionId( const QgsServerApiContext &context, const QString &collectionId );
356 
362  static json defaultResponse() SIP_SKIP;
363 
371  json jsonTags( ) const SIP_SKIP;
372 
373  protected:
374 
378  void setContentTypesInt( const QList<int> &contentTypes ) SIP_PYNAME( setContentTypes );
379 
384  void setContentTypes( const QList<QgsServerOgcApi::ContentType> &contentTypes ) SIP_SKIP;
385 
386  private:
387 
389  QList<QgsServerOgcApi::ContentType> mContentTypes = { QgsServerOgcApi::ContentType::JSON, QgsServerOgcApi::ContentType::HTML };
390 
391 
392 };
393 
394 #endif // QGSSERVEROGCAPIHANDLER_H
#define SIP_VIRTUALERRORHANDLER(name)
Definition: qgis_sip.h:177
The QgsServerOgcApiHandler abstract class represents a OGC API handler to be registered in QgsServerO...
ContentType
Media types used for content negotiation, insert more specific first.
#define SIP_SKIP
Definition: qgis_sip.h:126
The QgsServerApiContext class encapsulates the resources for a particular client request: the request...
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
Bad request error API exception.
virtual QList< QgsServerQueryStringParameter > parameters(const QgsServerApiContext &context) const
Returns a list of query string parameters.
Rel
Rel link types.
#define SIP_THROW(name)
Definition: qgis_sip.h:184
virtual QStringList tags() const
Tags.
Represents a vector layer which manages a vector based data sets.
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81