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()));
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations