use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class SurveyManagerIntegrationTest method createTemporarySurveyFromPublishedTest.
@Test
public void createTemporarySurveyFromPublishedTest() {
CollectSurvey surveyWork = surveyManager.createTemporarySurveyFromPublished(survey.getUri(), adminUser);
assertTrue(surveyWork.isTemporary());
{
CodeList list = survey.getCodeList("admin_unit");
List<CodeListItem> rootItems = codeListManager.loadRootItems(list);
assertEquals(8, rootItems.size());
List<CodeListItem> childItems = codeListManager.loadChildItems(rootItems.get(0));
assertEquals(3, childItems.size());
}
{
CodeList list = surveyWork.getCodeList("admin_unit");
List<CodeListItem> rootItems = codeListManager.loadRootItems(list);
assertEquals(8, rootItems.size());
List<CodeListItem> childItems = codeListManager.loadChildItems(rootItems.get(0));
assertEquals(3, childItems.size());
}
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CollectRecordIntegrationTest method createMultipleLevelCodeListTestSurvey.
private CollectSurvey createMultipleLevelCodeListTestSurvey() {
CollectSurvey survey = surveyManager.createTemporarySurvey("test", "en");
CodeList codeList = survey.createCodeList();
{
CodeListLevel codeListLevel = new CodeListLevel();
codeListLevel.setName("level1");
codeList.addLevel(codeListLevel);
}
{
CodeListLevel codeListLevel = new CodeListLevel();
codeListLevel.setName("level2");
codeList.addLevel(codeListLevel);
}
{
CodeListLevel codeListLevel = new CodeListLevel();
codeListLevel.setName("level3");
codeList.addLevel(codeListLevel);
}
{
CodeListItem item = codeList.createItem(1);
item.setCode("A");
codeList.addItem(item);
{
CodeListItem child = codeList.createItem(2);
child.setCode("1");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
{
CodeListItem child = codeList.createItem(2);
child.setCode("2");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
{
CodeListItem child = codeList.createItem(2);
child.setCode("3");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
}
{
CodeListItem item = codeList.createItem(1);
item.setCode("B");
codeList.addItem(item);
{
CodeListItem child = codeList.createItem(2);
child.setCode("1");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
{
CodeListItem child = codeList.createItem(2);
child.setCode("2");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
{
CodeListItem child = codeList.createItem(2);
child.setCode("3");
item.addChildItem(child);
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("a");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("b");
child.addChildItem(child2);
}
{
CodeListItem child2 = codeList.createItem(3);
child2.setCode("c");
child.addChildItem(child2);
}
}
}
survey.addCodeList(codeList);
Schema schema = survey.getSchema();
EntityDefinition root = schema.createEntityDefinition();
root.setName("root");
schema.addRootEntityDefinition(root);
{
CodeAttributeDefinition codeAttrDefn = schema.createCodeAttributeDefinition();
codeAttrDefn.setList(codeList);
codeAttrDefn.setName("code1");
root.addChildDefinition(codeAttrDefn);
}
{
CodeAttributeDefinition codeAttrDefn = schema.createCodeAttributeDefinition();
codeAttrDefn.setList(codeList);
codeAttrDefn.setName("code2");
codeAttrDefn.setParentExpression("code1");
root.addChildDefinition(codeAttrDefn);
}
{
CodeAttributeDefinition codeAttrDefn = schema.createCodeAttributeDefinition();
codeAttrDefn.setList(codeList);
codeAttrDefn.setName("code3");
codeAttrDefn.setParentExpression("code2");
root.addChildDefinition(codeAttrDefn);
}
survey.init();
return survey;
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListItemDaoIntegrationTest method moveItemInPersistedListTest.
@Test
public void moveItemInPersistedListTest() {
CodeList list = survey.getCodeList("admin_unit");
List<PersistedCodeListItem> items = codeListItemDao.loadRootItems(list);
List<String> codes = getCodes(items);
assertEquals(Arrays.asList("001", "002", "003", "004", "005", "006", "007", "008"), codes);
PersistedCodeListItem item = items.get(2);
assertEquals(Integer.valueOf(3), item.getSortOrder());
codeListItemDao.shiftItem(item, 0);
List<PersistedCodeListItem> items2 = codeListItemDao.loadRootItems(list);
List<String> codes2 = getCodes(items2);
assertEquals(Arrays.asList("003", "001", "002", "004", "005", "006", "007", "008"), codes2);
PersistedCodeListItem item2 = items2.get(0);
assertEquals(Integer.valueOf(1), item2.getSortOrder());
codeListItemDao.shiftItem(item2, 4);
List<PersistedCodeListItem> items3 = codeListItemDao.loadRootItems(list);
List<String> codes3 = getCodes(items3);
assertEquals(Arrays.asList("001", "002", "004", "005", "003", "006", "007", "008"), codes3);
PersistedCodeListItem item3 = items3.get(4);
assertEquals(Integer.valueOf(5), item3.getSortOrder());
codeListItemDao.shiftItem(item3, 8);
List<PersistedCodeListItem> items4 = codeListItemDao.loadRootItems(list);
List<String> codes4 = getCodes(items4);
assertEquals(Arrays.asList("001", "002", "004", "005", "006", "007", "008", "003"), codes4);
PersistedCodeListItem item4 = items4.get(7);
assertEquals(Integer.valueOf(8), item4.getSortOrder());
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class MondrianCubeGenerator method extractCodeListName.
private String extractCodeListName(CodeAttributeDefinition codeAttrDef) {
StringBuffer codeListName = new StringBuffer(codeAttrDef.getList().getName());
int levelIdx = codeAttrDef.getLevelIndex();
if (levelIdx != -1) {
CodeList codeList = codeAttrDef.getList();
List<CodeListLevel> codeHierarchy = codeList.getHierarchy();
if (!codeHierarchy.isEmpty()) {
CodeListLevel currentLevel = codeHierarchy.get(levelIdx);
codeListName.append("_");
codeListName.append(currentLevel.getName());
}
}
return codeListName.toString();
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class SurveyEditVM method openCodeListsManagerPopUp.
@GlobalCommand
public void openCodeListsManagerPopUp(@BindingParam(EDITING_ATTRIBUTE_PARAM) Boolean editingAttribute, @BindingParam(SELECTED_CODE_LIST_PARAM) CodeList selectedCodeList) {
if (codeListsPopUp == null) {
dispatchCurrentFormValidatedCommand(true);
Map<String, Object> args = new HashMap<String, Object>();
args.put(EDITING_ATTRIBUTE_PARAM, editingAttribute);
CodeList selectedCodeListInPopUp = selectedCodeList == survey.getSamplingDesignCodeList() ? null : selectedCodeList;
args.put(SELECTED_CODE_LIST_PARAM, selectedCodeListInPopUp);
codeListsPopUp = openPopUp(Resources.Component.CODE_LISTS_POPUP.getLocation(), true, args);
}
}
Aggregations