@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!"); } }
public ResponseBuilder initialize(final Resource parent, final Resource child) { if (MISSING_RESOURCE.equals(parent)) { throw new NotFoundException(); } else if (DELETED_RESOURCE.equals(parent)) { throw new ClientErrorException(GONE); } else if (getExtensionGraphName() != null || ldpResourceTypes(parent.getInteractionModel()).noneMatch(LDP.Container::equals)) { throw new NotAllowedException(GET, Stream.of(HEAD, OPTIONS, PATCH, PUT, DELETE).toArray(String[]::new)); } else if (!MISSING_RESOURCE.equals(child) && !DELETED_RESOURCE.equals(child)) { throw new ClientErrorException(CONFLICT); } else if (!supportsInteractionModel(ldpType)) { throw new BadRequestException("Unsupported interaction model provided", status(BAD_REQUEST) .link(UnsupportedInteractionModel.getIRIString(), LDP.constrainedBy.getIRIString()).build()); } else if (ldpType.equals(LDP.NonRDFSource) && rdfSyntax != null) { LOGGER.error("Cannot save {} as a NonRDFSource with RDF syntax", getIdentifier()); throw new BadRequestException("Cannot save resource as a NonRDFSource with RDF syntax"); } setParent(parent); return status(CREATED); }
PostHandler extends MutatingLdpHandler { public ResponseBuilder initialize(final Resource parent, final Resource child) { if (MISSING_RESOURCE.equals(parent)) { throw new NotFoundException(); } else if (DELETED_RESOURCE.equals(parent)) { throw new ClientErrorException(GONE); } else if (getExtensionGraphName() != null || ldpResourceTypes(parent.getInteractionModel()).noneMatch(LDP.Container::equals)) { throw new NotAllowedException(GET, Stream.of(HEAD, OPTIONS, PATCH, PUT, DELETE).toArray(String[]::new)); } else if (!MISSING_RESOURCE.equals(child) && !DELETED_RESOURCE.equals(child)) { throw new ClientErrorException(CONFLICT); } else if (!supportsInteractionModel(ldpType)) { throw new BadRequestException("Unsupported interaction model provided", status(BAD_REQUEST) .link(UnsupportedInteractionModel.getIRIString(), LDP.constrainedBy.getIRIString()).build()); } else if (ldpType.equals(LDP.NonRDFSource) && rdfSyntax != null) { LOGGER.error("Cannot save {} as a NonRDFSource with RDF syntax", getIdentifier()); throw new BadRequestException("Cannot save resource as a NonRDFSource with RDF syntax"); } setParent(parent); return status(CREATED); } }
PostHandler extends MutatingLdpHandler { public ResponseBuilder initialize(final Resource parent, final Resource child) { if (MISSING_RESOURCE.equals(parent)) { throw new NotFoundException(); } else if (DELETED_RESOURCE.equals(parent)) { throw new ClientErrorException(GONE); } else if (getExtensionGraphName() != null || ldpResourceTypes(parent.getInteractionModel()).noneMatch(LDP.Container::equals)) { throw new NotAllowedException(GET, Stream.of(HEAD, OPTIONS, PATCH, PUT, DELETE).toArray(String[]::new)); } else if (!MISSING_RESOURCE.equals(child) && !DELETED_RESOURCE.equals(child)) { throw new ClientErrorException(CONFLICT); } else if (!supportsInteractionModel(ldpType)) { throw new BadRequestException("Unsupported interaction model provided", status(BAD_REQUEST) .link(UnsupportedInteractionModel.getIRIString(), LDP.constrainedBy.getIRIString()).build()); } else if (ldpType.equals(LDP.NonRDFSource) && rdfSyntax != null) { LOGGER.error("Cannot save {} as a NonRDFSource with RDF syntax", getIdentifier()); throw new BadRequestException("Cannot save resource as a NonRDFSource with RDF syntax"); } setParent(parent); return status(CREATED); } PostHandler(final TrellisRequest req, final IRI parentIdentifier, final String id, final InputStream entity,
            final ServiceBundler trellis, final Map<String, IRI> extensions, final String baseUrl); }
PostHandler extends MutatingLdpHandler { public ResponseBuilder initialize(final Resource parent, final Resource child) { if (MISSING_RESOURCE.equals(parent)) { throw new NotFoundException(); } else if (DELETED_RESOURCE.equals(parent)) { throw new ClientErrorException(GONE); } else if (getExtensionGraphName() != null || ldpResourceTypes(parent.getInteractionModel()).noneMatch(LDP.Container::equals)) { throw new NotAllowedException(GET, Stream.of(HEAD, OPTIONS, PATCH, PUT, DELETE).toArray(String[]::new)); } else if (!MISSING_RESOURCE.equals(child) && !DELETED_RESOURCE.equals(child)) { throw new ClientErrorException(CONFLICT); } else if (!supportsInteractionModel(ldpType)) { throw new BadRequestException("Unsupported interaction model provided", status(BAD_REQUEST) .link(UnsupportedInteractionModel.getIRIString(), LDP.constrainedBy.getIRIString()).build()); } else if (ldpType.equals(LDP.NonRDFSource) && rdfSyntax != null) { LOGGER.error("Cannot save {} as a NonRDFSource with RDF syntax", getIdentifier()); throw new BadRequestException("Cannot save resource as a NonRDFSource with RDF syntax"); } setParent(parent); return status(CREATED); } PostHandler(final TrellisRequest req, final IRI parentIdentifier, final String id, final InputStream entity,
            final ServiceBundler trellis, final Map<String, IRI> extensions, final String baseUrl); ResponseBuilder initialize(final Resource parent, final Resource child); CompletionStage<ResponseBuilder> createResource(final ResponseBuilder builder); }
PostHandler extends MutatingLdpHandler { public ResponseBuilder initialize(final Resource parent, final Resource child) { if (MISSING_RESOURCE.equals(parent)) { throw new NotFoundException(); } else if (DELETED_RESOURCE.equals(parent)) { throw new ClientErrorException(GONE); } else if (getExtensionGraphName() != null || ldpResourceTypes(parent.getInteractionModel()).noneMatch(LDP.Container::equals)) { throw new NotAllowedException(GET, Stream.of(HEAD, OPTIONS, PATCH, PUT, DELETE).toArray(String[]::new)); } else if (!MISSING_RESOURCE.equals(child) && !DELETED_RESOURCE.equals(child)) { throw new ClientErrorException(CONFLICT); } else if (!supportsInteractionModel(ldpType)) { throw new BadRequestException("Unsupported interaction model provided", status(BAD_REQUEST) .link(UnsupportedInteractionModel.getIRIString(), LDP.constrainedBy.getIRIString()).build()); } else if (ldpType.equals(LDP.NonRDFSource) && rdfSyntax != null) { LOGGER.error("Cannot save {} as a NonRDFSource with RDF syntax", getIdentifier()); throw new BadRequestException("Cannot save resource as a NonRDFSource with RDF syntax"); } setParent(parent); return status(CREATED); } PostHandler(final TrellisRequest req, final IRI parentIdentifier, final String id, final InputStream entity,
            final ServiceBundler trellis, final Map<String, IRI> extensions, final String baseUrl); ResponseBuilder initialize(final Resource parent, final Resource child); CompletionStage<ResponseBuilder> createResource(final ResponseBuilder builder);  }