QGIS API Documentation 4.3.0-Master (bf28115e945)
Loading...
Searching...
No Matches
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 "qgis_server.h"
20#include "qgsserverapi.h"
21
23
47class SERVER_EXPORT QgsServerOgcApi : public QgsServerApi
48{
49 Q_GADGET
50
51 public:
52 // Note: non a scoped enum or qHash fails
54 // NOLINTBEGIN(readability-identifier-naming)
55 enum Rel
56 {
57 // The following registered link relation types are used
68 // In addition the following link relation types are used for which no applicable registered link relation type could be identified:
74 };
75 Q_ENUM( Rel )
76 // NOLINTEND(readability-identifier-naming)
77
78 // Note: cannot be a scoped enum because qHash does not support them
80 // NOLINTBEGIN(readability-identifier-naming)
91 Q_ENUM( ContentType )
92 // NOLINTEND(readability-identifier-naming)
93
94
95 enum class Profile
96 {
97 Unset,
98 Rfc7946,
99 // This not supported yet but I am leaving it here because
100 // I am very optimistic that it will be supported soon!
101 // JsonFg, //!< JSON Feature Geometry profile according to OGC API - Features 1.0
102 // JsonFgPlus //!< JSON Feature Geometry profile with GeoJSON compatibility extensions
103 RelAsLink,
104 RelAsKey,
105 RelAsUri
106 };
107 Q_ENUM( Profile )
108
109
117 QgsServerOgcApi( QgsServerInterface *serverIface, const QString &rootPath, const QString &name, const QString &description = QString(), const QString &version = QString() );
118
119 // QgsServerApi interface
120 const QString name() const override { return mName; }
121 const QString description() const override { return mDescription; }
122 const QString version() const override { return mVersion; }
123 const QString rootPath() const override { return mRootPath; }
124
125 ~QgsServerOgcApi() override;
126
130 void executeRequest( const QgsServerApiContext &context ) const override SIP_THROW( QgsServerApiBadRequestException ) SIP_VIRTUALERRORHANDLER( serverapi_badrequest_exception_handler );
131
136 static const QMap<QgsServerOgcApi::ContentType, QStringList> contentTypeMimes() SIP_SKIP;
137
142 static const QHash<QgsServerOgcApi::ContentType, QList<QgsServerOgcApi::ContentType>> contentTypeAliases() SIP_SKIP;
143
148 static QString profileToString( const QgsServerOgcApi::Profile &profile ) SIP_SKIP;
149
154 static QString profileToUri( const QgsServerOgcApi::Profile &profile ) SIP_SKIP;
155
156 // Utilities
157#ifndef SIP_RUN
158
163 template<class T, typename... Args> void registerHandler( Args... args ) { mHandlers.emplace_back( std::make_shared<T>( args... ) ); }
164#endif
165
169 void registerHandler( QgsServerOgcApiHandler *handler SIP_TRANSFER );
170
175 static QUrl sanitizeUrl( const QUrl &url );
176
180 static std::string relToString( const QgsServerOgcApi::Rel &rel );
181
185 static QString contentTypeToString( const QgsServerOgcApi::ContentType &ct );
186
190 static std::string contentTypeToStdString( const QgsServerOgcApi::ContentType &ct );
191
195 static QString contentTypeToExtension( const QgsServerOgcApi::ContentType &ct );
196
201 Q_DECL_DEPRECATED static QgsServerOgcApi::ContentType contenTypeFromExtension( const std::string &extension ) SIP_DEPRECATED { return contentTypeFromExtension( extension ); } // spellok
202
207 static QgsServerOgcApi::ContentType contentTypeFromExtension( const std::string &extension );
208
212 static std::string mimeType( const QgsServerOgcApi::ContentType &contentType );
213
217 const std::vector<std::shared_ptr<QgsServerOgcApiHandler>> handlers() const SIP_SKIP;
218
219 private:
220 QString mRootPath;
221 QString mName;
222 QString mDescription;
223 QString mVersion;
224
225 //Note: this cannot be unique because of SIP bindings
226 std::vector<std::shared_ptr<QgsServerOgcApiHandler>> mHandlers;
227
229 static QMap<QgsServerOgcApi::ContentType, QStringList> sContentTypeMime;
230
236 static QHash<QgsServerOgcApi::ContentType, QList<QgsServerOgcApi::ContentType>> sContentTypeAliases;
237};
238
239#endif // QGSSERVEROGCAPI_H
Bad request error API exception.
Encapsulates the resources for a particular client request.
QgsServerApi(QgsServerInterface *serverIface)
Creates a QgsServerApi object.
virtual void executeRequest(const QgsServerApiContext &context) const =0
Executes a request by passing the given context to the API handlers.
Defines interfaces exposed by QGIS Server and made available to plugins.
An abstract class which represents an OGC API handler to be registered in QgsServerOgcApi class.
QGIS Server OGC API endpoint.
const QString rootPath() const override
Returns the root path for the API.
void registerHandler(Args... args)
Registers an OGC API handler passing Args to the constructor.
QgsServerOgcApi(QgsServerInterface *serverIface, const QString &rootPath, const QString &name, const QString &description=QString(), const QString &version=QString())
QgsServerOgcApi constructor.
const QString description() const override
Returns the API description.
ContentType
Media types used for content negotiation, insert more specific first.
@ SCHEMA_JSON
"application/schema+json"
@ OPENAPI3
"application/openapi+json;version=3.0"
@ FLATGEOBUF
"application/flatgeobuf"
Rel
Rel link types.
@ alternate
Refers to a substitute for this context.
@ collection
The target IRI points to a resource that is a member of the collection represented by the context IRI...
@ self
Conveys an identifier for the link’s context.
@ prev
Indicates that the link’s context is a part of a series, and that the previous in the series is the l...
@ service_doc
Identifies service documentation for the context that is primarily intended for human consumption.
@ conformance
The target IRI points to a resource which represents the collection resource for the context IRI.
@ describedBy
Refers to a resource providing information about the link’s context.
@ profile
"http://www.opengis.net/spec/ogcapi-features-5/0.0/conf/feature-references"
@ next
Indicates that the link’s context is a part of a series, and that the next in the series is the link ...
@ license
Refers to a license associated with this context.
@ data
The target IRI points to resource data.
@ schema
"http://www.opengis.net/def/rel/ogc/0.0/schema"
@ service_desc
Identifies service description for the context that is primarily intended for consumption by machines...
@ items
Refers to a resource that is comprised of members of the collection represented by the link’s context...
@ item
The target IRI points to a resource that is a member of the collection represented by the context IRI...
const QString version() const override
Returns the version of the service.
const QString name() const override
Returns the API name.
Profile
JSON profile.
static Q_DECL_DEPRECATED QgsServerOgcApi::ContentType contenTypeFromExtension(const std::string &extension)
Returns the Content-Type value corresponding to extension.
static QgsServerOgcApi::ContentType contentTypeFromExtension(const std::string &extension)
Returns the Content-Type value corresponding to extension.
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_VIRTUALERRORHANDLER(name)
Definition qgis_sip.h:203
#define SIP_THROW(name,...)
Definition qgis_sip.h:210