use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class SurveyBaseVM method getCodeLists.
public List<CodeList> getCodeLists() {
CollectSurvey survey = getSurvey();
boolean includeSamplingDesignList = survey.getTarget() != SurveyTarget.COLLECT_EARTH;
List<CodeList> result = new ArrayList<CodeList>(survey.getCodeLists(includeSamplingDesignList));
result = sort(result);
return new BindingListModelList<CodeList>(result, false);
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CollectEarthBalloonGenerator method createComponent.
private CEComponent createComponent(NodeDefinition def, int entityPosition) {
String label = def.getLabel(Type.INSTANCE, language);
if (label == null && !isDefaultLanguage()) {
label = def.getLabel(Type.INSTANCE);
}
if (label == null) {
label = def.getName();
}
boolean multiple = def.isMultiple();
UIOptions uiOptions = survey.getUIOptions();
boolean hideWhenNotRelevant = uiOptions.isHideWhenNotRelevant(def);
CEComponent comp;
if (def instanceof EntityDefinition) {
if (def.isMultiple() && ((EntityDefinition) def).isEnumerable()) {
comp = createEnumeratedEntityComponent((EntityDefinition) def);
} else {
String tooltip = def.getDescription(language);
CEFieldSet fieldSet = new CEFieldSet(def.getName(), label, tooltip);
for (NodeDefinition child : ((EntityDefinition) def).getChildDefinitions()) {
if (!uiOptions.isHidden(child)) {
fieldSet.addChild(createComponent(child));
}
}
comp = fieldSet;
}
} else {
AttributeDefinition attrDef = (AttributeDefinition) def;
String htmlParameterName;
boolean insideEnumeratedEntity = def.getParentEntityDefinition().isEnumerable();
if (insideEnumeratedEntity) {
htmlParameterName = getEnumeratedEntityComponentHtmlParameterName(def.getParentEntityDefinition(), entityPosition, def);
} else {
htmlParameterName = getHtmlParameterName(def);
}
String tooltip = attrDef.getDescription(language);
CEFieldType type = getFieldType(def);
boolean key = def instanceof KeyAttributeDefinition ? ((KeyAttributeDefinition) def).isKey() : false;
if (insideEnumeratedEntity && key) {
comp = new CEEnumeratingCodeField(htmlParameterName, def.getName(), label, tooltip, multiple, type, key);
} else if (def instanceof CodeAttributeDefinition) {
CodeAttributeDefinition codeAttrDef = (CodeAttributeDefinition) def;
CodeList list = codeAttrDef.getList();
Integer listLevelIndex = codeAttrDef.getListLevelIndex();
Map<Integer, List<CodeListItem>> codeItemsByParentCodeItemId = getCodeListItemsByParentId(list, listLevelIndex);
CodeAttributeDefinition parentCodeAttributeDef = codeAttrDef.getParentCodeAttributeDefinition();
String parentName = parentCodeAttributeDef == null ? null : getHtmlParameterName(parentCodeAttributeDef);
comp = new CECodeField(htmlParameterName, def.getName(), label, tooltip, type, multiple, key, codeItemsByParentCodeItemId, parentName);
} else {
comp = new CEField(htmlParameterName, def.getName(), label, tooltip, multiple, type, key);
}
CollectAnnotations annotations = survey.getAnnotations();
if (attrDef.isCalculated() || (annotations.isFromCollectEarthCSV(attrDef) && annotations.isShowReadOnlyFieldInCollectEarth(attrDef))) {
((CEField) comp).setReadOnly(true);
}
}
comp.hideWhenNotRelevant = hideWhenNotRelevant;
componentByName.put(comp.getName(), comp);
return comp;
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CollectEarthBalloonGenerator method getCodeListItemsByParentId.
private Map<Integer, List<CodeListItem>> getCodeListItemsByParentId(CodeList list, Integer listLevelIndex) {
CodeListService codeListService = list.getSurvey().getContext().getCodeListService();
Map<Integer, List<CodeListItem>> codeItemsByParentCodeItemId = new HashMap<Integer, List<CodeListItem>>();
if (listLevelIndex == null || listLevelIndex == 0) {
List<CodeListItem> rootCodeItems = codeListService.loadRootItems(list);
// root items
codeItemsByParentCodeItemId.put(0, rootCodeItems);
} else {
int listLevelPosition = listLevelIndex + 1;
List<CodeListItem> parentLevelItems;
if (listLevelPosition == 2) {
parentLevelItems = codeListService.loadRootItems(list);
} else {
parentLevelItems = codeListService.loadItems(list, listLevelPosition - 1);
}
for (CodeListItem parentItem : parentLevelItems) {
List<CodeListItem> childItems = codeListService.loadChildItems(parentItem);
if (!childItems.isEmpty()) {
codeItemsByParentCodeItemId.put(parentItem.getId(), childItems);
}
}
}
return codeItemsByParentCodeItemId;
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListExportProcess method exportToCSV.
public void exportToCSV(OutputStream out, CollectSurvey survey, int codeListId) {
CsvWriter writer = null;
try {
OutputStreamWriter osWriter = new OutputStreamWriter(out, Charset.forName("UTF-8"));
writer = new CsvWriter(osWriter, SEPARATOR, QUOTECHAR);
CodeList list = survey.getCodeListById(codeListId);
initHeaders(writer, survey, list);
List<CodeListItem> rootItems = codeListManager.loadRootItems(list);
for (CodeListItem item : rootItems) {
List<CodeListItem> ancestors = Collections.emptyList();
writeItem(writer, item, ancestors);
}
} catch (Exception e) {
LOG.error(e);
} finally {
IOUtils.closeQuietly(writer);
}
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListBatchExportJob method initializeTask.
@Override
protected void initializeTask(Worker task) {
CodeList codeList = ((CodeListExportTask) task).getList();
String zipEntryName = codeList.getName() + ".csv";
try {
zipOutputStream.putNextEntry(new ZipEntry(zipEntryName));
} catch (IOException e) {
throw new RuntimeException(e);
}
super.initializeTask(task);
}
Aggregations