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