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.CONFLICT;
010import static org.fcrepo.http.commons.domain.RDFMediaType.TEXT_PLAIN_WITH_CHARSET;
011import static org.slf4j.LoggerFactory.getLogger;
012
013import javax.servlet.ServletContext;
014import javax.ws.rs.core.Context;
015import javax.ws.rs.core.Link;
016import javax.ws.rs.core.Response;
017import javax.ws.rs.core.UriInfo;
018import javax.ws.rs.ext.Provider;
019
020import org.fcrepo.kernel.api.exception.ServerManagedTypeException;
021
022import org.slf4j.Logger;
023
024/**
025 * @author whikloj
026 * @since 2015-06-02
027 */
028@Provider
029public class ServerManagedTypeExceptionMapper extends ConstraintExceptionMapper<ServerManagedTypeException>
030    implements ExceptionDebugLogging {
031
032    private static final Logger LOGGER =
033            getLogger(ServerManagedTypeExceptionMapper.class);
034
035    @Context
036    private UriInfo uriInfo;
037
038    @Context
039    private ServletContext context;
040
041    @Override
042    public Response toResponse(final ServerManagedTypeException e) {
043        debugException(this, e, LOGGER);
044        final Link link = buildConstraintLink(e, context, uriInfo);
045        final String msg = e.getMessage();
046        return status(CONFLICT).entity(msg).links(link).type(TEXT_PLAIN_WITH_CHARSET).build();
047    }
048}