Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed exception of WFS if requested feature (by resourceid) does not match the requested feature type (by typenames) #718

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
import org.deegree.geometry.Envelope;
import org.deegree.geometry.Geometry;
import org.deegree.geometry.GeometryTransformer;
import org.deegree.protocol.wfs.getfeature.TypeName;
import org.deegree.sqldialect.SQLDialect;
import org.deegree.sqldialect.filter.AbstractWhereBuilder;
import org.deegree.sqldialect.filter.DBField;
Expand Down Expand Up @@ -545,7 +546,7 @@ private GMLObject getObjectByIdRelational( String id )
throw new UnsupportedOperationException( msg );
}

FeatureInputStream rs = queryByIdFilterRelational( new IdFilter( id ), null );
FeatureInputStream rs = queryByIdFilterRelational( null, new IdFilter( id ), null );
try {
Iterator<Feature> iter = rs.iterator();
if ( iter.hasNext() ) {
Expand Down Expand Up @@ -644,7 +645,7 @@ public int queryHits( Query query )
throw new FilterEvaluationException( msg );
}
// should be no problem iterating over the features (id queries usually request only a few ids)
hits = queryByIdFilter( (IdFilter) filter, query.getSortProperties() ).count();
hits = queryByIdFilter( query.getTypeNames(), (IdFilter) filter, query.getSortProperties() ).count();
}
return hits;
}
Expand Down Expand Up @@ -901,7 +902,7 @@ public FeatureInputStream query( Query query )
String msg = "Invalid query. If no type names are specified, it must contain an IdFilter.";
throw new FilterEvaluationException( msg );
}
result = queryByIdFilter( (IdFilter) filter, query.getSortProperties() );
result = queryByIdFilter( query.getTypeNames(), (IdFilter) filter, query.getSortProperties() );
}
return result;
}
Expand Down Expand Up @@ -962,15 +963,16 @@ public void remove() {
return new CombinedFeatureInputStream( rsIter );
}

private FeatureInputStream queryByIdFilter( IdFilter filter, SortProperty[] sortCrit )
private FeatureInputStream queryByIdFilter( TypeName[] typeNames, IdFilter filter, SortProperty[] sortCrit )
throws FeatureStoreException {
if ( blobMapping != null ) {
return queryByIdFilterBlob( filter, sortCrit );
return queryByIdFilterBlob( typeNames, filter, sortCrit );
}
return queryByIdFilterRelational( filter, sortCrit );
return queryByIdFilterRelational( typeNames, filter, sortCrit );
}

private FeatureInputStream queryByIdFilterBlob( IdFilter filter, SortProperty[] sortCrit )
private FeatureInputStream queryByIdFilterBlob( TypeName[] typeNames,
IdFilter filter, SortProperty[] sortCrit )
throws FeatureStoreException {

FeatureInputStream result = null;
Expand All @@ -997,7 +999,7 @@ private FeatureInputStream queryByIdFilterBlob( IdFilter filter, SortProperty[]
begin = System.currentTimeMillis();
rs = stmt.executeQuery();
LOG.debug( "Executing SELECT took {} [ms] ", System.currentTimeMillis() - begin );
FeatureBuilder builder = new FeatureBuilderBlob( this, blobMapping );
FeatureBuilder builder = new FeatureBuilderBlob( this, blobMapping, typeNames );
result = new IteratorFeatureInputStream( new FeatureResultSetIterator( builder, rs, conn, stmt ) );
} catch ( Exception e ) {
release( rs, stmt, conn );
Expand All @@ -1013,7 +1015,7 @@ private FeatureInputStream queryByIdFilterBlob( IdFilter filter, SortProperty[]
return result;
}

private FeatureInputStream queryByIdFilterRelational( IdFilter filter, SortProperty[] sortCrit )
private FeatureInputStream queryByIdFilterRelational( TypeName[] typeNames, IdFilter filter, SortProperty[] sortCrit )
throws FeatureStoreException {

LinkedHashMap<QName, List<IdAnalysis>> ftNameToIdAnalysis = new LinkedHashMap<QName, List<IdAnalysis>>();
Expand Down Expand Up @@ -1042,6 +1044,7 @@ private FeatureInputStream queryByIdFilterRelational( IdFilter filter, SortPrope

QName ftName = ftNameToIdAnalysis.keySet().iterator().next();
FeatureType ft = getSchema().getFeatureType( ftName );
checkIfFeatureTypIsRequested( typeNames, ft );
FeatureTypeMapping ftMapping = getSchema().getFtMapping( ftName );
FIDMapping fidMapping = ftMapping.getFidMapping();
List<IdAnalysis> idKernels = ftNameToIdAnalysis.get( ftName );
Expand Down Expand Up @@ -1626,4 +1629,18 @@ public void init() {
nullEscalation = config.isNullEscalation();
}
}
}

public void checkIfFeatureTypIsRequested( TypeName[] typeNames, FeatureType ft ) {
if ( typeNames != null && typeNames.length > 0 ) {
boolean isFeatureTypeRequested = false;
for ( TypeName typeName : typeNames ) {
if ( typeName.getFeatureTypeName().equals( ft.getName() ) )
isFeatureTypeRequested = true;
}
if ( !isFeatureTypeRequested )
throw new InvalidParameterValueException( "Requested feature does not match the requested feature type.",
"RESOURCEID" );
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.deegree.feature.Feature;
import org.deegree.feature.persistence.sql.FeatureBuilder;
import org.deegree.feature.persistence.sql.SQLFeatureStore;
import org.deegree.protocol.wfs.getfeature.TypeName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -67,6 +68,8 @@ public class FeatureBuilderBlob implements FeatureBuilder {

private final ICRS crs;

private TypeName[] typeNames;

/**
* Creates a new {@link FeatureBuilderBlob} instance.
*
Expand All @@ -76,12 +79,28 @@ public class FeatureBuilderBlob implements FeatureBuilder {
* blob mapping parameters, must not be <code>null</code>
*/
public FeatureBuilderBlob( SQLFeatureStore fs, BlobMapping blobMapping ) {
this( fs, blobMapping, null );
}

/**
* Creates a new {@link FeatureBuilderBlob} instance.
*
* @param fs
* feature store, must not be <code>null</code>
* @param blobMapping
* blob mapping parameters, must not be <code>null</code>
* @param typeNames
* list of requested type names, if {@link #buildFeature(ResultSet)} is invoked and a feature is not in
* this list an exception is thrown
*/
public FeatureBuilderBlob( SQLFeatureStore fs, BlobMapping blobMapping, TypeName[] typeNames ) {
this.fs = fs;
this.blobMapping = blobMapping;
this.codec = blobMapping.getCodec();
this.crs = blobMapping.getCRS();
this.typeNames = typeNames;
}

@Override
public List<String> getInitialSelectList() {
List<String> columns = new ArrayList<String>();
Expand Down Expand Up @@ -109,10 +128,13 @@ public Feature buildFeature( ResultSet rs )
} else {
LOG.debug( "Cache hit." );
}
fs.checkIfFeatureTypIsRequested( typeNames, feature.getType() );
} catch ( Exception e ) {
String msg = "Cannot recreate feature from result set: " + e.getMessage();
throw new SQLException( msg, e );
}
return feature;
}


}