Grails

Groovy HTTP builder for sending multipart file.

I had two applications that communicate with each other through web-services. There I had a requirement to send multi-part file from one application to another. After searching I came out with the following solution and thought to share: [java] import org.apache.http.entity.mime.MultipartEntity import...

by Divya Setia
Tag: Groovy
31-Aug-2012

Grails

Evaluating Expressions with groovy.util.Eval

A few days ago I faced a problem of evaluating dynamic expressions on domain objects. The scenario was that, depending upon the user input, I needed to sort a list of objects on some properties, which were nested deep in the object, e.g., [java] student.course?.college?.name // if a user chose to sort students by college name ...

by Imran Mir
Tag: Groovy
27-Aug-2012

Grails

What is Delegate ??

Suppose a scenario, where User and Account classes are linked as below: [groovy] class Account { String email String password // ... other fields } class User { Account account String name String address // ... other fields } [/groovy] At the time of creating a new User, and accessing the user...

by Amit Kumar
Tag: Groovy
25-Aug-2012

Grails

Facebook ‘Like’ a wall post using Graph API

Hi, In one of my Grails project, i needed to 'Like' any Facebook wall post using facebook API. I searched about it and found a way to achieve this using Facebook Graph API and thought it worth sharing. To achieve it, we should have a valid facebook access_token, which can be obtained using steps described here. After obtaining a...

by Vishal Sahu
Tag: Groovy
28-Jun-2012

Grails

Posting photos to Facebook album using Graph API

Hi, In my recent grails project, i needed to post images to the albums for Facebook Profile/ Fan page/ Group using facebook API. I searched a lot and find a way to achieve this using Facebook Graph API. To post any content over facebook, we need to have facebook access_token which can be obtained using steps described here After...

by Vishal Sahu
Tag: Groovy
28-Jun-2012

Grails

Dealing with immutable collections in Java

Perhaps, you know it before or just skipped it after going through Java API. But I really found it very helpful at this point.   Recently, I had a requirement in an open-source project, where users can iterate through the objects saved in collections (esp. List). But the problem was, we really didn’t want users to directly or...

by Salil
Tag: Groovy
11-Apr-2012

Grails

Duplicate headers received from server issue on chrome

Hi,   Recently, in my project while downloading some files(not on all files) i am getting exception on chrome, that say :   Duplicate headers received from server Error 349 (net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION): Multiple Content-Disposition headers received. This is disallowed to protect against HTTP...

by Tarun Pareek
Tag: Groovy
11-Apr-2012

Grails

Writing sentences with Groovy 2.0

Groovy 2.0 comes with some amazing new features, which prompted a numbering scheme jump from 1.9.x to 2.0. One of the key features that I took note while going through  Guillaume Laforge's presentation at 33rd Degree was the support for plain language sentences made possible by optional parentheses,  and dots. We love the language...

by Vivek Krishna
Tag: Groovy
22-Mar-2012

Grails

Grails:Domain Design Via Intellij Idea’s Diagrams

Here is an example of how to design Grails domain class with Intellij Idea.For this we need to have blank domain classes. So lets say we created  three Domain Classes Company,Book,Author To see relationship diagram, Selected Domain Class, and selected tab Domain Class Dependencies.It should look like this Lets assume the...

by Hitesh Bhatia
Tag: Groovy
23-Nov-2011

AWS

Groovy : Find Index of Element in Map

Groovier way of finding index of element from Map. It can be obtained with findIndexOf Method, which accepts closure as argument. [groovy] Map map=["groovy":1,"grails":2,"index":3,"element":4] assert 3 == map.findIndexOf{it.key=="element"} assert 0...

by Hitesh Bhatia
Tag: Groovy
10-Nov-2011

Grails

Closure as an implementation to interface

Recently, I saw some code of grails Hibernate Plugin and noticed an interesting usage of 'as' operator. The 'as' operator of groovy is typically used to change the types of objects. For example: [groovy] int a = "20" as int assert a==20 [/groovy] The 'as' operator can be used to provide implementation to interface as...

by Mohd Farid
Tag: Groovy
04-Oct-2011

Grails

Grails: Dynamically create instance of a POGO class

Hi guys, Recently on a project, I was creating a number of command objects to accept incoming parameters from a POST call from an iPhone with which I needed to sync data. I created a parent class for all command object classes to accept the common properties and created individual command object classes to accept any additional...

by Roni C Thomas
Tag: Groovy
15-Jun-2011