Search in sources :

Example 1 with IBeanValidationResult

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);
}
Also used : IBeanValidationResult(org.jowidgets.cap.common.api.validation.IBeanValidationResult) IValidationMessage(org.jowidgets.validation.IValidationMessage)

Example 2 with IBeanValidationResult

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();
        }
    }
}
Also used : IBeanValidationResult(org.jowidgets.cap.common.api.validation.IBeanValidationResult) IValidationResult(org.jowidgets.validation.IValidationResult)

Example 3 with IBeanValidationResult

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());
}
Also used : IBeanValidationResult(org.jowidgets.cap.common.api.validation.IBeanValidationResult) ValueHolder(org.jowidgets.util.ValueHolder) IExternalBeanValidator(org.jowidgets.cap.ui.api.bean.IExternalBeanValidator) IBeanValidationResultListBuilder(org.jowidgets.cap.common.api.validation.IBeanValidationResultListBuilder) LinkedList(java.util.LinkedList)

Example 4 with IBeanValidationResult

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;
}
Also used : IBeanValidationResult(org.jowidgets.cap.common.api.validation.IBeanValidationResult)

Example 5 with IBeanValidationResult

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;
    }
}
Also used : IBeanValidationResult(org.jowidgets.cap.common.api.validation.IBeanValidationResult) BeanValidationException(org.jowidgets.cap.common.api.exception.BeanValidationException)

Aggregations

IBeanValidationResult (org.jowidgets.cap.common.api.validation.IBeanValidationResult)12 LinkedList (java.util.LinkedList)3 BeanValidationException (org.jowidgets.cap.common.api.exception.BeanValidationException)2 IExternalBeanValidator (org.jowidgets.cap.ui.api.bean.IExternalBeanValidator)2 IValidationMessage (org.jowidgets.validation.IValidationMessage)2 IValidationResult (org.jowidgets.validation.IValidationResult)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 IValidationResultLabel (org.jowidgets.api.widgets.IValidationResultLabel)1 BeansValidationException (org.jowidgets.cap.common.api.exception.BeansValidationException)1 KeyType (org.jowidgets.cap.common.api.exception.BeansValidationException.KeyType)1 ServiceCanceledException (org.jowidgets.cap.common.api.exception.ServiceCanceledException)1 IBeanValidationResultListBuilder (org.jowidgets.cap.common.api.validation.IBeanValidationResultListBuilder)1 ValueHolder (org.jowidgets.util.ValueHolder)1 IObserverSet (org.jowidgets.util.collection.IObserverSet)1