001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006package org.fcrepo.http.commons.exceptionhandlers;
007
008import static javax.ws.rs.core.Response.status;
009import static javax.ws.rs.core.Response.Status.FORBIDDEN;
010import static org.fcrepo.http.commons.domain.RDFMediaType.TEXT_PLAIN_WITH_CHARSET;
011
012import org.fcrepo.kernel.api.exception.IncorrectTripleSubjectException;
013
014import org.slf4j.Logger;
015import org.slf4j.LoggerFactory;
016
017import javax.servlet.ServletContext;
018import javax.ws.rs.core.Context;
019import javax.ws.rs.core.Link;
020import javax.ws.rs.core.Response;
021import javax.ws.rs.core.UriInfo;
022import javax.ws.rs.ext.Provider;
023
024/**
025 * @author ajs6f
026 * @since 2015-07-15
027 */
028@Provider
029public class IncorrectTripleSubjectExceptionMapper extends ConstraintExceptionMapper<IncorrectTripleSubjectException>
030    implements ExceptionDebugLogging {
031
032    private static final Logger LOGGER = LoggerFactory
033            .getLogger(IncorrectTripleSubjectExceptionMapper.class);
034
035    @Context
036    private UriInfo uriInfo;
037
038    @Context
039    private ServletContext context;
040
041    @Override
042    public Response toResponse(final IncorrectTripleSubjectException e) {
043        debugException(this, e, LOGGER);
044        final Link link = buildConstraintLink(e, context, uriInfo);
045        final String msg = e.getMessage();
046        return status(FORBIDDEN).entity(msg).links(link).type(TEXT_PLAIN_WITH_CHARSET).build();
047    }
048}