Search in sources :

Example 1 with FieldContext

use of net.sf.oval.context.FieldContext in project littlefisher-system by littlefishercoder.

the class ValidationHandler method publishValidationMessage.

/**
 * 查找最根本的校验问题
 * @param violationList 校验
 * @param location 校验字段位置
 */
default void publishValidationMessage(List<ConstraintViolation> violationList, String location) {
    if (CollectionUtil.isNotEmpty(violationList)) {
        for (ConstraintViolation constraintViolation : violationList) {
            if (ArrayUtils.isNotEmpty(constraintViolation.getCauses())) {
                OValContext oValContext = constraintViolation.getContext();
                if (oValContext instanceof FieldContext) {
                    FieldContext fieldContext = (FieldContext) oValContext;
                    location += "." + fieldContext.getField().getName();
                } else if (oValContext instanceof ClassContext) {
                    ClassContext classContext = (ClassContext) oValContext;
                    location += "." + classContext.getClazz().getSimpleName();
                }
                publishValidationMessage(Lists.newArrayList(constraintViolation.getCauses()), location);
            } else {
                ExceptionHandler.publish("CORE-000009", null, location, constraintViolation.getMessage());
            }
        }
    }
}
Also used : ClassContext(net.sf.oval.context.ClassContext) OValContext(net.sf.oval.context.OValContext) ConstraintViolation(net.sf.oval.ConstraintViolation) FieldContext(net.sf.oval.context.FieldContext)

Example 2 with FieldContext

use of net.sf.oval.context.FieldContext in project littlefisher-system by littlefishercoder.

the class ValidationHandler method publishValidationMessage.

/**
 * 查找最根本的校验问题
 * @param violationList 校验
 * @param location 校验字段位置
 */
default void publishValidationMessage(List<ConstraintViolation> violationList, String location) {
    if (CollectionUtil.isNotEmpty(violationList)) {
        for (ConstraintViolation constraintViolation : violationList) {
            if (ArrayUtils.isNotEmpty(constraintViolation.getCauses())) {
                OValContext oValContext = constraintViolation.getContext();
                if (oValContext instanceof FieldContext) {
                    FieldContext fieldContext = (FieldContext) oValContext;
                    location += "." + fieldContext.getField().getName();
                } else if (oValContext instanceof ClassContext) {
                    ClassContext classContext = (ClassContext) oValContext;
                    location += "." + classContext.getClazz().getSimpleName();
                }
                publishValidationMessage(Lists.newArrayList(constraintViolation.getCauses()), location);
            } else {
                ExceptionHandler.publish("CORE-000009", null, location, constraintViolation.getMessage());
            }
        }
    }
}
Also used : ClassContext(net.sf.oval.context.ClassContext) OValContext(net.sf.oval.context.OValContext) ConstraintViolation(net.sf.oval.ConstraintViolation) FieldContext(net.sf.oval.context.FieldContext)

Aggregations

ConstraintViolation (net.sf.oval.ConstraintViolation)2 ClassContext (net.sf.oval.context.ClassContext)2 FieldContext (net.sf.oval.context.FieldContext)2 OValContext (net.sf.oval.context.OValContext)2