Search in sources :

Example 1 with CodeTable

use of org.openforis.collect.relational.model.CodeTable in project collect by openforis.

the class JooqDatabaseExporter method insertReferenceData.

@Override
public void insertReferenceData(ProgressListener progressListener) {
    List<CodeTable> codeListTables = schema.getCodeListTables();
    long totalItems = codeListTables.size();
    long processedItems = 0;
    for (CodeTable codeTable : codeListTables) {
        DataExtractor extractor = DataExtractorFactory.getExtractor(codeTable);
        batchExecutor.executeInserts(extractor);
        processedItems++;
        progressListener.progressMade(new Progress(processedItems, totalItems));
    }
}
Also used : CodeTable(org.openforis.collect.relational.model.CodeTable) Progress(org.openforis.concurrency.Progress) DataExtractor(org.openforis.collect.relational.data.DataExtractor)

Example 2 with CodeTable

use of org.openforis.collect.relational.model.CodeTable in project collect by openforis.

the class NewMondrianSchemaGenerator method generateLevel.

private Level generateLevel(AttributeDefinition nodeDef) {
    DataTable dataTable = rdbSchema.getDataTable(nodeDef.getParentDefinition());
    Level level = new Level(determineDimensionName(nodeDef), determineLevelCaption(nodeDef));
    level.levelType = "Regular";
    if (nodeDef instanceof NumericAttributeDefinition) {
        level.type = ((NumericAttributeDefinition) nodeDef).getType() == Type.INTEGER ? INTEGER_DATATYPE : NUMERIC_DATATYPE;
    } else if (nodeDef instanceof BooleanAttributeDefinition) {
        level.type = BOOLEAN_DATATYPE;
    } else if (nodeDef instanceof CodeAttributeDefinition) {
        level.type = ((CodeAttributeDefinition) nodeDef).getList().isExternal() ? STRING_DATATYPE : INTEGER_DATATYPE;
    } else {
        level.type = STRING_DATATYPE;
    }
    if (nodeDef instanceof CodeAttributeDefinition && !((CodeAttributeDefinition) nodeDef).getList().isExternal()) {
        CodeAttributeDefinition codeDef = (CodeAttributeDefinition) nodeDef;
        CodeTable codeListTable = rdbSchema.getCodeListTable(codeDef);
        level.table = codeListTable.getName();
        level.column = codeListTable.getPrimaryKeyConstraint().getPrimaryKeyColumn().getName();
        level.nameColumn = CodeListTables.getLabelColumnName(rdbConfig, codeDef.getList(), codeDef.getLevelIndex(), language);
    } else if (nodeDef instanceof TaxonAttributeDefinition) {
        DataColumn dataColumn = dataTable.getDataColumn(((TaxonAttributeDefinition) nodeDef).getCodeFieldDefinition());
        level.column = dataColumn.getName();
    } else if (nodeDef.isMultiple()) {
        // TODO skip multiple attributes?
        level.column = nodeDef.getName();
    } else {
        DataColumn dataColumn = dataTable.getDataColumn(nodeDef.getMainFieldDefinition());
        level.column = dataColumn.getName();
    }
    return level;
}
Also used : CodeTable(org.openforis.collect.relational.model.CodeTable) DataTable(org.openforis.collect.relational.model.DataTable) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) DataColumn(org.openforis.collect.relational.model.DataColumn) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition)

Example 3 with CodeTable

use of org.openforis.collect.relational.model.CodeTable in project collect by openforis.

the class Mondrian4SchemaGenerator method createDimensionAttributes.

