Skip to content

Commit 7988775

Browse files
author
Miel Vander Sande
committed
Merge conflict
2 parents 889dd01 + d36cc14 commit 7988775

File tree

3 files changed

+159
-87
lines changed

3 files changed

+159
-87
lines changed

src/org/linkeddatafragments/config/ConfigReader.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
public class ConfigReader {
1818
private final Map<String, JsonObject> dataSources = new HashMap<>();
1919
private final Map<String, String> prefixes = new HashMap<>();
20+
private final String baseURL;
2021

2122
/**
2223
* Creates a new configuration reader.
@@ -25,6 +26,8 @@ public class ConfigReader {
2526
*/
2627
public ConfigReader(Reader configReader) {
2728
JsonObject root = new JsonParser().parse(configReader).getAsJsonObject();
29+
this.baseURL = root.has("baseURL") ? root.getAsJsonPrimitive("baseURL").getAsString() : null;
30+
2831
for (Entry<String, JsonElement> entry : root.getAsJsonObject("datasources").entrySet()) {
2932
JsonObject dataSource = entry.getValue().getAsJsonObject();
3033
this.dataSources.put(entry.getKey(), dataSource);
@@ -51,4 +54,8 @@ public Map<String, JsonObject> getDataSources() {
5154
public Map<String, String> getPrefixes() {
5255
return prefixes;
5356
}
57+
58+
public String getBaseURL() {
59+
return baseURL;
60+
}
5461
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.linkeddatafragments.datasource;
2+
3+
import com.hp.hpl.jena.rdf.model.Model;
4+
import com.hp.hpl.jena.rdf.model.ModelFactory;
5+
import com.hp.hpl.jena.rdf.model.Property;
6+
import com.hp.hpl.jena.rdf.model.RDFNode;
7+
import com.hp.hpl.jena.rdf.model.Resource;
8+
import com.hp.hpl.jena.rdf.model.StmtIterator;
9+
import com.hp.hpl.jena.rdf.model.impl.PropertyImpl;
10+
import com.hp.hpl.jena.rdf.model.impl.ResourceImpl;
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
14+
/**
15+
* An Index data source provides an overview of all available datasets.
16+
*
17+
* @author Miel Vander Sande
18+
*/
19+
public class IndexDataSource extends DataSource {
20+
21+
final String RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
22+
final String RDFS = "http://www.w3.org/2000/01/rdf-schema#";
23+
final String DC = "http://purl.org/dc/terms/";
24+
final String VOID = "http://rdfs.org/ns/void#";
25+
26+
private final Model model;
27+
28+
public IndexDataSource(String baseUrl, HashMap<String, IDataSource> datasources) {
29+
super("Index", "List of all datasources");
30+
31+
this.model = ModelFactory.createDefaultModel();
32+
33+
for (Map.Entry<String, IDataSource> entry : datasources.entrySet()) {
34+
String datasourceName = entry.getKey();
35+
IDataSource datasource = entry.getValue();
36+
37+
Resource datasourceUrl = new ResourceImpl(baseUrl + "/" + datasourceName);
38+
39+
model.add(datasourceUrl, new PropertyImpl(RDF + "type"), VOID + "Dataset");
40+
model.add(datasourceUrl, new PropertyImpl(RDFS + "label"), datasource.getTitle());
41+
model.add(datasourceUrl, new PropertyImpl(DC + "title"), datasource.getTitle());
42+
model.add(datasourceUrl, new PropertyImpl(DC + "description"), datasource.getDescription());
43+
}
44+
}
45+
46+
@Override
47+
public TriplePatternFragment getFragment(Resource subject, Property predicate, RDFNode object, long offset, long limit) {
48+
StmtIterator listStatements = this.model.listStatements(subject, predicate, object);
49+
Model result = ModelFactory.createDefaultModel();
50+
51+
long index = 0;
52+
while (listStatements.hasNext() && index < offset) {
53+
listStatements.next();
54+
index++;
55+
}
56+
57+
while (listStatements.hasNext() && index < (offset + limit)) {
58+
result.add(listStatements.next());
59+
}
60+
61+
return new TriplePatternFragmentBase(result, result.size());
62+
}
63+
64+
}

0 commit comments

Comments
 (0)