use of org.jowidgets.cap.common.api.validation.IBeanValidationResult in project jo-client-platform by jo-source.
the class BeanExceptionConverterImpl method convertBeanValidationException.
private IBeanMessage convertBeanValidationException(final String shortMessage, final IBeanProxy<?> bean, final BeanValidationException exception) {
final IBeanValidationResult firstWorstBeanResult = exception.getValidationResult();
final String propertyName = firstWorstBeanResult.getPropertyName();
final Collection<String> propertyLabel = getPropertyLabels(bean, Collections.singleton(propertyName));
final String labels = StringUtils.concatElementsSeparatedBy(propertyLabel, ',');
final IValidationMessage worstFirst = firstWorstBeanResult.getValidationResult().getWorstFirst();
final String message = labels + " - " + worstFirst.getText();
return new BeanMessageImpl(BeanMessageType.WARNING, shortMessage, message, exception);
}
use of org.jowidgets.cap.common.api.validation.IBeanValidationResult in project jo-client-platform by jo-source.
the class BeanProxyImpl method setValidationResults.
private void setValidationResults(final ValueHolder<IBeanValidationResult> firstWorstIndependendResultHolder, final Collection<IBeanValidationResult> results) {
if (results.size() > 0) {
boolean validationChanged = false;
// set the property dependent results
for (final IBeanValidationResult result : results) {
final String propertyName = result.getPropertyName();
final IValidationResult validationResult = result.getValidationResult();
final IValidationResult lastResult = validationResults.get(propertyName);
if (lastResult == null || !validationResult.getWorstFirst().equals(lastResult.getWorstFirst())) {
if (validationResult.isOk()) {
validationResults.remove(propertyName);
} else {
validationResults.put(propertyName, validationResult);
}
validationChanged = true;
}
}
// set the property independent result
final IValidationResult lastIndependentResult = independentWorstResult.get();
final IBeanValidationResult currentIndependentBeanValidationResult = firstWorstIndependendResultHolder.get();
if (currentIndependentBeanValidationResult != null) {
final IValidationResult currentIndependentResult = currentIndependentBeanValidationResult.getValidationResult();
if (lastIndependentResult == null || !currentIndependentResult.getWorstFirst().equals(lastIndependentResult.getWorstFirst())) {
independentWorstResult.set(currentIndependentResult);
validationChanged = true;
}
} else if (lastIndependentResult != null) {
independentWorstResult.set(null);
validationChanged = true;
}
if (validationChanged) {
fireValidationConditionsChanged();
}
}
}
use of org.jowidgets.cap.common.api.validation.IBeanValidationResult in project jo-client-platform by jo-source.
the class BeanProxyImpl method validateProperties.
private void validateProperties(Collection<String> propertyNames) {
if (!isValidationNecessary()) {
clearValidationResults();
return;
}
propertyNames = getDependendProperties(propertyNames);
final IBeanValidationResultListBuilder builder = CapCommonToolkit.beanValidationResultListBuilder();
final ValueHolder<IBeanValidationResult> firstWorstIndependendResultHolder = new ValueHolder<IBeanValidationResult>();
for (final String propertyName : propertyNames) {
builder.addResult(validateProperty(propertyName));
}
Map<String, IBeanValidationResult> consolidatedResult;
consolidatedResult = consolidateBeanValidationResult(firstWorstIndependendResultHolder, builder.build());
// validate all results external
if (!consolidatedResult.isEmpty()) {
final List<IBeanValidationResult> externalResults = new LinkedList<IBeanValidationResult>();
for (final Entry<String, IBeanValidationResult> parentResultEntry : consolidatedResult.entrySet()) {
final String propertyName = parentResultEntry.getKey();
final IBeanValidationResult parentResult = parentResultEntry.getValue();
for (final IExternalBeanValidator externalValidator : getRegisteredExternalValidators(propertyName)) {
externalResults.addAll(externalValidator.validate(Collections.singletonList(parentResult)));
}
}
if (!externalResults.isEmpty()) {
consolidatedResult = consolidateBeanValidationResult(consolidatedResult, firstWorstIndependendResultHolder, externalResults);
}
}
setValidationResults(firstWorstIndependendResultHolder, consolidatedResult.values());
}
use of org.jowidgets.cap.common.api.validation.IBeanValidationResult in project jo-client-platform by jo-source.
the class BeanValidationResultUtil method getWorstFirst.
public static IBeanValidationResult getWorstFirst(final Collection<IBeanValidationResult> validationResults) {
Assert.paramNotNull(validationResults, "validationResults");
IBeanValidationResult worstFirst = null;
for (final IBeanValidationResult validationResult : validationResults) {
if (worstFirst == null || validationResult.getValidationResult().getWorstFirst().worse(worstFirst.getValidationResult().getWorstFirst())) {
worstFirst = validationResult;
}
}
return worstFirst;
}
use of org.jowidgets.cap.common.api.validation.IBeanValidationResult in project jo-client-platform by jo-source.
the class DefaultServiceExceptionLogger method logBeanValidationException.
protected boolean logBeanValidationException(final Class<?> serviceType, final Throwable original, final BeanException beanException) {
if (beanException instanceof BeanValidationException) {
if (logger.isInfoEnabled()) {
final BeanValidationException beanValidationException = (BeanValidationException) beanException;
final IBeanValidationResult validationResult = beanValidationException.getValidationResult();
if (validationResult != null && validationResult.getValidationResult() != null) {
logger.info("Bean validation failed: " + validationResult.getValidationResult().getAll() + " for bean: " + beanValidationException.getBeanId());
} else {
logger.info("Bean validation failed for bean: " + beanValidationException.getBeanId());
}
}
return true;
} else {
return false;
}
}
Aggregations