Commit 2735982b authored by Steve Ikeoka's avatar Steve Ikeoka

[GEOS-9155] Fixed GetFeatureInfo templates not being able to retrieve metadata for raster layers.

parent a6210358
......@@ -28,8 +28,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.FeatureTypeInfo;
import org.geoserver.catalog.NamespaceInfo;
import org.geoserver.catalog.ResourceInfo;
import org.geoserver.platform.GeoServerExtensions;
import org.geotools.data.DataUtilities;
import org.geotools.feature.FeatureCollection;
......@@ -269,13 +269,13 @@ public class FeatureWrapper extends BeansWrapper {
Catalog cat = getCatalog();
FeatureTypeInfo info = null;
ResourceInfo info = null;
if (cat != null) {
info =
cat.getResourceByName(
att.getType().getName().getNamespaceURI(),
att.getType().getName().getLocalPart(),
FeatureTypeInfo.class);
ResourceInfo.class);
if (info != null) {
map.put("type", info);
......
......@@ -30,6 +30,7 @@ import java.util.concurrent.Future;
import net.opengis.wfs.FeatureCollectionType;
import net.opengis.wfs.WfsFactory;
import org.geoserver.catalog.FeatureTypeInfo;
import org.geoserver.catalog.Keyword;
import org.geoserver.catalog.LayerInfo;
import org.geoserver.catalog.NamespaceInfo;
import org.geoserver.catalog.PublishedType;
......@@ -44,11 +45,15 @@ import org.geoserver.template.GeoServerTemplateLoader;
import org.geoserver.wms.GetFeatureInfoRequest;
import org.geoserver.wms.MapLayerInfo;
import org.geoserver.wms.WMSTestSupport;
import org.geotools.data.DataUtilities;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.opengis.feature.simple.SimpleFeatureType;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletContext;
......@@ -163,6 +168,45 @@ public class HTMLFeatureInfoOutputFormatTest extends WMSTestSupport {
}
}
@SuppressWarnings("unchecked")
@Test
public void testCoverageInfoIsEvaluatedInTemplate() throws IOException {
currentTemplate = "test_resource_content.ftl";
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setName(toName(MockData.WORLD));
SimpleFeatureType type = builder.buildFeatureType();
Double[] values = new Double[0];
fcType.getFeature()
.set(0, DataUtilities.collection(SimpleFeatureBuilder.build(type, values, "")));
ResourceInfo resource = getCatalog().getCoverageByName(toName(MockData.WORLD));
resource.setTitle("Raster Title");
resource.setAbstract("Raster Abstract");
resource.getKeywords().set(0, new Keyword("Raster Keyword"));
getCatalog().save(resource);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
outputFormat.write(fcType, getFeatureInfoRequest, outStream);
String result = new String(outStream.toByteArray());
// Verify that a raster layer's title, abstract, etc. is retrieved properly.
assertEquals("Raster Title,Raster Abstract,Raster Keyword,EPSG:4326", result);
}
@Test
public void testFeatureTypeInfoIsEvaluatedInTemplate() throws IOException {
currentTemplate = "test_resource_content.ftl";
ResourceInfo resource = getFeatureTypeInfo(MockData.PRIMITIVEGEOFEATURE);
resource.setTitle("Vector Title");
resource.setAbstract("Vector Abstract");
resource.getKeywords().set(0, new Keyword("Vector Keyword"));
getCatalog().save(resource);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
outputFormat.write(fcType, getFeatureInfoRequest, outStream);
String result = new String(outStream.toByteArray());
// Verify that a vector layer's title, abstract, etc. is retrieved properly.
assertEquals("Vector Title,Vector Abstract,Vector Keyword,EPSG:4326", result);
}
@Test
public void testExecuteIsBlocked() throws IOException {
currentTemplate = "test_execute.ftl";
......
<#assign layer=features[0].type>
${layer.title},${layer.abstract},${layer.keywords[0]},${layer.SRS}
\ No newline at end of file
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