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;
}
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);
}
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()));
}
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()));
}
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);
}
Aggregations