// Path: src/main/java/info/interactivesystems/gamificationengine/api/ResponseSurrogate.java
// public class ResponseSurrogate<T> {
// 
// 	@SuppressWarnings("FieldCanBeLocal")
// 	// @JsonUnwrapped
// 	@JsonProperty
// 	final T content;
// 
// 	@JsonProperty
// 	final Response.Status contentResponseType;
// 
// 	@SuppressWarnings("FieldCanBeLocal")
// 	@JsonProperty
// 	final List<ErrorMessage> info;
// 
// 	private ResponseSurrogate(T content, Response.Status contentResponseType, Notification info) {
// 		this.content = content;
// 		this.contentResponseType = contentResponseType;
// 		this.info = info.getErrors();
// 	}
// 
// 	public static <T> Response of(Response.Status status, MediaType mediaType, T content, Response.Status contentType, Notification notification) {
// 		status = Optional.ofNullable(status).orElse(Response.Status.OK);
// 		mediaType = Optional.ofNullable(mediaType).orElse(MediaType.APPLICATION_JSON_TYPE);
// 
// 		notification = Optional.ofNullable(notification).orElse(new Notification());
// 
// 		if (content == null) {
// 			contentType = Response.Status.BAD_REQUEST;
// 		} else {
// 			contentType = Optional.ofNullable(contentType).orElse(Response.Status.OK);
// 		}
// 
// 		ResponseSurrogate<T> surrogate = new ResponseSurrogate<>(content, contentType, notification);
// 		return Response.status(status).type(mediaType).entity(surrogate).build();
// 	}
// 
// 	public static <T> Response of(T content) {
// 		return of(null, null, content, null, null);
// 	}
// 
// 	public static <T> Response of(T content, Notification notification) {
// 		return of(null, null, content, null, notification);
// 	}
// 
// 	public static <T> Response of(Response.Status status, T content, Notification notification) {
// 		return of(status, null, content, null, notification);
// 	}
// 
// 	public static <T> Response of(T content, MediaType mediaType) {
// 		return of(null, mediaType, content, null, null);
// 	}
// 
// 	public static <T> Response of(Response.Status status, T content, MediaType mediaType) {
// 		return of(status, mediaType, content, null, null);
// 	}
// 
// 	public static <T> Response created(T content) {
// 		return created(content, null);
// 	}
// 
// 	public static <T> Response created(T content, Notification notification) {
// 		return of(Response.Status.CREATED, null, content, null, notification);
// 	}
// 
// 	public static <T> Response updated(T content) {
// 		return updated(content, null);
// 	}
// 
// 	public static <T> Response updated(T content, Notification notification) {
// 		return of(Response.Status.OK, null, content, null, notification);
// 	}
// 
// 	public static <T> Response deleted(T content) {
// 		return deleted(content, null);
// 	}
// 
// 	public static <T> Response deleted(T content, Notification notification) {
// 		return of(Response.Status.OK, null, content, null, notification);
// 	}
// 
// }


import info.interactivesystems.gamificationengine.api.ResponseSurrogate;
import java.util.List;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.jboss.resteasy.api.validation.ResteasyConstraintViolation;
import org.jboss.resteasy.api.validation.ResteasyViolationException;
package info.interactivesystems.gamificationengine.api.exeption;





@Provider
public class ResteasyViolationExceptionMapper implements ExceptionMapper<ResteasyViolationException> {

