Search in sources :

Example 11 with EntityDefinition

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

the class DataCleansingChainIntegrationTest method testUpdateFieldChain.

@Test
public void testUpdateFieldChain() {
    DataCleansingChain chain = new DataCleansingChain(survey);
    chain.setTitle("Test chain");
    chain.setDescription("This is just a test");
    DataQuery query = new DataQuery(survey);
    EntityDefinition treeDef = (EntityDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree");
    TaxonAttributeDefinition speciesDef = (TaxonAttributeDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree/species");
    query.setTitle("Find trees with unlisted species");
    query.setEntityDefinition(treeDef);
    query.setAttributeDefinition(speciesDef);
    query.setConditions("species/@code = 'UNL'");
    dataQueryManager.save(query, user);
    int initialCount = countResults(query);
    assertEquals(1, initialCount);
    DataCleansingStep step = new DataCleansingStep(survey);
    step.setTitle("Step 1");
    step.setDescription("This is the step 1");
    step.setQuery(query);
    {
        DataCleansingStepValue updateValue = new DataCleansingStepValue();
        updateValue.setUpdateType(UpdateType.FIELD);
        updateValue.setCondition("idm:blank(species/@code)");
        updateValue.setFieldFixExpressions(Arrays.asList("'UNL'", "'Will not be applied'"));
        step.addUpdateValue(updateValue);
    }
    {
        DataCleansingStepValue updateValue = new DataCleansingStepValue();
        updateValue.setUpdateType(UpdateType.FIELD);
        updateValue.setFieldFixExpressions(Arrays.asList("'PIN'", "'Pinus Sp.'"));
        step.addUpdateValue(updateValue);
    }
    stepManager.save(step, user);
    chain.addStep(step);
    chainManager.save(chain, user);
    DataCleansingChainExecutorJob job = jobManager.createJob(DataCleansingChainExecutorJob.class);
    job.setSurvey(survey);
    job.setChain(chain);
    job.setRecordStep(Step.ENTRY);
    jobManager.start(job, false);
    int finalCount = countResults(query);
    assertEquals(0, finalCount);
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 12 with EntityDefinition

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

the class DataReportGeneratorIntegrationTest method testSimpleErrorReport.

@Test
public void testSimpleErrorReport() {
    EntityDefinition treeDef = (EntityDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree");
    NumberAttributeDefinition dbhDef = (NumberAttributeDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree/dbh");
    DataQuery query = dataQuery().title("Find trees with invalid DBH").entity(treeDef).attribute(dbhDef).conditions("dbh > 20").type(invalidAttributeErrorType).severity(ErrorSeverity.ERROR).build();
    dataQueryManager.save(query, adminUser);
    DataQueryGroup queryGroup = new DataQueryGroup(survey);
    queryGroup.setTitle("Simple query group");
    queryGroup.addQuery(query);
    dataQueryGroupManager.save(queryGroup, adminUser);
    DataReportGeneratorJob job = jobManager.createJob(DataReportGeneratorJob.class);
    job.setQueryGroup(queryGroup);
    job.setRecordStep(Step.ENTRY);
    job.setActiveUser(adminUser);
    jobManager.start(job, false);
    DataReport report = job.getReport();
    DataReport reloadedReport = dataReportManager.loadById(survey, report.getId());
    List<DataReportItem> items = dataReportManager.loadItems(reloadedReport, 0, 100);
    assertFalse(items.isEmpty());
    assertEquals(1, items.size());
    DataReportItem item = items.get(0);
    CollectRecord record = recordManager.load(survey, item.getRecordId());
    assertEquals(Arrays.asList("10_117"), record.getRootEntityKeyValues());
    assertEquals(new RealValue(30.0d, dbhDef.getDefaultUnit()), item.extractAttributeValue());
}
Also used : RealValue(org.openforis.idm.model.RealValue) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) Test(org.junit.Test)

Example 13 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition 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 14 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition 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 15 with EntityDefinition

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

the class RelationalSchemaGenerator method addDataTables.

private void addDataTables(RelationalSchema rs) throws CollectRdbException {
    Survey survey = rs.getSurvey();
    Schema schema = survey.getSchema();
    // Recursively create tables, columns and constraints
    List<EntityDefinition> roots = schema.getRootEntityDefinitions();
    for (EntityDefinition root : roots) {
        Path relativePath = Path.relative(root.getName());
        addDataObjects(rs, null, root, relativePath);
    }
}
Also used : Path(org.openforis.idm.path.Path) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Survey(org.openforis.idm.metamodel.Survey) CollectSurvey(org.openforis.collect.model.CollectSurvey) Schema(org.openforis.idm.metamodel.Schema)

Aggregations

EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)235 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)70 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)47 Schema (org.openforis.idm.metamodel.Schema)46 ArrayList (java.util.ArrayList)44 Test (org.junit.Test)38 Entity (org.openforis.idm.model.Entity)36 CollectRecord (org.openforis.collect.model.CollectRecord)30 CollectSurvey (org.openforis.collect.model.CollectSurvey)28 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)24 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)24 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)19 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)18 UITab (org.openforis.collect.metamodel.ui.UITab)16 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)14 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)13 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)12 RecordFilter (org.openforis.collect.model.RecordFilter)11 SurveyObject (org.openforis.idm.metamodel.SurveyObject)10 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)9