Search in sources :

Example 1 with TaxonAttributeDefinition

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

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

the class SpeciesService method deleteReferencingAttributes.

protected void deleteReferencingAttributes(CollectTaxonomy taxonomy) {
    List<TaxonAttributeDefinition> defns = getTaxonAttributeDefinitionsForDesignerSurvey(taxonomy.getName());
    if (!defns.isEmpty()) {
        for (TaxonAttributeDefinition defn : defns) {
            EntityDefinition parent = (EntityDefinition) defn.getParentDefinition();
            parent.removeChildDefinition(defn);
        }
        sessionManager.saveActiveDesignerSurvey();
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition)

Example 3 with TaxonAttributeDefinition

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

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

the class SpeciesManager method extractQualifierValues.

protected String[] extractQualifierValues(TaxonAttribute attr) {
    TaxonAttributeDefinition defn = attr.getDefinition();
    List<String> qualifiers = defn.getQualifiers();
    String[] qualifierValues = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
        qualifierValues = new String[qualifiers.size()];
        Entity parent = attr.getParent();
        for (int i = 0; i < qualifiers.size(); i++) {
            String qualifierExpr = qualifiers.get(i);
            try {
                ModelPathExpression expression = expressionFactory.createModelPathExpression(qualifierExpr);
                CodeAttribute code = (CodeAttribute) expression.evaluate(parent, null);
                String qualifierValue = code.getValue().getCode();
                qualifierValues[i] = qualifierValue;
            } catch (Exception e) {
                if (log.isWarnEnabled()) {
                    log.warn("Error evaluating taxon qualifiers: ", e);
                }
                break;
            }
        }
    }
    return qualifierValues;
}
Also used : Entity(org.openforis.idm.model.Entity) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) CodeAttribute(org.openforis.idm.model.CodeAttribute) ModelPathExpression(org.openforis.idm.model.expression.ModelPathExpression)

Example 5 with TaxonAttributeDefinition

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

TaxonAttributeDefinition (org.openforis.idm.metamodel.TaxonAttributeDefinition)10 CollectSurvey (org.openforis.collect.model.CollectSurvey)4 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)4 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)3 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)2 CodeTable (org.openforis.collect.relational.model.CodeTable)2 DataTable (org.openforis.collect.relational.model.DataTable)2 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)2 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)2 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)2 Schema (org.openforis.idm.metamodel.Schema)2 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)1 CollectRecord (org.openforis.collect.model.CollectRecord)1 Step (org.openforis.collect.model.CollectRecord.Step)1 CodeValueFKColumn (org.openforis.collect.relational.model.CodeValueFKColumn)1 DataColumn (org.openforis.collect.relational.model.DataColumn)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1