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;
}
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;
}
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;
}
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());
}
Aggregations