Search in sources :

Example 16 with ValidationResultFlag

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;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag) FieldSymbol(org.openforis.collect.model.FieldSymbol) Step(org.openforis.collect.model.CollectRecord.Step)

Example 17 with ValidationResultFlag

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;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag)

Example 18 with ValidationResultFlag

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);
    }
}
Also used : ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag)

Example 19 with ValidationResultFlag

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;
}
Also used : ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag) ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) ValidationResult(org.openforis.idm.metamodel.validation.ValidationResult)

Example 20 with ValidationResultFlag

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"));
}
Also used : Entity(org.openforis.idm.model.Entity) ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag) Test(org.junit.Test)

Aggregations

ValidationResultFlag (org.openforis.idm.metamodel.validation.ValidationResultFlag)20 Entity (org.openforis.idm.model.Entity)7 Test (org.junit.Test)6 CollectRecord (org.openforis.collect.model.CollectRecord)5 ArrayList (java.util.ArrayList)3 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)3 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ExternalizedProperty (org.granite.messaging.amf.io.util.externalizer.annotation.ExternalizedProperty)2 Step (org.openforis.collect.model.CollectRecord.Step)2 FieldSymbol (org.openforis.collect.model.FieldSymbol)2 ValidationResult (org.openforis.idm.metamodel.validation.ValidationResult)2 ValidationResults (org.openforis.idm.metamodel.validation.ValidationResults)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 NumberValueUnitValidator (org.openforis.idm.metamodel.validation.NumberValueUnitValidator)1 NumericRangeUnitValidator (org.openforis.idm.metamodel.validation.NumericRangeUnitValidator)1 Validator (org.openforis.idm.metamodel.validation.Validator)1 Attribute (org.openforis.idm.model.Attribute)1