Skip to content

Commit

Permalink
deegree#104 - introduces MetadataMerger to manipulate BBox of Layers …
Browse files Browse the repository at this point in the history
…in the capabilities
  • Loading branch information
lgoltz committed Mar 27, 2019
1 parent 2d0ad11 commit 9b105cb
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@
import org.deegree.services.metadata.OWSMetadataProvider;
import org.deegree.services.metadata.provider.OWSMetadataProviderProvider;
import org.deegree.services.wms.MapService;
import org.deegree.services.wms.controller.capabilities.theme.DefaultMetadataMerger;
import org.deegree.services.wms.controller.capabilities.theme.MetadataMerger;
import org.deegree.services.wms.controller.capabilities.serialize.CapabilitiesManager;
import org.deegree.services.wms.controller.exceptions.ExceptionsManager;
import org.deegree.services.wms.controller.plugins.DefaultOutputFormatProvider;
Expand Down Expand Up @@ -1150,6 +1152,10 @@ private void beginSoap11Response( HttpResponseBuffer response )
xmlWriter.writeStartElement( soapEnvNS, "Body" );
}

public MetadataMerger getMetadataMerger() {
return new DefaultMetadataMerger();
}

/**
* <code>Controller</code>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import org.deegree.commons.xml.XMLAdapter;
import org.deegree.geometry.metadata.SpatialMetadata;
import org.deegree.layer.dims.Dimension;
import org.deegree.layer.metadata.LayerMetadata;
import org.deegree.protocol.wms.WMSConstants;
import org.deegree.services.metadata.OWSMetadataProvider;
import org.deegree.services.wms.MapService;
Expand All @@ -64,7 +63,6 @@
import org.deegree.services.wms.controller.exceptions.ExceptionsManager;
import org.deegree.style.se.unevaluated.Style;
import org.deegree.theme.Theme;
import org.deegree.theme.Themes;

/**
* <code>Capabilities111XMLAdapter</code>
Expand Down Expand Up @@ -107,7 +105,7 @@ public Capabilities111XMLAdapter( ServiceIdentification identification, ServiceP
this.controller = controller;
metadataWriter = new WmsCapabilities111MetadataWriter( identification, provider, getUrl, postUrl, controller );
final String mdUrlTemplate = getMetadataUrlTemplate( controller, getUrl );
themeWriter = new WmsCapabilities111ThemeWriter( metadata, this, mdUrlTemplate );
themeWriter = new WmsCapabilities111ThemeWriter( metadata, this, mdUrlTemplate, controller.getMetadataMerger() );
}

private String getMetadataUrlTemplate( final WMSController controller, final String getUrl ) {
Expand Down Expand Up @@ -170,18 +168,8 @@ private void writeThemes( XMLStreamWriter writer, List<Theme> themes )
writeElement( writer, "Title", "Root" );

// TODO think about a push approach instead of a pull approach
LayerMetadata lmd = null;
for ( Theme t : themes ) {
for ( org.deegree.layer.Layer l : Themes.getAllLayers( t ) ) {
if ( lmd == null ) {
lmd = l.getMetadata();
} else {
lmd.merge( l.getMetadata() );
}
}
}
if ( lmd != null ) {
SpatialMetadata smd = lmd.getSpatialMetadata();
SpatialMetadata smd = mergeSpatialMetadata( themes );
if ( smd != null ) {
writeSrsAndEnvelope( writer, smd.getCoordinateSystems(), smd.getEnvelope() );
}

Expand Down Expand Up @@ -256,4 +244,8 @@ private void writeFormats( XMLStreamWriter writer )
}
}

private SpatialMetadata mergeSpatialMetadata( List<Theme> themes ) {
return controller.getMetadataMerger().mergeSpatialMetadata( themes );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@

/**
* <code>Capabilities130XMLAdapter</code>
*
*
* @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a>
* @author last edited by: $Author$
*
*
* @version $Revision$, $Date$
*/
@LoggingNotes(warn = "logs problems with CRS when outputting 1.3.0 capabilities", trace = "logs stack traces")
Expand Down Expand Up @@ -119,7 +119,7 @@ public Capabilities130XMLAdapter( ServiceIdentification identification, ServiceP
this.metadataWriter = new WmsCapabilities130MetadataWriter( identification, provider, getUrl, postUrl,
controller );
final String mdUrlTemplate = getMetadataUrlTemplate( controller, getUrl );
this.themeWriter = new WmsCapabilities130ThemeWriter( metadata, this, mdUrlTemplate );
this.themeWriter = new WmsCapabilities130ThemeWriter( metadata, this, mdUrlTemplate, controller.getMetadataMerger() );
}

