use of org.apache.commons.rdf.api.Dataset in project trellis by trellis-ldp.
the class TrellisWebDAV method moveResource.
/**
* Move a resource.
* @return the async response
*/
@MOVE
@Timed
public CompletionStage<Response> moveResource() {
final TrellisRequest req = new TrellisRequest(request, uriInfo, headers, security);
final String baseUrl = getBaseUrl(req);
final IRI identifier = rdf.createIRI(TRELLIS_DATA_PREFIX + req.getPath());
final IRI destination = getDestination(headers, baseUrl);
final Session session = HttpSession.from(security);
return getParent(destination).thenCombine(services.getResourceService().get(destination), this::checkResources).thenCompose(parent -> services.getResourceService().touch(parent.getIdentifier())).thenCompose(future -> services.getResourceService().get(identifier)).thenApply(this::checkResource).thenAccept(res -> recursiveCopy(services, session, res, destination, baseUrl)).thenRun(() -> recursiveDelete(services, session, identifier, baseUrl)).thenCompose(future -> services.getResourceService().delete(Metadata.builder(identifier).interactionModel(LDP.Resource).build())).thenCompose(future -> {
final Dataset immutable = rdf.createDataset();
services.getAuditService().creation(identifier, session).stream().map(skolemizeQuads(services.getResourceService(), baseUrl)).forEachOrdered(immutable::add);
return services.getResourceService().add(identifier, immutable).whenComplete((a, b) -> closeDataset(immutable));
}).thenRun(() -> services.getNotificationService().emit(new SimpleNotification(externalUrl(identifier, baseUrl), session.getAgent(), List.of(PROV.Activity, AS.Delete), List.of(LDP.Resource), null))).thenApply(future -> status(NO_CONTENT).build()).exceptionally(this::handleException);
}
use of org.apache.commons.rdf.api.Dataset in project trellis by trellis-ldp.
the class WebDAVUtils method recursiveDelete.
/**
* Recursively delete resources under the given identifier.
* @param services the trellis services
* @param session the session
* @param identifier the identifier
* @param baseUrl the baseURL
*/
public static void recursiveDelete(final ServiceBundler services, final Session session, final IRI identifier, final String baseUrl) {
final List<IRI> resources = services.getResourceService().get(identifier).thenApply(res -> res.stream(LDP.PreferContainment).map(Quad::getObject).filter(IRI.class::isInstance).map(IRI.class::cast).collect(toList())).toCompletableFuture().join();
resources.forEach(id -> recursiveDelete(services, session, id, baseUrl));
resources.stream().parallel().map(id -> {
final Dataset immutable = rdf.createDataset();
services.getAuditService().creation(id, session).stream().map(skolemizeQuads(services.getResourceService(), baseUrl)).forEachOrdered(immutable::add);
return services.getResourceService().delete(Metadata.builder(id).interactionModel(LDP.Resource).container(identifier).build()).thenCompose(future -> services.getResourceService().add(id, immutable)).whenComplete((a, b) -> closeDataset(immutable)).thenRun(() -> services.getNotificationService().emit(new SimpleNotification(externalUrl(id, baseUrl), session.getAgent(), List.of(PROV.Activity, AS.Delete), List.of(LDP.Resource), null)));
}).map(CompletionStage::toCompletableFuture).forEach(CompletableFuture::join);
}
use of org.apache.commons.rdf.api.Dataset in project trellis by trellis-ldp.
the class TriplestoreHealthCheckTest method testHealthy.
@Test
void testHealthy() {
final Dataset dataset = rdf.createDataset();
final RDFConnection rdfConnection = connect(wrap(toJena(dataset)));
final HealthCheck check = new TriplestoreHealthCheck(rdfConnection);
assertEquals(HealthCheckResponse.Status.UP, check.call().getStatus(), "RDFConnection isn't healthy!");
}
use of org.apache.commons.rdf.api.Dataset in project trellis by trellis-ldp.
the class TriplestoreHealthCheckTest method testUnhealthy.
@Test
void testUnhealthy() {
final Dataset dataset = rdf.createDataset();
final RDFConnection rdfConnection = connect(wrap(toJena(dataset)));
rdfConnection.close();
final HealthCheck check = new TriplestoreHealthCheck(rdfConnection);
assertEquals(HealthCheckResponse.Status.DOWN, check.call().getStatus(), "Closed RDFConnection doesn't report as unhealthy!");
}
use of org.apache.commons.rdf.api.Dataset in project trellis by trellis-ldp.
the class TriplestoreResourceServiceTest method testPutLdpNr.
@Test
void testPutLdpNr() {
final TriplestoreResourceService svc = new TriplestoreResourceService();
svc.rdfConnection = connect(wrap(toJena(rdf.createDataset())));
svc.idService = idService;
svc.initialize();
final IRI binaryIdentifier = rdf.createIRI("foo:binary");
final Dataset dataset = rdf.createDataset();
final BinaryMetadata binary = BinaryMetadata.builder(binaryIdentifier).mimeType("text/plain").build();
dataset.add(Trellis.PreferUserManaged, resource, DC.title, rdf.createLiteral("title"));
dataset.add(Trellis.PreferAudit, rdf.createBlankNode(), type, AS.Create);
final Instant later = meanwhile();
assertDoesNotThrow(() -> allOf(svc.create(builder(resource).interactionModel(LDP.NonRDFSource).container(root).binary(binary).build(), dataset).toCompletableFuture(), svc.touch(root).toCompletableFuture()).join(), "Unsuccessful create operation!");
allOf(svc.get(resource).thenAccept(checkResource(later, LDP.NonRDFSource, 1L, 1L, 0L)).toCompletableFuture(), svc.get(resource).thenAccept(res -> assertAll("Check binary", checkBinary(res, binaryIdentifier, "text/plain"))).toCompletableFuture(), svc.get(root).thenAccept(checkRoot(later, 1L)).toCompletableFuture()).join();
final IRI resource3 = rdf.createIRI(TRELLIS_DATA_PREFIX + "resource/notachild");
dataset.clear();
dataset.add(Trellis.PreferUserManaged, resource3, DC.title, rdf.createLiteral("title"));
dataset.add(Trellis.PreferAudit, rdf.createBlankNode(), type, AS.Create);
final Instant evenLater = meanwhile();
assertDoesNotThrow(() -> svc.create(builder(resource3).interactionModel(LDP.RDFSource).build(), dataset).toCompletableFuture().join(), "Unsuccessful create operation!");
allOf(svc.get(resource3).thenAccept(res -> {
assertAll("Check resource", checkResource(res, resource3, LDP.RDFSource, evenLater));
assertAll("Check resource stream", checkResourceStream(res, 1L, 0L, 1L, 0L, 0L));
assertFalse(res.getBinaryMetadata().isPresent(), "Unexpected binary metadata!");
}).toCompletableFuture(), svc.get(root).thenAccept(checkRoot(later, 1L)).toCompletableFuture(), svc.get(root).thenAccept(checkPredates(evenLater)).toCompletableFuture(), svc.get(root).thenAccept(res -> assertFalse(res.getBinaryMetadata().isPresent(), "unexpected binary metadata!")).toCompletableFuture(), svc.get(resource).thenAccept(checkResource(later, LDP.NonRDFSource, 1L, 1L, 0L)).toCompletableFuture(), svc.get(resource).thenAccept(checkPredates(evenLater)).toCompletableFuture()).join();
}
Aggregations