use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class CodeListImportProcess method hasDifferentLabel.
protected boolean hasDifferentLabel(String code, LanguageSpecificText item, CodeListItem parentItem) {
CodeListItem existingItem = getChildItem(parentItem, code);
if (existingItem == null) {
return false;
} else {
String lang = item.getLanguage();
String label = item.getText();
String existingItemLabel = existingItem.getLabel(lang);
return !existingItemLabel.equals(label);
}
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class CodeListImportProcess 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;
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class CodeListImportProcess 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 CollectEarthBalloonGenerator method createEnumeratedEntityComponent.
private CEComponent createEnumeratedEntityComponent(EntityDefinition def) {
String label = def.getLabel(Type.INSTANCE, language);
if (label == null && !isDefaultLanguage()) {
label = def.getLabel(Type.INSTANCE);
}
if (label == null) {
label = def.getName();
}
UIOptions uiOptions = survey.getUIOptions();
String tableTooltip = def.getDescription(language);
CEEnumeratedEntityTable ceTable = new CEEnumeratedEntityTable(def.getName(), label, tableTooltip);
for (NodeDefinition child : def.getChildDefinitions()) {
if (!uiOptions.isHidden(child)) {
String heading = child.getLabel(Type.INSTANCE, language);
if (heading == null && !isDefaultLanguage()) {
heading = child.getLabel(Type.INSTANCE);
}
if (heading == null) {
heading = child.getName();
}
ceTable.addHeading(heading);
}
}
CodeAttributeDefinition enumeratingCodeAttribute = def.getEnumeratingKeyCodeAttribute();
CodeListService codeListService = def.getSurvey().getContext().getCodeListService();
List<CodeListItem> codeItems = codeListService.loadRootItems(enumeratingCodeAttribute.getList());
int codeItemIdx = 0;
for (CodeListItem item : codeItems) {
String key = item.getCode();
String itemLabel = CEComponentHTMLFormatter.getItemLabel(item, language);
String tooltip = CEComponentHTMLFormatter.getDescription(item, language);
CETableRow row = new CETableRow(key, itemLabel, tooltip);
for (NodeDefinition child : def.getChildDefinitions()) {
if (!uiOptions.isHidden(child)) {
row.addChild(createComponent(child, codeItemIdx + 1));
}
}
ceTable.addRow(row);
codeItemIdx++;
}
return ceTable;
}
use of org.openforis.idm.metamodel.CodeListItem in project collect by openforis.
the class VersioningVM method getReferencesInCodeLists.
protected List<VersionableSurveyObject> getReferencesInCodeLists(ModelVersion version) {
List<VersionableSurveyObject> references = new ArrayList<VersionableSurveyObject>();
List<CodeList> codeLists = survey.getCodeLists();
for (CodeList codeList : codeLists) {
if (isVersionInUse(version, codeList)) {
references.add(codeList);
}
if (!codeList.isExternal()) {
List<CodeListItem> items = codeList.getItems();
Stack<CodeListItem> itemsStack = new Stack<CodeListItem>();
itemsStack.addAll(items);
while (!itemsStack.isEmpty()) {
CodeListItem item = itemsStack.pop();
if (isVersionInUse(version, item)) {
references.add(item);
}
itemsStack.addAll(item.getChildItems());
}
}
}
return references;
}
Aggregations