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

Collections mit in die Ausgabe aufnehmen

parent 3150e512
No related branches found
No related tags found
No related merge requests found
...@@ -5,12 +5,13 @@ ...@@ -5,12 +5,13 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version> <version>2.5.3</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/>
</parent> </parent>
<groupId>de.landsh.opendata</groupId> <groupId>de.landsh.opendata</groupId>
<artifactId>dcat-catalog-proxy</artifactId> <artifactId>dcat-catalog-proxy</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.1-SNAPSHOT</version>
<name>dcat-catalog-proxy</name> <name>dcat-catalog-proxy</name>
<description>DCAT catalog proxy</description> <description>DCAT catalog proxy</description>
......
...@@ -54,7 +54,7 @@ public class CatalogFilter implements InitializingBean { ...@@ -54,7 +54,7 @@ public class CatalogFilter implements InitializingBean {
final ResIterator it = model.listSubjectsWithProperty(RDF.type, DCAT.Dataset); final ResIterator it = model.listSubjectsWithProperty(RDF.type, DCAT.Dataset);
while (it.hasNext()) { while (it.hasNext()) {
Resource dataset = it.next(); Resource dataset = it.next();
if (hasAtLeastOneValidDistribution(dataset)) { if (hasAtLeastOneValidDistribution(dataset) || isCollection(dataset)) {
usedDistributionIds.addAll(getDistributionsForDataset(dataset)); usedDistributionIds.addAll(getDistributionsForDataset(dataset));
} else { } else {
model.remove(dataset.listProperties()); model.remove(dataset.listProperties());
...@@ -234,6 +234,11 @@ public class CatalogFilter implements InitializingBean { ...@@ -234,6 +234,11 @@ public class CatalogFilter implements InitializingBean {
return result; return result;
} }
boolean isCollection(Resource dataset) {
final Resource type = dataset.getPropertyResourceValue(DCTerms.type);
return type != null && "http://dcat-ap.de/def/datasetTypes/collection".equals(type.getURI());
}
boolean hasAtLeastOneValidDistribution(Resource dataset) { boolean hasAtLeastOneValidDistribution(Resource dataset) {
final StmtIterator it = dataset.listProperties(ResourceFactory.createProperty("http://www.w3.org/ns/dcat#distribution")); final StmtIterator it = dataset.listProperties(ResourceFactory.createProperty("http://www.w3.org/ns/dcat#distribution"));
boolean atLeastOneValidFormat = false; boolean atLeastOneValidFormat = false;
......
...@@ -55,7 +55,7 @@ public class CatalogFilterTest { ...@@ -55,7 +55,7 @@ public class CatalogFilterTest {
} }
@Test @Test
public void test() throws Exception { public void work() throws Exception {
final InputStream inputStream = getClass().getResourceAsStream("/catalog.xml"); final InputStream inputStream = getClass().getResourceAsStream("/catalog.xml");
catalogFilter.work(inputStream); catalogFilter.work(inputStream);
inputStream.close(); inputStream.close();
...@@ -137,4 +137,19 @@ public class CatalogFilterTest { ...@@ -137,4 +137,19 @@ public class CatalogFilterTest {
assertEquals("https://data.sh/fileadmin/Dokumente/Statistische_Berichte/landwirtschaft/C_II_1_m_S/C_II_1_m0409_S.pdf", accessURL.getURI()); assertEquals("https://data.sh/fileadmin/Dokumente/Statistische_Berichte/landwirtschaft/C_II_1_m_S/C_II_1_m0409_S.pdf", accessURL.getURI());
assertEquals("https://opendata.sh/file.csv", downloadURL.getURI()); assertEquals("https://opendata.sh/file.csv", downloadURL.getURI());
} }
/**
* Collections (dcat:Dataset with dct:type "http://dcat-ap.de/def/datasetTypes/collection" will be included in the
* filtered results.
*/
@Test
public void work_will_preseve_collections() throws Exception {
final InputStream inputStream = getClass().getResourceAsStream("/with_collection.xml");
final Model model = catalogFilter.work(inputStream);
Assertions.assertEquals(8, countInstances(model, DCAT.Dataset));
Assertions.assertEquals(7, countInstances(model, DCAT.Distribution));
inputStream.close();
}
} }
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