use of org.openforis.idm.metamodel.CodeListService in project collect by openforis.
the class SurveyViewGenerator method createCodeListItemView.
private CodeListItemView createCodeListItemView(CodeListItem item) {
CodeListService service = item.getSurvey().getContext().getCodeListService();
CodeListItemView itemView = new CodeListItemView();
itemView.id = item.getId();
itemView.code = item.getCode();
itemView.label = item.getLabel(languageCode);
itemView.color = item.getColor();
List<CodeListItemView> childItemsView = new ArrayList<CodeListItemView>();
List<CodeListItem> childItems = service.loadChildItems(item);
for (CodeListItem childItem : childItems) {
childItemsView.add(createCodeListItemView(childItem));
}
itemView.items.addAll(childItemsView);
return itemView;
}
use of org.openforis.idm.metamodel.CodeListService in project collect by openforis.
the class CSVValueFormatter method format.
public String format(AttributeDefinition defn, Value value) {
if (value == null) {
return "";
} else if (value instanceof BooleanValue) {
return ((BooleanValue) value).getValue().toString();
} else if (value instanceof Code) {
CodeListService codeListService = defn.getSurvey().getContext().getCodeListService();
CodeList list = ((CodeAttributeDefinition) defn).getList();
if (codeListService.hasQualifiableItems(list)) {
return String.format("%s: %s", ((Code) value).getCode(), ((Code) value).getQualifier());
} else {
return ((Code) value).getCode();
}
} else if (value instanceof Coordinate) {
return value.toString();
} else if (value instanceof Date) {
Date date = (Date) value;
return String.format("%d/%d/%d", ((Date) value).getDay(), ((Date) value).getMonth(), date.getYear());
} else if (value instanceof File) {
return ((File) value).getFilename();
} else if (value instanceof NumberValue) {
Number val = ((NumberValue<?>) value).getValue();
NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
String formattedVal = numberFormat.format(val);
return formattedVal;
} else if (value instanceof NumericRange) {
Number from = ((NumericRange<?>) value).getFrom();
Number to = ((NumericRange<?>) value).getFrom();
String format;
if (value instanceof IntegerRange) {
format = "%d-%d";
} else {
format = "%f-%f";
}
String formattedValue = String.format(Locale.ENGLISH, format, from, to);
return formattedValue;
} else if (value instanceof TextValue) {
return ((TextValue) value).getValue();
} else if (value instanceof Time) {
Time time = (Time) value;
return String.format("%d:%d", time.getHour(), time.getMinute());
} else
throw new IllegalArgumentException("Unsupported attribute value type: " + value.getClass().getName());
}
use of org.openforis.idm.metamodel.CodeListService in project collect by openforis.
the class CodeColumnProvider method getCodeListService.
private CodeListService getCodeListService() {
SurveyContext context = attributeDefinition.getSurvey().getContext();
CodeListService codeListService = context.getCodeListService();
return codeListService;
}
use of org.openforis.idm.metamodel.CodeListService in project collect by openforis.
the class EnumerableEntityColumnProvider method createProviders.
private static List<ColumnProvider> createProviders(CSVDataExportParameters config, EntityDefinition defn) {
List<ColumnProvider> providers = new ArrayList<ColumnProvider>();
List<AttributeDefinition> keyDefs = defn.getKeyAttributeDefinitions();
CodeAttributeDefinition keyDef = (CodeAttributeDefinition) keyDefs.get(0);
CodeList codeList = keyDef.getList();
SurveyContext context = defn.getSurvey().getContext();
CodeListService codeListService = context.getCodeListService();
List<CodeListItem> items = codeListService.loadRootItems(codeList);
for (CodeListItem item : items) {
String code = item.getCode();
String keyName = keyDef.getName();
EnumeratedCodeItemColumnProvider p = new EnumeratedCodeItemColumnProvider(config, defn, keyName, code);
providers.add(p);
}
return providers;
}
use of org.openforis.idm.metamodel.CodeListService in project collect by openforis.
the class CodeAttributeProxy method getCodeListItem.
@ExternalizedProperty
public CodeListItemProxy getCodeListItem() {
if (isEnumerator()) {
CodeListService codeListManager = getCodeListService();
CodeListItem codeListItem = codeListManager.loadItem(codeAttribute);
return codeListItem == null ? null : new CodeListItemProxy(codeListItem);
} else {
return null;
}
}
Aggregations