use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class SurveyViewGenerator method createCodeListItemView.
private CodeListItemView createCodeListItemView(CodeListItem item) {
CodeListService service = item.getSurvey().getContext().getCodeListService();
CodeListItemView itemView = new CodeListItemView();
itemView.id = item.getId();
itemView.code = item.getCode();
itemView.label = item.getLabel(languageCode);
itemView.color = item.getColor();
List<CodeListItemView> childItemsView = new ArrayList<CodeListItemView>();
List<CodeListItem> childItems = service.loadChildItems(item);
for (CodeListItem childItem : childItems) {
childItemsView.add(createCodeListItemView(childItem));
}
itemView.items.addAll(childItemsView);
return itemView;
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class EnumerableEntityColumnProvider method createProviders.
private static List<ColumnProvider> createProviders(CSVDataExportParameters config, EntityDefinition defn) {
List<ColumnProvider> providers = new ArrayList<ColumnProvider>();
List<AttributeDefinition> keyDefs = defn.getKeyAttributeDefinitions();
CodeAttributeDefinition keyDef = (CodeAttributeDefinition) keyDefs.get(0);
CodeList codeList = keyDef.getList();
SurveyContext context = defn.getSurvey().getContext();
CodeListService codeListService = context.getCodeListService();
List<CodeListItem> items = codeListService.loadRootItems(codeList);
for (CodeListItem item : items) {
String code = item.getCode();
String keyName = keyDef.getName();
EnumeratedCodeItemColumnProvider p = new EnumeratedCodeItemColumnProvider(config, defn, keyName, code);
providers.add(p);
}
return providers;
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class CodeAttributeProxy method getCodeListItem.
@ExternalizedProperty
public CodeListItemProxy getCodeListItem() {
if (isEnumerator()) {
CodeListService codeListManager = getCodeListService();
CodeListItem codeListItem = codeListManager.loadItem(codeAttribute);
return codeListItem == null ? null : new CodeListItemProxy(codeListItem);
} else {
return null;
}
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class SurveyViewGenerator method generateView.
public SurveyView generateView(final CollectSurvey survey) {
final SurveyView surveyView = new SurveyView(survey);
List<CodeList> codeLists = survey.getCodeLists();
for (CodeList codeList : codeLists) {
CodeListView codeListView = new CodeListView();
codeListView.setId(codeList.getId());
codeListView.setName(codeList.getName());
codeListView.setLabel(codeList.getLabel(CodeListLabel.Type.ITEM, languageCode));
if (includeCodeListValues && !codeList.isExternal()) {
CodeListService service = survey.getContext().getCodeListService();
List<CodeListItem> items = service.loadRootItems(codeList);
for (CodeListItem item : items) {
codeListView.addItem(createCodeListItemView(item));
}
}
surveyView.addCodeList(codeListView);
}
final Map<Integer, NodeDefView> viewById = new HashMap<Integer, NodeDefView>();
survey.getSchema().traverse(new NodeDefinitionVisitor() {
public void visit(NodeDefinition def) {
int id = def.getId();
String name = def.getName();
String label = getLabel(def);
NodeDefView view;
if (def instanceof EntityDefinition) {
view = new EntityDefView(((EntityDefinition) def).isRoot(), id, name, label, def.isMultiple());
} else if (def instanceof CodeAttributeDefinition) {
CodeAttributeDefinition attrDef = (CodeAttributeDefinition) def;
int codeListId = attrDef.getList() == null ? -1 : attrDef.getList().getId();
view = new CodeAttributeDefView(id, name, label, AttributeType.valueOf(attrDef), attrDef.getFieldNames(), attrDef.isKey(), attrDef.isMultiple(), survey.getAnnotations().isShowInSummary(attrDef), survey.getAnnotations().isQualifier(attrDef), codeListId);
} else {
AttributeDefinition attrDef = (AttributeDefinition) def;
view = new AttributeDefView(id, name, label, AttributeType.valueOf(attrDef), attrDef.getFieldNames(), attrDef.isKey(), attrDef.isMultiple(), survey.getAnnotations().isShowInSummary(attrDef), survey.getAnnotations().isQualifier(attrDef));
}
NodeDefinition parentDef = def.getParentDefinition();
if (parentDef == null) {
surveyView.getSchema().addRootEntity((EntityDefView) view);
} else {
EntityDefView parentView = (EntityDefView) viewById.get(parentDef.getId());
parentView.addChild(view);
}
viewById.put(id, view);
}
});
return surveyView;
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class CodeListManagerIntegrationTest method cascadeDeleteTest.
@Test
public void cascadeDeleteTest() {
CodeList list = survey.getCodeList("admin_unit");
List<CodeListItem> rootItems = codeListManager.loadItems(list, 1);
assertEquals(8, rootItems.size());
PersistedCodeListItem parentItem = (PersistedCodeListItem) rootItems.get(1);
List<CodeListItem> childItems = codeListManager.loadChildItems(parentItem);
assertEquals(3, childItems.size());
codeListManager.delete(parentItem);
rootItems = codeListManager.loadItems(list, 1);
assertEquals(7, rootItems.size());
PersistedCodeListItem fakeItem = new PersistedCodeListItem(list, parentItem.getId());
fakeItem.setSystemId(parentItem.getSystemId());
List<CodeListItem> reloadedItems = codeListManager.loadChildItems(fakeItem);
assertTrue(reloadedItems.isEmpty());
}
Aggregations