Search in sources :

Example 1 with AS

use of org.trellisldp.vocabulary.AS 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 AS

use of org.trellisldp.vocabulary.AS in project trellis by trellis-ldp.

the class PutHandler method setResource.

/**
 * Store the resource to the persistence layer.
 * @param builder the response builder
 * @return the response builder
 */
public CompletionStage<ResponseBuilder> setResource(final ResponseBuilder builder) {
    LOGGER.debug("Setting resource as {}", getIdentifier());
    final IRI ldpType = getLdpType();
    // Verify that the persistence layer supports the given interaction model
    if (!supportsInteractionModel(ldpType)) {
        throw new BadRequestException("Unsupported interaction model provided", status(BAD_REQUEST).link(UnsupportedInteractionModel.getIRIString(), LDP.constrainedBy.getIRIString()).build());
    }
    // It is not possible to change the LDP type to a type that is not a subclass
    if (hasInteractionModelChangeRestriction(ldpType)) {
        LOGGER.error("Cannot change the LDP type to {} for {}", ldpType, getIdentifier());
        throw new ClientErrorException("Cannot change the LDP type to " + ldpType, status(CONFLICT).build());
    }
    LOGGER.debug("Using LDP Type: {}", ldpType);
    final Dataset mutable = rdf.createDataset();
    final Dataset immutable = rdf.createDataset();
    LOGGER.trace("Persisting {} with mutable data:\n{}\n and immutable data:\n{}", getIdentifier(), mutable, immutable);
    return handleResourceUpdate(mutable, immutable, builder, ldpType).whenComplete((a, b) -> closeDataset(mutable)).whenComplete((a, b) -> closeDataset(immutable));
}
Also used : ServiceBundler(org.trellisldp.common.ServiceBundler) TrellisUtils.getContainer(org.trellisldp.api.TrellisUtils.getContainer) HttpUtils.ldpResourceTypes(org.trellisldp.http.impl.HttpUtils.ldpResourceTypes) ClientErrorException(javax.ws.rs.ClientErrorException) Resource(org.trellisldp.api.Resource) CONFIG_HTTP_LDP_MODEL_MODIFICATIONS(org.trellisldp.common.HttpConstants.CONFIG_HTTP_LDP_MODEL_MODIFICATIONS) MediaType(javax.ws.rs.core.MediaType) AS(org.trellisldp.vocabulary.AS) Metadata(org.trellisldp.api.Metadata) APPLICATION_OCTET_STREAM(javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM) TURTLE(org.apache.commons.rdf.api.RDFSyntax.TURTLE) HttpUtils.checkRequiredPreconditions(org.trellisldp.http.impl.HttpUtils.checkRequiredPreconditions) Map(java.util.Map) Response.status(javax.ws.rs.core.Response.status) UnsupportedInteractionModel(org.trellisldp.vocabulary.Trellis.UnsupportedInteractionModel) BadRequestException(javax.ws.rs.BadRequestException) UriBuilder(javax.ws.rs.core.UriBuilder) LDP(org.trellisldp.vocabulary.LDP) HttpUtils.exists(org.trellisldp.http.impl.HttpUtils.exists) Dataset(org.apache.commons.rdf.api.Dataset) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) BAD_REQUEST(javax.ws.rs.core.Response.Status.BAD_REQUEST) BinaryMetadata(org.trellisldp.api.BinaryMetadata) TrellisRequest(org.trellisldp.common.TrellisRequest) NotAcceptableException(javax.ws.rs.NotAcceptableException) Logger(org.slf4j.Logger) CONFLICT(javax.ws.rs.core.Response.Status.CONFLICT) NO_CONTENT(javax.ws.rs.core.Response.Status.NO_CONTENT) ConfigProvider.getConfig(org.eclipse.microprofile.config.ConfigProvider.getConfig) HttpUtils.closeDataset(org.trellisldp.http.impl.HttpUtils.closeDataset) Instant(java.time.Instant) List(java.util.List) IRI(org.apache.commons.rdf.api.IRI) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) Quad(org.apache.commons.rdf.api.Quad) RDFSyntax(org.apache.commons.rdf.api.RDFSyntax) IF_MATCH(javax.ws.rs.core.HttpHeaders.IF_MATCH) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) IF_UNMODIFIED_SINCE(javax.ws.rs.core.HttpHeaders.IF_UNMODIFIED_SINCE) PreferUserManaged(org.trellisldp.vocabulary.Trellis.PreferUserManaged) CREATED(javax.ws.rs.core.Response.Status.CREATED) Link(javax.ws.rs.core.Link) InputStream(java.io.InputStream) IRI(org.apache.commons.rdf.api.IRI) Dataset(org.apache.commons.rdf.api.Dataset) HttpUtils.closeDataset(org.trellisldp.http.impl.HttpUtils.closeDataset) BadRequestException(javax.ws.rs.BadRequestException) ClientErrorException(javax.ws.rs.ClientErrorException)

