Search in sources :

Example 1 with ALLOW

use of javax.ws.rs.core.HttpHeaders.ALLOW in project trellis by trellis-ldp.

the class MementoResource method getTimeMapBuilder.

/**
 * Create a response builder for a TimeMap response.
 *
 * @param mementos the mementos
 * @param baseUrl the base URL
 * @param req the LDP request
 * @return a response builder object
 */
public ResponseBuilder getTimeMapBuilder(final SortedSet<Instant> mementos, final TrellisRequest req, final String baseUrl) {
    final List<MediaType> acceptableTypes = req.getAcceptableMediaTypes();
    final String identifier = HttpUtils.buildResourceUrl(req, baseUrl);
    final List<Link> allLinks = getMementoLinks(identifier, mementos).collect(toList());
    final ResponseBuilder builder = ok().link(identifier, ORIGINAL + " " + TIMEGATE);
    builder.links(getMementoHeaders(identifier, mementos).map(this::filterLinkParams).toArray(Link[]::new)).link(Resource.getIRIString(), TYPE).link(RDFSource.getIRIString(), TYPE).header(ALLOW, join(",", GET, HEAD, OPTIONS));
    final RDFSyntax syntax = getSyntax(trellis.getIOService(), acceptableTypes, APPLICATION_LINK_FORMAT);
    if (syntax != null) {
        final IRI profile = getProfile(acceptableTypes, syntax);
        final IRI jsonldProfile = profile != null ? profile : compacted;
        return builder.type(syntax.mediaType()).entity((StreamingOutput) out -> trellis.getIOService().write(trellis.getTimemapGenerator().asRdf(identifier, allLinks), out, syntax, baseUrl, jsonldProfile));
    }
    return builder.type(APPLICATION_LINK_FORMAT).entity(allLinks.stream().map(this::filterLinkParams).map(Link::toString).collect(joining(",\n")) + "\n");
}
Also used : Stream.empty(java.util.stream.Stream.empty) DATETIME(org.trellisldp.common.HttpConstants.DATETIME) HttpUtils.getProfile(org.trellisldp.http.impl.HttpUtils.getProfile) SortedSet(java.util.SortedSet) GET(javax.ws.rs.HttpMethod.GET) ServiceBundler(org.trellisldp.common.ServiceBundler) UriBuilder.fromUri(javax.ws.rs.core.UriBuilder.fromUri) Resource(org.trellisldp.vocabulary.LDP.Resource) ALLOW(javax.ws.rs.core.HttpHeaders.ALLOW) ORIGINAL(org.trellisldp.common.HttpConstants.ORIGINAL) Collections.singletonList(java.util.Collections.singletonList) TIMEMAP(org.trellisldp.common.HttpConstants.TIMEMAP) HttpUtils.getSyntax(org.trellisldp.http.impl.HttpUtils.getSyntax) MediaType(javax.ws.rs.core.MediaType) String.join(java.lang.String.join) FROM(org.trellisldp.common.HttpConstants.FROM) UNTIL(org.trellisldp.common.HttpConstants.UNTIL) RDFSource(org.trellisldp.vocabulary.LDP.RDFSource) Arrays.asList(java.util.Arrays.asList) OPTIONS(javax.ws.rs.HttpMethod.OPTIONS) Response.status(javax.ws.rs.core.Response.status) Stream.concat(java.util.stream.Stream.concat) TYPE(javax.ws.rs.core.Link.TYPE) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) JSONLD.compacted(org.trellisldp.vocabulary.JSONLD.compacted) SECONDS(java.time.temporal.ChronoUnit.SECONDS) TrellisRequest(org.trellisldp.common.TrellisRequest) ZonedDateTime.ofInstant(java.time.ZonedDateTime.ofInstant) Iterator(java.util.Iterator) Collections.emptyList(java.util.Collections.emptyList) Stream.of(java.util.stream.Stream.of) APPLICATION_LINK_FORMAT(org.trellisldp.common.HttpConstants.APPLICATION_LINK_FORMAT) StreamingOutput(javax.ws.rs.core.StreamingOutput) FOUND(javax.ws.rs.core.Response.Status.FOUND) Instant(java.time.Instant) Collectors.joining(java.util.stream.Collectors.joining) Collectors.toList(java.util.stream.Collectors.toList) HEAD(javax.ws.rs.HttpMethod.HEAD) List(java.util.List) IRI(org.apache.commons.rdf.api.IRI) TIMEGATE(org.trellisldp.common.HttpConstants.TIMEGATE) Stream(java.util.stream.Stream) RDFSyntax(org.apache.commons.rdf.api.RDFSyntax) Response.ok(javax.ws.rs.core.Response.ok) UTC(java.time.ZoneOffset.UTC) RFC_1123_DATE_TIME(java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME) Link(javax.ws.rs.core.Link) MEMENTO(org.trellisldp.common.HttpConstants.MEMENTO) IRI(org.apache.commons.rdf.api.IRI) MediaType(javax.ws.rs.core.MediaType) RDFSyntax(org.apache.commons.rdf.api.RDFSyntax) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Link(javax.ws.rs.core.Link)

Aggregations

String.join (java.lang.String.join)1 Instant (java.time.Instant)1 UTC (java.time.ZoneOffset.UTC)1 ZonedDateTime.ofInstant (java.time.ZonedDateTime.ofInstant)1 RFC_1123_DATE_TIME (java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME)1 SECONDS (java.time.temporal.ChronoUnit.SECONDS)1 Arrays.asList (java.util.Arrays.asList)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 SortedSet (java.util.SortedSet)1 Collectors.joining (java.util.stream.Collectors.joining)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 Stream.concat (java.util.stream.Stream.concat)1 Stream.empty (java.util.stream.Stream.empty)1 Stream.of (java.util.stream.Stream.of)1 GET (javax.ws.rs.HttpMethod.GET)1 HEAD (javax.ws.rs.HttpMethod.HEAD)1