Skip to content

Commit

Permalink
Merge branch 'EMC-47-fuseki-tech-debt' into 'develop'
Browse files Browse the repository at this point in the history
Improve FusekiExportService

See merge request eip/catalogue!545
  • Loading branch information
joncooper65 committed Oct 17, 2023
2 parents fd24087 + 5ce632f commit 306b791
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,23 @@ private String getBigTtl() {
List<String> recordsTtl = getRecordsTtl(ids);

String bigTtl = catalogueTtl.concat(String.join("\n", recordsTtl));
log.debug("Big turtle to send: ", bigTtl);
log.debug("Big turtle to send: {}", bigTtl);
return bigTtl;
}

private List<String> getRequiredIds(){
List<String> ids = listing.getPublicDocumentsOfCatalogue(catalogueId);
return ids.stream()
.map(this::getMetadataDocument)
.filter(this::isRequired)
.map(MetadataDocument::getId)
.collect(Collectors.toList());
try {
List<String> ids = listing.getPublicDocumentsOfCatalogue(catalogueId);

return ids.stream()
.map(this::getMetadataDocument)
.filter(this::isRequired)
.map(MetadataDocument::getId)
.collect(Collectors.toList());
} catch(NullPointerException e) {
// no git commits
return new ArrayList<>();
}
}

@SneakyThrows
Expand Down Expand Up @@ -139,13 +145,11 @@ private void post(String data){
String serverUrl = new StringBuilder().append(fusekiUrl).append("?graph=").append(graphName).toString();

try {
// PUT the data - this works if there's no graph and if there's an existing graph, in which case it's updated
HttpHeaders headers = withBasicAuth(fusekiUsername, fusekiPassword);
headers.add(HttpHeaders.CONTENT_TYPE, "text/turtle");

HttpEntity<String> request = new HttpEntity<>(data, headers);
ResponseEntity<String> response = restTemplate.postForEntity(serverUrl, request, String.class);
log.info("Status code: {}", response.getStatusCode());
log.info("Response {}", response);
restTemplate.put(serverUrl, request);
} catch (RestClientResponseException ex) {
log.error(
"Error communicating with supplied URL: (statusCode={}, status={}, headers={}, body={})",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void exportDocuments() throws DataRepositoryException {
// given
mockServer
.expect(requestTo(equalTo(FUSEKI_URL + "?graph=" + BASE_URI)))
.andExpect(method(HttpMethod.POST))
.andExpect(method(HttpMethod.PUT))
.andExpect(header(HttpHeaders.CONTENT_TYPE, "text/turtle"))
.andExpect(header(HttpHeaders.AUTHORIZATION, "Basic dXNlcm5hbWU6cGFzc3dvcmQ="))
.andRespond(withSuccess());
Expand Down
8 changes: 4 additions & 4 deletions templates/rdf/catalogue.ttl.ftlh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<#include "_prefixes.ftlh">
@prefix : <${baseUri}/> .
@prefix : <${baseUri}/id/> .
@base <${baseUri}/> .

<https://catalogue.ceh.ac.uk/${catalogue}/documents/> a dcat:Catalog ;
<${baseUri}/${catalogue}/documents/> a dcat:Catalog ;
dct:title "${title} digital asset register"@en ;
foaf:homepage <https://catalogue.ceh.ac.uk/${catalogue}/documents> ;
dcat:resource <#list records as record>:${record} <#sep>,</#sep></#list> ;
<#if records?has_content>dcat:resource <#list records as record>:${record} <#sep>,</#sep></#list> ;</#if>
.

<#if catalogue=="eidc" >
Expand All @@ -15,4 +15,4 @@
<https://ror.org/00pggkr55> a vcard:Organization ;
vcard:fn "UK Centre for Ecology & Hydrology" ;
.
</#if>
</#if>
5 changes: 3 additions & 2 deletions templates/rdf/ttl.ftlh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<#compress>
<#include "_macros.ftlh">

<#include "_prefixes.ftlh">
@prefix : <${uri}/> .
@base <${uri}/> .
@base <${uri?replace(id,"")?replace("id/","")}> .
@prefix : <${uri?replace(id,"")}> .

<#include "_body.ftlh">
</#compress>

0 comments on commit 306b791

Please sign in to comment.