use of org.openforis.idm.model.CodeAttribute in project collect by openforis.
the class CollectRecordIntegrationTest method testMultipleCodeListLevelValidation.
@Test
public void testMultipleCodeListLevelValidation() {
CollectRecord record = createTestMultipleCodeListLevelRecord();
assertEquals(Integer.valueOf(0), record.getErrors());
assertEquals(Integer.valueOf(0), record.getWarnings());
Entity rootEntity = record.getRootEntity();
CodeAttribute code1 = (CodeAttribute) rootEntity.getChild("code1", 0);
CodeAttribute code2 = (CodeAttribute) rootEntity.getChild("code2", 0);
CodeAttribute code3 = (CodeAttribute) rootEntity.getChild("code3", 0);
recordUpdater.updateAttribute(code1, new Code("WRONG"));
assertEquals(Integer.valueOf(1), record.getErrors());
assertEquals(Integer.valueOf(2), record.getWarnings());
checkHasError(record, code1.getInternalId(), CodeValidator.class);
checkHasWarning(record, code2.getInternalId(), CodeParentValidator.class);
checkHasWarning(record, code3.getInternalId(), CodeParentValidator.class);
recordUpdater.updateAttribute(code1, new Code("A"));
assertEquals(Integer.valueOf(0), record.getErrors());
assertEquals(Integer.valueOf(0), record.getWarnings());
recordUpdater.updateAttribute(code2, new Code("WRONG"));
assertEquals(Integer.valueOf(1), record.getErrors());
assertEquals(Integer.valueOf(1), record.getWarnings());
checkHasError(record, code2.getInternalId(), CodeValidator.class);
checkHasWarning(record, code3.getInternalId(), CodeParentValidator.class);
}
use of org.openforis.idm.model.CodeAttribute in project collect by openforis.
the class RequiredExpressionTest method testTrue.
@Test
public void testTrue() throws InvalidExpressionException {
CodeAttribute region = EntityBuilder.addValue(cluster, "region", new Code("004"));
String expr = "true()";
boolean b = evaluateExpression(expr, region);
Assert.assertTrue(b);
}
use of org.openforis.idm.model.CodeAttribute in project collect by openforis.
the class CodeValueFKColumnValueExtractor method extractValue.
@Override
public Object extractValue(Node<?> context) {
CodeAttributeDefinition defn = (CodeAttributeDefinition) column.getNodeDefinition();
Node<?> valNode = super.extractValueNode(context);
if (valNode != null && valNode instanceof CodeAttribute) {
return extractValue((CodeAttribute) valNode);
} else if (column.getDefaultCodeValue() != null) {
ModelVersion version = context.getRecord().getVersion();
return getDefaultCodeItemId(((CodeAttributeDefinition) defn).getList(), version);
} else {
return null;
}
}
use of org.openforis.idm.model.CodeAttribute 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.CodeAttribute in project collect by openforis.
the class CodeListManager method loadValidItems.
public <T extends CodeListItem> List<T> loadValidItems(Entity parent, CodeAttributeDefinition def) {
List<T> items = null;
CodeList list = def.getList();
if (StringUtils.isEmpty(def.getParentExpression())) {
items = loadRootItems(list);
} else {
CodeAttribute parentCodeAttribute = getCodeParent(parent, def);
if (parentCodeAttribute != null) {
CodeListItem parentCodeListItem = loadItemByAttribute(parentCodeAttribute);
if (parentCodeListItem != null) {
items = loadChildItems(parentCodeListItem);
}
}
}
Record record = parent.getRecord();
ModelVersion version = record.getVersion();
return filterApplicableItems(items, version);
}
Aggregations