Groovy in Action
Groovy in Action
1 Refined Title
2 Practical Activity
This section will take into account the various sources of information I have found and review
what I have learned from them. I will then document how this information has been put into
practice with references made to practical work that can be seen in the appendix of this
document.
1. Kroenke, David M. "Beyond the Relational Database Model." IT Systems Perspectives May
2005. IEEE Computer Society. 24 Feb. 2008.
2. Mabanza, Ntima, Jim Chadwck, and G.s.v.r. Krishna Rao. Performance Evaluation of Open
Source Native XML Databases - a Case Study. Computer Science Department, University of
Fort Hare, Alice, South Africa. Alice: Association of Computing Machinery, 2006. 1861-1865.
3. Fong, Joseph, and H K. Wong. Replicate Relational and XML Databases for Internet
Computing. Computer Science Department, City University of Hong Kong. Hong Kong: IEEE
Computer Society, 2004. 24 Feb. 2008
4. Dietrich, Suzanne W., Susan D. Urban, Hua Ma, Yang Xiao, and Shama Patel. Exploring
XML for Data Exchange in the Context of an Undergraduate Database Curriculum.
Department of Computer Science and Engineering, Arizona State University. St. Louis:
SIGCSE, 2005. 53-57.
In the six weeks since submitting the last TMA I have concentrated on trying to find sources of
information that cover the development of the Teacher's Report Management System
(TRMS). Initially I was very much dictated by the Integrated Development Environment (IDE)
in how I was going to develop the TRMS. The IDE that I began using was Netbeans, which is
recommended by the OU and I initially referred to a lot of the documentation they provide, the
most useful of which was the following web tutorial:
The tutorial was very useful, giving step by step instructions on how to create a simple 3-tier
application that connected to a database containing details of American wrestlers. It used the
Java Scripting language JSP to do the middle layer processing between the database and the
client. JSP is a language I'm familiar with from studying M350, however I've never enjoyed
using it due to its sometimes confusing syntax. I was able to adapt the information in the
tutorial and produce a basic teacher selection and information page with little difficulty and at
this early stage of research I'd already made significant progress in my project schedule.
However, with the feedback given from TMA01, my tutor had advised that I investigate a new
web application framework called grails, which led me to reading the following source of
information:
6. Oak, Harshad. "An Introduction to Groovy and Grails." Dev2dev. 25 Oct. 2006. 3 Mar. 2008
<http://dev2dev.bea.com/pub/a/2006/10/introduction-groovy-grails.html>.
On first reading I found both the idea of the Groovy language and rails development hard to
grasp. I found Groovy confusing, I could understand the idea that one line of Groovy code
could do what takes Java 3 or 4 lines, yet being used to Java coding conventions made this
supposedly more simplistic coding more confusing for myself. Also, on first reading, the whole
idea of rails development, where the production framework is created for you, was completely
new and I couldn't understand the advantages from this introduction. It seemed that the most
useful thing to do at this stage was to follow some online tutorials, the three most significant of
which are detailed below:
The “Quick Start” tutorial was very useful and I was able to install Grails and instantly create a
basic prototype from the instructions given. It was easy to create the domain classes and
views necessary but I had some problems, mostly due to my own lack of understanding. One
of the explicit instructions was not to place your grails project in the same root directory as the
installed Grails files, but this is something that I did. I also had lots of problems with the
naming of my domain classes, I wanted to call one “Class” which produced conflicts,
changing the name to “Group” produced more conflicts. I could not find any explanation for
this but worked around it by changing the name of the domain class to “Term”. The Quick
Start tutorial got me started with Grails but I was really still very confused about the benefits it
gave, there was no real insight within the tutorial other than getting a basic project started with
Grails.
The next tutorial I found was Andrew Statton's Authorisation tutortial. This tutorial gave me
Stephen Burrows U5184463 3 TMA 02 M450
lots of problems. The main one being that the tutorial was written for a previous version of
Grails (v0.6) and I was using the current 1.1 version. There are many differences between the
two, mostly with the declaration of domain classes and subsequent constraints attached to
them. The tutorial was far from successful and in many ways convinced me that perhaps it
would not be a good idea to proceed with Grails because it was very difficult to fix errors
because error reporting in Grails is very poor. Once something went wrong I found it very hard
to find a fix, whereas with the JSP tutorial I could trace and correct my errors easily.
However, the final tutorial I have referenced, by Jason Randolph, was far more enlightening.
As I documented in my previous TMA, I had already started work on a MySQL database that
held the details of Teachers, the Classes they taught and the Students in those classes.
Randolph's tutorial was written in 2006 when Grails was at version 0.4.2, so once again there
was some confusion with the tutorial with regards to coding conventions, especially in domain
classes and with using hibernate files, a technology I was unfamiliar with. However, one
benefit of this tutorial being blog based was that readers could leave comments about the
tutorial and many people had. In the comments people had amended certain parts of the
tutorial so that it was up to date with the latest version of Grails. Due to this I was able to
complete about 80% of the tutorial but I had difficulties in getting full CRUD functionality with
the MySQL legacy database I has created. However, I found Randolph's style of explaining
Grails and how it works far more insightful than the other tutorials I had read, so when I
discovered he had recently written a book about Grails which was free to download, I decided
that this could be a valuable resource to investigate.
10. Rudolph, Jason. Getting Started with Grails. United States of America: C4Media Inc,
2006. 2-133.
This book has been an invaluable resource for me in developing my project using Grails.
Rudolph takes an example project from scratch, which is a race track application allowing
races and drivers to be monitored, and creates a substantial Grails project based on a 3 tier
architecture. Unlike many of the quick start tutorials I had read previously, Rudolph's book
takes time to explain the reasoning behind every action and most importantly, it clearly
demonstrates the power and advantages of Grails and the Groovy language. One of the initial
things I found fantastic about Grails was that it would create the whole MySQL database
schema based upon the domain classes I had previously created. This made it much easier
for me to apply one to one or one to many relationships between domain classes and it is
much easier to validate the class data through the available constraints. The book is
wonderfully put together, after developing a part of my project I would begin to wonder how
another feature, such as a search facility, could be introduced and literally within the next few
pages of the book this would be explained. I was able to work my way through the book within
a couple of weeks and went from being uncomfortable and slightly mistrusting of Groovy and
Grails to basically a child completely spellbound by the possibilities available and ease of
which they can be applied.
I believed that because of Rudolph's book I had made a lot of progress over the two weeks of
working with it. It was at this point that a small problem occurred, I decided to use a plug in for
the Eclipse IDE which helped with Groovy code. However there were some notes I hadn't
read in the install process about using the plug in with Grails and this caused problems with
Stephen Burrows U5184463 4 TMA 02 M450
the setting files of my Grails project which were unfortunately irreversibly broken. My work up
until that point was effectively ruined and I would have to start all over again. Surprisingly, to
me at the time, it took me roughly 20 minutes to recreate the project and have a 3 tiered web
application running that was identical to the ruined project. At this point I was somewhat
dismayed by exactly how much progress I could've made which could be replicated within 20
minutes. It was then by chance that I read the following magazine article:
11. Park, Andrew. "Keep It Simple, Stupid." Wired Mar. 2008: 124+.
The article was about Jason Fried and David Heinemeier Hansson, the creators of “Ruby on
Rails”, a web application framework for the Ruby programming language. Grails is very much
based up Ruby on Rails and was originally called “Groovy on Rails” until Hansson requested
they change the name. The article was incredibly insightful for me in explaining the
philosophy behind Rails development. The fact that I could recreate the ruined project in 20
minutes validates Hansson and Fried's theory that small teams of developers should be able
to build web applications in a matter of weeks using rails frameworks. The article highlights
that simple blogging applications can be built in 15 minutes and popular social networking
sites can be constructed within 2 weeks. After reading this article I was able to return to
Harshad Oak's "An Introduction to Groovy and Grails" and fully appreciate what Grails has to
offer.
More recently I have purchased two books on Groovy and I am currently reading the
following:
12. Konig, Dierk, Paul King, Guillaume Laforge, and Jon Skeet. Groovy in Action. New York:
Manning Publications Co., 2007. 1-75.
This is a very big and comprehensive guide to the Groovy programming language. The one
thing I find that is hindering my progress with the Grails framework is my lack of knowledge of
Groovy. Although Groovy is just a form of Java, adapted for simplicity, it does have several
features that make it a better alternative to Java in certain situations. One of the main
advantages Groovy provides over Java is the production and reading of XML documents.
From the initial reading I have made of the book I have already discovered how easily XML
files can be created through Groovy commands and how Groovy can be used to create
various Microsoft Office documents.
Appendix 1.1 shows the the code for the two Java Server Pages (index.jsp and response.jsp)
that I created based on the Netbeans tutorial I followed. I was able to create a basic teacher
selection tool by connecting the page to the Teacher table in the MySQL database using the
JDBC driver. Appendix 1.2 shows screen shots from the resulting pages. I found the pages
easy to code but was frustrated that I would need to create a new page for each action and
there was no way I could introduce client side code such as JavaScript with server pages.
Also, as I mentioned before, I find the amalgamation of HTML and JSP code quite confusing
to read and code and find myself making constant syntactical mistakes.
Stephen Burrows U5184463 5 TMA 02 M450
Appendix 2.1 shows various screen shots from the grails project I have developed.
Screenshot 2.1.1 shows the various controllers I've created that control the use of the domain
classes. Eventually this page will be redundant, the Groovy code directs the user to this page
as the index page but I will change that so that a log-in page becomes the initial indexing
page. But at this development stage it's an important part of the project for navigation
purposes. I've included a screenshot of the “Terms” page, to show how Grails displays
information by default in a style very similar to that of a database. This screenshot 2.1.2
displays 9 terms or classes that are taught by 3 different teachers. For these pages I haven't
written any coding, Grails has done everything based upon the domain classes I specified.
Screenshot 2.1.3 shows the first page I created beyond those automatically created by the
Grails framework (create, edit, list, show). The page I created is a simple teacher log-in page.
Front end elements like web pages are referred to as “views” in Grails, so I created a new
view in the “Teacher” folder and adapted some code that was featured in Jason Rudolph's
“Getting Started With Grails” book. Naming the view “login.gsp” (the gsp stands for groovy
server page), the page requests two pieces of information, a username and a password, the
page code can be seen in Appendix 2.2.1. Once they are entered and the user clicks the “Log
in” button, a method within the Teacher controller which has the same name as this view
(login) is activated, the code for this method can be seen in Appendix 2.2.3. It simply
searches for the username and password against the information held in the database and if
it is correct the user is redirected to another view “teacherlist” which is held with the Term
views. The reasoning behind this is that when the teacher logs in they need to see a list of
classes they are responisble for and of whom they'll need to write reports.
Screenshot 2.1.4 shows the list of classes applicable to a specific teacher. The code for this is
shown in Appendix 2.2.2 but is really little different to the code that is automatically generated
by grails for the list view included with every domain class. What is different with this page is
the controller method “teacherlist”, which can be seen in Appendix 2.2.4. This method takes
the teacher's details which are held in the session,username property and finds all terms that
are taught by that teacher, returning them as “termList”. You might also notice in this method
that I assign a new value to “flash.message”. I have found this a useful way of experimenting
with code and being able to see what values are being passed. In this example I'm just
confirming that the teacher's name is what I intended it to be.
Finally, Screenshot 2.1.5 shows the adapted report entry form. Adapting this was very easy,
just a matter of altering the tags within the report form. It cannot be seen on the screenshot,
but I have added a small checkbox to the form which allows the teacher to indicate when the
form is fully completed. This will eventually be an important element for indicating to the
administrative users which of the reports are complete and ready to be sent.
The process of a teacher using the system will be to log-in to the system, see a list of the
classes they teach, select a class, select a student and then complete the report of that
student. At the moment I would estimate the development of this procedure is 80%
completed.
Making versions of my project. Sometimes I have had unexpected problems with the
project caused by third party sources such as IDEs. I have recently started versioning
my project by creating a copy of the project files after significant progress has been
made so that any future progress is protected from unforeseen problems by rolling
back the project to the last working version. This has given me more confidence to
experiment with code and different IDEs which aid my progress.
Using the Grails Framework has made my work on this project much easier. In many
ways it seems as if Grails was designed for projects like mine, three tier applications
which can be easily built by small development teams. This combined with the
excellent XML features of Groovy have made it easy for me to find the solutions to the
requirements of my project all under one roof.
Groovy error handling is very poor, meaning that when a mistake is made with Groovy
code, be it semantical or logical, it is very difficult to trace the source of this error. With
experience I am getting better at analyzing the error reports but on many occasions I
have been unable to trace back my steps and correct the error. Making versions of the
project, as mentioned before, has been a good way to overcome this problem.
Keeping to the project schedule has been difficult. The three week iteration cycles have
been too short for me to complete all the sub-tasks referred to in the first project
schedule. A four week iteration cycle would've been more appropriate. Due to the fact
that I am dealing with a an unfamiliar framework and programming language I get
frequently sidetracked in trying to gather more information about these things rather
than completing work on the project. For example, I have spent the last week reading
Dierk Konig's “Groovy in Action” book opposed to actually working on the project. This
was not part of my original project schedule. Although I am on schedule and don't
foresee any problems in completing the project on time. I find the iteration cycles too
small and inflexible.
As I have already mentioned, I have found the three week iteration cycle of my project
schedule at this early stage a little restrictive. Although I don't believe myself to be behind
schedule, I think this cycle doesn't give me enough time during the design and
implementation stage. I have included in Appendix 3 both the old project schedule (3.1) and
the new, revised project schedule (3.2). The first change I made was the order of the main
tasks, due to the fact I was becoming engrossed in learning Grails and Groovy, I wanted to
continue with a hands on development approach, so I decided to bring forward Task 4
(Developing the Administrator Report Delivery System) to weeks 7, 8 and 9 and subsequently
push back task 3 (Implementation of Document Formatting) to weeks 10, 11 and 12.
I have maintained the iteration cycle for the delayed Task 3 to still be of 3 weeks because in
Stephen Burrows U5184463 7 TMA 02 M450
researching the Groovy language I have already done much of the analysis and design work
necessary for how document formatting will be implemented.
After that task I have increased the iteration cycles to 4 weeks each and I have completely
removed any more work on Task 1, Developing a Database. This is due to the fact that Grails
handles database development and construction perfectly through the validation of classes
and as far as I can see there's little if any more work required in this area.
The final four weeks of the plan still look a bit disorganized but I envisage a more organized a
task specific schedule will be produced by the time of the next TMA when the main work for
Tasks 3 and 4 should've been completed.
3.3 Ethics
At this point I feel it necessary to point out that the personal details of all stakeholders which I
have included within this project are all fictitious and none of these people, to my knowledge,
exist. Due to this I see no ethical problems with the data I am using because at this stage it is
only for test purposes. If the project where ever to be implemented within the environment I
have designed it for, this would change but it would be beyond the scope or time frame of this
course. So, I see no need for approval from HPMEC.
With regards to the future use of the report management system by stakeholders, I have
identified the following legitimate interests for each stakeholder.
1. Teachers: Have no need to access personal information about the student such as
address or email details. They should only be able to access the academic records of
students they are teaching, have taught or are due to teach.
2. Administration Staff: Can access personal details of students, alter their details and
see their academic records. A member of the Administration staff can view the
academic records of a student but cannot alter them.
3. Students: They can view any personal information that has been written about them
and can also see all academic records written about them by teachers.
As can be seen, I have extended my project title to highlight the fact that I am using the Grails
framework as the backbone of the project. I believe it has taken an important part of the
development process but most importantly has become an important part in my learning
process. By adopting Groovy and Grails I have gained knowledge in various new
technologies, the power of which has really captured my imagination and interest.
I aim to continue my reading on the Groovy language as it seems all the necessary
information I require is contained within the literature about Groovy that I have purchased.
This combined with various blogs and message boards which I have discovered online gives
me enough sources of information to maintain my upward learning curve and knowledge of
the subject.
I feel certain that the project will be completed on time and already have some ideas for some
“added extras” that could be incorporated into the project.
4.2 Resources
Beyond what has already been specified, the main resource that I believe I haven't taken full
advantage of as yet are the stakeholders in this project, most specifically members of the
teaching staff and administration staff. I need to have a working prototype prepared within the
next couple of weeks that can be tested by stakeholders so that I can receive some initial
feedback on my project.
I aim to have a fully working prototype of the project prepared before I start work in earnest on
the document formatting task of the project. I think this is important so that I can receive
feedback from stakeholders.
I already have an idea of an added extra I could implement with the system. This would be a
booking form for a school computer room. The school has one computer room that can be
reserved by teachers for one hour at a time. There are certain rules and restrictions in place
with the booking of the room but these rules are constantly broken. What's more, one needs
to be at the school to be able to reserve the room, many times teachers plan lessons from
home and need to factor into their lesson plan whether or not the computer room would be
available for the lesson. Being able to check the booking form online would make this much
easier and suitable conditions could be easily implemented into any domain class so that the
rules of who can book the computer room and when can be maintained. I believe I could
implement the system easily using much of the existing code.
Stephen Burrows U5184463 9 TMA 02 M450
1.1 Code
1.1.2 index.jsp
<%
Document : index
Created on : Feb 28, 2008, 3:34:10 PM
Author : stephen
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<sql:query var="teachers" dataSource="jdbc/ReportSystem">
SELECT teacher_name as name FROM Teachers
</sql:query>
<%@page contentType="text/html" pageEncoding="UTF8"%>
<!DOCTYPE HTML PUBLIC "//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta httpequiv="ContentType" content="text/html; charset=UTF8">
<title>Teacher Login Page</title>
</head>
<body>
<h2>Teacher Login Page</h2>
<table border="0">
<thead>
<tr>
<th>Choose you teacher ID and enter your password</th>
</tr>
</thead>
<tbody>
<tr>
<td><form action="response.jsp">
<strong>Select your name:</strong><select name="teacher_name">
<c:forEach var="teacher" items="${teachers.rows}">
<option value="${teacher.name}">${teacher.name}</option>
</c:forEach>
</select><input type="submit" value="submit" name="submit" />
</form></td>
</tr>
</tbody>
</table>
</body>
</html>
Stephen Burrows U5184463 10 TMA 02 M450
1.1.2 response.jsp
<%
Document : response
Created on : Feb 28, 2008, 11:09:43 PM
Author : stephen
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<sql:query var="teachers" dataSource="jdbc/ReportSystem">
SELECT teacher_name FROM Teachers
</sql:query>
<c:set var="name" value="${param.teacher_name}"/>
<%@page contentType="text/html" pageEncoding="UTF8"%>
<!DOCTYPE HTML PUBLIC "//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta httpequiv="ContentType" content="text/html; charset=UTF8">
<title>Report Entry Form</title>
</head>
<body>
<h2>Report Entry Form</h2>
<c:if test="${name == 'Veronica Wilson'}">
Go away
${name}
</c:if>
<c:if test="${name != 'Veronica Wilson'}">
Hello ${name}
</c:if>
</body>
</html>
Stephen Burrows U5184463 11 TMA 02 M450
1.2.2 response.jsp
Stephen Burrows U5184463 12 TMA 02 M450
<html>
<head>
<meta httpequiv="ContentType" content="text/html; charset=UTF8"/>
<meta name="layout" content="main" />
<title>Teacher's Term List</title>
</head>
<body>
<div class="nav">
<span class="menuButton"><a class="home"
href="${createLinkTo(dir:'')}">Home</a></span>
<! test: added this link to logout 27/03>
<span class="menuButton"><g:link controller="teacher" action="logout">Log
out</g:link></span>
${session.username}
</div>
<div class="body">
<h1>Term List</h1>
<g:if test="${flash.message}">
<div class="message">${flash.message}</div>
</g:if>
<div class="list">
<table>
<thead>
<tr>
<g:sortableColumn property="id" title="Id" />
<g:sortableColumn property="name" title="Name" />
<g:sortableColumn property="level" title="Level" />
</tr>
</thead>
<tbody>
<g:each in="${termList}" status="i" var="term">
Stephen Burrows U5184463 16 TMA 02 M450
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
<td><g:link action="show"
id="${term.id}">${term.id?.encodeAsHTML()}</g:link></td>
<td>${term.name?.encodeAsHTML()}</td>
<td>${term.level?.encodeAsHTML()}</td>
<td>${term.teacher?.encodeAsHTML()}</td>
<td>blank</td>
</tr>
</g:each>
</tbody>
</table>
</div>
<div class="paginateButtons">
<g:paginate total="${Term.count()}" />
</div>
</div>
</body>
</html>
def login = {
if (request.method == "GET") {
session.username = null
} else {
def teacher =
Teacher.findByUsernameAndPassword(params.username,params.password)
if (teacher) {
session.username = teacher.username
redirect(controller:'term',action:"teacherlist")
} else {
flash['message'] = 'Please enter a valid username and password'
}
}
}
def teacherlist = {
def teacher = new Teacher()
teacher = Teacher.findByUsername(session.username)
flash.message = "help ${teacher.name}"
render(view:'list', model:[ termList: Term.findAllByTeacher(teacher) ])
}
Stephen Burrows U5184463 17 TMA 02 M450
Apendix 3
TMA 01 x x
TMA 02 x x
TMA 03 x x
ECA x x x x x x
Stephen Burrows U5184463 18 TMA 02 M450
TMA 01 x x
TMA 02 x x
TMA 03 x x
ECA x x x x x x