use of org.openforis.collect.relational.model.CodeValueFKColumn in project collect by openforis.
the class Mondrian4SchemaGenerator method createDimensionLink.
private DimensionLink createDimensionLink(Dimension dimension, AttributeDefinition attrDef) {
DimensionLink dimensionLink;
if (attrDef instanceof CodeAttributeDefinition) {
CodeAttributeDefinition codeAttrDef = (CodeAttributeDefinition) attrDef;
if (codeAttrDef.isMultiple()) {
dimensionLink = new NoLink();
} else if (codeAttrDef.getList().isExternal()) {
dimensionLink = new FactLink();
} else {
dimensionLink = new ForeignKeyLink();
DataTable dataTable = rdbSchema.getDataTable(attrDef.getParentEntityDefinition());
CodeValueFKColumn fkColumn = dataTable.getForeignKeyCodeColumn((CodeAttributeDefinition) attrDef);
((ForeignKeyLink) dimensionLink).foreignKeyColumn = fkColumn.getName();
}
} else {
dimensionLink = new FactLink();
}
dimensionLink.dimension = dimension.name;
return dimensionLink;
}
use of org.openforis.collect.relational.model.CodeValueFKColumn 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;
}
use of org.openforis.collect.relational.model.CodeValueFKColumn in project collect by openforis.
the class NewMondrianSchemaGenerator method generateDimension.
private Dimension generateDimension(Cube cube, AttributeDefinition attrDef) {
Dimension dimension = new Dimension(determineDimensionName(attrDef));
EntityDefinition ancestorMultipleEntity = attrDef.getNearestAncestorMultipleEntity();
if (ancestorMultipleEntity.isRoot()) {
dimension.caption = extractLabel(attrDef);
} else {
dimension.caption = String.format("%s %s", extractLabel(ancestorMultipleEntity), extractLabel(attrDef));
}
Hierarchy hierarchy = dimension.hierarchy;
hierarchy.table = new Table(dbSchemaName, cube.tables.get(0).name);
if (attrDef instanceof CodeAttributeDefinition) {
CodeAttributeDefinition codeAttrDef = (CodeAttributeDefinition) attrDef;
if (!codeAttrDef.getList().isExternal()) {
if (attrDef.isMultiple()) {
DataTable dataTable = rdbSchema.getDataTable(attrDef);
String parentEntityPKColumnName = getEntityPKColumnName(ancestorMultipleEntity);
dimension.foreignKey = parentEntityPKColumnName;
hierarchy.table = null;
hierarchy.primaryKey = parentEntityPKColumnName;
hierarchy.primaryKeyTable = dataTable.getName();
Join join = new Join(null);
String codeListTableName = CodeListTables.getTableName(rdbConfig, codeAttrDef);
join.leftKey = dataTable.getForeignKeyCodeColumn(codeAttrDef).getName();
join.rightKey = CodeListTables.getIdColumnName(rdbConfig, codeListTableName);
join.tables = Arrays.asList(new Table(dbSchemaName, dataTable.getName()), new Table(dbSchemaName, codeListTableName));
hierarchy.join = join;
} else {
String codeListTableName = CodeListTables.getTableName(rdbConfig, codeAttrDef);
hierarchy.table = new Table(dbSchemaName, codeListTableName);
DataTable dataTable = rdbSchema.getDataTable(attrDef.getParentEntityDefinition());
CodeValueFKColumn foreignKeyCodeColumn = dataTable.getForeignKeyCodeColumn(codeAttrDef);
dimension.foreignKey = foreignKeyCodeColumn.getName();
}
}
hierarchy.levels.add(generateLevel(attrDef));
} else if (attrDef instanceof CoordinateAttributeDefinition) {
dimension.type = "";
hierarchy.type = "StandardDimension";
{
String fieldName = CoordinateAttributeDefinition.Y_FIELD_NAME;
Level level = new Level(dimension.name + "_" + fieldName, extractLabel(attrDef) + " - Latitude");
level.column = attrDef.getName() + "_" + fieldName;
hierarchy.levels.add(level);
}
{
String fieldName = CoordinateAttributeDefinition.X_FIELD_NAME;
Level level = new Level(dimension.name + "_" + fieldName, extractLabel(attrDef) + " - Longitude");
level.column = attrDef.getName() + "_" + fieldName;
hierarchy.levels.add(level);
}
} else if (attrDef instanceof DateAttributeDefinition) {
dimension.type = "";
hierarchy.type = "TimeDimension";
hierarchy.allMemberName = "attrLabel";
String[] fieldNames = new String[] { DateAttributeDefinition.YEAR_FIELD_NAME, DateAttributeDefinition.MONTH_FIELD_NAME, DateAttributeDefinition.DAY_FIELD_NAME };
for (String fieldName : fieldNames) {
String fieldLabel = StringUtils.capitalize(fieldName);
Level level = new Level(dimension.name + "_" + fieldName, determineLevelCaption(attrDef, fieldLabel));
level.column = attrDef.getName() + "_" + fieldName.toLowerCase(Locale.ENGLISH);
level.levelType = String.format("Time%ss", fieldLabel);
level.type = NUMERIC_DATATYPE;
hierarchy.levels.add(level);
}
} else if (attrDef instanceof TaxonAttributeDefinition) {
{
String fieldName = TaxonAttributeDefinition.CODE_FIELD_NAME;
Level level = new Level(dimension.name + "_" + fieldName, extractLabel(attrDef) + " - Code");
level.column = attrDef.getName() + "_" + fieldName;
hierarchy.levels.add(level);
}
{
String fieldName = TaxonAttributeDefinition.SCIENTIFIC_NAME_FIELD_NAME;
Level level = new Level(dimension.name + "_" + fieldName, extractLabel(attrDef) + " - Scientific name");
level.column = attrDef.getName() + "_" + fieldName;
hierarchy.levels.add(level);
}
} else if (attrDef instanceof TimeAttributeDefinition) {
dimension.type = "";
hierarchy.type = "TimeDimension";
hierarchy.allMemberName = "attrLabel";
String[] fieldNames = new String[] { TimeAttributeDefinition.HOUR_FIELD, TimeAttributeDefinition.MINUTE_FIELD };
for (String fieldName : fieldNames) {
String fieldLabel = StringUtils.capitalize(fieldName);
Level level = new Level(dimension.name + "_" + fieldName, determineLevelCaption(attrDef, fieldLabel));
level.column = attrDef.getName() + "_" + fieldName.toLowerCase(Locale.ENGLISH);
level.levelType = String.format("Time%ss", fieldLabel);
level.type = NUMERIC_DATATYPE;
hierarchy.levels.add(level);
}
} else {
hierarchy.levels.add(generateLevel(attrDef));
}
return dimension;
}
Aggregations