use of org.apache.commons.rdf.api.Graph in project trellis by trellis-ldp.
the class DBResourceService method storeResource.
private void storeResource(final Metadata metadata, final Dataset dataset, final Instant time, final OperationType opType) {
try {
jdbi.useTransaction(handle -> {
final int resourceId = updateResource(handle, metadata, dataset, time, opType == OperationType.DELETE);
updateDescription(handle, resourceId, dataset, batchSize);
updateAcl(handle, resourceId, dataset, batchSize);
updateExtra(handle, resourceId, metadata.getIdentifier(), dataset);
extensions.forEach((ext, graph) -> dataset.getGraph(graph).filter(g -> !"acl".equals(ext)).ifPresent(g -> updateExtension(handle, resourceId, ext, g)));
if (opType == OperationType.DELETE) {
// Verify that the container really is empty
final String query = "SELECT EXISTS(SELECT 1 FROM resource WHERE is_part_of = ?)";
if (Boolean.TRUE.equals(handle.select(query, metadata.getIdentifier().getIRIString()).map((rs, ctx) -> rs.getBoolean(1)).one())) {
throw new StorageConflictException("Cannot delete non-empty containers");
}
}
});
} catch (final TrellisRuntimeException ex) {
throw ex;
} catch (final Exception ex) {
throw new TrellisRuntimeException("Could not update data for " + metadata.getIdentifier(), ex);
}
}
use of org.apache.commons.rdf.api.Graph in project trellis by trellis-ldp.
the class JenaIOServiceTest method testUpdate.
@Test
void testUpdate() {
final Graph graph = rdf.createGraph();
getTriples().forEach(graph::add);
assertEquals(3L, graph.size(), "Incorrect graph size!");
service.update(graph, "DELETE WHERE { ?s <http://purl.org/dc/terms/title> ?o }", SPARQL_UPDATE, "test:info");
assertEquals(2L, graph.size(), "Incorrect graph size, post update!");
service.update(graph, "INSERT { " + "<> <http://purl.org/dc/terms/title> \"Other title\" } WHERE {}", SPARQL_UPDATE, "trellis:data/resource");
assertEquals(3L, graph.size(), "Incorrect graph size, after adding triple!");
service.update(graph, "DELETE WHERE { ?s ?p ?o };" + "INSERT { <> <http://purl.org/dc/terms/title> \"Other title\" } WHERE {}", SPARQL_UPDATE, "trellis:data/");
assertEquals(1L, graph.size(), "Incorrect graph size after removing triples!");
assertEquals("<trellis:data/>", graph.stream().findFirst().map(Triple::getSubject).map(RDFTerm::ntriplesString).get(), "Incorrect graph subject from updates!");
}
use of org.apache.commons.rdf.api.Graph in project trellis by trellis-ldp.
the class JenaIOServiceTest method testJsonLdFlattenedSerializer4.
@Test
void testJsonLdFlattenedSerializer4() throws UnsupportedEncodingException {
when(mockNamespaceService.getNamespaces()).thenReturn(namespaces);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
service.write(getTriples(), out, JSONLD, identifier, compacted, flattened);
final String output = out.toString("UTF-8");
final Graph graph = rdf.createGraph();
service.read(new ByteArrayInputStream(output.getBytes(UTF_8)), JSONLD, null).forEach(graph::add);
assertAll("Check flattened serialization", checkCompactSerialization(output, graph));
}
use of org.apache.commons.rdf.api.Graph in project trellis by trellis-ldp.
the class JenaIOServiceTest method testJsonLdFlattenedSerializer.
@Test
void testJsonLdFlattenedSerializer() throws UnsupportedEncodingException {
when(mockNamespaceService.getNamespaces()).thenReturn(namespaces);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
service.write(getTriples(), out, JSONLD, identifier, flattened);
final String output = out.toString("UTF-8");
final Graph graph = rdf.createGraph();
service.read(new ByteArrayInputStream(output.getBytes(UTF_8)), JSONLD, null).forEach(graph::add);
assertAll("Check flattened serialization", checkFlattenedSerialization(output, graph));
}
use of org.apache.commons.rdf.api.Graph in project trellis by trellis-ldp.
the class JenaIOServiceTest method testJsonLdDefaultSerializer.
@Test
void testJsonLdDefaultSerializer() throws UnsupportedEncodingException {
when(mockNamespaceService.getNamespaces()).thenReturn(namespaces);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
service3.write(getTriples(), out, JSONLD, identifier);
final String output = out.toString("UTF-8");
final Graph graph = rdf.createGraph();
service3.read(new ByteArrayInputStream(output.getBytes(UTF_8)), JSONLD, null).forEach(graph::add);
assertAll("Check compact serialization", checkCompactSerialization(output, graph));
}
Aggregations