Find interesting places to spend beautiful day with kids on
www.spenddaywithkids.com

Friday, July 17, 2009

Groovy and Grails help build apps faster

Actually this is not my post but a very interesting article about productivity gained using Grails and Groovy.

Usually I am not posting links to other articles but my feeling is that this one deserves this. I didn't notice link to this articles on other grails/groovy related sites so I want to share it.

So navigate to "Groovy and Grails help build apps faster" to read the whole case.

Sunday, July 5, 2009

Spend day with kids Grails web app launched

I have launched new Grails powered web site www.spenddaywithkids.com.

Idea of the web site is to help you find interesting places where you can go with kids. There are places like zoos, water parks, theme parks....

Developing this application was interesting for me because this was for me the first time I used google maps in some of my application. Also new for me was geocoding but actually this turned out to be as easy as reuse formulas available online. Currently on USA is covered but Europe should come soon.

Currently I have three sites online: grails tutorials, software books reviews and spend day with kids.
For me it is just prove that development of web applications with Grails is easy and fun but know I will concentrate on extending my existing site and hope I will not get any fun idea soon :)

Let me know if you have some proposals for any of mentioned sites.

Tuesday, June 30, 2009

Book Review: Grails in Action

I was lucky enough to get copy of the book Grails in Action from Manning. And of course I have promised to write review of the book.

My feelings about the book are somehow mixed. Basically book is divided into four parts:
  • Introducing Grails
  • Core Grails
  • Everyday Grails
  • Advanced Grails
The first two parts, Introducing Grails and Core Grails, are for more or less newcomers to the Grails so if you already have experience with Grails they are somehow boring. That wouldn't be a problem if my opinion wouldn't be that they are not written in an appropriate way for the Grails/Groovy beginners. My feeling is that beginners will get confused as the authors jump too much directly into action. So my advice for the beginners is to read e.g. Getting Started with Grails and then come back to the book Grails in Action.

But even if you already have Grails experience don't just skip over the first two parts, because after having some Grails foundation the first two parts become very useful and very easy understandable. Even for me (and I have some experience with Grails) there were useful information and discoveries.

Very good approach in this two parts from the authors is that they have devoted lot of energy to explain how to test Grails application. This is something I should definitely start to do on my own projects :)

The real fun comes with the second two parts - Everyday Grails and Advanced Grails. I have really enjoyed reading chapters from those parts. They are very nice and are really covering lot of skills you will need during real Grails projects.

In the third part authors are explaining how not to reinvent wheel by using number of available plugins. They show you how to fast and reliably put together advance features by reusing already existing functionality. I liked this approach and using it myself a lot.
There are also chapters devoted to workflows, exposing interface to outside world and using messaging.

After finishing third part you have really solid foundation to do some serious Grails development.

The fourth part is really advanced although I would include basic transactional behavior into at least third part of the book as this is probably more everyday grails than advanced grails. The fourth part will explain advance GORM related features, advance usage of spring and something you will for sure meet in the corporate environment - build and deploy process.

Conclusion
At the end I was very happy that I got a chance to read this book. This book will lead you from the beggining to the really advanced features of the Grails. If you are developing with Grails I am very sure you will have this book near you.
If you are just starting with Grails I would recommend, first read something simplier and then come back to this book. I am sure you will enjoy reading it.


And if you want to buy the book you can do it here :)


Sunday, June 14, 2009

Book Review: Becoming Agile

