use of javax.ws.rs.core.Link.TYPE in project trellis by trellis-ldp.
the class PostHandlerTest method testUnsupportedType.
@Test
void testUnsupportedType() throws IOException {
when(mockResourceService.supportedInteractionModels()).thenReturn(emptySet());
when(mockTrellisRequest.getLink()).thenReturn(fromUri(LDP.Container.getIRIString()).rel(TYPE).build());
final PostHandler handler = buildPostHandler(RESOURCE_EMPTY, NEW_RESOURCE, null);
try (final Response res = assertThrows(BadRequestException.class, () -> handler.initialize(mockParent, MISSING_RESOURCE), "No exception thrown when the IXN model isn't supported!").getResponse()) {
assertEquals(BAD_REQUEST, res.getStatusInfo(), ERR_RESPONSE_CODE);
assertTrue(res.getLinks().stream().anyMatch(link -> link.getUri().toString().equals(UnsupportedInteractionModel.getIRIString()) && link.getRel().equals(LDP.constrainedBy.getIRIString())), "Missing constraint Link header!");
}
}
use of javax.ws.rs.core.Link.TYPE in project trellis by trellis-ldp.
the class PutHandlerTest method testUnsupportedType.
@Test
void testUnsupportedType() {
when(mockResourceService.supportedInteractionModels()).thenReturn(emptySet());
when(mockTrellisRequest.getContentType()).thenReturn(TEXT_TURTLE);
when(mockTrellisRequest.getLink()).thenReturn(fromUri(LDP.Resource.getIRIString()).rel(TYPE).build());
final PutHandler handler = buildPutHandler(RESOURCE_TURTLE, null);
final Response.ResponseBuilder builder = handler.initialize(mockParent, mockResource);
try (final Response res = assertThrows(BadRequestException.class, () -> handler.setResource(builder), "No exception when the interaction model isn't supported!").getResponse()) {
assertEquals(BAD_REQUEST, res.getStatusInfo(), ERR_RESPONSE_CODE);
assertTrue(res.getLinks().stream().anyMatch(link -> link.getUri().toString().equals(UnsupportedInteractionModel.getIRIString()) && link.getRel().equals(LDP.constrainedBy.getIRIString())), "Missing constraint header!");
}
}
use of javax.ws.rs.core.Link.TYPE in project trellis by trellis-ldp.
the class TrellisWebDAVRequestFilter method filter.
@Override
public void filter(final ContainerRequestContext ctx) {
final IRI identifier = services.getResourceService().getResourceIdentifier(getBaseUrl(baseUrl, ctx.getUriInfo()), ctx.getUriInfo().getPath());
if (PUT.equals(ctx.getMethod()) && createUncontained) {
final Resource res = services.getResourceService().get(identifier).toCompletableFuture().join();
final List<PathSegment> segments = ctx.getUriInfo().getPathSegments();
if ((MISSING_RESOURCE.equals(res) || DELETED_RESOURCE.equals(res)) && segments.stream().map(PathSegment::getPath).anyMatch(s -> !s.isEmpty())) {
ctx.setMethod(POST);
ctx.setRequestUri(ctx.getUriInfo().getBaseUriBuilder().path(getAllButLastSegment(segments)).build());
ctx.getHeaders().putSingle(SLUG, getLastSegment(segments));
}
} else if ("MKCOL".equals(ctx.getMethod())) {
// Note: MKCOL is just a POST with Link: <ldp:BasicContainer>; rel=type and appropriate Slug header
final List<PathSegment> segments = ctx.getUriInfo().getPathSegments();
final String slug = getLastSegment(segments);
if (slug.isEmpty()) {
// cannot POST a new root resource
ctx.abortWith(status(CONFLICT).build());
} else {
ctx.setRequestUri(ctx.getUriInfo().getBaseUriBuilder().path(getAllButLastSegment(segments)).build());
ctx.setMethod(POST);
ctx.getHeaders().putSingle(SLUG, getLastSegment(segments));
ctx.getHeaders().putSingle(LINK, Link.fromUri(LDP.BasicContainer.getIRIString()).rel(TYPE).build().toString());
}
} else if (DELETE.equals(ctx.getMethod())) {
recursiveDelete(services, HttpSession.from(ctx.getSecurityContext()), identifier, getBaseUrl(baseUrl, ctx.getUriInfo()));
}
}
use of javax.ws.rs.core.Link.TYPE 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");
}
Aggregations