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