Search in sources :

Example 26 with CodeListItem

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

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

the class CodeColumnProvider method generateExpandedItemsHeadings.

private List<String> generateExpandedItemsHeadings() {
    List<String> headings = new ArrayList<String>();
    for (CodeListItem item : expandedItems) {
        String heading = ColumnProviders.generateHeadingPrefix(attributeDefinition, config) + getConfig().getFieldHeadingSeparator() + item.getCode();
        headings.add(heading);
        if (item.isQualifiable()) {
            headings.add(heading + getConfig().getFieldHeadingSeparator() + CodeAttributeDefinition.QUALIFIER_FIELD);
        }
    }
    return headings;
}
Also used : ArrayList(java.util.ArrayList) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 28 with CodeListItem

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

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

the class SurveyValidator method validateEnumeratingCodeListNotChanged.

protected List<SurveyValidationResult> validateEnumeratingCodeListNotChanged(CodeList oldCodeList, CodeList codeList) {
    List<SurveyValidationResult> results = new ArrayList<SurveyValidationResult>();
    List<CodeListItem> oldItems = codeListManager.loadRootItems(oldCodeList);
    for (CodeListItem oldItem : oldItems) {
        CodeListItem newItem = codeListManager.loadRootItem(codeList, oldItem.getCode(), null);
        if (newItem == null) {
            String messageKey = "survey.validation.error.enumerating_code_list_changed.code_removed";
            String codeListPath = String.format(CODE_LIST_PATH_FORMAT, codeList.getName());
            String path = codeListPath + "/" + oldItem.getCode();
            SurveyValidationResult validationError = new SurveyValidationResult(path, messageKey);
            results.add(validationError);
        }
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 30 with CodeListItem

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

CodeListItem (org.openforis.idm.metamodel.CodeListItem)69 CodeList (org.openforis.idm.metamodel.CodeList)26 ArrayList (java.util.ArrayList)19 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)19 PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)18 CodeListService (org.openforis.idm.metamodel.CodeListService)13 List (java.util.List)7 CollectSurvey (org.openforis.collect.model.CollectSurvey)7 ModelVersion (org.openforis.idm.metamodel.ModelVersion)7 Test (org.junit.Test)5 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)5 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)5 Entity (org.openforis.idm.model.Entity)5 Record (org.openforis.idm.model.Record)5 CodeListItemProxy (org.openforis.collect.metamodel.proxy.CodeListItemProxy)4 CollectRecord (org.openforis.collect.model.CollectRecord)4 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)4 CodeAttribute (org.openforis.idm.model.CodeAttribute)4 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3