Search in sources :

Example 6 with AttributeDefinition

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

the class Mondrian4SchemaGenerator method getAttributeCaption.

private String getAttributeCaption(FieldDefinition<?> fieldDef) {
    AttributeDefinition attrDef = fieldDef.getAttributeDefinition();
    String caption = extractLabel(attrDef);
    if (!(attrDef.hasMainField() && attrDef.getMainFieldDefinition() == fieldDef)) {
        caption += " - " + fieldDef.getName();
    }
    return caption;
}
Also used : DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition)

Example 7 with AttributeDefinition

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

the class QueryExecutorIntegrationTest method testSimpleQuery.

@Test
public void testSimpleQuery() {
    // select region from tree where dbh > 20
    DataQuery query = new DataQuery(survey);
    EntityDefinition treeDef = (EntityDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree");
    AttributeDefinition dbhDef = (AttributeDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree/dbh");
    query.setEntityDefinition(treeDef);
    query.setAttributeDefinition(dbhDef);
    query.setConditions("dbh > 20");
    final List<Node<?>> nodes = new ArrayList<Node<?>>();
    DataQueryExecutorJob job = jobManager.createJob(DataQueryExecutorJob.class);
    DataQueryExecutorJobInput input = new DataQueryExecutorJobInput(query, Step.ENTRY, new NodeProcessor() {

        public void process(Node<?> node) {
            nodes.add(node);
        }
    });
    job.setInput(input);
    jobManager.start(job, false);
    assertFalse(nodes.isEmpty());
    // first result
    Node<?> node = nodes.get(0);
    assertTrue(node instanceof Attribute);
    CollectRecord record = (CollectRecord) node.getRecord();
    assertEquals(Arrays.asList("10_117"), record.getRootEntityKeyValues());
}
Also used : DataQueryExecutorJobInput(org.openforis.collect.datacleansing.DataQueryExecutorJob.DataQueryExecutorJobInput) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) NodeProcessor(org.openforis.collect.model.NodeProcessor) Attribute(org.openforis.idm.model.Attribute) Node(org.openforis.idm.model.Node) ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 8 with AttributeDefinition

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

the class RelationalSchemaGenerator method addDataObjects.

/**
 * Recursively creates and adds tables and columns
 *
 * @param rs
 * @param parentTable
 * @param defn
 * @throws CollectRdbException
 */
private void addDataObjects(RelationalSchema rs, DataTable table, NodeDefinition defn, Path relativePath) throws CollectRdbException {
    if (defn instanceof EntityDefinition) {
        if (defn.isMultiple()) {
            // Create table for multiple entity
            table = createDataTable(rs, table, defn, relativePath);
            rs.addTable(table);
        } else {
            // just keep a reference
            rs.assignAncestorTable((EntityDefinition) defn);
        }
        // Add child tables and columns
        EntityDefinition entityDefn = (EntityDefinition) defn;
        for (NodeDefinition child : entityDefn.getChildDefinitions()) {
            Path childPath;
            if (defn.isMultiple()) {
                childPath = Path.relative(child.getName());
            } else {
                childPath = relativePath.appendElement(child.getName());
            }
            addDataObjects(rs, table, child, childPath);
        }
    } else if (defn instanceof AttributeDefinition) {
        AttributeDefinition attrDefn = (AttributeDefinition) defn;
        CollectSurvey survey = (CollectSurvey) defn.getSurvey();
        CollectAnnotations annotations = survey.getAnnotations();
        // do not include if it's a calculated attribute and it has not to be included in data export
        if (!attrDefn.isCalculated() || annotations.isIncludedInDataExport(defn)) {
            if (defn.isMultiple()) {
                // Create table for multiple attributes
                table = createDataTable(rs, table, defn, relativePath);
                rs.addTable(table);
                relativePath = Path.relative(".");
            }
            // Add columns for attributes in entity tables or attribute tables
            addDataColumns(rs, table, (AttributeDefinition) defn, relativePath);
        }
    }
}
Also used : Path(org.openforis.idm.path.Path) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) 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) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 9 with AttributeDefinition

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

the class DataQueryGenerator method generateMissingDataQueries.

public List<DataQuery> generateMissingDataQueries(final CollectSurvey survey, final DataQueryType type) {
    final List<DataQuery> result = new ArrayList<DataQuery>();
    survey.getSchema().traverse(new NodeDefinitionVisitor() {

        public void visit(NodeDefinition def) {
            if (def instanceof AttributeDefinition) {
                if (StringUtils.isNotBlank(def.getMinCountExpression())) {
                    DataQuery query = new DataQuery(survey);
                    query.setTitle(String.format(MISSING_DATA_QUERY_TITLE_FORMAT, def.getName()));
                    query.setAttributeDefinition((AttributeDefinition) def);
                    query.setEntityDefinition(def.getParentEntityDefinition());
                    query.setConditions(String.format(MISSING_DATA_CONDITION_FORMAT, def.getName()));
                    query.setType(type);
                    result.add(query);
                }
            }
        }
    });
    return result;
}
Also used : ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor)

Example 10 with AttributeDefinition

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

the class DataQueryGenerator method generateValidationCheckQueries.

public List<DataQuery> generateValidationCheckQueries(CollectSurvey survey) {
    final List<DataQuery> result = new ArrayList<DataQuery>();
    survey.getSchema().traverse(new NodeDefinitionVisitor() {

        public void visit(NodeDefinition def) {
            if (def instanceof AttributeDefinition) {
                for (Check<?> check : ((AttributeDefinition) def).getChecks()) {
                    DataQuery query = createQuery(def, check);
                    result.add(query);
                }
            }
        }
    });
    return result;
}
Also used : ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) Check(org.openforis.idm.metamodel.validation.Check) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor)

Aggregations

AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)107 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)47 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)37 ArrayList (java.util.ArrayList)33 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)27 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)21 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)20 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)18 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)18 CollectSurvey (org.openforis.collect.model.CollectSurvey)17 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)16 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)16 TextAttributeDefinition (org.openforis.idm.metamodel.TextAttributeDefinition)12 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)12 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)11 Schema (org.openforis.idm.metamodel.Schema)10 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)9 Entity (org.openforis.idm.model.Entity)9 Value (org.openforis.idm.model.Value)9 RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)8