Skip to content

Commit

Permalink
address review and performance improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
myarjunar committed Oct 27, 2019
1 parent d656fee commit 5ca6104
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
52 changes: 27 additions & 25 deletions src/core/geocms/geonode/qgsgeonoderequest.cpp
Expand Up @@ -280,18 +280,16 @@ QList<QgsGeoNodeRequest::ServiceLayerDetail> QgsGeoNodeRequest::parseLayers( con

if ( layerMap.value( QStringLiteral( "typename" ) ).toString().isEmpty() )
{
const QStringList splitURL = layerMap.value( QStringLiteral( "detail_url" ) ).toString().split( '/' );
layerStruct.typeName = splitURL.at( splitURL.length() - 1 );
const QStringList splitUrl = layerMap.value( QStringLiteral( "detail_url" ) ).toString().split( '/' );
layerStruct.typeName = !splitUrl.isEmpty() ? splitUrl.last() : QString();
}
layerStruct.uuid = layerMap.value( QStringLiteral( "uuid" ) ).toString();
layerStruct.id = layerMap.value( QStringLiteral( "id" ) ).toString();
layerStruct.name = layerMap.value( QStringLiteral( "name" ) ).toString();
layerStruct.typeName = layerMap.value( QStringLiteral( "typename" ) ).toString();
layerStruct.title = layerMap.value( QStringLiteral( "title" ) ).toString();

layerStruct = parseOWSUrl( layerStruct, layerLinks );

if ( layerStruct.wmsURL.isEmpty() && layerStruct.wfsURL.isEmpty() && layerStruct.xyzURL.isEmpty() )
if ( ! layerMap.contains( QStringLiteral( "links" ) ) )
{
if ( wmsURLFormat.isEmpty() && wfsURLFormat.isEmpty() && xyzURLFormat.isEmpty() )
{
Expand All @@ -303,43 +301,47 @@ QList<QgsGeoNodeRequest::ServiceLayerDetail> QgsGeoNodeRequest::parseLayers( con
const QVariantMap resourceUriMap = resourceUriObject.toVariantMap();
QVariantList resourceUriLinks = resourceUriMap.value( QStringLiteral( "links" ) ).toList();
QgsGeoNodeRequest::ServiceLayerDetail tempLayerStruct;
tempLayerStruct = parseOWSUrl( tempLayerStruct, resourceUriLinks );
tempLayerStruct = parseOwsUrl( tempLayerStruct, resourceUriLinks );

if ( tempLayerStruct.wmsURL.isEmpty() && tempLayerStruct.wfsURL.isEmpty() && tempLayerStruct.xyzURL.isEmpty() )
continue;

// Avoid iterating all the layers to get the service url. Instead, generate a string format once we found one service url
// for every service (wms, wfs, xyz). And then use the string format for the other layers since they are identical.
if ( tempLayerStruct.server == "qgis-server" )
if ( tempLayerStruct.server == QgsGeoNodeRequest::QGIS_SERVER )
{
wmsURLFormat = !tempLayerStruct.wmsURL.isEmpty() ? tempLayerStruct.wmsURL.replace( layerStruct.name, "%1" ) : "";
wfsURLFormat = !tempLayerStruct.wfsURL.isEmpty() ? tempLayerStruct.wfsURL.replace( layerStruct.name, "%1" ) : "";
xyzURLFormat = !tempLayerStruct.xyzURL.isEmpty() ? tempLayerStruct.xyzURL.replace( layerStruct.name, "%1" ) : "";
wmsURLFormat = ! tempLayerStruct.wmsURL.isEmpty() ? tempLayerStruct.wmsURL.replace( layerStruct.name, QStringLiteral( "%1" ) ) : QString();
wfsURLFormat = ! tempLayerStruct.wfsURL.isEmpty() ? tempLayerStruct.wfsURL.replace( layerStruct.name, QStringLiteral( "%1" ) ) : QString();
xyzURLFormat = ! tempLayerStruct.xyzURL.isEmpty() ? tempLayerStruct.xyzURL.replace( layerStruct.name, QStringLiteral( "%1" ) ) : QString();
}
else if ( tempLayerStruct.server == "geoserver" )
else if ( tempLayerStruct.server == QgsGeoNodeRequest::GEOSERVER )
{
wmsURLFormat = !tempLayerStruct.wmsURL.isEmpty() ? tempLayerStruct.wmsURL : "";
wfsURLFormat = !tempLayerStruct.wfsURL.isEmpty() ? tempLayerStruct.wfsURL : "";
xyzURLFormat = !tempLayerStruct.xyzURL.isEmpty() ? tempLayerStruct.xyzURL.replace( layerStruct.name, "%1" ) : "";
wmsURLFormat = ! tempLayerStruct.wmsURL.isEmpty() ? tempLayerStruct.wmsURL : QString();
wfsURLFormat = ! tempLayerStruct.wfsURL.isEmpty() ? tempLayerStruct.wfsURL : QString();
xyzURLFormat = ! tempLayerStruct.xyzURL.isEmpty() ? tempLayerStruct.xyzURL.replace( layerStruct.name, QStringLiteral( "%1" ) ) : "";
}
}
else
{
layers.append( layerStruct );
continue;
}
}

// Replace string argument with the layer id.
layerStruct.wmsURL = wmsURLFormat.contains( "%1" ) ? wmsURLFormat.arg( layerStruct.name ) : wmsURLFormat;
layerStruct.wfsURL = wfsURLFormat.contains( "%1" ) ? wfsURLFormat.arg( layerStruct.name ) : wfsURLFormat;
layerStruct.xyzURL = xyzURLFormat.contains( "%1" ) ? xyzURLFormat.arg( layerStruct.name ) : xyzURLFormat;
else
{
// Replace string argument with the layer id.
layerStruct.wmsURL = wmsURLFormat.contains( "%1" ) ? wmsURLFormat.arg( layerStruct.name ) : wmsURLFormat;
layerStruct.wfsURL = wfsURLFormat.contains( "%1" ) ? wfsURLFormat.arg( layerStruct.name ) : wfsURLFormat;
layerStruct.xyzURL = xyzURLFormat.contains( "%1" ) ? xyzURLFormat.arg( layerStruct.name ) : xyzURLFormat;
}
}
else
layerStruct = parseOwsUrl( layerStruct, layerLinks );

layers.append( layerStruct );
}

