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

Remove check of area of use of CRS during insert #972

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,12 @@ class TransactionHandler {
*
* @param response
* response that is used to write the result
* @param queryCRS
* list of all supported CRS
* @throws OWSException
* if a WFS specific exception occurs, e.g. a feature type is not served
* @throws IOException
* @throws XMLStreamException
*/
void doTransaction( HttpResponseBuffer response, List<ICRS> queryCRS )
void doTransaction( HttpResponseBuffer response )
throws OWSException, XMLStreamException, IOException {

LOG.debug( "doTransaction: " + request );
Expand All @@ -243,7 +241,7 @@ void doTransaction( HttpResponseBuffer response, List<ICRS> queryCRS )
break;
}
case INSERT: {
doInsert( (Insert) operation, queryCRS );
doInsert( (Insert) operation );
break;
}
case NATIVE: {
Expand Down Expand Up @@ -375,7 +373,7 @@ private void doDelete( Delete delete, Lock lock )
}
}

private void doInsert( Insert insert, List<ICRS> queryCRS )
private void doInsert( Insert insert )
throws OWSException {

LOG.debug( "doInsert: " + insert );
Expand All @@ -392,17 +390,15 @@ private void doInsert( Insert insert, List<ICRS> queryCRS )
throw new OWSException( msg, NO_APPLICABLE_CODE );
}

ICRS defaultCRS = determineDefaultCrs( insert, queryCRS );
ICRS defaultCRS = determineDefaultCrs( insert );
GMLVersion inputFormat = determineFormat( request.getVersion(), insert.getInputFormat() );