Example 3 with AS

use of org.trellisldp.vocabulary.AS in project trellis by trellis-ldp.

the class PostHandler method createResource.

/**
 * Create a new resource.
 * @param builder the response builder
 * @return the response builder
 */
public CompletionStage<ResponseBuilder> createResource(final ResponseBuilder builder) {
    LOGGER.debug("Creating resource as {}", getIdentifier());
    final Dataset mutable = rdf.createDataset();
    final Dataset immutable = rdf.createDataset();
    return handleResourceCreation(mutable, immutable, builder).whenComplete((a, b) -> closeDataset(mutable)).whenComplete((a, b) -> closeDataset(immutable));
}
Also used : DELETE(javax.ws.rs.HttpMethod.DELETE) GET(javax.ws.rs.HttpMethod.GET) ServiceBundler(org.trellisldp.common.ServiceBundler) HttpUtils.ldpResourceTypes(org.trellisldp.http.impl.HttpUtils.ldpResourceTypes) NotAllowedException(javax.ws.rs.NotAllowedException) ClientErrorException(javax.ws.rs.ClientErrorException) Resource(org.trellisldp.api.Resource) MediaType(javax.ws.rs.core.MediaType) AS(org.trellisldp.vocabulary.AS) Metadata(org.trellisldp.api.Metadata) APPLICATION_OCTET_STREAM(javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM) GONE(javax.ws.rs.core.Response.Status.GONE) TURTLE(org.apache.commons.rdf.api.RDFSyntax.TURTLE) OPTIONS(javax.ws.rs.HttpMethod.OPTIONS) Map(java.util.Map) Response.status(javax.ws.rs.core.Response.status) UnsupportedInteractionModel(org.trellisldp.vocabulary.Trellis.UnsupportedInteractionModel) BadRequestException(javax.ws.rs.BadRequestException) UriBuilder(javax.ws.rs.core.UriBuilder) LDP(org.trellisldp.vocabulary.LDP) Dataset(org.apache.commons.rdf.api.Dataset) DELETED_RESOURCE(org.trellisldp.api.Resource.SpecialResources.DELETED_RESOURCE) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) BAD_REQUEST(javax.ws.rs.core.Response.Status.BAD_REQUEST) BinaryMetadata(org.trellisldp.api.BinaryMetadata) TrellisRequest(org.trellisldp.common.TrellisRequest) Logger(org.slf4j.Logger) CONFLICT(javax.ws.rs.core.Response.Status.CONFLICT) PATCH(javax.ws.rs.HttpMethod.PATCH) HttpUtils.closeDataset(org.trellisldp.http.impl.HttpUtils.closeDataset) NotFoundException(javax.ws.rs.NotFoundException) HEAD(javax.ws.rs.HttpMethod.HEAD) List(java.util.List) IRI(org.apache.commons.rdf.api.IRI) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) RDFSyntax(org.apache.commons.rdf.api.RDFSyntax) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) PUT(javax.ws.rs.HttpMethod.PUT) MISSING_RESOURCE(org.trellisldp.api.Resource.SpecialResources.MISSING_RESOURCE) PreferUserManaged(org.trellisldp.vocabulary.Trellis.PreferUserManaged) CREATED(javax.ws.rs.core.Response.Status.CREATED) Link(javax.ws.rs.core.Link) InputStream(java.io.InputStream) Dataset(org.apache.commons.rdf.api.Dataset) HttpUtils.closeDataset(org.trellisldp.http.impl.HttpUtils.closeDataset)

Aggregations

List (java.util.List)3 Map (java.util.Map)3 CompletionStage (java.util.concurrent.CompletionStage)3 Stream (java.util.stream.Stream)3 BadRequestException (javax.ws.rs.BadRequestException)3 ClientErrorException (javax.ws.rs.ClientErrorException)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 Logger (org.slf4j.Logger)3 LoggerFactory.getLogger (org.slf4j.LoggerFactory.getLogger)3 BinaryMetadata (org.trellisldp.api.BinaryMetadata)3 Metadata (org.trellisldp.api.Metadata)3 Resource (org.trellisldp.api.Resource)3 ServiceBundler (org.trellisldp.common.ServiceBundler)3 TrellisRequest (org.trellisldp.common.TrellisRequest)3 AS (org.trellisldp.vocabulary.AS)3 LDP (org.trellisldp.vocabulary.LDP)3 PreferUserManaged (org.trellisldp.vocabulary.Trellis.PreferUserManaged)3