use of org.jowidgets.cap.common.api.validation.IBeanValidationResult in project jo-client-platform by jo-source.
the class ServiceBeanValidationHelper method createUserQuestionString.
private static String createUserQuestionString(final List<IBeanValidationResult> validationWarnings) {
final Set<String> messages = new HashSet<String>();
final StringBuilder builder = new StringBuilder();
builder.append(THERE_ARE_VALIDATION_WARNINGS.get() + "\n\n");
for (final IBeanValidationResult validationWarning : validationWarnings) {
final String messageText = validationWarning.getValidationResult().getWorstFirst().getText();
if (!messages.contains(messageText)) {
builder.append(messageText + "\n");
messages.add(messageText);
}
}
builder.append("\n" + PROCEED_ANYWAY.get());
return builder.toString();
}
use of org.jowidgets.cap.common.api.validation.IBeanValidationResult 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();
}
}
}
use of org.jowidgets.cap.common.api.validation.IBeanValidationResult in project jo-client-platform by jo-source.
the class BeanExceptionConverterImpl method convertBeansValidationException.
private IBeanMessage convertBeansValidationException(final String shortMessage, final List<? extends IBeanProxy<?>> processedBeans, final int destinationBeanIndex, final IBeanProxy<?> destinationBean, final BeansValidationException exception) {
final Map<Object, IBeanValidationResult> validationResults = exception.getValidationResults();
final IBeanValidationResult validationResult;
if (KeyType.INDEX.equals(exception.getKeyType())) {
validationResult = validationResults.get(Integer.valueOf(destinationBeanIndex));
} else {
validationResult = validationResults.get(destinationBean.getId());
}
if (validationResult != null) {
return convertBeanValidationException(shortMessage, destinationBean, new BeanValidationException(destinationBean.getId(), validationResult));
} else {
return new BeanMessageImpl(BeanMessageType.WARNING, shortMessage, VALIDATION_OF_OTHER_DATASETS_FAILED.get(), exception);
}
}
use of org.jowidgets.cap.common.api.validation.IBeanValidationResult in project jo-client-platform by jo-source.
the class BeanProxyImpl method consolidateBeanValidationResult.
private Map<String, IBeanValidationResult> consolidateBeanValidationResult(final Map<String, IBeanValidationResult> currentResultMap, final ValueHolder<IBeanValidationResult> firstWorstIndependendResultHolder, final Collection<IBeanValidationResult> validationResults) {
for (final IBeanValidationResult result : validationResults) {
final String propertyName = result.getPropertyName();
if (propertyName != null) {
final IBeanValidationResult currentResult = currentResultMap.get(propertyName);
final IBeanValidationResult worseResult = getWorseResult(currentResult, result);
if (worseResult == result) {
currentResultMap.put(propertyName, result);
}
} else {
final IBeanValidationResult firstWorstIndependendResult = firstWorstIndependendResultHolder.get();
final IBeanValidationResult worseResult = getWorseResult(firstWorstIndependendResult, result);
if (worseResult == result) {
firstWorstIndependendResultHolder.set(result);
}
}
}
return currentResultMap;
}
use of org.jowidgets.cap.common.api.validation.IBeanValidationResult 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();
}
}
Aggregations