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
Branches
No related tags found
No related merge requests found
Pipeline #1411 passed
......@@ -42,7 +42,7 @@ public class MDMetadata2Dataset {
private static final String LANGUAGE_EN = "en";
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();
private final Model model;
private final Map<String, String> keywordMapping = new HashMap<>();
......@@ -361,6 +361,19 @@ public class MDMetadata2Dataset {
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() {
return settings;
}
......@@ -411,16 +424,7 @@ public class MDMetadata2Dataset {
return convertMultiFormatDataset(metadata, true);
}
final 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")));
}
final String url = getServiceEndpoint(metadata);
if (!isValidURLandIRI(url)) {
log.warn("Distribution has an invalid URI {} - ignoring it.", url);
return Collections.emptySet();
......@@ -995,14 +999,7 @@ public class MDMetadata2Dataset {
convertDataResource(metadata, dataService);
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")));
}
String url = getServiceEndpoint(metadata);
if (StringUtils.contains(StringUtils.lowerCase(url), "request=getcapabilities")) {
// the GetCapabilites request is linked
......
......@@ -34,6 +34,7 @@ public class MDMetadata2DatasetTests {
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");
final Model model = ModelFactory.createDefaultModel();
private final SAXReader saxReader = new SAXReader();
private MDMetadata2Dataset service;
private CswInterface cswInterface;
......@@ -85,7 +86,6 @@ public class MDMetadata2DatasetTests {
@Test
public void testConvert() throws DocumentException, IOException {
final Model model = ModelFactory.createDefaultModel();
model.read(getClass().getResourceAsStream("/f7f90143-c2ad-46b2-934d-93dfd5e0f031.rdf"), null);
final Resource referenceDataset = model.listResourcesWithProperty(RDF.type, DCAT.Dataset).next();
......@@ -550,7 +550,6 @@ public class MDMetadata2DatasetTests {
Element element = new SAXReader().read(new StringReader(xml)).getRootElement();
Model model = ModelFactory.createDefaultModel();
Resource resource = model.createResource();
MDMetadata2Dataset.addTemporalExtend(resource, element);
......@@ -576,7 +575,6 @@ public class MDMetadata2DatasetTests {
Element element = new SAXReader().read(new StringReader(xml)).getRootElement();
Model model = ModelFactory.createDefaultModel();
Resource resource = model.createResource();
MDMetadata2Dataset.addTemporalExtend(resource, element);
......@@ -725,8 +723,6 @@ public class MDMetadata2DatasetTests {
@Test
public void createFoafOrg_invalidEmail() throws DocumentException {
final Element ciResponsibleParty = saxReader.read(getClass().getResourceAsStream("/CI_ResponsibleParty1.xml")).getRootElement();
final Model model = ModelFactory.createDefaultModel();
MDMetadata2Dataset.createFoafOrg(ciResponsibleParty, model);
model.write(Writer.nullWriter(), "RDF/XML-ABBREV");
}
......@@ -848,7 +844,6 @@ public class MDMetadata2DatasetTests {
@Test
void addBoundingBox_null() throws DocumentException {
Model model = ModelFactory.createDefaultModel();
Resource resource = model.createResource();
MDMetadata2Dataset.addBoundingBox(resource, null);
assertFalse(model.listStatements().hasNext());
......@@ -865,7 +860,6 @@ public class MDMetadata2DatasetTests {
"</gmd:EX_GeographicBoundingBox>";
Element element = new SAXReader().read(new StringReader(xml)).getRootElement();
Model model = ModelFactory.createDefaultModel();
Resource resource = model.createResource();
MDMetadata2Dataset.addBoundingBox(resource, element);
......@@ -905,7 +899,6 @@ public class MDMetadata2DatasetTests {
"</gmd:EX_GeographicBoundingBox>";
Element element = new SAXReader().read(new StringReader(xml)).getRootElement();
Model model = ModelFactory.createDefaultModel();
Resource resource = model.createResource();
MDMetadata2Dataset.addBoundingBox(resource, element);
......@@ -943,7 +936,6 @@ public class MDMetadata2DatasetTests {
"</gmd:EX_GeographicBoundingBox>";
Element element = new SAXReader().read(new StringReader(xml)).getRootElement();
Model model = ModelFactory.createDefaultModel();
Resource resource = model.createResource();
MDMetadata2Dataset.addBoundingBox(resource, element);
......@@ -981,7 +973,6 @@ public class MDMetadata2DatasetTests {
"</gmd:EX_GeographicBoundingBox>";
Element element = new SAXReader().read(new StringReader(xml)).getRootElement();
Model model = ModelFactory.createDefaultModel();
Resource resource = model.createResource();
MDMetadata2Dataset.addBoundingBox(resource, element);
......@@ -1179,7 +1170,7 @@ public class MDMetadata2DatasetTests {
assertTrue(collectApplicableLegislation(result).contains("http://data.europa.eu/eli/dir/2007/2/2019-06-26"));
}
private Set<String> collectApplicableLegislation( Resource result) {
private Set<String> collectApplicableLegislation(Resource result) {
Set<String> conformsTo = new HashSet<>();
StmtIterator it = result.listProperties(DCATAP.applicableLegislation);
while (it.hasNext()) {
......@@ -1452,9 +1443,69 @@ public class MDMetadata2DatasetTests {
result.getProperty(DCAT.endpointURL).getResource().getURI());
assertTrue(result.hasProperty(DCAT.servesDataset, ResourceFactory.createResource("https://registry.gdi-de.org/id/de.sh/f5626e31-7674-446b-be64-af93d494cd0b")));
assertTrue(collectApplicableLegislation(result) .contains( "http://data.europa.eu/eli/reg_impl/2023/138/oj"));
assertTrue(collectApplicableLegislation(result).contains("http://data.europa.eu/eli/reg_impl/2023/138/oj"));
assertEquals("http://data.europa.eu/bna/c_ac64a52d",
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