28#include "moc_qgsserverogcapi.cpp"
30using namespace Qt::StringLiterals;
32QMap<QgsServerOgcApi::ContentType, QStringList> QgsServerOgcApi::sContentTypeMime = []() -> QMap<QgsServerOgcApi::ContentType, QStringList> {
33 QMap<QgsServerOgcApi::ContentType, QStringList> map;
44QHash<QgsServerOgcApi::ContentType, QList<QgsServerOgcApi::ContentType>> QgsServerOgcApi::sContentTypeAliases = []() -> QHash<ContentType, QList<ContentType>> {
45 QHash<QgsServerOgcApi::ContentType, QList<QgsServerOgcApi::ContentType>> map;
66 std::shared_ptr<QgsServerOgcApiHandler> hp( handler );
67 mHandlers.emplace_back( std::move( hp ) );
73 QUrl u { url.adjusted( QUrl::StripTrailingSlash | QUrl::NormalizePathSegments ) };
74 if ( u.path().contains(
"//"_L1 ) )
76 u.setPath( u.path().replace(
"//"_L1, QChar(
'/' ) ) );
79 if ( !u.path().startsWith(
'/' ) )
81 u.setPath( u.path().prepend(
'/' ) );
91 auto hasMatch {
false };
92 for (
const auto &handler : mHandlers )
95 if ( handler->path().match( path ).hasMatch() )
103 handler->handleRequest( context );
105 catch ( json::exception &ex )
121 return sContentTypeMime;
126 return sContentTypeAliases;
138 case Profile::JsonFg:
140 case Profile::JsonFgPlus:
141 return u
"jsonfg-plus"_s;
146 return u
"rel-as-key"_s;
148 return u
"rel-as-uri"_s;
150 return u
"rel-as-link"_s;
161 return u
"http://www.opengis.net/def/profile/OGC/0/rfc7946"_s;
165 case Profile::JsonFg:
166 return u
"http://www.opengis.net/def/profile/OGC/0/jsonfg"_s;
167 case Profile::JsonFgPlus:
168 return u
"http://www.opengis.net/def/profile/OGC/0/jsonfg-plus"_s;
171 return u
"http://www.opengis.net/def/profile/ogc/0/rel-as-key"_s;
173 return u
"http://www.opengis.net/def/profile/ogc/0/rel-as-uri"_s;
175 return u
"http://www.opengis.net/def/profile/ogc/0/rel-as-link"_s;
187 return "http://www.opengis.net/def/rel/ogc/1.0/schema";
189 static const QMetaEnum metaEnum = QMetaEnum::fromType<QgsServerOgcApi::Rel>();
190 std::string val { metaEnum.valueToKey( rel ) };
191 std::replace( val.begin(), val.end(),
'_',
'-' );
197 static const QMetaEnum metaEnum = QMetaEnum::fromType<ContentType>();
198 QString result { metaEnum.valueToKey( ct ) };
199 return result.replace(
'_',
'-' );
204 static const QMetaEnum metaEnum = QMetaEnum::fromType<ContentType>();
205 return metaEnum.valueToKey( ct );
228 const QString exts = QString::fromStdString( extension );
230 for (
auto it = constMimeTypes.constBegin(); it != constMimeTypes.constEnd(); ++it )
232 const auto constValues = it.value();
233 for (
const auto &value : constValues )
235 if ( value.contains( exts, Qt::CaseSensitivity::CaseInsensitive ) )
248 if ( !sContentTypeMime.contains( contentType ) )
252 return sContentTypeMime.value( contentType ).first().toStdString();
@ Warning
Warning message.
@ Info
Information message.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
Bad request error API exception.
Encapsulates the resources for a particular client request.
QString handlerPath() const
Returns the handler component of the URL path, i.e.
Internal server error API exception.
QgsServerApi(QgsServerInterface *serverIface)
Creates a QgsServerApi object.
QgsServerInterface * serverIface() const
Returns the server interface.
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.
static QUrl sanitizeUrl(const QUrl &url)
Returns a sanitized url with extra slashes removed and the path URL component that always starts with...
void executeRequest(const QgsServerApiContext &context) const override
Executes a request by passing the given context to the API handlers.
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.
static QString contentTypeToExtension(const QgsServerOgcApi::ContentType &ct)
Returns the file extension for a ct (Content-Type).
const QString description() const override
Returns the API description.
const std::vector< std::shared_ptr< QgsServerOgcApiHandler > > handlers() const
Returns registered handlers.
static const QMap< QgsServerOgcApi::ContentType, QStringList > contentTypeMimes()
Returns a map of contentType => list of mime types.
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"
static QString contentTypeToString(const QgsServerOgcApi::ContentType &ct)
Returns the string representation of a ct (Content-Type) attribute.
static QString profileToString(const QgsServerOgcApi::Profile &profile)
Returns a string representation of the profile.
static QString profileToUri(const QgsServerOgcApi::Profile &profile)
Returns a URI string representation of the profile.
@ profile
"http://www.opengis.net/spec/ogcapi-features-5/0.0/conf/feature-references"
@ schema
"http://www.opengis.net/def/rel/ogc/0.0/schema"
static std::string contentTypeToStdString(const QgsServerOgcApi::ContentType &ct)
Returns the string representation of a ct (Content-Type) attribute.
static std::string mimeType(const QgsServerOgcApi::ContentType &contentType)
Returns the mime-type for the contentType or an empty string if not found.
const QString version() const override
Returns the version of the service.
~QgsServerOgcApi() override
const QString name() const override
Returns the API name.
@ Rfc7946
GeoJSON profile according to RFC7946.
@ RelAsUri
JSON responses that include URI for referenced resources http://www.opengis.net/def/profile/ogc/0/rel...
@ RelAsLink
JSON responses that include links for referenced resources http://www.opengis.net/def/profile/ogc/0/r...
@ RelAsKey
JSON responses that include key for referenced resources http://www.opengis.net/def/profile/ogc/0/rel...
static std::string relToString(const QgsServerOgcApi::Rel &rel)
Returns the string representation of rel attribute, to be used or "rel" link attribute in an OGC API ...
static const QHash< QgsServerOgcApi::ContentType, QList< QgsServerOgcApi::ContentType > > contentTypeAliases()
Returns contentType specializations (e.g.
static QgsServerOgcApi::ContentType contentTypeFromExtension(const std::string &extension)
Returns the Content-Type value corresponding to extension.