Jump to content
We've recently updated our Privacy Statement, available here ×

Groovy limitations


novakv

Recommended Posts

We have recently decided to use Groovy in our reports. Scripting in reports is very exciting feature, that can definitely solve many  customization needs of users. 

Anyway, we found out very soon, that there are some limitations (as there always are some:) 

- Groovy version 1.5.5

- No closures alowed

- Only expressions alowed

We started with simple task of building full name from $F{FIRST_NAME}, $F{MIDDLE_NAME} and $F{LAST_NAME}, where any of these can have null value. The only way to solve this is to use consecutive elvis operators ?:. This is possible for names with two parts, but who has the courage to do this with 3, 4 or more parts? Or if the number is unknown?

Look at the code snippets we found out.

Maybe there is another simple solution, we didn't find - if anyone knows, please help. Also if anyone found old documentation on Groovy 1.5, this one is hard to find.

Anyway, is there any chance to ease groovy support? Most useful would be upgrading groovy compiler and allowing closures. 

Thanks for help.

 

Code:
// Using elvis operator($F{FIRST_NAME} == null ? "" : $F{FIRST_NAME}) + ($F{MIDDLE_NAME} == null ? "" : " " + $F{MIDDLE_NAME}) + ($F{LAST_NAME} == null ? "" : " " + $F{LAST_NAME})// Going beyond simple expressiondef names = [$F{FIRST_NAME}, $F{MIDDLE_NAME}, $F{LAST_NAME}];while (names.contains(null)) {  names.remove(null);}return names.join(' ');// groovy 1.5 using closure([$F{FIRST_NAME}, $F{MIDDLE_NAME}, $F{LAST_NAME}].findAll{it != null}.join(' ')// groovy 1.7([$F{FIRST_NAME}, $F{MIDDLE_NAME}, $F{LAST_NAME}] - null).join(' ')
Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...