Search in sources :

Example 1 with IExternalBeanValidator

use of org.jowidgets.cap.ui.api.bean.IExternalBeanValidator 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 2 with IExternalBeanValidator

use of org.jowidgets.cap.ui.api.bean.IExternalBeanValidator in project jo-client-platform by jo-source.

the class BeanProxyImpl method clearValidationResults.

private void clearValidationResults() {
    final boolean hasResults = independentWorstResult.get() != null || validationResults.size() > 0;
    if (hasResults) {
        if (independentWorstResult.get() != null) {
            for (final Entry<String, IObserverSet<IExternalBeanValidator>> entry : externalValidators.entrySet()) {
                final IBeanValidationResult okResult = BeanValidationResult.create(entry.getKey(), ValidationResult.ok());
                for (final IExternalBeanValidator externalValidator : entry.getValue()) {
                    externalValidator.validate(Collections.singletonList(okResult));
                }
            }
        } else {
            for (final String propertyName : validationResults.keySet()) {
                final IBeanValidationResult okResult = BeanValidationResult.create(propertyName, ValidationResult.ok());
                for (final IExternalBeanValidator externalValidator : getRegisteredExternalValidators(propertyName)) {
                    externalValidator.validate(Collections.singletonList(okResult));
                }
            }
        }
        independentWorstResult.set(null);
        validationResults.clear();
        fireValidationConditionsChanged();
    }
}
Also used : IObserverSet(org.jowidgets.util.collection.IObserverSet) IBeanValidationResult(org.jowidgets.cap.common.api.validation.IBeanValidationResult) IExternalBeanValidator(org.jowidgets.cap.ui.api.bean.IExternalBeanValidator)

Aggregations

IBeanValidationResult (org.jowidgets.cap.common.api.validation.IBeanValidationResult)2 IExternalBeanValidator (org.jowidgets.cap.ui.api.bean.IExternalBeanValidator)2 LinkedList (java.util.LinkedList)1 IBeanValidationResultListBuilder (org.jowidgets.cap.common.api.validation.IBeanValidationResultListBuilder)1 ValueHolder (org.jowidgets.util.ValueHolder)1 IObserverSet (org.jowidgets.util.collection.IObserverSet)1