use of org.openforis.idm.model.Entity 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.model.Entity in project collect by openforis.
the class CollectRecordIntegrationTest method testConfirmError.
@Test
public void testConfirmError() throws Exception {
CollectSurvey survey = loadSurvey();
CollectRecord record = createTestRecord(survey);
Entity cluster = record.getRootEntity();
CodeAttribute region = (CodeAttribute) cluster.getChild("region", 0);
// add wrong value
{
NodeChangeSet changeSet = recordUpdater.updateAttribute(region, new Code("ZZZ"));
assertFalse(changeSet.isEmpty());
NodeChange<?> regionChange = changeSet.getChange(region);
assertTrue(regionChange instanceof AttributeChange);
ValidationResults validationResults = ((AttributeChange) regionChange).getValidationResults();
List<ValidationResult> errors = validationResults.getErrors();
assertFalse(errors.isEmpty());
List<ValidationResult> warnings = validationResults.getWarnings();
assertTrue(warnings.isEmpty());
}
{
NodeChangeSet changeSet = recordUpdater.confirmError(region);
assertFalse(changeSet.isEmpty());
NodeChange<?> regionChange = changeSet.getChange(region);
assertTrue(regionChange instanceof AttributeChange);
ValidationResults validationResults = ((AttributeChange) regionChange).getValidationResults();
List<ValidationResult> errors = validationResults.getErrors();
assertTrue(errors.isEmpty());
List<ValidationResult> warnings = validationResults.getWarnings();
assertFalse(warnings.isEmpty());
}
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class CollectRecordIntegrationTest method addTestValues.
private void addTestValues(Entity cluster, String id) {
EntityBuilder.addValue(cluster, "id", new Code(id));
EntityBuilder.addValue(cluster, "gps_realtime", Boolean.TRUE);
EntityBuilder.addValue(cluster, "region", new Code("001"));
EntityBuilder.addValue(cluster, "district", new Code("002"));
EntityBuilder.addValue(cluster, "crew_no", 10);
EntityBuilder.addValue(cluster, "map_sheet", "value 1");
EntityBuilder.addValue(cluster, "map_sheet", "value 2");
EntityBuilder.addValue(cluster, "vehicle_location", new Coordinate((double) 432423423l, (double) 4324324l, "srs"));
EntityBuilder.addValue(cluster, "gps_model", "TomTom 1.232");
{
Entity ts = EntityBuilder.addEntity(cluster, "time_study");
EntityBuilder.addValue(ts, "date", new Date(2011, 2, 14));
EntityBuilder.addValue(ts, "start_time", new Time(8, 15));
EntityBuilder.addValue(ts, "end_time", new Time(15, 29));
}
/*
{
Entity ts = EntityBuilder.addEntity(cluster, "time_study");
EntityBuilder.addValue(ts, "date", new Date(2011,2,15));
EntityBuilder.addValue(ts, "start_time", new Time(8,32));
EntityBuilder.addValue(ts, "end_time", new Time(11,20));
}
*/
{
Entity plot = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addValue(plot, "no", new Code("1"));
Entity tree1 = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree1, "tree_no", 1);
EntityBuilder.addValue(tree1, "dbh", 54.2);
EntityBuilder.addValue(tree1, "total_height", 2.0);
// EntityBuilder.addValue(tree1, "bole_height", (Double) null).setMetadata(new CollectAttributeMetadata('*',null,"No value specified"));
RealAttribute boleHeight = EntityBuilder.addValue(tree1, "bole_height", (Double) null);
boleHeight.getField(0).setSymbol('*');
boleHeight.getField(0).setRemarks("No value specified");
Entity tree2 = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree2, "tree_no", 2);
EntityBuilder.addValue(tree2, "dbh", 82.8);
EntityBuilder.addValue(tree2, "total_height", 3.0);
}
{
Entity plot = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addValue(plot, "no", new Code("2"));
Entity tree1 = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree1, "tree_no", 1);
EntityBuilder.addValue(tree1, "dbh", 34.2);
EntityBuilder.addValue(tree1, "total_height", 2.0);
Entity tree2 = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree2, "tree_no", 2);
EntityBuilder.addValue(tree2, "dbh", 85.8);
EntityBuilder.addValue(tree2, "total_height", 4.0);
{
Entity humanImpact = EntityBuilder.addEntity(plot, "human_impact");
EntityBuilder.addValue(humanImpact, "type", new Code("0"));
}
}
}
use of org.openforis.idm.model.Entity 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.model.Entity in project collect by openforis.
the class ModelDaoIntegrationTest method addTestValues.
private void addTestValues(Entity cluster, String id) {
EntityBuilder.addValue(cluster, "id", new Code(id));
EntityBuilder.addValue(cluster, "gps_realtime", Boolean.TRUE);
EntityBuilder.addValue(cluster, "region", new Code("001"));
EntityBuilder.addValue(cluster, "district", new Code("002"));
EntityBuilder.addValue(cluster, "crew_no", 10);
EntityBuilder.addValue(cluster, "map_sheet", "value 1");
EntityBuilder.addValue(cluster, "map_sheet", "value 2");
EntityBuilder.addValue(cluster, "vehicle_location", new Coordinate((double) 432423423l, (double) 4324324l, "srs"));
EntityBuilder.addValue(cluster, "gps_model", "TomTom 1.232");
{
Entity ts = EntityBuilder.addEntity(cluster, "time_study");
EntityBuilder.addValue(ts, "date", new Date(2011, 2, 14));
EntityBuilder.addValue(ts, "start_time", new Time(8, 15));
EntityBuilder.addValue(ts, "end_time", new Time(15, 29));
}
{
Entity ts = EntityBuilder.addEntity(cluster, "time_study");
EntityBuilder.addValue(ts, "date", new Date(2011, 2, 15));
EntityBuilder.addValue(ts, "start_time", new Time(8, 32));
EntityBuilder.addValue(ts, "end_time", new Time(11, 20));
}
{
Entity plot = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addValue(plot, "no", new Code("1"));
Entity tree1 = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree1, "tree_no", 1);
EntityBuilder.addValue(tree1, "dbh", 54.2);
EntityBuilder.addValue(tree1, "total_height", 2.0);
// EntityBuilder.addValue(tree1, "bole_height", (Double) null).setMetadata(new CollectAttributeMetadata('*',null,"No value specified"));
RealAttribute boleHeight = EntityBuilder.addValue(tree1, "bole_height", (Double) null);
boleHeight.getField(0).setSymbol('*');
boleHeight.getField(0).setRemarks("No value specified");
Entity tree2 = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree2, "tree_no", 2);
EntityBuilder.addValue(tree2, "dbh", 82.8);
EntityBuilder.addValue(tree2, "total_height", 3.0);
}
{
Entity plot = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addValue(plot, "no", new Code("2"));
Entity tree1 = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree1, "tree_no", 1);
EntityBuilder.addValue(tree1, "dbh", 34.2);
EntityBuilder.addValue(tree1, "total_height", 2.0);
Entity tree2 = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree2, "tree_no", 2);
EntityBuilder.addValue(tree2, "dbh", 85.8);
EntityBuilder.addValue(tree2, "total_height", 4.0);
}
}
Aggregations