@Test void testGetLdprs() { when(mockTrellisRequest.getBaseUrl()).thenReturn("http: final GetConfiguration config = new GetConfiguration(false, true, true, null, null); final GetHandler handler = new GetHandler(mockTrellisRequest, mockBundler, extensions, config); try (final Response res = handler.getRepresentation(handler.standardHeaders(handler.initialize(mockResource))) .toCompletableFuture().join().build()) { assertEquals(OK, res.getStatusInfo(), ERR_RESPONSE_CODE); assertEquals(APPLICATION_SPARQL_UPDATE, res.getHeaderString(ACCEPT_PATCH), ERR_ACCEPT_PATCH); assertEquals(from(time), res.getLastModified(), ERR_LAST_MODIFIED); assertTrue(TEXT_TURTLE_TYPE.isCompatible(res.getMediaType()), ERR_CONTENT_TYPE); assertTrue(res.getMediaType().isCompatible(TEXT_TURTLE_TYPE), ERR_CONTENT_TYPE); assertNull(res.getHeaderString(PREFERENCE_APPLIED), ERR_PREFERENCE_APPLIED); assertNull(res.getHeaderString(ACCEPT_RANGES), ERR_ACCEPT_RANGES); assertNull(res.getHeaderString(ACCEPT_POST), ERR_ACCEPT_POST); assertAll(CHECK_LINK_TYPES, checkLdpType(res, LDP.RDFSource)); assertAll(CHECK_ALLOW, checkAllowHeader(res, asList(GET, HEAD, OPTIONS, PUT, DELETE, PATCH))); final EntityTag etag = res.getEntityTag(); assertTrue(etag.isWeak(), "ETag isn't weak for an RDF document!"); assertEquals(sha256Hex(mockResource.getRevision()), etag.getValue(), "Unexpected ETag value!"); final List<String> varies = getVaryHeaders(res); assertFalse(varies.contains(RANGE), ERR_VARY_RANGE); assertTrue(varies.contains(ACCEPT_DATETIME), ERR_VARY_ACCEPT_DATETIME); assertTrue(varies.contains(PREFER), ERR_VARY_PREFER); } }
private ResponseBuilder getLdpRs(final ResponseBuilder builder, final RDFSyntax syntax, final IRI profile) { final Prefer prefer = getRequest().getPrefer(); final EntityTag etag = generateEtag(getResource(), 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); } } if (HEAD.equals(getRequest().getMethod())) { return builder; } 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)); } }); }
GetHandler extends BaseLdpHandler { private ResponseBuilder getLdpRs(final ResponseBuilder builder, final RDFSyntax syntax, final IRI profile) { final Prefer prefer = getRequest().getPrefer(); final EntityTag etag = generateEtag(getResource(), 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); } } if (HEAD.equals(getRequest().getMethod())) { return builder; } 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)); } }); } }
GetHandler extends BaseLdpHandler { private ResponseBuilder getLdpRs(final ResponseBuilder builder, final RDFSyntax syntax, final IRI profile) { final Prefer prefer = getRequest().getPrefer(); final EntityTag etag = generateEtag(getResource(), 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); } } if (HEAD.equals(getRequest().getMethod())) { return builder; } 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)); } }); } GetHandler(final TrellisRequest req, final ServiceBundler trellis, final Map<String, IRI> extensions,
            final GetConfiguration config); }
GetHandler extends BaseLdpHandler { private ResponseBuilder getLdpRs(final ResponseBuilder builder, final RDFSyntax syntax, final IRI profile) { final Prefer prefer = getRequest().getPrefer(); final EntityTag etag = generateEtag(getResource(), 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); } } if (HEAD.equals(getRequest().getMethod())) { return builder; } 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)); } }); } GetHandler(final TrellisRequest req, final ServiceBundler trellis, final Map<String, IRI> extensions,
            final GetConfiguration config); ResponseBuilder initialize(final Resource resource); ResponseBuilder standardHeaders(final ResponseBuilder builder); CompletionStage<ResponseBuilder> getRepresentation(final ResponseBuilder builder); ResponseBuilder addMementoHeaders(final ResponseBuilder builder, final SortedSet<Instant> mementos); }
GetHandler extends BaseLdpHandler { private ResponseBuilder getLdpRs(final ResponseBuilder builder, final RDFSyntax syntax, final IRI profile) { final Prefer prefer = getRequest().getPrefer(); final EntityTag etag = generateEtag(getResource(), 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); } } if (HEAD.equals(getRequest().getMethod())) { return builder; } 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)); } }); } GetHandler(final TrellisRequest req, final ServiceBundler trellis, final Map<String, IRI> extensions,
            final GetConfiguration config); ResponseBuilder initialize(final Resource resource); ResponseBuilder standardHeaders(final ResponseBuilder builder); CompletionStage<ResponseBuilder> getRepresentation(final ResponseBuilder builder); ResponseBuilder addMementoHeaders(final ResponseBuilder builder, final SortedSet<Instant> mementos);  }