Search in sources :

Example 11 with NameValueEntry

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

the class DatabaseExternalCodeListProvider method getParentKeys.

protected Collection<NameValueEntry> getParentKeys(ExternalCodeListItem item) {
    Set<NameValueEntry> result = new HashSet<NameValueEntry>();
    Map<String, String> parentKeyByLevel = item.getParentKeyByLevel();
    Set<Entry<String, String>> entrySet = parentKeyByLevel.entrySet();
    for (Entry<String, String> entry : entrySet) {
        NameValueEntry keyValuePair = new NameValueEntry(entry);
        result.add(keyValuePair);
    }
    return result;
}
Also used : NameValueEntry(org.openforis.collect.model.NameValueEntry) Entry(java.util.Map.Entry) NameValueEntry(org.openforis.collect.model.NameValueEntry) HashSet(java.util.HashSet)

Example 12 with NameValueEntry

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

the class DatabaseExternalCodeListProvider method getChildItems.

@Override
public List<ExternalCodeListItem> getChildItems(ExternalCodeListItem item) {
    CodeList list = item.getCodeList();
    int itemLevel = item.getLevel();
    int childrenLevel = itemLevel + 1;
    if (childrenLevel > list.getHierarchy().size()) {
        return Collections.emptyList();
    }
    List<NameValueEntry> filters = createChildItemsFilters(item);
    String childrenKeyColName = getLevelKeyColumnName(list, childrenLevel);
    String[] notNullColumns = new String[] { childrenKeyColName };
    List<Map<String, String>> rows = dynamicTableDao.loadRows(list.getLookupTable(), filters.toArray(new NameValueEntry[filters.size()]), notNullColumns);
    List<ExternalCodeListItem> result = new ArrayList<ExternalCodeListItem>();
    for (Map<String, String> row : rows) {
        ExternalCodeListItem child = parseRow(row, list, childrenLevel);
        result.add(child);
    }
    return result;
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) ExternalCodeListItem(org.openforis.idm.metamodel.ExternalCodeListItem) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) NameValueEntry(org.openforis.collect.model.NameValueEntry)

Example 13 with NameValueEntry

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

the class DatabaseExternalCodeListProvider method getRootItems.

@Override
public List<ExternalCodeListItem> getRootItems(CodeList list) {
    List<NameValueEntry> filters = new ArrayList<NameValueEntry>();
    addSurveyFilter(list, filters);
    List<NameValueEntry> emptyNextLevelsFilters = createEmptyNextLevelFilters(list, 1);
    filters.addAll(emptyNextLevelsFilters);
    List<Map<String, String>> rows = dynamicTableDao.loadRows(list.getLookupTable(), filters.toArray(new NameValueEntry[0]));
    List<ExternalCodeListItem> result = new ArrayList<ExternalCodeListItem>();
    for (Map<String, String> row : rows) {
        ExternalCodeListItem item = parseRow(row, list, 1);
        result.add(item);
    }
    return result;
}
Also used : ExternalCodeListItem(org.openforis.idm.metamodel.ExternalCodeListItem) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) NameValueEntry(org.openforis.collect.model.NameValueEntry)

Example 14 with NameValueEntry

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

the class DatabaseExternalCodeListProvider method getChildItem.

public ExternalCodeListItem getChildItem(ExternalCodeListItem item, String code) {
    CodeList list = item.getCodeList();
    List<NameValueEntry> filters = createChildItemsFilters(item);
    int itemLevel = item.getLevel();
    int childrenLevel = itemLevel + 1;
    String childrenLevelColName = getLevelKeyColumnName(list, childrenLevel);
    NameValueEntry codeFilter = new NameValueEntry(childrenLevelColName, code);
    filters.add(codeFilter);
    Map<String, String> row = dynamicTableDao.loadRow(list.getLookupTable(), filters.toArray(new NameValueEntry[0]));
    return parseRow(row, list, childrenLevel);
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) NameValueEntry(org.openforis.collect.model.NameValueEntry)

Example 15 with NameValueEntry

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

the class DatabaseExternalCodeListProvider method hasChildItems.

public boolean hasChildItems(ExternalCodeListItem item) {
    CodeList list = item.getCodeList();
    List<NameValueEntry> filters = createChildItemsFilters(item);
    int itemLevel = item.getLevel();
    int childrenLevel = itemLevel + 1;
    String childrenKeyColName = getLevelKeyColumnName(list, childrenLevel);
    String[] notNullColumns = new String[] { childrenKeyColName };
    return dynamicTableDao.exists(list.getLookupTable(), filters.toArray(new NameValueEntry[0]), notNullColumns);
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) 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