Search in sources :

Example 1 with CodeAttributeVM

use of org.openforis.collect.designer.viewmodel.CodeAttributeVM 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)

Aggregations

CodeAttributeVM (org.openforis.collect.designer.viewmodel.CodeAttributeVM)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 CodeList (org.openforis.idm.metamodel.CodeList)1