Search in sources :

Example 41 with CodeAttributeDefinition

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

the class UIOptionsMigrator method createField.

protected UIField createField(UIFormContentContainer parent, NodeDefinition nodeDefn) {
    CollectSurvey survey = (CollectSurvey) nodeDefn.getSurvey();
    UIOptions uiOptions = survey.getUIOptions();
    CollectAnnotations annotations = survey.getAnnotations();
    UIField field;
    if (nodeDefn instanceof CodeAttributeDefinition) {
        UICodeField codeField = parent.createCodeField();
        CodeAttributeDefinition codeAttrDefn = (CodeAttributeDefinition) nodeDefn;
        codeField.setLayout(uiOptions.getLayoutType(codeAttrDefn));
        codeField.setShowCode(uiOptions.getShowCode(codeAttrDefn));
        codeField.setItemsOrientation(uiOptions.getLayoutDirection(codeAttrDefn));
        field = codeField;
    } else {
        field = parent.createField();
    }
    field.setAttributeDefinitionId(nodeDefn.getId());
    if (nodeDefn instanceof TextAttributeDefinition) {
        String autoCompleteGroup = annotations.getAutoCompleteGroup((TextAttributeDefinition) nodeDefn);
        field.setAutoCompleteGroup(autoCompleteGroup);
    } else if (nodeDefn instanceof CoordinateAttributeDefinition) {
        CoordinateAttributeFieldsOrder fieldsOrder = uiOptions.getFieldsOrder((CoordinateAttributeDefinition) nodeDefn);
        field.setFieldsOrder(fieldsOrder);
    }
    field.setHidden(uiOptions.isHidden(nodeDefn));
    return field;
}
Also used : CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) CollectSurvey(org.openforis.collect.model.CollectSurvey) CoordinateAttributeFieldsOrder(org.openforis.collect.metamodel.ui.UIOptions.CoordinateAttributeFieldsOrder)

Example 42 with CodeAttributeDefinition

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

the class UIOptionsTest method populateSchema.

protected void populateSchema() {
    EntityDefinition cluster = schema.createEntityDefinition();
    cluster.setName("cluster");
    schema.addRootEntityDefinition(cluster);
    CodeAttributeDefinition region = schema.createCodeAttributeDefinition();
    region.setName("region");
    cluster.addChildDefinition(region);
    EntityDefinition plot = schema.createEntityDefinition();
    plot.setMultiple(true);
    plot.setName("plot");
    cluster.addChildDefinition(plot);
    EntityDefinition tree = schema.createEntityDefinition();
    tree.setMultiple(true);
    tree.setName("tree");
    plot.addChildDefinition(tree);
    EntityDefinition informant = schema.createEntityDefinition();
    informant.setMultiple(true);
    informant.setName("informant");
    cluster.addChildDefinition(informant);
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition)

Example 43 with CodeAttributeDefinition

use of org.openforis.idm.metamodel.CodeAttributeDefinition 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)

Example 44 with CodeAttributeDefinition

use of org.openforis.idm.metamodel.CodeAttributeDefinition 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;
}
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) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) CodeValueFKColumn(org.openforis.collect.relational.model.CodeValueFKColumn) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition)

Example 45 with CodeAttributeDefinition

use of org.openforis.idm.metamodel.CodeAttributeDefinition 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;
}
Also used : DataTable(org.openforis.collect.relational.model.DataTable) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) CodeTable(org.openforis.collect.relational.model.CodeTable) DataTable(org.openforis.collect.relational.model.DataTable) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) CodeValueFKColumn(org.openforis.collect.relational.model.CodeValueFKColumn) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition)

Aggregations

CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)48 CodeList (org.openforis.idm.metamodel.CodeList)21 CodeListItem (org.openforis.idm.metamodel.CodeListItem)19 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)13 ArrayList (java.util.ArrayList)12 CollectSurvey (org.openforis.collect.model.CollectSurvey)8 CodeListService (org.openforis.idm.metamodel.CodeListService)8 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)8 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)7 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)7 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)6 ModelVersion (org.openforis.idm.metamodel.ModelVersion)6 Code (org.openforis.idm.model.Code)6 Entity (org.openforis.idm.model.Entity)6 DataTable (org.openforis.collect.relational.model.DataTable)5 CodeAttribute (org.openforis.idm.model.CodeAttribute)5 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)4 CollectRecord (org.openforis.collect.model.CollectRecord)4 CodeTable (org.openforis.collect.relational.model.CodeTable)4 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)4