Search in sources :

Example 1 with CodeAttribute

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;
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) ExternalCodeListItem(org.openforis.idm.metamodel.ExternalCodeListItem) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeAttribute(org.openforis.idm.model.CodeAttribute) ArrayList(java.util.ArrayList) NameValueEntry(org.openforis.collect.model.NameValueEntry)

Example 2 with CodeAttribute

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;
}
Also used : CodeAttribute(org.openforis.idm.model.CodeAttribute) FieldSymbol(org.openforis.collect.model.FieldSymbol) NumericRangeAttribute(org.openforis.idm.model.NumericRangeAttribute) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NumberAttribute(org.openforis.idm.model.NumberAttribute) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 3 with CodeAttribute

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());
}
Also used : Entity(org.openforis.idm.model.Entity) CodeAttribute(org.openforis.idm.model.CodeAttribute) Node(org.openforis.idm.model.Node) Code(org.openforis.idm.model.Code) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 4 with CodeAttribute

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);
}
Also used : CodeAttribute(org.openforis.idm.model.CodeAttribute) Code(org.openforis.idm.model.Code) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 5 with CodeAttribute

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());
    }
}
Also used : CodeAttribute(org.openforis.idm.model.CodeAttribute) Code(org.openforis.idm.model.Code)

Aggregations

CodeAttribute (org.openforis.idm.model.CodeAttribute)28 Code (org.openforis.idm.model.Code)16 Test (org.junit.Test)13 Entity (org.openforis.idm.model.Entity)12 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)7 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)5 CodeList (org.openforis.idm.metamodel.CodeList)5 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)5 ModelVersion (org.openforis.idm.metamodel.ModelVersion)5 CollectRecord (org.openforis.collect.model.CollectRecord)4 CodeListItem (org.openforis.idm.metamodel.CodeListItem)4 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)4 Record (org.openforis.idm.model.Record)4 ArrayList (java.util.ArrayList)3 CollectSurvey (org.openforis.collect.model.CollectSurvey)3 AbstractTest (org.openforis.idm.AbstractTest)3 PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)3 Node (org.openforis.idm.model.Node)3 List (java.util.List)2 CSVDataImportSettings (org.openforis.collect.io.data.csv.CSVDataImportSettings)2