Skip to content

Commit

Permalink
it's ok if the field name doesn't exist as long a formatter with the …
Browse files Browse the repository at this point in the history
…name exists.
  • Loading branch information
Larry Gouger committed Apr 25, 2016
1 parent 83cda10 commit 508e8f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract class AbstractExporter implements Exporter {
}

protected Object getValue(Object domain, String field){
return formatValue(domain, ExporterUtil.getNestedValue(domain, field), field)
return formatValue(domain, ExporterUtil.getNestedValue(domain, field, formatters?.containsKey(field)), field)
}

protected Writer getOutputStreamWriter(OutputStream outputStream) {
Expand Down
11 changes: 8 additions & 3 deletions src/groovy/de/andreasschmitt/export/exporter/ExporterUtil.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ExporterUtil {
throw new AssertionError()
}

public static Object getNestedValue(Object domain, String field){
public static Object getNestedValue(Object domain, String field, boolean hasFormatter){
try {
// Doesn't work for dynamic properties such as tags used in taggable
return PropertyUtils.getProperty(domain, field)
Expand All @@ -35,25 +35,30 @@ class ExporterUtil {

int i = 0
def lastProp
def lastE
for(prop in subProps){
if(i == 0){
try {
lastProp = domain?."$prop"
}
catch(Exception e){
log.info("Couldn't retrieve property ${prop}", e)
lastE = e
}
}
else {
try {
lastProp = lastProp?."$prop"
}
catch(Exception e){
log.info("Couldn't retrieve property ${prop}", e)
lastE = e
}
}
i += 1
}

if (lastE && !hasFormatter) {
log.info("Couldn't retrieve property ${field}", lastE)
}

return lastProp
}
Expand Down

0 comments on commit 508e8f5

Please sign in to comment.