When I started to think that majority of agile books are somehow breaking DRY (don't repeat yourself) principle I was lucky enough to get a copy of the book Becoming Agile: ...in an imperfect world.

Introduction

What I liked the most in this book is that it is completely oriented to the real world. Therefore it will not try to teach you any of the existing agile frameworks but will help you to make your company (team) agile taking into account all constraints surrounding you. Book is oriented around agile principles and authors consider you environment agile if you are following agile manifesto principles.
Another value of the book is that agile introduction is taken from the complete beginning. From company readiness assessment up to the project deployment and spreading your agile process through out the whole company. The whole project lifecycle is covered. From the vision, through adapting idea to the deployment. This is something that I was missing the most in lot of books about agile.

Book follows imaginary company Acme media and its move toward more agile environment.
Getting started chapter will explain how to check your company readiness to adopt agile processes, ensure buy-in and inject agility into your existing process. When you have selected pilot project you are moving forward.

Kicking off
chapter explains how to make feasibility study and how to decide if you should continue or stop with the project.

If you decided to continue with the project Populating the product backlog chapter will show how to create product backlog, what means "just enough" for a feature card and how to estimate and prioritize the product backlog.

Enough information for scheduling creates release plan and explains in how much details you should plan your iterations. And don't forget that having plan is not enough. What you need is planning because during the project your plan will change for sure.

When you have release and iteration plan you can move to the Building the product chapter. You will see how to welcome change, how to apply agile principles into development and how to ensure that you have working software at the end of iteration.

Embracing change chapter cope with adapting to change requirements. It explains common reasons for requirement changes and how to adapt to them. Next parts of this chapter will show you how to plan deploying and how to improve your process using retrospective.

If your pilot project was successful you will want to spread the agile process throughout the company. The Moving forward chapter will help you with this process.

Rest of the book explains the whole process from two different points of view. In one chapter the overall diagram of the project lifecycle is displayed and shortly explained while another chapter contains text description of the overall process.

Conclusion
Although at the beginning I was not sure if I want to read this book I must admit I have really enjoyed reading the book. I believe that this book must be mandatory read for anyone who want to become member of agile community.
The only downside of the book is that it covers really wide area (complete project lifecycle) and thus after reading this book you will need to read other books to improve your knowledge about e.g. estimating, testing, writing good user stories...

I really recommend this book to everyone that already are or want to enter the agile world.



Tuesday, May 19, 2009

Analyzing domain of the problem - GORM classes

[From the series - creating software books reviews grails web application]

In the previous posts I have created basic empty grails application. All the steps done to get up to this point are linked in this post. When the basic layout of the application is prepared it is obviously time to analyze domain objects. Domain objects in the grails are called GORM (grail's object relational mapping). Database schema is automatically generated from GORM objects and they probably represent the most powerful feature of the grails framework.

As software books reviews site is about providing reviews for the books the main features that need to be covered by application are following.

Visitor comes to the web site. From here he can navigate through existing books and read reviews and summaries. Review can be written on the site or link to the web site with the review can be provided. Summary is expressed as number (from 1 to 5) of some book aspects. Visitor can register and then he is able to post reviews and summaries for the books. Additionally there are some tasks for the administrator like: moderating books, posting new books...

If I try to express this short description as a list of user stories we get following:

As visitor I want to register.

As registered user I want to login.

As visitor I want to see books and reviews/summaries of the books.

As registered user I want to post book review.

As registered user I want to post summary.

As administrator I want to moderate books (this is probably epic).

Although user stories should be implemented one by one it is not a mistake to make an overview of the whole system. So described system can be pictured like this:

domain_model

On the picture above I have depicted domain object classes that I will create for the sbr project. For those that already have some knowledge about GORM the class BookAuthor may be surprising. In the GORM it is possible to model "many-to-many" relationship directly. I don't like this way and most of the time I create additional domain class that is representing connection object. Of course you can use what ever approach but for me this is much more flexible because I can easily navigate in both directions in the relationship and even having custom logical methods in the connecting class - BookAuthor in this case.

Let me write few words about this domain objects model. As you can see the central place in the model plays the Book class. It is not surprise because sbr is more or less about books. For each book we want to have different details except reviews and summaries. Those details are Author and Publisher.

The relationship between Book and Author is many-to-many. This means that each book can have more than one author and each author can write more than one book. Thus domain object BookAuthor is created.

The relationship between Book and Publisher is many-to-one. This means that each book can have only one publisher. Or from the other point of the relationship, each publisher can publish many books.

Next interesting part of the diagram is BookReview and BookSummary and User. The logic here is that book review and book summary must be provided for an existing book by an existing user. There is no limit on the domain level how many reviews/summaries user can provide for the same book. This limit is set as a business logic. Registered user can post one review/summary per book while moderator can post many reviews per book and one summary per book.

Knowing all these we are ready to start with implementation. If you do it in hurry you can start with the book class. But as we already know that we will need possibility to register and we will need User class it is good moment to have a look into grails plugins.

Before you start implementing anything in the Grails it is good idea to see what is available from the Grails plugins. Very often functionality you need is already implemented as a plugin and you can simply reuse it. The same story is for registration and the User class. For software books reviews site I am using Spring security plugin (former Acegi security plugin). So you need to install this plugin. How to do that you can find in the plugins section of the Grails web site. After installing it create two roles: admin and user. This plugin offers out of the box login, logout, register pages and lot of useful methods that can be used in the application.

So in my next post I will install Spring (Acegi) security plugin, initialize default roles on the startup (if they are not initialized already) and then we will include register/login links on the home page and implement the first two user stories: As visitor I want to register and As registered user I want to login. So stay tuned.

P.S. Don't forget to write some review or post summary on the software books reviews.

Tuesday, May 5, 2009

Integrating blueprint into Grails application

[From the series - creating software books reviews grails web application]

In the previous post we have created home and admin page. Now it is time to create layout of the application. If you visit software books reviews site you can see that layout of the page is header and footer and three columns. If you are not a CSS expert creating such layout can be probably complex so it is good idea to use help of some CSS framework. My CSS framework is blueprint.

Blueprint is the grid based framework with the fixed width. Screen is divided into 24 columns and you can specify "boxes" and number of columns they should span through. The most important thing to remember is that sum of the box widths may not be bigger than 24. It can be smaller but not bigger.

The short example of the web page with the blueprint can look like this:

<div class="container">
<div id="one" class="span-24 last">
<!-- some content -->
</div>
<hr/>
<div id="two" class="span-4 colborder">
<!-- some content -->
</div>
<div id="three" class="span-14 colborder">
<!-- some content -->
</div>
<div class="span-4 last">
</div>
</div>

In this short code example the most important features of the blueprint framework are already visible.

The first div with class container is mandatory and blueprint will work inside this div.

<div id="one" class="span-24 last"> defines box that should spread through all 24 columns. This means that content will take the whole row of the screen. "last" class is used to specified that it is last box in the given row. This class has more sense when the sum of box widths is less than 24 but you want to put next box into the new row.

<hr> is blueprint tag that just makes more space between two rows.

Next three <divs> are actually more interesting. Here you are defining that row should be divided into three columns. First column of the width 4, next column of the width 14, and last column of the width 4. What you can notice immediately is that sum of these numbers is 22.

The reason is that class colborder separates two columns and actually takes the space of the whole column.

Now when we have basic knowledge about blueprint it is time to integrate it into our sbr application. The first step is to download the blueprint framework from their site. When you extract the downloaded zip file, copy the three css files from the blueprint folder. The file to copy are: ie.css, screen.css, and print.css.

You should copy them into web-app/css folder of the sbr application.

Now it is time to define layout of our application. As already mentioned we want that all pages are same and have header/footer and three columns: left, middle and right column. If you have read Starting with front-end in Grails application post then it should be clear that the right place where to specify this is the main.gsp template. This template specifies how all pages that are based on this template will look like. First of all we need to reference css files we have copied to the css folder. To do this change to grails-app/views/layouts/main.gsp to look like this:

<html>
<head>
<title><g:layoutTitle default="Grails" /></title>
<link rel="stylesheet" href="${createLinkTo(dir:'css',file:'main.css')}" />
<g:layoutHead />
<link rel="stylesheet" href="${createLinkTo(dir:'css',file:'screen.css')}" type="text/css" media="screen, projection" />
<link rel="stylesheet" href="${createLinkTo(dir:'css',file:'print.css')}" type="text/css" media="print" />
<link rel="stylesheet" href="${createLinkTo(dir:'css',file:'ie.css')}" type="text/css" media="screen, projection" />
<g:javascript library="application" />
</head>
<body>
<g:layoutBody />
</body>
</html>

The three lines to notice are:

<link rel="stylesheet" href="${createLinkTo(dir:'css',file:'screen.css')}" type="text/css" media="screen, projection" />
<link rel="stylesheet" href="${createLinkTo(dir:'css',file:'print.css')}" type="text/css" media="print" />
<link rel="stylesheet" href="${createLinkTo(dir:'css',file:'ie.css')}" type="text/css" media="screen, projection" />

They are added as specified by the blueprint framework. The only difference is that I have used createLinkTo grails construct.

Now when we are referencing necessary css files we can specify layout of the template.

<html>
<head>
<title><g:layoutTitle default="Grails" /></title>
<link rel="stylesheet" href="${createLinkTo(dir:'css',file:'main.css')}" />
<g:layoutHead />
<link rel="stylesheet" href="${createLinkTo(dir:'css',file:'screen.css')}" type="text/css" media="screen, projection" />
<link rel="stylesheet" href="${createLinkTo(dir:'css',file:'print.css')}" type="text/css" media="print" />
<link rel="stylesheet" href="${createLinkTo(dir:'css',file:'ie.css')}" type="text/css" media="screen, projection" />
<g:javascript library="application" />
</head>
<body>
<div class="container">
<div id="header" class="span-24 last">
header
</div>
<hr/>
<div id="left-sidebar" class="span-4 colborder">
left sidebar
</div>
<div id="content" class="span-14 colborder">
<g:layoutBody />
</div>
<div id="right-sidebar" class="span-4 last">
right sidebar
</div>
<hr/>
<div id="footer" class="span-24 last">
footer
</div>
</div>
</body>
</html>

As you can see that is quiet easy and understandable. And what is good it is all what we need to the to get required layout. If you start the application now you will see that home page of the sbr application has correct layout. Of course we still need to populate all parts with the real content but that will be part of the next posts.

I know that usually I am announcing what will be topic of the next post but this time I am not sure. But for sure good reading is introduction into grails templates and tag libs mechanism that I have described in this and this post.

P.S. Don't forget to write some review or post summary on the software books reviews.

Tuesday, April 28, 2009

Creating home and admin page

[From the series - creating software books reviews grails web application]

In the previous post I have explained some basic aspects of grails front-end. Having this knowledge it is a time to create home page of sbr application. For the list of steps how I got up to this point you may want to have a look at this post pointing to all posts related to sbr series.

If you start sbr application (grails run-app) default home page generated by grails is displayed. This is not very useful page as a home page but will be very useful as admin page. It can be very useful as a admin page because it displays all controllers in your application. For each controller you can generate default list/show/create/edit pages.

So let create home page. To create home page I usually create HomeController. So the first step is to generate home controller. To create home controller type the following command:

grails create-controller Home

This command will generate HomeController.groovy file in the grails-app/controllers folder and home folder in the grails-app/views folder. In this folder we should put our new home page.

So to create home page in the home folder create file home.gsp that should look like this one:

<html>
<head>
<title>SBR</title>
<meta name="layout" content="main" />
</head>
<body>
Welcome to the SBR
</body>
</html>

We want to display this page when ever the HomeController is accessed. This is very easy to achieve. Update the code of the HomeController to look like this:

class HomeController {
def index = {
render (view:'home')
}
}

index closure is default closure of the controller and is executed when controller is accessed without specifying action to be executed. So if you type in your browser http://localhost:8080/sbr/home, index action will be executed. And this action is telling that the view 'home' should be displayed. As you are in the HomeController it will look for the file home.gsp in the grails-app/views/home folder. But if you want in the render closure you can specify the full path to the page to be displayed relative to the views folder. So render (view:'home/home') would be valid too.

Now it is time to create admin page. For admin page we will need AdminController. To create AdminController execute following command:

grails create-controller admin

Same as for the HomeController this command will create file AdminController.groovy and folder admin. To create admin page in the admin folder create admin.gsp file. Copy the content of the web-app/index.gsp file into the admin.gsp file. At the end admin.gsp should look like this:

<html>
<head>
<title>SBR admin</title>
<meta name="layout" content="main" />
</head>
<body>
<div class="dialog" style="margin-left:20px;width:60%;">
<ul>
<g:each var="c" in="${grailsApplication.controllerClasses}">
<li class="controller"><g:link controller="${c.logicalPropertyName}">${c.fullName}</g:link></li>
</g:each>
</ul>
</div>
</body>
</html>

We still need ability to display admin page. To process is the same as for the HomeController. Change the AdminController so it looks like this:

class AdminController {
def index = {
render (view:'admin')
}
}

But still, when you start application and access the link http://localhost:8080/sbr you are getting old index page. To change this change the web-app/index.gsp file to this:

<html>
<body>
<%response.sendRedirect(request.getContextPath()+"/home/");%>
</body>
</html>

This will redirect you to the HomeController and home page will be displayed after accessing sbr application.

We are almost done. But what is still remaining is to update template that we use for our pages. So go the the grails-app/views/layouts/main.gsp file and change it to look like this:

<html>
<head>
<title><g:layoutTitle default="Grails" /></title>
<link rel="stylesheet" href="${createLinkTo(dir:'css',file:'main.css')}" />
<g:layoutHead />
<g:javascript library="application" />
</head>
<body>
<g:layoutBody />
</body>
</html>

What I did are just simple changes to this file. Actually I have only removed some code from file generated by default.

As it turned out that this post is longer than I have expected let me summarize steps I have done. So after your grails application is generated you are ready to create home and future admin page. I am usually doing these steps:

  • Create HomeController and home.gps page
  • Create AdminController and admin.gsp page
  • Change index.gsp file so it redirects to the HomeController
  • Make main.gsp layout file simple.

After those steps basic skeleton of the grails application is prepared.

What remains is to prepare layout of the home.page and this can be achieved by changing main.gsp file. If you remember from the previous post, main.gsp is actually template that we can reuse for all the pages in the grails application. Actually we already did it for the home and admin page.

In the next post I will describe layouting of the main.gsp file or to be more precise I will integrate blueprint css framework into sbr application.

P.S. Don't forget to write some review or post summary on the software books reviews.