Search in sources :

Example 11 with CodeListItem

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

the class CollectRecordIntegrationTest method createMultipleLevelCodeListTestSurvey.

private CollectSurvey createMultipleLevelCodeListTestSurvey() {
    CollectSurvey survey = surveyManager.createTemporarySurvey("test", "en");
    CodeList codeList = survey.createCodeList();
    {
        CodeListLevel codeListLevel = new CodeListLevel();
        codeListLevel.setName("level1");
        codeList.addLevel(codeListLevel);
    }
    {
        CodeListLevel codeListLevel = new CodeListLevel();
        codeListLevel.setName("level2");
        codeList.addLevel(codeListLevel);
    }
    {
        CodeListLevel codeListLevel = new CodeListLevel();
        codeListLevel.setName("level3");
        codeList.addLevel(codeListLevel);
    }
    {
        CodeListItem item = codeList.createItem(1);
        item.setCode("A");
        codeList.addItem(item);
        {
            CodeListItem child = codeList.createItem(2);
            child.setCode("1");
            item.addChildItem(child);
            {
                CodeListItem child2 = codeList.createItem(3);
                child2.setCode("a");
                child.addChildItem(child2);
            }
            {
                CodeListItem child2 = codeList.createItem(3);
                child2.setCode("b");
                child.addChildItem(child2);
            }
            {
                CodeListItem child2 = codeList.createItem(3);
                child2.setCode("c");
                child.addChildItem(child2);
            }
        }
        {
            CodeListItem child = codeList.createItem(2);
            child.setCode("2");
            item.addChildItem(child);
            {
                CodeListItem child2 = codeList.createItem(3);
                child2.setCode("a");
                child.addChildItem(child2);
            }
            {
                CodeListItem child2 = codeList.createItem(3);
                child2.setCode("b");
                child.addChildItem(child2);
            }
            {
                CodeListItem child2 = codeList.createItem(3);
                child2.setCode("c");
                child.addChildItem(child2);
            }
        }
        {
            CodeListItem child = codeList.createItem(2);
            child.setCode("3");
            item.addChildItem(child);
            {
                CodeListItem child2 = codeList.createItem(3);
                child2.setCode("a");
                child.addChildItem(child2);
            }
            {
                CodeListItem child2 = codeList.createItem(3);
                child2.setCode("b");
                child.addChildItem(child2);
            }
            {
                CodeListItem child2 = codeList.createItem(3);
                child2.setCode("c");
                child.addChildItem(child2);
            }
        }
    }
    {
        CodeListItem item = codeList.createItem(1);
        item.setCode("B");
        codeList.addItem(item);
        {
            CodeListItem child = codeList.createItem(2);
            child.setCode("1");
            item.addChildItem(child);
            {
                CodeListItem child2 = codeList.createItem(3);
                child2.setCode("a");
                child.addChildItem(child2);
            }
            {
                CodeListItem child2 = codeList.createItem(3);
                child2.setCode("b");
                child.addChildItem(child2);
            }
            {
                CodeListItem child2 = codeList.createItem(3);
                child2.setCode("c");
                child.addChildItem(child2);
            }
        }
        {
            CodeListItem child = codeList.createItem(2);
            child.setCode("2");
            item.addChildItem(child);
            {
                CodeListItem child2 = codeList.createItem(3);
                child2.setCode("a");
                child.addChildItem(child2);
            }
            {
                CodeListItem child2 = codeList.createItem(3);
                child2.setCode("b");
                child.addChildItem(child2);
            }
            {
                CodeListItem child2 = codeList.createItem(3);
                child2.setCode("c");
                child.addChildItem(child2);
            }
        }
        {
            CodeListItem child = codeList.createItem(2);
            child.setCode("3");
            item.addChildItem(child);
            {
                CodeListItem child2 = codeList.createItem(3);
                child2.setCode("a");
                child.addChildItem(child2);
            }
            {
                CodeListItem child2 = codeList.createItem(3);
                child2.setCode("b");
                child.addChildItem(child2);
            }
            {
                CodeListItem child2 = codeList.createItem(3);
                child2.setCode("c");
                child.addChildItem(child2);
            }
        }
    }
    survey.addCodeList(codeList);
    Schema schema = survey.getSchema();
    EntityDefinition root = schema.createEntityDefinition();
    root.setName("root");
    schema.addRootEntityDefinition(root);
    {
        CodeAttributeDefinition codeAttrDefn = schema.createCodeAttributeDefinition();
        codeAttrDefn.setList(codeList);
        codeAttrDefn.setName("code1");
        root.addChildDefinition(codeAttrDefn);
    }
    {
        CodeAttributeDefinition codeAttrDefn = schema.createCodeAttributeDefinition();
        codeAttrDefn.setList(codeList);
        codeAttrDefn.setName("code2");
        codeAttrDefn.setParentExpression("code1");
        root.addChildDefinition(codeAttrDefn);
    }
    {
        CodeAttributeDefinition codeAttrDefn = schema.createCodeAttributeDefinition();
        codeAttrDefn.setList(codeList);
        codeAttrDefn.setName("code3");
        codeAttrDefn.setParentExpression("code2");
        root.addChildDefinition(codeAttrDefn);
    }
    survey.init();
    return survey;
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeListLevel(org.openforis.idm.metamodel.CodeListLevel) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Schema(org.openforis.idm.metamodel.Schema) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 12 with CodeListItem

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

the class MinCountValidator method isAvailableCodeListItems.

private boolean isAvailableCodeListItems(Entity parentEntity) {
    CodeAttributeDefinition codeAttrDef = (CodeAttributeDefinition) nodeDefinition;
    SurveyContext context = codeAttrDef.getSurvey().getContext();
    CodeListService codeListService = context.getCodeListService();
    if (codeListService == null) {
        // test context does not have a CodeListService
        return true;
    }
    List<CodeListItem> validItems = codeListService.loadValidItems(parentEntity, codeAttrDef);
    return !validItems.isEmpty();
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeListService(org.openforis.idm.metamodel.CodeListService) CodeListItem(org.openforis.idm.metamodel.CodeListItem) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Example 13 with CodeListItem

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

the class CodeListImportTask 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 14 with CodeListItem

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

the class CodeListImportTask method processLevel.

protected CodeListItem processLevel(CodeListItem parent, CodeListLine line, int levelIdx, boolean lastLevel) {
    CodeListItem result;
    // validate code
    List<String> codes = line.getLevelCodes();
    if (codes.isEmpty()) {
        addEmptyCodeColumnError(line, levelIdx);
    }
    String code = codes.get(levelIdx);
    if (lastLevel && isDuplicate(code, parent)) {
        addDuplicateCodeError(line, levelIdx);
    }
    // validate labels
    List<LanguageSpecificText> labels = line.getLabelItems(levelIdx);
    for (LanguageSpecificText label : labels) {
        if (hasDifferentLabel(code, label, parent)) {
            addDifferentLabelError(line, levelIdx, label.getLanguage());
        }
    }
    result = getChildItem(parent, code);
    if (result == null) {
        result = codeList.createItem(levelIdx + 1);
        List<LanguageSpecificText> descriptions = line.getDescriptionItems(levelIdx);
        fillItem(result, code, labels, descriptions);
        if (parent == null) {
            codeToRootItem.put(code, result);
        } else {
            parent.addChildItem(result);
        }
    }
    return result;
}
Also used : LanguageSpecificText(org.openforis.idm.metamodel.LanguageSpecificText) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 15 with CodeListItem

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

the class CEComponentHTMLFormatter method buildCodeSelect.

private void buildCodeSelect(XMLBuilder builder, CECodeField comp) {
    String elId = comp.getHtmlParameterName();
    // build select
    XMLBuilder selectBuilder = // $NON-NLS-1$
    builder.e("select").a("id", // $NON-NLS-1$
    elId).a("name", // $NON-NLS-1$
    elId).a("data-field-type", // $NON-NLS-1$
    comp.getType().name()).a("class", // $NON-NLS-1$ //$NON-NLS-2$
    "form-control selectboxit show-menu-arrow show-tick").a("data-width", // $NON-NLS-1$ //$NON-NLS-2$
    "75px");
    if (comp.getParentName() != null) {
        // $NON-NLS-1$
        selectBuilder.a("data-parent-id-field-id", comp.getParentName());
    }
    // add root items, if any
    Map<Integer, List<CodeListItem>> itemsByParentCode = ((CECodeField) comp).getCodeItemsByParentId();
    List<CodeListItem> rootItems = itemsByParentCode.get(0);
    if (rootItems != null) {
        boolean hasNAoption = false;
        for (CodeListItem item : rootItems) {
            if (// $NON-NLS-1$
            item.getCode().equalsIgnoreCase("na") || // $NON-NLS-1$
            item.getCode().equalsIgnoreCase("n/a")) {
                hasNAoption = true;
            }
        }
        if (!hasNAoption) {
            // $NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            selectBuilder.e("option").a("value", "").t(HtmlUnicodeEscaperUtil.escapeForBalloon(Messages.getString("CEComponentHTMLFormatter.119", language)));
        }
        for (CodeListItem item : rootItems) {
            String itemLabel = getItemLabel(item);
            // $NON-NLS-1$
            selectBuilder.e("option").a("value", // $NON-NLS-1$
            item.getCode()).t(itemLabel);
        }
    }
}
Also used : List(java.util.List) CodeListItem(org.openforis.idm.metamodel.CodeListItem) XMLBuilder(com.jamesmurty.utils.XMLBuilder)

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