Search in sources :

Example 21 with CodeList

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);
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) ArrayList(java.util.ArrayList) CollectSurvey(org.openforis.collect.model.CollectSurvey) BindingListModelList(org.zkoss.zkplus.databind.BindingListModelList)

Example 22 with CodeList

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;
}
Also used : UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeList(org.openforis.idm.metamodel.CodeList) CEFieldType(org.openforis.collect.io.metadata.collectearth.balloon.CEField.CEFieldType) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) CodeListItem(org.openforis.idm.metamodel.CodeListItem) HashMap(java.util.HashMap) Map(java.util.Map)

Example 23 with CodeList

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;
}
Also used : HashMap(java.util.HashMap) CodeListService(org.openforis.idm.metamodel.CodeListService) ArrayList(java.util.ArrayList) CodeList(org.openforis.idm.metamodel.CodeList) List(java.util.List) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 24 with CodeList

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);
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CsvWriter(org.openforis.commons.io.csv.CsvWriter) OutputStreamWriter(java.io.OutputStreamWriter) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 25 with CodeList

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);
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException)

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