Search in sources :

Example 11 with RealAttribute

use of org.openforis.idm.model.RealAttribute in project collect by openforis.

the class CSVDataImportProcessIntegrationTest method newRecordsTest.

@Test
public void newRecordsTest() throws Exception {
    EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
    CSVDataImportProcess process = importCSVFile(VALID_TEST_CSV, clusterDefn.getId(), true, true, "2.0");
    ReferenceDataImportStatus<ParsingError> status = process.getStatus();
    assertTrue(status.isComplete());
    assertEquals(3, status.getProcessed());
    {
        CollectRecord reloadedRecord = loadRecord("10_111");
        Entity cluster = reloadedRecord.getRootEntity();
        RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
        RealValue plotDistanceVal = plotDistance.getValue();
        assertEquals(Double.valueOf(200d), plotDistanceVal.getValue());
        assertEquals(meterUnit, plotDistanceVal.getUnit());
    }
    {
        CollectRecord reloadedRecord = loadRecord("10_114");
        Entity cluster = reloadedRecord.getRootEntity();
        RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
        RealValue plotDistanceVal = plotDistance.getValue();
        assertEquals(Double.valueOf(0.3d), plotDistanceVal.getValue());
        assertEquals(kilometerUnit, plotDistanceVal.getUnit());
    }
}
Also used : RealValue(org.openforis.idm.model.RealValue) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) RealAttribute(org.openforis.idm.model.RealAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 12 with RealAttribute

use of org.openforis.idm.model.RealAttribute in project collect by openforis.

the class CSVDataImportProcessIntegrationTest 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");
    CSVDataImportProcess process = importCSVFile(MISSING_PARENT_ENTITY_TEST_CSV, treeDefn.getId(), true, false, null, true);
    ReferenceDataImportStatus<ParsingError> status = process.getStatus();
    assertTrue(status.isComplete());
    assertEquals(0, status.getRowsInError().size());
    assertEquals(4, status.getProcessed());
    {
        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());
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entity(org.openforis.idm.model.Entity) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) RealAttribute(org.openforis.idm.model.RealAttribute) IntegerAttribute(org.openforis.idm.model.IntegerAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 13 with RealAttribute

use of org.openforis.idm.model.RealAttribute in project collect by openforis.

the class CSVDataImportProcessIntegrationTest 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");
    CSVDataImportProcess process = importCSVFile(VALID_TEST_CSV, clusterDefn.getId());
    ReferenceDataImportStatus<ParsingError> status = process.getStatus();
    assertTrue(status.isComplete());
    assertTrue(status.getSkippedRows().isEmpty());
    assertEquals(3, status.getProcessed());
    {
        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());
    }
}
Also used : RealValue(org.openforis.idm.model.RealValue) CollectRecord(org.openforis.collect.model.CollectRecord) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entity(org.openforis.idm.model.Entity) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) RealAttribute(org.openforis.idm.model.RealAttribute) TextAttribute(org.openforis.idm.model.TextAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 14 with RealAttribute

use of org.openforis.idm.model.RealAttribute 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"));
        }
    }
}
Also used : Entity(org.openforis.idm.model.Entity) Coordinate(org.openforis.idm.model.Coordinate) RealAttribute(org.openforis.idm.model.RealAttribute) Time(org.openforis.idm.model.Time) Code(org.openforis.idm.model.Code) Date(org.openforis.idm.model.Date)

Example 15 with RealAttribute

use of org.openforis.idm.model.RealAttribute 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);
    }
}
Also used : Entity(org.openforis.idm.model.Entity) Coordinate(org.openforis.idm.model.Coordinate) RealAttribute(org.openforis.idm.model.RealAttribute) Time(org.openforis.idm.model.Time) Code(org.openforis.idm.model.Code) Date(org.openforis.idm.model.Date)

Aggregations

RealAttribute (org.openforis.idm.model.RealAttribute)39 Test (org.junit.Test)33 Entity (org.openforis.idm.model.Entity)25 AbstractTest (org.openforis.idm.AbstractTest)14 CollectRecord (org.openforis.collect.model.CollectRecord)9 Code (org.openforis.idm.model.Code)9 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)8 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)6 Node (org.openforis.idm.model.Node)6 RealValue (org.openforis.idm.model.RealValue)6 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)5 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)5 Coordinate (org.openforis.idm.model.Coordinate)4 Date (org.openforis.idm.model.Date)4 Time (org.openforis.idm.model.Time)4 Unit (org.openforis.idm.metamodel.Unit)2 IntegerAttribute (org.openforis.idm.model.IntegerAttribute)2 TextAttribute (org.openforis.idm.model.TextAttribute)2 GregorianCalendar (java.util.GregorianCalendar)1 Ignore (org.junit.Ignore)1