use of nl.knaw.huygens.timbuctoo.rdf.conversion.TriplePropertyConverter in project timbuctoo by HuygensING.
the class SingleEntityNTriple method get.
@GET
public Response get(@PathParam("collection") String collectionName, @PathParam("id") UUIDParam id, @QueryParam("rev") Integer rev) {
return transactionEnforcer.executeAndReturn(timbuctooActions -> {
try {
Collection collection = timbuctooActions.getCollectionMetadata(collectionName);
ReadEntity entity = timbuctooActions.getEntity(collection, id.get(), rev);
URI rdfUri = entity.getRdfUri();
String rdfString = rdfUri == null ? uriHelper.fromResourceUri(makeUrl(collectionName, id.get())).toString() : rdfUri.toString();
StringBuilder sb = new StringBuilder();
addRdfProp(rdfString, sb, "id", entity.getId() + "", "https://www.ietf.org/rfc/rfc4122.txt");
entity.getRdfAlternatives().forEach(alt -> sb.append(asNtriples(new LinkTriple(rdfString, SAME_AS_PRED, alt))));
TriplePropertyConverter converter = new TriplePropertyConverter(collection, rdfString);
for (TimProperty<?> timProperty : entity.getProperties()) {
try {
timProperty.convert(converter).getRight().forEach(triple -> sb.append(asNtriples(triple)));
} catch (IOException e) {
LOG.error("Could not convert property with name '{}' and value '{}'", timProperty.getName(), timProperty.getValue());
}
}
entity.getRelations().forEach(rel -> sb.append(asNtriples(new LinkTriple(rdfString, getRelationRdfUri(rel), getEntityRdfUri(rel)))));
return commitAndReturn(Response.ok(sb.toString()).build());
} catch (InvalidCollectionException e) {
return commitAndReturn(Response.status(BAD_REQUEST).entity(e.getMessage()).build());
} catch (NotFoundException e) {
return commitAndReturn(Response.status(NOT_FOUND).build());
}
});
}
Aggregations