Search in sources :

Example 36 with CodeListItem

use of org.openforis.idm.metamodel.CodeListItem 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 37 with CodeListItem

use of org.openforis.idm.metamodel.CodeListItem 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 38 with CodeListItem

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

the class CodeValueFKColumnValueExtractor method getDefaultCodeItemId.

private Integer getDefaultCodeItemId(CodeList list, ModelVersion version) {
    CodeListService codeListService = getCodeListService((CollectSurvey) list.getSurvey());
    CodeListItem defaultCodeItem = codeListService.loadRootItem(list, column.getDefaultCodeValue(), version);
    return defaultCodeItem == null ? CodeTableDataExtractor.DEFAULT_CODE_ROW_ID : defaultCodeItem.getId();
}
Also used : CodeListService(org.openforis.idm.metamodel.CodeListService) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 39 with CodeListItem

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

the class CodeListItemFormValidator method getExistingCodeListItem.

protected CodeListItem getExistingCodeListItem(ValidationContext ctx, String code) {
    SurveyObjectBaseVM<CodeListItem> viewModel = getVM(ctx);
    CodeListItem editedItem = viewModel.getEditedItem();
    CodeList codeList = editedItem.getCodeList();
    CodeListItem parentItem = getParentItem(ctx);
    CodeListItem existingItem = null;
    CodeListManager codeListManager = getCodeListManager(ctx);
    if (parentItem == null) {
        existingItem = codeListManager.loadRootItem(codeList, code, null);
    } else {
        existingItem = codeListManager.loadChildItem(parentItem, code, null);
    }
    return existingItem;
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeListManager(org.openforis.collect.manager.CodeListManager) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 40 with CodeListItem

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

the class CodeListsVM method initItemsPerLevel.

protected void initItemsPerLevel() {
    itemsPerLevel = new ArrayList<List<CodeListItem>>();
    if (/*isSurveyStored() && */
    editedItem != null && !editedItem.isExternal()) {
        List<CodeListItem> rootItems = codeListManager.loadRootItems(editedItem);
        itemsPerLevel.add(new ArrayList<CodeListItem>(rootItems));
        for (CodeListItem selectedItem : selectedItemsPerLevel) {
            List<CodeListItem> childItems = codeListManager.loadChildItems(selectedItem);
            itemsPerLevel.add(new ArrayList<CodeListItem>(childItems));
        }
    } else {
        // add empty root items list
        itemsPerLevel.add(new ArrayList<CodeListItem>());
    }
    notifyChange("itemsPerLevel");
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) List(java.util.List) ArrayList(java.util.ArrayList) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Aggregations

CodeListItem (org.openforis.idm.metamodel.CodeListItem)69 CodeList (org.openforis.idm.metamodel.CodeList)26 ArrayList (java.util.ArrayList)19 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)19 PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)18 CodeListService (org.openforis.idm.metamodel.CodeListService)13 List (java.util.List)7 CollectSurvey (org.openforis.collect.model.CollectSurvey)7 ModelVersion (org.openforis.idm.metamodel.ModelVersion)7 Test (org.junit.Test)5 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)5 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)5 Entity (org.openforis.idm.model.Entity)5 Record (org.openforis.idm.model.Record)5 CodeListItemProxy (org.openforis.collect.metamodel.proxy.CodeListItemProxy)4 CollectRecord (org.openforis.collect.model.CollectRecord)4 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)4 CodeAttribute (org.openforis.idm.model.CodeAttribute)4 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3