	@Override
	public Response toResponse(ResteasyViolationException ex) {
		Response.Status status = Response.Status.PRECONDITION_FAILED;
		List<ResteasyConstraintViolation> constraintViolations = ex.getViolations();

		if (ex.getException() != null) {
			// There are some exceptions during validation
			throw new RuntimeException(ex.getException());
		}
		Notification notification = new Notification();
		constraintViolations.forEach(c -> notification.addError(c.getValue() + ": " + c.getMessage()));

// Path: src/main/java/info/interactivesystems/gamificationengine/api/ResponseSurrogate.java
// public class ResponseSurrogate<T> {
// 
// 	@SuppressWarnings("FieldCanBeLocal")
// 	// @JsonUnwrapped
// 	@JsonProperty
// 	final T content;
// 
// 	@JsonProperty
// 	final Response.Status contentResponseType;
// 
// 	@SuppressWarnings("FieldCanBeLocal")
// 	@JsonProperty
// 	final List<ErrorMessage> info;
// 
// 	private ResponseSurrogate(T content, Response.Status contentResponseType, Notification info) {
// 		this.content = content;
// 		this.contentResponseType = contentResponseType;
// 		this.info = info.getErrors();
// 	}
// 
// 	public static <T> Response of(Response.Status status, MediaType mediaType, T content, Response.Status contentType, Notification notification) {
// 		status = Optional.ofNullable(status).orElse(Response.Status.OK);
// 		mediaType = Optional.ofNullable(mediaType).orElse(MediaType.APPLICATION_JSON_TYPE);
// 
// 		notification = Optional.ofNullable(notification).orElse(new Notification());
// 
// 		if (content == null) {
// 			contentType = Response.Status.BAD_REQUEST;
// 		} else {
// 			contentType = Optional.ofNullable(contentType).orElse(Response.Status.OK);
// 		}
// 
// 		ResponseSurrogate<T> surrogate = new ResponseSurrogate<>(content, contentType, notification);
// 		return Response.status(status).type(mediaType).entity(surrogate).build();
// 	}
// 
// 	public static <T> Response of(T content) {
// 		return of(null, null, content, null, null);
// 	}
// 
// 	public static <T> Response of(T content, Notification notification) {
// 		return of(null, null, content, null, notification);
// 	}
// 
// 	public static <T> Response of(Response.Status status, T content, Notification notification) {
// 		return of(status, null, content, null, notification);
// 	}
// 
// 	public static <T> Response of(T content, MediaType mediaType) {
// 		return of(null, mediaType, content, null, null);
// 	}
// 
// 	public static <T> Response of(Response.Status status, T content, MediaType mediaType) {
// 		return of(status, mediaType, content, null, null);
// 	}
// 
// 	public static <T> Response created(T content) {
// 		return created(content, null);
// 	}
// 
// 	public static <T> Response created(T content, Notification notification) {
// 		return of(Response.Status.CREATED, null, content, null, notification);
// 	}
// 
// 	public static <T> Response updated(T content) {
// 		return updated(content, null);
// 	}
// 
// 	public static <T> Response updated(T content, Notification notification) {
// 		return of(Response.Status.OK, null, content, null, notification);
// 	}
// 
// 	public static <T> Response deleted(T content) {
// 		return deleted(content, null);
// 	}
// 
// 	public static <T> Response deleted(T content, Notification notification) {
// 		return of(Response.Status.OK, null, content, null, notification);
// 	}
// 
// }


// Path: src/main/java/info/interactivesystems/gamificationengine/api/exeption/ResteasyViolationExceptionMapper.java
import info.interactivesystems.gamificationengine.api.ResponseSurrogate;
import java.util.List;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.jboss.resteasy.api.validation.ResteasyConstraintViolation;
import org.jboss.resteasy.api.validation.ResteasyViolationException;

package info.interactivesystems.gamificationengine.api.exeption;





@Provider
public class ResteasyViolationExceptionMapper implements ExceptionMapper<ResteasyViolationException> {

	@Override
	public Response toResponse(ResteasyViolationException ex) {
		Response.Status status = Response.Status.PRECONDITION_FAILED;
		List<ResteasyConstraintViolation> constraintViolations = ex.getViolations();

		if (ex.getException() != null) {
			// There are some exceptions during validation
			throw new RuntimeException(ex.getException());
		}
		Notification notification = new Notification();
		constraintViolations.forEach(c -> notification.addError(c.getValue() + ": " + c.getMessage()));

		return ResponseSurrogate.of(status, null, notification);