diff --git a/src/main/java/de/landsh/opendata/catalogproxy/CatalogFilter.java b/src/main/java/de/landsh/opendata/catalogproxy/CatalogFilter.java index a5c6b75de2473de03084645d6fc18221f39a9ec5..67e90bbc68d17b21c08b7884361e1dff64767e6f 100644 --- a/src/main/java/de/landsh/opendata/catalogproxy/CatalogFilter.java +++ b/src/main/java/de/landsh/opendata/catalogproxy/CatalogFilter.java @@ -74,6 +74,7 @@ public class CatalogFilter implements InitializingBean { rewriteDownloadAndAccessURLs(model); addDownloadURLs(model); addAccessRights(model); + addRights(model); return model; } @@ -292,4 +293,24 @@ public class CatalogFilter implements InitializingBean { urlReplacements.put(source, target); } } + + /** + * Add a dct:rights statement to Distributions. The German DCAT-AP.de treats dct:rights as a not so + * important optional property and relies on dct:license. However, the European data portal values the + * dct:rights property highly. + */ + void addRights(Model model) { + final ResIterator it = model.listSubjectsWithProperty(RDF.type, DCAT.Distribution); + while (it.hasNext()) { + final Resource distribution = it.next(); + + final Resource rights = distribution.getPropertyResourceValue(DCTerms.rights); + final Resource license = distribution.getPropertyResourceValue(DCTerms.license); + + if (rights == null && license != null) { + distribution.addProperty(DCTerms.rights, license); + } + } + } + } diff --git a/src/test/java/de/landsh/opendata/catalogproxy/CatalogFilterTest.java b/src/test/java/de/landsh/opendata/catalogproxy/CatalogFilterTest.java index 89bb0aa926a929563ae69ae17d609c5975a48c5d..3578986be7d43acc5a543bde77c56a902b059ad2 100644 --- a/src/test/java/de/landsh/opendata/catalogproxy/CatalogFilterTest.java +++ b/src/test/java/de/landsh/opendata/catalogproxy/CatalogFilterTest.java @@ -156,7 +156,7 @@ public class CatalogFilterTest { /** * Check that a <code>dct:accessRights http://publications.europa.eu/resource/authority/access-right/PUBLIC</code> - * statement ist added to each dataset. + * statement has been added to each dataset. */ @Test public void work_will_add_accessRights() throws Exception { @@ -178,4 +178,29 @@ public class CatalogFilterTest { inputStream.close(); } + + /** + * Check that a dct:rights statement has been added to each distribution and is equal to the dct:license statement. + */ + @Test + public void work_will_add_rights() throws Exception { + final InputStream inputStream = getClass().getResourceAsStream("/with_collection.xml"); + final Model model = catalogFilter.work(inputStream); + + // Every dataset has a dct:accessRights statement + final ResIterator it = model.listSubjectsWithProperty(RDF.type, DCAT.Distribution); + int count = 0; + while (it.hasNext()) { + final Resource distribution = it.next(); + count++; + final Resource rights = distribution.getPropertyResourceValue(DCTerms.rights); + final Resource license = distribution.getPropertyResourceValue(DCTerms.license); + assertNotNull(rights); + assertEquals( license, rights); + } + + assertEquals(7, count); + + inputStream.close(); + } }