use of org.openforis.collect.relational.model.CodeTable in project collect by openforis.
the class MondrianCubeGenerator method generateCube.
private Cube generateCube() {
Cube cube = new Cube("Collect Earth Plot");
EntityDefinition rootEntityDef = survey.getSchema().getFirstRootEntityDefinition();
Table table = new Table(rootEntityDef.getName());
cube.table = table;
List<NodeDefinition> children = rootEntityDef.getChildDefinitions();
for (NodeDefinition nodeDef : children) {
if (!survey.getAnnotations().isIncludedInDataExport(nodeDef)) {
continue;
}
String nodeName = nodeDef.getName();
if (nodeDef instanceof AttributeDefinition) {
Dimension dimension = generateDimension(nodeDef, rootEntityDef);
if (nodeDef instanceof KeyAttributeDefinition && ((KeyAttributeDefinition) nodeDef).isKey()) {
Measure measure = new Measure(rootEntityDef.getName() + "_count");
measure.column = "_" + rootEntityDef.getName() + "_" + nodeName;
measure.caption = StringEscapeUtils.escapeHtml4(extractFailsafeLabel(rootEntityDef) + " Count");
measure.aggregator = "distinct count";
measure.datatype = "Integer";
cube.measures.add(measure);
} else if (nodeDef instanceof NumberAttributeDefinition) {
for (String aggregator : MEASURE_AGGREGATORS) {
Measure measure = new Measure(nodeName + "_" + aggregator);
measure.column = nodeName;
measure.caption = StringEscapeUtils.escapeHtml4(extractFailsafeLabel(nodeDef) + " " + aggregator);
measure.aggregator = aggregator;
measure.datatype = "Numeric";
measure.formatString = "#.##";
cube.measures.add(measure);
}
}
cube.dimensions.add(dimension);
} else {
String rootEntityIdColumnName = getRootEntityIdColumnName(rootEntityDef);
String entityName = nodeName;
String entityLabel = extractFailsafeLabel(nodeDef);
for (NodeDefinition childDef : ((EntityDefinition) nodeDef).getChildDefinitions()) {
String childLabel = extractReportingLabel(childDef);
if (childLabel == null) {
childLabel = extractFailsafeLabel(childDef);
if (!childLabel.startsWith(entityLabel)) {
childLabel = entityLabel + " " + childLabel;
}
}
Dimension dimension = new Dimension(childLabel);
Hierarchy hierarchy = new Hierarchy(childLabel);
if (nodeDef.isMultiple()) {
dimension.foreignKey = rootEntityIdColumnName;
hierarchy.primaryKey = rootEntityIdColumnName;
hierarchy.primaryKeyTable = entityName;
if (childDef instanceof CodeAttributeDefinition) {
CodeAttributeDefinition codeAttr = (CodeAttributeDefinition) childDef;
Join join = new Join(null);
DataTable dataTable = rdbSchema.getDataTable(nodeDef);
CodeValueFKColumn foreignKeyCodeColumn = dataTable.getForeignKeyCodeColumn(codeAttr);
join.leftKey = foreignKeyCodeColumn.getName();
CodeTable codeListTable = rdbSchema.getCodeListTable(codeAttr);
join.rightKey = CodeListTables.getIdColumnName(rdbConfig, codeListTable.getName());
;
join.tables = Arrays.asList(new Table(entityName), new Table(codeListTable.getName()));
hierarchy.join = join;
} else {
hierarchy.table = new Table(entityName);
}
hierarchy.levels.addAll(generateLevel(childDef));
dimension.hierarchy = hierarchy;
} else {
dimension = generateDimension(childDef, rootEntityDef);
}
cube.dimensions.add(dimension);
}
}
}
// add predefined dimensions
// DEPRECATED 07/08/2015 : From now on all the operations to calculate the aspect,elevation,slope and initial land use class are made through Calculated Members
// cube.dimensions.addAll(generatePredefinedDimensions());
// add predefined measures
// Add the measures AFTER the 1st measure, which shouyld be Plot Count
cube.measures.addAll(1, generatePredefinedMeasures());
return cube;
}
Aggregations