use of org.openforis.idm.metamodel.CodeListLevel in project collect by openforis.
the class DatabaseExternalCodeListProvider method createParentKeyByLevelMap.
protected Map<String, String> createParentKeyByLevelMap(CodeList list, Map<String, String> row, int levelIndex) {
Map<String, String> result = new HashMap<String, String>();
List<CodeListLevel> hierarchy = list.getHierarchy();
for (int i = 0; i < levelIndex - 1; i++) {
CodeListLevel l = hierarchy.get(i);
String levelName = l.getName();
result.put(levelName, row.get(levelName));
}
return result;
}
use of org.openforis.idm.metamodel.CodeListLevel in project collect by openforis.
the class CodeListTables method getBaseTableName.
private static String getBaseTableName(CodeList codeList, Integer levelIdx) {
StringBuilder sb = new StringBuilder();
String tableNameAnnotation = codeList.getAnnotation(TABLE_NAME_QNAME);
if (tableNameAnnotation == null) {
sb.append(codeList.getName());
} else {
sb.append(tableNameAnnotation);
}
if (codeList.isHierarchical() && levelIdx != null) {
List<CodeListLevel> hierarchy = codeList.getHierarchy();
if (levelIdx >= hierarchy.size()) {
throw new IllegalArgumentException(String.format("The hierarchy of code list '%s' has %d levels, but level %d has been asked", codeList.getName(), hierarchy.size(), levelIdx + 1));
}
CodeListLevel currentLevel = hierarchy.get(levelIdx);
sb.append("_");
sb.append(currentLevel.getName());
}
return sb.toString();
}
use of org.openforis.idm.metamodel.CodeListLevel in project collect by openforis.
the class CodeAttributeVM method getHierarchicalLevelName.
private String getHierarchicalLevelName(CodeAttributeDefinition parentAttrDefn) {
if (parentAttrDefn == null) {
return null;
} else {
Integer parentLevelIndex = parentAttrDefn.getListLevelIndex();
int levelIndex = parentLevelIndex + 1;
CodeListLevel level = parentAttrDefn.getList().getHierarchy().get(levelIndex);
return level.getName();
}
}
use of org.openforis.idm.metamodel.CodeListLevel in project collect by openforis.
the class CodeListsVM method removeLevel.
@Command
public void removeLevel() {
final List<CodeListLevel> levels = editedItem.getHierarchy();
if (!levels.isEmpty()) {
final int levelIndex = levels.size() - 1;
if (codeListManager.hasChildItemsInLevel(editedItem, levelIndex + 1)) {
ConfirmHandler handler = new ConfirmHandler() {
@Override
public void onOk() {
performRemoveLevel(levelIndex);
}
};
MessageUtil.ConfirmParams params = new MessageUtil.ConfirmParams(handler, "survey.code_list.alert.cannot_delete_non_empty_level");
params.setOkLabelKey("global.delete_item");
MessageUtil.showConfirm(params);
} else {
performRemoveLevel(levelIndex);
}
}
}
use of org.openforis.idm.metamodel.CodeListLevel in project collect by openforis.
the class CollectRecordIntegrationTest method createMultipleLevelCodeListTestSurvey.
private CollectSurvey createMultipleLevelCodeListTestSurvey() {
CollectSurvey survey = surveyManager.createTemporarySurvey("test", "en");
CodeList codeList = survey.createCodeList();
{
CodeListLevel codeListLevel = new CodeListLevel();
codeListLevel.setName("level1");
codeList.addLevel(codeListLevel);
}
{
CodeListLevel codeListLevel = new CodeListLevel();
codeListLevel.setName("level2");
codeList.addLevel(codeListLevel);
}
{
CodeListLevel codeListLevel = new CodeListLevel();
codeListLevel.setName("level3");
codeList.addLevel(codeListLevel);
}
{
CodeListItem item = codeList.createItem(1);
item.setCode("A");
codeList.addItem(item);
{
CodeListItem child = codeList.createItem(2);
child.setCode("1");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
{
CodeListItem child = codeList.createItem(2);
child.setCode("2");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
{
CodeListItem child = codeList.createItem(2);
child.setCode("3");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
}
{
CodeListItem item = codeList.createItem(1);
item.setCode("B");
codeList.addItem(item);
{
CodeListItem child = codeList.createItem(2);
child.setCode("1");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
{
CodeListItem child = codeList.createItem(2);
child.setCode("2");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
{
CodeListItem child = codeList.createItem(2);
child.setCode("3");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
}
survey.addCodeList(codeList);
Schema schema = survey.getSchema();
EntityDefinition root = schema.createEntityDefinition();
root.setName("root");
schema.addRootEntityDefinition(root);
{
CodeAttributeDefinition codeAttrDefn = schema.createCodeAttributeDefinition();
codeAttrDefn.setList(codeList);
codeAttrDefn.setName("code1");
root.addChildDefinition(codeAttrDefn);
}
{
CodeAttributeDefinition codeAttrDefn = schema.createCodeAttributeDefinition();
codeAttrDefn.setList(codeList);
codeAttrDefn.setName("code2");
codeAttrDefn.setParentExpression("code1");
root.addChildDefinition(codeAttrDefn);
}
{
CodeAttributeDefinition codeAttrDefn = schema.createCodeAttributeDefinition();
codeAttrDefn.setList(codeList);
codeAttrDefn.setName("code3");
codeAttrDefn.setParentExpression("code2");
root.addChildDefinition(codeAttrDefn);
}
survey.init();
return survey;
}
Aggregations