Search in sources :

Example 1 with NO_CONTENT

use of javax.ws.rs.core.Response.Status.NO_CONTENT in project trellis by trellis-ldp.

the class TrellisWebDAV method copyResource.

/**
 * Copy a resource.
 * @return the async response
 */
@COPY
@Timed
public CompletionStage<Response> copyResource() {
    final TrellisRequest req = new TrellisRequest(request, uriInfo, headers, security);
    final Session session = HttpSession.from(security);
    final IRI destination = getDestination(headers, getBaseUrl(req));
    final IRI identifier = rdf.createIRI(TRELLIS_DATA_PREFIX + req.getPath());
    // Default is recursive copy as per RFC-4918
    final Depth.DEPTH depth = getDepth(headers.getHeaderString("Depth"));
    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).thenCompose(res -> copyTo(res, session, depth, destination, getBaseUrl(req))).thenApply(future -> status(NO_CONTENT).build()).exceptionally(this::handleException);
}
Also used : Produces(javax.ws.rs.Produces) WebDAVUtils.recursiveCopy(org.trellisldp.webdav.impl.WebDAVUtils.recursiveCopy) UriBuilder.fromUri(javax.ws.rs.core.UriBuilder.fromUri) SecurityContext(javax.ws.rs.core.SecurityContext) Resource(org.trellisldp.api.Resource) Document(org.w3c.dom.Document) Map(java.util.Map) Response.status(javax.ws.rs.core.Response.status) ACCESS_EXTERNAL_SCHEMA(javax.xml.XMLConstants.ACCESS_EXTERNAL_SCHEMA) DavPropertyUpdate(org.trellisldp.webdav.xml.DavPropertyUpdate) INFINITY(org.trellisldp.webdav.Depth.DEPTH.INFINITY) Set(java.util.Set) Literal(org.apache.commons.rdf.api.Literal) WebDAVUtils.depth1Copy(org.trellisldp.webdav.impl.WebDAVUtils.depth1Copy) SplitIRI.namespaceXML(org.apache.jena.util.SplitIRI.namespaceXML) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) TRELLIS_DATA_PREFIX(org.trellisldp.api.TrellisUtils.TRELLIS_DATA_PREFIX) WebApplicationException(javax.ws.rs.WebApplicationException) UriInfo(javax.ws.rs.core.UriInfo) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) WebDAVUtils.skolemizeQuads(org.trellisldp.webdav.impl.WebDAVUtils.skolemizeQuads) TrellisExtensions(org.trellisldp.common.TrellisExtensions) TrellisUtils.getContainer(org.trellisldp.api.TrellisUtils.getContainer) ArrayList(java.util.ArrayList) Metadata(org.trellisldp.api.Metadata) LdpResource(org.trellisldp.common.LdpResource) GONE(javax.ws.rs.core.Response.Status.GONE) DavPropFind(org.trellisldp.webdav.xml.DavPropFind) FEATURE_SECURE_PROCESSING(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING) LDP(org.trellisldp.vocabulary.LDP) Dataset(org.apache.commons.rdf.api.Dataset) DavProp(org.trellisldp.webdav.xml.DavProp) BinaryMetadata(org.trellisldp.api.BinaryMetadata) SECONDS(java.time.temporal.ChronoUnit.SECONDS) RDFFactory(org.trellisldp.api.RDFFactory) TrellisRequest(org.trellisldp.common.TrellisRequest) ZonedDateTime.ofInstant(java.time.ZonedDateTime.ofInstant) WebDAVUtils.externalUrl(org.trellisldp.webdav.impl.WebDAVUtils.externalUrl) NO_CONTENT(javax.ws.rs.core.Response.Status.NO_CONTENT) PROV(org.trellisldp.vocabulary.PROV) DavRemove(org.trellisldp.webdav.xml.DavRemove) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) RFC_1123_DATE_TIME(java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME) PreferUserManaged(org.trellisldp.vocabulary.Trellis.PreferUserManaged) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Path(javax.ws.rs.Path) ACCESS_EXTERNAL_DTD(javax.xml.XMLConstants.ACCESS_EXTERNAL_DTD) ClientErrorException(javax.ws.rs.ClientErrorException) APPLICATION_XML(javax.ws.rs.core.MediaType.APPLICATION_XML) Consumes(javax.ws.rs.Consumes) Timed(org.eclipse.microprofile.metrics.annotation.Timed) BadRequestException(javax.ws.rs.BadRequestException) Collectors.toSet(java.util.stream.Collectors.toSet) Context(javax.ws.rs.core.Context) WebDAVUtils.closeDataset(org.trellisldp.webdav.impl.WebDAVUtils.closeDataset) HttpConstants(org.trellisldp.common.HttpConstants) PermitAll(javax.annotation.security.PermitAll) WebDAVUtils.copy(org.trellisldp.webdav.impl.WebDAVUtils.copy) CONFLICT(javax.ws.rs.core.Response.Status.CONFLICT) SimpleNotification(org.trellisldp.common.SimpleNotification) DavResponse(org.trellisldp.webdav.xml.DavResponse) NotFoundException(javax.ws.rs.NotFoundException) Objects(java.util.Objects) List(java.util.List) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) DavMultiStatus(org.trellisldp.webdav.xml.DavMultiStatus) UTC(java.time.ZoneOffset.UTC) DAV_NAMESPACE(org.trellisldp.webdav.xml.DavUtils.DAV_NAMESPACE) PostConstruct(javax.annotation.PostConstruct) HttpSession(org.trellisldp.common.HttpSession) Optional(java.util.Optional) SpecialResources(org.trellisldp.api.Resource.SpecialResources) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Request(javax.ws.rs.core.Request) ServiceBundler(org.trellisldp.common.ServiceBundler) Session(org.trellisldp.api.Session) CompletableFuture(java.util.concurrent.CompletableFuture) PreferAccessControl(org.trellisldp.vocabulary.Trellis.PreferAccessControl) Function(java.util.function.Function) RDF(org.apache.commons.rdf.api.RDF) HashSet(java.util.HashSet) Inject(javax.inject.Inject) AS(org.trellisldp.vocabulary.AS) ZERO(org.trellisldp.webdav.Depth.DEPTH.ZERO) Node(org.w3c.dom.Node) Logger(org.slf4j.Logger) Collections.emptySet(java.util.Collections.emptySet) DavPropStat(org.trellisldp.webdav.xml.DavPropStat) Collectors.toList(java.util.stream.Collectors.toList) IRI(org.apache.commons.rdf.api.IRI) Quad(org.apache.commons.rdf.api.Quad) Element(org.w3c.dom.Element) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) DavSet(org.trellisldp.webdav.xml.DavSet) WebDAVUtils.recursiveDelete(org.trellisldp.webdav.impl.WebDAVUtils.recursiveDelete) SplitIRI.localnameXML(org.apache.jena.util.SplitIRI.localnameXML) ONE(org.trellisldp.webdav.Depth.DEPTH.ONE) IRI(org.apache.commons.rdf.api.IRI) TrellisRequest(org.trellisldp.common.TrellisRequest) HttpSession(org.trellisldp.common.HttpSession) Session(org.trellisldp.api.Session) Timed(org.eclipse.microprofile.metrics.annotation.Timed)

