use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListManager method loadItemByAttribute.
@SuppressWarnings("unchecked")
public <T extends CodeListItem> T loadItemByAttribute(CodeAttribute attribute) {
CodeAttributeDefinition defn = attribute.getDefinition();
CodeList list = defn.getList();
boolean persistedSurvey = list.getSurvey().getId() != null;
if (persistedSurvey && list.isExternal()) {
return (T) provider.getItem(attribute);
} else if (persistedSurvey && list.isEmpty()) {
return (T) loadPersistedItem(attribute);
} else {
return (T) getInternalCodeListItem(attribute);
}
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListImagesImportTask method execute.
@Override
protected void execute() throws Throwable {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
String entryName = entry.getName();
if (CodeListImageEntry.isValidEntry(entryName)) {
CodeListImageEntry codeListImageEntry = CodeListImageEntry.parseEntryName(entryName);
CodeList codeList = survey.getCodeListById(codeListImageEntry.getListId());
if (codeList != null) {
CodeListItem item = codeListManager.loadItem(codeList, codeListImageEntry.getItemId());
if (item != null && item instanceof PersistedCodeListItem) {
byte[] content = IOUtils.toByteArray(zipFile.getInputStream(entry));
codeListManager.saveImageContent((PersistedCodeListItem) item, new FileWrapper(content, codeListImageEntry.getFileName()));
} else {
log().warn("Error restoring code list image file : " + entry.getName());
}
}
}
}
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListItemPR method createItem.
protected void createItem(int id, int level) {
CodeList list = getCodeList();
this.item = list.createItem(id, level);
}
use of org.openforis.idm.metamodel.CodeList 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.idm.metamodel.CodeList 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