QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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"
27 #include "qgsserverprojectutils.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 
39 class QgsRectangle;
41 class QgsVectorLayer;
42 
43 #ifndef SIP_RUN
44 #include "nlohmann/json_fwd.hpp"
45 using namespace nlohmann;
46 #endif
47 
53 class SERVER_EXPORT QgsServerApiUtils
54 {
55 
56  public:
57 
63  static QgsRectangle parseBbox( const QString &bbox );
64 
69  static QList< QgsVectorLayerServerProperties::WmsDimensionInfo > temporalDimensions( const QgsVectorLayer *layer );
70 
77  static QgsDateRange parseTemporalDateInterval( const QString &interval ) SIP_THROW( QgsServerApiBadRequestException );
78 
85  static QgsDateTimeRange parseTemporalDateTimeInterval( const QString &interval ) SIP_THROW( QgsServerApiBadRequestException );
86 
88  // T is TemporalDateInterval|TemporalDateTimeInterval, T2 is QDate|QdateTime
89  template<typename T, class T2> static T parseTemporalInterval( const QString &interval ) SIP_SKIP;
91 
92 
105  static QgsExpression temporalFilterExpression( const QgsVectorLayer *layer, const QString &interval );
106 
110  static json layerExtent( const QgsVectorLayer *layer ) SIP_SKIP;
111 
129  static json temporalExtent( const QgsVectorLayer *layer ) SIP_SKIP;
130 
147  static QVariantList temporalExtentList( const QgsVectorLayer *layer ) SIP_PYNAME( temporalExtent );
148 
152  static QgsCoordinateReferenceSystem parseCrs( const QString &bboxCrs );
153 
159  static const QVector<QgsVectorLayer *> publishedWfsLayers( const QgsServerApiContext &context );
160 
161 #ifndef SIP_RUN
162 
172  template <typename T>
173  static const QVector<T> publishedWfsLayers( const QgsServerApiContext &context )
174  {
175 #ifdef HAVE_SERVER_PYTHON_PLUGINS
176  QgsAccessControl *accessControl = context.serverInterface()->accessControls();
177 #endif
178  const QgsProject *project = context.project();
179  QVector<T> result;
180  if ( project )
181  {
182  const QStringList wfsLayerIds = QgsServerProjectUtils::wfsLayerIds( *project );
183  const auto constLayers { project->layers<T>() };
184  for ( const auto &layer : constLayers )
185  {
186  if ( ! wfsLayerIds.contains( layer->id() ) )
187  {
188  continue;
189  }
190 #ifdef HAVE_SERVER_PYTHON_PLUGINS
191  if ( accessControl && !accessControl->layerReadPermission( layer ) )
192  {
193  continue;
194  }
195 #endif
196  result.push_back( layer );
197  }
198  }
199  return result;
200  }
201 
202 #endif
203 
204 
209  static QString sanitizedFieldValue( const QString &value );
210 
215  static QStringList publishedCrsList( const QgsProject *project );
216 
221  static QString crsToOgcUri( const QgsCoordinateReferenceSystem &crs );
222 
226  static QString appendMapParameter( const QString &path, const QUrl &requestUrl );
227 
228 };
229 #endif // QGSSERVERAPIUTILS_H
SIP_PYNAME
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
QgsProject::layers
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
Definition: qgsproject.h:1070
QgsServerApiContext
The QgsServerApiContext class encapsulates the resources for a particular client request: the request...
Definition: qgsserverapicontext.h:39
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:51
qgsserverprojectutils.h
QgsServerApiUtils::publishedWfsLayers
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.
Definition: qgsserverapiutils.h:173
QgsAccessControl::layerReadPermission
bool layerReadPermission(const QgsMapLayer *layer) const
Returns the layer read right.
Definition: qgsaccesscontrol.cpp:105
qgsrange.h
QgsServerInterface::accessControls
virtual QgsAccessControl * accessControls() const =0
Gets the registered access control filters.
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:95
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
SIP_THROW
#define SIP_THROW(name)
Definition: qgis_sip.h:189
QgsServerProjectUtils::wfsLayerIds
SERVER_EXPORT QStringList wfsLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published in WFS.
Definition: qgsserverprojectutils.cpp:337
QgsServerApiContext::project
const QgsProject * project() const
Returns the (possibly NULL) project.
Definition: qgsserverapicontext.cpp:45
QgsServerApiUtils
The QgsServerApiUtils class contains helper functions to handle common API operations.
Definition: qgsserverapiutils.h:54
QgsMapLayer::id
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
Definition: qgsmaplayer.cpp:148
QgsServerApiContext::serverInterface
QgsServerInterface * serverInterface() const
Returns the server interface.
Definition: qgsserverapicontext.cpp:55
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
QgsAccessControl
A helper class that centralizes restrictions given by all the access control filter plugins.
Definition: qgsaccesscontrol.h:37
qgsaccesscontrol.h
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
qgsjsonutils.h
QgsExpression
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:105
QgsWcs::parseBbox
QgsRectangle parseBbox(const QString &bboxStr)
Parse bounding box.
Definition: qgswcsutils.cpp:290
QgsServerApiBadRequestException
Bad request error API exception.
Definition: qgsserverexception.h:245
qgsserverexception.h
qgsproject.h
qgsvectorlayerserverproperties.h
qgsserverapicontext.h
qgsserverinterface.h