Search in sources :

Example 51 with CodeList

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

the class CodeListManagerIntegrationTest method loadItemsByLevelTest.

@Test
public void loadItemsByLevelTest() {
    CodeList list = survey.getCodeList("admin_unit");
    List<CodeListItem> rootItems = codeListManager.loadItems(list, 1);
    assertEquals(8, rootItems.size());
    {
        CodeListItem item = rootItems.get(1);
        assertEquals("002", item.getCode());
    }
    List<CodeListItem> secondLevelItems = codeListManager.loadItems(list, 2);
    assertEquals(23, secondLevelItems.size());
    {
        CodeListItem item = secondLevelItems.get(1);
        assertEquals("002", item.getCode());
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 52 with CodeList

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

the class SurveyManagerIntegrationTest method publishSurveyCodeListsTest.

@Test
public void publishSurveyCodeListsTest() throws SurveyImportException {
    CollectSurvey surveyWork = surveyManager.createTemporarySurveyFromPublished(survey.getUri(), adminUser);
    {
        // modify item in list
        CodeList list = surveyWork.getCodeList("admin_unit");
        PersistedCodeListItem item = codeListManager.loadRootItem(list, "001", null);
        assertEquals(Integer.valueOf(1), item.getSortOrder());
        item.setCode("001A");
        codeListManager.save(item);
    }
    surveyManager.publish(surveyWork, adminUser);
    CollectSurvey publishedSurvey = surveyManager.getByUri(surveyWork.getUri());
    CodeList list = publishedSurvey.getCodeList("admin_unit");
    List<CodeListItem> rootItems = codeListManager.loadRootItems(list);
    assertEquals(8, rootItems.size());
    {
        PersistedCodeListItem item = codeListManager.loadRootItem(list, "001A", null);
        assertEquals(Integer.valueOf(1), item.getSortOrder());
    }
    {
        PersistedCodeListItem item = codeListManager.loadRootItem(list, "001", null);
        assertNull(item);
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CollectSurvey(org.openforis.collect.model.CollectSurvey) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 53 with CodeList

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

the class CodeListItemDaoIntegrationTest method persistedFlatListTest.

@Test
public void persistedFlatListTest() {
    CodeList list = survey.getCodeList("measurement");
    List<PersistedCodeListItem> rootItems = codeListItemDao.loadRootItems(list);
    assertEquals(3, rootItems.size());
    {
        PersistedCodeListItem item = rootItems.get(0);
        assertEquals("P", item.getCode());
        assertEquals(Integer.valueOf(1), item.getSortOrder());
        assertEquals("Planned", item.getLabel(EN_LANG_CODE));
        assertEquals("Planned as part of original sampling design", item.getDescription(EN_LANG_CODE));
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 54 with CodeList

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

the class CodeListItemDaoIntegrationTest method persistedHierarchicalListTest.

@Test
public void persistedHierarchicalListTest() {
    CodeList list = survey.getCodeList("admin_unit");
    List<PersistedCodeListItem> rootItems = codeListItemDao.loadRootItems(list);
    assertEquals(8, rootItems.size());
    {
        PersistedCodeListItem item = rootItems.get(2);
        assertEquals(22, item.getId());
        assertEquals("003", item.getCode());
        assertEquals(Integer.valueOf(3), item.getSortOrder());
        assertEquals("Colin", item.getLabel(EN_LANG_CODE));
        boolean hasChildItems = codeListItemDao.hasChildItems(list, item.getSystemId());
        assertTrue(hasChildItems);
        {
            PersistedCodeListItem child = (PersistedCodeListItem) codeListItemDao.loadItem(list, item.getSystemId(), "002", null);
            assertNotNull(child);
            assertEquals(24, child.getId());
            assertEquals(Integer.valueOf(2), child.getSortOrder());
            assertEquals("Muddy Banks", child.getLabel(EN_LANG_CODE));
            boolean hasChildItems2 = codeListItemDao.hasChildItems(list, child.getSystemId());
            assertFalse(hasChildItems2);
        }
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 55 with CodeList

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

the class CodeParentValidator method isExternalCodeList.

private boolean isExternalCodeList(CodeAttribute node) {
    CodeAttributeDefinition definition = node.getDefinition();
    CodeList codeList = definition.getList();
    return codeList.isExternal();
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition)

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