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));
}
}
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();
}
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"));
}
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);
}
}
Aggregations