Search in sources :

Example 76 with CodeList

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

the class RelationalSchemaGenerator method addCodeListTables.

private void addCodeListTables(RelationalSchema rs) throws CollectRdbException {
    Survey survey = rs.getSurvey();
    List<CodeList> codeLists = survey.getCodeLists();
    for (CodeList codeList : codeLists) {
        addCodeListTable(rs, codeList);
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) Survey(org.openforis.idm.metamodel.Survey) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 77 with CodeList

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

the class RelationalSchemaGenerator method addCodeAttributeDataColumns.

private void addCodeAttributeDataColumns(RelationalSchema rs, DataTable table, CodeAttributeDefinition defn, Path relativePath) throws CollectRdbException {
    FieldDefinition<?> codeField = defn.getFieldDefinition(CodeAttributeDefinition.CODE_FIELD);
    addCodeColumn(table, codeField, relativePath);
    CodeList list = defn.getList();
    if (!list.isExternal()) {
        addCodeValueFKColumn(rs, table, defn, relativePath);
    }
    boolean qualifiable = isQualifiable(list);
    if (qualifiable) {
        addDataColumn(table, defn.getFieldDefinition(CodeAttributeDefinition.QUALIFIER_FIELD), relativePath);
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList)

Example 78 with CodeList

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

the class IdmDatabaseSnapshotBuilder method createCodeListTables.

// private void createDataTable(EntityDefinition defn)  throws DatabaseException {
// Set<Table> tables = snapshot.getTables();
// 
// // Tail recursion so that leaf tables are created first; required for relations
// List<NodeDefinition> childDefns = ((EntityDefinition) defn).getChildDefinitions();
// for (NodeDefinition child : childDefns) {
// if ( child instanceof EntityDefinition ) {
// createDataTable((EntityDefinition) child);
// }
// }
// 
// IdmDataTableBuilder dtb = new IdmDataTableBuilder(defn);
// dtb.setTablePrefix(tablePrefix);
// dtb.setTableSuffix(dataTableSuffix);
// Table table = dtb.toTable();
// 
// if ( tables.contains(table) ) {
// throw new DatabaseException("Duplicate table name '"+table.getName()+"' for "+defn.getPath());
// }
// 
// tables.add(table);
// }
// TODO hierarchical code lists as multiple tables
private void createCodeListTables() throws DatabaseException {
    List<CodeList> lists = survey.getCodeLists();
    for (CodeList list : lists) {
        IdmCodeListTableBuilder tb = new IdmCodeListTableBuilder();
        tb.setList(list);
        tb.setTablePrefix(tablePrefix);
        tb.setTableSuffix(codeTableSuffix);
        Table table = tb.toTable();
        if (tables.contains(table)) {
            throw new DatabaseException("Duplicate table name '" + table.getName() + "' for list " + list.getName());
        }
        tables.add(table);
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) Table(liquibase.database.structure.Table) DatabaseException(liquibase.exception.DatabaseException)

Example 79 with CodeList

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

the class RelationalSchema method addTable.

/**
 * Adds a table to the schema.  If table with the same name
 * already exists it will be replaced.
 * @param table
 */
void addTable(Table<?> table) {
    String name = table.getName();
    tablesByName.put(name, table);
    if (table instanceof DataTable) {
        DataTable dataTable = (DataTable) table;
        NodeDefinition defn = dataTable.getNodeDefinition();
        dataTableByDefinitionId.put(defn.getId(), dataTable);
        if (dataTable.getParent() == null) {
            rootDataTables.put(defn.getName(), dataTable);
        }
    } else if (table instanceof CodeTable) {
        CodeTable codeListTable = (CodeTable) table;
        CodeList codeList = codeListTable.getCodeList();
        CodeListTableKey key = new CodeListTableKey(codeList.getId(), codeListTable.getLevelIdx());
        codeListTables.put(key, codeListTable);
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 80 with CodeList

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

the class CodeListSessionService method isEditedSurveyCodeListEmpty.

@Secured("ROLE_ADMIN")
public boolean isEditedSurveyCodeListEmpty(int codeListId) {
    CollectSurvey editedSurvey = sessionManager.getActiveDesignerSurvey();
    CodeList list = editedSurvey.getCodeListById(codeListId);
    boolean result = codeListManager.isEmpty(list);
    return result;
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CollectSurvey(org.openforis.collect.model.CollectSurvey) Secured(org.springframework.security.access.annotation.Secured)

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