001/*
002 * Copyright (c) 2013 Maxim Yunusov
003 *    Licensed under the Apache License, Version 2.0 (the "License");
004 *    you may not use this file except in compliance with the License.
005 *    You may obtain a copy of the License at
006 *
007 *        http://www.apache.org/licenses/LICENSE-2.0
008 *
009 *    Unless required by applicable law or agreed to in writing, software
010 *    distributed under the License is distributed on an "AS IS" BASIS,
011 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 *    See the License for the specific language governing permissions and
013 *    limitations under the License.
014 */
015
016package org.maxur.perfmodel.backend.rest;
017
018import org.maxur.perfmodel.backend.domain.Incident;
019
020import javax.ws.rs.WebApplicationException;
021import javax.ws.rs.core.GenericEntity;
022import javax.ws.rs.core.Response;
023import java.util.List;
024
025import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
026import static javax.ws.rs.core.Response.Status.*;
027import static org.maxur.perfmodel.backend.domain.Incident.incidents;
028
029/**
030 * @author Maxim Yunusov
031 * @version 1.0 06.11.13
032 */
033public final class WebException extends WebApplicationException {
034
035    private static final long serialVersionUID = -2826609919565709334L;
036
037    private WebException(final Response.Status status, final String... messages) {
038        super(Response
039                .status(status)
040                .type(APPLICATION_JSON)
041                .entity(new GenericEntity<List<Incident>>(incidents(messages)) {
042                })
043                .build());
044    }
045
046    public static WebException notFoundException(final String... errors) {
047        return new WebException(NOT_FOUND, errors);
048    }
049
050    public static WebException badRequestException(final String... errors) {
051        return new WebException(BAD_REQUEST, errors);
052    }
053
054    public static WebException conflictException(final String... errors) {
055        return new WebException(CONFLICT, errors);
056    }
057
058
059}