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