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

Add bbox_cache.properties per SQLFeatureStore #1477

Merged
merged 9 commits into from
May 12, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ Occam Labs UG (haftungsbeschränkt)
----------------------------------------------------------------------------*/
package org.deegree.feature.persistence;

import java.io.File;
import java.io.IOException;

import org.deegree.feature.persistence.cache.BBoxCache;
import org.deegree.feature.persistence.cache.BBoxPropertiesCache;
import org.deegree.workspace.Workspace;
Expand All @@ -53,12 +50,16 @@ Occam Labs UG (haftungsbeschränkt)
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
* Responsible for finding feature store resources.
*
*
* @author <a href="mailto:schmitz@occamlabs.de">Andreas Schmitz</a>
* @author last edited by: $Author: stranger $
*
* @version $Revision: $, $Date: $
*/
public class FeatureStoreManager extends DefaultResourceManager<FeatureStore> {
Expand All @@ -67,29 +68,82 @@ public class FeatureStoreManager extends DefaultResourceManager<FeatureStore> {

private static final String BBOX_CACHE_FILE = "bbox_cache.properties";

private static final String BBOX_CACHE_FEATURESTOE_FILE = "bbox_cache_%s.properties";

private BBoxPropertiesCache bboxCache;

private final Map<String, BBoxPropertiesCache> customBboxCaches = new HashMap<>();

private Workspace workspace;

public FeatureStoreManager() {
super( new DefaultResourceManagerMetadata<FeatureStore>( FeatureStoreProvider.class, "feature stores",
"datasources/feature" ) );
super( new DefaultResourceManagerMetadata<>( FeatureStoreProvider.class, "feature stores",
"datasources/feature" ) );
}

@Override
public void startup( Workspace workspace ) {
this.workspace = workspace;
super.startup( workspace );
}

/**
* Returns the bbox_cache.properties file (which is created if not existing).
* As there may be feature store specific bbox_cache_FEATURESTOE_ID.properties
* file the method getBBoxCache( String featureStoreId ) should be used.
*/
public BBoxCache getBBoxCache() {
return getOrCreateBBoxCache();
}

/**
* Returns the feature store specific bbox_cache_FEATURESTOE_ID.properties if existing,
* if not the bbox_cache.properties file is returned (which is created if not existing).
*
* @param featureStoreId
* @return
*/
public BBoxCache getBBoxCache( String featureStoreId ) {
if ( customBboxCaches.containsValue( featureStoreId ) ) {
return customBboxCaches.get( featureStoreId );
}
BBoxPropertiesCache customBBoxCache = getCustomBBoxCache( featureStoreId );
if ( customBBoxCache != null ) {
customBboxCaches.put( featureStoreId, customBBoxCache );
return customBBoxCache;
}
return getOrCreateBBoxCache();
}

private BBoxPropertiesCache getOrCreateBBoxCache() {
try {
if ( workspace instanceof DefaultWorkspace ) {
if ( bboxCache == null ) {
File dir = new File( ( (DefaultWorkspace) workspace ).getLocation(), getMetadata().getWorkspacePath() );
bboxCache = new BBoxPropertiesCache( new File( dir, BBOX_CACHE_FILE ) );
File propsFile = new File( dir, BBOX_CACHE_FILE );
bboxCache = new BBoxPropertiesCache( propsFile );
}
// else?
} catch ( IOException e ) {
LOG.error( "Unable to initialize global envelope cache: " + e.getMessage(), e );
LOG.error( "Unable to initialize envelope cache {}: {}", BBOX_CACHE_FILE, e.getMessage() );
LOG.trace( e.getMessage(), e );
}
super.startup( workspace );
return bboxCache;
}

public BBoxCache getBBoxCache() {
stephanr marked this conversation as resolved.
Show resolved Hide resolved
return bboxCache;
private BBoxPropertiesCache getCustomBBoxCache( String featureStoreId ) {
try {
if ( workspace instanceof DefaultWorkspace ) {
File dir = new File( ( (DefaultWorkspace) workspace ).getLocation(), getMetadata().getWorkspacePath() );
File propsFile = new File( dir, String.format( BBOX_CACHE_FEATURESTOE_FILE, featureStoreId ) );
if ( propsFile.exists() ) {
return new BBoxPropertiesCache( propsFile );
}
}
} catch ( IOException e ) {
LOG.error( "Unable to initialize envelope cache for feature store with id {}: {}", featureStoreId,
e.getMessage() );
LOG.trace( e.getMessage(), e );
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1773,9 +1773,10 @@ public void init() {
}

// TODO make this configurable
String sqlFeatureStoreId = getMetadata().getIdentifier().getId();
FeatureStoreManager fsMgr = this.workspace.getResourceManager( FeatureStoreManager.class );
if ( fsMgr != null ) {
this.bboxCache = fsMgr.getBBoxCache();
this.bboxCache = fsMgr.getBBoxCache( sqlFeatureStoreId );
} else {
LOG.warn( "Unmanaged feature store." );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory;
Expand Down Expand Up @@ -170,9 +171,10 @@ private boolean isFileToIgnore( File file ) {
final String path = file.getAbsolutePath();
if ( path.contains( "appschemas" ) )
return true;
if ( "bbox_cache.properties".equals( file.getName() ) )
String fileName = file.getName();
if ( Pattern.matches( "bbox_cache.*\\.properties", fileName ) )
return true;
if ( "main.xml".equals( file.getName() ) )
if ( "main.xml".equals( fileName ) )
return true;
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2008,3 +2008,19 @@ After entering the URL, click *Import*:

.Imported INSPIRE datasets via the Loader
image::console_featurestore_mapping20.jpg[Imported INSPIRE datasets via the Loader,scaledwidth=50.0%]

==== Spatial extent of FeatureTypes

The spatial extent of all feature types defined in all SQLFeatureStore configurations are cached in a file named bbox_cache.properties. The file is created when the workspace is initialised.
The file contains the bounding box with its coordinate system assigned to the qualified name of each feature type, e.g.:

----
{http\://www.deegree.org/app}Lakes=epsg\:4326,11.16,51.29,14.83,53.59
{http\://www.deegree.org/app}Railroads=epsg\:4326,11.16,51.29,14.83,53.59
----

Inserting new features via WFS-T results in an increased bounding box in the bbox_cache.properties file, if the extent did not include the features.
The file can also be used to configure the bounding box to a larger extent than the data, e.g. if the extent is already known but not all data imported.
The extent of a FeatureType is written in the capabilities as WGS84BoundingBox (WFS 2.0) of the FeatureType.

It is possible to configure a bbox_cache_<FeatureStoreId>.properties per SQLFeatureStore, this FeatureStore specific configuration is preferred over the bbox_cache.properties.