Search in sources :

Example 1 with NameValueEntry

use of org.openforis.collect.model.NameValueEntry in project collect by openforis.

the class DatabaseExternalCodeListProvider method addSurveyFilter.

protected NameValueEntry[] addSurveyFilter(CodeList list, NameValueEntry... filters) {
    NameValueEntry surveyFilter = createSurveyFilter(list);
    NameValueEntry[] newFilters = Arrays.copyOf(filters, filters.length + 1);
    newFilters[filters.length] = surveyFilter;
    return newFilters;
}
Also used : NameValueEntry(org.openforis.collect.model.NameValueEntry)

Example 2 with NameValueEntry

use of org.openforis.collect.model.NameValueEntry in project collect by openforis.

the class DatabaseExternalCodeListProvider method visitChildItems.

@Override
public void visitChildItems(final ExternalCodeListItem item, final Visitor<CodeListItem> visitor) {
    final CodeList list = item.getCodeList();
    int itemLevel = item.getLevel();
    final int childrenLevel = itemLevel + 1;
    if (childrenLevel > list.getHierarchy().size()) {
        return;
    }
    List<NameValueEntry> filters = createChildItemsFilters(item);
    String childrenKeyColName = getLevelKeyColumnName(list, childrenLevel);
    String[] notNullColumns = new String[] { childrenKeyColName };
    dynamicTableDao.visitRows(list.getLookupTable(), filters.toArray(new NameValueEntry[filters.size()]), notNullColumns, new Visitor<Map<String, String>>() {

        public void visit(Map<String, String> row) {
            ExternalCodeListItem item = parseRow(row, list, childrenLevel);
            visitor.visit(item);
        }
    });
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) ExternalCodeListItem(org.openforis.idm.metamodel.ExternalCodeListItem) HashMap(java.util.HashMap) Map(java.util.Map) NameValueEntry(org.openforis.collect.model.NameValueEntry)

Example 3 with NameValueEntry

use of org.openforis.collect.model.NameValueEntry in project collect by openforis.

the class DatabaseExternalCodeListProvider method addSurveyFilter.

protected void addSurveyFilter(CodeList list, List<NameValueEntry> filters) {
    NameValueEntry surveyFilter = createSurveyFilter(list);
    filters.add(surveyFilter);
}
Also used : NameValueEntry(org.openforis.collect.model.NameValueEntry)

Example 4 with NameValueEntry

use of org.openforis.collect.model.NameValueEntry 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 5 with NameValueEntry

use of org.openforis.collect.model.NameValueEntry in project collect by openforis.

the class DatabaseExternalCodeListProvider method getRootItem.

public ExternalCodeListItem getRootItem(CodeList list, String code) {
    List<NameValueEntry> filters = new ArrayList<NameValueEntry>();
    addSurveyFilter(list, filters);
    List<NameValueEntry> emptyNextLevelsFilters = createEmptyNextLevelFilters(list, 1);
    filters.addAll(emptyNextLevelsFilters);
    String firstLevelKeyColName = getLevelKeyColumnName(list, 1);
    NameValueEntry itemFilter = new NameValueEntry(firstLevelKeyColName, code);
    filters.add(itemFilter);
    Map<String, String> row = dynamicTableDao.loadRow(list.getLookupTable(), filters.toArray(new NameValueEntry[0]));
    return parseRow(row, list, 1);
}
Also used : ArrayList(java.util.ArrayList) NameValueEntry(org.openforis.collect.model.NameValueEntry)

Aggregations

NameValueEntry (org.openforis.collect.model.NameValueEntry)16 ArrayList (java.util.ArrayList)8 CodeList (org.openforis.idm.metamodel.CodeList)7 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 HashSet (java.util.HashSet)1 Entry (java.util.Map.Entry)1 Condition (org.jooq.Condition)1 TableField (org.jooq.TableField)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 LookupRecord (org.openforis.collect.persistence.jooq.tables.records.LookupRecord)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 CodeListLevel (org.openforis.idm.metamodel.CodeListLevel)1 CodeAttribute (org.openforis.idm.model.CodeAttribute)1