Search in sources :

Example 6 with ExternalCodeListItem

use of org.openforis.idm.metamodel.ExternalCodeListItem in project collect by openforis.

the class DatabaseExternalCodeListProvider method parseRow.

protected ExternalCodeListItem parseRow(Map<String, String> row, CodeList list, int levelIndex) {
    if (row == null) {
        return null;
    }
    String idValue = row.get(ID_COLUMN_NAME);
    Integer id = Integer.valueOf(idValue);
    Map<String, String> parentKeysByLevel = createParentKeyByLevelMap(list, row, levelIndex);
    ExternalCodeListItem item = new ExternalCodeListItem(list, id, parentKeysByLevel, levelIndex + 1);
    String currentLevelKeyColName = getLevelKeyColumnName(list, levelIndex);
    String code = row.get(currentLevelKeyColName);
    item.setCode(code);
    Survey survey = list.getSurvey();
    List<String> languages = survey.getLanguages();
    for (int i = 0; i < languages.size(); i++) {
        String langCode = languages.get(i);
        String colName = LABEL_COLUMN_PREFIX + (i + 1);
        String label = row.get(colName);
        if (label != null) {
            item.setLabel(langCode, label);
        }
    }
    return item;
}
Also used : Survey(org.openforis.idm.metamodel.Survey) CollectSurvey(org.openforis.collect.model.CollectSurvey) ExternalCodeListItem(org.openforis.idm.metamodel.ExternalCodeListItem)

Example 7 with ExternalCodeListItem

use of org.openforis.idm.metamodel.ExternalCodeListItem 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 8 with ExternalCodeListItem

use of org.openforis.idm.metamodel.ExternalCodeListItem 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 9 with ExternalCodeListItem

use of org.openforis.idm.metamodel.ExternalCodeListItem in project collect by openforis.

the class ExternalCodeListIntegrationTest method getNestedChildItemTest.

@Test
public void getNestedChildItemTest() throws SQLException {
    List<ExternalCodeListItem> rootItems = codeListManager.loadRootItems(hierarchicalList);
    ExternalCodeListItem parent = rootItems.get(0);
    List<ExternalCodeListItem> children = codeListManager.loadChildItems(parent);
    assertEquals(2, children.size());
    ExternalCodeListItem child = children.get(1);
    assertEquals("012", child.getCode());
}
Also used : ExternalCodeListItem(org.openforis.idm.metamodel.ExternalCodeListItem) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Aggregations

ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)9 ArrayList (java.util.ArrayList)4 NameValueEntry (org.openforis.collect.model.NameValueEntry)4 CodeList (org.openforis.idm.metamodel.CodeList)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Test (org.junit.Test)2 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)2 CodeAttribute (org.openforis.idm.model.CodeAttribute)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 ExternalCodeListProvider (org.openforis.idm.metamodel.ExternalCodeListProvider)1 ModelVersion (org.openforis.idm.metamodel.ModelVersion)1 PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)1 Survey (org.openforis.idm.metamodel.Survey)1 Code (org.openforis.idm.model.Code)1 Record (org.openforis.idm.model.Record)1