Search in sources :

Example 1 with KeyAttributeDefinition

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

the class CollectEarthBalloonGenerator method createComponent.

private CEComponent createComponent(NodeDefinition def, int entityPosition) {
    String label = def.getLabel(Type.INSTANCE, language);
    if (label == null && !isDefaultLanguage()) {
        label = def.getLabel(Type.INSTANCE);
    }
    if (label == null) {
        label = def.getName();
    }
    boolean multiple = def.isMultiple();
    UIOptions uiOptions = survey.getUIOptions();
    boolean hideWhenNotRelevant = uiOptions.isHideWhenNotRelevant(def);
    CEComponent comp;
    if (def instanceof EntityDefinition) {
        if (def.isMultiple() && ((EntityDefinition) def).isEnumerable()) {
            comp = createEnumeratedEntityComponent((EntityDefinition) def);
        } else {
            String tooltip = def.getDescription(language);
            CEFieldSet fieldSet = new CEFieldSet(def.getName(), label, tooltip);
            for (NodeDefinition child : ((EntityDefinition) def).getChildDefinitions()) {
                if (!uiOptions.isHidden(child)) {
                    fieldSet.addChild(createComponent(child));
                }
            }
            comp = fieldSet;
        }
    } else {
        AttributeDefinition attrDef = (AttributeDefinition) def;
        String htmlParameterName;
        boolean insideEnumeratedEntity = def.getParentEntityDefinition().isEnumerable();
        if (insideEnumeratedEntity) {
            htmlParameterName = getEnumeratedEntityComponentHtmlParameterName(def.getParentEntityDefinition(), entityPosition, def);
        } else {
            htmlParameterName = getHtmlParameterName(def);
        }
        String tooltip = attrDef.getDescription(language);
        CEFieldType type = getFieldType(def);
        boolean key = def instanceof KeyAttributeDefinition ? ((KeyAttributeDefinition) def).isKey() : false;
        if (insideEnumeratedEntity && key) {
            comp = new CEEnumeratingCodeField(htmlParameterName, def.getName(), label, tooltip, multiple, type, key);
        } else if (def instanceof CodeAttributeDefinition) {
            CodeAttributeDefinition codeAttrDef = (CodeAttributeDefinition) def;
            CodeList list = codeAttrDef.getList();
            Integer listLevelIndex = codeAttrDef.getListLevelIndex();
            Map<Integer, List<CodeListItem>> codeItemsByParentCodeItemId = getCodeListItemsByParentId(list, listLevelIndex);
            CodeAttributeDefinition parentCodeAttributeDef = codeAttrDef.getParentCodeAttributeDefinition();
            String parentName = parentCodeAttributeDef == null ? null : getHtmlParameterName(parentCodeAttributeDef);
            comp = new CECodeField(htmlParameterName, def.getName(), label, tooltip, type, multiple, key, codeItemsByParentCodeItemId, parentName);
        } else {
            comp = new CEField(htmlParameterName, def.getName(), label, tooltip, multiple, type, key);
        }
        CollectAnnotations annotations = survey.getAnnotations();
        if (attrDef.isCalculated() || (annotations.isFromCollectEarthCSV(attrDef) && annotations.isShowReadOnlyFieldInCollectEarth(attrDef))) {
            ((CEField) comp).setReadOnly(true);
        }
    }
    comp.hideWhenNotRelevant = hideWhenNotRelevant;
    componentByName.put(comp.getName(), comp);
    return comp;
}
Also used : UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeList(org.openforis.idm.metamodel.CodeList) CEFieldType(org.openforis.collect.io.metadata.collectearth.balloon.CEField.CEFieldType) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) CodeListItem(org.openforis.idm.metamodel.CodeListItem) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with KeyAttributeDefinition

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

the class SchemaVM method getIcon.

public static String getIcon(SchemaNodeData data) {
    SurveyObject surveyObject = data.getSurveyObject();
    boolean key = surveyObject instanceof KeyAttributeDefinition && ((KeyAttributeDefinition) surveyObject).isKey();
    boolean calculated = surveyObject instanceof AttributeDefinition && ((AttributeDefinition) surveyObject).isCalculated();
    return getIcon(data, key, calculated);
}
Also used : SurveyObject(org.openforis.idm.metamodel.SurveyObject) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition)

Example 3 with KeyAttributeDefinition

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

Aggregations

AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)3 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)3 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)2 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)2 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)2 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)2 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)2 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)2 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CEFieldType (org.openforis.collect.io.metadata.collectearth.balloon.CEField.CEFieldType)1 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)1 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)1 CodeTable (org.openforis.collect.relational.model.CodeTable)1 CodeValueFKColumn (org.openforis.collect.relational.model.CodeValueFKColumn)1 DataTable (org.openforis.collect.relational.model.DataTable)1 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)1 CodeList (org.openforis.idm.metamodel.CodeList)1 CodeListItem (org.openforis.idm.metamodel.CodeListItem)1