use of org.apache.commons.rdf.api.Dataset in project trellis by trellis-ldp.
the class DBResourceTest method testDirectContainerInverse.
@Test
void testDirectContainerInverse() {
final IRI dc = rdf.createIRI(TRELLIS_DATA_PREFIX + idService.getSupplier().get());
final IRI child = rdf.createIRI(dc.getIRIString() + "/" + idService.getSupplier().get());
final IRI member = rdf.createIRI(TRELLIS_DATA_PREFIX + idService.getSupplier().get());
final Dataset dcDataset = rdf.createDataset();
dcDataset.add(Trellis.PreferUserManaged, dc, LDP.isMemberOfRelation, DC.isPartOf);
dcDataset.add(Trellis.PreferUserManaged, dc, LDP.membershipResource, member);
assertDoesNotThrow(() -> allOf(svc.create(builder(dc).interactionModel(LDP.DirectContainer).container(root).memberOfRelation(DC.isPartOf).membershipResource(member).build(), dcDataset).toCompletableFuture(), svc.create(builder(member).interactionModel(LDP.Container).container(root).build(), rdf.createDataset()).toCompletableFuture(), svc.create(builder(child).interactionModel(LDP.RDFSource).container(dc).build(), rdf.createDataset()).toCompletableFuture()).join());
svc.get(child).thenAccept(res -> {
assertEquals(1L, res.stream(LDP.PreferMembership).count());
assertEquals(of(rdf.createQuad(LDP.PreferMembership, child, DC.isPartOf, member)), res.stream(LDP.PreferMembership).findFirst());
}).toCompletableFuture().join();
}
use of org.apache.commons.rdf.api.Dataset in project trellis by trellis-ldp.
the class DBUtilsTest method testCloseDatasetError.
@Test
void testCloseDatasetError() throws Exception {
final Dataset mockDataset = mock(Dataset.class);
doThrow(IOException.class).when(mockDataset).close();
assertThrows(TrellisRuntimeException.class, () -> DBUtils.closeDataset(mockDataset));
}
use of org.apache.commons.rdf.api.Dataset 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.Dataset in project trellis by trellis-ldp.
the class DBResourceTest method testDirectContainer.
@Test
void testDirectContainer() {
final IRI member = rdf.createIRI(TRELLIS_DATA_PREFIX + idService.getSupplier().get());
final IRI dc = rdf.createIRI(TRELLIS_DATA_PREFIX + idService.getSupplier().get());
final IRI child = rdf.createIRI(dc.getIRIString() + "/" + idService.getSupplier().get());
final Dataset dcDataset = rdf.createDataset();
dcDataset.add(Trellis.PreferUserManaged, dc, LDP.hasMemberRelation, LDP.member);
dcDataset.add(Trellis.PreferUserManaged, dc, LDP.membershipResource, member);
assertDoesNotThrow(() -> allOf(svc.create(builder(dc).interactionModel(LDP.DirectContainer).container(root).memberRelation(LDP.member).membershipResource(member).build(), dcDataset).toCompletableFuture(), svc.create(builder(member).interactionModel(LDP.RDFSource).container(root).build(), rdf.createDataset()).toCompletableFuture(), svc.create(builder(child).interactionModel(LDP.RDFSource).container(dc).build(), rdf.createDataset()).toCompletableFuture()).join());
svc.get(member).thenAccept(res -> {
assertEquals(1L, res.stream(LDP.PreferMembership).count());
assertEquals(of(rdf.createQuad(LDP.PreferMembership, member, LDP.member, child)), res.stream(LDP.PreferMembership).findFirst());
}).toCompletableFuture().join();
}
use of org.apache.commons.rdf.api.Dataset in project trellis by trellis-ldp.
the class DBResourceTest method testAddErrorCondition.
@Test
void testAddErrorCondition() {
final IRI identifier = rdf.createIRI(TRELLIS_DATA_PREFIX + "resource");
final Dataset dataset = rdf.createDataset();
dataset.add(Trellis.PreferAudit, rdf.createBlankNode(), type, rdf.createLiteral("Invalid quad"));
final CompletableFuture<Void> future = svc.add(identifier, dataset).toCompletableFuture();
assertThrows(CompletionException.class, future::join);
}
Aggregations