Example 2 with NO_CONTENT

use of javax.ws.rs.core.Response.Status.NO_CONTENT 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);
}
Also used : Produces(javax.ws.rs.Produces) WebDAVUtils.recursiveCopy(org.trellisldp.webdav.impl.WebDAVUtils.recursiveCopy) UriBuilder.fromUri(javax.ws.rs.core.UriBuilder.fromUri) SecurityContext(javax.ws.rs.core.SecurityContext) Resource(org.trellisldp.api.Resource) Document(org.w3c.dom.Document) Map(java.util.Map) Response.status(javax.ws.rs.core.Response.status) ACCESS_EXTERNAL_SCHEMA(javax.xml.XMLConstants.ACCESS_EXTERNAL_SCHEMA) DavPropertyUpdate(org.trellisldp.webdav.xml.DavPropertyUpdate) INFINITY(org.trellisldp.webdav.Depth.DEPTH.INFINITY) Set(java.util.Set) Literal(org.apache.commons.rdf.api.Literal) WebDAVUtils.depth1Copy(org.trellisldp.webdav.impl.WebDAVUtils.depth1Copy) SplitIRI.namespaceXML(org.apache.jena.util.SplitIRI.namespaceXML) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) TRELLIS_DATA_PREFIX(org.trellisldp.api.TrellisUtils.TRELLIS_DATA_PREFIX) WebApplicationException(javax.ws.rs.WebApplicationException) UriInfo(javax.ws.rs.core.UriInfo) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) WebDAVUtils.skolemizeQuads(org.trellisldp.webdav.impl.WebDAVUtils.skolemizeQuads) TrellisExtensions(org.trellisldp.common.TrellisExtensions) TrellisUtils.getContainer(org.trellisldp.api.TrellisUtils.getContainer) ArrayList(java.util.ArrayList) Metadata(org.trellisldp.api.Metadata) LdpResource(org.trellisldp.common.LdpResource) GONE(javax.ws.rs.core.Response.Status.GONE) DavPropFind(org.trellisldp.webdav.xml.DavPropFind) FEATURE_SECURE_PROCESSING(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING) LDP(org.trellisldp.vocabulary.LDP) Dataset(org.apache.commons.rdf.api.Dataset) DavProp(org.trellisldp.webdav.xml.DavProp) BinaryMetadata(org.trellisldp.api.BinaryMetadata) SECONDS(java.time.temporal.ChronoUnit.SECONDS) RDFFactory(org.trellisldp.api.RDFFactory) TrellisRequest(org.trellisldp.common.TrellisRequest) ZonedDateTime.ofInstant(java.time.ZonedDateTime.ofInstant) WebDAVUtils.externalUrl(org.trellisldp.webdav.impl.WebDAVUtils.externalUrl) NO_CONTENT(javax.ws.rs.core.Response.Status.NO_CONTENT) PROV(org.trellisldp.vocabulary.PROV) DavRemove(org.trellisldp.webdav.xml.DavRemove) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) RFC_1123_DATE_TIME(java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME) PreferUserManaged(org.trellisldp.vocabulary.Trellis.PreferUserManaged) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Path(javax.ws.rs.Path) ACCESS_EXTERNAL_DTD(javax.xml.XMLConstants.ACCESS_EXTERNAL_DTD) ClientErrorException(javax.ws.rs.ClientErrorException) APPLICATION_XML(javax.ws.rs.core.MediaType.APPLICATION_XML) Consumes(javax.ws.rs.Consumes) Timed(org.eclipse.microprofile.metrics.annotation.Timed) BadRequestException(javax.ws.rs.BadRequestException) Collectors.toSet(java.util.stream.Collectors.toSet) Context(javax.ws.rs.core.Context) WebDAVUtils.closeDataset(org.trellisldp.webdav.impl.WebDAVUtils.closeDataset) HttpConstants(org.trellisldp.common.HttpConstants) PermitAll(javax.annotation.security.PermitAll) WebDAVUtils.copy(org.trellisldp.webdav.impl.WebDAVUtils.copy) CONFLICT(javax.ws.rs.core.Response.Status.CONFLICT) SimpleNotification(org.trellisldp.common.SimpleNotification) DavResponse(org.trellisldp.webdav.xml.DavResponse) NotFoundException(javax.ws.rs.NotFoundException) Objects(java.util.Objects) List(java.util.List) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) DavMultiStatus(org.trellisldp.webdav.xml.DavMultiStatus) UTC(java.time.ZoneOffset.UTC) DAV_NAMESPACE(org.trellisldp.webdav.xml.DavUtils.DAV_NAMESPACE) PostConstruct(javax.annotation.PostConstruct) HttpSession(org.trellisldp.common.HttpSession) Optional(java.util.Optional) SpecialResources(org.trellisldp.api.Resource.SpecialResources) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Request(javax.ws.rs.core.Request) ServiceBundler(org.trellisldp.common.ServiceBundler) Session(org.trellisldp.api.Session) CompletableFuture(java.util.concurrent.CompletableFuture) PreferAccessControl(org.trellisldp.vocabulary.Trellis.PreferAccessControl) Function(java.util.function.Function) RDF(org.apache.commons.rdf.api.RDF) HashSet(java.util.HashSet) Inject(javax.inject.Inject) AS(org.trellisldp.vocabulary.AS) ZERO(org.trellisldp.webdav.Depth.DEPTH.ZERO) Node(org.w3c.dom.Node) Logger(org.slf4j.Logger) Collections.emptySet(java.util.Collections.emptySet) DavPropStat(org.trellisldp.webdav.xml.DavPropStat) Collectors.toList(java.util.stream.Collectors.toList) IRI(org.apache.commons.rdf.api.IRI) Quad(org.apache.commons.rdf.api.Quad) Element(org.w3c.dom.Element) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) DavSet(org.trellisldp.webdav.xml.DavSet) WebDAVUtils.recursiveDelete(org.trellisldp.webdav.impl.WebDAVUtils.recursiveDelete) SplitIRI.localnameXML(org.apache.jena.util.SplitIRI.localnameXML) ONE(org.trellisldp.webdav.Depth.DEPTH.ONE) IRI(org.apache.commons.rdf.api.IRI) TrellisRequest(org.trellisldp.common.TrellisRequest) Dataset(org.apache.commons.rdf.api.Dataset) WebDAVUtils.closeDataset(org.trellisldp.webdav.impl.WebDAVUtils.closeDataset) SimpleNotification(org.trellisldp.common.SimpleNotification) HttpSession(org.trellisldp.common.HttpSession) Session(org.trellisldp.api.Session) Timed(org.eclipse.microprofile.metrics.annotation.Timed)

