Search in sources :

Example 76 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.

the class CalculatedAttributeDependencyGraphTest method testRemoveEntityWithAgregateFunction.

@Test
public void testRemoveEntityWithAgregateFunction() {
    Entity plot = entity(rootEntity, "plot");
    EntityDefinition treeDef = entityDefinition(plot.getDefinition(), "tree");
    attributeDefinition(treeDef, "dbh");
    Entity tree1 = entity(plot, "tree");
    Attribute<?, ?> dbh1 = attribute(tree1, "dbh");
    Attribute<?, ?> dbhsum1 = calculatedAttribute(tree1, "dbhsum", "sum(parent()/tree/dbh)");
    Entity tree2 = entity(plot, "tree");
    Attribute<?, ?> dbh2 = attribute(tree2, "dbh");
    Attribute<?, ?> dbhsum2 = calculatedAttribute(tree2, "dbhsum", "sum(parent()/tree/dbh)");
    assertCalculatedDependentsInAnyOrder(dbh1, dbhsum1, dbhsum2);
    assertCalculatedDependentsInAnyOrder(dbh2, dbhsum1, dbhsum2);
    plot.remove("tree", 0);
    assertCalculatedDependentsInAnyOrder(dbh2, dbhsum2);
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Test(org.junit.Test)

Example 77 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.

the class CalculatedAttributeDependencyGraphTest method testAddingDependentAfterSource.

@Test
public void testAddingDependentAfterSource() {
    EntityDefinition rootEntityDef = rootEntity.getDefinition();
    attributeDefinition(rootEntityDef, "source");
    calculatedAttributeDefinition(rootEntityDef, "dependent", "source");
    Attribute<?, ?> dependent = attribute(rootEntity, "dependent");
    Attribute<?, ?> source = attribute(rootEntity, "source");
    assertDependents(source, dependent);
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Test(org.junit.Test)

Example 78 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.

the class CalculatedAttributeDependencyGraphTest method testAggregateFunctions.

@Test
public void testAggregateFunctions() {
    Entity plot = entity(rootEntity, "plot");
    EntityDefinition treeDef = entityDefinition(plot.getDefinition(), "tree");
    attributeDefinition(treeDef, "dbh");
    Entity tree1 = entity(plot, "tree");
    Attribute<?, ?> dbh1 = attribute(tree1, "dbh");
    Entity tree2 = entity(plot, "tree");
    Attribute<?, ?> dbh2 = attribute(tree2, "dbh");
    Attribute<?, ?> total = calculatedAttribute(plot, "total", "sum(tree/dbh)");
    assertDependents(dbh1, total);
    assertDependents(dbh2, total);
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Test(org.junit.Test)

Example 79 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.

the class CalculatedAttributeTest method createTestSurvey.

/**
 * Creates a test survey in which there is a bill with a list of items.
 * For each item there is a price, a quantity and a total
 * (calculated using the an expression or a constant).
 *
 * @return
 */
private Survey createTestSurvey() {
    SurveyContext surveyContext = new TestSurveyContext();
    Survey survey = surveyContext.createSurvey();
    Schema schema = survey.getSchema();
    EntityDefinition root = schema.createEntityDefinition();
    root.setName("bill");
    schema.addRootEntityDefinition(root);
    EntityDefinition item = schema.createEntityDefinition();
    item.setName("item");
    root.addChildDefinition(item);
    NumberAttributeDefinition qty = schema.createNumberAttributeDefinition();
    qty.setType(Type.INTEGER);
    qty.setName("qty");
    item.addChildDefinition(qty);
    NumberAttributeDefinition price = schema.createNumberAttributeDefinition();
    price.setName("price");
    item.addChildDefinition(price);
    NumberAttributeDefinition total = schema.createNumberAttributeDefinition();
    total.setName("total");
    total.setCalculated(true);
    total.addAttributeDefault(new AttributeDefault("qty * (price - (price * discount_percent div 100))"));
    item.addChildDefinition(total);
    TimeAttributeDefinition time = schema.createTimeAttributeDefinition();
    time.setName("time");
    time.addAttributeDefault(new AttributeDefault("idm:currentTime()"));
    item.addChildDefinition(time);
    TimeAttributeDefinition timeAlias = schema.createTimeAttributeDefinition();
    timeAlias.setName("time_alias");
    timeAlias.setCalculated(true);
    timeAlias.addAttributeDefault(new AttributeDefault("time"));
    item.addChildDefinition(timeAlias);
    NumberAttributeDefinition discountPercent = schema.createNumberAttributeDefinition();
    discountPercent.setType(Type.INTEGER);
    discountPercent.setName("discount_percent");
    discountPercent.setCalculated(true);
    discountPercent.addAttributeDefault(new AttributeDefault("30", "qty > 50"));
    discountPercent.addAttributeDefault(new AttributeDefault("20", "qty > 20"));
    discountPercent.addAttributeDefault(new AttributeDefault("10", "qty > 10"));
    discountPercent.addAttributeDefault(new AttributeDefault("0", "true()"));
    item.addChildDefinition(discountPercent);
    return survey;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Survey(org.openforis.idm.metamodel.Survey) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) Schema(org.openforis.idm.metamodel.Schema) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) AttributeDefault(org.openforis.idm.metamodel.AttributeDefault) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Example 80 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.

the class DefaultValueTest method addItem.

protected Entity addItem(Entity rootEntity, Integer qtyValue, Double priceValue) {
    EntityDefinition rootEntityDefn = rootEntity.getDefinition();
    EntityDefinition itemDefn = (EntityDefinition) rootEntityDefn.getChildDefinition("item");
    Entity item = (Entity) itemDefn.createNode();
    if (qtyValue != null) {
        NodeDefinition qtyDefn = itemDefn.getChildDefinition("qty");
        IntegerAttribute qty = (IntegerAttribute) qtyDefn.createNode();
        qty.setValue(new IntegerValue(qtyValue, null));
        qty.updateSummaryInfo();
        item.add(qty);
    }
    if (priceValue != null) {
        NumericAttributeDefinition priceDefn = (NumericAttributeDefinition) itemDefn.getChildDefinition("price");
        RealAttribute price = (RealAttribute) priceDefn.createNode();
        price.setValue(new RealValue(priceValue, null));
        price.updateSummaryInfo();
        item.add(price);
    }
    NumericAttributeDefinition totalDefn = (NumericAttributeDefinition) itemDefn.getChildDefinition("total");
    RealAttribute total = (RealAttribute) totalDefn.createNode();
    item.add(total);
    rootEntity.add(item);
    return item;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition)

Aggregations

EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)235 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)70 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)47 Schema (org.openforis.idm.metamodel.Schema)46 ArrayList (java.util.ArrayList)44 Test (org.junit.Test)38 Entity (org.openforis.idm.model.Entity)36 CollectRecord (org.openforis.collect.model.CollectRecord)30 CollectSurvey (org.openforis.collect.model.CollectSurvey)28 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)24 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)24 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)19 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)18 UITab (org.openforis.collect.metamodel.ui.UITab)16 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)14 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)13 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)12 RecordFilter (org.openforis.collect.model.RecordFilter)11 SurveyObject (org.openforis.idm.metamodel.SurveyObject)10 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)9