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