로깅 개선 및 EAI 배치 가상 연동 작업 완료
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package com.eactive.ext.kjb.utils;
|
||||
|
||||
import org.hibernate.validator.messageinterpolation.ParameterMessageInterpolator;
|
||||
|
||||
import javax.validation.*;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ValidationUtil {
|
||||
private static final ValidatorFactory factory;
|
||||
private static final Validator validator;
|
||||
|
||||
static {
|
||||
factory = Validation.byDefaultProvider()
|
||||
.configure()
|
||||
.messageInterpolator(new ParameterMessageInterpolator())
|
||||
.buildValidatorFactory();
|
||||
|
||||
validator = factory.getValidator();
|
||||
}
|
||||
|
||||
|
||||
private ValidationUtil() {
|
||||
}
|
||||
|
||||
|
||||
public static <T> Set<ConstraintViolation<T>> validate(T target) {
|
||||
return validator.validate(target);
|
||||
}
|
||||
|
||||
public static <T> void validateOrThrow(T target) {
|
||||
Set<ConstraintViolation<T>> violations = validate(target);
|
||||
if (!violations.isEmpty()) {
|
||||
String message = violations.stream()
|
||||
.map(v -> v.getPropertyPath() + " : " + v.getMessage())
|
||||
.collect(Collectors.joining(", "));
|
||||
throw new ConstraintViolationException("Validation failed: " + message, violations);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> String getViolationMessage(T target) {
|
||||
Set<ConstraintViolation<T>> violations = validate(target);
|
||||
if (violations.isEmpty()) return null;
|
||||
return violations.stream()
|
||||
.map(v -> v.getPropertyPath() + " : " + v.getMessage())
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user