Commit 36db838d authored by Andrea Aime's avatar Andrea Aime
Browse files

[GEOS-9111] WMTS capabilities generation fails when using a 'style group'

parent 2d499712
......@@ -51,6 +51,7 @@ import org.custommonkey.xmlunit.XpathEngine;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.CatalogBuilder;
import org.geoserver.catalog.FeatureTypeInfo;
import org.geoserver.catalog.LayerGroupHelper;
import org.geoserver.catalog.LayerGroupInfo;
import org.geoserver.catalog.LayerInfo;
import org.geoserver.catalog.ProjectionPolicy;
......@@ -183,6 +184,15 @@ public class GWCIntegrationTest extends GeoServerSystemTestSupport {
this.getClass(),
catalog);
// add a style group (any caps request would fail without the fix in GEOS-9111)
testData.addStyle("stylegroup", "stylegroup.sld", GWCIntegrationTest.class, catalog);
final LayerGroupInfo group = catalog.getFactory().createLayerGroup();
group.getLayers().add(null);
group.getStyles().add(catalog.getStyleByName("stylegroup"));
group.setName("stylegroup");
new LayerGroupHelper(group).calculateBounds();
catalog.add(group);
// clean up the recorded http requests
HttpRequestRecorderCallback.reset();
}
......@@ -1661,6 +1671,7 @@ public class GWCIntegrationTest extends GeoServerSystemTestSupport {
assertThat(response.getStatus(), is(200));
// parse XML response content
Document document = dom(response, false);
print(document);
// check that default styles are advertised
String result =
WMTS_XPATH_10.evaluate(
......@@ -1694,6 +1705,12 @@ public class GWCIntegrationTest extends GeoServerSystemTestSupport {
+ "wmts:LegendURL[@minScaleDenominator='100000.0'][@maxScaleDenominator='300000.0'])",
document);
assertThat(Integer.parseInt(result), greaterThan(0));
// check the style group is reported
result =
WMTS_XPATH_10.evaluate(
"count(//wmts:Contents/wmts:Layer[ows:Identifier='stylegroup'])", document);
assertThat(Integer.parseInt(result), equalTo(1));
// check that legend URI are correctly encoded in the context of a local workspace
WorkspaceInfo workspace = getCatalog().getWorkspaceByName(TEST_WORKSPACE_NAME);
assertThat(workspace, notNullValue());
......@@ -1720,7 +1737,7 @@ public class GWCIntegrationTest extends GeoServerSystemTestSupport {
@Test
public void testGetCapabilitiesRequestRestEndpoints() throws Exception {
int totLayers = getCatalog().getLayers().size();
int totLayers = getCatalog().getLayers().size() + 1; // one cached layer group
// getting capabilities document for CITE workspace
Document doc = getAsDOM("/gwc/service/wmts?request=GetCapabilities");
......
<?xml version="1.0" encoding="ISO-8859-1"?>
<sld:StyledLayerDescriptor xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0">
<sld:NamedLayer>
<sld:Name>DividedRoutes</sld:Name>
<sld:UserStyle>
<sld:FeatureTypeStyle>
<sld:Rule>
<sld:LineSymbolizer>
<sld:Stroke>
<sld:CssParameter name="stroke">#FF0000</sld:CssParameter>
</sld:Stroke>
</sld:LineSymbolizer>
</sld:Rule>
</sld:FeatureTypeStyle>
</sld:UserStyle>
</sld:NamedLayer>
<sld:NamedLayer>
<sld:Name>Lakes</sld:Name>
<sld:UserStyle>
<sld:FeatureTypeStyle>
<sld:Rule>
<sld:PolygonSymbolizer>
<sld:Fill>
<sld:CssParameter name="fill">#0000ff</sld:CssParameter>
</sld:Fill>
</sld:PolygonSymbolizer>
</sld:Rule>
</sld:FeatureTypeStyle>
</sld:UserStyle>
</sld:NamedLayer>
</sld:StyledLayerDescriptor>
\ No newline at end of file
......@@ -76,6 +76,53 @@ public class LayerGroupHelper {
}
}
/**
* Returns top level PublishedInfo, eventually expanding style groups
*
* @return
*/
public List<PublishedInfo> allPublished() {
List<PublishedInfo> publisheds = new ArrayList<>();
allPublished(group, publisheds);
return publisheds;
}
private List<PublishedInfo> allPublished(LayerGroupInfo group, List<PublishedInfo> publisheds) {
if (LayerGroupInfo.Mode.EO.equals(group.getMode())) {
publisheds.add(group.getRootLayer());
}
int size = group.getLayers().size();
for (int i = 0; i < size; i++) {
PublishedInfo p = group.getLayers().get(i);
StyleInfo s;
// Handle incomplete layer groups, especially those constructed by the XStreamPersister
if (group.getStyles() == null || group.getStyles().size() == 0) {
s = null;
} else {
s = group.getStyles().get(i);
}
if (p instanceof LayerInfo) {
LayerInfo l = (LayerInfo) p;
publisheds.add(l);
} else if (p instanceof LayerGroupInfo) {
publisheds.add(p);
} else if (p == null && s != null) {
List<LayerInfo> layers = new ArrayList<>();
expandStyleGroup(
s,
group.getBounds() == null
? null
: group.getBounds().getCoordinateReferenceSystem(),
layers,
null);
publisheds.addAll(layers);
}
}
return publisheds;
}
/**
* Returns all the groups contained in this group (including the group itself)
*
......
......@@ -73,6 +73,25 @@ public class AdvertisedCatalog extends AbstractFilteredCatalog {
public List<PublishedInfo> getOriginalLayers() {
return delegate.getLayers();
}
/**
* Returns the original styles, including the advertised ones. Use this method only if
* strictly necessary (current use case, figuring out if the group is queryable or not)
*
* @return
*/
public List<StyleInfo> getOriginalStyles() {
return delegate.getStyles();
}
/**
* Returns the delegate. Thread carefully when using this!
*
* @return
*/
public LayerGroupInfo unwrap() {
return delegate;
}
}
private LayerGroupVisibilityPolicy layerGroupPolicy = LayerGroupVisibilityPolicy.HIDE_NEVER;
......
......@@ -31,6 +31,7 @@ import org.geoserver.catalog.CoverageInfo;
import org.geoserver.catalog.DimensionInfo;
import org.geoserver.catalog.DimensionPresentation;
import org.geoserver.catalog.FeatureTypeInfo;
import org.geoserver.catalog.LayerGroupHelper;
import org.geoserver.catalog.LayerGroupInfo;
import org.geoserver.catalog.LayerInfo;
import org.geoserver.catalog.MetadataMap;
......@@ -991,7 +992,7 @@ public class WMS implements ApplicationContextAware {
for (PublishedInfo published : layers) {
if (published instanceof LayerInfo) {
queryable |= isQueryable((LayerInfo) published);
} else {
} else if (published instanceof LayerGroupInfo) {
queryable |= isQueryable((LayerGroupInfo) published);
}
}
......@@ -1010,12 +1011,11 @@ public class WMS implements ApplicationContextAware {
* @return a list of {@link PublishedInfo} contained in the layer (queryable or not)
*/
private List<PublishedInfo> getLayersForQueryableChecks(LayerGroupInfo layerGroup) {
List<PublishedInfo> layers = layerGroup.getLayers();
// direct wrapper?
if (layerGroup instanceof AdvertisedCatalog.AdvertisedLayerGroup) {
AdvertisedCatalog.AdvertisedLayerGroup wrapper =
(AdvertisedCatalog.AdvertisedLayerGroup) layerGroup;
layers = wrapper.getOriginalLayers();
layerGroup = wrapper.unwrap();
} else if (layerGroup instanceof Wrapper) {
// hidden inside some other wrapper?
Wrapper wrapper = (Wrapper) layerGroup;
......@@ -1023,10 +1023,12 @@ public class WMS implements ApplicationContextAware {
wrapper.unwrap(AdvertisedCatalog.AdvertisedLayerGroup.class);
AdvertisedCatalog.AdvertisedLayerGroup alg =
(AdvertisedCatalog.AdvertisedLayerGroup) layerGroup;
layers = alg.getOriginalLayers();
layerGroup = alg.unwrap();
}
}
return layers;
// get the full list of layers and groups
return new LayerGroupHelper(layerGroup).allPublished();
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment