QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
30 #ifdef HAVE_SERVER_PYTHON_PLUGINS
31 #include "qgsaccesscontrol.h"
32 #include "qgsserverinterface.h"
33 #endif
34 
35 class QgsRectangle;
37 class QgsVectorLayer;
38 
39 #ifndef SIP_RUN
40 #include "nlohmann/json_fwd.hpp"
41 using namespace nlohmann;
42 #endif
43 
49 class SERVER_EXPORT QgsServerApiUtils
50 {
51 
52  public:
53 
59  static QgsRectangle parseBbox( const QString &bbox );
60 
67  static json layerExtent( const QgsVectorLayer *layer ) SIP_SKIP;
68 
72  static QgsCoordinateReferenceSystem parseCrs( const QString &bboxCrs );
73 
81  static const QVector<QgsMapLayer *> publishedWfsLayers( const QgsProject *project );
82 
83 #ifndef SIP_RUN
84 
94  template <typename T>
95  static const QVector<const T *> publishedWfsLayers( const QgsServerApiContext &context )
96  {
97 #ifdef HAVE_SERVER_PYTHON_PLUGINS
98  QgsAccessControl *accessControl = context.serverInterface()->accessControls();
99 #endif
100  const QgsProject *project = context.project();
101  QVector<const T *> result;
102  if ( project )
103  {
104  const QStringList wfsLayerIds = QgsServerProjectUtils::wfsLayerIds( *project );
105  const auto constLayers { project->layers<T *>() };
106  for ( const auto &layer : constLayers )
107  {
108  if ( ! wfsLayerIds.contains( layer->id() ) )
109  {
110  continue;
111  }
112 #ifdef HAVE_SERVER_PYTHON_PLUGINS
113  if ( accessControl && !accessControl->layerReadPermission( layer ) )
114  {
115  continue;
116  }
117 #endif
118  result.push_back( layer );
119  }
120  }
121  return result;
122  }
123 
124 #endif
125 
130  static QString sanitizedFieldValue( const QString &value );
131 
136  static QStringList publishedCrsList( const QgsProject *project );
137 
142  static QString crsToOgcUri( const QgsCoordinateReferenceSystem &crs );
143 
147  static QString appendMapParameter( const QString &path, const QUrl &requestUrl );
148 
149 };
150 #endif // QGSSERVERAPIUTILS_H
The QgsServerApiUtils class contains helper functions to handle common API operations.
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsRectangle parseBbox(const QString &bboxStr)
Parse bounding box.
const QgsProject * project() const
Returns the (possibly NULL) project.
const QgsCoordinateReferenceSystem & crs
QgsServerInterface * serverInterface() const
Returns the server interface.
QString id() const
Returns the layer&#39;s unique ID, which is used to access this layer from QgsProject.
#define SIP_SKIP
Definition: qgis_sip.h:126
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
Definition: qgsproject.h:89
The QgsServerApiContext class encapsulates the resources for a particular client request: the request...
bool layerReadPermission(const QgsMapLayer *layer) const
Returns the layer read right.
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
Definition: qgsproject.h:821
SERVER_EXPORT QStringList wfsLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published in WFS.
This class represents a coordinate reference system (CRS).
A helper class that centralizes restrictions given by all the access control filter plugins...
virtual QgsAccessControl * accessControls() const =0
Gets the registered access control filters.
Represents a vector layer which manages a vector based data sets.
static const QVector< const T * > publishedWfsLayers(const QgsServerApiContext &context)
Returns the list of layers of type T accessible to the WFS service for a given project.