Skip to content
Permalink
Browse files

[BUGFIX][Server] Enhance cleaning propertyname and searching by prope…

…rtyname
  • Loading branch information
rldhont committed Apr 1, 2018
1 parent c1b9706 commit b7c566b1873baddd51856ba1c5f07363dfa804d9
Showing with 21 additions and 5 deletions.
  1. +2 −1 src/server/qgswfsprojectparser.cpp
  2. +3 −0 src/server/qgswfsprojectparser.h
  3. +16 −4 src/server/qgswfsserver.cpp
@@ -35,6 +35,7 @@ QgsWFSProjectParser::QgsWFSProjectParser(
#endif
{
mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
mCleanTagNameRegExp = QRegExp( "(?![\\w\\d\\.-])." );
}

QgsWFSProjectParser::~QgsWFSProjectParser()
@@ -464,7 +465,7 @@ void QgsWFSProjectParser::describeFeatureType( const QString& aTypeName, QDomEle

//xsd:element
QDomElement attElem = doc.createElement( "element"/*xsd:element*/ );
attElem.setAttribute( "name", attributeName.replace( " ", "_" ) );
attElem.setAttribute( "name", attributeName.replace( " ", "_" ).replace( mCleanTagNameRegExp, "" ) );
QVariant::Type attributeType = fields[idx].type();
if ( attributeType == QVariant::Int )
attElem.setAttribute( "type", "integer" );
@@ -37,6 +37,8 @@ class SERVER_EXPORT QgsWFSProjectParser
);
~QgsWFSProjectParser();

QRegExp getCleanTagNameRegExp() const { return mCleanTagNameRegExp; }

void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;
QString serviceUrl() const;
QString wfsServiceUrl() const;
@@ -56,6 +58,7 @@ class SERVER_EXPORT QgsWFSProjectParser

private:
QgsServerProjectParser* mProjectParser;
QRegExp mCleanTagNameRegExp;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
const QgsAccessControl* mAccessControl;
#endif
@@ -523,10 +523,12 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
QList<int> idxList;
QgsFields fields = layer->pendingFields();
// build corresponding propertyname
QList<QString> fieldnames;
QList<QString> propertynames;
for ( int idx = 0; idx < fields.count(); ++idx )
{
propertynames.append( fields[idx].name().replace( " ", "_" ) );
fieldnames.append( fields[idx].name() );
propertynames.append( fields[idx].name().replace( " ", "_" ).replace( mConfigParser->getCleanTagNameRegExp(), "" ) );
}
QString fieldName;
QDomElement propertyElem;
@@ -541,6 +543,10 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
fieldName = fieldName.section( ":", 1, 1 );
}
int fieldNameIdx = propertynames.indexOf( fieldName );
if ( fieldNameIdx == -1 )
{
fieldNameIdx = fieldnames.indexOf( fieldName );
}
if ( fieldNameIdx > -1 )
{
idxList.append( fieldNameIdx );
@@ -941,16 +947,22 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
QList<int> idxList;
QgsFields fields = layer->pendingFields();
// build corresponding propertyname
QList<QString> fieldnames;
QList<QString> propertynames;
for ( int idx = 0; idx < fields.count(); ++idx )
{
propertynames.append( fields[idx].name().replace( " ", "_" ) );
fieldnames.append( fields[idx].name() );
propertynames.append( fields[idx].name().replace( " ", "_" ).replace( mConfigParser->getCleanTagNameRegExp(), "" ) );
}
QString fieldName;
for ( alstIt = attrList.begin(); alstIt != attrList.end(); ++alstIt )
{
fieldName = *alstIt;
int fieldNameIdx = propertynames.indexOf( fieldName );
if ( fieldNameIdx == -1 )
{
fieldNameIdx = fieldnames.indexOf( fieldName );
}
if ( fieldNameIdx > -1 )
{
idxList.append( fieldNameIdx );
@@ -2059,7 +2071,7 @@ QDomElement QgsWFSServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc
continue;
}

QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( " ", "_" ) );
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( " ", "_" ).replace( mConfigParser->getCleanTagNameRegExp(), "" ) );
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
fieldElem.appendChild( fieldText );
typeNameElement.appendChild( fieldElem );
@@ -2141,7 +2153,7 @@ QDomElement QgsWFSServer::createFeatureGML3( QgsFeature* feat, QDomDocument& doc
continue;
}

QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( " ", "_" ) );
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( " ", "_" ).replace( mConfigParser->getCleanTagNameRegExp(), "" ) );
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
fieldElem.appendChild( fieldText );
typeNameElement.appendChild( fieldElem );

0 comments on commit b7c566b

Please sign in to comment.
You can’t perform that action at this time.