use of org.openforis.idm.metamodel.validation.ValidationResultFlag in project collect by openforis.
the class CollectNumericRangeUnitValidator method evaluate.
@Override
public ValidationResultFlag evaluate(NumericRangeAttribute<?, ?> attribute) {
CollectRecord record = (CollectRecord) attribute.getRecord();
Step step = record.getStep();
ValidationResultFlag resultFlag = super.evaluate(attribute);
if (resultFlag == ValidationResultFlag.ERROR && step == Step.ENTRY) {
Character unitSymbolChar = attribute.getUnitField().getSymbol();
FieldSymbol unitSymbol = FieldSymbol.valueOf(unitSymbolChar);
if (unitSymbol != null && unitSymbol.isReasonBlank()) {
return ValidationResultFlag.WARNING;
}
}
return resultFlag;
}
use of org.openforis.idm.metamodel.validation.ValidationResultFlag in project collect by openforis.
the class CollectValidator method validateMinCount.
@Override
public ValidationResultFlag validateMinCount(Entity entity, NodeDefinition childDef) {
ValidationResultFlag flag = super.validateMinCount(entity, childDef);
CollectRecord record = (CollectRecord) entity.getRecord();
record.updateMinCountsValidationCache(entity, childDef, flag);
return flag;
}
use of org.openforis.idm.metamodel.validation.ValidationResultFlag in project collect by openforis.
the class CollectValidator method validateRootEntityKey.
private void validateRootEntityKey(Attribute<?, ?> attribute, ValidationResults results) {
RecordKeyUniquenessValidator keyValidator = new RecordKeyUniquenessValidator(recordManager);
ValidationResultFlag res = keyValidator.evaluate(attribute);
if (res == ValidationResultFlag.ERROR) {
results.addResult(keyValidator, ValidationResultFlag.ERROR);
}
}
use of org.openforis.idm.metamodel.validation.ValidationResultFlag 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.ValidationResultFlag in project collect by openforis.
the class RecordUpdaterTest method testCardinalityRevalidatedOnDelete.
@Test
public void testCardinalityRevalidatedOnDelete() {
record(rootEntityDef(attributeDef("max_time_study"), entityDef("time_study", attributeDef("start_time")).multiple().maxCount("max_time_study")), attribute("max_time_study", "2"), entity("time_study", attribute("start_time", "2011")), entity("time_study", attribute("start_time", "2012")), entity("time_study", attribute("start_time", "2013")));
Entity rootEntity = record.getRootEntity();
assertEquals(ValidationResultFlag.ERROR, rootEntity.getMaxCountValidationResult("time_study"));
// EntityDefinition timeStudyDef = (EntityDefinition) survey.getSchema().getDefinitionByPath("/root/time_study");
// Integer timeStudyMaxCount = rootEntityChange.getMaxCountByChildDefinitionId().get(timeStudyDef);
NodeChangeSet changeSet = updater.deleteNode(record.findNodeByPath("/root/time_study[1]"));
EntityChange rootEntityChange = (EntityChange) changeSet.getChange(rootEntity);
assertNotNull(rootEntityChange);
ValidationResultFlag maxTimeStudyCountValidation = rootEntityChange.getChildrenMaxCountValidation().get("time_study");
assertEquals(ValidationResultFlag.OK, maxTimeStudyCountValidation);
assertEquals(ValidationResultFlag.OK, rootEntity.getMaxCountValidationResult("time_study"));
}
Aggregations