Search in sources :

Example 1 with CodeListImportStatus

use of org.openforis.collect.manager.codelistimport.CodeListImportStatus 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 2 with CodeListImportStatus

use of org.openforis.collect.manager.codelistimport.CodeListImportStatus 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 3 with CodeListImportStatus

use of org.openforis.collect.manager.codelistimport.CodeListImportStatus in project collect by openforis.

the class CodeListImportProcessIntegrationTest method testDuplicateValues.

@Test
public void testDuplicateValues() throws Exception {
    CodeList codeList = survey.createCodeList();
    codeList.setName(TEST_CODE_LIST_NAME);
    survey.addCodeList(codeList);
    CodeListImportProcess process = importCSVFile(INVALID_TEST_CSV, codeList);
    CodeListImportStatus status = process.getStatus();
    assertTrue(status.isError());
    List<ParsingError> errors = status.getErrors();
    // different label
    assertTrue(containsError(errors, 4, "region_label_en"));
    assertTrue(containsError(errors, 4, "district_code"));
    assertTrue(containsError(errors, 7, "district_code"));
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) CodeListImportStatus(org.openforis.collect.manager.codelistimport.CodeListImportStatus) CodeListImportProcess(org.openforis.collect.manager.codelistimport.CodeListImportProcess) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 4 with CodeListImportStatus

use of org.openforis.collect.manager.codelistimport.CodeListImportStatus in project collect by openforis.

the class CodeListImportProcessIntegrationTest method testImport.

@Test
public void testImport() throws Exception {
    CodeList codeList = survey.createCodeList();
    codeList.setName(TEST_CODE_LIST_NAME);
    survey.addCodeList(codeList);
    CodeListImportProcess process = importCSVFile(VALID_TEST_CSV, codeList);
    CodeListImportStatus status = process.getStatus();
    assertTrue(status.isComplete());
    assertTrue(status.getSkippedRows().isEmpty());
    assertEquals(6, status.getProcessed());
    List<CodeListItem> items = codeListManager.loadRootItems(codeList);
    assertEquals(3, items.size());
    {
        CodeListItem item = codeListManager.loadRootItem(codeList, "001", null);
        assertNotNull(item);
        assertEquals("Dodoma", item.getLabel(LANG));
        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));
    }
    {
        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));
        childItem = childItems.get(1);
        assertEquals("002", childItem.getCode());
        assertEquals("Arumeru", childItem.getLabel(LANG));
    }
    {
        CodeListItem item = codeListManager.loadRootItem(codeList, "003", null);
        assertNotNull(item);
    }
}
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)

Aggregations

CodeListImportProcess (org.openforis.collect.manager.codelistimport.CodeListImportProcess)4 CodeListImportStatus (org.openforis.collect.manager.codelistimport.CodeListImportStatus)4 CodeList (org.openforis.idm.metamodel.CodeList)4 Test (org.junit.Test)3 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)3 List (java.util.List)2 CodeListItem (org.openforis.idm.metamodel.CodeListItem)2 File (java.io.File)1 SessionStatus (org.openforis.collect.designer.session.SessionStatus)1 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 Secured (org.springframework.security.access.annotation.Secured)1