use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListBatchImportJob method getOrCreateCodeList.
private CodeList getOrCreateCodeList(String codeListName) {
CodeList codeList = survey.getCodeList(codeListName);
if (codeList == null) {
codeList = survey.createCodeList();
codeList.setName(codeListName);
survey.addCodeList(codeList);
}
return codeList;
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListManager method loadParentItem.
protected CodeListItem loadParentItem(CodeAttribute attribute) {
CodeList list = attribute.getDefinition().getList();
boolean persistedSurvey = list.getSurvey().getId() != null;
Record record = attribute.getRecord();
ModelVersion version = record.getVersion();
if (persistedSurvey && list.isExternal()) {
ExternalCodeListItem item = (ExternalCodeListItem) loadItemByAttribute(attribute);
return provider.getParentItem(item);
} else if (persistedSurvey && list.isEmpty()) {
PersistedCodeListItem lastParentItem = null;
List<CodeAttribute> codeAncestors = attribute.getCodeAncestors();
for (int i = 0; i < codeAncestors.size(); i++) {
CodeAttribute ancestor = codeAncestors.get(i);
Integer lastParentItemId = lastParentItem == null ? null : lastParentItem.getSystemId();
Code code = ancestor.getValue();
lastParentItem = codeListItemDao.loadItem(list, lastParentItemId, code.getCode(), version);
if (lastParentItem == null) {
break;
}
}
return lastParentItem;
} else {
CodeAttribute codeParent = attribute.getCodeParent();
if (codeParent == null) {
return null;
} else {
return loadItemByAttribute(codeParent);
}
}
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListImagesExportTask method execute.
@Override
protected void execute() throws Throwable {
List<CodeList> codeLists = survey.getCodeLists();
for (CodeList list : codeLists) {
if (!list.isExternal()) {
Deque<CodeListItem> stack = new LinkedList<CodeListItem>();
List<CodeListItem> rootItems = codeListManager.loadRootItems(list);
stack.addAll(rootItems);
while (!stack.isEmpty()) {
if (!isRunning()) {
break;
}
CodeListItem item = stack.pop();
if (item instanceof PersistedCodeListItem && item.hasUploadedImage()) {
FileWrapper imageFileWrapper = codeListManager.loadImageContent((PersistedCodeListItem) item);
ZipEntry entry = new ZipEntry(getEntryName(item));
zipOutputStream.putNextEntry(entry);
IOUtils.write(imageFileWrapper.getContent(), zipOutputStream);
zipOutputStream.closeEntry();
}
List<CodeListItem> childItems = codeListManager.loadChildItems(item);
for (CodeListItem childItem : childItems) {
stack.push(childItem);
}
}
}
}
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CollectEarthGridTemplateGenerator method getFirstAvailableCodeItem.
private CodeListItem getFirstAvailableCodeItem(AttributeDefinition attrDef) {
CodeAttributeDefinition codeDefn = (CodeAttributeDefinition) attrDef;
CodeList list = codeDefn.getList();
CodeListService codeListService = attrDef.getSurvey().getContext().getCodeListService();
Integer levelIndex = codeDefn.getListLevelIndex();
int levelPosition = levelIndex == null ? 1 : levelIndex + 1;
List<CodeListItem> items;
if (levelPosition == 1) {
items = codeListService.loadRootItems(list);
} else {
items = codeListService.loadItems(list, levelPosition);
}
if (items.isEmpty()) {
return null;
} else {
return items.get(0);
}
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeColumnProvider method init.
@Override
protected void init() {
if (getConfig().isCodeAttributeExpanded()) {
CodeList list = attributeDefinition.getList();
CollectSurvey survey = (CollectSurvey) list.getSurvey();
if (survey.isPredefinedCodeList(list)) {
hasExpandedItems = false;
expandedItems = null;
} else {
int levelPosition = attributeDefinition.getLevelPosition();
CodeListService codeListService = getCodeListService();
List<CodeListItem> items = codeListService.loadItems(list, levelPosition);
hasExpandedItems = items.size() <= getConfig().getMaxExpandedCodeAttributeItems();
expandedItems = hasExpandedItems ? items : null;
}
}
super.init();
}
Aggregations