use of org.openforis.idm.model.CodeAttribute in project collect by openforis.
the class DatabaseExternalCodeListProvider method getItem.
@Override
public ExternalCodeListItem getItem(CodeAttribute attribute) {
CodeAttributeDefinition defn = attribute.getDefinition();
CodeList list = defn.getList();
List<NameValueEntry> filters = new ArrayList<NameValueEntry>();
addSurveyFilter(list, filters);
CodeAttribute codeParent = attribute.getCodeParent();
while (codeParent != null) {
String colName = getLevelKeyColumnName(codeParent);
String codeValue = getCodeValue(codeParent);
filters.add(new NameValueEntry(colName, codeValue));
codeParent = codeParent.getCodeParent();
}
String colName = getLevelKeyColumnName(attribute);
String codeValue = getCodeValue(attribute);
filters.add(new NameValueEntry(colName, codeValue));
int level = defn.getLevelPosition();
List<NameValueEntry> emptyNextLevelsFilters = createEmptyNextLevelFilters(list, level);
filters.addAll(emptyNextLevelsFilters);
Map<String, String> row = dynamicTableDao.loadRow(list.getLookupTable(), filters.toArray(new NameValueEntry[filters.size()]));
if (row == null) {
return null;
} else {
ExternalCodeListItem result = parseRow(row, list, level);
return result;
}
}
use of org.openforis.idm.model.CodeAttribute in project collect by openforis.
the class CollectValidator method isReasonBlankAlwaysSpecified.
static boolean isReasonBlankAlwaysSpecified(Attribute<?, ?> attribute) {
int fieldCount = 0;
// ignore unit for numeric attributes
if (attribute instanceof NumberAttribute || attribute instanceof CodeAttribute) {
fieldCount = 1;
} else if (attribute instanceof NumericRangeAttribute) {
fieldCount = 2;
} else {
fieldCount = attribute.getFieldCount();
}
AttributeDefinition defn = attribute.getDefinition();
CollectSurvey survey = (CollectSurvey) defn.getSurvey();
UIOptions uiOptions = survey.getUIOptions();
for (int i = 0; i < fieldCount; i++) {
Field<?> field = attribute.getField(i);
boolean visible = uiOptions.isVisibleField(defn, field.getName());
if (visible) {
FieldSymbol symbol = FieldSymbol.valueOf(field.getSymbol());
if (symbol == null || !symbol.isReasonBlank()) {
return false;
}
}
}
return true;
}
use of org.openforis.idm.model.CodeAttribute in project collect by openforis.
the class ModelPathExpressionTest method testThis.
@Test
public void testThis() throws InvalidExpressionException {
Entity plot = EntityBuilder.addEntity(cluster, "plot");
CodeAttribute plotNum = EntityBuilder.addValue(plot, "no", new Code("1"));
List<Node<?>> plotNums = iterateExpression("$this", plot, plotNum);
Assert.assertEquals(1, plotNums.size());
}
use of org.openforis.idm.model.CodeAttribute in project collect by openforis.
the class RequiredExpressionTest method testFalse.
@Test
public void testFalse() throws InvalidExpressionException {
CodeAttribute region = EntityBuilder.addValue(cluster, "region", new Code("004"));
String expr = "false()";
boolean b = evaluateExpression(expr, region);
Assert.assertFalse(b);
}
use of org.openforis.idm.model.CodeAttribute in project collect by openforis.
the class CodeAttributeMapper method setFields.
@Override
void setFields(Node<?> node, InsertSetStep<?> insert) {
Code value = ((CodeAttribute) node).getValue();
if (value != null) {
insert.set(DATA.TEXT1, value.getCode());
insert.set(DATA.TEXT2, value.getQualifier());
}
}
Aggregations