Search in sources :

Example 66 with CodeList

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

the class CodeListsVM method isCodeListInPublishedSurvey.

protected boolean isCodeListInPublishedSurvey() {
    SessionStatus sessionStatus = getSessionStatus();
    Integer publishedSurveyId = sessionStatus.getPublishedSurveyId();
    if (publishedSurveyId != null) {
        CollectSurvey publishedSurvey = surveyManager.getById(publishedSurveyId);
        CodeList oldPublishedCodeList = publishedSurvey.getCodeListById(editedItem.getId());
        return oldPublishedCodeList != null;
    } else {
        return false;
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) SessionStatus(org.openforis.collect.designer.session.SessionStatus) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 67 with CodeList

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

the class SurveyMigrator method fixCodeListHierarchyLevelNames.

protected void fixCodeListHierarchyLevelNames(CollectSurvey survey) {
    List<CodeList> codeLists = survey.getCodeLists();
    for (CodeList list : codeLists) {
        List<CodeListLevel> hierarchy = list.getHierarchy();
        for (CodeListLevel level : hierarchy) {
            String name = level.getName();
            Pattern pattern = Pattern.compile(INTERNAL_NAME_REGEX);
            Matcher matcher = pattern.matcher(name);
            if (!matcher.matches()) {
                String fixedName = fixInternalName(name);
                level.setName(fixedName);
            }
        }
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) Pattern(java.util.regex.Pattern) CodeListLevel(org.openforis.idm.metamodel.CodeListLevel) Matcher(java.util.regex.Matcher)

Example 68 with CodeList

use of org.openforis.idm.metamodel.CodeList 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 69 with CodeList

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

the class CodeListManager method loadValidItems.

public <T extends CodeListItem> List<T> loadValidItems(Entity parent, CodeAttributeDefinition def) {
    List<T> items = null;
    CodeList list = def.getList();
    if (StringUtils.isEmpty(def.getParentExpression())) {
        items = loadRootItems(list);
    } else {
        CodeAttribute parentCodeAttribute = getCodeParent(parent, def);
        if (parentCodeAttribute != null) {
            CodeListItem parentCodeListItem = loadItemByAttribute(parentCodeAttribute);
            if (parentCodeListItem != null) {
                items = loadChildItems(parentCodeListItem);
            }
        }
    }
    Record record = parent.getRecord();
    ModelVersion version = record.getVersion();
    return filterApplicableItems(items, version);
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeAttribute(org.openforis.idm.model.CodeAttribute) 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)

Example 70 with CodeList

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

the class CodeListManager method getUnusedCodeLists.

protected Set<CodeList> getUnusedCodeLists(CollectSurvey survey) {
    Set<CodeList> result = new HashSet<CodeList>();
    List<CodeList> codeLists = survey.getCodeLists();
    for (CodeList list : codeLists) {
        if (!isInUse(list)) {
            result.add(list);
        }
    }
    return result;
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) HashSet(java.util.HashSet)

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