Search in sources :

Example 31 with CodeAttributeDefinition

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

the class CodeAttributeMapper method addNode.

@Override
CodeAttribute addNode(NodeDefinition defn, Record r, Entity parent) {
    String name = defn.getName();
    String qualifier = r.getValueAsString(DATA.TEXT2);
    CodeAttributeDefinition codeAttrDefn = (CodeAttributeDefinition) defn;
    CodeList list = codeAttrDefn.getList();
    String code = r.getValueAsString(DATA.TEXT1);
    Code value = new Code(code, qualifier);
    return parent.addValue(name, value);
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Code(org.openforis.idm.model.Code)

Example 32 with CodeAttributeDefinition

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

the class CodeAttributeVM method confirmParentCodeListChange.

private void confirmParentCodeListChange(final Binder binder, final CodeList list) {
    ConfirmParams confirmParams = new ConfirmParams(new MessageUtil.CompleteConfirmHandler() {

        @Override
        public void onOk() {
            performListChange(binder, list);
        }

        @Override
        public void onCancel() {
            CodeList oldList = editedItem.getList();
            setFormFieldValue(binder, "list", oldList);
            setTempFormObjectFieldValue("list", oldList);
        }
    }, "survey.schema.attribute.code.confirm_change_list_on_referenced_node.message");
    confirmParams.setOkLabelKey("survey.schema.attribute.code.confirm_change_list_on_referenced_node.ok");
    confirmParams.setTitleKey("survey.schema.attribute.code.confirm_change_list_on_referenced_node.title");
    List<String> dependentAttributePaths = new ArrayList<String>();
    for (CodeAttributeDefinition codeAttributeDefinition : editedItem.getDependentCodeAttributeDefinitions()) {
        dependentAttributePaths.add(codeAttributeDefinition.getPath());
    }
    confirmParams.setMessageArgs(new String[] { StringUtils.join(dependentAttributePaths, ", ") });
    MessageUtil.showConfirm(confirmParams);
}
Also used : ConfirmParams(org.openforis.collect.designer.util.MessageUtil.ConfirmParams) CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) MessageUtil(org.openforis.collect.designer.util.MessageUtil) ArrayList(java.util.ArrayList)

Example 33 with CodeAttributeDefinition

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

the class CodeAttributeDefinitionFormValidator method validateParentAttributeDefinition.

private void validateParentAttributeDefinition(ValidationContext ctx) {
    String parentCodeAttributeDefPath = getValue(ctx, PARENT_CODE_ATTRIBUTE_DEFINITION_PATH_FIELD);
    if (parentCodeAttributeDefPath != null) {
        CodeAttributeVM vm = getVM(ctx);
        CollectSurvey survey = vm.getSurvey();
        CodeAttributeDefinition parentDef = (CodeAttributeDefinition) survey.getSchema().getDefinitionByPath(parentCodeAttributeDefPath);
        if (parentDef != null) {
            CodeList list = getValue(ctx, LIST_FIELD);
            if (list.isHierarchical()) {
                try {
                    Integer parentHierarchicalLevelIdx = parentDef.getListLevelIndex();
                    if (parentHierarchicalLevelIdx + 1 >= list.getHierarchy().size()) {
                        addInvalidMessage(ctx, PARENT_CODE_ATTRIBUTE_DEFINITION_PATH_FIELD, Labels.getLabel("survey.validation.attribute.code.invalid_parent_attribute_relation"));
                    }
                } catch (Exception e) {
                    addInvalidMessage(ctx, PARENT_CODE_ATTRIBUTE_DEFINITION_PATH_FIELD, Labels.getLabel("survey.validation.attribute.code.invalid_parent_attribute_relation_in_referenced_parent_attribute"));
                }
            } else {
                addInvalidMessage(ctx, PARENT_CODE_ATTRIBUTE_DEFINITION_PATH_FIELD, Labels.getLabel("survey.validation.attribute.code.parent_attribute_specified_for_a_flat_list"));
            }
        }
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeAttributeVM(org.openforis.collect.designer.viewmodel.CodeAttributeVM) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 34 with CodeAttributeDefinition

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

the class CodeListManager method loadPersistedItem.

protected PersistedCodeListItem loadPersistedItem(CodeAttribute attribute) {
    Code code = attribute.getValue();
    if (code == null || StringUtils.isBlank(code.getCode())) {
        return null;
    } else {
        String codeVal = code.getCode();
        CodeAttributeDefinition defn = attribute.getDefinition();
        CodeList list = defn.getList();
        Record record = attribute.getRecord();
        ModelVersion version = record.getVersion();
        if (StringUtils.isBlank(defn.getParentExpression())) {
            CodeListItem item = codeListItemDao.loadRootItem(list, codeVal, version);
            return (PersistedCodeListItem) item;
        } else {
            PersistedCodeListItem parentItem = (PersistedCodeListItem) loadParentItem(attribute);
            if (parentItem == null) {
                return null;
            } else {
                CodeListItem item = codeListItemDao.loadItem(list, parentItem.getSystemId(), codeVal, version);
                return (PersistedCodeListItem) item;
            }
        }
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Record(org.openforis.idm.model.Record) ModelVersion(org.openforis.idm.metamodel.ModelVersion) ExternalCodeListItem(org.openforis.idm.metamodel.ExternalCodeListItem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) Code(org.openforis.idm.model.Code) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem)

Example 35 with CodeAttributeDefinition

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

the class CodeListManager method getInternalCodeListItem.

protected CodeListItem getInternalCodeListItem(CodeAttribute attribute) {
    Code code = attribute.getValue();
    if (code != null) {
        String codeValue = code.getCode();
        if (StringUtils.isNotBlank(codeValue)) {
            ModelVersion currentVersion = attribute.getRecord().getVersion();
            CodeAttributeDefinition definition = attribute.getDefinition();
            String parentExpression = definition.getParentExpression();
            if (StringUtils.isBlank(parentExpression)) {
                return getCodeListItem(definition.getList().getItems(), codeValue, currentVersion);
            } else {
                CodeAttribute codeParent = attribute.getCodeParent();
                if (codeParent != null) {
                    CodeListItem codeListItemParent = loadItemByAttribute(codeParent);
                    if (codeListItemParent != null) {
                        return getCodeListItem(codeListItemParent.getChildItems(), codeValue, currentVersion);
                    }
                }
            }
        }
    }
    return null;
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeAttribute(org.openforis.idm.model.CodeAttribute) ModelVersion(org.openforis.idm.metamodel.ModelVersion) ExternalCodeListItem(org.openforis.idm.metamodel.ExternalCodeListItem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) Code(org.openforis.idm.model.Code)

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