Search in sources :

Example 26 with CodeAttribute

use of org.openforis.idm.model.CodeAttribute in project collect by openforis.

the class CodeListManager method getCodeParent.

protected CodeAttribute getCodeParent(Entity context, CodeAttributeDefinition def) {
    try {
        Survey survey = context.getSurvey();
        SurveyContext surveyContext = survey.getContext();
        ExpressionEvaluator expressionEvaluator = surveyContext.getExpressionEvaluator();
        String parentExpr = def.getParentExpression();
        Node<?> parentNode = expressionEvaluator.evaluateNode(context, null, parentExpr);
        if (parentNode != null && parentNode instanceof CodeAttribute) {
            return (CodeAttribute) parentNode;
        } else {
            return null;
        }
    } catch (Exception e) {
        return null;
    }
}
Also used : Survey(org.openforis.idm.metamodel.Survey) CollectSurvey(org.openforis.collect.model.CollectSurvey) CodeAttribute(org.openforis.idm.model.CodeAttribute) ExpressionEvaluator(org.openforis.idm.model.expression.ExpressionEvaluator) SurveyContext(org.openforis.idm.metamodel.SurveyContext) CodeListImportException(org.openforis.collect.io.exception.CodeListImportException) IdmlParseException(org.openforis.idm.metamodel.xml.IdmlParseException) FileNotFoundException(java.io.FileNotFoundException)

Example 27 with CodeAttribute

use of org.openforis.idm.model.CodeAttribute in project collect by openforis.

the class ComparisonCheckTest method testCodeGtConstant.

@Test
public void testCodeGtConstant() throws Exception {
    ComparisonCheck check = new ComparisonCheck();
    check.setGreaterThanExpression("-1");
    CodeAttribute region = EntityBuilder.addValue(cluster, "region", new Code("001"));
    ValidationResultFlag result = check.evaluate(region);
    assertEquals(OK, result);
}
Also used : CodeAttribute(org.openforis.idm.model.CodeAttribute) Code(org.openforis.idm.model.Code) Test(org.junit.Test)

Example 28 with CodeAttribute

use of org.openforis.idm.model.CodeAttribute in project collect by openforis.

the class EntityKeyValidationTest method test.

@Test
public void test() {
    Entity plot1 = EntityBuilder.addEntity(cluster, "plot");
    CodeAttribute plotNo1 = EntityBuilder.addValue(plot1, "no", new Code("1"));
    Entity plot2 = EntityBuilder.addEntity(cluster, "plot");
    CodeAttribute plotNo2 = EntityBuilder.addValue(plot2, "no", new Code("1"));
    ValidationResults results1 = validate(plotNo1);
    assertTrue(containsEntityKeyValidator(results1.getErrors()));
    ValidationResults results2 = validate(plotNo2);
    assertTrue(containsEntityKeyValidator(results2.getErrors()));
}
Also used : Entity(org.openforis.idm.model.Entity) CodeAttribute(org.openforis.idm.model.CodeAttribute) Code(org.openforis.idm.model.Code) Test(org.junit.Test)

Aggregations

CodeAttribute (org.openforis.idm.model.CodeAttribute)28 Code (org.openforis.idm.model.Code)16 Test (org.junit.Test)13 Entity (org.openforis.idm.model.Entity)12 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)7 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)5 CodeList (org.openforis.idm.metamodel.CodeList)5 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)5 ModelVersion (org.openforis.idm.metamodel.ModelVersion)5 CollectRecord (org.openforis.collect.model.CollectRecord)4 CodeListItem (org.openforis.idm.metamodel.CodeListItem)4 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)4 Record (org.openforis.idm.model.Record)4 ArrayList (java.util.ArrayList)3 CollectSurvey (org.openforis.collect.model.CollectSurvey)3 AbstractTest (org.openforis.idm.AbstractTest)3 PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)3 Node (org.openforis.idm.model.Node)3 List (java.util.List)2 CSVDataImportSettings (org.openforis.collect.io.data.csv.CSVDataImportSettings)2