Search in sources :

Example 6 with NumberAttributeDefinition

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

the class CollectEarthGridTemplateGenerator method getAttributesPerRow.

private List<AttributeDefinition> getAttributesPerRow(CollectSurvey survey) {
    List<AttributeDefinition> expectedColumns = new ArrayList<AttributeDefinition>();
    List<AttributeDefinition> keyAttributeDefinitions = survey.getSchema().getFirstRootEntityDefinition().getKeyAttributeDefinitions();
    expectedColumns.addAll(keyAttributeDefinitions);
    NumberAttributeDefinition latAttribute = survey.getSchema().createNumberAttributeDefinition();
    latAttribute.setType(Type.REAL);
    latAttribute.setName(LAT_COORDINATE);
    latAttribute.setLabel(NodeLabel.Type.INSTANCE, survey.getDefaultLanguage(), "Latitude");
    expectedColumns.add(latAttribute);
    NumberAttributeDefinition longAttribute = survey.getSchema().createNumberAttributeDefinition();
    longAttribute.setType(Type.REAL);
    longAttribute.setName(LONG_COORDINATE);
    longAttribute.setLabel(NodeLabel.Type.INSTANCE, survey.getDefaultLanguage(), "Longitude");
    expectedColumns.add(longAttribute);
    List<AttributeDefinition> fromCsvAttributes = survey.getExtendedDataFields();
    expectedColumns.addAll(fromCsvAttributes);
    return expectedColumns;
}
Also used : ArrayList(java.util.ArrayList) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) 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) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition)

Example 7 with NumberAttributeDefinition

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

Example 8 with NumberAttributeDefinition

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

the class NumberValueUnitValidator method evaluate.

@Override
public ValidationResultFlag evaluate(NumberAttribute<?, ?> attribute) {
    Unit unit = attribute.getUnit();
    NumberAttributeDefinition defn = attribute.getDefinition();
    List<Unit> units = defn.getUnits();
    if (units.size() > 1 && unit == null) {
        Number number = attribute.getNumber();
        if (number != null && number.doubleValue() != 0) {
            return ValidationResultFlag.ERROR;
        } else {
            return ValidationResultFlag.OK;
        }
    } else {
        return ValidationResultFlag.OK;
    }
}
Also used : NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) Unit(org.openforis.idm.metamodel.Unit)

Example 9 with NumberAttributeDefinition

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

the class CalculatedAttributeTest method addItem.

protected Entity addItem(Entity parentEntity, Integer qtyValue, Double priceValue) {
    EntityDefinition rootEntityDefn = parentEntity.getDefinition();
    EntityDefinition itemDefn = (EntityDefinition) rootEntityDefn.getChildDefinition("item");
    Entity item = (Entity) itemDefn.createNode();
    if (qtyValue != null) {
        NodeDefinition qtyDefn = itemDefn.getChildDefinition("qty");
        IntegerAttribute qty = (IntegerAttribute) qtyDefn.createNode();
        qty.setValue(new IntegerValue(qtyValue, null));
        item.add(qty);
    }
    if (priceValue != null) {
        NumericAttributeDefinition priceDefn = (NumericAttributeDefinition) itemDefn.getChildDefinition("price");
        RealAttribute price = (RealAttribute) priceDefn.createNode();
        price.setValue(new RealValue(priceValue, null));
        item.add(price);
    }
    NumberAttributeDefinition totalDefn = (NumberAttributeDefinition) itemDefn.getChildDefinition("total");
    RealAttribute total = (RealAttribute) totalDefn.createNode();
    item.add(total);
    NumberAttributeDefinition discountDefn = (NumberAttributeDefinition) itemDefn.getChildDefinition("discount_percent");
    IntegerAttribute discount = (IntegerAttribute) discountDefn.createNode();
    item.add(discount);
    EntityBuilder.addValue(item, "time", new Time(110, 5));
    parentEntity.add(item);
    recordUpdater.initializeRecord(record);
    return item;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition)

Example 10 with NumberAttributeDefinition

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

NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)10 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)7 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)3 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)3 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)3 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)3 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 AttributeDefault (org.openforis.idm.metamodel.AttributeDefault)2 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)2 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)2 Schema (org.openforis.idm.metamodel.Schema)2 Survey (org.openforis.idm.metamodel.Survey)2 SurveyContext (org.openforis.idm.metamodel.SurveyContext)2 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)2 Unit (org.openforis.idm.metamodel.Unit)2 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)1 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)1 CollectRecord (org.openforis.collect.model.CollectRecord)1