Skip to content

Commit

Permalink
[GEOS-9155] Fixed GetFeatureInfo templates not being able to retrieve…
Browse files Browse the repository at this point in the history
… metadata for raster layers.
  • Loading branch information
sikeoka committed Mar 20, 2019
1 parent bde79d5 commit 2aecebd
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
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;
Expand Down Expand Up @@ -269,13 +269,13 @@ private SimpleHash buildComplex(ComplexAttribute att) {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand All @@ -44,11 +45,15 @@
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;

Expand Down Expand Up @@ -163,6 +168,45 @@ public void testEnvironmentVariablesAreEvaluatedInTemplate() throws IOException
}
}

@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";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<#assign layer=features[0].type>
${layer.title},${layer.abstract},${layer.keywords[0]},${layer.SRS}

0 comments on commit 2aecebd

Please sign in to comment.