QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
server
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 <nlohmann/json_fwd.hpp>
20
21
#include "qgis_server.h"
22
#include "
qgsserverogcapi.h
"
23
#include "
qgsserverquerystringparameter.h
"
24
25
#include <QRegularExpression>
26
#include <QString>
27
28
using namespace
Qt::StringLiterals;
29
30
#ifndef SIP_RUN
31
using namespace
nlohmann;
32
#endif
33
34
class
QgsServerApiContext
;
35
98
class
SERVER_EXPORT
QgsServerOgcApiHandler
99
{
100
public
:
101
virtual
~QgsServerOgcApiHandler
();
102
103
// /////////////////////////////////////////////
104
// MAIN Section (operational)
105
115
virtual
QRegularExpression
path
()
const
= 0;
116
118
virtual
std::string
operationId
()
const
= 0;
119
126
virtual
QList<QgsServerQueryStringParameter>
parameters
(
const
QgsServerApiContext
&context )
const
127
{
128
Q_UNUSED( context );
129
return
{};
130
}
131
132
// /////////////////////////////////////////////
133
// METADATA Sections (informative)
134
136
virtual
std::string
summary
()
const
= 0;
137
139
virtual
std::string
description
()
const
= 0;
140
142
virtual
std::string
linkTitle
()
const
= 0;
143
145
virtual
QgsServerOgcApi::Rel
linkType
()
const
= 0;
146
148
virtual
QStringList
tags
()
const
{
return
{}; }
149
156
virtual
QgsServerOgcApi::ContentType
defaultContentType()
const
;
157
164
QList<QgsServerOgcApi::ContentType> contentTypes() const
SIP_SKIP
;
165
174
virtual
void
handleRequest( const
QgsServerApiContext
&context ) const
SIP_THROW
(
QgsServerApiBadRequestException
)
SIP_VIRTUALERRORHANDLER
( serverapi_badrequest_exception_handler );
175
195
virtual QVariantMap values( const
QgsServerApiContext
&context ) const
SIP_THROW
(
QgsServerApiBadRequestException
);
196
201
QString contentTypeForAccept( const QString &accept ) const;
202
203
// /////////////////////////////////////////////////////
204
// Utility methods: override should not be required
205
206
#ifndef SIP_RUN
// Skip SIP
207
232
void
write( json &data,
const
QgsServerApiContext
&context,
const
json &htmlMetadata =
nullptr
)
const
;
233
240
void
jsonDump( json &data,
const
QgsServerApiContext
&context,
const
QString &contentType = u
"application/json"
_s )
const
;
241
248
void
htmlDump(
const
json &data,
const
QgsServerApiContext
&context )
const
;
249
257
virtual
json schema(
const
QgsServerApiContext
&context )
const
;
258
268
json link(
269
const
QgsServerApiContext
&context,
270
const
QgsServerOgcApi::Rel
&linkType =
QgsServerOgcApi::Rel::self
,
271
const
QgsServerOgcApi::ContentType
contentType =
QgsServerOgcApi::ContentType::JSON
,
272
const
std::string &title =
""
273
)
const
;
274
283
json links(
const
QgsServerApiContext
&context )
const
;
284
285
295
QgsVectorLayer
*layerFromContext(
const
QgsServerApiContext
&context )
const
;
296
297
#endif
// SIP skipped
298
308
QString headerLink(
309
const
QgsServerApiContext
&context,
310
const
QgsServerOgcApi::Rel
&linkType =
QgsServerOgcApi::Rel::self
,
311
const
QgsServerOgcApi::ContentType
contentType =
QgsServerOgcApi::ContentType::JSON
,
312
const
QgsServerOgcApi::Profile
&profile =
QgsServerOgcApi::Profile::Unset
,
313
const
QString &title =
""
314
)
const
;
315
339
void
write( QVariant &data,
const
QgsServerApiContext
&context,
const
QVariantMap &htmlMetadata = QVariantMap() ) const
SIP_THROW
(
QgsServerApiBadRequestException
);
340
348
std::
string
href( const
QgsServerApiContext
&context, const QString &extraPath = QString(), const QString &extension = QString() ) const;
349
358
virtual const QString templatePath( const
QgsServerApiContext
&context ) const;
359
365
virtual const QString staticPath( const
QgsServerApiContext
&context ) const;
366
376
QgsServerOgcApi
::ContentType contentTypeFromRequest( const
QgsServerRequest
*request ) const;
377
384
static
QgsServerOgcApi
::Profile profileFromString( const QString &profile,
bool
&ok
SIP_OUT
);
385
390
QList<
QgsServerOgcApi
::Profile> profilesFromRequest( const
QgsServerRequest
*request ) const;
391
395
static QString parentLink( const QUrl &url,
int
levels = 1 );
396
401
static
QgsVectorLayer
*layerFromCollectionId( const
QgsServerApiContext
&context, const QString &collectionId );
402
408
static json defaultResponse()
SIP_SKIP
;
409
417
json jsonTags() const
SIP_SKIP
;
418
419
protected:
423
void
setContentTypesInt( const QList<
int
> &contentTypes )
SIP_PYNAME
( setContentTypes );
424
429
void
setContentTypes( const QList<
QgsServerOgcApi
::ContentType> &contentTypes )
SIP_SKIP
;
430
431
private:
433
QList<
QgsServerOgcApi
::ContentType> mContentTypes = {
QgsServerOgcApi::ContentType::JSON
,
QgsServerOgcApi::ContentType::HTML
};
434
};
435
436
#endif
// QGSSERVEROGCAPIHANDLER_H
QgsServerApiBadRequestException
Bad request error API exception.
Definition
qgsserverexception.h:225
QgsServerApiContext
Encapsulates the resources for a particular client request.
Definition
qgsserverapicontext.h:41
QgsServerOgcApiHandler
An abstract class which represents an OGC API handler to be registered in QgsServerOgcApi class.
Definition
qgsserverogcapihandler.h:99
QgsServerOgcApiHandler::summary
virtual std::string summary() const =0
Summary.
QgsServerOgcApiHandler::linkType
virtual QgsServerOgcApi::Rel linkType() const =0
Main role for the resource link.
QgsServerOgcApiHandler::tags
virtual QStringList tags() const
Tags.
Definition
qgsserverogcapihandler.h:148
QgsServerOgcApiHandler::linkTitle
virtual std::string linkTitle() const =0
Title for the handler link.
QgsServerOgcApiHandler::parameters
virtual QList< QgsServerQueryStringParameter > parameters(const QgsServerApiContext &context) const
Returns a list of query string parameters.
Definition
qgsserverogcapihandler.h:126
QgsServerOgcApiHandler::operationId
virtual std::string operationId() const =0
Returns the operation id for template file names and other internal references.
QgsServerOgcApiHandler::description
virtual std::string description() const =0
Description.
QgsServerOgcApiHandler::path
virtual QRegularExpression path() const =0
URL pattern for this handler, named capture group are automatically extracted and returned by values(...
QgsServerOgcApi
QGIS Server OGC API endpoint.
Definition
qgsserverogcapi.h:48
QgsServerOgcApi::ContentType
ContentType
Media types used for content negotiation, insert more specific first.
Definition
qgsserverogcapi.h:84
QgsServerOgcApi::JSON
@ JSON
Definition
qgsserverogcapi.h:87
QgsServerOgcApi::HTML
@ HTML
Definition
qgsserverogcapi.h:89
QgsServerOgcApi::Rel
Rel
Rel link types.
Definition
qgsserverogcapi.h:56
QgsServerOgcApi::self
@ self
Conveys an identifier for the link’s context.
Definition
qgsserverogcapi.h:62
QgsServerOgcApi::Profile
Profile
JSON profile.
Definition
qgsserverogcapi.h:98
QgsServerOgcApi::Profile::Unset
@ Unset
No profile.
Definition
qgsserverogcapi.h:99
QgsServerRequest
Defines requests passed to QgsService classes.
Definition
qgsserverrequest.h:36
QgsVectorLayer
Represents a vector layer which manages a vector based dataset.
Definition
qgsvectorlayer.h:414
SIP_SKIP
#define SIP_SKIP
Definition
qgis_sip.h:138
SIP_PYNAME
#define SIP_PYNAME(name)
Definition
qgis_sip.h:88
SIP_OUT
#define SIP_OUT
Definition
qgis_sip.h:57
SIP_VIRTUALERRORHANDLER
#define SIP_VIRTUALERRORHANDLER(name)
Definition
qgis_sip.h:208
SIP_THROW
#define SIP_THROW(name,...)
Definition
qgis_sip.h:215
qgsserverogcapi.h
qgsserverquerystringparameter.h
Generated on
for QGIS API Documentation by
1.17.0