private String getMetadataUrlTemplate( final WMSController controller, final String getUrl ) {
Expand All @@ -136,7 +136,7 @@ private String getMetadataUrlTemplate( final WMSController controller, final Str

/**
* Writes out a 1.3.0 style capabilities document.
*
*
* @param writer
* @throws XMLStreamException
*/
Expand Down Expand Up @@ -281,15 +281,7 @@ private void writeExceptionFormats( XMLStreamWriter writer )
}

private SpatialMetadata mergeSpatialMetadata( List<Theme> themes ) {
if ( themes.isEmpty() )
return null;
SpatialMetadata smd = new SpatialMetadata();
for ( Theme t : themes ) {
for ( org.deegree.layer.Layer l : Themes.getAllLayers( t ) ) {
smd.merge( l.getMetadata().getSpatialMetadata() );
}
}
return smd;
return controller.getMetadataMerger().mergeSpatialMetadata( themes );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.deegree.services.wms.controller.capabilities.theme;

import org.deegree.geometry.metadata.SpatialMetadata;
import org.deegree.layer.metadata.LayerMetadata;
import org.deegree.theme.Theme;
import org.deegree.theme.Themes;

import java.util.List;

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

@Override
public SpatialMetadata mergeSpatialMetadata( List<Theme> themes ) {
if ( themes.isEmpty() )
return null;
SpatialMetadata smd = new SpatialMetadata();
for ( Theme t : themes ) {
for ( org.deegree.layer.Layer l : Themes.getAllLayers( t ) ) {
smd.merge( l.getMetadata().getSpatialMetadata() );
}
}
return smd;
}

@Override
public LayerMetadata mergeLayerMetadata( Theme theme ) {
return new LayerMetadataMerger().merge( theme );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.deegree.services.wms.controller.capabilities.theme;

import org.deegree.geometry.metadata.SpatialMetadata;
import org.deegree.layer.metadata.LayerMetadata;
import org.deegree.theme.Theme;

import java.util.List;

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

SpatialMetadata mergeSpatialMetadata( List<Theme> themes );

LayerMetadata mergeLayerMetadata( Theme theme );
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,27 @@ public class WmsCapabilities111ThemeWriter {

private final String mdUrlTemplate;

private final MetadataMerger metadataMerger;

private final DecimalFormat scaleFormat;

/**
* Creates a new {@link WmsCapabilities111ThemeWriter} instance.
*
* @param metadataProvider
* @param metadataProvider
* provider for metadata on OWS datasets, can be <code>null</code>
* @param styleWriter
* writer for WMS 1.1.1 Style elements, can be <code>null</code> (styles will be skipped)
* @param mdUrlTemplate
* URL template for requesting metadata records (<code>${metadataSetId}</code> will be replaced with
* metadata id), can be <code>null</code>
* URL template for requesting metadata records (<code>${metadataSetId}</code> will be replaced with
* @param metadataMerger
*/
public WmsCapabilities111ThemeWriter( final OWSMetadataProvider metadataProvider,
final Capabilities111XMLAdapter styleWriter, final String mdUrlTemplate ) {
final Capabilities111XMLAdapter styleWriter, final String mdUrlTemplate,
MetadataMerger metadataMerger ) {
this.metadataProvider = metadataProvider;
this.styleWriter = styleWriter;
this.mdUrlTemplate = mdUrlTemplate;
this.metadataMerger = metadataMerger;
final DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator( '.' );
this.scaleFormat = new DecimalFormat( "0.0#######", symbols );
Expand All @@ -129,7 +132,7 @@ public WmsCapabilities111ThemeWriter( final OWSMetadataProvider metadataProvider
*/
public void writeTheme( final XMLStreamWriter writer, final Theme theme )
throws XMLStreamException {
final LayerMetadata layerMetadata = new LayerMetadataMerger().merge( theme );
final LayerMetadata layerMetadata = metadataMerger.mergeLayerMetadata( theme );
final DatasetMetadataFactory factory = new DatasetMetadataFactory();
final List<DatasetMetadata> dsMd1 = getDatasetMetadataFromProvider( theme );
final DatasetMetadata dsMd2 = factory.buildDatasetMetadata( layerMetadata, theme, mdUrlTemplate );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,27 @@ public class WmsCapabilities130ThemeWriter {

private final String mdUrlTemplate;

private final MetadataMerger metadataMerger;

private final DecimalFormat scaleFormat;

/**
* Creates a new {@link WmsCapabilities130ThemeWriter} instance.
*
* @param metadataProvider
* @param metadataProvider
* provider for metadata on OWS datasets, can be <code>null</code>
* @param styleWriter
* writer for WMS 1.3.0 Style elements, can be <code>null</code> (styles will be skipped)
* @param mdUrlTemplate
* URL template for requesting metadata records (<code>${metadataSetId}</code> will be replaced with
* metadata id), can be <code>null</code>
* URL template for requesting metadata records (<code>${metadataSetId}</code> will be replaced with
* @param metadataMerger
*/
public WmsCapabilities130ThemeWriter( final OWSMetadataProvider metadataProvider,
final Capabilities130XMLAdapter styleWriter, final String mdUrlTemplate ) {
final Capabilities130XMLAdapter styleWriter, final String mdUrlTemplate,
MetadataMerger metadataMerger ) {
this.metadataProvider = metadataProvider;
this.styleWriter = styleWriter;
this.mdUrlTemplate = mdUrlTemplate;
this.metadataMerger = metadataMerger;
final DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator( '.' );
this.scaleFormat = new DecimalFormat( "0.0#######", symbols );
Expand All @@ -128,7 +131,7 @@ public WmsCapabilities130ThemeWriter( final OWSMetadataProvider metadataProvider
*/
public void writeTheme( final XMLStreamWriter writer, final Theme theme )
throws XMLStreamException {
final LayerMetadata layerMetadata = new LayerMetadataMerger().merge( theme );
final LayerMetadata layerMetadata = metadataMerger.mergeLayerMetadata( theme );
final DatasetMetadataFactory factory = new DatasetMetadataFactory();
final List<DatasetMetadata> dsMd1 = getDatasetMetadataFromProvider( theme );
final DatasetMetadata dsMd2 = factory.buildDatasetMetadata( layerMetadata, theme, mdUrlTemplate );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ Occam Labs UG (haftungsbeschränkt)
*/
public class WmsCapabilities111ThemeWriterTest {

private final WmsCapabilities111ThemeWriter themeWriter = new WmsCapabilities111ThemeWriter( null, null, null );
private final WmsCapabilities111ThemeWriter themeWriter = new WmsCapabilities111ThemeWriter( null, null, null,
new DefaultMetadataMerger() );

@Test
public void writeThemeMinimal()
Expand Down Expand Up @@ -152,7 +153,8 @@ public void testWriteThemeMultipleMetadataUrls()
mds.add( createDatasetMetadata( "http://url3" ) );
when( provider.getAllDatasetMetadata( Mockito.any( QName.class ) ) ).thenReturn( mds );

WmsCapabilities111ThemeWriter themeWriter = new WmsCapabilities111ThemeWriter( provider, null, mdurlTemplate );
WmsCapabilities111ThemeWriter themeWriter = new WmsCapabilities111ThemeWriter( provider, null, mdurlTemplate,
new DefaultMetadataMerger() );
Theme theme = new StandardTheme( layerMetadata, Collections.<Theme> emptyList(),
Collections.<Layer> emptyList(), null );
themeWriter.writeTheme( writer, theme );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public class WmsCapabilities130ThemeWriterTest {

private static final String SCHEMA_URL = "http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd";

private final WmsCapabilities130ThemeWriter themeWriter = new WmsCapabilities130ThemeWriter( null, null, null );
private final WmsCapabilities130ThemeWriter themeWriter = new WmsCapabilities130ThemeWriter( null, null, null,
new DefaultMetadataMerger() );

@Test
public void writeThemeMinimal()
Expand Down Expand Up @@ -166,7 +167,8 @@ public void testWriteThemeMultipleMetadataUrls()
mds.add( createDatasetMetadata( "http://url3" ) );
when( provider.getAllDatasetMetadata( Mockito.any( QName.class ) ) ).thenReturn( mds );

WmsCapabilities130ThemeWriter themeWriter = new WmsCapabilities130ThemeWriter( provider, null, mdurlTemplate );
WmsCapabilities130ThemeWriter themeWriter = new WmsCapabilities130ThemeWriter( provider, null, mdurlTemplate,
new DefaultMetadataMerger() );

Theme theme = new StandardTheme( layerMetadata, Collections.<Theme> emptyList(),
Collections.<Layer> emptyList(), null );
Expand Down

0 comments on commit 9b105cb

Please sign in to comment.