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);
}
}
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));
}
}
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);
}
}
}
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());
}
}
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, ".");
}
Aggregations