All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.erigir.wrench.ape.exception.DataValidationException Maven / Gradle / Ivy

There is a newer version: 2.2.16+16
Show newest version
package com.erigir.wrench.ape.exception;

import com.erigir.wrench.ape.http.ApeException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.Map;
import java.util.TreeMap;

/**
 * Created by chrweiss on 6/28/14.
 */
@ApeException(
        httpStatusCode = 400,
        detailCode = 103,
        message = "There are invalid values in the data submitted",
        developerMessage = "Data does not pass schema validation - check json schema and details object",
        detailObjectPropertyName = "errorMap"
)
public class DataValidationException extends RuntimeException {
    private Map errorMap;

    public DataValidationException(BindingResult errors) {
        super();
        errorMap = toErrorMap(errors);
    }

    public DataValidationException(Map errorMap) {
        super();
        this.errorMap = errorMap;
    }

    private static Map toErrorMap(BindingResult errors) {
        TreeMap rval = new TreeMap<>();

        for (FieldError fe : errors.getFieldErrors()) {
            rval.put(fe.getField(), fe.getDefaultMessage());
        }

        return rval;
    }

    public Map getErrorMap() {
        return errorMap;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy