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"));
}
}
}
}
Aggregations