use of org.openforis.idm.model.Field in project collect by openforis.
the class RecordConverter method convertToLatestUnitStorage.
/**
* This is a workaround: it avoids to refer to the old unit field to get data
*
* TODO remove this conversion or apply only for records stored using version prior to 3.0 Alpha 5
*
* @param survey
* @param rootEntity
*/
protected void convertToLatestUnitStorage(CollectRecord record) {
final CollectSurvey survey = (CollectSurvey) record.getSurvey();
Entity rootEntity = record.getRootEntity();
rootEntity.traverse(new NodeVisitor() {
@Override
public void visit(Node<? extends NodeDefinition> node, int idx) {
if (node instanceof NumberAttribute<?, ?> || node instanceof NumericRangeAttribute<?, ?>) {
Field<String> unitNameField;
Field<Integer> unitField;
if (node instanceof NumberAttribute<?, ?>) {
unitNameField = ((NumberAttribute<?, ?>) node).getUnitNameField();
unitField = ((NumberAttribute<?, ?>) node).getUnitField();
} else {
unitNameField = ((NumericRangeAttribute<?, ?>) node).getUnitNameField();
unitField = ((NumericRangeAttribute<?, ?>) node).getUnitField();
}
if (unitNameField.hasData()) {
moveDataToNewUnitField(survey, unitNameField, unitField);
}
}
}
});
}
use of org.openforis.idm.model.Field in project collect by openforis.
the class JSONValueFormatter method formatValue.
@SuppressWarnings("unchecked")
public String formatValue(Attribute<?, ?> attr) {
if (attr.isEmpty()) {
return null;
}
JSONObject jsonObj = new JSONObject();
List<Field<?>> fields = attr.getFields();
for (Field<?> field : fields) {
jsonObj.put(field.getName(), field.getValue());
}
return jsonObj.toJSONString();
}
Aggregations