use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class CSVDataImportJobIntegrationTest method loadRecord.
private CollectRecord loadRecord(String key) {
RecordFilter filter = new RecordFilter(survey);
filter.setRootEntityId(survey.getSchema().getRootEntityDefinition("cluster").getId());
filter.setKeyValues(Arrays.asList(key));
List<CollectRecordSummary> summaries = recordDao.loadSummaries(filter);
assertEquals(1, summaries.size());
CollectRecordSummary summary = summaries.get(0);
CollectRecord reloadedRecord = recordManager.load(survey, summary.getId(), summary.getStep());
return reloadedRecord;
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class CSVDataImportJobIntegrationTest method validTest.
@Test
public void validTest() throws Exception {
{
CollectRecord record = createTestRecord(survey, "10_111");
recordDao.insert(record);
assertEquals(Integer.valueOf(0), record.getErrors());
}
{
CollectRecord record = createTestRecord(survey, "10_114");
recordDao.insert(record);
}
EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
CSVDataImportJob process = importCSVFile(VALID_TEST_CSV, clusterDefn.getId());
assertTrue(process.isCompleted());
assertTrue(process.getParsingErrors().isEmpty());
{
CollectRecord reloadedRecord = loadRecord("10_111");
assertEquals(Integer.valueOf(1), reloadedRecord.getErrors());
Entity cluster = reloadedRecord.getRootEntity();
RealAttribute plotDirection = (RealAttribute) cluster.getChild("plot_direction");
RealValue plotDirectionVal = plotDirection.getValue();
assertEquals(Double.valueOf(50d), plotDirectionVal.getValue());
RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
RealValue plotDistanceVal = plotDistance.getValue();
assertEquals(Double.valueOf(200d), plotDistanceVal.getValue());
assertEquals(meterUnit, plotDistanceVal.getUnit());
TextAttribute gpsModel = (TextAttribute) cluster.getChild("gps_model");
assertEquals("GPS MAP 62S", gpsModel.getValue().getValue());
assertEquals(2, cluster.getCount("map_sheet"));
{
TextAttribute mapSheet = (TextAttribute) cluster.getChild("map_sheet", 0);
assertEquals("new map sheet 1", mapSheet.getValue().getValue());
}
{
TextAttribute mapSheet = (TextAttribute) cluster.getChild("map_sheet", 1);
assertEquals("new map sheet 2", mapSheet.getValue().getValue());
}
}
{
CollectRecord reloadedRecord = loadRecord("10_114");
Entity cluster = reloadedRecord.getRootEntity();
RealAttribute plotDirection = (RealAttribute) cluster.getChild("plot_direction");
RealValue plotDirectionVal = plotDirection.getValue();
assertEquals(Double.valueOf(40d), plotDirectionVal.getValue());
RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
RealValue plotDistanceVal = plotDistance.getValue();
assertEquals(Double.valueOf(0.3d), plotDistanceVal.getValue());
assertEquals(kilometerUnit, plotDistanceVal.getUnit());
TextAttribute gpsModel = (TextAttribute) cluster.getChild("gps_model");
assertEquals("GPS MAP 62S", gpsModel.getValue().getValue());
}
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class CSVDataImportJobIntegrationTest method createMissingParentEntityTest.
@Test
public void createMissingParentEntityTest() throws Exception {
{
CollectRecord record = createTestRecord(survey, "10_111");
recordDao.insert(record);
}
{
CollectRecord record = createTestRecord(survey, "10_114");
recordDao.insert(record);
}
EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
EntityDefinition plotDefn = (EntityDefinition) clusterDefn.getChildDefinition("plot");
EntityDefinition treeDefn = (EntityDefinition) plotDefn.getChildDefinition("tree");
CSVDataImportJob process = importCSVFile(MISSING_PARENT_ENTITY_TEST_CSV, treeDefn.getId(), true, false, null, true);
assertTrue(process.isCompleted());
assertTrue(process.getParsingErrors().isEmpty());
{
CollectRecord reloadedRecord = loadRecord("10_111");
Entity cluster = reloadedRecord.getRootEntity();
Entity plot = (Entity) cluster.getChild("plot", 0);
assertEquals(3, plot.getCount("tree"));
Entity tree = (Entity) plot.getChild("tree", 2);
IntegerAttribute treeNo = (IntegerAttribute) tree.getChild("tree_no");
assertEquals(Integer.valueOf(2), treeNo.getValue().getValue());
IntegerAttribute stemNo = (IntegerAttribute) tree.getChild("stem_no");
assertEquals(Integer.valueOf(2), stemNo.getValue().getValue());
RealAttribute dbh = (RealAttribute) tree.getChild("dbh");
assertEquals(Double.valueOf(200), dbh.getValue().getValue());
}
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class CSVDataImportJobIntegrationTest method singleEntityTest.
@Test
public void singleEntityTest() throws Exception {
{
CollectRecord record = createTestRecord(survey, "10_114");
recordDao.insert(record);
}
EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
EntityDefinition plotDefn = (EntityDefinition) clusterDefn.getChildDefinition("plot");
CSVDataImportJob process = importCSVFile(VALID_SINGLE_ENTITY_TEST_CSV, plotDefn.getId());
assertTrue(process.isCompleted());
assertTrue(process.getParsingErrors().isEmpty());
{
CollectRecord reloadedRecord = loadRecord("10_114");
Entity reloadedCluster = reloadedRecord.getRootEntity();
{
Entity plot = reloadedCluster.findChildEntitiesByKeys("plot", "1", "A").get(0);
Entity timeStudy = (Entity) plot.getChild("time_study");
DateAttribute date = (DateAttribute) timeStudy.getChild("date");
assertEquals(new Date(2012, 2, 15), date.getValue());
}
{
Entity plot = reloadedCluster.findChildEntitiesByKeys("plot", "2", "B").get(0);
Entity timeStudy = (Entity) plot.getChild("time_study");
DateAttribute date = (DateAttribute) timeStudy.getChild("date");
assertEquals(new Date(2013, 5, 18), date.getValue());
}
}
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class CSVDataImportProcessIntegrationTest method createTestRecord.
private CollectRecord createTestRecord(CollectSurvey survey, String id) {
CollectRecord record = new CollectRecord(survey, "2.0", "cluster");
Entity cluster = record.getRootEntity();
record.setCreationDate(new GregorianCalendar(2011, 11, 31, 23, 59).getTime());
EntityBuilder.addValue(cluster, "id", new Code(id));
EntityBuilder.addValue(cluster, "region", new Code("001"));
EntityBuilder.addValue(cluster, "district", new Code("002"));
EntityBuilder.addValue(cluster, "plot_distance", 100d, meterUnit);
EntityBuilder.addValue(cluster, "map_sheet", "map sheet 1");
EntityBuilder.addValue(cluster, "map_sheet", "map sheet 2");
EntityBuilder.addValue(cluster, "map_sheet", "map sheet 3");
{
Entity timeStudy = EntityBuilder.addEntity(cluster, "time_study");
EntityBuilder.addValue(timeStudy, "date", new Date(2012, 1, 1));
EntityBuilder.addValue(timeStudy, "start_time", new Time(9, 10));
EntityBuilder.addValue(timeStudy, "end_time", new Time(12, 20));
}
{
Entity timeStudy = EntityBuilder.addEntity(cluster, "time_study");
EntityBuilder.addValue(timeStudy, "date", new Date(2012, 2, 20));
EntityBuilder.addValue(timeStudy, "start_time", new Time(8, 15));
EntityBuilder.addValue(timeStudy, "end_time", new Time(11, 10));
}
{
Entity plot = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addValue(plot, "no", new Code("1"));
EntityBuilder.addValue(plot, "subplot", "A");
EntityBuilder.addValue(plot, "land_use", new Code("1"));
{
Entity tree = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree, "tree_no", 1);
EntityBuilder.addValue(tree, "stem_no", 1);
EntityBuilder.addValue(tree, "dbh", 10.5d);
}
{
Entity tree = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree, "tree_no", 2);
EntityBuilder.addValue(tree, "stem_no", 1);
EntityBuilder.addValue(tree, "dbh", 20.5d);
}
}
{
Entity plot = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addValue(plot, "no", new Code("2"));
EntityBuilder.addValue(plot, "subplot", "A");
EntityBuilder.addValue(plot, "land_use", new Code("2"));
{
Entity tree = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree, "tree_no", 1);
EntityBuilder.addValue(tree, "stem_no", 1);
EntityBuilder.addValue(tree, "dbh", 10.5d);
}
{
Entity tree = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree, "tree_no", 2);
EntityBuilder.addValue(tree, "stem_no", 1);
EntityBuilder.addValue(tree, "dbh", 20.5d);
}
}
{
Entity plot = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addValue(plot, "no", new Code("2"));
EntityBuilder.addValue(plot, "subplot", "B");
EntityBuilder.addValue(plot, "land_use", new Code("3"));
{
Entity tree = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree, "tree_no", 1);
EntityBuilder.addValue(tree, "stem_no", 1);
EntityBuilder.addValue(tree, "dbh", 10.5d);
}
{
Entity tree = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree, "tree_no", 2);
EntityBuilder.addValue(tree, "stem_no", 1);
EntityBuilder.addValue(tree, "dbh", 20.5d);
}
}
record.updateSummaryFields();
recordManager.validate(record);
return record;
}
Aggregations