Search in sources :

Example 1 with ValidationResult

use of org.openforis.idm.metamodel.validation.ValidationResult in project collect by openforis.

the class ValidationMessageBuilder method getValidationMessages.

public List<String> getValidationMessages(Attribute<?, ?> attribute, ValidationResults validationResults, Flag flag, Locale locale) {
    List<String> result = new ArrayList<String>();
    List<ValidationResult> items = flag == Flag.ERROR ? validationResults.getErrors() : validationResults.getWarnings();
    if (items != null) {
        for (ValidationResult validationResult : items) {
            String message = getValidationMessage(attribute, validationResult, locale);
            if (!result.contains(message)) {
                result.add(message);
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ValidationResult(org.openforis.idm.metamodel.validation.ValidationResult)

Example 2 with ValidationResult

use of org.openforis.idm.metamodel.validation.ValidationResult in project collect by openforis.

the class CollectRecordIntegrationTest method checkHasError.

private void checkHasError(CollectRecord record, int attributeId, Class<?> checkType) {
    ValidationResults validationResults = record.getValidationCache().getAttributeValidationResults(attributeId);
    List<ValidationResult> errors = validationResults.getErrors();
    for (ValidationResult validationResult : errors) {
        if (checkType.isAssignableFrom(validationResult.getValidator().getClass())) {
            return;
        }
    }
    Assert.fail("Error of class " + checkType + " not found in validation results");
}
Also used : ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) ValidationResult(org.openforis.idm.metamodel.validation.ValidationResult)

Example 3 with ValidationResult

use of org.openforis.idm.metamodel.validation.ValidationResult in project collect by openforis.

the class ValidationResultsProxy method extractValidationResultMessages.

private List<String> extractValidationResultMessages(List<ValidationResult> validationResultList) {
    List<String> result = new ArrayList<String>();
    ValidationMessageBuilder validationMessageBuilder = ValidationMessageBuilder.createInstance(context.getMessageSource());
    for (ValidationResult validationResult : validationResultList) {
        result.add(validationMessageBuilder.getValidationMessage(attribute, validationResult, context.getLocale()));
    }
    return result;
}
Also used : ValidationMessageBuilder(org.openforis.collect.model.validation.ValidationMessageBuilder) ArrayList(java.util.ArrayList) ValidationResult(org.openforis.idm.metamodel.validation.ValidationResult)

Example 4 with ValidationResult

use of org.openforis.idm.metamodel.validation.ValidationResult in project collect by openforis.

the class CollectRecordIntegrationTest method checkHasWarning.

private void checkHasWarning(CollectRecord record, int attributeId, Class<?> checkType) {
    ValidationResults validationResults = record.getValidationCache().getAttributeValidationResults(attributeId);
    List<ValidationResult> warnings = validationResults.getWarnings();
    for (ValidationResult validationResult : warnings) {
        if (checkType.isAssignableFrom(validationResult.getValidator().getClass())) {
            return;
        }
    }
    Assert.fail();
}
Also used : ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) ValidationResult(org.openforis.idm.metamodel.validation.ValidationResult)

Example 5 with ValidationResult

use of org.openforis.idm.metamodel.validation.ValidationResult in project collect by openforis.

the class RecordValidationReportGenerator method extractAttributeValidationResultItem.

protected List<RecordValidationReportItem> extractAttributeValidationResultItem(Locale locale, Integer attrId, ValidationResultFlag level, boolean includeConfirmedErrors) {
    List<RecordValidationReportItem> items = new ArrayList<RecordValidationReportItem>();
    Attribute<?, ?> attr = (Attribute<?, ?>) record.getNodeByInternalId(attrId);
    ValidationResults validationResults = validationCache.getAttributeValidationResults(attrId);
    List<ValidationResult> failed = validationResults.getFailed();
    if (CollectionUtils.isNotEmpty(failed)) {
        String path = getPath(attr);
        String prettyFormatPath = messageBuilder.getPrettyFormatPath(attr, locale);
        for (ValidationResult validationResult : failed) {
            ValidationResultFlag flag = validationResult.getFlag();
            if (isInLevel(flag, level) || flag == ValidationResultFlag.WARNING && includeConfirmedErrors && record.isErrorConfirmed(attr)) {
                String message = messageBuilder.getValidationMessage(attr, validationResult, locale);
                RecordValidationReportItem recordValidationItem = new RecordValidationReportItem(attrId, path, prettyFormatPath, flag, message);
                items.add(recordValidationItem);
            }
        }
    }
    return items;
}
Also used : ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag) ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) Attribute(org.openforis.idm.model.Attribute) ArrayList(java.util.ArrayList) ValidationResult(org.openforis.idm.metamodel.validation.ValidationResult)

Aggregations

ValidationResult (org.openforis.idm.metamodel.validation.ValidationResult)6 ValidationResults (org.openforis.idm.metamodel.validation.ValidationResults)4 ArrayList (java.util.ArrayList)3 ValidationResultFlag (org.openforis.idm.metamodel.validation.ValidationResultFlag)2 ValidationMessageBuilder (org.openforis.collect.model.validation.ValidationMessageBuilder)1 Attribute (org.openforis.idm.model.Attribute)1