QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsserverapiutils.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsserverapiutils.h
3
4 Class defining utilities for QGIS server APIs.
5 -------------------
6 begin : 2019-04-16
7 copyright : (C) 2019 by Alessandro Pasotti
8 email : elpaso at itopen dot it
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19
20
21#ifndef QGSSERVERAPIUTILS_H
22#define QGSSERVERAPIUTILS_H
23
24#include "qgis_server.h"
25#include <QString>
26#include "qgsproject.h"
28#include "qgsserverapicontext.h"
29#include "qgsserverexception.h"
31#include "qgsrange.h"
32#include "qgsjsonutils.h"
33
34#ifdef HAVE_SERVER_PYTHON_PLUGINS
35#include "qgsaccesscontrol.h"
36#include "qgsserverinterface.h"
37#endif
38
39class QgsRectangle;
41class QgsVectorLayer;
42
43#ifndef SIP_RUN
44#include <nlohmann/json_fwd.hpp>
45using namespace nlohmann;
46#endif
47
53class SERVER_EXPORT QgsServerApiUtils
54{
55 public:
61 static QgsRectangle parseBbox( const QString &bbox );
62
67 static QList<QgsServerWmsDimensionProperties::WmsDimensionInfo> temporalDimensions( const QgsVectorLayer *layer );
68
75 static QgsDateRange parseTemporalDateInterval( const QString &interval ) SIP_THROW( QgsServerApiBadRequestException );
76
83 static QgsDateTimeRange parseTemporalDateTimeInterval( const QString &interval ) SIP_THROW( QgsServerApiBadRequestException );
84
85
91 static QString fieldName( const QString &name, const QgsVectorLayer *layer ) SIP_THROW( QgsServerApiBadRequestException );
92
94 // T is TemporalDateInterval|TemporalDateTimeInterval, T2 is QDate|QdateTime
95 template<typename T, class T2> static T parseTemporalInterval( const QString &interval ) SIP_SKIP;
97
98
111 static QgsExpression temporalFilterExpression( const QgsVectorLayer *layer, const QString &interval );
112
116 static json layerExtent( const QgsVectorLayer *layer ) SIP_SKIP;
117
135 static json temporalExtent( const QgsVectorLayer *layer ) SIP_SKIP;
136
153 static QVariantList temporalExtentList( const QgsVectorLayer *layer ) SIP_PYNAME( temporalExtent );
154
158 static QgsCoordinateReferenceSystem parseCrs( const QString &bboxCrs );
159
165 static const QVector<QgsVectorLayer *> publishedWfsLayers( const QgsServerApiContext &context );
166
167#ifndef SIP_RUN
168
178 template<typename T>
179 static const QVector<T> publishedWfsLayers( const QgsServerApiContext &context )
180 {
181#ifdef HAVE_SERVER_PYTHON_PLUGINS
182 QgsAccessControl *accessControl = context.serverInterface()->accessControls();
183#endif
184 const QgsProject *project = context.project();
185 QVector<T> result;
186 if ( project )
187 {
188 const QStringList wfsLayerIds = QgsServerProjectUtils::wfsLayerIds( *project );
189 const auto constLayers { project->layers<T>() };
190 for ( const auto &layer : constLayers )
191 {
192 if ( !wfsLayerIds.contains( layer->id() ) )
193 {
194 continue;
195 }
196#ifdef HAVE_SERVER_PYTHON_PLUGINS
197 if ( accessControl && !accessControl->layerReadPermission( layer ) )
198 {
199 continue;
200 }
201#endif
202 result.push_back( layer );
203 }
204 }
205 return result;
206 }
207
208#endif
209
210
215 static QString sanitizedFieldValue( const QString &value );
216
221 static QStringList publishedCrsList( const QgsProject *project );
222
229 Q_DECL_DEPRECATED static QString crsToOgcUri( const QgsCoordinateReferenceSystem &crs ) SIP_DEPRECATED;
230
234 static QString appendMapParameter( const QString &path, const QUrl &requestUrl );
235};
236#endif // QGSSERVERAPIUTILS_H
A helper class that centralizes restrictions given by all the access control filter plugins.
bool layerReadPermission(const QgsMapLayer *layer) const
Returns the layer read right.
This class represents a coordinate reference system (CRS).
Class for parsing and evaluation of expressions (formerly called "search strings").
QString id
Definition qgsmaplayer.h:79
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
A rectangle specified with double values.
Bad request error API exception.
The QgsServerApiContext class encapsulates the resources for a particular client request: the request...
const QgsProject * project() const
Returns the (possibly NULL) project.
QgsServerInterface * serverInterface() const
Returns the server interface.
The QgsServerApiUtils class contains helper functions to handle common API operations.
static const QVector< T > publishedWfsLayers(const QgsServerApiContext &context)
Returns the list of layers of type T accessible to the WFS service for a given project.
virtual QgsAccessControl * accessControls() const =0
Gets the registered access control filters.
Represents a vector layer which manages a vector based data sets.
SERVER_EXPORT QStringList wfsLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published in WFS.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_PYNAME(name)
Definition qgis_sip.h:81
#define SIP_THROW(name,...)
Definition qgis_sip.h:203
QgsTemporalRange< QDate > QgsDateRange
QgsRange which stores a range of dates.
Definition qgsrange.h:729
const QgsCoordinateReferenceSystem & crs