Search in sources :

Example 1 with BooleanAttributeDefinition

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

the class BooleanAttributeDefinitionPR method onStartDefinition.

@Override
protected void onStartDefinition() throws XmlParseException, XmlPullParserException, IOException {
    super.onStartDefinition();
    BooleanAttributeDefinition defn = (BooleanAttributeDefinition) getDefinition();
    Boolean affirmativeOnly = getBooleanAttribute(AFFIRMATIVE_ONLY, false);
    defn.setAffirmativeOnly(affirmativeOnly == null ? false : affirmativeOnly);
}
Also used : BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition)

Example 2 with BooleanAttributeDefinition

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

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

the class CollectEarthGridTemplateGenerator method getDummyValue.

private String getDummyValue(AttributeDefinition attrDef, Integer ord) {
    String attrName = attrDef.getName();
    String value;
    if (attrDef instanceof NumericAttributeDefinition || attrDef instanceof BooleanAttributeDefinition) {
        value = "0";
        if (ord != null) {
            value = ord + "";
        }
    } else if (attrDef instanceof DateAttributeDefinition) {
        value = "1/1/2000";
    } else if (attrDef instanceof CodeAttributeDefinition) {
        CodeListItem firstAvailableItem = getFirstAvailableCodeItem(attrDef);
        value = firstAvailableItem == null ? "0" : firstAvailableItem.getCode();
    } else {
        value = attrName;
        if (ord != null) {
            value += "_" + ord;
        }
    }
    return value;
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) CodeListItem(org.openforis.idm.metamodel.CodeListItem) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition)

Example 4 with BooleanAttributeDefinition

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

the class RecordUpdater method applyInitialValue.

private Value applyInitialValue(Attribute<?, ?> attr) {
    Value value = null;
    if (!attr.getDefinition().isCalculated()) {
        if (attr.isEmpty() && isDefaultValueToBeApplied(attr)) {
            value = performDefaultValueApply(attr);
        }
        if (attr instanceof BooleanAttribute && ((BooleanAttributeDefinition) attr.getDefinition()).isAffirmativeOnly() && attr.isEmpty()) {
            BooleanAttribute boolAttr = (BooleanAttribute) attr;
            value = new BooleanValue(false);
            boolAttr.setValue((BooleanValue) value);
            boolAttr.updateSummaryInfo();
        }
    }
    return value;
}
Also used : BooleanAttribute(org.openforis.idm.model.BooleanAttribute) BooleanValue(org.openforis.idm.model.BooleanValue) Value(org.openforis.idm.model.Value) BooleanValue(org.openforis.idm.model.BooleanValue) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition)

Example 5 with BooleanAttributeDefinition

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

the class NodeDefinitionProxy method fromList.

static List<NodeDefinitionProxy> fromList(EntityDefinitionProxy parent, List<? extends NodeDefinition> list) {
    List<NodeDefinitionProxy> proxies = new ArrayList<NodeDefinitionProxy>();
    if (list != null) {
        for (NodeDefinition n : list) {
            NodeDefinitionProxy p = null;
            CollectSurvey survey = (CollectSurvey) n.getSurvey();
            UIOptions uiOptions = survey.getUIOptions();
            boolean hidden = uiOptions.isHidden(n);
            if (!hidden) {
                if (n instanceof AttributeDefinition) {
                    if (n instanceof BooleanAttributeDefinition) {
                        p = new BooleanAttributeDefinitionProxy(parent, (BooleanAttributeDefinition) n);
                    } else if (n instanceof CodeAttributeDefinition) {
                        p = new CodeAttributeDefinitionProxy(parent, (CodeAttributeDefinition) n);
                    } else if (n instanceof CoordinateAttributeDefinition) {
                        p = new CoordinateAttributeDefinitionProxy(parent, (CoordinateAttributeDefinition) n);
                    } else if (n instanceof DateAttributeDefinition) {
                        p = new DateAttributeDefinitionProxy(parent, (DateAttributeDefinition) n);
                    } else if (n instanceof FileAttributeDefinition) {
                        p = new FileAttributeDefinitionProxy(parent, (FileAttributeDefinition) n);
                    } else if (n instanceof NumberAttributeDefinition) {
                        p = new NumberAttributeDefinitionProxy(parent, (NumberAttributeDefinition) n);
                    } else if (n instanceof RangeAttributeDefinition) {
                        p = new RangeAttributeDefinitionProxy(parent, (RangeAttributeDefinition) n);
                    } else if (n instanceof TaxonAttributeDefinition) {
                        p = new TaxonAttributeDefinitionProxy(parent, (TaxonAttributeDefinition) n);
                    } else if (n instanceof TextAttributeDefinition) {
                        p = new TextAttributeDefinitionProxy(parent, (TextAttributeDefinition) n);
                    } else if (n instanceof TimeAttributeDefinition) {
                        p = new TimeAttributeDefinitionProxy(parent, (TimeAttributeDefinition) n);
                    } else {
                        throw new RuntimeException("AttributeDefinition not supported: " + n.getClass().getSimpleName());
                    }
                } else if (n instanceof EntityDefinition) {
                    p = new EntityDefinitionProxy(parent, (EntityDefinition) n);
                }
                if (p != null) {
                    proxies.add(p);
                }
            }
        }
    }
    return proxies;
}
Also used : TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) FileAttributeDefinition(org.openforis.idm.metamodel.FileAttributeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) FileAttributeDefinition(org.openforis.idm.metamodel.FileAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition)

Aggregations

BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)5 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)3 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)2 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)2 TaxonAttributeDefinition (org.openforis.idm.metamodel.TaxonAttributeDefinition)2 ArrayList (java.util.ArrayList)1 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 CodeTable (org.openforis.collect.relational.model.CodeTable)1 DataColumn (org.openforis.collect.relational.model.DataColumn)1 DataTable (org.openforis.collect.relational.model.DataTable)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 CodeListItem (org.openforis.idm.metamodel.CodeListItem)1 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 FileAttributeDefinition (org.openforis.idm.metamodel.FileAttributeDefinition)1 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)1 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)1 RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)1 TextAttributeDefinition (org.openforis.idm.metamodel.TextAttributeDefinition)1