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;
}
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);
}
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());
}
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;
}
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();
}
Aggregations