Search in sources :

Example 1 with CodeListLevel

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;
}
Also used : CodeListLevel(org.openforis.idm.metamodel.CodeListLevel) HashMap(java.util.HashMap)

Example 2 with CodeListLevel

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();
}
Also used : CodeListLevel(org.openforis.idm.metamodel.CodeListLevel)

Example 3 with CodeListLevel

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();
    }
}
Also used : CodeListLevel(org.openforis.idm.metamodel.CodeListLevel)

Example 4 with CodeListLevel

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);
        }
    }
}
Also used : CodeListLevel(org.openforis.idm.metamodel.CodeListLevel) ConfirmHandler(org.openforis.collect.designer.util.MessageUtil.ConfirmHandler) MessageUtil(org.openforis.collect.designer.util.MessageUtil) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

Example 5 with CodeListLevel

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;
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeListLevel(org.openforis.idm.metamodel.CodeListLevel) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Schema(org.openforis.idm.metamodel.Schema) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Aggregations

CodeListLevel (org.openforis.idm.metamodel.CodeListLevel)15 CodeList (org.openforis.idm.metamodel.CodeList)4 ArrayList (java.util.ArrayList)3 Command (org.zkoss.bind.annotation.Command)2 GlobalCommand (org.zkoss.bind.annotation.GlobalCommand)2 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 MessageUtil (org.openforis.collect.designer.util.MessageUtil)1 ConfirmHandler (org.openforis.collect.designer.util.MessageUtil.ConfirmHandler)1 NameValueEntry (org.openforis.collect.model.NameValueEntry)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 CodeListItem (org.openforis.idm.metamodel.CodeListItem)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 Schema (org.openforis.idm.metamodel.Schema)1 NotifyChange (org.zkoss.bind.annotation.NotifyChange)1