private List<Attribute> createDimensionAttributes(DataTable dataTable, AttributeDefinition attrDefn) {
    List<Attribute> attributes = new ArrayList<Attribute>();
    if (attrDefn instanceof CodeAttributeDefinition && !((CodeAttributeDefinition) attrDefn).getList().isExternal()) {
        CodeAttributeDefinition codeAttrDefn = (CodeAttributeDefinition) attrDefn;
        CodeTable codeListTable = rdbSchema.getCodeListTable(codeAttrDefn);
        String codeListTableName = codeListTable.getName();
        Attribute attribute = new Attribute();
        FieldDefinition<String> codeFieldDef = codeAttrDefn.getCodeFieldDefinition();
        attribute.name = codeFieldDef.getName();
        attribute.caption = getAttributeCaption(codeFieldDef);
        attribute.table = codeListTableName;
        attribute.keyColumn = CodeListTables.getCodeColumnName(rdbConfig, codeListTableName);
        attribute.nameColumn = CodeListTables.getLabelColumnName(rdbConfig, codeListTableName);
        attributes.add(attribute);
    } else if (attrDefn.hasMainField()) {
        attributes.addAll(createAttributesForFields(dataTable, attrDefn));
    } else if (attrDefn instanceof DateAttributeDefinition || attrDefn instanceof TimeAttributeDefinition) {
        List<DataColumn> dataColumns = dataTable.getDataColumns(attrDefn);
        DataColumn dataColumn = dataColumns.get(0);
        Attribute attribute = new Attribute();
        attribute.name = attrDefn.getName();
        attribute.caption = getDimensionCaption(attrDefn);
        attribute.keyColumn = dataColumn.getName();
        attributes.add(attribute);
        attributes.addAll(createAttributesForFields(dataTable, attrDefn));
    } else {
    // TODO
    // every field makes the Key of the Attribute ?! then nameColumn must be specified
    // Attribute attribute = new Attribute();
    // attribute.name = attrDefn.getName();
    // attribute.caption = getDimensionCaption(attrDefn);
    // Key key = new Key();
    // for (FieldDefinition<?> fieldDef : attrDefn.getFieldDefinitions()) {
    // DataColumn dataColumn = dataTable.getDataColumn(fieldDef);
    // if (dataColumn != null) {
    // Column column = new Column();
    // column.name = dataColumn.getName();
    // key.list().add(column);
    // }
    // }
    // attribute.children.add(key);
    // Name name = new Name();
    // name.list().add(e)
    // attribute.children.add(name);
    // attributes.add(attribute);
    }
    return attributes;
}
Also used : CodeTable(org.openforis.collect.relational.model.CodeTable) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) Attribute(mondrian.olap.MondrianDef.Attribute) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) ArrayList(java.util.ArrayList) DataColumn(org.openforis.collect.relational.model.DataColumn) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition)

Example 4 with CodeTable

use of org.openforis.collect.relational.model.CodeTable in project collect by openforis.

the class JooqRelationalSchemaCreator method addCodeListsCodeIndexes.

private void addCodeListsCodeIndexes(RelationalSchema schema, CollectDSLContext dsl) {
    for (Table<?> table : schema.getTables()) {
        if (table instanceof CodeTable) {
            CodeTable codeTable = (CodeTable) table;
            org.jooq.Table<Record> jooqTable = jooqTable(schema, table, !dsl.isSchemaLess());
            CodeListCodeColumn codeColumn = codeTable.getCodeColumn();
            CollectCreateIndexStep createIndexStep = dsl.createIndex(table.getName() + "_code_idx");
            if (codeTable.getLevelIdx() == null || codeTable.getLevelIdx() == 0) {
                // unique index only for first level or when the code scope is 'scheme'
                createIndexStep.unique();
            }
            createIndexStep.on(jooqTable, field(codeColumn.getName())).execute();
        }
    }
}
Also used : CodeTable(org.openforis.collect.relational.model.CodeTable) CodeListCodeColumn(org.openforis.collect.relational.model.CodeListCodeColumn) CollectCreateIndexStep(org.jooq.CollectCreateIndexStep) Record(org.jooq.Record)

Example 5 with CodeTable

use of org.openforis.collect.relational.model.CodeTable in project collect by openforis.

the class MondrianCubeGenerator method generateDimension.

