Search in sources :

Example 16 with CodeList

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

the class SurveyManagerIntegrationTest method createTemporarySurveyFromPublishedTest.

@Test
public void createTemporarySurveyFromPublishedTest() {
    CollectSurvey surveyWork = surveyManager.createTemporarySurveyFromPublished(survey.getUri(), adminUser);
    assertTrue(surveyWork.isTemporary());
    {
        CodeList list = survey.getCodeList("admin_unit");
        List<CodeListItem> rootItems = codeListManager.loadRootItems(list);
        assertEquals(8, rootItems.size());
        List<CodeListItem> childItems = codeListManager.loadChildItems(rootItems.get(0));
        assertEquals(3, childItems.size());
    }
    {
        CodeList list = surveyWork.getCodeList("admin_unit");
        List<CodeListItem> rootItems = codeListManager.loadRootItems(list);
        assertEquals(8, rootItems.size());
        List<CodeListItem> childItems = codeListManager.loadChildItems(rootItems.get(0));
        assertEquals(3, childItems.size());
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeList(org.openforis.idm.metamodel.CodeList) List(java.util.List) CollectSurvey(org.openforis.collect.model.CollectSurvey) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 17 with CodeList

use of org.openforis.idm.metamodel.CodeList 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)

Example 18 with CodeList

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

the class CodeListItemDaoIntegrationTest method moveItemInPersistedListTest.

@Test
public void moveItemInPersistedListTest() {
    CodeList list = survey.getCodeList("admin_unit");
    List<PersistedCodeListItem> items = codeListItemDao.loadRootItems(list);
    List<String> codes = getCodes(items);
    assertEquals(Arrays.asList("001", "002", "003", "004", "005", "006", "007", "008"), codes);
    PersistedCodeListItem item = items.get(2);
    assertEquals(Integer.valueOf(3), item.getSortOrder());
    codeListItemDao.shiftItem(item, 0);
    List<PersistedCodeListItem> items2 = codeListItemDao.loadRootItems(list);
    List<String> codes2 = getCodes(items2);
    assertEquals(Arrays.asList("003", "001", "002", "004", "005", "006", "007", "008"), codes2);
    PersistedCodeListItem item2 = items2.get(0);
    assertEquals(Integer.valueOf(1), item2.getSortOrder());
    codeListItemDao.shiftItem(item2, 4);
    List<PersistedCodeListItem> items3 = codeListItemDao.loadRootItems(list);
    List<String> codes3 = getCodes(items3);
    assertEquals(Arrays.asList("001", "002", "004", "005", "003", "006", "007", "008"), codes3);
    PersistedCodeListItem item3 = items3.get(4);
    assertEquals(Integer.valueOf(5), item3.getSortOrder());
    codeListItemDao.shiftItem(item3, 8);
    List<PersistedCodeListItem> items4 = codeListItemDao.loadRootItems(list);
    List<String> codes4 = getCodes(items4);
    assertEquals(Arrays.asList("001", "002", "004", "005", "006", "007", "008", "003"), codes4);
    PersistedCodeListItem item4 = items4.get(7);
    assertEquals(Integer.valueOf(8), item4.getSortOrder());
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 19 with CodeList

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

the class MondrianCubeGenerator method extractCodeListName.

private String extractCodeListName(CodeAttributeDefinition codeAttrDef) {
    StringBuffer codeListName = new StringBuffer(codeAttrDef.getList().getName());
    int levelIdx = codeAttrDef.getLevelIndex();
    if (levelIdx != -1) {
        CodeList codeList = codeAttrDef.getList();
        List<CodeListLevel> codeHierarchy = codeList.getHierarchy();
        if (!codeHierarchy.isEmpty()) {
            CodeListLevel currentLevel = codeHierarchy.get(levelIdx);
            codeListName.append("_");
            codeListName.append(currentLevel.getName());
        }
    }
    return codeListName.toString();
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeListLevel(org.openforis.idm.metamodel.CodeListLevel)

Example 20 with CodeList

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

the class SurveyEditVM method openCodeListsManagerPopUp.

@GlobalCommand
public void openCodeListsManagerPopUp(@BindingParam(EDITING_ATTRIBUTE_PARAM) Boolean editingAttribute, @BindingParam(SELECTED_CODE_LIST_PARAM) CodeList selectedCodeList) {
    if (codeListsPopUp == null) {
        dispatchCurrentFormValidatedCommand(true);
        Map<String, Object> args = new HashMap<String, Object>();
        args.put(EDITING_ATTRIBUTE_PARAM, editingAttribute);
        CodeList selectedCodeListInPopUp = selectedCodeList == survey.getSamplingDesignCodeList() ? null : selectedCodeList;
        args.put(SELECTED_CODE_LIST_PARAM, selectedCodeListInPopUp);
        codeListsPopUp = openPopUp(Resources.Component.CODE_LISTS_POPUP.getLocation(), true, args);
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) HashMap(java.util.HashMap) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand)

Aggregations

CodeList (org.openforis.idm.metamodel.CodeList)88 CodeListItem (org.openforis.idm.metamodel.CodeListItem)24 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)20 ArrayList (java.util.ArrayList)16 CollectSurvey (org.openforis.collect.model.CollectSurvey)15 PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)14 Test (org.junit.Test)10 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)10 HashMap (java.util.HashMap)7 NameValueEntry (org.openforis.collect.model.NameValueEntry)7 CodeListService (org.openforis.idm.metamodel.CodeListService)7 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)6 List (java.util.List)5 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)5 ModelVersion (org.openforis.idm.metamodel.ModelVersion)5 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)5 Code (org.openforis.idm.model.Code)5 Record (org.openforis.idm.model.Record)5 CodeAttributeDefinitionFormObject (org.openforis.collect.designer.form.CodeAttributeDefinitionFormObject)4 CodeListImportProcess (org.openforis.collect.manager.codelistimport.CodeListImportProcess)4