Search in sources :

Example 6 with EntityDefinition

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

the class CollectValidator method isRootEntityKey.

private boolean isRootEntityKey(Attribute<?, ?> attribute) {
    AttributeDefinition attrDef = attribute.getDefinition();
    if (attrDef.isKey()) {
        Record record = attribute.getRecord();
        Entity rootEntity = record.getRootEntity();
        EntityDefinition rootEntityDef = rootEntity.getDefinition();
        List<AttributeDefinition> keyAttributeDefs = rootEntityDef.getKeyAttributeDefinitions();
        for (AttributeDefinition keyDef : keyAttributeDefs) {
            if (keyDef.getId() == attrDef.getId()) {
                return true;
            }
        }
    }
    return false;
}
Also used : Entity(org.openforis.idm.model.Entity) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) Record(org.openforis.idm.model.Record) CollectRecord(org.openforis.collect.model.CollectRecord)

Example 7 with EntityDefinition

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

the class Mondrian4SchemaGenerator method createCube.

private Cube createCube(DataTable dataTable) {
    NodeDefinition nodeDef = dataTable.getNodeDefinition();
    Cube cube = new Cube();
    cube.name = nodeDef.getName();
    MeasureGroups measureGroups = new MondrianDef.MeasureGroups();
    MeasureGroup measureGroup = new MeasureGroup();
    measureGroup.name = cube.name;
    Measures measures = new Measures();
    List<Measure> measureList = createMeasures(dataTable);
    measures.list().addAll(measureList);
    measureGroup.children.add(measures);
    measureGroup.table = dataTable.getName();
    DimensionLinks dimensionLinks = new DimensionLinks();
    measureGroup.children.add(dimensionLinks);
    measureGroups.list().add(measureGroup);
    cube.children.add(measureGroups);
    if (nodeDef instanceof EntityDefinition) {
        Dimensions dimensions = new Dimensions();
        Queue<NodeDefinition> queue = new LinkedList<NodeDefinition>();
        queue.addAll(((EntityDefinition) nodeDef).getChildDefinitions());
        while (!queue.isEmpty()) {
            NodeDefinition def = queue.poll();
            if (def instanceof AttributeDefinition) {
                AttributeDefinition attrDef = (AttributeDefinition) def;
                Dimension dimension = createDimension(dataTable, attrDef);
                if (dimension != null) {
                    dimensions.list().add(dimension);
                    // add dimension link
                    DimensionLink dimensionLink = createDimensionLink(dimension, attrDef);
                    dimensionLinks.list().add(dimensionLink);
                }
            } else if (!def.isMultiple()) {
                queue.addAll(((EntityDefinition) def).getChildDefinitions());
            }
        }
        cube.children.add(dimensions);
    }
    return cube;
}
Also used : MeasureGroup(mondrian.olap.MondrianDef.MeasureGroup) DimensionLinks(mondrian.olap.MondrianDef.DimensionLinks) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) Dimensions(mondrian.olap.MondrianDef.Dimensions) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) Dimension(mondrian.olap.MondrianDef.Dimension) LinkedList(java.util.LinkedList) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Measures(mondrian.olap.MondrianDef.Measures) Cube(mondrian.olap.MondrianDef.Cube) Measure(mondrian.olap.MondrianDef.Measure) MeasureGroups(mondrian.olap.MondrianDef.MeasureGroups) DimensionLink(mondrian.olap.MondrianDef.DimensionLink)

Example 8 with EntityDefinition

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

the class RelationalTransformer method initDataTableTransformations.

/**
 * Recursively init table transformations
 * @param defn
 */
private void initDataTableTransformations(EntityDefinition defn) {
    List<NodeDefinition> children = defn.getChildDefinitions();
    for (NodeDefinition child : children) {
        if (child instanceof EntityDefinition) {
            initDataTableTransformations((EntityDefinition) child);
        }
    }
    if (defn.isMultiple()) {
        Transformation xform = Transformation.createDefaultTransformation(defn);
        Path path = (Path) xform.getRowAxis();
        dataTransforms.put(path, xform);
        System.out.println(path);
    }
}
Also used : Path(org.openforis.idm.path.Path) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Transformation(org.openforis.idm.transform2.Transformation) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 9 with EntityDefinition

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

the class RelationalTransformer method initDataTableTransformations.

private void initDataTableTransformations() {
    this.dataTransforms = new LinkedHashMap<Path, Transformation>();
    this.schema = survey.getSchema();
    List<EntityDefinition> roots = schema.getRootEntityDefinitions();
    for (EntityDefinition root : roots) {
        initDataTableTransformations(root);
    }
}
Also used : Path(org.openforis.idm.path.Path) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Transformation(org.openforis.idm.transform2.Transformation)

Example 10 with EntityDefinition

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

the class DataCleansingChainIntegrationTest method testSimpleChain.

@Test
public void testSimpleChain() {
    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");
    NumberAttributeDefinition dbhDef = (NumberAttributeDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree/dbh");
    query.setTitle("Find trees with invalid DBH");
    query.setEntityDefinition(treeDef);
    query.setAttributeDefinition(dbhDef);
    query.setConditions("dbh > 20");
    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.ATTRIBUTE);
    // set dbh = 20
    updateValue.setFixExpression("20");
    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);
    job.setActiveUser(user);
    jobManager.start(job, false);
    int finalCount = countResults(query);
    assertEquals(0, finalCount);
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

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