Skip to content

Commit

Permalink
Merge remote-tracking branch 'deegree/main' into changeConfigurationE…
Browse files Browse the repository at this point in the history
…xamples
  • Loading branch information
julianzz98 committed May 12, 2023
2 parents a7dbe7b + da57c96 commit 48b42db
Show file tree
Hide file tree
Showing 31 changed files with 608 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ private Style parseStyle( String styleName, OMElement styleEl )
String url = getNodeAsString( styleEl, new XPath( getPrefix() + "LegendURL/" + getPrefix()
+ "OnlineResource/@xlink:href", nsContext ), null );
Style style = new Style();
style.setName( styleName );
if ( url != null ) {
style.setLegendURL( new URL( url ) );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
package org.deegree.sqldialect;

import org.deegree.commons.jdbc.TableName;

/**
* @author <a href="mailto:goltz@lat-lon.de">Lyn Goltz </a>
*/
public class SortCriterion {

private final String columneName;
private final String columnName;

private final TableName tableName;

private final boolean sortAscending;

public SortCriterion( String columneName, boolean sortAscending ) {
this.columneName = columneName;
public SortCriterion( String columnName, TableName tableName, boolean sortAscending ) {
this.columnName = columnName;
this.sortAscending = sortAscending;
this.tableName = tableName;
}

public String getColumneName() {
return columneName;
public String getColumnName() {
return columnName;
}

public TableName getTableName() {
return tableName;
}

public boolean isSortAscending() {
return sortAscending;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -981,8 +981,8 @@ protected SQLExpression toProtoSQL( List<SortCriterion> sortCriteria )
if ( sortCriteria.indexOf( sortCriterion ) > 0 ) {
builder.add( "," );
}
String rootTableAlias = aliasManager.getRootTableAlias();
String columnName = sortCriterion.getColumneName();
String rootTableAlias = aliasManager.getTableAlias( sortCriterion.getTableName() );
String columnName = sortCriterion.getColumnName();
builder.add( rootTableAlias == null ? columnName : ( rootTableAlias + "." + columnName ) );
if ( sortCriterion.isSortAscending() ) {
builder.add( " ASC" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ Occam Labs UG (haftungsbeschränkt)
import static org.deegree.theme.Themes.aggregateSpatialMetadata;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -77,10 +80,10 @@ Occam Labs UG (haftungsbeschränkt)

/**
* Builds a {@link StandardTheme} from jaxb config beans.
*
*
* @author <a href="mailto:schmitz@occamlabs.de">Andreas Schmitz</a>
* @author last edited by: $Author: stranger $
*
*
* @version $Revision: $, $Date: $
*/
public class StandardThemeBuilder implements ResourceBuilder<Theme> {
Expand Down Expand Up @@ -170,11 +173,46 @@ private StandardTheme buildTheme( ThemeType current, List<ThemeType.Layer> layer
md.setRequestable( false );
}
md.setDimensions( dims );
md.setStyles( styles );
md.setLegendStyles( legendStyles );
if ( current.getLegendGraphic() != null && current.getLegendGraphic().getValue() != null
&& !current.getLegendGraphic().getValue().isEmpty() ) {
Map<String, Style> configuredLegendStyles = new HashMap<>();
Style style = parseConfiguredStyle( current.getLegendGraphic() );
configuredLegendStyles.put( style.getName(), style );
md.setStyles( configuredLegendStyles );
md.setLegendStyles( configuredLegendStyles );
} else {
md.setStyles( styles );
md.setLegendStyles( legendStyles );
}
return new StandardTheme( md, thms, lays, metadata );
}

private Style parseConfiguredStyle( ThemeType.LegendGraphic configuredLegendGraphic ) {
Style style = new Style();
style.setName( "default" );
URL url = null;
try {
url = new URL( configuredLegendGraphic.getValue() );
if ( url.toURI().isAbsolute() ) {
style.setLegendURL( url );
}
style.setPrefersGetLegendGraphicUrl( configuredLegendGraphic.isOutputGetLegendGraphicUrl() );
} catch ( Exception e ) {
LOG.debug( "LegendGraphic was not an absolute URL." );
LOG.trace( "Stack trace:", e );
}

if ( url == null ) {
File file = metadata.getLocation().resolveToFile( configuredLegendGraphic.getValue() );
if ( file.exists() ) {
style.setLegendFile( file );
} else {
LOG.warn( "LegendGraphic {} could not be resolved to a legend.", configuredLegendGraphic );
}
}
return style;
}

private Theme buildAutoTheme( Layer layer ) {
LayerMetadata md = new LayerMetadata( null, null, null );
LayerMetadata lmd = layer.getMetadata();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
</element>
<group ref="d:Description" />
<group ref="g:SpatialMetadata" />
<element name="LegendGraphic" minOccurs="0" >
<complexType>
<simpleContent>
<extension base="string">
<attribute name="outputGetLegendGraphicUrl" type="boolean" default="true" use="optional" />
</extension>
</simpleContent>
</complexType>
</element>
<element name="Layer" minOccurs="0" maxOccurs="unbounded">
<complexType>
<simpleContent>
Expand Down
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() {
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 @@ -68,7 +68,7 @@
<artifactId>antlr-runtime</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>net.gcardone.junidecode</groupId>
<artifactId>junidecode</artifactId>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
import org.deegree.commons.utils.kvp.InvalidParameterValueException;
import org.deegree.cs.coordinatesystems.ICRS;
import org.deegree.cs.persistence.CRSManager;
import org.deegree.cs.refs.coordinatesystem.CRSRef;
import org.deegree.db.ConnectionProvider;
import org.deegree.db.ConnectionProviderProvider;
import org.deegree.feature.Feature;
Expand Down Expand Up @@ -1011,10 +1010,10 @@ public FeatureInputStream query( final Query[] queries )
}
}

boolean isMaxFeaturesAndStartIndexApplicable = isMaxFeaturesAndStartIndexApplicable( queries );
if ( wmsStyleQuery ) {
return queryMultipleFts( queries, env );
return queryMultipleFtsFromBlob( queries, env, isMaxFeaturesAndStartIndexApplicable );
}
boolean isMaxFeaturesAndStartIndexApplicable = isMaxFeaturesAndStartIndexApplicable( queries );
Iterator<FeatureInputStream> rsIter = new Iterator<FeatureInputStream>() {
int i = 0;

Expand Down Expand Up @@ -1534,7 +1533,8 @@ private FeatureInputStream queryByOperatorFilter( Query query, List<QName> ftNam
return result;
}

private FeatureInputStream queryMultipleFts( Query[] queries, Envelope looseBBox )
private FeatureInputStream queryMultipleFtsFromBlob( Query[] queries, Envelope looseBBox,
boolean isMaxFeaturesAndStartIndexApplicable )
throws FeatureStoreException {
FeatureInputStream result = null;
Connection conn = null;
Expand All @@ -1547,14 +1547,20 @@ private FeatureInputStream queryMultipleFts( Query[] queries, Envelope looseBBox
blobWb = getWhereBuilderBlob( bboxFilter, conn );
}
conn = getConnection();
final short[] ftId = getQueriedFeatureTypeIds( queries );
final List<Short> ftIds = new ArrayList<>();
final StringBuilder sql = new StringBuilder();
for ( int i = 0; i < ftId.length; i++ ) {
for ( int i = 0; i < queries.length; i++ ) {
Query query = queries[i];
if ( query.getTypeNames() == null || query.getTypeNames().length > 1 ) {
String msg = "Join queries between multiple feature types are currently not supported.";
throw new UnsupportedOperationException( msg );
}
short ftId = getFtId( query.getTypeNames()[0].getFeatureTypeName() );
if ( i > 0 ) {
sql.append( " UNION " );
}
sql.append( "SELECT gml_id,binary_object" );
if ( ftId.length > 1 ) {
if ( queries.length > 1 ) {
sql.append( "," );
sql.append( i );
sql.append( " AS QUERY_POS" );
Expand All @@ -1565,14 +1571,18 @@ private FeatureInputStream queryMultipleFts( Query[] queries, Envelope looseBBox
if ( looseBBox != null ) {
sql.append( " AND gml_bounded_by && ?" );
}
if (isMaxFeaturesAndStartIndexApplicable) {
appendOffsetAndFetch(sql, query.getMaxFeatures(), query.getStartIndex());
}
ftIds.add( ftId );
}
if ( ftId.length > 1 ) {
if ( queries.length > 1 ) {
sql.append( " ORDER BY QUERY_POS" );
}
stmt = conn.prepareStatement( sql.toString() );
stmt.setFetchSize( fetchSize );
int argIdx = 1;
for ( final short ftId2 : ftId ) {
for ( final short ftId2 : ftIds ) {
stmt.setShort( argIdx++, ftId2 );
if ( blobWb != null && blobWb.getWhere() != null ) {
for ( SQLArgument o : blobWb.getWhere().getArguments() ) {
Expand All @@ -1595,19 +1605,6 @@ private FeatureInputStream queryMultipleFts( Query[] queries, Envelope looseBBox
return result;
}

private short[] getQueriedFeatureTypeIds( Query[] queries ) {
short[] ftId = new short[queries.length];
for ( int i = 0; i < ftId.length; i++ ) {
Query query = queries[i];
if ( query.getTypeNames() == null || query.getTypeNames().length > 1 ) {
String msg = "Join queries between multiple feature types are currently not supported.";
throw new UnsupportedOperationException( msg );
}
ftId[i] = getFtId( query.getTypeNames()[0].getFeatureTypeName() );
}
return ftId;
}

private AbstractWhereBuilder getWhereBuilder( Collection<FeatureTypeMapping> ftMappings, OperatorFilter filter, SortProperty[] sortCrit,
boolean handleStrict )
throws FilterEvaluationException, UnmappableException {
Expand Down Expand Up @@ -1773,9 +1770,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
Loading

0 comments on commit 48b42db

Please sign in to comment.