use of org.openforis.idm.model.Entity in project collect by openforis.
the class PathTest method testMultipleFieldPathWithIndex.
@Test
public void testMultipleFieldPathWithIndex() throws InvalidPathException {
Entity cluster = getRootEntity();
Entity plot = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addEntity(plot, "tree");
Entity tree2 = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree2, "dbh", 12.2);
RealAttribute dbh2 = EntityBuilder.addValue(tree2, "dbh", 15.7);
Path path = Path.parse("tree[2]/dbh[2]/value");
// Node
List<Node<?>> res = path.evaluate(plot);
Assert.assertEquals(1, res.size());
Assert.assertEquals(15.7, ((Field<?>) res.get(0)).getValue());
// Defn
NodeDefinition def = path.evaluate(plot.getDefinition());
Assert.assertEquals(dbh2.getDefinition().getFieldDefinition("value"), def);
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class NodeBuilder method createEntity.
private Entity createEntity(Entity parent) {
EntityDefinition def = (EntityDefinition) parent.getDefinition().getChildDefinition(name);
Entity entity = createDetachedEntity(def);
return entity;
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class NodeBuilder method createDetachedEntity.
protected Entity createDetachedEntity(EntityDefinition def) {
Entity entity = (Entity) def.createNode();
addChildren(entity, builders);
return entity;
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class CollectRelationalTest method createTestRecord.
protected static CollectRecord createTestRecord(CollectSurvey survey, String id) {
CollectRecord record = new CollectRecord(survey, "2.0");
Entity cluster = record.createRootEntity("cluster");
record.setCreationDate(new GregorianCalendar(2011, 12, 31, 23, 59).getTime());
// record.setCreatedBy("ModelDaoIntegrationTest");
record.setStep(Step.ENTRY);
addTestValues(cluster, id);
// set counts
record.getEntityCounts().add(2);
// set keys
record.getRootEntityKeyValues().add(id);
return record;
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class AbsoluteModelPathExpressionTest method testIteratePath2.
@Test
public void testIteratePath2() throws InvalidExpressionException {
Entity plot1 = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addValue(plot1, "no", new Code("1"));
Entity plot2 = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addValue(plot2, "no", new Code("1"));
Entity plot3 = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addValue(plot3, "no", new Code("1"));
List<Node<?>> list = iterateExpression("/cluster/plot/no", record);
Assert.assertEquals(3, list.size());
}
Aggregations