return layers;
}

QgsGeoNodeRequest::ServiceLayerDetail QgsGeoNodeRequest::parseOWSUrl( QgsGeoNodeRequest::ServiceLayerDetail &layerStruct, const QVariantList &layerLinks )
QgsGeoNodeRequest::ServiceLayerDetail QgsGeoNodeRequest::parseOwsUrl( QgsGeoNodeRequest::ServiceLayerDetail &layerStruct, const QVariantList &layerLinks )
{
QString urlFound;
for ( const QVariant &link : layerLinks )
Expand All @@ -364,8 +366,8 @@ QgsGeoNodeRequest::ServiceLayerDetail QgsGeoNodeRequest::parseOWSUrl( QgsGeoNode
}
}

if ( layerStruct.server.isEmpty() )
layerStruct.server = urlFound.contains( QStringLiteral( "qgis-server" ) ) ? QStringLiteral( "qgis-server" ) : QStringLiteral( "geoserver" );
if ( layerStruct.server == QgsGeoNodeRequest::UNKNOWN )
layerStruct.server = urlFound.contains( QStringLiteral( "qgis-server" ) ) ? QgsGeoNodeRequest::QGIS_SERVER : QgsGeoNodeRequest::GEOSERVER;
}

return layerStruct;
Expand Down
14 changes: 12 additions & 2 deletions src/core/geocms/geonode/qgsgeonoderequest.h
Expand Up @@ -67,6 +67,16 @@ class CORE_EXPORT QgsGeoNodeRequest : public QObject
Q_OBJECT
public:

/**
* GeoNode backend server type.
*/
typedef enum
{
UNKNOWN,
QGIS_SERVER,
GEOSERVER
} BackendServer;

/**
* Service layer details for an individual layer from a GeoNode connection.
*/
Expand All @@ -89,7 +99,7 @@ class CORE_EXPORT QgsGeoNodeRequest : public QObject
//! XYZ tileserver URL for layer
QString xyzURL;
//! Backend server (geoserver or qgis-server)
QString server;
BackendServer server{};
};

/**
Expand Down Expand Up @@ -220,7 +230,7 @@ class CORE_EXPORT QgsGeoNodeRequest : public QObject
/**
* Returns the updated ServiceLayerDetail struct with WMS/WFS/XYZ url.
*/
QgsGeoNodeRequest::ServiceLayerDetail parseOWSUrl( QgsGeoNodeRequest::ServiceLayerDetail &layerStruct, const QVariantList &layerLinks );
QgsGeoNodeRequest::ServiceLayerDetail parseOwsUrl( QgsGeoNodeRequest::ServiceLayerDetail &layerStruct, const QVariantList &layerLinks );

public slots:

Expand Down

0 comments on commit 5ca6104

Please sign in to comment.