Example 3 with NO_CONTENT

use of javax.ws.rs.core.Response.Status.NO_CONTENT in project trellis by trellis-ldp.

the class PatchHandler method assembleResponse.

private CompletionStage<ResponseBuilder> assembleResponse(final Dataset mutable, final Dataset immutable, final ResponseBuilder builder) {
    final IRI ext = getExtensionGraphName();
    final IRI graphName = ext != null ? ext : PreferUserManaged;
    // Put triples in buffer, short-circuit on exception
    final List<Triple> triples;
    try {
        triples = updateGraph(syntax, graphName);
    } catch (final TrellisRuntimeException ex) {
        throw new BadRequestException("Invalid RDF: " + ex.getMessage(), ex);
    }
    triples.stream().map(skolemizeTriples(getServices().getResourceService(), getBaseUrl())).map(triple -> rdf.createQuad(graphName, triple.getSubject(), triple.getPredicate(), triple.getObject())).forEachOrdered(mutable::add);
    // Check any constraints on the resulting dataset
    final List<ConstraintViolation> violations = new ArrayList<>();
    getServices().getConstraintServices().forEach(svc -> handleConstraintViolation(svc, getInternalId(), mutable, graphName, getLdpType()).forEach(violations::add));
    // Short-ciruit if there is a constraint violation
    if (!violations.isEmpty()) {
        final ResponseBuilder err = status(CONFLICT);
        violations.forEach(v -> err.link(v.getConstraint().getIRIString(), LDP.constrainedBy.getIRIString()));
        throw new ClientErrorException(err.entity((StreamingOutput) out -> getServices().getIOService().write(violations.stream().flatMap(v2 -> v2.getTriples().stream()), out, RDFSyntax.TURTLE, getIdentifier())).type(RDFSyntax.TURTLE.mediaType()).build());
    }
    // When updating one particular graph, be sure to add the other category to the dataset
    if (getResource() != null) {
        try (final Stream<Quad> remaining = getResource().stream(getNonCurrentGraphNames())) {
            remaining.forEachOrdered(mutable::add);
        }
    }
    // Collect the audit data
    getAuditQuadData().forEachOrdered(immutable::add);
    final Metadata metadata;
    if (getResource() == null) {
        metadata = metadataBuilder(getInternalId(), LDP.RDFSource, mutable).container(TrellisUtils.getContainer(getInternalId()).orElse(null)).build();
    } else {
        final Metadata.Builder mbuilder = metadataBuilder(getResource().getIdentifier(), getResource().getInteractionModel(), mutable);
        getResource().getContainer().ifPresent(mbuilder::container);
        getResource().getBinaryMetadata().ifPresent(mbuilder::binary);
        mbuilder.revision(getResource().getRevision());
        metadata = mbuilder.build();
    }
    return createOrReplace(metadata, mutable, immutable).thenCompose(future -> emitNotification(metadata.getIdentifier(), getResource() == null ? AS.Create : AS.Update, getLdpType(), metadata.getRevision().orElse(null))).thenApply(future -> {
        final RDFSyntax outputSyntax = getSyntax(getServices().getIOService(), getRequest().getAcceptableMediaTypes(), null);
        if (preference != null) {
            final IRI profile = getResponseProfile(outputSyntax);
            return builder.header(PREFERENCE_APPLIED, "return=representation").type(outputSyntax.mediaType()).entity((StreamingOutput) out -> getServices().getIOService().write(triples.stream().map(unskolemizeTriples(getServices().getResourceService(), getBaseUrl())), out, outputSyntax, getIdentifier(), profile));
        }
        return builder.status(getResource() == null ? CREATED : NO_CONTENT);
    });
}
Also used : HttpUtils.getProfile(org.trellisldp.http.impl.HttpUtils.getProfile) TrellisRuntimeException(org.trellisldp.api.TrellisRuntimeException) HttpUtils.getDefaultProfile(org.trellisldp.http.impl.HttpUtils.getDefaultProfile) ConstraintService(org.trellisldp.api.ConstraintService) HttpUtils.unskolemizeTriples(org.trellisldp.http.impl.HttpUtils.unskolemizeTriples) HttpUtils.ldpResourceTypes(org.trellisldp.http.impl.HttpUtils.ldpResourceTypes) NotAllowedException(javax.ws.rs.NotAllowedException) Prefer(org.trellisldp.common.Prefer) ClientErrorException(javax.ws.rs.ClientErrorException) Resource(org.trellisldp.api.Resource) HttpUtils.getSyntax(org.trellisldp.http.impl.HttpUtils.getSyntax) MediaType(javax.ws.rs.core.MediaType) Map(java.util.Map) Graph(org.apache.commons.rdf.api.Graph) Response.status(javax.ws.rs.core.Response.status) BadRequestException(javax.ws.rs.BadRequestException) HttpUtils.exists(org.trellisldp.http.impl.HttpUtils.exists) DELETED_RESOURCE(org.trellisldp.api.Resource.SpecialResources.DELETED_RESOURCE) BAD_REQUEST(javax.ws.rs.core.Response.Status.BAD_REQUEST) CONFLICT(javax.ws.rs.core.Response.Status.CONFLICT) StreamingOutput(javax.ws.rs.core.StreamingOutput) NotFoundException(javax.ws.rs.NotFoundException) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) Response.ok(javax.ws.rs.core.Response.ok) CREATED(javax.ws.rs.core.Response.Status.CREATED) Link(javax.ws.rs.core.Link) ServiceBundler(org.trellisldp.common.ServiceBundler) HttpMethod(javax.ws.rs.HttpMethod) HttpUtils.skolemizeTriples(org.trellisldp.http.impl.HttpUtils.skolemizeTriples) ArrayList(java.util.ArrayList) Triple(org.apache.commons.rdf.api.Triple) PREFERENCE_APPLIED(org.trellisldp.common.HttpConstants.PREFERENCE_APPLIED) ConstraintViolation(org.trellisldp.api.ConstraintViolation) RDF(org.trellisldp.vocabulary.RDF) AS(org.trellisldp.vocabulary.AS) Metadata(org.trellisldp.api.Metadata) GONE(javax.ws.rs.core.Response.Status.GONE) UnsupportedInteractionModel(org.trellisldp.vocabulary.Trellis.UnsupportedInteractionModel) LDP(org.trellisldp.vocabulary.LDP) Dataset(org.apache.commons.rdf.api.Dataset) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) NotSupportedException(javax.ws.rs.NotSupportedException) PREFER_REPRESENTATION(org.trellisldp.common.Prefer.PREFER_REPRESENTATION) TrellisRequest(org.trellisldp.common.TrellisRequest) Logger(org.slf4j.Logger) NO_CONTENT(javax.ws.rs.core.Response.Status.NO_CONTENT) TrellisUtils(org.trellisldp.api.TrellisUtils) HttpUtils.closeDataset(org.trellisldp.http.impl.HttpUtils.closeDataset) TEXT_PLAIN_TYPE(javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE) Collectors.toList(java.util.stream.Collectors.toList) IRI(org.apache.commons.rdf.api.IRI) Quad(org.apache.commons.rdf.api.Quad) RDFSyntax(org.apache.commons.rdf.api.RDFSyntax) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MISSING_RESOURCE(org.trellisldp.api.Resource.SpecialResources.MISSING_RESOURCE) PreferUserManaged(org.trellisldp.vocabulary.Trellis.PreferUserManaged) IRI(org.apache.commons.rdf.api.IRI) Quad(org.apache.commons.rdf.api.Quad) ArrayList(java.util.ArrayList) Metadata(org.trellisldp.api.Metadata) StreamingOutput(javax.ws.rs.core.StreamingOutput) Triple(org.apache.commons.rdf.api.Triple) TrellisRuntimeException(org.trellisldp.api.TrellisRuntimeException) ConstraintViolation(org.trellisldp.api.ConstraintViolation) BadRequestException(javax.ws.rs.BadRequestException) ClientErrorException(javax.ws.rs.ClientErrorException) RDFSyntax(org.apache.commons.rdf.api.RDFSyntax) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder)

