Search in sources :

Example 61 with CodeList

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"));
            }
        }
    }
}
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 62 with CodeList

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;
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 63 with CodeList

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;
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeListManager(org.openforis.collect.manager.CodeListManager) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 64 with CodeList

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;
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) IdSpace(org.zkoss.zk.ui.IdSpace) Component(org.zkoss.zk.ui.Component)

Example 65 with 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;
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Aggregations

CodeList (org.openforis.idm.metamodel.CodeList)88 CodeListItem (org.openforis.idm.metamodel.CodeListItem)24 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)20 ArrayList (java.util.ArrayList)16 CollectSurvey (org.openforis.collect.model.CollectSurvey)15 PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)14 Test (org.junit.Test)10 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)10 HashMap (java.util.HashMap)7 NameValueEntry (org.openforis.collect.model.NameValueEntry)7 CodeListService (org.openforis.idm.metamodel.CodeListService)7 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)6 List (java.util.List)5 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)5 ModelVersion (org.openforis.idm.metamodel.ModelVersion)5 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)5 Code (org.openforis.idm.model.Code)5 Record (org.openforis.idm.model.Record)5 CodeAttributeDefinitionFormObject (org.openforis.collect.designer.form.CodeAttributeDefinitionFormObject)4 CodeListImportProcess (org.openforis.collect.manager.codelistimport.CodeListImportProcess)4