Search in sources :

Example 6 with ValidationResultFlag

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

the class CollectValidator method validateSpecified.

private boolean validateSpecified(Attribute<?, ?> attribute, ValidationResults results) {
    SpecifiedValidator specifiedValidator = new SpecifiedValidator();
    ValidationResultFlag specifiedResultFlag = specifiedValidator.evaluate(attribute);
    results.addResult(specifiedValidator, specifiedResultFlag);
    return !specifiedResultFlag.isError();
}
Also used : ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag)

Example 7 with ValidationResultFlag

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

the class CollectRecordIntegrationTest method testApproveMissingValue.

@Test
public void testApproveMissingValue() throws Exception {
    CollectSurvey survey = loadSurvey();
    CollectRecord record = createTestRecord(survey);
    record.setStep(Step.CLEANSING);
    Entity cluster = record.getRootEntity();
    int missingCount = cluster.getMissingCount("time_study");
    assertEquals(0, missingCount);
    Entity timeStudy = (Entity) cluster.getChild("time_study", 0);
    {
        // delete node (min count error expected)
        NodeChangeSet changeSet = recordUpdater.deleteNode(timeStudy);
        int missingCount2 = cluster.getMissingCount("time_study");
        assertEquals(1, missingCount2);
        NodeChange<?> clusterChange = changeSet.getChange(cluster);
        assertTrue(clusterChange instanceof EntityChange);
        EntityChange clusterEntityChange = (EntityChange) clusterChange;
        Map<String, ValidationResultFlag> childrenMinCountValid = clusterEntityChange.getChildrenMinCountValidation();
        ValidationResultFlag timeStudyMinCountValid = childrenMinCountValid.get("time_study");
        assertEquals(ValidationResultFlag.ERROR, timeStudyMinCountValid);
    }
    {
        // approve missing value (min count warning expected)
        NodeChangeSet changeSet = recordUpdater.approveMissingValue(cluster, "time_study");
        NodeChange<?> clusterChange = changeSet.getChange(cluster);
        assertTrue(clusterChange instanceof EntityChange);
        assertEquals(cluster, clusterChange.getNode());
        EntityChange clusterEntityChange = (EntityChange) clusterChange;
        Map<String, ValidationResultFlag> childrenMinCountValid = clusterEntityChange.getChildrenMinCountValidation();
        ValidationResultFlag timeStudyMinCountValid = childrenMinCountValid.get("time_study");
        assertEquals(ValidationResultFlag.WARNING, timeStudyMinCountValid);
    }
}
Also used : Entity(org.openforis.idm.model.Entity) ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag) HashMap(java.util.HashMap) Map(java.util.Map) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 8 with ValidationResultFlag

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

the class CollectRecordIntegrationTest method testAddMultipleEntityWithMaxCount.

@Test
public void testAddMultipleEntityWithMaxCount() throws Exception {
    CollectSurvey survey = loadSurvey();
    CollectRecord record = createTestRecord(survey);
    Entity cluster = record.getRootEntity();
    {
        NodeChangeSet changeSet = recordUpdater.addEntity(cluster, "time_study");
        assertEquals(4, changeSet.size());
        changeSet = recordUpdater.addEntity(cluster, "time_study");
        assertEquals(5, changeSet.size());
        {
            Entity timeStudy = (Entity) cluster.getChild("time_study", 2);
            NodeChange<?> timeStudyChange = changeSet.getChange(timeStudy);
            assertTrue(timeStudyChange instanceof EntityAddChange);
        }
        {
            NodeChange<?> clusterChange = changeSet.getChange(cluster);
            assertTrue(clusterChange instanceof EntityChange);
            EntityChange clusterEntityChange = (EntityChange) clusterChange;
            Map<String, ValidationResultFlag> childrenMinCountValid = clusterEntityChange.getChildrenMinCountValidation();
            ValidationResultFlag plotMinCountValid = childrenMinCountValid.get("time_study");
            assertNull(plotMinCountValid);
            Map<String, ValidationResultFlag> childrenMaxCountValid = clusterEntityChange.getChildrenMaxCountValidation();
            ValidationResultFlag plotMaxCountValid = childrenMaxCountValid.get("time_study");
            assertEquals(ValidationResultFlag.ERROR, plotMaxCountValid);
        }
    }
}
Also used : Entity(org.openforis.idm.model.Entity) ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 9 with ValidationResultFlag

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

the class RecordUpdaterTest method testCardinalityRevalidatedOnRequiredAttributeUpdate.

@Test
public void testCardinalityRevalidatedOnRequiredAttributeUpdate() {
    record(rootEntityDef(attributeDef("source"), attributeDef("dependent").required("source = 1")), attribute("source", "2"), attribute("dependent", null));
    Entity rootEntity = record.getRootEntity();
    assertEquals(ValidationResultFlag.OK, rootEntity.getMinCountValidationResult("dependent"));
    Attribute<?, ?> source = record.findNodeByPath("/root/source");
    NodeChangeSet nodeChangeSet = update(source, "1");
    EntityChange rootEntityChange = (EntityChange) nodeChangeSet.getChange(rootEntity);
    assertNotNull(rootEntityChange);
    ValidationResultFlag dependentValidationResult = rootEntityChange.getChildrenMinCountValidation().get("dependent");
    assertEquals(ValidationResultFlag.ERROR, dependentValidationResult);
    assertEquals(ValidationResultFlag.ERROR, rootEntity.getMinCountValidationResult("dependent"));
}
Also used : Entity(org.openforis.idm.model.Entity) ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag) Test(org.junit.Test)

Example 10 with ValidationResultFlag

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

the class RecordUpdaterTest method testCardinalityRevalidatedWhenBecomesRelevant.

@Test
public void testCardinalityRevalidatedWhenBecomesRelevant() {
    record(rootEntityDef(attributeDef("source"), attributeDef("dependent").multiple().relevant("source = '1'").minCount("1")), attribute("source", "2"), attribute("dependent", null));
    Entity rootEntity = record.getRootEntity();
    assertEquals(ValidationResultFlag.OK, rootEntity.getMinCountValidationResult("dependent"));
    Attribute<?, ?> source = record.findNodeByPath("/root/source");
    NodeChangeSet nodeChangeSet = update(source, "1");
    EntityChange rootEntityChange = (EntityChange) nodeChangeSet.getChange(rootEntity);
    assertNotNull(rootEntityChange);
    ValidationResultFlag dependentValidationResult = rootEntityChange.getChildrenMinCountValidation().get("dependent");
    assertEquals(ValidationResultFlag.ERROR, dependentValidationResult);
    assertEquals(ValidationResultFlag.ERROR, rootEntity.getMinCountValidationResult("dependent"));
}
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