use of org.openforis.idm.metamodel.CodeList 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"));
}
}
}
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListFormValidator method validateNameUniqueness.
protected boolean validateNameUniqueness(ValidationContext ctx) {
SurveyObjectBaseVM<CodeList> viewModel = getVM(ctx);
CodeList editedItem = viewModel.getEditedItem();
CollectSurvey survey = viewModel.getSurvey();
String name = (String) getValue(ctx, NAME_FIELD);
CodeList existingItem = survey.getCodeList(name);
if (existingItem != null && existingItem.getId() != editedItem.getId()) {
String message = Labels.getLabel(ITEM_NAME_ALREADY_DEFINED_MESSAGE_KEY);
addInvalidMessage(ctx, NAME_FIELD, message);
return false;
} else {
return true;
}
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListItemFormValidator method getExistingCodeListItem.
protected CodeListItem getExistingCodeListItem(ValidationContext ctx, String code) {
SurveyObjectBaseVM<CodeListItem> viewModel = getVM(ctx);
CodeListItem editedItem = viewModel.getEditedItem();
CodeList codeList = editedItem.getCodeList();
CodeListItem parentItem = getParentItem(ctx);
CodeListItem existingItem = null;
CodeListManager codeListManager = getCodeListManager(ctx);
if (parentItem == null) {
existingItem = codeListManager.loadRootItem(codeList, code, null);
} else {
existingItem = codeListManager.loadChildItem(parentItem, code, null);
}
return existingItem;
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListsPopUpVM method getSelectedCodeList.
private CodeList getSelectedCodeList(Binder binder) {
Component view = binder.getView();
IdSpace spaceOwner = view.getSpaceOwner();
Component innerInclude = spaceOwner.getFellow("codeListsInclude");
Component managerContainer = innerInclude.getSpaceOwner().getFellow("codeListsManagerContainer");
CodeListsVM vm = (CodeListsVM) managerContainer.getAttribute("vm");
CodeList codeList = vm.getSelectedItem();
return codeList;
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListsVM method getItemsInternal.
@Override
protected List<CodeList> getItemsInternal() {
CollectSurvey survey = getSurvey();
if (survey == null) {
// TODO session expired
return Collections.emptyList();
}
List<CodeList> codeLists = survey.getCodeLists(false);
codeLists = sort(codeLists);
return codeLists;
}
Aggregations