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 org.fcrepo.kernel.api.exception.ConcurrentUpdateException;
009import org.slf4j.Logger;
010
011import javax.ws.rs.core.Response;
012import javax.ws.rs.ext.ExceptionMapper;
013import javax.ws.rs.ext.Provider;
014
015import static javax.ws.rs.core.Response.status;
016import static org.fcrepo.http.commons.domain.RDFMediaType.TEXT_PLAIN_WITH_CHARSET;
017import static org.slf4j.LoggerFactory.getLogger;
018
019/**
020 * @author pwinckles
021 */
022@Provider
023public class ConcurrentUpdateExceptionMapper implements
024        ExceptionMapper<ConcurrentUpdateException>, ExceptionDebugLogging {
025
026    private static final Logger LOGGER = getLogger(ConcurrentUpdateExceptionMapper.class);
027
028    @Override
029    public Response toResponse(final ConcurrentUpdateException e) {
030        debugException(this, e, LOGGER);
031        return status(Response.Status.CONFLICT).entity(e.getMessage()).type(TEXT_PLAIN_WITH_CHARSET).build();
032    }
033
034}