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

Merge branch '1-dct-accessrights-hinzufuegen' into 'master'

Resolve "dct:accessRights hinzufügen"

Closes #1

See merge request opendata/dcat-catalogy-proxy!1
parents bc30ed7a 183912d8
Branches
Tags
1 merge request!1Resolve "dct:accessRights hinzufügen"
...@@ -21,17 +21,21 @@ import java.util.*; ...@@ -21,17 +21,21 @@ import java.util.*;
*/ */
public class CatalogFilter implements InitializingBean { public class CatalogFilter implements InitializingBean {
private static final Collection<Resource> UNWANTED_FORMATS = Arrays.asList( 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/PDF"),
ResourceFactory.createResource("http://publications.europa.eu/resource/authority/file-type/DOC"), 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/DOCX"),
ResourceFactory.createResource("http://publications.europa.eu/resource/authority/file-type/HTML") 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"); private static final Property LOCN_GEOMETRY = ResourceFactory.createProperty("http://www.w3.org/ns/locn#geometry");
final private Map<String, String> urlReplacements = new HashMap<>(); final private Map<String, String> urlReplacements = new HashMap<>();
@Value("#{${replaceURL:''}}") @Value("#{${replaceURL:''}}")
List<String> replaceURL; List<String> replaceURL;
@Value("${baseURL:http://localhost:8080/}") @Value("${baseURL:http://localhost:8080/}")
private String baseURL; private String baseURL;
...@@ -69,10 +73,28 @@ public class CatalogFilter implements InitializingBean { ...@@ -69,10 +73,28 @@ public class CatalogFilter implements InitializingBean {
rewriteHydraURLs(model); rewriteHydraURLs(model);
rewriteDownloadAndAccessURLs(model); rewriteDownloadAndAccessURLs(model);
addDownloadURLs(model); addDownloadURLs(model);
addAccessRights(model);
return 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 * 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 * important optional properties and relies on the accessURL. However, the European data portal values the
......
...@@ -8,6 +8,7 @@ import org.apache.jena.riot.RDFLanguages; ...@@ -8,6 +8,7 @@ import org.apache.jena.riot.RDFLanguages;
import org.apache.jena.riot.RDFParser; import org.apache.jena.riot.RDFParser;
import org.apache.jena.riot.system.ErrorHandlerFactory; import org.apache.jena.riot.system.ErrorHandlerFactory;
import org.apache.jena.vocabulary.DCAT; import org.apache.jena.vocabulary.DCAT;
import org.apache.jena.vocabulary.DCTerms;
import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.RDF;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
...@@ -152,4 +153,29 @@ public class CatalogFilterTest { ...@@ -152,4 +153,29 @@ public class CatalogFilterTest {
inputStream.close(); 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();
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment