Search in sources :

Example 6 with CodeList

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

the class CodeListImportProcessIntegrationTest method testMultiLangImport.

@Test
public void testMultiLangImport() throws Exception {
    survey.addLanguage("es");
    CodeList codeList = survey.createCodeList();
    codeList.setName(TEST_CODE_LIST_NAME);
    survey.addCodeList(codeList);
    CodeListImportProcess process = importCSVFile(VALID_MULTILANG_TEST_CSV, codeList);
    CodeListImportStatus status = process.getStatus();
    assertTrue(status.isComplete());
    assertTrue(status.getSkippedRows().isEmpty());
    assertEquals(5, status.getProcessed());
    List<CodeListItem> items = codeListManager.loadRootItems(codeList);
    assertEquals(2, items.size());
    {
        CodeListItem item = codeListManager.loadRootItem(codeList, "001", null);
        assertNotNull(item);
        assertEquals("Dodoma", item.getLabel(LANG));
        assertEquals("Dodoma ES", item.getLabel("es"));
        List<CodeListItem> childItems = codeListManager.loadChildItems(item);
        assertEquals(2, childItems.size());
        CodeListItem childItem = childItems.get(0);
        assertEquals("001", childItem.getCode());
        assertEquals("Kondoa", childItem.getLabel(LANG));
        childItem = childItems.get(1);
        assertEquals("002", childItem.getCode());
        assertEquals("Mpwapwa", childItem.getLabel(LANG));
        assertEquals("Mpwapwa ES", childItem.getLabel("es"));
    }
    {
        CodeListItem item = codeListManager.loadRootItem(codeList, "002", null);
        assertNotNull(item);
        assertEquals("Arusha", item.getLabel(LANG));
        List<CodeListItem> childItems = codeListManager.loadChildItems(item);
        assertEquals(2, childItems.size());
        CodeListItem childItem = childItems.get(0);
        assertEquals("001", childItem.getCode());
        assertEquals("Monduli", childItem.getLabel(LANG));
        assertNull(childItem.getLabel("es"));
        childItem = childItems.get(1);
        assertEquals("002", childItem.getCode());
        assertEquals("Arumeru", childItem.getLabel(LANG));
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeListImportStatus(org.openforis.collect.manager.codelistimport.CodeListImportStatus) CodeList(org.openforis.idm.metamodel.CodeList) List(java.util.List) CodeListItem(org.openforis.idm.metamodel.CodeListItem) CodeListImportProcess(org.openforis.collect.manager.codelistimport.CodeListImportProcess) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 7 with CodeList

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

the class RelationalSchemaGenerator method addCodeValueFKColumn.

private void addCodeValueFKColumn(RelationalSchema rs, DataTable table, CodeAttributeDefinition attrDefn, Path relativePath) throws CollectRdbException {
    CodeList list = attrDefn.getList();
    Integer levelIdx = attrDefn.getListLevelIndex();
    String codeListTableName = CodeListTables.getTableName(config, list, levelIdx);
    DataColumn codeValueColumn = table.getDataColumn(attrDefn.getFieldDefinition(CodeAttributeDefinition.CODE_FIELD));
    String codeValueColumnName = codeValueColumn.getName();
    String fkColumnName = DataTables.getCodeFKColumnName(config, table, attrDefn);
    CodeValueFKColumn col = new CodeValueFKColumn(fkColumnName, attrDefn, relativePath, config.getDefaultCode());
    addColumn(table, col);
    // Create FK constraint
    CodeTable codeListTable = rs.getCodeListTable(list, levelIdx);
    if (codeListTable != null) {
        String fkConstraintName = config.getFkConstraintPrefix() + codeValueColumnName + "_" + codeListTableName;
        PrimaryKeyConstraint codeListPkConstraint = codeListTable.getPrimaryKeyConstraint();
        ReferentialConstraint fkConstraint = new ReferentialConstraint(fkConstraintName, table, codeListPkConstraint, col);
        table.addConstraint(fkConstraint);
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList)

Example 8 with CodeList

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

the class CodeValueFKColumnValueExtractor method extractValue.

private Object extractValue(CodeAttribute valNode) {
    CodeListItem item = findCodeListItem(valNode);
    if (item == null) {
        String defaultCodeValue = column.getDefaultCodeValue();
        String codeValue = getCodeValue(valNode);
        if (defaultCodeValue == null || (codeValue != null && !codeValue.equals(defaultCodeValue))) {
            // no default code value specified or code list item not found (invalid code?)
            return null;
        } else {
            CodeAttributeDefinition definition = valNode.getDefinition();
            CodeList list = definition.getList();
            Record record = valNode.getRecord();
            ModelVersion version = record.getVersion();
            return getDefaultCodeItemId(list, version);
        }
    } else {
        return item.getId();
    }
}
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) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 9 with CodeList

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

the class CodeListImportService method start.

@Secured("ROLE_ADMIN")
public CodeListImportStatusProxy start(int codeListId, String tempFileName, CSVFileOptions fileOptions, boolean overwriteData) throws DataImportExeption {
    if (importProcess == null || !importProcess.getStatus().isRunning()) {
        File importFile = new File(tempFileName);
        SessionStatus designerSessionStatus = sessionManager.getDesignerSessionStatus();
        CollectSurvey survey = designerSessionStatus.getSurvey();
        String langCode = designerSessionStatus.getCurrentLanguageCode();
        CodeList codeList = survey.getCodeListById(codeListId);
        importProcess = new CodeListImportProcess(codeListManager, codeList, langCode, importFile, fileOptions, overwriteData);
        importProcess.init();
        CodeListImportStatus status = importProcess.getStatus();
        if (status != null && !importProcess.getStatus().isError()) {
            startProcessThread();
        }
    }
    return getStatus();
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) SessionStatus(org.openforis.collect.designer.session.SessionStatus) CodeListImportStatus(org.openforis.collect.manager.codelistimport.CodeListImportStatus) CollectSurvey(org.openforis.collect.model.CollectSurvey) File(java.io.File) CodeListImportProcess(org.openforis.collect.manager.codelistimport.CodeListImportProcess) Secured(org.springframework.security.access.annotation.Secured)

Example 10 with CodeList

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

the class CodeListItemPR method onEndTag.

@Override
protected void onEndTag() throws XmlParseException {
    if (parentItem == null) {
        CodeList list = getCodeList();
        list.addItem(item);
    } else {
        parentItem.addChildItem(item);
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList)

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