Search in sources :

Example 81 with EntityDefinition

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

the class DefaultValueTest 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
 */
protected 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");
    item.addChildDefinition(total);
    {
        AttributeDefault attributeDefault = new AttributeDefault();
        attributeDefault.setExpression("qty * price");
        attributeDefault.setCondition("price > 0");
        total.addAttributeDefault(attributeDefault);
    }
    {
        AttributeDefault attributeDefault = new AttributeDefault();
        attributeDefault.setValue("0");
        attributeDefault.setCondition("price = 0");
        total.addAttributeDefault(attributeDefault);
    }
    return survey;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Survey(org.openforis.idm.metamodel.Survey) 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 82 with EntityDefinition

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

the class MetaModelExpressionTest method testParentExpression.

@Test
public void testParentExpression() {
    Schema schema = survey.getSchema();
    EntityDefinition clusterDefn = schema.getRootEntityDefinition("cluster");
    EntityDefinition plotDefn = (EntityDefinition) clusterDefn.getChildDefinition("plot");
    NodeDefinition plotNoDefn = plotDefn.getChildDefinition("no");
    SchemaPathExpression expression = new SchemaPathExpression("parent()");
    NodeDefinition resultDefn = expression.evaluate(plotDefn, plotNoDefn);
    Assert.assertEquals(clusterDefn, resultDefn);
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Schema(org.openforis.idm.metamodel.Schema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 83 with EntityDefinition

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

the class UIOptionsTest method testTabSetAssociation.

@Test
public void testTabSetAssociation() throws InvalidPathException {
    UITabSet clusterTabSet = uiOptions.getTabSet("cluster");
    assertNotNull(clusterTabSet);
    assertEquals("cluster", clusterTabSet.getName());
    EntityDefinition cluster = schema.getRootEntityDefinition("cluster");
    clusterTabSet = uiOptions.getAssignedRootTabSet(cluster);
    assertEquals("cluster", clusterTabSet.getName());
    EntityDefinition plot = (EntityDefinition) cluster.getChildDefinition("plot");
    UITab assignedTab = uiOptions.getAssignedTab(plot);
    assertEquals("plot", assignedTab.getName());
    NodeDefinition tree = plot.getChildDefinition("tree");
    assignedTab = uiOptions.getAssignedTab(tree);
    assertEquals("tree", assignedTab.getName());
    UITabSet assignedToParentTabSet = uiOptions.getAssignedTabSet(plot);
    assertEquals("plot", assignedToParentTabSet.getName());
    assignedToParentTabSet = uiOptions.getAssignedTabSet(cluster);
    assertEquals("cluster", assignedToParentTabSet.getName());
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) Test(org.junit.Test)

Example 84 with EntityDefinition

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

the class NewMondrianSchemaGenerator method generateCube.

private Cube generateCube(EntityDefinition multipleEntityDef) {
    Cube cube = new Cube(determineCubeName(multipleEntityDef));
    cube.caption = extractLabel(multipleEntityDef);
    DataTable dataTable = rdbSchema.getDataTable(multipleEntityDef);
    Table table = new Table(dbSchemaName, dataTable.getName() + "_view");
    cube.tables.add(table);
    addCountMeasure(cube, multipleEntityDef);
    List<EntityDefinition> viewEntityDefinitions = new ArrayList<EntityDefinition>();
    viewEntityDefinitions.addAll(multipleEntityDef.getAncestorEntityDefinitions());
    viewEntityDefinitions.add(multipleEntityDef);
    for (EntityDefinition entityDef : viewEntityDefinitions) {
        List<AttributeDefinition> attributes = entityDef.getNestedAttributes();
        for (AttributeDefinition attrDef : attributes) {
            if (canBeMeasured(attrDef)) {
                Dimension dimension = generateDimension(cube, attrDef);
                cube.dimensions.add(dimension);
                addMeasures(cube, attrDef);
            }
        }
    }
    if (survey.getTarget() == SurveyTarget.COLLECT_EARTH) {
        cube.measures.addAll(1, generateEarthSpecificMeasures());
    }
    return cube;
}
Also used : DataTable(org.openforis.collect.relational.model.DataTable) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeTable(org.openforis.collect.relational.model.CodeTable) DataTable(org.openforis.collect.relational.model.DataTable) ArrayList(java.util.ArrayList) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition)

Example 85 with EntityDefinition

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

the class NewMondrianSchemaGenerator method determineLevelCaption.

private String determineLevelCaption(NodeDefinition attrDef, String subLevelName) {
    EntityDefinition nearestAncestorMultipleEntity = attrDef.getNearestAncestorMultipleEntity();
    StringBuffer sb = new StringBuffer();
    if (!nearestAncestorMultipleEntity.isRoot()) {
        sb.append(extractLabel(nearestAncestorMultipleEntity));
        sb.append(' ');
    }
    sb.append(extractLabel(attrDef));
    if (subLevelName != null) {
        sb.append(" - ");
        sb.append(subLevelName);
    }
    return sb.toString();
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition)

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