Search in sources :

Example 6 with CodeListService

use of org.openforis.idm.metamodel.CodeListService 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 7 with CodeListService

use of org.openforis.idm.metamodel.CodeListService 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 8 with CodeListService

use of org.openforis.idm.metamodel.CodeListService 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)

Example 9 with CodeListService

use of org.openforis.idm.metamodel.CodeListService in project collect by openforis.

the class CodeColumnProvider method extractValue.

@Override
protected String extractValue(Attribute<?, ?> attr, String fieldName) {
    if (ITEM_POSITION_FIELD_NAME.equals(fieldName) || ITEM_LABEL_FIELD_NAME.equals(fieldName)) {
        CodeListService codeListService = getCodeListService();
        CodeListItem item = codeListService.loadItem((CodeAttribute) attr);
        if (item == null) {
            return "";
        } else if (ITEM_POSITION_FIELD_NAME.equals(fieldName)) {
            List<CodeListItem> items = codeListService.loadItems(attributeDefinition.getList(), attributeDefinition.getLevelPosition());
            int position = items.indexOf(item) + 1;
            return Integer.toString(position);
        } else {
            return item.getLabel(getConfig().getLanguageCode());
        }
    } else {
        return super.extractValue(attr, fieldName);
    }
}
Also used : CodeListService(org.openforis.idm.metamodel.CodeListService) CodeList(org.openforis.idm.metamodel.CodeList) List(java.util.List) ArrayList(java.util.ArrayList) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 10 with CodeListService

use of org.openforis.idm.metamodel.CodeListService in project collect by openforis.

the class RecordUpdater method addEmptyEnumeratedEntities.

private void addEmptyEnumeratedEntities(Entity parentEntity, EntityDefinition enumerableEntityDefn) {
    Record record = parentEntity.getRecord();
    ModelVersion version = record.getVersion();
    CodeAttributeDefinition enumeratingCodeDefn = enumerableEntityDefn.getEnumeratingKeyCodeAttribute(version);
    if (enumeratingCodeDefn != null) {
        CodeList list = enumeratingCodeDefn.getList();
        Survey survey = record.getSurvey();
        CodeListService codeListService = survey.getContext().getCodeListService();
        List<CodeListItem> items = codeListService.loadRootItems(list);
        int i = 0;
        for (CodeListItem item : items) {
            if (version == null || version.isApplicable(item)) {
                String code = item.getCode();
                Entity enumeratedEntity = parentEntity.getEnumeratedEntity(enumerableEntityDefn, enumeratingCodeDefn, code);
                if (enumeratedEntity == null) {
                    Entity addedEntity = performEntityAdd(parentEntity, enumerableEntityDefn, i);
                    addEmptyNodes(addedEntity);
                    // set the value of the key CodeAttribute
                    CodeAttribute addedCode = (CodeAttribute) addedEntity.getChild(enumeratingCodeDefn, 0);
                    addedCode.setValue(new Code(code));
                    addedCode.updateSummaryInfo();
                } else if (enumeratedEntity.getIndex() != i) {
                    parentEntity.move(enumerableEntityDefn, enumeratedEntity.getIndex(), i);
                }
                i++;
            }
        }
    }
}
Also used : Entity(org.openforis.idm.model.Entity) CodeListService(org.openforis.idm.metamodel.CodeListService) Code(org.openforis.idm.model.Code) CodeList(org.openforis.idm.metamodel.CodeList) Survey(org.openforis.idm.metamodel.Survey) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeAttribute(org.openforis.idm.model.CodeAttribute) Record(org.openforis.idm.model.Record) ModelVersion(org.openforis.idm.metamodel.ModelVersion) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Aggregations

CodeListService (org.openforis.idm.metamodel.CodeListService)19 CodeListItem (org.openforis.idm.metamodel.CodeListItem)13 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)8 CodeList (org.openforis.idm.metamodel.CodeList)8 SurveyContext (org.openforis.idm.metamodel.SurveyContext)6 ArrayList (java.util.ArrayList)4 CollectSurvey (org.openforis.collect.model.CollectSurvey)3 HashMap (java.util.HashMap)2 List (java.util.List)2 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)2 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)2 Survey (org.openforis.idm.metamodel.Survey)2 Code (org.openforis.idm.model.Code)2 NumberValue (org.openforis.idm.model.NumberValue)2 IOException (java.io.IOException)1 NumberFormat (java.text.NumberFormat)1 ExternalizedProperty (org.granite.messaging.amf.io.util.externalizer.annotation.ExternalizedProperty)1 CodeListItemProxy (org.openforis.collect.metamodel.proxy.CodeListItemProxy)1 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1