Search in sources :

Example 26 with CodeList

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;
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList)

Example 27 with 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);
        }
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) ExternalCodeListItem(org.openforis.idm.metamodel.ExternalCodeListItem) CodeAttribute(org.openforis.idm.model.CodeAttribute) Record(org.openforis.idm.model.Record) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) CodeList(org.openforis.idm.metamodel.CodeList) List(java.util.List) ModelVersion(org.openforis.idm.metamodel.ModelVersion) Code(org.openforis.idm.model.Code) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem)

Example 28 with CodeList

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);
                }
            }
        }
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) ZipEntry(java.util.zip.ZipEntry) FileWrapper(org.openforis.collect.model.FileWrapper) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) LinkedList(java.util.LinkedList) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem)

Example 29 with CodeList

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);
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeListService(org.openforis.idm.metamodel.CodeListService) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 30 with CodeList

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();
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeListService(org.openforis.idm.metamodel.CodeListService) CollectSurvey(org.openforis.collect.model.CollectSurvey) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Aggregations

CodeList (org.openforis.idm.metamodel.CodeList)88 CodeListItem (org.openforis.idm.metamodel.CodeListItem)24 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)20 ArrayList (java.util.ArrayList)16 CollectSurvey (org.openforis.collect.model.CollectSurvey)15 PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)14 Test (org.junit.Test)10 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)10 HashMap (java.util.HashMap)7 NameValueEntry (org.openforis.collect.model.NameValueEntry)7 CodeListService (org.openforis.idm.metamodel.CodeListService)7 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)6 List (java.util.List)5 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)5 ModelVersion (org.openforis.idm.metamodel.ModelVersion)5 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)5 Code (org.openforis.idm.model.Code)5 Record (org.openforis.idm.model.Record)5 CodeAttributeDefinitionFormObject (org.openforis.collect.designer.form.CodeAttributeDefinitionFormObject)4 CodeListImportProcess (org.openforis.collect.manager.codelistimport.CodeListImportProcess)4