QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
58 class SERVER_EXPORT QgsServerOgcApiHandler
59 {
60 
61  public:
62 
63  virtual ~QgsServerOgcApiHandler();
64 
65  // /////////////////////////////////////////////
66  // MAIN Section (operational)
67 
77  virtual QRegularExpression path() const = 0;
78 
80  virtual std::string operationId() const = 0;
81 
88  virtual QList<QgsServerQueryStringParameter> parameters( const QgsServerApiContext &context ) const { Q_UNUSED( context ); return { }; }
89 
90  // /////////////////////////////////////////////
91  // METADATA Sections (informative)
92 
94  virtual std::string summary() const = 0;
95 
97  virtual std::string description() const = 0;
98 
100  virtual std::string linkTitle() const = 0;
101 
103  virtual QgsServerOgcApi::Rel linkType() const = 0;
104 
106  virtual QStringList tags() const { return {}; }
107 
114  virtual QgsServerOgcApi::ContentType defaultContentType() const;
115 
122  QList<QgsServerOgcApi::ContentType> contentTypes() const SIP_SKIP;
123 
132  virtual void handleRequest( const QgsServerApiContext &context ) const SIP_THROW( QgsServerApiBadRequestException ) SIP_VIRTUALERRORHANDLER( serverapi_badrequest_exception_handler );
133 
153  virtual QVariantMap values( const QgsServerApiContext &context ) const SIP_THROW( QgsServerApiBadRequestException );
154 
159  QString contentTypeForAccept( const QString &accept ) const;
160 
161  // /////////////////////////////////////////////////////
162  // Utility methods: override should not be required
163 
164 #ifndef SIP_RUN // Skip SIP
165 
187  void write( json &data, const QgsServerApiContext &context, const json &htmlMetadata = nullptr ) const;
188 
195  void jsonDump( json &data, const QgsServerApiContext &context, const QString &contentType = QStringLiteral( "application/json" ) ) const;
196 
203  void htmlDump( const json &data, const QgsServerApiContext &context ) const;
204 
212  virtual json schema( const QgsServerApiContext &context ) const;
213 
223  json link( const QgsServerApiContext &context,
224  const QgsServerOgcApi::Rel &linkType = QgsServerOgcApi::Rel::self,
225  const QgsServerOgcApi::ContentType contentType = QgsServerOgcApi::ContentType::JSON,
226  const std::string &title = "" ) const;
227 
236  json links( const QgsServerApiContext &context ) const;
237 
238 
248  QgsVectorLayer *layerFromContext( const QgsServerApiContext &context ) const;
249 
250 #endif // SIP skipped
251 
272  void write( QVariant &data, const QgsServerApiContext &context, const QVariantMap &htmlMetadata = QVariantMap() ) const SIP_THROW( QgsServerApiBadRequestException );
273 
281  std::string href( const QgsServerApiContext &context, const QString &extraPath = QString(), const QString &extension = QString() ) const;
282 
291  virtual const QString templatePath( const QgsServerApiContext &context ) const;
292 
298  virtual const QString staticPath( const QgsServerApiContext &context ) const;
299 
309  QgsServerOgcApi::ContentType contentTypeFromRequest( const QgsServerRequest *request ) const;
310 
314  static QString parentLink( const QUrl &url, int levels = 1 );
315 
320  static QgsVectorLayer *layerFromCollectionId( const QgsServerApiContext &context, const QString &collectionId );
321 
327  static json defaultResponse() SIP_SKIP;
328 
336  json jsonTags( ) const SIP_SKIP;
337 
338  protected:
339 
343  void setContentTypesInt( const QList<int> &contentTypes ) SIP_PYNAME( setContentTypes );
344 
349  void setContentTypes( const QList<QgsServerOgcApi::ContentType> &contentTypes ) SIP_SKIP;
350 
351  private:
352 
354  QList<QgsServerOgcApi::ContentType> mContentTypes = { QgsServerOgcApi::ContentType::JSON, QgsServerOgcApi::ContentType::HTML };
355 
356 
357 };
358 
359 #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