/*	private List<Dimension> generatePredefinedDimensions() {
		List<Dimension> dimensions = new ArrayList<Dimension>();
		//Slope category
		{
			Dimension d = new Dimension("Slope category");
			d.foreignKey = "slope_id";
			d.highCardinality = "false";
			Hierarchy h = new Hierarchy();
			h.table = new Table("slope_category");
			Level l = new Level("Slope_category");
			l.table = "slope_category";
			l.column = "slope_id";
			l.nameColumn = "slope_caption";
			l.type = "String";
			l.levelType = "Regular";
			l.uniqueMembers = "false";
			h.levels.add(l);
			d.hierarchy = h;
			dimensions.add(d);
		}
		//Initial Land Use
		{
			Dimension d = new Dimension("Initial Land Use");
			d.foreignKey = "dynamics_id";
			d.highCardinality = "false";
			Hierarchy h = new Hierarchy();
			h.table = new Table("dynamics_category");
			Level l = new Level("Initial_land_use");
			l.table = "dynamics_category";
			l.column = "dynamics_id";
			l.nameColumn = "dynamics_caption";
			l.type = "String";
			l.levelType = "Regular";
			l.uniqueMembers = "false";
			l.hideMemberIf = "Never";
			h.levels.add(l);
			d.hierarchy = h;
			dimensions.add(d);
		}
		//Elevation Range
		{
			Dimension d = new Dimension("Elevation range");
			d.foreignKey = "elevation_id";
			d.highCardinality = "false";
			Hierarchy h = new Hierarchy();
			h.table = new Table("elevation_category");
			Level l = new Level("Elevation_range");
			l.table = "elevation_category";
			l.column = "elevation_id";
			l.nameColumn = "elevation_caption";
			l.type = "String";
			l.levelType = "Regular";
			l.uniqueMembers = "false";
			l.hideMemberIf = "Never";
			h.levels.add(l);
			d.hierarchy = h;
			dimensions.add(d);
		}
		return dimensions;
	}
*/
private Dimension generateDimension(NodeDefinition nodeDef, EntityDefinition rootEntityDef) {
    String attrLabel = extractFailsafeLabel(nodeDef);
    Dimension dimension = new Dimension(attrLabel);
    Hierarchy hierarchy = dimension.hierarchy;
    if (nodeDef instanceof CodeAttributeDefinition) {
        CodeAttributeDefinition codeDef = (CodeAttributeDefinition) nodeDef;
        DataTable dataTable = nodeDef.isMultiple() ? rdbSchema.getDataTable(nodeDef) : rdbSchema.getDataTable(nodeDef.getParentDefinition());
        CodeTable codeListTable = rdbSchema.getCodeListTable(codeDef);
        String codeListTableName = codeListTable.getName();
        String codeFKColumnName = DataTables.getCodeFKColumnName(rdbConfig, dataTable, codeDef);
        String rootEntityIdColumnName = getRootEntityIdColumnName(rootEntityDef);
        if (nodeDef.isMultiple()) {
            dimension.foreignKey = rootEntityIdColumnName;
            hierarchy.primaryKey = rootEntityIdColumnName;
            hierarchy.primaryKeyTable = dataTable.getName();
            Join join = new Join(null);
            join.leftKey = codeFKColumnName;
            join.rightKey = CodeListTables.getIdColumnName(rdbConfig, codeListTableName);
            join.tables = Arrays.asList(new Table(dataTable.getName()), new Table(codeListTableName));
            hierarchy.join = join;
        } else {
            dimension.foreignKey = codeFKColumnName;
            hierarchy.table = new Table(codeListTableName);
        }
    }
    if (nodeDef instanceof DateAttributeDefinition) {
        dimension.type = "";
        hierarchy.type = "TimeDimension";
        hierarchy.allMemberName = "attrLabel";
        String[] levelNames = new String[] { "Year", "Month", "Day" };
        for (String levelName : levelNames) {
            Level level = new Level(attrLabel + " - " + levelName);
            level.column = nodeDef.getName() + "_" + levelName.toLowerCase(Locale.ENGLISH);
            level.levelType = String.format("Time%ss", levelName);
            level.type = "Numeric";
            // Avoids grouping the values of the sane day over multiple months!!!
            level.uniqueMembers = "false";
            hierarchy.levels.add(level);
        }
    } else if (nodeDef instanceof CoordinateAttributeDefinition) {
        dimension.type = "";
        hierarchy.type = "StandardDimension";
        Level level = new Level(attrLabel + " - Latitude");
        level.column = nodeDef.getName() + "_y";
        hierarchy.levels.add(level);
        Level level2 = new Level(attrLabel + " - Longitude");
        level2.column = nodeDef.getName() + "_x";
        hierarchy.levels.add(level2);
    } else {
        List<Level> levels = generateLevel(nodeDef);
        hierarchy.levels.addAll(levels);
    }
    return dimension;
}
Also used : CodeTable(org.openforis.collect.relational.model.CodeTable) DataTable(org.openforis.collect.relational.model.DataTable) CodeTable(org.openforis.collect.relational.model.CodeTable) DataTable(org.openforis.collect.relational.model.DataTable) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeListLevel(org.openforis.idm.metamodel.CodeListLevel) ArrayList(java.util.ArrayList) CodeList(org.openforis.idm.metamodel.CodeList) List(java.util.List)

Aggregations

CodeTable (org.openforis.collect.relational.model.CodeTable)6 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)4 DataTable (org.openforis.collect.relational.model.DataTable)3 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)3 ArrayList (java.util.ArrayList)2 DataColumn (org.openforis.collect.relational.model.DataColumn)2 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)2 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)2 List (java.util.List)1 Attribute (mondrian.olap.MondrianDef.Attribute)1 CollectCreateIndexStep (org.jooq.CollectCreateIndexStep)1 Record (org.jooq.Record)1 DataExtractor (org.openforis.collect.relational.data.DataExtractor)1 CodeListCodeColumn (org.openforis.collect.relational.model.CodeListCodeColumn)1 CodeValueFKColumn (org.openforis.collect.relational.model.CodeValueFKColumn)1 Progress (org.openforis.concurrency.Progress)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)1 CodeList (org.openforis.idm.metamodel.CodeList)1 CodeListLevel (org.openforis.idm.metamodel.CodeListLevel)1