Search in sources :

Example 1 with TriplePropertyConverter

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());
        }
    });
}
Also used : ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) LinkTriple(nl.knaw.huygens.timbuctoo.rdf.LinkTriple) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) InvalidCollectionException(nl.knaw.huygens.timbuctoo.crud.InvalidCollectionException) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) IOException(java.io.IOException) TriplePropertyConverter(nl.knaw.huygens.timbuctoo.rdf.conversion.TriplePropertyConverter) URI(java.net.URI) GET(javax.ws.rs.GET)

Aggregations

IOException (java.io.IOException)1 URI (java.net.URI)1 GET (javax.ws.rs.GET)1 NotFoundException (nl.knaw.huygens.timbuctoo.core.NotFoundException)1 ReadEntity (nl.knaw.huygens.timbuctoo.core.dto.ReadEntity)1 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)1 InvalidCollectionException (nl.knaw.huygens.timbuctoo.crud.InvalidCollectionException)1 LinkTriple (nl.knaw.huygens.timbuctoo.rdf.LinkTriple)1 TriplePropertyConverter (nl.knaw.huygens.timbuctoo.rdf.conversion.TriplePropertyConverter)1