Skip to content

Commit 6b73ce6

Browse files
authored
OBPIH-6275 Export boolean values as true/false booleans, instead of a… (#4881)
1 parent cefb141 commit 6b73ce6

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

grails-app/services/org/pih/warehouse/core/DocumentService.groovy

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,11 @@ class DocumentService {
404404
void createExcelRow(HSSFSheet sheet, int rowNumber, Map dataRow) {
405405
Row excelRow = sheet.createRow(rowNumber)
406406
dataRow.keySet().eachWithIndex { columnName, index ->
407-
def cellValue = dataRow.get(columnName) ?: ""
408-
// POI can't handle objects so we need to convert all objects to strings unless they are numeric
409-
if (!(cellValue instanceof Number)) {
407+
def actualValue = dataRow.get(columnName)
408+
// We can't just check the truthiness of the actualValue, because the false boolean would be evaluated to an empty string
409+
def cellValue = actualValue == null ? "" : actualValue
410+
// POI can't handle objects so we need to convert all objects to strings unless they are numeric or boolean
411+
if (!(cellValue instanceof Number) && !(cellValue instanceof Boolean)) {
410412
cellValue = cellValue.toString()
411413
}
412414
excelRow.createCell(index).setCellValue(cellValue)

grails-app/services/org/pih/warehouse/data/DataService.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,12 +702,14 @@ class DataService {
702702
} else if (element.defaultValue && !value) {
703703
value = element.defaultValue
704704
}
705-
properties[fieldName] = value ?: ""
705+
// We can't just check the truthiness of the value, because the false boolean would be evaluated to an empty string
706+
properties[fieldName] = value == null ? "" : value
706707
} else {
707708
// to access object value by key we must use the object.get(key) instead of object[key]
708709
// because using the object[key] will throw an error when trying to export data using the batch controller
709710
value = object.get(element) ?: element.tokenize('.').inject(object) { v, k -> v?."$k" }
710-
properties[fieldName] = value ?: ""
711+
// We can't just check the truthiness of the value, because the false boolean would be evaluated to an empty string
712+
properties[fieldName] = value == null ? "" : value
711713
}
712714
}
713715
return properties

0 commit comments

Comments
 (0)