Search in sources :

Example 26 with CodeAttributeDefinition

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

the class DatabaseExternalCodeListProvider method getLevelKeyColumnName.

protected String getLevelKeyColumnName(CodeAttribute codeAttribute) {
    CodeAttributeDefinition defn = codeAttribute.getDefinition();
    CodeList list = defn.getList();
    if (list.getHierarchy().isEmpty()) {
        return defn.getName();
    } else {
        int level = defn.getLevelPosition();
        return getLevelKeyColumnName(list, level);
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition)

Example 27 with CodeAttributeDefinition

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

the class BaseAttributeUpdateRequestProxy method parseCompositeAttributeValue.

protected Value parseCompositeAttributeValue(CodeListManager codeListManager, Entity parentEntity, String attributeName, Object value) {
    EntityDefinition parentEntityDefn = parentEntity.getDefinition();
    AttributeDefinition defn = (AttributeDefinition) parentEntityDefn.getChildDefinition(attributeName);
    if (defn instanceof CodeAttributeDefinition) {
        if (value instanceof String) {
            String stringVal = (String) value;
            Value result = parseCode(codeListManager, parentEntity, (CodeAttributeDefinition) defn, stringVal);
            return result;
        } else {
            throw new IllegalArgumentException("Invalid value type: expected String");
        }
    } else if (defn instanceof RangeAttributeDefinition) {
        if (value instanceof String) {
            String stringVal = (String) value;
            RangeAttributeDefinition rangeDef = (RangeAttributeDefinition) defn;
            RangeAttributeDefinition.Type type = rangeDef.getType();
            NumericRange<?> range = null;
            // todo check if unit is required here or is set later by the client
            Unit unit = null;
            switch(type) {
                case INTEGER:
                    range = IntegerRange.parseIntegerRange(stringVal, unit);
                    break;
                case REAL:
                    range = RealRange.parseRealRange(stringVal, unit);
                    break;
            }
            return range;
        } else {
            throw new IllegalArgumentException("Invalid value type: expected String");
        }
    } else {
        throw new IllegalArgumentException("Invalid AttributeDefinition: expected CodeAttributeDefinition or RangeAttributeDefinition");
    }
}
Also used : NumericRange(org.openforis.idm.model.NumericRange) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Value(org.openforis.idm.model.Value) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition) Unit(org.openforis.idm.metamodel.Unit) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition)

Example 28 with CodeAttributeDefinition

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

the class SurveyViewGenerator method generateView.

public SurveyView generateView(final CollectSurvey survey) {
    final SurveyView surveyView = new SurveyView(survey);
    List<CodeList> codeLists = survey.getCodeLists();
    for (CodeList codeList : codeLists) {
        CodeListView codeListView = new CodeListView();
        codeListView.setId(codeList.getId());
        codeListView.setName(codeList.getName());
        codeListView.setLabel(codeList.getLabel(CodeListLabel.Type.ITEM, languageCode));
        if (includeCodeListValues && !codeList.isExternal()) {
            CodeListService service = survey.getContext().getCodeListService();
            List<CodeListItem> items = service.loadRootItems(codeList);
            for (CodeListItem item : items) {
                codeListView.addItem(createCodeListItemView(item));
            }
        }
        surveyView.addCodeList(codeListView);
    }
    final Map<Integer, NodeDefView> viewById = new HashMap<Integer, NodeDefView>();
    survey.getSchema().traverse(new NodeDefinitionVisitor() {

        public void visit(NodeDefinition def) {
            int id = def.getId();
            String name = def.getName();
            String label = getLabel(def);
            NodeDefView view;
            if (def instanceof EntityDefinition) {
                view = new EntityDefView(((EntityDefinition) def).isRoot(), id, name, label, def.isMultiple());
            } else if (def instanceof CodeAttributeDefinition) {
                CodeAttributeDefinition attrDef = (CodeAttributeDefinition) def;
                int codeListId = attrDef.getList() == null ? -1 : attrDef.getList().getId();
                view = new CodeAttributeDefView(id, name, label, AttributeType.valueOf(attrDef), attrDef.getFieldNames(), attrDef.isKey(), attrDef.isMultiple(), survey.getAnnotations().isShowInSummary(attrDef), survey.getAnnotations().isQualifier(attrDef), codeListId);
            } else {
                AttributeDefinition attrDef = (AttributeDefinition) def;
                view = new AttributeDefView(id, name, label, AttributeType.valueOf(attrDef), attrDef.getFieldNames(), attrDef.isKey(), attrDef.isMultiple(), survey.getAnnotations().isShowInSummary(attrDef), survey.getAnnotations().isQualifier(attrDef));
            }
            NodeDefinition parentDef = def.getParentDefinition();
            if (parentDef == null) {
                surveyView.getSchema().addRootEntity((EntityDefView) view);
            } else {
                EntityDefView parentView = (EntityDefView) viewById.get(parentDef.getId());
                parentView.addChild(view);
            }
            viewById.put(id, view);
        }
    });
    return surveyView;
}
Also used : HashMap(java.util.HashMap) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) CodeListService(org.openforis.idm.metamodel.CodeListService) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor) CodeList(org.openforis.idm.metamodel.CodeList) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 29 with CodeAttributeDefinition

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

the class CodeParentValidator method isExternalCodeList.

private boolean isExternalCodeList(CodeAttribute node) {
    CodeAttributeDefinition definition = node.getDefinition();
    CodeList codeList = definition.getList();
    return codeList.isExternal();
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition)

Example 30 with CodeAttributeDefinition

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

the class CodeValueFKColumnValueExtractor method extractValue.

@Override
public Object extractValue(Node<?> context) {
    CodeAttributeDefinition defn = (CodeAttributeDefinition) column.getNodeDefinition();
    Node<?> valNode = super.extractValueNode(context);
    if (valNode != null && valNode instanceof CodeAttribute) {
        return extractValue((CodeAttribute) valNode);
    } else if (column.getDefaultCodeValue() != null) {
        ModelVersion version = context.getRecord().getVersion();
        return getDefaultCodeItemId(((CodeAttributeDefinition) defn).getList(), version);
    } else {
        return null;
    }
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeAttribute(org.openforis.idm.model.CodeAttribute) ModelVersion(org.openforis.idm.metamodel.ModelVersion)

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