use of org.jowidgets.cap.common.api.exception.BeansValidationException in project jo-client-platform by jo-source.
the class DefaultServiceExceptionLogger method logBeansValidationException.
protected boolean logBeansValidationException(final Class<?> serviceType, final Throwable original, final ServiceException beanException) {
if (beanException instanceof BeansValidationException) {
if (logger.isInfoEnabled()) {
final BeansValidationException beanValidationException = (BeansValidationException) beanException;
logger.info("Bean validation failed: " + beanValidationException.getValidationResults());
}
return true;
} else {
return false;
}
}
use of org.jowidgets.cap.common.api.exception.BeansValidationException in project jo-client-platform by jo-source.
the class ServiceBeanValidationHelper method validate.
public static <BEAN_TYPE> void validate(final IBeanValidator<BEAN_TYPE> beanValidator, final boolean confirmValidationWarnings, final Collection<BEAN_TYPE> beans, final IBeanIdentityResolver<BEAN_TYPE> beanIdentityResolver, final IExecutionCallback executionCallback) {
final Map<Object, IBeanValidationResult> validationResultMap = new HashMap<Object, IBeanValidationResult>();
boolean hasError = false;
final List<IBeanValidationResult> validationWarnings = new LinkedList<IBeanValidationResult>();
int beanIndex = 0;
BeansValidationException.KeyType keyType = KeyType.ID;
for (final BEAN_TYPE bean : beans) {
CapServiceToolkit.checkCanceled(executionCallback);
final Object id = beanIdentityResolver.getId(bean);
final Collection<IBeanValidationResult> validationResults = beanValidator.validate(bean);
final IBeanValidationResult worstFirst = BeanValidationResultUtil.getWorstFirst(validationResults);
if (worstFirst != null) {
if (!worstFirst.getValidationResult().isValid()) {
hasError = true;
keyType = addResultsToMap(validationResultMap, id, beanIndex, keyType, worstFirst);
} else {
final IValidationMessage validationResult = worstFirst.getValidationResult().getWorstFirst();
if (MessageType.WARNING.equals(validationResult.getType())) {
validationWarnings.add(worstFirst);
keyType = addResultsToMap(validationResultMap, id, beanIndex, keyType, worstFirst);
}
}
}
beanIndex++;
}
if (hasError) {
throw new BeansValidationException(validationResultMap, keyType);
} else if (confirmValidationWarnings && validationWarnings.size() > 0) {
final String userQuestion = createUserQuestionString(validationWarnings);
if (UserQuestionResult.NO.equals(executionCallback.userQuestion(userQuestion))) {
throw new ServiceCanceledException();
}
}
}
Aggregations