<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Intelligrape  Groovy &#38; Grails Blogs &#187; Grails</title>
	<atom:link href="http://www.intelligrape.com/blog/tag/grails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.intelligrape.com/blog</link>
	<description></description>
	<lastBuildDate>Thu, 02 Feb 2012 07:48:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
			<title>Intelligrape  Groovy &amp; Grails Blogs</title>
			<url>http://www.intelligrape.com/blog/wp-content/uploads/2011/05/favicon2.ico</url>
			<link>http://www.intelligrape.com/blog</link>
			<width></width>
			<height></height>
			<description></description>
		</image>		<item>
		<title>Alphanumeric Sorting using Criteria Query (with MySQL database)</title>
		<link>http://www.intelligrape.com/blog/2012/02/02/alphanum_sort/</link>
		<comments>http://www.intelligrape.com/blog/2012/02/02/alphanum_sort/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 07:48:06 +0000</pubDate>
		<dc:creator>Gaurav Sharma</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[GORM]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Alphanumeric Sort]]></category>
		<category><![CDATA[criteria query]]></category>
		<category><![CDATA[formula]]></category>
		<category><![CDATA[Human Sort]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[Natural Sort]]></category>
		<category><![CDATA[sorting]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=5051</guid>
		<description><![CDATA[I am working on a Grails application with MySQL database. I had a use case in which I had to implement alphanumeric sorting using Criteria Query on Grails. By alphanumeric sorting I mean if there is a class Employee with field empId then on doing :

Employee e1 = new Employee(empId:'emp10').save()
Employee e2 = new Employee(empId:'emp2').save()
Employee e3 = [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on a Grails application with MySQL database. I had a use case in which I had to implement alphanumeric sorting using Criteria Query on Grails. By alphanumeric sorting I mean if there is a class Employee with field empId then on doing :</p>
<pre class="brush: plain;">
Employee e1 = new Employee(empId:'emp10').save()
Employee e2 = new Employee(empId:'emp2').save()
Employee e3 = new Employee(empId:'emp1').save()
Employee e4 = new Employee(empId:'1emp').save()
Employee e5 = new Employee(empId:'10emp').save()
Employee e6 = new Employee(empId:'2emp').save()

Employee.createCriteria().list([sort:'empId'])
            /* OR */
Employee.createCriteria().list{
    order('empId')
}
</pre>
<p><strong>should give result like [e4,e6,e5,e3,e2,e1]</strong>. But according to sql sorting the <strong>result would be [e5,e4,e6,e3,e1,e2]</strong><br />
<br />
One thing to note was that criteria query implemented sorting at the database end.<br />
After googling around, I came <a href="http://drupal.org/project/natsort">across a script</a> that had a SQL function which converted the field value to string that can alphanumerically sorted easily at database end.</p>
<p>To migrate the functions in script to database you have to unzip the script and write following command on terminal:</p>
<pre class="brush: bash;">mysql -u username -p database_name &lt; /path/to/unzipped/directory/natsort.install.mysql</pre>
<p>Now only thing I had to do was to get a derived field from the Grails property that had to be sorted alphanumerically which was easily possible as the Grails had ability to create transient field using formula (thanks to wonderful <a href="http://www.intelligrape.com/blog/2010/12/31/create-transients-using-formula-in-grails/">Blog by Uday</a>). Thus I had to create a new transient field using SQL function in formula. So I did something like this :</p>
<pre class="brush: groovy;">
class Employee {
    String empId
    String empIdSortField           //transient field
    static mapping = {
        empIdSortField formula: 'natsort_canon(empId, &quot;natural&quot;)'
    }
}
</pre>
<p>Now if I had to get Employee objects are sorted by empId alphanumerically, what I would do is :  </p>
<pre class="brush: groovy;">
Employee.createCriteria().list {
    order('empIdSortField')
}
</pre>
<p>Hope this was helpful to you!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2012/02/02/alphanum_sort/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>My Top 9 Features from Grails 2.0</title>
		<link>http://www.intelligrape.com/blog/2012/01/18/my-top-9-features-from-grails-2-0/</link>
		<comments>http://www.intelligrape.com/blog/2012/01/18/my-top-9-features-from-grails-2-0/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 13:22:07 +0000</pubDate>
		<dc:creator>Vivek Krishna</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[GORM]]></category>
		<category><![CDATA[grails 2.0]]></category>
		<category><![CDATA[grails testing]]></category>
		<category><![CDATA[new features of grails]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=4960</guid>
		<description><![CDATA[The  groovy world is abuzz about the latest release from the Grails Stable, Grails 2.0, which packs a lot more punch than its predecessors, which by  themselves were productivity enhancers and wonderful to develop our web  applications with. The new version brings with itself a lot of changes  compared to the [...]]]></description>
			<content:encoded><![CDATA[<p>The  groovy world is abuzz about the latest release from the Grails Stable, Grails 2.0, which packs a lot more punch than its predecessors, which by  themselves were productivity enhancers and wonderful to develop our web  applications with. The new version brings with itself a lot of changes  compared to the previous releases and deserves to be truly called 2.0 instead of 1.4 or 1.5.</p>
<p>I  would like to walk you through some of the coolest features from grails 2.0 that I have discovered in the limited time I have spent with the  new version and fell in love with.</p>
<ol>
<li> <strong>The Improved Interactive Mode</strong>:  I love working on the command line and the new interactive mode is a  joy to work with. The auto-completions, combined with the quick response  times(as a result of not having to load JVM for each command) is a sure  shot productivity booster. That I can run normal commands from the  grails shell by just prefixing them with a “!” is an added advantage.</li>
<li><strong>Dynamic Domain Class Reloading</strong>:  One activity that consumed a lot of time with earlier versions of  Grails was waiting for the servlet container to restart, once we made  even a line’s change in the domain class or src/groovy file. Now, the  reloading is dynamic which means that the changes take effect very  quickly, this letting us focus on the development without the flow being  interrupted by the restart process.</li>
<li><strong>HTML5 scaffolded screens</strong>:  One of the complaints I had with earlier versions of grails was the  not-so-good looking screens that were generated by scaffolding. For most  of the admin screens, the scaffolded screens are sufficient and the new  HTML5 compatible scaffolded screens are very easy on the eye and  provide an excellent user experience. With the new screens however, I  can simply change the logo and they make for sufficiently pleasing CRUD  screens.</li>
<li><strong>Business Class Citizenship for Testing</strong>:  Testing has been a first class citizen of the framework right from day  1, but the new testing framework has made life easy for people like me,  for whom testing doesn’t come naturally. With scaffolded tests being  generated, newbies will find it easier to learn aspects of testing the  application. In addition to that, the capability to unit-test criteria  queries adds an element which was missing from earlier versions.</li>
<li><strong>Link Generation/Page Renderer APIs</strong>:  Earlier, generating html from gsp files from non-request bound threads  was a pain, especially with mocking the web request. Now, with the  PageRenderer API, generating a view in a job or a service is as simple  as injecting a groovyPageRenderer bean and calling  groovyPageRenderer.render() method just like from within a controller.</li>
<li><strong>GORM Finders with Groovy Collection find/findAll like syntax</strong>:  If there was one feature I could keep from all the enhancements in 2.0,  it would be this. This is also the feature which, I think would go a  long way in making GORM queries easier. There couldn’t be a more  expressive syntax!</li>
<li><strong>Public methods in controllers as actions which can take arguments</strong>:  Earlier, it used to be a pain to type-cast the parameters into their  respective types(when one felt that command objects are an overhead  while working with at most 2-3 params). The new method like syntax lets  us define actions as public methods in controllers, which automatically  bind data to the method arguments, based on the params. If I have a  command object as argument, it works just the way it worked earlier. We  talk about thin controllers a lot. This also means that we’ll be more  diligent while creating methods in controllers and even if we really  must, they have to be private. This just made the controllers thinner!</li>
<li><strong>The New Improved Test Reports</strong>:  The new test reports are very easy on the eye and even more easier  while finding test failures. Though we don’t recommend having println statements in our test cases, the fact that I can see the system outputs  on the same page as my test case is a winner.</li>
<li><strong>DB Console</strong>: Viewing the contents of the in-memory DB was a pain in the earlier versions. The new dbconsole, which can be accessed only in development mode is a clear winner.</li>
</ol>
<p>Grails 2.0 comes with its set of wonderful features which makes development with it, a much better experience.</p>
<p><script src="https://www.surveymonkey.com/jsEmbed.aspx?sm=G7LJIMEJCZsd6zwvkl7fJA_3d_3d"> </script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2012/01/18/my-top-9-features-from-grails-2-0/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Writing JSON APIs : Part II &#8211; Creating JSON Named Configs to Control What You Render</title>
		<link>http://www.intelligrape.com/blog/2011/12/29/writing-json-apis-part-ii-creating-json-named-configs-to-control-what-you-render/</link>
		<comments>http://www.intelligrape.com/blog/2011/12/29/writing-json-apis-part-ii-creating-json-named-configs-to-control-what-you-render/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 13:15:05 +0000</pubDate>
		<dc:creator>Vivek Krishna</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Grails Custom Marshaller]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[JSON API]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=4893</guid>
		<description><![CDATA[In the 1st part of the series, we looked at how to secure our application with Spring Security Basic Authentication and modifying the JSON Marshaller. However, it could often be the case that the same set of fields shouldn&#8217;t be returned on every JSON response.
For example, we could very well have a summary JSON for [...]]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://www.intelligrape.com/blog/2011/11/16/writing-json-apis-part-i-creating-a-secure-rest-json-api-with-grails-and-spring-security-in-3-easy-steps/" target="_blank">1st part of the series</a>, we looked at how to secure our application with Spring Security Basic Authentication and modifying the JSON Marshaller. However, it could often be the case that the same set of fields shouldn&#8217;t be returned on every JSON response.</p>
<p>For example, we could very well have a summary JSON for Book, which just returns the id and name of the Book, ignoring the other details like ISBN, genre etc. A real life example would be a Product&#8217;s complete details when returning JSON for its show view, while returning just the id, name and price for its view in a shopping cart.</p>
<p>In addition to that, we could choose, not to override the default JSON Marshallers provided by Grails so that the standard rendering method is not tampered.</p>
<p>Grails provides an excellent solution called &#8220;Named Configurations&#8221; which comes to our aid here. That, combined with some minor modifications on our CustomDomainClassJSONMarshaller can help us achieve this.</p>
<p><strong>1. Add a static Map to the domain class, probably jsonProperties</strong> :</p>
<p>This property will hold the group name as key and the list of properties to be included as values.</p>
<pre class="brush: java;">

//Book.groovy

static jsonProperties = [summary:['name']] //summary is the group name
</pre>
<p><strong>2. Update the CustomDomainClassJSONMarshaller to have a property jsonPropertyGroup</strong> :</p>
<pre class="brush: java;">
String jsonPropertyGroup
public CustomDomainClassJSONMarshaller(boolean includeVersion, GrailsApplication application, String jsonPropertyGroup = &quot;&quot;) {
      this(includeVersion, new DefaultProxyHandler(), application, jsonPropertyGroup);
}
public CustomDomainClassJSONMarshaller(boolean includeVersion, ProxyHandler proxyHandler, GrailsApplication application, String jsonPropertyGroup) {
      this.includeVersion = includeVersion;
      this.proxyHandler = proxyHandler;
      this.application = application;
      this.jsonPropertyGroup = jsonPropertyGroup
}
</pre>
<p><strong>3. Update the custom marshaller registrations to create Named Configs :</strong></p>
<p>This method needs updation for two reasons</p>
<ul>
<li>Calling the newly created constructors</li>
<li>API changes in grails 2.0</li>
</ul>
<p>For creating a named config &#8220;summary&#8221;, we need to write something like</p>
<pre class="brush: java;">

JSON.createNamedConfig(JSONConstants.SUMMARY_JSON_MARSHALLER_GROUP){
     it.registerObjectMarshaller(new CustomDomainClassJSONMarshaller(false, grailsApplication, &quot;summary&quot;), 2)
}
</pre>
<p><strong>4. Using the newly registered named configs from within the controller:</strong></p>
<p>This is the final step. We can use the named config with a static method JSON.use(), which takes in the configuration&#8217;s name and a closure inside which we will call the <em>render &lt;XYZ&gt; as JSON</em> method</p>
<pre class="brush: java;">

JSON.use(&quot;summary&quot;){
     render Book.list() as JSON
}
</pre>
<p>I have updated the <a href="https://github.com/svivekkrishna/Json-API-Sample/tree/grails20NamedConfig" target="_blank">example application</a> to grails 2.0 and added an example to this approach.</p>
<p>Grails never ceases to amaze me. <img src='http://www.intelligrape.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2011/12/29/writing-json-apis-part-ii-creating-json-named-configs-to-control-what-you-render/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dbconsole in Grails.</title>
		<link>http://www.intelligrape.com/blog/2011/12/25/dbconsole-in-grails/</link>
		<comments>http://www.intelligrape.com/blog/2011/12/25/dbconsole-in-grails/#comments</comments>
		<pubDate>Sun, 25 Dec 2011 08:56:38 +0000</pubDate>
		<dc:creator>Sachin</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[GUI console]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=4829</guid>
		<description><![CDATA[So, Grails 2.0 was released a few days back and I upgraded my application to it as soon as I came to know of its final release and it rocks.!!
Among the many things which are making a lot of noise on grails 2.0, there seems to be a lack of noise over the GUI Database [...]]]></description>
			<content:encoded><![CDATA[<p>So, Grails 2.0 was released a few days back and I upgraded my application to it as soon as I came to know of its final release and it rocks.!!</p>
<p>Among the many things which are making a lot of noise on grails 2.0, there seems to be a lack of noise over the GUI Database console which grails has provided. Developers can connect to the database from a GUI right inside there application, see the data in tables and execute simple queries. Probably its not polished yet so that could be a reason why there is not much noise over it but it still is a usable feature.</p>
<p>All you need to do is, run your grails 2.0 app navigate to<strong> http://localhost:8080/app-name/dbconsole/</strong> and configure your database connection. Just select what database you are using, Select the driver, a couple of entries for username and password and you are good to go.</p>
<p>The query builder isn&#8217;t too great, but that is no reason to miss this useful tool. No need to move to any other application or console to see whats in the database. The database is available right in your application, and its available only in development mode, so no worries of this slipping into production. Hope this saves some time for all of us.</p>
<p>Thanks.<br />
Sachin Anand<br />
mail : sachin[at]intelligrape[dot]com<br />
twitter : @sachin__anand</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2011/12/25/dbconsole-in-grails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Grails productivity enhancer. The unsung hero &#8216;grails interactive mode&#8217;</title>
		<link>http://www.intelligrape.com/blog/2011/11/30/grails-productivity-enhancer-the-unsung-hero-grails-interactive-mode/</link>
		<comments>http://www.intelligrape.com/blog/2011/11/30/grails-productivity-enhancer-the-unsung-hero-grails-interactive-mode/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 11:18:52 +0000</pubDate>
		<dc:creator>Mohd Farid</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[Unit Test]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[Tricks]]></category>
		<category><![CDATA[unit-test]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=4501</guid>
		<description><![CDATA[Of late, I have been thinking about the popularity of grails interactive mode amongst developers. I found that though most of us are aware of this mode but we don't use it as often, as it should be.

</br>
<strong>Where should I use grails --interactive mode while developing in grails?</strong>
The answer may vary from person to person and the level of expertise. For me, I found it amazing while running my tests and creating artifacts. 
</br>
I shall describe the advantages that I found with interactive mode while running Unit Tests. Let us take an example here:

I have a class called PersonUtil which needs to be unit tested. I write a PersonUtilTests class for testing its functionality. In order to run this particular unit test, I can use the following command:
[java]grails test-app unit: PersonUtilTests[/java]
This takes approximately 20 secs on an average to run on my machine with a decent configuration. 

Alternatively, We can run it in interactive mode. What we need to do is 

[java] grails --interactive[/java]

This shall bring the grails infrastructure up and make it just ready to run commands. It takes around 5 seconds.
[java]Welcome to Grails 1.3.7 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /opt/grails

Base Directory: /home/farid/grailsApplications/survey-app/ErServices
--------------------------------------------------------
Interactive mode ready. Enter a Grails command or type "exit" to quit interactive mode (hit ENTER to run the last command):

[/java]
Now, to test the app I can use the following command:
[java]
-------------------------------------------------------
Command TestApp completed in 2461ms
--------------------------------------------------------
Interactive mode ready. Enter a Grails command or type "exit" to quit interactive mode (hit ENTER to run the last command):
test-app unit: PersonUtilTests
[/java]

It took 15 seconds to run this for first time.
For subsequent runs, it took 2-4 seconds. Which is a clear advantage of 16 seconds for every run. These 16 seconds are no less than gem when you are in your "flow-state"( in concentration mode). 
<p>
While development, we make frequent changes to our code and therefore we need to run our unit tests multiple times. Every time I make a change and re run my unit test it takes 20 seconds through conventional grails test-app whereas it takes 3-4 seconds through interactive mode. 
 </p>

Earlier, I used to get frustrated while waiting for test cases to execute. This waiting time is one of the biggest factor that drives us from doing Test Driven Development.  
</br>
Just in case you have not tried it. Please give it a shot. Believe me, it's worth trying, you wont be disappointed!!! 
</br>
Mohd Farid
farid@intelligrape.com










]]></description>
			<content:encoded><![CDATA[<p>Of late, I have been thinking about the popularity of grails interactive mode amongst developers. I found that though most of us are aware of this mode but we don&#8217;t use it as often, as it should be.</p>
<p></br><br />
<strong>Where should I use grails &#8211;interactive mode while developing in grails?</strong><br />
The answer may vary from person to person and the level of expertise. For me, I found it amazing while running my tests and creating artifacts.<br />
</br><br />
I shall describe the advantages that I found with interactive mode while running Unit Tests. Let us take an example here:</p>
<p>I have a class called PersonUtil which needs to be unit tested. I write a PersonUtilTests class for testing its functionality. In order to run this particular unit test, I can use the following command:</p>
<pre class="brush: java;">grails test-app unit: PersonUtilTests</pre>
<p>This takes approximately 20 secs on an average to run on my machine with a decent configuration. </p>
<p>Alternatively, We can run it in interactive mode. What we need to do is </p>
<pre class="brush: java;"> grails --interactive</pre>
<p>This shall bring the grails infrastructure up and make it just ready to run commands. It takes around 5 seconds.</p>
<pre class="brush: java;">Welcome to Grails 1.3.7 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /opt/grails

Base Directory: /home/farid/grailsApplications/survey-app/ErServices
--------------------------------------------------------
Interactive mode ready. Enter a Grails command or type &quot;exit&quot; to quit interactive mode (hit ENTER to run the last command):
</pre>
<p>Now, to test the app I can use the following command:</p>
<pre class="brush: java;">
-------------------------------------------------------
Command TestApp completed in 2461ms
--------------------------------------------------------
Interactive mode ready. Enter a Grails command or type &quot;exit&quot; to quit interactive mode (hit ENTER to run the last command):
test-app unit: PersonUtilTests
</pre>
<p>It took 15 seconds to run this for first time.<br />
For subsequent runs, it took 2-4 seconds. Which is a clear advantage of 16 seconds for every run. These 16 seconds are no less than gem when you are in your &#8220;flow-state&#8221;( in concentration mode). </p>
<p>
While development, we make frequent changes to our code and therefore we need to run our unit tests multiple times. Every time I make a change and re run my unit test it takes 20 seconds through conventional grails test-app whereas it takes 3-4 seconds through interactive mode.
 </p>
<p>Earlier, I used to get frustrated while waiting for test cases to execute. This waiting time is one of the biggest factor that drives us from doing Test Driven Development.<br />
</br><br />
Just in case you have not tried it. Please give it a shot. Believe me, it&#8217;s worth trying, you wont be disappointed!!!<br />
</br><br />
Mohd Farid<br />
farid@intelligrape.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2011/11/30/grails-productivity-enhancer-the-unsung-hero-grails-interactive-mode/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Grails:Domain Design Via Intellij Idea&#8217;s Diagrams</title>
		<link>http://www.intelligrape.com/blog/2011/11/23/grailsdomain-design-via-intellij-ideas-ui/</link>
		<comments>http://www.intelligrape.com/blog/2011/11/23/grailsdomain-design-via-intellij-ideas-ui/#comments</comments>
		<pubDate>Tue, 22 Nov 2011 19:07:37 +0000</pubDate>
		<dc:creator>Hitesh Bhatia</dc:creator>
				<category><![CDATA[GORM]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[domain]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[IDEA]]></category>
		<category><![CDATA[Intellij]]></category>
		<category><![CDATA[Intellij Idea]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=4533</guid>
		<description><![CDATA[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 relation that 	publication has many [...]]]></description>
			<content:encoded><![CDATA[<p>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</p>
<ol>
<li>To see relationship diagram, Selected Domain Class, and 	selected tab Domain Class  Dependencies.It should look like this<br />
<img src="http://www.intelligrape.com/blog/wp-content/uploads/2011/11/Screenshot-at-2011-11-22-231031.png" alt="image" width="650px" height="400px" /></li>
<li>Lets assume the relation that 	publication has many books. So I drag mouse from Company to Books. 	Which invokes a popup asking about relationship between the domains 	and type and name of the field.<br />
<img src="http://www.intelligrape.com/blog/wp-content/uploads/2011/11/Screenshot-at-2011-11-22-231857.png" alt="image" width="300px" height="150px" /></li>
<li>On Selecting ok from previous 	popup. Their relation is defined in domain and in diagram. Similarly, lets  define</li>
<ol>
<li>Book hasMany Authors,</li>
<li>Authors hasMany Books,</li>
<li>Book belongsTo Author</li>
<li>And Diagram looked like this.</li>
</ol>
<p><img src="http://www.intelligrape.com/blog/wp-content/uploads/2011/11/Screenshot-at-2011-11-22-232618.png" alt="image" width="650px" height="300px" /></li>
<li>Next Step – Lets add fields to Domain Class all by Intellij Idea&#8217;s UI. Select package of domain class and pressshft+ctrl+alt+u. It&#8217;ll open package diagram of  app.<br />
<img src="http://www.intelligrape.com/blog/wp-content/uploads/2011/11/Screenshot-at-2011-11-22-233416.png" alt="image" width="650px" height="300px" /></li>
<li>Now lets add field name to domain 	Author. For that we&#8217;ll need to select domain author,right click and select fields. It&#8217;ll 	invoke a popup asking details about field.<br />
<img src="http://www.intelligrape.com/blog/wp-content/uploads/2011/11/Screenshot-at-2011-11-22-233553.png" alt="image" width="400px" height="150px" /><br />
Similarly we add field name to Author and published on to Book.</li>
<li>Now lets add a method  to named “publishedBefore” to Book which takes a date and return list of books published before that date.For this we need to right click on domain and select method.And it&#8217;ll invoke popup asking 	details.Select create and its done.<br />
<img src="http://www.intelligrape.com/blog/wp-content/uploads/2011/11/Screenshot-at-2011-11-22-234759.png" alt="image" width="650px" height="300px" /></li>
</ol>
<p>This was a simple and easy way to create structure of grails app in Intellij Idea.</p>
<div>_________________________________</div>
<div>Hitesh Bhatia<br />
<a href="http://in.linkedin.com/in/bhatiahitesh" target="_blank">Mail,LinkedIn</a>,<a href="http://www.facebook.com/home.php?#%21/profile.php?id=100000114437286" target="_blank">Facebook</a>,<a href="http://twitter.com/d1_ricky" target="_blank">Twitter</a><br />
_________________________________</div>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2011/11/23/grailsdomain-design-via-intellij-ideas-ui/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing JSON APIs : Part I &#8211; Creating a secure JSON API with Grails and Spring Security in 3 easy steps</title>
		<link>http://www.intelligrape.com/blog/2011/11/16/writing-json-apis-part-i-creating-a-secure-rest-json-api-with-grails-and-spring-security-in-3-easy-steps/</link>
		<comments>http://www.intelligrape.com/blog/2011/11/16/writing-json-apis-part-i-creating-a-secure-rest-json-api-with-grails-and-spring-security-in-3-easy-steps/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 06:01:57 +0000</pubDate>
		<dc:creator>Vivek Krishna</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[REST Calls]]></category>
		<category><![CDATA[spring security]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=4502</guid>
		<description><![CDATA[We had a requirement in a recent project to expose some of the functionality we had via a JSON API. The functionality needed to be secure, as was the initial web interface which exposed the functionality. We were using Spring Security for the security aspect of our application.
The spring security plugin, together with a secured [...]]]></description>
			<content:encoded><![CDATA[<p>We had a requirement in a recent project to expose some of the functionality we had via a JSON API. The functionality needed to be secure, as was the initial web interface which exposed the functionality. We were using Spring Security for the security aspect of our application.</p>
<p>The spring security plugin, together with a secured controller and a custom JSON marshaller(which overrides the default functionality of render as JSON method) gave us a very simple, yet elegant and powerful JSON API which was secure. Here are the three steps that we followed</p>
<p><strong>1. Setting up Spring Security Plugin: </strong></p>
<p>The first step is to set up Spring Security Plugin to expose our JSON based controllers to use Basic Authentication, instead of the standard web based authentication. This is done by adding the lines given below in Config.groovy</p>
<pre class="brush: java;">
//Enable Basic Auth Filter
grails.plugins.springsecurity.useBasicAuth = true
grails.plugins.springsecurity.basic.realmName = &quot;JSON API Example&quot;
//Exclude normal controllers from basic auth filter. Just the JSON API is included
grails.plugins.springsecurity.filterChain.chainMap = [
'/json/**': 'JOINED_FILTERS,-exceptionTranslationFilter',
'/**': 'JOINED_FILTERS,-basicAuthenticationFilter,-basicExceptionTranslationFilter'
]
</pre>
<p>More details about the authentication mechanism can be found <a href="http://burtbeckwith.github.com/grails-spring-security-core/docs/manual/guide/9%20Authentication.html" target="_blank">here</a>.<br />
<strong>2. Adding a Controller with required actions:</strong></p>
<p>Naturally, this is the next step. We added a controller which would expose the functionalities required(another reason why most of our logic should be in our services instead of controllers). A sample controller would look like this.</p>
<pre class="brush: java;">
package jsonapi
import grails.plugins.springsecurity.Secured
import grails.converters.JSON
import com.intelligrape.example.json.Book

@Secured([&quot;ROLE_USER&quot;])
class JsonController {
      def getBooks = {
          render Book.list() as JSON
      }
}
</pre>
<p><strong>3. Customizing the Marshaller to change the way some properties like enums are rendered:</strong></p>
<p>We had to change the way some of the properties like enums were going to be rendered. We just had to render the property name and the id of the enum. So instead of a json map like</p>
<pre class="brush: java;">

&quot;genre&quot;:{&quot;enumType&quot;:&quot;com.intelligrape.example.json.Book$Genre&quot;,&quot;name&quot;:&quot;FICTION&quot;}
</pre>
<p>we needed</p>
<pre class="brush: java;">

&quot;genre&quot;:&quot;FICTION&quot;
</pre>
<p>I sought help from David Bower&#8217;s <a href="http://manbuildswebsite.com/2010/02/15/rendering-json-in-grails-part-3-customise-your-json-with-object-marshallers/" target="_blank">post</a> and created my own custom Domain Class Marshaller for JSON with a modification to just use the Enum value if the property happened to be an enum. This is a very powerful feature because it allows us to customize the way in which we want to render the values when creating a JSON or XML document from our classes. We can even customize it to have an <em>excludes </em>list in our domain class where we can specify the properties to be excluded while constructing our JSON or XML<em> </em></p>
<p>With this, we had a JSON API ready in very little time. I have extracted the functionality into a small example application, which has been shared on <a href="https://github.com/svivekkrishna/Json-API-Sample" target="_blank">Github</a>.</p>
<p>Yet another example of how simple grails has made it easy for developers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2011/11/16/writing-json-apis-part-i-creating-a-secure-rest-json-api-with-grails-and-spring-security-in-3-easy-steps/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Grails Spring Security Plugin: User Switcher</title>
		<link>http://www.intelligrape.com/blog/2011/11/14/grails-spring-security-plugin-user-swticher/</link>
		<comments>http://www.intelligrape.com/blog/2011/11/14/grails-spring-security-plugin-user-swticher/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 06:37:47 +0000</pubDate>
		<dc:creator>Himanshu Seth</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[spring security]]></category>
		<category><![CDATA[user switcher]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=4487</guid>
		<description><![CDATA[If you are using Grails Spring Security in your application, one killer functionality that we can easily provide is a simple user switcher
Add this to your admin layout:

&#60;sec:ifAllGranted roles='ROLE_ADMIN'&#62;
    &#60;form action='/j_spring_security_switch_user' method='POST'&#62;
        Switch: &#60;g:select from=&#34;${users}&#34; optionKey=&#34;username&#34; optionValue=&#34;displayInfo&#34;
         [...]]]></description>
			<content:encoded><![CDATA[<p>If you are using Grails Spring Security in your application, one killer functionality that we can easily provide is a simple user switcher<br />
Add this to your admin layout:</p>
<pre class="brush: xml;">
&lt;sec:ifAllGranted roles='ROLE_ADMIN'&gt;
    &lt;form action='/j_spring_security_switch_user' method='POST'&gt;
        Switch: &lt;g:select from=&quot;${users}&quot; optionKey=&quot;username&quot; optionValue=&quot;displayInfo&quot;
                          name='j_username'/&gt;&amp;nbsp;&lt;input type='submit' value='Switch'/&gt;
    &lt;/form&gt;
&lt;/sec:ifAllGranted&gt;
&lt;sec:ifSwitched&gt;
    &lt;a href='${request.contextPath}/j_spring_security_exit_user'&gt;
        Resume as &lt;sec:switchedUserOriginalUsername/&gt;
    &lt;/a&gt;
&lt;/sec:ifSwitched&gt;
</pre>
<p>In Config.groovy, add the following:</p>
<pre class="brush: groovy;">grails.plugins.springsecurity.useSwitchUserFilter = true</pre>
<p>So, in two easy steps we can provide the application admin to impersonate other users. This also checks if the current user is actually an impersonation and if it is, it provides a link to go back to the original user.</p>
<p>Very neat indeed <img src='http://www.intelligrape.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>More detailed info available <a href="http://burtbeckwith.github.com/grails-spring-security-core/docs/manual/guide/15%20Switch%20User.html" target="_blank">here</a></p>
<p>Regards<br />
~~Himanshu Seth~~</p>
<p>http://www.IntelliGrape.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2011/11/14/grails-spring-security-plugin-user-swticher/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Groovy : Find Index of Element in Map</title>
		<link>http://www.intelligrape.com/blog/2011/11/10/groovy-find-index-of-element-in-map/</link>
		<comments>http://www.intelligrape.com/blog/2011/11/10/groovy-find-index-of-element-in-map/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 18:16:26 +0000</pubDate>
		<dc:creator>Hitesh Bhatia</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[map]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=4474</guid>
		<description><![CDATA[Groovier way of finding index of element from Map. It can be obtained with findIndexOf Method, which accepts closure as argument.


Map map=[&#34;groovy&#34;:1,&#34;grails&#34;:2,&#34;index&#34;:3,&#34;element&#34;:4]
assert 3 == map.findIndexOf{it.key==&#34;element&#34;}
assert 0 == map.findIndexOf{it.value==1}

]]></description>
			<content:encoded><![CDATA[<p>Groovier way of finding index of element from Map. It can be obtained with findIndexOf Method, which accepts closure as argument.</p>
<pre class="brush: groovy;">

Map map=[&quot;groovy&quot;:1,&quot;grails&quot;:2,&quot;index&quot;:3,&quot;element&quot;:4]
assert 3 == map.findIndexOf{it.key==&quot;element&quot;}
assert 0 == map.findIndexOf{it.value==1}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2011/11/10/groovy-find-index-of-element-in-map/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Grails bindData to collections</title>
		<link>http://www.intelligrape.com/blog/2011/10/24/grails-binddata-to-collections/</link>
		<comments>http://www.intelligrape.com/blog/2011/10/24/grails-binddata-to-collections/#comments</comments>
		<pubDate>Mon, 24 Oct 2011 06:51:44 +0000</pubDate>
		<dc:creator>Mohd Farid</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[bindData]]></category>
		<category><![CDATA[collection]]></category>
		<category><![CDATA[data binding]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=4381</guid>
		<description><![CDATA[Recently, I was stuck with a scenario where I was trying to bind a list of objects in my controller.  While trying the way as suggested in the grails docs I was getting some weird IndexOutOfBoundException. Luckily I found a good solution on the grails mailing list: http://grails.1312388.n4.nabble.com/Databinding-Collection-of-non-domain-objects-tp3260578p3260856.html
Thanks to mkwhit for asking this and [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I was stuck with a scenario where I was trying to bind a list of objects in my controller.  While trying the way as suggested in the grails docs I was getting some weird IndexOutOfBoundException. Luckily I found a good solution on the grails mailing list: <a href="http://grails.1312388.n4.nabble.com/Databinding-Collection-of-non-domain-objects-tp3260578p3260856.html">http://grails.1312388.n4.nabble.com/Databinding-Collection-of-non-domain-objects-tp3260578p3260856.html</a><br />
Thanks to <a href="http://grails.1312388.n4.nabble.com/template/NamlServlet.jtp?macro=user_nodes&amp;user=210908">mkwhit</a> for asking this and   <a href="http://grails.1312388.n4.nabble.com/template/NamlServlet.jtp?macro=user_nodes&amp;user=137554">Dana</a> for suggesting this solution.<br />
<br />
There is  a Car class in my src/groovy. There is a create.gsp that should create n number of cars at a time. The problem is to bind this data to a List of Car objects.</p>
<p>Here is how I got it done:</p>
<p>I ensured in my gsp that the car parameters are passed as car.1.name, car.1.brand, car.2.name, car.2.brand &#8230;.. So, when I did a params.car I get a Map like this:</p>
<pre class="brush: groovy;">
1: [name:'carA', brand:'brand1']
2: [name:'carB', brand:'brand2']
3: [name:'carC', brand:'brand2']
1.name:'carA'
1.brand:'brand1'
2.name:'carB'
2.brand:'brand2'
3.name:'carC'
3.brand:'brand3'
</pre>
<pre class="brush: groovy;">
def carParams = params.car.values().findAll {it instanceof GrailsParameterMap}
List&lt;Car&gt; carList = carParams.collect {
   def car = new Car()
   bindData(car, it)
   car
}</pre>
<p>So, we have a list of Car objects out from the params.</p>
<p>Hope this helps.</p>
<p>-Mohd Farid-</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2011/10/24/grails-binddata-to-collections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