// TODO streaming
FeatureStoreTransaction ta = null;
try {
XMLStreamReader xmlStream = insert.getFeatures();
FeatureCollection fc = parseFeaturesOrCollection( xmlStream, inputFormat, defaultCRS );
evaluateSrsNameForFeatureCollection( fc, queryCRS, insert.getHandle() );
FeatureStore fs = service.getStores()[0];
ta = acquireTransaction( fs );
FeatureStoreTransaction ta = acquireTransaction( fs );
IDGenMode mode = insert.getIdGen();
if ( mode == null ) {
if ( VERSION_110.equals( request.getVersion() ) ) {
Expand Down Expand Up @@ -930,17 +926,12 @@ private String determineNamespaceUri( ValueReference valueReference, FeatureType
return ft.getName().getNamespaceURI();
}

private ICRS determineDefaultCrs( Insert insert, List<ICRS> queryCRS )
throws OWSException {
private ICRS determineDefaultCrs( Insert insert )
throws OWSException {
String srsName = insert.getSrsName();
if ( srsName != null ) {
try {
ICRS defaultCrs = CRSManager.lookup( insert.getSrsName() );
if ( !isCrsSupported( defaultCrs, queryCRS ) ) {
String msg = "The value of the srsName parameter is not one of the SRS values the server claims to support in its capabilities document.";
throw new OWSException( msg, INVALID_PARAMETER_VALUE, "srsName" );
}
return defaultCrs;
return CRSManager.lookup( insert.getSrsName() );
} catch ( UnknownCRSException e ) {
String msg = "Cannot perform insert. Specified srsName '" + srsName + "' is not supported by this WFS.";
throw new OWSException( msg, INVALID_PARAMETER_VALUE, "srsName" );
Expand All @@ -949,59 +940,4 @@ private ICRS determineDefaultCrs( Insert insert, List<ICRS> queryCRS )
return null;
}

private void evaluateSrsNameForFeatureCollection( FeatureCollection fc, List<ICRS> queryCRS, String handle )
throws OWSException {
for ( Feature feature : fc )
evaluateSrsNameForFeature( feature, queryCRS, handle );
}

private void evaluateSrsNameForFeature( Feature feature, List<ICRS> queryCRS, String handle )
throws OWSException {
Set<Geometry> geometries = new LinkedHashSet<Geometry>();
findFeaturesAndGeometries( feature, geometries, new LinkedHashSet<Feature>(), new LinkedHashSet<String>(),
new LinkedHashSet<String>() );
for ( Geometry geometry : geometries ) {
ICRS crs = geometry.getCoordinateSystem();
evaluateSrsName( crs, queryCRS, handle );
evaluateValidDomain( crs, geometry, handle );
}
}

private void evaluateSrsName( ICRS crs, List<ICRS> supportedCrs, String handle )
throws OWSException {
if ( !isCrsSupported( crs, supportedCrs ) ) {
String message = "The value of the at least one geometrie srs is not one of the SRS values "
+ "the server claims to support in its capabilities document.";
if ( handle == null || "".equals( handle ) )
handle = "Transaction";
throw new OWSException( message, OWSException.OPERATION_PROCESSING_FAILED, handle );
}
}

private void evaluateValidDomain( ICRS crs, Geometry geometry, String handle )
throws OWSException {
double[] validDomain = crs.getValidDomain();
if ( validDomain == null ) {
LOG.warn( "Valid domain of crs {} is not available. Check if geometry is inside the valid "
+ "domain not possible. The check is skipped and insert processed.", crs.getAlias() );
return;
}
Envelope validDomainBbox = GEOM_FACTORY.createEnvelope( validDomain[0], validDomain[1], validDomain[2],
validDomain[3], crs );
if ( !geometry.isWithin( validDomainBbox ) ) {
String message = "At least one geometry is not in the valid domain of the srs.";
if ( handle == null || "".equals( handle ) )
handle = "Transaction";
throw new OWSException( message, OWSException.OPERATION_PROCESSING_FAILED, handle );
}
}

private boolean isCrsSupported( ICRS crs, List<ICRS> supportedCrs )
throws OWSException {
if ( crs != null && supportedCrs != null )
if ( !supportedCrs.contains( crs ) )
return false;
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ public void doKVP( Map<String, String> kvpParamsUC, HttpServletRequest request,
}
checkTransactionsEnabled( requestName );
Transaction transaction = TransactionKVPAdapter.parse( kvpParamsUC );
new TransactionHandler( this, service, transaction, idGenMode, allowFeatureReferencesToDatastore ).doTransaction( response, queryCRS );
new TransactionHandler( this, service, transaction, idGenMode, allowFeatureReferencesToDatastore ).doTransaction( response );
break;
default:
throw new RuntimeException( "Internal error: Unhandled request '" + requestName + "'." );
Expand Down Expand Up @@ -983,7 +983,7 @@ public void doXML( XMLStreamReader xmlStream, HttpServletRequest request, HttpRe
checkTransactionsEnabled( requestName );
TransactionXmlReader transactionReader = new TransactionXmlReaderFactory().createReader( xmlStream );
Transaction transaction = transactionReader.read( xmlStream );
new TransactionHandler( this, service, transaction, idGenMode, allowFeatureReferencesToDatastore ).doTransaction( response, queryCRS );
new TransactionHandler( this, service, transaction, idGenMode, allowFeatureReferencesToDatastore ).doTransaction( response );
break;
default:
throw new RuntimeException( "Internal error: Unhandled request '" + requestName + "'." );
Expand Down Expand Up @@ -1150,7 +1150,7 @@ public void doSOAP( SOAPEnvelope soapDoc, HttpServletRequest request, HttpRespon
checkTransactionsEnabled( requestName );
TransactionXmlReader transactionReader = new TransactionXmlReaderFactory().createReader( requestVersion );
Transaction transaction = transactionReader.read( bodyXmlStream );
new TransactionHandler( this, service, transaction, idGenMode, allowFeatureReferencesToDatastore ).doTransaction( response, queryCRS );
new TransactionHandler( this, service, transaction, idGenMode, allowFeatureReferencesToDatastore ).doTransaction( response );
break;
default:
throw new RuntimeException( "Internal error: Unhandled request '" + requestName + "'." );
Expand Down