use of org.openforis.idm.metamodel.CodeListItem 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.CodeListItem in project collect by openforis.
the class CodeColumnProvider method generateExpandedItemsHeadings.
private List<String> generateExpandedItemsHeadings() {
List<String> headings = new ArrayList<String>();
for (CodeListItem item : expandedItems) {
String heading = ColumnProviders.generateHeadingPrefix(attributeDefinition, config) + getConfig().getFieldHeadingSeparator() + item.getCode();
headings.add(heading);
if (item.isQualifiable()) {
headings.add(heading + getConfig().getFieldHeadingSeparator() + CodeAttributeDefinition.QUALIFIER_FIELD);
}
}
return headings;
}
use of org.openforis.idm.metamodel.CodeListItem 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.CodeListItem in project collect by openforis.
the class SurveyValidator method validateEnumeratingCodeListNotChanged.
protected List<SurveyValidationResult> validateEnumeratingCodeListNotChanged(CodeList oldCodeList, CodeList codeList) {
List<SurveyValidationResult> results = new ArrayList<SurveyValidationResult>();
List<CodeListItem> oldItems = codeListManager.loadRootItems(oldCodeList);
for (CodeListItem oldItem : oldItems) {
CodeListItem newItem = codeListManager.loadRootItem(codeList, oldItem.getCode(), null);
if (newItem == null) {
String messageKey = "survey.validation.error.enumerating_code_list_changed.code_removed";
String codeListPath = String.format(CODE_LIST_PATH_FORMAT, codeList.getName());
String path = codeListPath + "/" + oldItem.getCode();
SurveyValidationResult validationError = new SurveyValidationResult(path, messageKey);
results.add(validationError);
}
}
return results;
}
use of org.openforis.idm.metamodel.CodeListItem 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