QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
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
27using namespace nlohmann;
28#endif
29
31
94class SERVER_EXPORT QgsServerOgcApiHandler
95{
96 public:
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
123 {
124 Q_UNUSED( context );
125 return {};
126 }
127
128 // /////////////////////////////////////////////
129 // METADATA Sections (informative)
130
132 virtual std::string summary() const = 0;
133
135 virtual std::string description() const = 0;
136
138 virtual std::string linkTitle() const = 0;
139
141 virtual QgsServerOgcApi::Rel linkType() const = 0;
142
144 virtual QStringList tags() const { return {}; }
145
152 virtual QgsServerOgcApi::ContentType defaultContentType() const;
153
160 QList<QgsServerOgcApi::ContentType> contentTypes() const SIP_SKIP;
161
170 virtual void handleRequest( const QgsServerApiContext &context ) const SIP_THROW( QgsServerApiBadRequestException ) SIP_VIRTUALERRORHANDLER( serverapi_badrequest_exception_handler );
171
191 virtual QVariantMap values( const QgsServerApiContext &context ) const SIP_THROW( QgsServerApiBadRequestException );
192
197 QString contentTypeForAccept( const QString &accept ) const;
198
199 // /////////////////////////////////////////////////////
200 // Utility methods: override should not be required
201
202#ifndef SIP_RUN // Skip SIP
203
228 void write( json &data, const QgsServerApiContext &context, const json &htmlMetadata = nullptr ) const;
229
236 void jsonDump( json &data, const QgsServerApiContext &context, const QString &contentType = QStringLiteral( "application/json" ) ) const;
237
244 void htmlDump( const json &data, const QgsServerApiContext &context ) const;
245
253 virtual json schema( const QgsServerApiContext &context ) const;
254
264 json link( const QgsServerApiContext &context, const QgsServerOgcApi::Rel &linkType = QgsServerOgcApi::Rel::self, const QgsServerOgcApi::ContentType contentType = QgsServerOgcApi::ContentType::JSON, const std::string &title = "" ) const;
265
274 json links( const QgsServerApiContext &context ) const;
275
276
286 QgsVectorLayer *layerFromContext( const QgsServerApiContext &context ) const;
287
288#endif // SIP skipped
289
313 void write( QVariant &data, const QgsServerApiContext &context, const QVariantMap &htmlMetadata = QVariantMap() ) const SIP_THROW( QgsServerApiBadRequestException );
314
322 std::string href( const QgsServerApiContext &context, const QString &extraPath = QString(), const QString &extension = QString() ) const;
323
332 virtual const QString templatePath( const QgsServerApiContext &context ) const;
333
339 virtual const QString staticPath( const QgsServerApiContext &context ) const;
340
350 QgsServerOgcApi::ContentType contentTypeFromRequest( const QgsServerRequest *request ) const;
351
355 static QString parentLink( const QUrl &url, int levels = 1 );
356
361 static QgsVectorLayer *layerFromCollectionId( const QgsServerApiContext &context, const QString &collectionId );
362
368 static json defaultResponse() SIP_SKIP;
369
377 json jsonTags() const SIP_SKIP;
378
379 protected:
383 void setContentTypesInt( const QList<int> &contentTypes ) SIP_PYNAME( setContentTypes );
384
389 void setContentTypes( const QList<QgsServerOgcApi::ContentType> &contentTypes ) SIP_SKIP;
390
391 private:
394};
395
396#endif // QGSSERVEROGCAPIHANDLER_H
Bad request error API exception.
The QgsServerApiContext class encapsulates the resources for a particular client request: the request...
The QgsServerOgcApiHandler abstract class represents a OGC API handler to be registered in QgsServerO...
virtual std::string summary() const =0
Summary.
virtual QgsServerOgcApi::Rel linkType() const =0
Main role for the resource link.
virtual QStringList tags() const
Tags.
virtual std::string linkTitle() const =0
Title for the handler link.
virtual QList< QgsServerQueryStringParameter > parameters(const QgsServerApiContext &context) const
Returns a list of query string parameters.
virtual std::string operationId() const =0
Returns the operation id for template file names and other internal references.
virtual std::string description() const =0
Description.
virtual QRegularExpression path() const =0
URL pattern for this handler, named capture group are automatically extracted and returned by values(...
QGIS Server OGC API endpoint.
ContentType
Media types used for content negotiation, insert more specific first.
Rel
Rel link types.
@ self
Conveys an identifier for the link’s context.
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
Represents a vector layer which manages a vector based data sets.
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_PYNAME(name)
Definition qgis_sip.h:81
#define SIP_VIRTUALERRORHANDLER(name)
Definition qgis_sip.h:196
#define SIP_THROW(name,...)
Definition qgis_sip.h:203