use of org.openforis.idm.metamodel.CodeListService in project collect by openforis.
the class CollectEarthBalloonGenerator method getCodeListItemsByParentId.
private Map<Integer, List<CodeListItem>> getCodeListItemsByParentId(CodeList list, Integer listLevelIndex) {
CodeListService codeListService = list.getSurvey().getContext().getCodeListService();
Map<Integer, List<CodeListItem>> codeItemsByParentCodeItemId = new HashMap<Integer, List<CodeListItem>>();
if (listLevelIndex == null || listLevelIndex == 0) {
List<CodeListItem> rootCodeItems = codeListService.loadRootItems(list);
// root items
codeItemsByParentCodeItemId.put(0, rootCodeItems);
} else {
int listLevelPosition = listLevelIndex + 1;
List<CodeListItem> parentLevelItems;
if (listLevelPosition == 2) {
parentLevelItems = codeListService.loadRootItems(list);
} else {
parentLevelItems = codeListService.loadItems(list, listLevelPosition - 1);
}
for (CodeListItem parentItem : parentLevelItems) {
List<CodeListItem> childItems = codeListService.loadChildItems(parentItem);
if (!childItems.isEmpty()) {
codeItemsByParentCodeItemId.put(parentItem.getId(), childItems);
}
}
}
return codeItemsByParentCodeItemId;
}
use of org.openforis.idm.metamodel.CodeListService in project collect by openforis.
the class CollectEarthGridTemplateGenerator method getFirstAvailableCodeItem.
private CodeListItem getFirstAvailableCodeItem(AttributeDefinition attrDef) {
CodeAttributeDefinition codeDefn = (CodeAttributeDefinition) attrDef;
CodeList list = codeDefn.getList();
CodeListService codeListService = attrDef.getSurvey().getContext().getCodeListService();
Integer levelIndex = codeDefn.getListLevelIndex();
int levelPosition = levelIndex == null ? 1 : levelIndex + 1;
List<CodeListItem> items;
if (levelPosition == 1) {
items = codeListService.loadRootItems(list);
} else {
items = codeListService.loadItems(list, levelPosition);
}
if (items.isEmpty()) {
return null;
} else {
return items.get(0);
}
}
use of org.openforis.idm.metamodel.CodeListService in project collect by openforis.
the class CodeColumnProvider method init.
@Override
protected void init() {
if (getConfig().isCodeAttributeExpanded()) {
CodeList list = attributeDefinition.getList();
CollectSurvey survey = (CollectSurvey) list.getSurvey();
if (survey.isPredefinedCodeList(list)) {
hasExpandedItems = false;
expandedItems = null;
} else {
int levelPosition = attributeDefinition.getLevelPosition();
CodeListService codeListService = getCodeListService();
List<CodeListItem> items = codeListService.loadItems(list, levelPosition);
hasExpandedItems = items.size() <= getConfig().getMaxExpandedCodeAttributeItems();
expandedItems = hasExpandedItems ? items : null;
}
}
super.init();
}
use of org.openforis.idm.metamodel.CodeListService in project collect by openforis.
the class CodeColumnProvider method extractValue.
@Override
protected String extractValue(Attribute<?, ?> attr, String fieldName) {
if (ITEM_POSITION_FIELD_NAME.equals(fieldName) || ITEM_LABEL_FIELD_NAME.equals(fieldName)) {
CodeListService codeListService = getCodeListService();
CodeListItem item = codeListService.loadItem((CodeAttribute) attr);
if (item == null) {
return "";
} else if (ITEM_POSITION_FIELD_NAME.equals(fieldName)) {
List<CodeListItem> items = codeListService.loadItems(attributeDefinition.getList(), attributeDefinition.getLevelPosition());
int position = items.indexOf(item) + 1;
return Integer.toString(position);
} else {
return item.getLabel(getConfig().getLanguageCode());
}
} else {
return super.extractValue(attr, fieldName);
}
}
use of org.openforis.idm.metamodel.CodeListService in project collect by openforis.
the class RecordUpdater method addEmptyEnumeratedEntities.
private void addEmptyEnumeratedEntities(Entity parentEntity, EntityDefinition enumerableEntityDefn) {
Record record = parentEntity.getRecord();
ModelVersion version = record.getVersion();
CodeAttributeDefinition enumeratingCodeDefn = enumerableEntityDefn.getEnumeratingKeyCodeAttribute(version);
if (enumeratingCodeDefn != null) {
CodeList list = enumeratingCodeDefn.getList();
Survey survey = record.getSurvey();
CodeListService codeListService = survey.getContext().getCodeListService();
List<CodeListItem> items = codeListService.loadRootItems(list);
int i = 0;
for (CodeListItem item : items) {
if (version == null || version.isApplicable(item)) {
String code = item.getCode();
Entity enumeratedEntity = parentEntity.getEnumeratedEntity(enumerableEntityDefn, enumeratingCodeDefn, code);
if (enumeratedEntity == null) {
Entity addedEntity = performEntityAdd(parentEntity, enumerableEntityDefn, i);
addEmptyNodes(addedEntity);
// set the value of the key CodeAttribute
CodeAttribute addedCode = (CodeAttribute) addedEntity.getChild(enumeratingCodeDefn, 0);
addedCode.setValue(new Code(code));
addedCode.updateSummaryInfo();
} else if (enumeratedEntity.getIndex() != i) {
parentEntity.move(enumerableEntityDefn, enumeratedEntity.getIndex(), i);
}
i++;
}
}
}
}
Aggregations