Search in sources :

Example 6 with ValidationResults

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

the class DistanceCheckTest method testValidMaxDistance.

@Test
public void testValidMaxDistance() {
    String coordStr = "SRID=EPSG:21035;POINT(805750 9333820)";
    Coordinate coord = Coordinate.parseCoordinate(coordStr);
    EntityBuilder.addValue(cluster, "id", new Code("001"));
    CoordinateAttribute vehicleLocation = EntityBuilder.addValue(cluster, "vehicle_location", coord);
    ValidationResults results = validate(vehicleLocation);
    Assert.assertFalse(containsDistanceCheck(results.getErrors()));
}
Also used : ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) Coordinate(org.openforis.idm.model.Coordinate) CoordinateAttribute(org.openforis.idm.model.CoordinateAttribute) Code(org.openforis.idm.model.Code) Test(org.junit.Test)

Example 7 with ValidationResults

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

the class RecordUpdater method validateAttributes.

private void validateAttributes(Record record, Set<Attribute<?, ?>> attributes, NodeChangeMap changeMap) {
    Validator validator = record.getSurveyContext().getValidator();
    for (Attribute<?, ?> a : attributes) {
        ValidationResults validationResults;
        if (a.isRelevant()) {
            validationResults = validator.validate(a);
        } else {
            validationResults = new ValidationResults();
        }
        a.setValidationResults(validationResults);
        changeMap.addValidationResultChange(a, validationResults);
    }
}
Also used : ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) Validator(org.openforis.idm.metamodel.validation.Validator)

Example 8 with ValidationResults

use of org.openforis.idm.metamodel.validation.ValidationResults 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)

Example 9 with ValidationResults

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

the class CollectValidator method adjustErrorsForEntryPhase.

private ValidationResults adjustErrorsForEntryPhase(ValidationResults results, Attribute<?, ?> attribute) {
    boolean confirmed = isErrorConfirmed(attribute);
    ValidationResults phaseEntryResults = new ValidationResults();
    List<ValidationResult> errors = results.getErrors();
    for (ValidationResult error : errors) {
        ValidationResultFlag newFlag = confirmed ? ValidationResultFlag.WARNING : ValidationResultFlag.ERROR;
        phaseEntryResults.addResult(error.getValidator(), newFlag);
    }
    phaseEntryResults.addResults(results.getWarnings());
    return phaseEntryResults;
}
Also used : ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag) ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) ValidationResult(org.openforis.idm.metamodel.validation.ValidationResult)

Example 10 with ValidationResults

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

the class CollectValidator method validate.

@Override
public ValidationResults validate(Attribute<?, ?> attribute) {
    ValidationResults results = new ValidationResults();
    // skip validation for calculated attributes
    if (attribute.getDefinition().isCalculated()) {
        return results;
    }
    CollectRecord record = (CollectRecord) attribute.getRecord();
    // check if attribute has been specified
    boolean specifiedValid = validateSpecified ? validateSpecified(attribute, results) : true;
    if (specifiedValid) {
        Step step = record.getStep();
        // validate root entity keys
        if (isRootEntityKey(attribute)) {
            validateRootEntityKey(attribute, results);
        }
        /*
			 * if the attribute is not empty and 'reason blank' has not been specified than validate it
			 */
        if (!(attribute.isEmpty() || isReasonBlankAlwaysSpecified(attribute))) {
            validateAttributeValue(attribute, results);
            if (!results.hasErrors()) {
                validateAttributeChecks(attribute, results);
            }
        }
        if (step == Step.ENTRY) {
            results = adjustErrorsForEntryPhase(results, attribute);
        }
        record.updateAttributeValidationCache(attribute, results);
    } else {
        record.updateSkippedCount(attribute.getInternalId());
    }
    return results;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) Step(org.openforis.collect.model.CollectRecord.Step)

Aggregations

ValidationResults (org.openforis.idm.metamodel.validation.ValidationResults)10 Test (org.junit.Test)4 ValidationResult (org.openforis.idm.metamodel.validation.ValidationResult)4 Code (org.openforis.idm.model.Code)4 Coordinate (org.openforis.idm.model.Coordinate)3 CoordinateAttribute (org.openforis.idm.model.CoordinateAttribute)3 ValidationResultFlag (org.openforis.idm.metamodel.validation.ValidationResultFlag)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)1 CollectRecord (org.openforis.collect.model.CollectRecord)1 Step (org.openforis.collect.model.CollectRecord.Step)1 CodeList (org.openforis.idm.metamodel.CodeList)1 Validator (org.openforis.idm.metamodel.validation.Validator)1 Attribute (org.openforis.idm.model.Attribute)1 CodeAttribute (org.openforis.idm.model.CodeAttribute)1 Entity (org.openforis.idm.model.Entity)1