LayerMetadataMerger { LayerMetadata merge( final Theme theme ) { final LayerMetadata themeMetadata = theme.getLayerMetadata(); LayerMetadata layerMetadata = new LayerMetadata( null, null, null ); int queryable = 0; boolean opaque = false; int cascaded = 0; for ( final Layer l : Themes.getAllLayers( theme ) ) { queryable |= analyseQueryable( l.getMetadata() ); if ( checkIfOpaque( l.getMetadata() ) ) opaque = true; if ( checkIfLargerCascadedValue( cascaded, l.getMetadata() ) ) cascaded = l.getMetadata().getCascaded(); layerMetadata.merge( l.getMetadata() ); } themeMetadata.merge( layerMetadata ); adjustMapOptions( themeMetadata, queryable, opaque, cascaded ); return themeMetadata; }    }
@Test public void mergeEmptyThemeNoLayers() { final Theme theme = createThemeWithoutMetadata( "Theme", null, null ); final LayerMetadata merged = merger.merge( theme ); assertEquals( "Theme", merged.getName() ); final Description description = merged.getDescription(); assertEquals( 0, description.getTitles().size() ); assertEquals( 0, description.getAbstracts().size() ); assertEquals( 0, description.getKeywords().size() ); assertNull( merged.getSpatialMetadata() ); }
@Test public void mergeSingleThemeNoLayers() { final Theme theme = createTheme( "Theme", -180.0, -90.0, 180.0, 90, null, null, null ); final LayerMetadata merged = merger.merge( theme ); assertEquals( "Theme", merged.getName() ); final Description description = merged.getDescription(); assertSingleEntry( "Theme Title", description.getTitles() ); assertSingleEntry( "Theme Abstract", description.getAbstracts() ); final SpatialMetadata spatialMetadata = merged.getSpatialMetadata(); assertEquals( "EPSG:4326", spatialMetadata.getCoordinateSystems().get( 0 ).getAlias() ); assertEquals( -180.0, spatialMetadata.getEnvelope().getMin().get0(), 0.0000001 ); assertEquals( -90.0, spatialMetadata.getEnvelope().getMin().get1(), 0.0000001 ); assertEquals( 180.0, spatialMetadata.getEnvelope().getMax().get0(), 0.0000001 ); assertEquals( 90.0, spatialMetadata.getEnvelope().getMax().get1(), 0.0000001 ); }
@Test public void mergeEmptyThemeSingleSubtheme() { final Theme subTheme = createTheme( "Subtheme", -180.0, -90.0, 180.0, 90, null, null, null ); final List<Theme> subThemes = singletonList( subTheme ); final Theme theme = createThemeWithoutMetadata( "Theme", null, subThemes ); final LayerMetadata merged = merger.merge( theme ); assertEquals( "Theme", merged.getName() ); final Description description = merged.getDescription(); assertEquals( 0, description.getTitles().size() ); assertEquals( 0, description.getAbstracts().size() ); assertEquals( 0, description.getKeywords().size() ); assertNull( merged.getSpatialMetadata() ); }
@Test public void mergeEmptyThemeSingleLayer() { final Layer layer = createLayer( "Layer", -180.0, -90.0, 180.0, 90, null ); final List<Layer> layers = Collections.singletonList( layer ); final Theme theme = createThemeWithoutMetadata( "Theme", layers, null ); final LayerMetadata merged = merger.merge( theme ); assertEquals( "Theme", merged.getName() ); final Description description = merged.getDescription(); assertEquals( 1, description.getTitles().size() ); assertSingleEntry( "Layer Title", description.getTitles() ); assertSingleEntry( "Layer Abstract", description.getAbstracts() ); final SpatialMetadata spatialMetadata = merged.getSpatialMetadata(); assertEquals( "EPSG:4326", spatialMetadata.getCoordinateSystems().get( 0 ).getAlias() ); assertEquals( -180.0, spatialMetadata.getEnvelope().getMin().get0(), 0.0000001 ); assertEquals( -90.0, spatialMetadata.getEnvelope().getMin().get1(), 0.0000001 ); assertEquals( 180.0, spatialMetadata.getEnvelope().getMax().get0(), 0.0000001 ); assertEquals( 90.0, spatialMetadata.getEnvelope().getMax().get1(), 0.0000001 ); }
@Test public void mergeEmptyThemeSingleSubthemeWithLayer() { final Layer layer = createLayer( "Layer", -180.0, -90.0, 180.0, 90, null ); final List<Layer> layers = Collections.singletonList( layer ); final Theme subTheme = createTheme( "Subtheme", -180.0, -90.0, 180.0, 90, layers, null, null ); final List<Theme> subThemes = singletonList( subTheme ); final Theme theme = createThemeWithoutMetadata( "Theme", null, subThemes ); final LayerMetadata merged = merger.merge( theme ); assertEquals( "Theme", merged.getName() ); final Description description = merged.getDescription(); assertEquals( 1, description.getTitles().size() ); assertSingleEntry( "Layer Title", description.getTitles() ); assertSingleEntry( "Layer Abstract", description.getAbstracts() ); final SpatialMetadata spatialMetadata = merged.getSpatialMetadata(); assertEquals( "EPSG:4326", spatialMetadata.getCoordinateSystems().get( 0 ).getAlias() ); assertEquals( -180.0, spatialMetadata.getEnvelope().getMin().get0(), 0.0000001 ); assertEquals( -90.0, spatialMetadata.getEnvelope().getMin().get1(), 0.0000001 ); assertEquals( 180.0, spatialMetadata.getEnvelope().getMax().get0(), 0.0000001 ); assertEquals( 90.0, spatialMetadata.getEnvelope().getMax().get1(), 0.0000001 ); }
@Test public void mergeThemeWithTwoSubthemesWithTwoLayersWithOpaqueAndWithoutOpaque() { final MapOptions mapOptionsWithOpaque = new MapOptions( null, null, null, -1, -1, true ); final Layer layerWithOpaque = createLayer( "LayerWithOpaque", -180.0, -90.0, 180.0, 90, mapOptionsWithOpaque ); final List<Layer> layersWithOpaque = Collections.singletonList( layerWithOpaque ); final Theme subThemeWithOpaque = createTheme( "SubthemeWithOpaque", -180.0, -90.0, 180.0, 90, layersWithOpaque, null, null ); final MapOptions mapOptionsWithoutOpaque = new MapOptions( null, null, null, -1, -1, false ); final Layer layerWithoutOpaque = createLayer( "LayerWithoutOpaque", -180.0, -90.0, 180.0, 90, mapOptionsWithoutOpaque ); final List<Layer> layersWithoutOpaque = Collections.singletonList( layerWithoutOpaque ); final Theme subThemeWithoutOpaque = createTheme( "SubthemeWithoutOpaque", -180.0, -90.0, 180.0, 90, layersWithoutOpaque, null, null ); final List<Theme> subThemes = asList( subThemeWithOpaque, subThemeWithoutOpaque ); final Theme theme = createThemeWithoutMetadata( "Theme", null, subThemes ); final LayerMetadata mergedTheme = merger.merge( theme ); final LayerMetadata mergedSubThemeWithOpaque = merger.merge( subThemeWithOpaque ); final LayerMetadata mergedSubThemeWithoutOpaque = merger.merge( subThemeWithoutOpaque ); assertThat( mergedTheme.getMapOptions().isOpaque(), is( true ) ); assertThat( mergedSubThemeWithOpaque.getMapOptions().isOpaque(), is( true ) ); assertThat( mergedSubThemeWithoutOpaque.getMapOptions().isOpaque(), is( false ) ); }