The Grails PetClinic Application

Updated:19.JAN.2007Graeme Rocher

Introduction

Java web development as it stands today is dramatically more complicated than it needs to be. Most modern web frameworks in the Java space are over complicated and don't embrace the Don't Repeat Yourself (DRY) principals.

Dynamic frameworks like Rails, Django and TurboGears helped pave the way to a more modern way of thinking about web applications. Grails builds on these concepts and dramatically reduces the complexity of building web applications on the Java platform. What makes it different, however, is that it does so by building on already established Java technology like Spring & Hibernate.

Grails is a full stack framework and attempts to solve as many pieces of the web development puzzle through the core technology and it's associated plug-ins. Included out the box are things like:

All of these are made easy to use through the power of the Groovy language and the extensive use of Domain Specific Languages (DSLs)

PetClinic Sample Application Requirements

The application requirement is for an information system that is accessible through a web browser. The users of the application are employees of the clinic who in the course of their work need to view and manage information regarding the veterinarians, the clients, and their pets. The sample application supports the following:

Use Cases

Business Rules

  1. An owner may not have multiple pets with the same case-insensitive name.

PetClinic Sample Application Design & Implementation

Server Technology

The sample application should be usable with any Java EE web application container that is compatible with the Servlet 2.4 and JSP 2.0 specifications.

Database Technology

HypersonicSQL version 1.8.0 is the default database used by Grails, but an alternative database can be configured as per the instruction in the Grails user guide.

Development Environment

The developer will need to obtain the following tools externally, all of which are freely available:

NOTE: The version numbers listed are those that were used in the development of the PetClinic application. Other versions of the same tools may or may not work.

Download links for the various tools needed are provided in the Downloads section.

Directory Structure

petclinic: the root directory of the project contains build related files
    grails-app: contains main Grails sources
        conf: contains configuration files
        controllers: contains web controllers
        domain: contains domain objects (entities)
        i18n: contains internationalization (i18n) property bundles
        services: contains transactional services that implement business logic
        taglibs: contains tag libraries that serve as view helpers
        utils: contains utility classes
        views: contains views written in Groovy Server Pages (GSP)
              layouts: contains layouts for separating out view logic
              common: contains common view templates
    lib: contains any user provided JAR files
    scripts: contains any user provided scripts
    src: contains additional Java and Groovy sources
    test: contains unit and integration tests
    lib: contains all static web resources

PetClinic Application Design

Logging

Grails supports the use of the Apache Commons Logging API. You can configure logging using the Grails Log4j DSL within the grails-app/Config.groovy file.

Business Layer

The Business Layer consists of a number of basic Grails domain classes representing the application domain objects and associated validation logic that are used by the Presentation Layer.

Presentation Layer classes

Logical Views & Implemented Use Cases

Testing

Downloads

Using the PetClinic Application

Make sure the PetClinic web application is running by typing "grails run-app" from the root of the project and then browse to http://localhost:8080/petclinic.

Deploying the PetClinic Application

Deploy the web application to the server in the usual way. If you need instructions for web application deployment, see the Tomcat documentation for details. The Web ARchive (WAR) file can be created by running the "grails war" command, which places it in the root of the project.