Search in sources :

Example 61 with Code

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

the class CodeListManager method getInternalCodeListItem.

protected CodeListItem getInternalCodeListItem(CodeAttribute attribute) {
    Code code = attribute.getValue();
    if (code != null) {
        String codeValue = code.getCode();
        if (StringUtils.isNotBlank(codeValue)) {
            ModelVersion currentVersion = attribute.getRecord().getVersion();
            CodeAttributeDefinition definition = attribute.getDefinition();
            String parentExpression = definition.getParentExpression();
            if (StringUtils.isBlank(parentExpression)) {
                return getCodeListItem(definition.getList().getItems(), codeValue, currentVersion);
            } else {
                CodeAttribute codeParent = attribute.getCodeParent();
                if (codeParent != null) {
                    CodeListItem codeListItemParent = loadItemByAttribute(codeParent);
                    if (codeListItemParent != null) {
                        return getCodeListItem(codeListItemParent.getChildItems(), codeValue, currentVersion);
                    }
                }
            }
        }
    }
    return null;
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeAttribute(org.openforis.idm.model.CodeAttribute) ModelVersion(org.openforis.idm.metamodel.ModelVersion) ExternalCodeListItem(org.openforis.idm.metamodel.ExternalCodeListItem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) Code(org.openforis.idm.model.Code)

Example 62 with Code

use of org.openforis.idm.model.Code 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 63 with Code

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

the class CustomCheckTest method testPassLtEqWithCondition1.

@Test
public void testPassLtEqWithCondition1() {
    Entity plot = EntityBuilder.addEntity(cluster, "plot");
    Entity tree = EntityBuilder.addEntity(plot, "tree");
    EntityBuilder.addValue(tree, "health", new Code("1"));
    RealAttribute totalHeight = EntityBuilder.addValue(tree, "total_height", 16.0);
    EntityBuilder.addValue(tree, "dbh", 16.0);
    ValidationResults results = validate(totalHeight);
    assertFalse(containsCustomCheck(results.getWarnings()));
}
Also used : Entity(org.openforis.idm.model.Entity) RealAttribute(org.openforis.idm.model.RealAttribute) Code(org.openforis.idm.model.Code) Test(org.junit.Test)

Example 64 with Code

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

the class CustomCheckTest method testPassLtEqWithCondition.

@Test
public void testPassLtEqWithCondition() {
    Entity plot = EntityBuilder.addEntity(cluster, "plot");
    Entity tree = EntityBuilder.addEntity(plot, "tree");
    RealAttribute totalHeight = EntityBuilder.addValue(tree, "total_height", 2.0);
    EntityBuilder.addValue(tree, "dbh", 16.5);
    EntityBuilder.addValue(tree, "health", new Code("2"));
    ValidationResults results = validate(totalHeight);
    assertFalse(containsCustomCheck(results.getWarnings()));
}
Also used : Entity(org.openforis.idm.model.Entity) RealAttribute(org.openforis.idm.model.RealAttribute) Code(org.openforis.idm.model.Code) Test(org.junit.Test)

Example 65 with Code

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

the class CustomCheckTest method testCustomMessageWithoutExpressions.

@Test
public void testCustomMessageWithoutExpressions() {
    Entity plot = EntityBuilder.addEntity(cluster, "plot");
    Entity tree = EntityBuilder.addEntity(plot, "tree");
    RealAttribute totalHeight = EntityBuilder.addValue(tree, "total_height", 2.0);
    RealAttribute dbh = EntityBuilder.addValue(tree, "dbh", 16.5);
    EntityBuilder.addValue(tree, "health", new Code("1"));
    ValidationResults results = validate(dbh);
    CustomCheck check = (CustomCheck) results.getWarnings().get(0).getValidator();
    String message = check.getMessageWithEvaluatedExpressions(totalHeight);
    Assert.assertEquals("Unusual relationship between DBH and total height.", message);
}
Also used : Entity(org.openforis.idm.model.Entity) RealAttribute(org.openforis.idm.model.RealAttribute) Code(org.openforis.idm.model.Code) Test(org.junit.Test)

Aggregations

Code (org.openforis.idm.model.Code)68 Test (org.junit.Test)45 Entity (org.openforis.idm.model.Entity)35 CodeAttribute (org.openforis.idm.model.CodeAttribute)16 AbstractTest (org.openforis.idm.AbstractTest)14 Coordinate (org.openforis.idm.model.Coordinate)14 Date (org.openforis.idm.model.Date)10 Time (org.openforis.idm.model.Time)10 CollectRecord (org.openforis.collect.model.CollectRecord)9 RealAttribute (org.openforis.idm.model.RealAttribute)9 GregorianCalendar (java.util.GregorianCalendar)8 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)6 CodeList (org.openforis.idm.metamodel.CodeList)6 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)5 CoordinateAttribute (org.openforis.idm.model.CoordinateAttribute)5 RecordUpdater (org.openforis.collect.model.RecordUpdater)4 ModelVersion (org.openforis.idm.metamodel.ModelVersion)4 ValidationResults (org.openforis.idm.metamodel.validation.ValidationResults)4 Node (org.openforis.idm.model.Node)4 User (org.openforis.collect.model.User)3