Skip to content
Snippets Groups Projects
Verified Commit f5f79fb5 authored by Jesper Zedlitz's avatar Jesper Zedlitz
Browse files

adjusted xpath to find GetCapabilities request

Comprehesive tests for a difficult problem with a dataset from Norderstedt.
parent cf0ab26f
No related branches found
No related tags found
No related merge requests found
Pipeline #1411 passed
...@@ -42,7 +42,7 @@ public class MDMetadata2Dataset { ...@@ -42,7 +42,7 @@ public class MDMetadata2Dataset {
private static final String LANGUAGE_EN = "en"; private static final String LANGUAGE_EN = "en";
private static final Logger log = LoggerFactory.getLogger(MDMetadata2Dataset.class); private static final Logger log = LoggerFactory.getLogger(MDMetadata2Dataset.class);
private static final String XPATH_OPERATION_GET_CAPABILITIES = "gmd:identificationInfo/*/srv:containsOperations/srv:SV_OperationMetadata[srv:operationName/gco:CharacterString/text()='GetCapabilities']"; private static final String XPATH_OPERATION_GET_CAPABILITIES = "gmd:identificationInfo/*/srv:containsOperations/srv:SV_OperationMetadata[srv:operationName/gco:CharacterString ='GetCapabilities']";
static IRIFactory factory = IRIFactory.iriImplementation(); static IRIFactory factory = IRIFactory.iriImplementation();
private final Model model; private final Model model;
private final Map<String, String> keywordMapping = new HashMap<>(); private final Map<String, String> keywordMapping = new HashMap<>();
...@@ -361,6 +361,19 @@ public class MDMetadata2Dataset { ...@@ -361,6 +361,19 @@ public class MDMetadata2Dataset {
metadata.addNamespace("srv", "http://www.isotc211.org/2005/srv"); metadata.addNamespace("srv", "http://www.isotc211.org/2005/srv");
} }
static String getServiceEndpoint(Element metadata) {
String url;
// Is it a service with a comprehensive description of operations?
if (metadata.selectSingleNode(XPATH_OPERATION_GET_CAPABILITIES) != null) {
final Element operationMetadata = (Element) metadata.selectSingleNode(XPATH_OPERATION_GET_CAPABILITIES);
url = repairURL(StringUtils.trim(operationMetadata.selectSingleNode("srv:connectPoint/gmd:CI_OnlineResource/gmd:linkage/gmd:URL").getStringValue()));
} else {
url = repairURL(getTextOrNull(metadata.selectSingleNode("gmd:identificationInfo[1]/*/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:MD_Identifier/gmd:code")));
log.warn("Using identifier as service endpoint: {}", url);
}
return url;
}
public BridgeSettings getSettings() { public BridgeSettings getSettings() {
return settings; return settings;
} }
...@@ -411,16 +424,7 @@ public class MDMetadata2Dataset { ...@@ -411,16 +424,7 @@ public class MDMetadata2Dataset {
return convertMultiFormatDataset(metadata, true); return convertMultiFormatDataset(metadata, true);
} }
final String url; final String url = getServiceEndpoint(metadata);
// Is it a service with a comprehensive description of operations?
if (metadata.selectSingleNode(XPATH_OPERATION_GET_CAPABILITIES) != null) {
final Element operationMetadata = (Element) metadata.selectSingleNode(XPATH_OPERATION_GET_CAPABILITIES);
url = repairURL(StringUtils.trim(operationMetadata.selectSingleNode("srv:connectPoint/gmd:CI_OnlineResource/gmd:linkage/gmd:URL").getStringValue()));
} else {
url = repairURL(getTextOrNull(metadata.selectSingleNode("gmd:identificationInfo[1]/*/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:MD_Identifier/gmd:code")));
}
if (!isValidURLandIRI(url)) { if (!isValidURLandIRI(url)) {
log.warn("Distribution has an invalid URI {} - ignoring it.", url); log.warn("Distribution has an invalid URI {} - ignoring it.", url);
return Collections.emptySet(); return Collections.emptySet();
...@@ -995,14 +999,7 @@ public class MDMetadata2Dataset { ...@@ -995,14 +999,7 @@ public class MDMetadata2Dataset {
convertDataResource(metadata, dataService); convertDataResource(metadata, dataService);
String url; String url = getServiceEndpoint(metadata);
// Is it a service with a comprehensive description of operations?
if (metadata.selectSingleNode(XPATH_OPERATION_GET_CAPABILITIES) != null) {
final Element operationMetadata = (Element) metadata.selectSingleNode(XPATH_OPERATION_GET_CAPABILITIES);
url = repairURL(StringUtils.trim(operationMetadata.selectSingleNode("srv:connectPoint/gmd:CI_OnlineResource/gmd:linkage/gmd:URL").getStringValue()));
} else {
url = repairURL(getTextOrNull(metadata.selectSingleNode("gmd:identificationInfo[1]/*/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:MD_Identifier/gmd:code")));
}
if (StringUtils.contains(StringUtils.lowerCase(url), "request=getcapabilities")) { if (StringUtils.contains(StringUtils.lowerCase(url), "request=getcapabilities")) {
// the GetCapabilites request is linked // the GetCapabilites request is linked
......
...@@ -34,6 +34,7 @@ public class MDMetadata2DatasetTests { ...@@ -34,6 +34,7 @@ public class MDMetadata2DatasetTests {
private static final Property PROPERTY_applicable_Legislation = ResourceFactory.createProperty("http://data.europa.eu/r5r/", "applicableLegislation"); private static final Property PROPERTY_applicable_Legislation = ResourceFactory.createProperty("http://data.europa.eu/r5r/", "applicableLegislation");
static Namespace NS_GMD = Namespace.get("gmd", "http://www.isotc211.org/2005/gmd"); static Namespace NS_GMD = Namespace.get("gmd", "http://www.isotc211.org/2005/gmd");
final Model model = ModelFactory.createDefaultModel();
private final SAXReader saxReader = new SAXReader(); private final SAXReader saxReader = new SAXReader();
private MDMetadata2Dataset service; private MDMetadata2Dataset service;
private CswInterface cswInterface; private CswInterface cswInterface;
...@@ -85,7 +86,6 @@ public class MDMetadata2DatasetTests { ...@@ -85,7 +86,6 @@ public class MDMetadata2DatasetTests {
@Test @Test
public void testConvert() throws DocumentException, IOException { public void testConvert() throws DocumentException, IOException {
final Model model = ModelFactory.createDefaultModel();
model.read(getClass().getResourceAsStream("/f7f90143-c2ad-46b2-934d-93dfd5e0f031.rdf"), null); model.read(getClass().getResourceAsStream("/f7f90143-c2ad-46b2-934d-93dfd5e0f031.rdf"), null);
final Resource referenceDataset = model.listResourcesWithProperty(RDF.type, DCAT.Dataset).next(); final Resource referenceDataset = model.listResourcesWithProperty(RDF.type, DCAT.Dataset).next();
...@@ -550,7 +550,6 @@ public class MDMetadata2DatasetTests { ...@@ -550,7 +550,6 @@ public class MDMetadata2DatasetTests {
Element element = new SAXReader().read(new StringReader(xml)).getRootElement(); Element element = new SAXReader().read(new StringReader(xml)).getRootElement();
Model model = ModelFactory.createDefaultModel();
Resource resource = model.createResource(); Resource resource = model.createResource();
MDMetadata2Dataset.addTemporalExtend(resource, element); MDMetadata2Dataset.addTemporalExtend(resource, element);
...@@ -576,7 +575,6 @@ public class MDMetadata2DatasetTests { ...@@ -576,7 +575,6 @@ public class MDMetadata2DatasetTests {
Element element = new SAXReader().read(new StringReader(xml)).getRootElement(); Element element = new SAXReader().read(new StringReader(xml)).getRootElement();
Model model = ModelFactory.createDefaultModel();
Resource resource = model.createResource(); Resource resource = model.createResource();
MDMetadata2Dataset.addTemporalExtend(resource, element); MDMetadata2Dataset.addTemporalExtend(resource, element);
...@@ -725,8 +723,6 @@ public class MDMetadata2DatasetTests { ...@@ -725,8 +723,6 @@ public class MDMetadata2DatasetTests {
@Test @Test
public void createFoafOrg_invalidEmail() throws DocumentException { public void createFoafOrg_invalidEmail() throws DocumentException {
final Element ciResponsibleParty = saxReader.read(getClass().getResourceAsStream("/CI_ResponsibleParty1.xml")).getRootElement(); final Element ciResponsibleParty = saxReader.read(getClass().getResourceAsStream("/CI_ResponsibleParty1.xml")).getRootElement();
final Model model = ModelFactory.createDefaultModel();
MDMetadata2Dataset.createFoafOrg(ciResponsibleParty, model); MDMetadata2Dataset.createFoafOrg(ciResponsibleParty, model);
model.write(Writer.nullWriter(), "RDF/XML-ABBREV"); model.write(Writer.nullWriter(), "RDF/XML-ABBREV");
} }
...@@ -848,7 +844,6 @@ public class MDMetadata2DatasetTests { ...@@ -848,7 +844,6 @@ public class MDMetadata2DatasetTests {
@Test @Test
void addBoundingBox_null() throws DocumentException { void addBoundingBox_null() throws DocumentException {
Model model = ModelFactory.createDefaultModel();
Resource resource = model.createResource(); Resource resource = model.createResource();
MDMetadata2Dataset.addBoundingBox(resource, null); MDMetadata2Dataset.addBoundingBox(resource, null);
assertFalse(model.listStatements().hasNext()); assertFalse(model.listStatements().hasNext());
...@@ -865,7 +860,6 @@ public class MDMetadata2DatasetTests { ...@@ -865,7 +860,6 @@ public class MDMetadata2DatasetTests {
"</gmd:EX_GeographicBoundingBox>"; "</gmd:EX_GeographicBoundingBox>";
Element element = new SAXReader().read(new StringReader(xml)).getRootElement(); Element element = new SAXReader().read(new StringReader(xml)).getRootElement();
Model model = ModelFactory.createDefaultModel();
Resource resource = model.createResource(); Resource resource = model.createResource();
MDMetadata2Dataset.addBoundingBox(resource, element); MDMetadata2Dataset.addBoundingBox(resource, element);
...@@ -905,7 +899,6 @@ public class MDMetadata2DatasetTests { ...@@ -905,7 +899,6 @@ public class MDMetadata2DatasetTests {
"</gmd:EX_GeographicBoundingBox>"; "</gmd:EX_GeographicBoundingBox>";
Element element = new SAXReader().read(new StringReader(xml)).getRootElement(); Element element = new SAXReader().read(new StringReader(xml)).getRootElement();
Model model = ModelFactory.createDefaultModel();
Resource resource = model.createResource(); Resource resource = model.createResource();
MDMetadata2Dataset.addBoundingBox(resource, element); MDMetadata2Dataset.addBoundingBox(resource, element);
...@@ -943,7 +936,6 @@ public class MDMetadata2DatasetTests { ...@@ -943,7 +936,6 @@ public class MDMetadata2DatasetTests {
"</gmd:EX_GeographicBoundingBox>"; "</gmd:EX_GeographicBoundingBox>";
Element element = new SAXReader().read(new StringReader(xml)).getRootElement(); Element element = new SAXReader().read(new StringReader(xml)).getRootElement();
Model model = ModelFactory.createDefaultModel();
Resource resource = model.createResource(); Resource resource = model.createResource();
MDMetadata2Dataset.addBoundingBox(resource, element); MDMetadata2Dataset.addBoundingBox(resource, element);
...@@ -981,7 +973,6 @@ public class MDMetadata2DatasetTests { ...@@ -981,7 +973,6 @@ public class MDMetadata2DatasetTests {
"</gmd:EX_GeographicBoundingBox>"; "</gmd:EX_GeographicBoundingBox>";
Element element = new SAXReader().read(new StringReader(xml)).getRootElement(); Element element = new SAXReader().read(new StringReader(xml)).getRootElement();
Model model = ModelFactory.createDefaultModel();
Resource resource = model.createResource(); Resource resource = model.createResource();
MDMetadata2Dataset.addBoundingBox(resource, element); MDMetadata2Dataset.addBoundingBox(resource, element);
...@@ -1457,4 +1448,64 @@ public class MDMetadata2DatasetTests { ...@@ -1457,4 +1448,64 @@ public class MDMetadata2DatasetTests {
result.getPropertyResourceValue(DCATAP.hvdCategory).getURI()); result.getPropertyResourceValue(DCATAP.hvdCategory).getURI());
} }
@Test
public void getServiceEndpoint_norderstedtWFS() throws DocumentException {
final Element inputDocument = saxReader.read(getClass().getResourceAsStream("/norderstedt_wfs.xml")).getRootElement();
String result = MDMetadata2Dataset.getServiceEndpoint(inputDocument);
assertEquals("https://geoservice.norderstedt.de/geoserver/pub/wfs?SERVICE=WFS&version=2.0.0&request=GetCapabilities", result);
}
@Test
public void createDataService_norderstedtWMS() throws DocumentException {
final Element input = saxReader.read(getClass().getResourceAsStream("/norderstedt_wms.xml")).getRootElement();
Resource dataService = service.createDataService(input, model);
assertEquals("https://geoservice.norderstedt.de/geoserver/pub/soz_Wohlfahrt/wms", dataService.getPropertyResourceValue(DCAT.endpointURL).getURI());
}
@Test
public void convertServiceToDistributions_norderstedtWMS() throws DocumentException {
final Element input = saxReader.read(getClass().getResourceAsStream("/norderstedt_wms.xml")).getRootElement();
Collection<Resource> distributions = service.convertServiceToDistributions(input);
assertEquals(1, distributions.size());
Resource distribution = distributions.iterator().next();
assertEquals("https://geoservice.norderstedt.de/geoserver/pub/soz_Wohlfahrt/wms?SERVICE=WMS&version=1.3.0&request=GetCapabilities", distribution.getPropertyResourceValue(DCAT.accessURL).getURI());
}
@Test
public void getServiceEndpoint_norderstedtWMS() throws DocumentException {
final Element inputDocument = saxReader.read(getClass().getResourceAsStream("/norderstedt_wms.xml")).getRootElement();
String result = MDMetadata2Dataset.getServiceEndpoint(inputDocument);
assertEquals("https://geoservice.norderstedt.de/geoserver/pub/soz_Wohlfahrt/wms?SERVICE=WMS&version=1.3.0&request=GetCapabilities", result);
}
@Test
public void convert_norderstedtDataset() throws DocumentException, IOException {
final Element wmsElement = saxReader.read(getClass().getResourceAsStream("/norderstedt_wms.xml")).getRootElement();
final Element wfsElement = saxReader.read(getClass().getResourceAsStream("/norderstedt_wfs.xml")).getRootElement();
final Element input = saxReader.read(getClass().getResourceAsStream("/norderstedt_dataset.xml")).getRootElement();
Mockito.when(cswInterface.findOperatesOn("https://registry.gdi-de.org/id/de.sh/ea7599f9-0134-4a3f-ab46-5116addc1bb3")).thenReturn(Arrays.asList(wfsElement, wmsElement));
Resource dataset = service.convert(input);
final Map<String, Resource> distributionMap = collectDistributions(dataset);
assertEquals(4, distributionMap.size());
Resource distributionWMS = distributionMap.get("https://geoservice.norderstedt.de/geoserver/pub/soz_Wohlfahrt/wms?SERVICE=WMS&version=1.3.0&request=GetCapabilities");
Resource distributionWFS = distributionMap.get("https://geoservice.norderstedt.de/geoserver/pub/wfs?SERVICE=WFS&version=2.0.0&request=GetCapabilities");
Resource distributionCSV = distributionMap.get("https://geoservice.norderstedt.de/geoserver/pub/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=pub:soz_Wohlfahrt&outputFormat=CSV");
Resource distributionSHP = distributionMap.get("https://geoservice.norderstedt.de/geoserver/pub/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=pub:soz_Wohlfahrt&outputFormat=SHAPE-ZIP");
assertNotNull(distributionCSV);
assertNotNull(distributionSHP);
assertNotNull(distributionWFS);
assertNotNull(distributionWMS);
assertEquals("http://publications.europa.eu/resource/authority/file-type/WFS_SRVC",
distributionWFS.getPropertyResourceValue(DCTerms.format).getURI());
assertEquals("http://publications.europa.eu/resource/authority/file-type/WMS_SRVC",
distributionWMS.getPropertyResourceValue(DCTerms.format).getURI());
}
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment