Skip to content

Commit fd928ee

Browse files
committed
BASEURI file can now contain Json to specify the base URI for multiple branches
1 parent c619862 commit fd928ee

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ Create a linked data site serving RDF data from files in a GitHub repository. Fo
44

55
## How to use it?
66

7-
- Add a BASEURI file to the root of your repo with the base URI of your data
7+
- Add a BASEURI file to the root of your repo with the base URI of your data (see below)
88
- Start an instance of PSPS
99
- Add a webhook in Github notifying `http(s)://<your-host>/webhook` with the set webhook secret (see below)
1010
- Add RDF data to your repository
1111
- To customize the (client-side) rendering of the resource add a `renderes.ttl`file to the root of your repository. See the [RDF2h-Documentation](https://rdf2h.github.io/rdf2h-documentation/) to learn how the rendering works
1212

13+
### Specifying base URI
14+
15+
The file BASEURI in the root of the repository can either directly contain the base URI for the branch containg the file or a JSON object with branch names as keys and base URIs as values.
16+
Having such a JSON is handy as it allows to have staging branches with proposed modifications differing from the main branch only in the proposed change and not also in the BASEURI file.
17+
18+
1319
## Building
1420

1521
docker-compose build

src/main/java/com/factsmission/psps/RepositoryProcessor.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,26 @@ private void processTree(String treeURLString) throws IOException, ParseExceptio
172172
IRI constructFileBaseIRI(String path) {
173173
return new IRI(baseIRI.getUnicodeString() + path);
174174
}
175+
176+
private IRI getBaseIRI(URL baseUrlFile) throws IOException, ParseException {
177+
if (baseUrlFile != null) {
178+
try ( InputStream baseUrlStream = getAuthenticatedStream(baseUrlFile); BufferedReader stuffJsonReader = new BufferedReader(new InputStreamReader(baseUrlStream, "utf-8"))) {
179+
JSONParser jsonParser = new JSONParser();
180+
Object obj = jsonParser.parse(stuffJsonReader);
181+
JSONObject jsonObject = (JSONObject) obj;
182+
String contentBase64 = (String) jsonObject.get("content");
183+
String content = new String(Base64.getMimeDecoder().decode(contentBase64), "UTF-8");
184+
if (content.trim().charAt(0) == '{') {
185+
JSONObject contentObject = (JSONObject) jsonParser.parse(content);
186+
return new IRI((String) contentObject.get(branch));
187+
} else {
188+
return new IRI(content.trim());
189+
}
190+
}
191+
} else {
192+
return getDefaultBaseIRI();
193+
}
194+
}
175195

176196
}
177197

@@ -227,22 +247,6 @@ private void processRepository() throws IOException, ParseException {
227247
}
228248
}
229249

230-
231-
232-
private IRI getBaseIRI(URL baseUrlFile) throws IOException, ParseException {
233-
if (baseUrlFile != null) {
234-
try ( InputStream baseUrlStream = getAuthenticatedStream(baseUrlFile); BufferedReader stuffJsonReader = new BufferedReader(new InputStreamReader(baseUrlStream, "utf-8"))) {
235-
JSONParser jsonParser = new JSONParser();
236-
Object obj = jsonParser.parse(stuffJsonReader);
237-
JSONObject jsonObject = (JSONObject) obj;
238-
String contentBase64 = (String) jsonObject.get("content");
239-
String content = new String(Base64.getMimeDecoder().decode(contentBase64));
240-
return new IRI(content.trim());
241-
}
242-
} else {
243-
return getDefaultBaseIRI();
244-
}
245-
}
246250

247251
private IRI getDefaultBaseIRI() {
248252
return new IRI("https://raw.githubusercontent.com/" + repository + "/master/");

0 commit comments

Comments
 (0)