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