diff --git a/src/main/java/de/landsh/opendata/catalogproxy/CatalogFilter.java b/src/main/java/de/landsh/opendata/catalogproxy/CatalogFilter.java index 9a1aa2ce792d5f610eb90f1f7bf7b476f923796b..a5c6b75de2473de03084645d6fc18221f39a9ec5 100644 --- a/src/main/java/de/landsh/opendata/catalogproxy/CatalogFilter.java +++ b/src/main/java/de/landsh/opendata/catalogproxy/CatalogFilter.java @@ -21,17 +21,21 @@ import java.util.*; */ public class CatalogFilter implements InitializingBean { - private static final Collection<Resource> UNWANTED_FORMATS = Arrays.asList( ResourceFactory.createResource("http://publications.europa.eu/resource/authority/file-type/PDF"), ResourceFactory.createResource("http://publications.europa.eu/resource/authority/file-type/DOC"), ResourceFactory.createResource("http://publications.europa.eu/resource/authority/file-type/DOCX"), ResourceFactory.createResource("http://publications.europa.eu/resource/authority/file-type/HTML") ); + + private static final Resource ACCESS_RIGHTS_PUBLIC = ResourceFactory.createResource("http://publications.europa.eu/resource/authority/access-right/PUBLIC"); + private static final Property LOCN_GEOMETRY = ResourceFactory.createProperty("http://www.w3.org/ns/locn#geometry"); final private Map<String, String> urlReplacements = new HashMap<>(); + @Value("#{${replaceURL:''}}") List<String> replaceURL; + @Value("${baseURL:http://localhost:8080/}") private String baseURL; @@ -69,10 +73,28 @@ public class CatalogFilter implements InitializingBean { rewriteHydraURLs(model); rewriteDownloadAndAccessURLs(model); addDownloadURLs(model); + addAccessRights(model); return model; } + /** + * It is totally important to the European data portal that there is an <code>accessRights = PUBLIC</code> statement + * for every dataset. + */ + private void addAccessRights(Model model) { + final ResIterator it = model.listSubjectsWithProperty(RDF.type, DCAT.Dataset); + while (it.hasNext()) { + final Resource dataset = it.next(); + + final Resource accessRight = dataset.getPropertyResourceValue(DCTerms.accessRights); + + if (accessRight == null) { + dataset.addProperty(DCTerms.accessRights, ACCESS_RIGHTS_PUBLIC); + } + } + } + /** * Add downloadURL properties to Distributions. The German DCAT-AP.de treats downloadURL as a not so * important optional properties and relies on the accessURL. However, the European data portal values the diff --git a/src/test/java/de/landsh/opendata/catalogproxy/CatalogFilterTest.java b/src/test/java/de/landsh/opendata/catalogproxy/CatalogFilterTest.java index 4c4e2676031226f0984ae954ec753272b0a2a972..89bb0aa926a929563ae69ae17d609c5975a48c5d 100644 --- a/src/test/java/de/landsh/opendata/catalogproxy/CatalogFilterTest.java +++ b/src/test/java/de/landsh/opendata/catalogproxy/CatalogFilterTest.java @@ -8,6 +8,7 @@ import org.apache.jena.riot.RDFLanguages; import org.apache.jena.riot.RDFParser; import org.apache.jena.riot.system.ErrorHandlerFactory; import org.apache.jena.vocabulary.DCAT; +import org.apache.jena.vocabulary.DCTerms; import org.apache.jena.vocabulary.RDF; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -152,4 +153,29 @@ public class CatalogFilterTest { inputStream.close(); } + + /** + * Check that a <code>dct:accessRights http://publications.europa.eu/resource/authority/access-right/PUBLIC</code> + * statement ist added to each dataset. + */ + @Test + public void work_will_add_accessRights() 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.Dataset); + int count = 0; + while (it.hasNext()) { + final Resource distribution = it.next(); + count++; + final Resource accessRights = distribution.getPropertyResourceValue(DCTerms.accessRights); + assertNotNull(accessRights); + assertEquals("http://publications.europa.eu/resource/authority/access-right/PUBLIC", accessRights.getURI()); + } + + assertEquals(8, count); + + inputStream.close(); + } }