// Path: core/src/main/java/io/confluent/rest/entities/ErrorMessage.java
// public class ErrorMessage {
// 
//   private int errorCode;
//   private String message;
// 
//   public ErrorMessage(
//       @JsonProperty("error_code") int errorCode,
//       @JsonProperty("message") String message
//   ) {
//     this.errorCode = errorCode;
//     this.message = message;
//   }
// 
//   @JsonProperty("error_code")
//   public int getErrorCode() {
//     return errorCode;
//   }
// 
//   @JsonProperty("error_code")
//   public void setErrorCode(int errorCode) {
//     this.errorCode = errorCode;
//   }
// 
//   @JsonProperty
//   public String getMessage() {
//     return message;
//   }
// 
//   @JsonProperty
//   public void setMessage(String message) {
//     this.message = message;
//   }
// 
//   @Override
//   public boolean equals(Object o) {
//     if (this == o) {
//       return true;
//     }
//     if (o == null || getClass() != o.getClass()) {
//       return false;
//     }
//     ErrorMessage that = (ErrorMessage) o;
//     return errorCode == that.errorCode
//             && Objects.equals(message, that.message);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hash(errorCode, message);
//   }
// }
// 
// Path: core/src/main/java/io/confluent/rest/validation/ConstraintViolations.java
// public class ConstraintViolations {
// 
//   private ConstraintViolations() {
//     /* singleton */
//   }
// 
//   public static <T> String format(ConstraintViolation<T> v) {
//     return String.format("%s %s (was %s)",
//                          v.getPropertyPath(),
//                          v.getMessage(),
//                          v.getInvalidValue());
//   }
// 
//   public static String formatUntyped(Set<ConstraintViolation<?>> violations) {
//     StringBuilder builder = new StringBuilder();
//     boolean first = true;
//     for (ConstraintViolation<?> v : violations) {
//       if (!first) {
//         builder.append("; ");
//       }
//       builder.append(format(v));
//       first = false;
//     }
//     return builder.toString();
//   }
// 
//   public static ConstraintViolationException simpleException(String msg) {
//     return new ConstraintViolationException(msg, new HashSet<>());
//   }
// }


import javax.validation.ConstraintViolationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import io.confluent.rest.entities.ErrorMessage;
import io.confluent.rest.validation.ConstraintViolations;
/*
 * Copyright 2014 Confluent Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.confluent.rest.exceptions;



@Provider
public class ConstraintViolationExceptionMapper
    implements ExceptionMapper<ConstraintViolationException> {

  public static final int UNPROCESSABLE_ENTITY_CODE = 422;
  public static final Response.StatusType UNPROCESSABLE_ENTITY = new Response.StatusType() {
    @Override
    public int getStatusCode() {
      return UNPROCESSABLE_ENTITY_CODE;
    }

    @Override
    public Response.Status.Family getFamily() {
      return Response.Status.Family.CLIENT_ERROR;
    }

    @Override
    public String getReasonPhrase() {
      return "Unprocessable entity";
    }
  };

  @Override
  public Response toResponse(ConstraintViolationException exception) {
    final ErrorMessage message;
    if (exception instanceof RestConstraintViolationException) {
      RestConstraintViolationException restException = (RestConstraintViolationException)exception;
// Path: core/src/main/java/io/confluent/rest/entities/ErrorMessage.java
// public class ErrorMessage {
// 
//   private int errorCode;
//   private String message;
// 
//   public ErrorMessage(
//       @JsonProperty("error_code") int errorCode,
//       @JsonProperty("message") String message
//   ) {
//     this.errorCode = errorCode;
//     this.message = message;
//   }
// 
//   @JsonProperty("error_code")
//   public int getErrorCode() {
//     return errorCode;
//   }
// 
//   @JsonProperty("error_code")
//   public void setErrorCode(int errorCode) {
//     this.errorCode = errorCode;
//   }
// 
//   @JsonProperty
//   public String getMessage() {
//     return message;
//   }
// 
//   @JsonProperty
//   public void setMessage(String message) {
//     this.message = message;
//   }
// 
//   @Override
//   public boolean equals(Object o) {
//     if (this == o) {
//       return true;
//     }
//     if (o == null || getClass() != o.getClass()) {
//       return false;
//     }
//     ErrorMessage that = (ErrorMessage) o;
//     return errorCode == that.errorCode
//             && Objects.equals(message, that.message);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hash(errorCode, message);
//   }
// }
// 
// Path: core/src/main/java/io/confluent/rest/validation/ConstraintViolations.java
// public class ConstraintViolations {
// 
//   private ConstraintViolations() {
//     /* singleton */
//   }
// 
//   public static <T> String format(ConstraintViolation<T> v) {
//     return String.format("%s %s (was %s)",
//                          v.getPropertyPath(),
//                          v.getMessage(),
//                          v.getInvalidValue());
//   }
// 
//   public static String formatUntyped(Set<ConstraintViolation<?>> violations) {
//     StringBuilder builder = new StringBuilder();
//     boolean first = true;
//     for (ConstraintViolation<?> v : violations) {
//       if (!first) {
//         builder.append("; ");
//       }
//       builder.append(format(v));
//       first = false;
//     }
//     return builder.toString();
//   }
// 
//   public static ConstraintViolationException simpleException(String msg) {
//     return new ConstraintViolationException(msg, new HashSet<>());
//   }
// }


// Path: core/src/main/java/io/confluent/rest/exceptions/ConstraintViolationExceptionMapper.java
import javax.validation.ConstraintViolationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import io.confluent.rest.entities.ErrorMessage;
import io.confluent.rest.validation.ConstraintViolations;

/*
 * Copyright 2014 Confluent Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.confluent.rest.exceptions;



@Provider
public class ConstraintViolationExceptionMapper
    implements ExceptionMapper<ConstraintViolationException> {

  public static final int UNPROCESSABLE_ENTITY_CODE = 422;
  public static final Response.StatusType UNPROCESSABLE_ENTITY = new Response.StatusType() {
    @Override
    public int getStatusCode() {
      return UNPROCESSABLE_ENTITY_CODE;
    }

    @Override
    public Response.Status.Family getFamily() {
      return Response.Status.Family.CLIENT_ERROR;
    }

    @Override
    public String getReasonPhrase() {
      return "Unprocessable entity";
    }
  };

  @Override
  public Response toResponse(ConstraintViolationException exception) {
    final ErrorMessage message;
    if (exception instanceof RestConstraintViolationException) {
      RestConstraintViolationException restException = (RestConstraintViolationException)exception;
      message = new ErrorMessage(restException.getErrorCode(), restException.getMessage());