Search in sources :

Example 11 with PersistedCodeListItem

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

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

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

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

the class CodeListsVM method reloadSiblingsSortOrder.

/**
 * Reloads the siblings from the database.
 * The sort order of these items changes after calling codeListManager.shiftItem method.
 *
 * @param item
 */
protected void reloadSiblingsSortOrder(PersistedCodeListItem item) {
    int levelIdx = getLevelIndex(item);
    List<CodeListItem> newItems;
    if (levelIdx == 0) {
        newItems = codeListManager.loadRootItems(item.getCodeList());
    } else {
        CodeListItem parentItem = codeListManager.loadParentItem(item);
        newItems = codeListManager.loadChildItems(parentItem);
    }
    List<CodeListItem> items = itemsPerLevel.get(levelIdx);
    for (int i = 0; i < items.size(); i++) {
        CodeListItem oldItem = items.get(i);
        CodeListItem newItem = newItems.get(i);
        ((PersistedCodeListItem) oldItem).setSortOrder(((PersistedCodeListItem) newItem).getSortOrder());
    }
}
Also used : PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem)

Example 15 with PersistedCodeListItem

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

the class CodeListsVM method addChildItemToCodeList.

private void addChildItemToCodeList() {
    if (editedItem.isEmpty() && isSurveyStored()) {
        // persist item in db
        PersistedCodeListItem persistedChildItem = (PersistedCodeListItem) editedChildItem;
        if (editedChildItemParentItem != null) {
            persistedChildItem.setParentId(((PersistedCodeListItem) editedChildItemParentItem).getSystemId());
        }
        codeListManager.save(persistedChildItem);
        dispatchSurveySaveCommand();
    } else if (editedChildItemParentItem == null) {
        // add item among the root items
        editedItem.addItem(editedChildItem);
    } else {
        // add item as a child of the edited parent item in the code list
        editedChildItemParentItem.addChildItem(editedChildItem);
    }
    List<CodeListItem> itemsForCurrentLevel = itemsPerLevel.get(editedChildItemLevelIndex);
    itemsForCurrentLevel.add(editedChildItem);
    deselectItemsAfterLevel(editedChildItemLevelIndex);
    selectedItemsPerLevel.add(editedChildItem);
    initItemsPerLevel();
    notifyChange("selectedItemsPerLevel");
    BindUtils.postNotifyChange(null, null, editedItem, ".");
}
Also used : PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem)

Aggregations

PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)18 CodeList (org.openforis.idm.metamodel.CodeList)12 CodeListItem (org.openforis.idm.metamodel.CodeListItem)8 Test (org.junit.Test)5 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)5 OfcCodeListRecord (org.openforis.collect.persistence.jooq.tables.records.OfcCodeListRecord)3 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 ZipEntry (java.util.zip.ZipEntry)2 Record (org.jooq.Record)2 FileWrapper (org.openforis.collect.model.FileWrapper)2 ModelVersion (org.openforis.idm.metamodel.ModelVersion)2 Code (org.openforis.idm.model.Code)2 Record (org.openforis.idm.model.Record)2 List (java.util.List)1 BatchBindStep (org.jooq.BatchBindStep)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 SurveyObject (org.openforis.idm.metamodel.SurveyObject)1