Grails

Groovy: Few ways to convert string into enum

Many at times, we have a string which needs to be converted into Enum. I will be sharing few options as stated by Mr.Haki, Isa Goksu and in the last the one I discovered during the process. Lets say we have a Enum AccountType as given below : [groovy] enum AccountType { CHECKING, SAVING } assert AccountType.CHECKING...

by Amit Jain
Tag: Groovy
15-Apr-2011

Grails

Handling Instance Based Security

In my current project, we were required to implement Instance Based Security. The idea was to find a clean solution separate from the main business logic of the application. We took a clue from the Spring Security Plugin to use the Annotations to do our job. All we wanted to do was to develop annotations for actions, which could help to...

by Imran Mir
Tag: Groovy
06-Apr-2011

Grails

Using Groovy execute bash scripts

Hi Friends, Recently I had to execute bash script using groovy on a windows server. Though I could easily make the similar script run on linux, but on windows it just didn't work as it was unable to recognize the internal DOS commands like cp, rm etc. On linux the following code worked but not on windows: [bash] File script =...

by Amit Jain
Tag: Groovy
15-Feb-2011

Grails

Groovy: Sort list of objects on the basis of more than one field

Usually, when we deal with databases, we don't face such kind of situation because we query database to get result-set in required order. But let's say you have a List of objects that you want to sort on the basis of two fields. Let's discuss it with an example. I have a list of Tasks (with date and priority fields). I want to sort...

by Salil
Tag: Groovy
25-Jan-2011

Grails

How to use Thread-Pooling using Groovy

Grails Development is challenging and most Groovy and Grails projects require in-depth understanding of thread-pooling. As a Groovy developer, I really like the thread-pooling API (in java.util.concurrent package), especially when you are hitting x number of API dealing with outside network to fetch information for a single request. ...

by Salil
Tag: Groovy
16-Jan-2011

Grails

Curried Closures in groovy

There’s a feature that adds spice to Groovy—it’s called Curried Closures. The term curry is taken from Haskell Curry, the mathematician who developed the concept of partial functions. Currying refers to taking multiple arguments into a function that takes many arguments, resulting in a new function that takes the remaining...

by Gautam Malhotra
Tag: Groovy
15-Jan-2011

Grails

Request Mocking to use groovyPagesTemplateEngine in backend threads

We have a setup where a backend thread, fired by the Spring Events, does some processing, generates a PDF and emails the result to the user. The code we were using to generate the HTML from a GSP to be converted to a PDF using iText was as follows : [java] def webRequest = RequestContextHolder.getRequestAttributes() ...

by Vivek Krishna
Tag: Groovy
27-Dec-2010

Grails

Using Groovy MOP and Closure to prevent expression evaluation in logger.debug()

Generally in our code, we have lots of debug statements that prints the intricate details of the state of the program. Infact, the debug statements are meant for doing this. Sometimes, these debug statements may contain a call to some other method to evaluate what is to be logged. [java] //Logging statement calling some function to...

by Mohd Farid
Tag: Groovy
13-Dec-2010

Grails

Encode Content to MD5 Using GROOVY or GRAILS – with Webhook example

Recently I was working on webhooks (which are getting quite popular for sending notifications to other applications using HTTP POST methods). MD5 encoded content is heavily used in webhooks for security concern. My purpose of writing this blog is neither to explain MD5 nor webhooks. But just to show you - 1. a quicker way in...

by Salil
Tag: Groovy
12-Nov-2010

Grails

Grails way for rendering the GSP templates: The tmpl namespace.

Today while working on a project, I paired up with my colleague (Uday)  and we found that we can render a gsp template in a different manner also. Grails provide us a "tmpl" namespace for rendering the GSP templates. The old way that we use to render a gsp template The other way for  rendering the template. Like me,...

by Chandan Luthra
Tag: Groovy
01-Oct-2010

Grails

Handling Password Protected Pdf with PdfReader

In one of our grails project , we had to attach cover to Pdf file . But since some of pdf's uploaded were password protected. To handle this scenario we added bouncyCastle.jar , so our version of iText was able to handle password protected pdf . And Then to check whether pdf is password protected or not , we used "Boolean...

by Hitesh Bhatia
Tag: Groovy
19-Aug-2010