Search in sources :

Example 11 with CodeAttributeDefinition

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

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

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

the class MondrianCubeGenerator method generateLevel.

private List<Level> generateLevel(NodeDefinition nodeDef) {
    List<Level> levels = new ArrayList<Level>();
    String attrLabel = extractFailsafeLabel(nodeDef);
    Level level = new Level(attrLabel);
    levels.add(level);
    if (nodeDef instanceof NumericAttributeDefinition) {
        level.type = ((NumericAttributeDefinition) nodeDef).getType() == Type.INTEGER ? INTEGER_DATATYPE : NUMERIC_DATATYPE;
    } else if (nodeDef instanceof CodeAttributeDefinition) {
        level.type = ((CodeAttributeDefinition) nodeDef).getList().isExternal() ? STRING_DATATYPE : INTEGER_DATATYPE;
    } else {
        level.type = STRING_DATATYPE;
    }
    level.levelType = "Regular";
    if (nodeDef instanceof CodeAttributeDefinition) {
        CodeAttributeDefinition codeDef = (CodeAttributeDefinition) nodeDef;
        String codeTableName = extractCodeListTableName(codeDef);
        level.table = codeTableName;
        level.column = codeTableName + rdbConfig.getIdColumnSuffix();
        level.nameColumn = codeTableName.substring(0, codeTableName.length() - rdbConfig.getCodeListTableSuffix().length()) + "_label_" + language;
        Level levelId = new Level(attrLabel + " -  ID");
        levelId.type = "String";
        levelId.table = codeTableName;
        levelId.column = codeTableName + rdbConfig.getIdColumnSuffix();
        levelId.nameColumn = extractCodeListName(codeDef);
        levels.add(levelId);
    } else {
        level.column = nodeDef.getName();
    }
    return levels;
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) ArrayList(java.util.ArrayList) CodeListLevel(org.openforis.idm.metamodel.CodeListLevel) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition)

Example 14 with CodeAttributeDefinition

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

the class NewMondrianSchemaGenerator method generateLevel.

private Level generateLevel(AttributeDefinition nodeDef) {
    DataTable dataTable = rdbSchema.getDataTable(nodeDef.getParentDefinition());
    Level level = new Level(determineDimensionName(nodeDef), determineLevelCaption(nodeDef));
    level.levelType = "Regular";
    if (nodeDef instanceof NumericAttributeDefinition) {
        level.type = ((NumericAttributeDefinition) nodeDef).getType() == Type.INTEGER ? INTEGER_DATATYPE : NUMERIC_DATATYPE;
    } else if (nodeDef instanceof BooleanAttributeDefinition) {
        level.type = BOOLEAN_DATATYPE;
    } else if (nodeDef instanceof CodeAttributeDefinition) {
        level.type = ((CodeAttributeDefinition) nodeDef).getList().isExternal() ? STRING_DATATYPE : INTEGER_DATATYPE;
    } else {
        level.type = STRING_DATATYPE;
    }
    if (nodeDef instanceof CodeAttributeDefinition && !((CodeAttributeDefinition) nodeDef).getList().isExternal()) {
        CodeAttributeDefinition codeDef = (CodeAttributeDefinition) nodeDef;
        CodeTable codeListTable = rdbSchema.getCodeListTable(codeDef);
        level.table = codeListTable.getName();
        level.column = codeListTable.getPrimaryKeyConstraint().getPrimaryKeyColumn().getName();
        level.nameColumn = CodeListTables.getLabelColumnName(rdbConfig, codeDef.getList(), codeDef.getLevelIndex(), language);
    } else if (nodeDef instanceof TaxonAttributeDefinition) {
        DataColumn dataColumn = dataTable.getDataColumn(((TaxonAttributeDefinition) nodeDef).getCodeFieldDefinition());
        level.column = dataColumn.getName();
    } else if (nodeDef.isMultiple()) {
        // TODO skip multiple attributes?
        level.column = nodeDef.getName();
    } else {
        DataColumn dataColumn = dataTable.getDataColumn(nodeDef.getMainFieldDefinition());
        level.column = dataColumn.getName();
    }
    return level;
}
Also used : CodeTable(org.openforis.collect.relational.model.CodeTable) DataTable(org.openforis.collect.relational.model.DataTable) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) DataColumn(org.openforis.collect.relational.model.DataColumn) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition)

Example 15 with CodeAttributeDefinition

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

Aggregations

CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)48 CodeList (org.openforis.idm.metamodel.CodeList)21 CodeListItem (org.openforis.idm.metamodel.CodeListItem)19 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)13 ArrayList (java.util.ArrayList)12 CollectSurvey (org.openforis.collect.model.CollectSurvey)8 CodeListService (org.openforis.idm.metamodel.CodeListService)8 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)8 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)7 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)7 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)6 ModelVersion (org.openforis.idm.metamodel.ModelVersion)6 Code (org.openforis.idm.model.Code)6 Entity (org.openforis.idm.model.Entity)6 DataTable (org.openforis.collect.relational.model.DataTable)5 CodeAttribute (org.openforis.idm.model.CodeAttribute)5 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)4 CollectRecord (org.openforis.collect.model.CollectRecord)4 CodeTable (org.openforis.collect.relational.model.CodeTable)4 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)4