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.BAD_REQUEST;
010import static org.fcrepo.http.commons.domain.RDFMediaType.TEXT_PLAIN_WITH_CHARSET;
011import static org.slf4j.LoggerFactory.getLogger;
012
013import org.fcrepo.kernel.api.exception.OutOfDomainSubjectException;
014
015import org.slf4j.Logger;
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 whikloj
026 * @since 2015-05-29
027 */
028@Provider
029public class OutOfDomainSubjectExceptionMapper extends ConstraintExceptionMapper<OutOfDomainSubjectException>
030    implements ExceptionDebugLogging {
031
032    private static final Logger LOGGER =
033            getLogger(OutOfDomainSubjectExceptionMapper.class);
034
035    @Context
036    private UriInfo uriInfo;
037
038    @Context
039    private ServletContext context;
040
041    @Override
042    public Response toResponse(final OutOfDomainSubjectException e) {
043
044        debugException(this, e, LOGGER);
045        final Link link = buildConstraintLink(e, context, uriInfo);
046        final String msg = e.getMessage();
047        return status(BAD_REQUEST).entity(msg).links(link).type(TEXT_PLAIN_WITH_CHARSET).build();
048    }
049
050}