Agile Web Development with Groovy & Grails
-
Upload
david-trattnig -
Category
Documents
-
view
711 -
download
1
description
Transcript of Agile Web Development with Groovy & Grails
Agile Web Development with Groovy & Grails
Groovy
3© 2008 BearingPoint, Inc.
Groovy
Why?
4© 2008 BearingPoint, Inc.
Groovy
Java Jobs
5© 2008 BearingPoint, Inc.
Groovy
Java EE Jobs
6© 2008 BearingPoint, Inc.
Groovy
Ruby On Rails Jobs
7© 2008 BearingPoint, Inc.
Groovy
JSR 241
8© 2008 BearingPoint, Inc.
Groovy
„Java-stylish with a Ruby-esque feeling“
9© 2008 BearingPoint, Inc.
Groovy
„Groovy is not a replacement for the Java programming language; it‘s a complement to that language“
Richard Monson-Haefel, award winning author & technical analyst
10
© 2008 BearingPoint, Inc.
Groovy
GroovyBeans
class GroovyBean {String name
}
11
© 2008 BearingPoint, Inc.
Groovy
Autoboxing
def b = new GroovyBean()b.name = “groovy bean“
12
© 2008 BearingPoint, Inc. 12
Groovy
Duck Typing„When I see a bird that walks like a
duck and swims like a duck and quacks like a duck, I call that bird a duck.“Poem by James Whitcomb Riley
13
© 2008 BearingPoint, Inc.
Groovy
Expressiveness
14
© 2008 BearingPoint, Inc.
Groovy
Java:java.net.URLEncoder.encode(“a b“);
Groovy:URLEncoder.encode ‘a b‘
15
© 2008 BearingPoint, Inc.
Groovy
GStrings
16
© 2008 BearingPoint, Inc.
Groovy
def name = “world“def message = “Hello ${name}“
17
© 2008 BearingPoint, Inc.
Groovy
def text = “““Ein längerer Stringmit Zeilenumbrüchen
“““
18
© 2008 BearingPoint, Inc.
Groovy
Native Lists, Maps, Regex
19
© 2008 BearingPoint, Inc.
Groovy
def aList = []
def myList = [22,55,33]
Lists
20
© 2008 BearingPoint, Inc.
Groovy
def emptyMap = [:]
def myMap = [“name“: “Max“, “age“ : “33“ ]
Maps
21
© 2008 BearingPoint, Inc.
Groovy
myMap.name == “Max“
myMap[“age“] == “33“
Maps
22
© 2008 BearingPoint, Inc.
Groovy
“cheesecheese“ =~ “cheese“ “cheesecheese“ =~ /cheese/
“potatoe“ ==~ /potatoe?/ “potato“ ==~ /potatoe?/
Regular Expressions
23
© 2008 BearingPoint, Inc.
Groovy
Loopsfor (int i=0;i<6;i++) {}
for (i in 0..9) {}
def list = [1, 2, 3]for (i in list) {}
10.times {}
24
© 2008 BearingPoint, Inc.
Groovy
Closures
def myClosure = { /* do something */}
25
© 2008 BearingPoint, Inc.
Groovy
[3,1,2].each { print “value:“+it}
26
© 2008 BearingPoint, Inc. 26
Groovy
Buildersdef xml = new groovy.xml.MarkupBuilder()
xml.authors {
author(name:‘Stephen King‘) {
book(title:‘The Shining‘)
book(title:‘The Stand‘)
}
author(name:‘James Patterson‘) {
book(title:‘Along Came a Spider‘)
}
}
27
© 2008 BearingPoint, Inc. 27
Groovy
Builders<authors>
<author name=“Stephen King“>
<book title=“The Shining“ />
<book title=“The Stand“ />
</author>
<author name=“James Patterson“>
<book title=“Along Came a Spider“ />
<author>
<authors>
28
© 2008 BearingPoint, Inc.
Groovy
The Groovy Truth
if (myString != null && myString.length() > 0) {myMethod(myString);}
if (myString) myMethod(myString)
29
© 2008 BearingPoint, Inc.
Groovy
Save DereferencingLong id=null;if (session.getAttribute(“user“) != null) {id = ((User) session.getAttribute(“user“)).getId();}
def id = session.user?.id
30
© 2008 BearingPoint, Inc.
Groovy
Meta Class Concept
31
© 2008 BearingPoint, Inc. 31
Groovy
IDE Integration
32
© 2008 BearingPoint, Inc.
Groovy
Domain Specific Language (DSL)
33
© 2008 BearingPoint, Inc.
Groovy
Java:public class RecursiveFileReading {
public static void main(String[] args) { printAllFiles(new File(".")); } public static final void printAllFiles(File root) { File[] allChildren = root.listFiles(); for (File child : allChildren) { if (child.isDirectory()) { RecursiveFileReading.printAllFiles(child); } else { System.out.println(child.toString()); } } }}
34
© 2008 BearingPoint, Inc.
Groovy
Groovy:groovy -e “new File(‘.‘).eachFileRecurse { println it }“
35
© 2008 BearingPoint, Inc.
Groovy
„There is a value for learning Groovy for its own sake. It will open your mind...“
Grails
37
© 2008 BearingPoint, Inc.
Grails
Rapid Application Develoment(RAD)
38
© 2008 BearingPoint, Inc.
Grails
Full Stack Framework
39
© 2008 BearingPoint, Inc.
Grails
Convention Over Configuration(CoC)
40
© 2008 BearingPoint, Inc.
Grails
RESTfullRepresentational State Transfer
41
© 2008 BearingPoint, Inc.
Grails
GET
42
© 2008 BearingPoint, Inc.
Grails
POST
43
© 2008 BearingPoint, Inc.
Grails
PUT
44
© 2008 BearingPoint, Inc.
Grails
DELETE
45
© 2008 BearingPoint, Inc.
Grails
HEAD
46
© 2008 BearingPoint, Inc.
Grails
OPTIONS
47
© 2008 BearingPoint, Inc.
Grails
http://localhost:8080/application/user/profile/123
Controller IDAction
RESTfull
48
© 2008 BearingPoint, Inc.
Grails
DRY Paradigm(Don‘t Repeat Yourself)
49
© 2008 BearingPoint, Inc.
Grails
Leverages existing hardware
Leverages existing Java/Framework knowledge
50
© 2008 BearingPoint, Inc.
Grails
Components
Java Virtual Machine
Java Language
Java EE
JDK
Grails
51
© 2008 BearingPoint, Inc.
Grails
UI, AJAX & RIA Frameworks
GWTYUI
52
© 2008 BearingPoint, Inc.
Grails
Plugin API JSF
Struts
JMS
ACEGI/Spring Security, JSecurity
OpenID
Functional Testing (Canoo WebTest)
Apache Axis 2, XFire
53
© 2008 BearingPoint, Inc.
Grails
GORMGroovy Object-Relational Mapping
54
class Book { String title}
© 2008 BearingPoint, Inc.
Grails
GORM
55
class Book {String author String title Date releaseDate
static constraints = { author(blank:false, size:2..30) releaseDate(nullable: true) }
}
© 2008 BearingPoint, Inc.
Grails
GORM
56
def book = new Book()
book.author = “author A“book.title = “title 1“
book.save()
© 2008 BearingPoint, Inc.
Grails
GORM
57
def book = new Book()
book.author = “author A“book.title = “title 1“
if (book.save()) {/* successfull flow */} else {/* error flow */}
© 2008 BearingPoint, Inc.
Grails
GORM
58
© 2008 BearingPoint, Inc.
Grails
(Dynamic) Finders
def macBook = Book.get(1)
def macBook = Book.findByTitle(“MacBook“)
def macBook = Book.findByTitleAndAuthor(“MacBook“, “Apple“)
59
<h1>Book list</h1><table> <tr> <th>Title</th> <th>Author</th> </tr><g:each in="${books}"> <tr> <td>${it.title}</td>
<td>${it.author}</td> </tr>
</g:each> </table>
© 2008 BearingPoint, Inc.
Grails
Groovy Server Pages (GSP)
60
<g:if test="${name == 'fred'}"> Hello Fred!</g:if><g:else> Hello ${name}! Do I know you?</g:else>
© 2008 BearingPoint, Inc.
Grails
Groovy Server Pages (GSP)
61
<g:datePicker name="myDate" value="${new Date()}"
precision="day" years="${1930..1970}"/>
© 2008 BearingPoint, Inc.
Grails
Groovy Server Pages (GSP)
62
© 2008 BearingPoint, Inc.
Grails
Scaffolding
Dynamic Scaffolding
Static Scaffolding
63
© 2008 BearingPoint, Inc.
Grails
How does it look like?
64
© 2008 BearingPoint, Inc.
Grails
Success Stories?
65
© 2008 BearingPoint, Inc.
Grails
66
© 2008 BearingPoint, Inc.
Grails
67
© 2008 BearingPoint, Inc.
Grails
68
© 2008 BearingPoint, Inc.
Grails
69
© 2008 BearingPoint, Inc.
Grails
http://groovy.codehaus.org/
http://www.grails.org
70
© 2008 BearingPoint, Inc.
Grails
Dirk König - Groovy In ActionManning, 2007
Graeme Keith Rocher - The Definitive Guide To GrailsApress, 2006