use of org.openforis.idm.metamodel.CodeListItem 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);
}
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class DataService method findAssignableCodeListItems.
/**
* Finds a list of code list items assignable to the specified attribute and matching the passed codes
*
* @param parentEntityId
* @param attributeName
* @param codes
* @return
*/
@Secured(USER)
public List<CodeListItemProxy> findAssignableCodeListItems(int parentEntityId, String attributeName, String[] codes) {
CollectRecord record = getActiveRecord();
Entity parent = (Entity) record.getNodeByInternalId(parentEntityId);
CodeAttributeDefinition def = (CodeAttributeDefinition) parent.getDefinition().getChildDefinition(attributeName);
List<CodeListItem> items = codeListManager.findValidItems(parent, def, codes);
List<CodeListItemProxy> result = new ArrayList<CodeListItemProxy>();
for (CodeListItem item : items) {
result.add(new CodeListItemProxy(item));
}
return result;
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class CodeListController method loadAvailableItems.
@RequestMapping(value = "survey/{surveyId}/codelist/{codeListId}", method = GET)
@ResponseBody
public List<CodeListItemView> loadAvailableItems(@PathVariable Integer surveyId, @PathVariable Integer codeListId, @RequestParam Integer recordId, @RequestParam Integer parentEntityId, @RequestParam Integer codeAttrDefId) {
CollectSurvey survey = surveyManager.getOrLoadSurveyById(surveyId);
CollectRecord record = recordManager.load(survey, recordId, false);
Entity parentEntity = (Entity) record.getNodeByInternalId(parentEntityId);
CodeAttributeDefinition codeAttrDef = (CodeAttributeDefinition) survey.getSchema().getDefinitionById(codeAttrDefId);
List<CodeListItem> items = codeListManager.loadValidItems(parentEntity, codeAttrDef);
return toViews(items);
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class CodeListImportTask method getCodeListItemInDescendants.
protected CodeListItem getCodeListItemInDescendants(String code) {
Deque<CodeListItem> stack = new LinkedList<CodeListItem>();
stack.addAll(codeToRootItem.values());
while (!stack.isEmpty()) {
CodeListItem item = stack.pop();
if (item.matchCode(code)) {
return item;
} else {
stack.addAll(item.getChildItems());
}
}
return null;
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class CodeListImportTask method isDuplicate.
/**
* Returns when:
* not is leaf but has different label than existing node with same code
* or is leaf and:
* - LOCAL scope and exist item with same code at the same level
* - SCHEME scope and exist item with same code in some level
* @param code
* @param parentItem
* @param lastLevel
* @return
*/
protected boolean isDuplicate(String code, CodeListItem parentItem) {
CodeListItem duplicateItem;
duplicateItem = getChildItem(parentItem, code);
return duplicateItem != null;
}
Aggregations