Search in sources :

Example 26 with RealAttribute

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

the class PathTest method testMultipleAttributeWithoutIndex.

@Test
public void testMultipleAttributeWithoutIndex() throws InvalidPathException {
    Entity cluster = getRootEntity();
    Entity plot = EntityBuilder.addEntity(cluster, "plot");
    EntityBuilder.addEntity(plot, "tree");
    Entity tree2 = EntityBuilder.addEntity(plot, "tree");
    RealAttribute dbh1 = EntityBuilder.addValue(tree2, "dbh", 12.2);
    RealAttribute dbh2 = EntityBuilder.addValue(tree2, "dbh", 15.7);
    Path path = Path.parse("tree[2]/dbh");
    // Node
    List<Node<?>> res = path.evaluate(plot);
    Assert.assertEquals(2, res.size());
    Assert.assertEquals(dbh1, res.get(0));
    Assert.assertEquals(dbh2, res.get(1));
    // Defn
    NodeDefinition def = path.evaluate(plot.getDefinition());
    Assert.assertEquals(dbh2.getDefinition(), def);
}
Also used : Entity(org.openforis.idm.model.Entity) RealAttribute(org.openforis.idm.model.RealAttribute) Node(org.openforis.idm.model.Node) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 27 with RealAttribute

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

the class PathTest method testMultipleFieldPathWithoutIndex.

@Test
public void testMultipleFieldPathWithoutIndex() throws InvalidPathException {
    Entity cluster = getRootEntity();
    Entity plot = EntityBuilder.addEntity(cluster, "plot");
    EntityBuilder.addEntity(plot, "tree");
    Entity tree2 = EntityBuilder.addEntity(plot, "tree");
    RealAttribute dbh1 = EntityBuilder.addValue(tree2, "dbh", 12.2);
    RealAttribute dbh2 = EntityBuilder.addValue(tree2, "dbh", 15.7);
    Path path = Path.parse("tree[2]/dbh/value");
    // Node
    List<Node<?>> res = path.evaluate(plot);
    Assert.assertEquals(2, res.size());
    Assert.assertEquals(12.2, ((Field<?>) res.get(0)).getValue());
    Assert.assertEquals(15.7, ((Field<?>) res.get(1)).getValue());
    // Defn
    NodeDefinition def = path.evaluate(plot.getDefinition());
    Assert.assertEquals(dbh1.getDefinition().getFieldDefinition("value"), def);
    Assert.assertEquals(dbh2.getDefinition().getFieldDefinition("value"), def);
}
Also used : Entity(org.openforis.idm.model.Entity) RealAttribute(org.openforis.idm.model.RealAttribute) Node(org.openforis.idm.model.Node) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 28 with RealAttribute

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

the class PathTest method testSingleAttributeWithoutIndex.

@Test
public void testSingleAttributeWithoutIndex() throws InvalidPathException {
    Entity cluster = getRootEntity();
    Entity plot = EntityBuilder.addEntity(cluster, "plot");
    Entity tree1 = EntityBuilder.addEntity(plot, "tree");
    EntityBuilder.addValue(tree1, "dbh", 12.2);
    Entity tree2 = EntityBuilder.addEntity(plot, "tree");
    RealAttribute dbh2 = EntityBuilder.addValue(tree2, "dbh", 15.7);
    Path path = Path.parse("tree[2]/dbh");
    // Node
    List<Node<?>> res = path.evaluate(plot);
    Assert.assertEquals(1, res.size());
    Assert.assertEquals(dbh2, res.get(0));
    // Defn
    NodeDefinition def = path.evaluate(plot.getDefinition());
    Assert.assertEquals(dbh2.getDefinition(), def);
}
Also used : Entity(org.openforis.idm.model.Entity) RealAttribute(org.openforis.idm.model.RealAttribute) Node(org.openforis.idm.model.Node) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 29 with RealAttribute

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

the class CollectRelationalTest method addTestValues.

private static void addTestValues(Entity cluster, String id) {
    // cluster.setId(100);
    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)

Example 30 with RealAttribute

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

the class ComparisonCheckTest method testRealPassRange2.

@Test
public void testRealPassRange2() {
    RealAttribute plotDir = EntityBuilder.addValue(cluster, "plot_direction", 0.0);
    ValidationResults results = validate(plotDir);
    assertFalse(containsComparisonCheck(results.getErrors()));
}
Also used : RealAttribute(org.openforis.idm.model.RealAttribute) Test(org.junit.Test)

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