Search in sources :

Example 61 with CodeListItem

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

the class CodeListImportProcess method hasDifferentLabel.

protected boolean hasDifferentLabel(String code, LanguageSpecificText item, CodeListItem parentItem) {
    CodeListItem existingItem = getChildItem(parentItem, code);
    if (existingItem == null) {
        return false;
    } else {
        String lang = item.getLanguage();
        String label = item.getText();
        String existingItemLabel = existingItem.getLabel(lang);
        return !existingItemLabel.equals(label);
    }
}
Also used : CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 62 with CodeListItem

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

the class CodeListImportProcess method isDuplicate.

/**
 * Returns when:
 * not is leaf but has different label than existing node with same code
 * or is leaf and:
 * - LOCAL scope and exist item with same code at the same level
 * - SCHEME scope and exist item with same code in some level
 * @param code
 * @param parentItem
 * @param lastLevel
 * @return
 */
protected boolean isDuplicate(String code, CodeListItem parentItem) {
    CodeListItem duplicateItem;
    duplicateItem = getChildItem(parentItem, code);
    return duplicateItem != null;
}
Also used : CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 63 with CodeListItem

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

the class CodeListImportProcess method getCodeListItemInDescendants.

protected CodeListItem getCodeListItemInDescendants(String code) {
    Deque<CodeListItem> stack = new LinkedList<CodeListItem>();
    stack.addAll(codeToRootItem.values());
    while (!stack.isEmpty()) {
        CodeListItem item = stack.pop();
        if (item.matchCode(code)) {
            return item;
        } else {
            stack.addAll(item.getChildItems());
        }
    }
    return null;
}
Also used : CodeListItem(org.openforis.idm.metamodel.CodeListItem) LinkedList(java.util.LinkedList)

Example 64 with CodeListItem

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

the class CollectEarthBalloonGenerator method createEnumeratedEntityComponent.

private CEComponent createEnumeratedEntityComponent(EntityDefinition def) {
    String label = def.getLabel(Type.INSTANCE, language);
    if (label == null && !isDefaultLanguage()) {
        label = def.getLabel(Type.INSTANCE);
    }
    if (label == null) {
        label = def.getName();
    }
    UIOptions uiOptions = survey.getUIOptions();
    String tableTooltip = def.getDescription(language);
    CEEnumeratedEntityTable ceTable = new CEEnumeratedEntityTable(def.getName(), label, tableTooltip);
    for (NodeDefinition child : def.getChildDefinitions()) {
        if (!uiOptions.isHidden(child)) {
            String heading = child.getLabel(Type.INSTANCE, language);
            if (heading == null && !isDefaultLanguage()) {
                heading = child.getLabel(Type.INSTANCE);
            }
            if (heading == null) {
                heading = child.getName();
            }
            ceTable.addHeading(heading);
        }
    }
    CodeAttributeDefinition enumeratingCodeAttribute = def.getEnumeratingKeyCodeAttribute();
    CodeListService codeListService = def.getSurvey().getContext().getCodeListService();
    List<CodeListItem> codeItems = codeListService.loadRootItems(enumeratingCodeAttribute.getList());
    int codeItemIdx = 0;
    for (CodeListItem item : codeItems) {
        String key = item.getCode();
        String itemLabel = CEComponentHTMLFormatter.getItemLabel(item, language);
        String tooltip = CEComponentHTMLFormatter.getDescription(item, language);
        CETableRow row = new CETableRow(key, itemLabel, tooltip);
        for (NodeDefinition child : def.getChildDefinitions()) {
            if (!uiOptions.isHidden(child)) {
                row.addChild(createComponent(child, codeItemIdx + 1));
            }
        }
        ceTable.addRow(row);
        codeItemIdx++;
    }
    return ceTable;
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) CodeListService(org.openforis.idm.metamodel.CodeListService) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 65 with CodeListItem

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

the class VersioningVM method getReferencesInCodeLists.

protected List<VersionableSurveyObject> getReferencesInCodeLists(ModelVersion version) {
    List<VersionableSurveyObject> references = new ArrayList<VersionableSurveyObject>();
    List<CodeList> codeLists = survey.getCodeLists();
    for (CodeList codeList : codeLists) {
        if (isVersionInUse(version, codeList)) {
            references.add(codeList);
        }
        if (!codeList.isExternal()) {
            List<CodeListItem> items = codeList.getItems();
            Stack<CodeListItem> itemsStack = new Stack<CodeListItem>();
            itemsStack.addAll(items);
            while (!itemsStack.isEmpty()) {
                CodeListItem item = itemsStack.pop();
                if (isVersionInUse(version, item)) {
                    references.add(item);
                }
                itemsStack.addAll(item.getChildItems());
            }
        }
    }
    return references;
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) VersionableSurveyObject(org.openforis.idm.metamodel.VersionableSurveyObject) ArrayList(java.util.ArrayList) CodeListItem(org.openforis.idm.metamodel.CodeListItem) Stack(java.util.Stack)

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