Unverified Commit e6a4def7 authored by Steve Ikeoka's avatar Steve Ikeoka Committed by GitHub

Merge pull request #3422 from sikeoka/GEOS-9142-15

[GEOS-9142][2.15.x] Added missing metadata to WCS 2.0.1 GetCapabilities and DescribeCoverage.
parents 454721da 2dcf719b
......@@ -138,6 +138,8 @@ public class DescribeEOCoverageSetTransformer extends TransformerBase {
atts(
"xmlns:eop",
"http://www.opengis.net/eop/2.0", //
"xmlns:ows",
"http://www.opengis.net/ows/2.0",
"xmlns:gml",
"http://www.opengis.net/gml/3.2", //
"xmlns:wcsgs",
......
......@@ -286,6 +286,7 @@ class GMLTransformer extends TransformerBase {
start("gmlcov:metadata");
start("gmlcov:Extension");
handleAdditionalMetadata(context);
if (dimensionsHelper != null) {
// handle time if necessary
......@@ -306,6 +307,10 @@ class GMLTransformer extends TransformerBase {
end("gmlcov:metadata");
}
protected void handleAdditionalMetadata(Object context) {
// Override to do something.
}
/**
* Look for additional dimensions in the dimensionsHelper and put additional domains to the
* metadata
......
......@@ -5,6 +5,7 @@
*/
package org.geoserver.wcs2_0.response;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.geoserver.ows.util.ResponseUtils.buildSchemaURL;
import java.io.IOException;
......@@ -15,7 +16,9 @@ import net.opengis.wcs20.DescribeCoverageType;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.CoverageDimensionInfo;
import org.geoserver.catalog.CoverageInfo;
import org.geoserver.catalog.KeywordInfo;
import org.geoserver.catalog.LayerInfo;
import org.geoserver.catalog.MetadataLinkInfo;
import org.geoserver.platform.GeoServerExtensions;
import org.geoserver.wcs.CoverageCleanerCallback;
import org.geoserver.wcs2_0.GetCoverage;
......@@ -38,6 +41,7 @@ import org.geotools.wcs.v2_0.WCS;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.datum.PixelInCell;
import org.vfny.geoserver.util.ResponseUtils;
import org.vfny.geoserver.wcs.WcsException;
import org.xml.sax.ContentHandler;
import org.xml.sax.helpers.AttributesImpl;
......@@ -231,6 +235,8 @@ public class WCS20DescribeCoverageTransformer extends GMLTransformer {
// starting encoding
start("wcs:CoverageDescription", coverageAttributes);
elementSafe("gml:description", ci.getDescription());
elementSafe("gml:name", ci.getTitle());
// handle domain
final StringBuilder builder = new StringBuilder();
......@@ -297,6 +303,33 @@ public class WCS20DescribeCoverageTransformer extends GMLTransformer {
}
}
@Override
protected void handleAdditionalMetadata(Object context) {
if (context instanceof CoverageInfo) {
CoverageInfo ci = (CoverageInfo) context;
List<KeywordInfo> keywords = ci.getKeywords();
if (keywords != null && !keywords.isEmpty()) {
start("ows:Keywords");
keywords.forEach(kw -> element("ows:Keyword", kw.getValue()));
end("ows:Keywords");
}
ci.getMetadataLinks().forEach(this::handleMetadataLink);
}
}
private void handleMetadataLink(MetadataLinkInfo mdl) {
if (isNotBlank(mdl.getContent())) {
String url = ResponseUtils.proxifyMetadataLink(mdl, request.getBaseUrl());
AttributesImpl attributes = new AttributesImpl();
if (isNotBlank(mdl.getAbout())) {
attributes.addAttribute("", "about", "about", "", mdl.getAbout());
}
attributes.addAttribute("", "xlink:type", "xlink:type", "", "simple");
attributes.addAttribute("", "xlink:href", "xlink:href", "", url);
element("ows:Metadata", null, attributes);
}
}
private void handleServiceParameters(CoverageInfo ci) throws IOException {
start("wcs:ServiceParameters");
element("wcs:CoverageSubtype", "RectifiedGridCoverage");
......
......@@ -27,6 +27,7 @@ import net.opengis.wcs20.GetCapabilitiesType;
import org.geoserver.ExtendedCapabilitiesProvider;
import org.geoserver.catalog.CoverageInfo;
import org.geoserver.catalog.KeywordInfo;
import org.geoserver.catalog.MetadataLinkInfo;
import org.geoserver.config.ContactInfo;
import org.geoserver.config.GeoServer;
import org.geoserver.config.ResourceErrorHandling;
......@@ -47,6 +48,7 @@ import org.geotools.xml.transform.TransformerBase;
import org.geotools.xml.transform.Translator;
import org.opengis.geometry.BoundingBox;
import org.vfny.geoserver.global.CoverageInfoLabelComparator;
import org.vfny.geoserver.util.ResponseUtils;
import org.vfny.geoserver.wcs.WcsException;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
......@@ -653,12 +655,16 @@ public class WCS20GetCapabilitiesTransformer extends TransformerBase {
private void handleCoverageSummary(CoverageInfo cv) throws Exception {
start("wcs:CoverageSummary");
elementIfNotEmpty("ows:Title", cv.getTitle());
elementIfNotEmpty("ows:Abstract", cv.getDescription());
handleKeywords(cv.getKeywords());
String covId = NCNameResourceCodec.encode(cv);
element("wcs:CoverageId", covId);
element("wcs:CoverageSubtype", "RectifiedGridCoverage"); // TODO make this parametric
handleWGS84BoundingBox(cv.getLatLonBoundingBox());
handleBoundingBox(cv.boundingBox());
cv.getMetadataLinks().forEach(this::handleMetadataLink);
end("wcs:CoverageSummary");
}
......@@ -701,6 +707,19 @@ public class WCS20GetCapabilitiesTransformer extends TransformerBase {
end("ows:BoundingBox");
}
private void handleMetadataLink(MetadataLinkInfo mdl) {
if (isNotBlank(mdl.getContent())) {
String url = ResponseUtils.proxifyMetadataLink(mdl, request.getBaseUrl());
AttributesImpl attributes = new AttributesImpl();
if (isNotBlank(mdl.getAbout())) {
attributes.addAttribute("", "about", "about", "", mdl.getAbout());
}
attributes.addAttribute("", "xlink:type", "xlink:type", "", "simple");
attributes.addAttribute("", "xlink:href", "xlink:href", "", url);
element("ows:Metadata", null, attributes);
}
}
private void handleLanguages() {
// start("ows:Languages");
// // TODO
......
......@@ -5,16 +5,21 @@
package org.geoserver.wcs2_0.kvp;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.geoserver.data.test.MockData.TASMANIA_DEM;
import static org.junit.Assert.assertNotNull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import org.custommonkey.xmlunit.exceptions.XpathException;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.CoverageInfo;
import org.geoserver.catalog.DimensionPresentation;
import org.geoserver.catalog.Keyword;
import org.geoserver.catalog.MetadataLinkInfo;
import org.geoserver.catalog.ResourceInfo;
import org.geoserver.catalog.impl.CoverageDimensionImpl;
import org.geoserver.config.GeoServerInfo;
import org.geoserver.data.test.MockData;
import org.geoserver.data.test.SystemTestData;
import org.geoserver.wcs2_0.WCSTestSupport;
......@@ -401,6 +406,51 @@ public class DescribeCoverageTest extends WCSTestSupport {
dom);
}
@Test
public void testMetadata() throws Exception {
GeoServerInfo global = getGeoServer().getGlobal();
global.getSettings().setProxyBaseUrl("src/test/resources/geoserver");
getGeoServer().save(global);
Catalog catalog = getCatalog();
CoverageInfo ci = catalog.getCoverageByName(getLayerId(TASMANIA_DEM));
ci.setTitle("My Title");
ci.setDescription("My Abstract");
ci.getKeywords().add(0, new Keyword("my_keyword"));
MetadataLinkInfo mdl1 = catalog.getFactory().createMetadataLink();
mdl1.setContent("http://www.geoserver.org/tasmania/dem.xml");
mdl1.setAbout("http://www.geoserver.org");
ci.getMetadataLinks().add(mdl1);
MetadataLinkInfo mdl2 = catalog.getFactory().createMetadataLink();
mdl2.setContent("/metadata?key=value");
mdl2.setAbout("http://www.geoserver.org");
ci.getMetadataLinks().add(mdl2);
catalog.save(ci);
String coverageId = getLayerId(TASMANIA_DEM).replace(":", "__");
Document dom = getAsDOM(DESCRIBE_URL + "&coverageId=" + coverageId);
// print(dom);
checkValidationErrors(dom, getWcs20Schema());
String base = "//wcs:CoverageDescriptions/wcs:CoverageDescription/";
assertXpathEvaluatesTo("My Title", base + "gml:name", dom);
assertXpathEvaluatesTo("My Abstract", base + "gml:description", dom);
base += "gmlcov:metadata/gmlcov:Extension/";
assertXpathEvaluatesTo("4", "count(" + base + "ows:Keywords/ows:Keyword)", dom);
assertXpathEvaluatesTo("my_keyword", base + "ows:Keywords/ows:Keyword[1]", dom);
assertXpathEvaluatesTo("2", "count(" + base + "ows:Metadata)", dom);
assertXpathEvaluatesTo("http://www.geoserver.org", base + "ows:Metadata[1]/@about", dom);
assertXpathEvaluatesTo("simple", base + "ows:Metadata[1]/@xlink:type", dom);
assertXpathEvaluatesTo(
"http://www.geoserver.org/tasmania/dem.xml",
base + "ows:Metadata[1]/@xlink:href",
dom);
assertXpathEvaluatesTo("http://www.geoserver.org", base + "ows:Metadata[2]/@about", dom);
assertXpathEvaluatesTo("simple", base + "ows:Metadata[2]/@xlink:type", dom);
assertXpathEvaluatesTo(
"src/test/resources/geoserver/metadata?key=value",
base + "ows:Metadata[2]/@xlink:href",
dom);
}
@Test
public void testDescribeTimeList() throws Exception {
setupRasterDimension(
......
......@@ -6,8 +6,14 @@ package org.geoserver.wcs2_0.kvp;
import static junit.framework.Assert.assertEquals;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.geoserver.data.test.MockData.TASMANIA_DEM;
import static org.junit.Assert.*;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.CoverageInfo;
import org.geoserver.catalog.Keyword;
import org.geoserver.catalog.MetadataLinkInfo;
import org.geoserver.config.GeoServerInfo;
import org.geoserver.wcs.WCSInfo;
import org.geoserver.wcs2_0.GetCapabilities;
import org.geoserver.wcs2_0.WCSTestSupport;
......@@ -116,4 +122,48 @@ public class GetCapabilitiesTest extends WCSTestSupport {
assertXpathEvaluatesTo(
"0", "count(//ows:ExceptionReport//ows:Exception[@locator='wCS'])", dom);
}
@Test
public void testMetadata() throws Exception {
GeoServerInfo global = getGeoServer().getGlobal();
global.getSettings().setProxyBaseUrl("src/test/resources/geoserver");
getGeoServer().save(global);
Catalog catalog = getCatalog();
CoverageInfo ci = catalog.getCoverageByName(getLayerId(TASMANIA_DEM));
ci.setTitle("My Title");
ci.setDescription("My Abstract");
ci.getKeywords().add(0, new Keyword("my_keyword"));
MetadataLinkInfo mdl1 = catalog.getFactory().createMetadataLink();
mdl1.setContent("http://www.geoserver.org/tasmania/dem.xml");
mdl1.setAbout("http://www.geoserver.org");
ci.getMetadataLinks().add(mdl1);
MetadataLinkInfo mdl2 = catalog.getFactory().createMetadataLink();
mdl2.setContent("/metadata?key=value");
mdl2.setAbout("http://www.geoserver.org");
ci.getMetadataLinks().add(mdl2);
catalog.save(ci);
Document dom = getAsDOM("wcs?service=WCS&version=2.0.1&request=GetCapabilities");
// print(dom);
checkValidationErrors(dom, getWcs20Schema());
String base = "//wcs:Capabilities/wcs:Contents/wcs:CoverageSummary[wcs:CoverageId = '";
base += getLayerId(TASMANIA_DEM).replace(":", "__") + "']/";
assertXpathEvaluatesTo("My Title", base + "ows:Title", dom);
assertXpathEvaluatesTo("My Abstract", base + "ows:Abstract", dom);
assertXpathEvaluatesTo("4", "count(" + base + "ows:Keywords/ows:Keyword)", dom);
assertXpathEvaluatesTo("my_keyword", base + "ows:Keywords/ows:Keyword[1]", dom);
assertXpathEvaluatesTo("2", "count(" + base + "ows:Metadata)", dom);
assertXpathEvaluatesTo("http://www.geoserver.org", base + "ows:Metadata[1]/@about", dom);
assertXpathEvaluatesTo("simple", base + "ows:Metadata[1]/@xlink:type", dom);
assertXpathEvaluatesTo(
"http://www.geoserver.org/tasmania/dem.xml",
base + "ows:Metadata[1]/@xlink:href",
dom);
assertXpathEvaluatesTo("http://www.geoserver.org", base + "ows:Metadata[2]/@about", dom);
assertXpathEvaluatesTo("simple", base + "ows:Metadata[2]/@xlink:type", dom);
assertXpathEvaluatesTo(
"src/test/resources/geoserver/metadata?key=value",
base + "ows:Metadata[2]/@xlink:href",
dom);
}
}
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