Example 4 with NO_CONTENT

use of javax.ws.rs.core.Response.Status.NO_CONTENT in project trellis by trellis-ldp.

the class GetHandler method getLdpRs.

private ResponseBuilder getLdpRs(final ResponseBuilder builder, final RDFSyntax syntax, final IRI profile) {
    final Prefer prefer = getRequest().getPrefer();
    // Check for a cache hit
    if (!RDFSyntax.RDFA.equals(syntax)) {
        final EntityTag etag = generateEtag(getResource().getRevision(), weakEtags);
        checkCache(getResource().getModified(), etag);
        builder.tag(etag);
    }
    addAllowHeaders(builder);
    if (prefer != null) {
        builder.header(PREFERENCE_APPLIED, PREFER_RETURN + "=" + prefer.getPreference().orElse(PREFER_REPRESENTATION));
        if (prefer.getPreference().filter(PREFER_MINIMAL::equals).isPresent()) {
            return builder.status(NO_CONTENT);
        }
    }
    // Short circuit HEAD requests
    if (HEAD.equals(getRequest().getMethod())) {
        return builder;
    }
    // Stream the rdf content
    return builder.entity((StreamingOutput) out -> {
        try (final Stream<Quad> stream = getResource().stream(getPreferredGraphs(prefer))) {
            getServices().getIOService().write(stream.map(Quad::asTriple).map(unskolemizeTriples(getServices().getResourceService(), getBaseUrl())), out, syntax, getIdentifier(), getJsonLdProfile(profile, syntax));
        }
    });
}
Also used : DELETE(javax.ws.rs.HttpMethod.DELETE) HttpUtils.getProfile(org.trellisldp.http.impl.HttpUtils.getProfile) RedirectionException(javax.ws.rs.RedirectionException) HttpUtils.getDefaultProfile(org.trellisldp.http.impl.HttpUtils.getDefaultProfile) SortedSet(java.util.SortedSet) GET(javax.ws.rs.HttpMethod.GET) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ACCEPT_POST(org.trellisldp.common.HttpConstants.ACCEPT_POST) HttpUtils.unskolemizeTriples(org.trellisldp.http.impl.HttpUtils.unskolemizeTriples) WILDCARD(javax.ws.rs.core.MediaType.WILDCARD) ALLOW(javax.ws.rs.core.HttpHeaders.ALLOW) HttpUtils.ldpResourceTypes(org.trellisldp.http.impl.HttpUtils.ldpResourceTypes) Prefer(org.trellisldp.common.Prefer) ACCEPT_DATETIME(org.trellisldp.common.HttpConstants.ACCEPT_DATETIME) ClientErrorException(javax.ws.rs.ClientErrorException) Resource(org.trellisldp.api.Resource) HttpUtils.getSyntax(org.trellisldp.http.impl.HttpUtils.getSyntax) Collectors.toMap(java.util.stream.Collectors.toMap) APPLICATION_OCTET_STREAM(javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM) Map(java.util.Map) UriBuilder(javax.ws.rs.core.UriBuilder) DELETED_RESOURCE(org.trellisldp.api.Resource.SpecialResources.DELETED_RESOURCE) PREFER(org.trellisldp.common.HttpConstants.PREFER) RANGE(org.trellisldp.common.HttpConstants.RANGE) PATCH(javax.ws.rs.HttpMethod.PATCH) Set(java.util.Set) StreamingOutput(javax.ws.rs.core.StreamingOutput) HttpUtils.isContainer(org.trellisldp.http.impl.HttpUtils.isContainer) Instant(java.time.Instant) Collectors.joining(java.util.stream.Collectors.joining) NotFoundException(javax.ws.rs.NotFoundException) ACCEPT_RANGES(org.trellisldp.common.HttpConstants.ACCEPT_RANGES) VARY(javax.ws.rs.core.HttpHeaders.VARY) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) ORIGIN(org.trellisldp.common.HttpConstants.ORIGIN) POST(javax.ws.rs.HttpMethod.POST) Response.ok(javax.ws.rs.core.Response.ok) PUT(javax.ws.rs.HttpMethod.PUT) Link(javax.ws.rs.core.Link) PREFER_RETURN(org.trellisldp.common.Prefer.PREFER_RETURN) ServiceBundler(org.trellisldp.common.ServiceBundler) Binary(org.trellisldp.api.Binary) TrellisUtils.normalizePath(org.trellisldp.api.TrellisUtils.normalizePath) ArrayList(java.util.ArrayList) PREFERENCE_APPLIED(org.trellisldp.common.HttpConstants.PREFERENCE_APPLIED) MEMENTO_DATETIME(org.trellisldp.common.HttpConstants.MEMENTO_DATETIME) String.join(java.lang.String.join) PREFER_MINIMAL(org.trellisldp.common.Prefer.PREFER_MINIMAL) GONE(javax.ws.rs.core.Response.Status.GONE) Date.from(java.util.Date.from) OPTIONS(javax.ws.rs.HttpMethod.OPTIONS) ACCEPT_PATCH(org.trellisldp.common.HttpConstants.ACCEPT_PATCH) Stream.concat(java.util.stream.Stream.concat) LDP(org.trellisldp.vocabulary.LDP) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) PREFER_REPRESENTATION(org.trellisldp.common.Prefer.PREFER_REPRESENTATION) OutputStream(java.io.OutputStream) BinaryMetadata(org.trellisldp.api.BinaryMetadata) TrellisRequest(org.trellisldp.common.TrellisRequest) NotAcceptableException(javax.ws.rs.NotAcceptableException) Logger(org.slf4j.Logger) DESCRIPTION(org.trellisldp.common.HttpConstants.DESCRIPTION) Stream.of(java.util.stream.Stream.of) NO_CONTENT(javax.ws.rs.core.Response.Status.NO_CONTENT) IOException(java.io.IOException) EntityTag(javax.ws.rs.core.EntityTag) HEAD(javax.ws.rs.HttpMethod.HEAD) IRI(org.apache.commons.rdf.api.IRI) Quad(org.apache.commons.rdf.api.Quad) RDFSyntax(org.apache.commons.rdf.api.RDFSyntax) Version(org.trellisldp.common.Version) ACCEPT(javax.ws.rs.core.HttpHeaders.ACCEPT) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) HttpUtils.triplePreferences(org.trellisldp.http.impl.HttpUtils.triplePreferences) MISSING_RESOURCE(org.trellisldp.api.Resource.SpecialResources.MISSING_RESOURCE) InputStream(java.io.InputStream) Prefer(org.trellisldp.common.Prefer) EntityTag(javax.ws.rs.core.EntityTag) Stream(java.util.stream.Stream) OutputStream(java.io.OutputStream) InputStream(java.io.InputStream)

Aggregations

ArrayList (java.util.ArrayList)4 List (java.util.List)4 Map (java.util.Map)4 CompletionStage (java.util.concurrent.CompletionStage)4 Stream (java.util.stream.Stream)4 ClientErrorException (javax.ws.rs.ClientErrorException)4 NotFoundException (javax.ws.rs.NotFoundException)4 GONE (javax.ws.rs.core.Response.Status.GONE)4 NO_CONTENT (javax.ws.rs.core.Response.Status.NO_CONTENT)4 Set (java.util.Set)3 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)3 Collectors.toList (java.util.stream.Collectors.toList)3 BadRequestException (javax.ws.rs.BadRequestException)3 CONFLICT (javax.ws.rs.core.Response.Status.CONFLICT)3 Response.status (javax.ws.rs.core.Response.status)3 Dataset (org.apache.commons.rdf.api.Dataset)3 IRI (org.apache.commons.rdf.api.IRI)3 Quad (org.apache.commons.rdf.api.Quad)3 Logger (org.slf4j.Logger)3 LoggerFactory.getLogger (org.slf4j.LoggerFactory.getLogger)3