SlideShare une entreprise Scribd logo
Grails, from scratch to prod

… plus vite !



!"#$%&"'()*+,-&            12+3,().)2(%0+&-+#/(%01)
!"#$%&'(#')*+,-()          4+-5,67-).)678.99504&-#:+;-#4<"/9-#9(%0+&-+#/(%01)
./0+*).)(/(%0123+,-(450)   8*9:&.)678.99,&"=43+,-(450)
Grails from scratch to prod - MixIT 2011
Qu'est-ce que Grails ?
Qu'est-ce que Grails ?
!  Framework d'application web complet
   !  MVC, basé sur le langage Groovy


!  Inspiré de RoR, Django, TurboGears
    !  Adapté à la culture Java


!  Bâti sur le roc
   !  Stack éprouvée : Spring, Hibernate, Tomcat
Buts
!  Pile application web Java standard
   !  Fournir un niveau d'abstraction en plus


!  Réduire la complexité
   !  En outillant l'existant


!  Augmenter la productivité
   !  En scriptant les tâches répétitives
Approche
!  Convention over configuration
   !  Principe de "défaut raisonnable"


!  Don't repeat yourself
   !  Structure imposée pour réduire les duplications


!  Plateforme complète
   !  Méthodologie et approche fournies
Histoire
!  Janvier 2007
    !  Sortie de Groovy 1.0


!  Février 2008
   !  Sortie de Grails 1.0


!  Novembre 2008
   !  SpringSource rachète G2One
Rock Stars
!  Guillaume Laforge (@glaforge)
   !  Leader Groovy chez SpringSource




!  Graeme Rocher (@graemerocher)
   !  Leader Grails chez SpringSource
Comment ça marche ?
Plateforme complète
Simplifié par Groovy
!  Syntaxe allégée
   !  Accessible à tous les développeurs Java


!  Closures, Collections, Gpars, …
   !  L'essayer c'est l'adopter


!  Scripts de génération de code
   !  Facilement extensible
Développement rapide
                         ?+$')




                  @-3)           !";+)




 <0+('+)   0%#)                          >(0)
Support IDE
!  Intellij IDEA



!  Eclipse STS



!  Netbeans
$ grails create-app bookstore
Structure d'un projet
bookstore!
|_grails-app!
| !|_conf       !   !=> BootStraping, Datasources, UrlMappings!
| !|_controllers!
| !|_domain!
| !|_i18n       !   !=> messages.properties internationalisés!
| !|_services!
| !|_taglib!
| !|_utils!
| !|_views      !   !=> Groovy Server Pages!
|_lib   !       !   !=> Dépendances Java!
|_scripts!
|_src!
| !|_groovy!
| !|_java!
|_test!
|_web-app       !   !=> Ressources statiques: images, JS, CSS, etc!
Scaffolding
!  Génération de CRUD à partir des entités
   !  Economie de temps


!  Popularisé par Ruby on Rails
   !  Orienté schéma base de données


!  Adopté par Grails
   !  Orienté domaine
Scaffolding
!  grails create-domain-class


!  grails create-controller


!  grails create-service


!  grails generate-all
Scaffolding
Scaffolding
!  grails generate-all org.bookstore.Book
    !  BookController
    !  BookControllerTest
    !  grails-app/views/book/list.gsp
    !  grails-app/views/book/show.gsp
    !  grails-app/views/book/edit.gsp
    !  grails-app/views/book/create.gsp
Scaffolding dynamique
class BookController {   class BookController {
 def index = {…}          def scaffold = true
 def list = {…}          }
 def create = {…}
 def save = {…}
 def show = {…}
 def edit = {…}
 def update = {…}
 def delete = {…}
}
GORM : Mapping
class Book {
  String title
  static belongsTo = [author: Author]
  static hasMany = [chapters: Chapters]
  static constraints = {
      title nullable:false
  }
}
GORM : Requêtage
Book.list(sort: 'title', order: 'asc')
Book.getAll(37, 41, 43)
Book.findByTitleLike("Harry P%")
Book.withCriteria {
  eq('title', 'Harry Potter')
  author {
     like('Rowli%')
  }
}
GORM : Requêtage
class Book {
  static namedQueries = {
     withPotterInTitle {
           like 'title', '%Potter%'
     }
  }
}
Book.withPotterInTitle.list()
Vues
!  Groovy Server Pages
   !  HTML + Taglib groovy


!  Assemblage par Sitemesh
   !  Commandé par tags GSP


!  Taglib Grails (Prototype pour le JS)
    !  Formulaires, AJAX
Vues : exemples
<g:formRemote name="myForm"
       on404="alert('not found!')"
       update="updateMe"           // onSuccess="jsFunc"
       url="[action:'show']">
Login: <input name="login" type="text"></input>
</g:formRemote>

<div id="updateMe">this div is updated by the form</div>

!  fieldRemote, remoteFunction
Vues : exemples
<g:each var="book" in="${books}">

  <p>Title: ${book.title}</p>
  <p>Author: ${book.author}</p>

</g:each>

!  if, else, formatDate, sortableColumn, datePicker,
  …
Contrôleurs
!  grails create-controller org.bookstore.Book
    !  Génère un contrôlleur coquille


!  Injection de dépendance
    !  def leNomDeMonService en attribut de classe


!  Helpers
   !  render as JSON, render as XML
Contrôleurs : exemple
class AuthorController {
  def springSecurityService

    def list = {
       [ authorInstanceList: Author.list(),
         authorInstanceTotal: Author.count() ]
    }
}
Configuration : dépendances
grails.project.dependency.resolution = {
  repositories {
    grailsPlugins()
    grailsHome()
    grailsCentral()
    mavenLocal()
    mavenCentral()
    mavenRepo "http://snapshots.repository.codehaus.org"
  }
  dependencies {
    runtime 'mysql:mysql-connector-java:5.1.13'
  }
}
Configuration : environnements
environments {
   development {
     dataSource {
         dbCreate = "create-drop"
         url = "jdbc:hsqldb:mem:devDB" } }
  test { dataSource { … } }
  production { dataSource { … } }
}
Environnements
!  grails run-app     => dev

!  grails test run-app => test


!  grails test-app    => test

!  grails war         => production
Extensible
!  Dépôt de plugins centralisé
!  grails install-plugin …
    !  spring-security-core
    !  spring-security-ui
    !  quartz
    !  codenarc
    !  mongodb
    !  spock
    !  …
Très extensible
  !  app-engine    (GORM en mode JPA)

  !  groovy-plus-plus
  !  jquery
  !  searchable
  !  gwt
  !  feeds
  !  birt-report
  !  …
!  ou : grails create-plugin monPlugin
Extensible
!  Plugin Grails == Application Grails
Questions fréquemment posées
Intégration continue ?
Est-ce performant ?
!  Overhead Groovy : x5-7
   !  Utilisez Groovy++ (x3-5)


!  Productivité contre vitesse d'exécution
   !  Pas de compile check ? Pas grave.


!  Optimisations Java
   !  "src/java" ou librairies
Et la courbe d'apprentissage ?
!  Groovy s'apprend vite
   !  Bases ~ 2 jours, Courant ~ 1 mois


!  Pièges, GORM Gotchas
   !  Dans l'ensemble, rien ne bloque longtemps


!  Au delà de la carrosserie
   !  Sur le Tao de Grails, la stack tu maîtriseras
La communauté est-elle active ?
!  7 versions mineures en 1 an


!  ~ 60 Users Group sur la planète


!  ~ 800 repository GitHub autour de Grails


!  ~ 2500 mails par mois sur les ML
Y a-t-il du support ?
Dans quels cas utiliser Grails ?
!  Minimum Viable Product rapide
  !  Du prototype au produit en douceur



!  Reprise d'une application existante
  !  IHM Web rapide, intégration existant en librairie



!  Tout nouveau projet d'appli web
  !  En toute simplicité "
Success stories
Bibliothèque
Linkothèque
!  Groovy home
   !  http://groovy.codehaus.org/
!  Grails home
   !  http://www.grails.org
!  Grails plugins
   !  http://www.grails.org/plugins/
!  An army of solipsists (this week in Grails)
   !  http://burtbeckwith.com/blog/
Questions ?
Merci à tous
       et bon appétit

Contenu connexe

ODP
Réu technodejs
PDF
Votre mission ? Découvrir Haskell et le mettre en prod
PDF
Tout ce que le getting started mongo db ne vous dira pas
PPT
Présentation jQuery pour débutant
PDF
MongoDB : la base NoSQL qui réinvente la gestion de données
PDF
Breizhcamp : Guide de survie du développeur dans une application (Java) qui rame
PDF
Les données transitoires (transients) vous veulent du bien
PPTX
Initiation à Express js
Réu technodejs
Votre mission ? Découvrir Haskell et le mettre en prod
Tout ce que le getting started mongo db ne vous dira pas
Présentation jQuery pour débutant
MongoDB : la base NoSQL qui réinvente la gestion de données
Breizhcamp : Guide de survie du développeur dans une application (Java) qui rame
Les données transitoires (transients) vous veulent du bien
Initiation à Express js

Tendances (19)

PPT
KEY
Paris RailsCamp 2009
PDF
Jquery - introduction au langage
PDF
Tout ce que le getting started mongodb ne vous dira pas
PDF
jQuery
PDF
Introduction a jQuery
PPTX
MUG Nantes - MongoDB et son connecteur pour hadoop
PDF
Conférence #nwx2014 - Thibaud Juin - Varnish, accélérateur web
PPT
Dynamic Languages
KEY
Hands on lab Elasticsearch
KEY
Cascalog présenté par Bertrand Dechoux
PDF
Migrer une application existante vers Elasticsearch - Nuxeo Tour 2014 - workshop
KEY
Elasticsearch - OSDC France 2012
KEY
Lyon JUG - Elasticsearch
PDF
MongoDB et Elasticsearch, meilleurs ennemis ?
PDF
Jquery
PDF
KEY
Elasticsearch - Montpellier JUG
PDF
Paris data geek - Elasticsearch
Paris RailsCamp 2009
Jquery - introduction au langage
Tout ce que le getting started mongodb ne vous dira pas
jQuery
Introduction a jQuery
MUG Nantes - MongoDB et son connecteur pour hadoop
Conférence #nwx2014 - Thibaud Juin - Varnish, accélérateur web
Dynamic Languages
Hands on lab Elasticsearch
Cascalog présenté par Bertrand Dechoux
Migrer une application existante vers Elasticsearch - Nuxeo Tour 2014 - workshop
Elasticsearch - OSDC France 2012
Lyon JUG - Elasticsearch
MongoDB et Elasticsearch, meilleurs ennemis ?
Jquery
Elasticsearch - Montpellier JUG
Paris data geek - Elasticsearch
Publicité

Similaire à Grails from scratch to prod - MixIT 2011 (20)

PPTX
Grails from scratch to prod - MixIT 2010
PPTX
Grails Un Framework Web Agile
PDF
ENIB 2013-2014 - CAI Web #3: J’ai besoin d’une appli web rapidement
PDF
Enib cours c.a.i. web - séance #5 - j’ai besoin d’une appli web rapidement !
PDF
Introduction à Groovy - OpenSource eXchange 2008
PPT
Présentation Groovy
PPT
Présentation Groovy
PDF
JUGL 2009 - Introduction Groovy/Grails
PDF
Introduction Groovy / Grails - Cyril Picat - December 2009
PDF
FinistJUG - J’ai besoin d’une appli web rapidement
PDF
YaJUG - Spring 3.0
PDF
tp-spring.pdf
PDF
tp-spring.pdf
PDF
Quelle place pour le framework Rails dans le développement d'application web
PPTX
Google appengine&guice
PDF
ENIB cours CAI Web - Séance 4 - Frameworks/Spring - Cours
PDF
ENIB 2013-2014 - CAI Web #3: Groovy
PPTX
Application de gestion des projets en J2EE (Spring-Hibernate) avec architectu...
PDF
Telosys tools jug-nantes-2014-v1.2
PDF
JUG Nantes - Telosys Tools - Avril 2014
Grails from scratch to prod - MixIT 2010
Grails Un Framework Web Agile
ENIB 2013-2014 - CAI Web #3: J’ai besoin d’une appli web rapidement
Enib cours c.a.i. web - séance #5 - j’ai besoin d’une appli web rapidement !
Introduction à Groovy - OpenSource eXchange 2008
Présentation Groovy
Présentation Groovy
JUGL 2009 - Introduction Groovy/Grails
Introduction Groovy / Grails - Cyril Picat - December 2009
FinistJUG - J’ai besoin d’une appli web rapidement
YaJUG - Spring 3.0
tp-spring.pdf
tp-spring.pdf
Quelle place pour le framework Rails dans le développement d'application web
Google appengine&guice
ENIB cours CAI Web - Séance 4 - Frameworks/Spring - Cours
ENIB 2013-2014 - CAI Web #3: Groovy
Application de gestion des projets en J2EE (Spring-Hibernate) avec architectu...
Telosys tools jug-nantes-2014-v1.2
JUG Nantes - Telosys Tools - Avril 2014
Publicité

Dernier (7)

PDF
FORMATION COMPLETE EN EXCEL DONE BY MR. NYONGA BRICE.pdf
PDF
Modems expliqués- votre passerelle vers Internet.pdf
PDF
presentation_with_intro_compressee IEEE EPS France
PPTX
Souveraineté numérique - Définition et enjeux pour les entreprises et les dév...
PDF
FORMATION EN Programmation En Langage C.pdf
PDF
Tendances tech 2025 - SFEIR & WENVISION.pdf
PPTX
Presentation_Securite_Reseaux_Bac+2.pptx
FORMATION COMPLETE EN EXCEL DONE BY MR. NYONGA BRICE.pdf
Modems expliqués- votre passerelle vers Internet.pdf
presentation_with_intro_compressee IEEE EPS France
Souveraineté numérique - Définition et enjeux pour les entreprises et les dév...
FORMATION EN Programmation En Langage C.pdf
Tendances tech 2025 - SFEIR & WENVISION.pdf
Presentation_Securite_Reseaux_Bac+2.pptx

Grails from scratch to prod - MixIT 2011

  • 1. Grails, from scratch to prod … plus vite ! !"#$%&"'()*+,-& 12+3,().)2(%0+&-+#/(%01) !"#$%&'(#')*+,-() 4+-5,67-).)678.99504&-#:+;-#4<"/9-#9(%0+&-+#/(%01) ./0+*).)(/(%0123+,-(450) 8*9:&.)678.99,&"=43+,-(450)
  • 4. Qu'est-ce que Grails ? !  Framework d'application web complet !  MVC, basé sur le langage Groovy !  Inspiré de RoR, Django, TurboGears !  Adapté à la culture Java !  Bâti sur le roc !  Stack éprouvée : Spring, Hibernate, Tomcat
  • 5. Buts !  Pile application web Java standard !  Fournir un niveau d'abstraction en plus !  Réduire la complexité !  En outillant l'existant !  Augmenter la productivité !  En scriptant les tâches répétitives
  • 6. Approche !  Convention over configuration !  Principe de "défaut raisonnable" !  Don't repeat yourself !  Structure imposée pour réduire les duplications !  Plateforme complète !  Méthodologie et approche fournies
  • 7. Histoire !  Janvier 2007 !  Sortie de Groovy 1.0 !  Février 2008 !  Sortie de Grails 1.0 !  Novembre 2008 !  SpringSource rachète G2One
  • 8. Rock Stars !  Guillaume Laforge (@glaforge) !  Leader Groovy chez SpringSource !  Graeme Rocher (@graemerocher) !  Leader Grails chez SpringSource
  • 11. Simplifié par Groovy !  Syntaxe allégée !  Accessible à tous les développeurs Java !  Closures, Collections, Gpars, … !  L'essayer c'est l'adopter !  Scripts de génération de code !  Facilement extensible
  • 12. Développement rapide ?+$') @-3) !";+) <0+('+) 0%#) >(0)
  • 13. Support IDE !  Intellij IDEA !  Eclipse STS !  Netbeans
  • 14. $ grails create-app bookstore
  • 15. Structure d'un projet bookstore! |_grails-app! | !|_conf ! !=> BootStraping, Datasources, UrlMappings! | !|_controllers! | !|_domain! | !|_i18n ! !=> messages.properties internationalisés! | !|_services! | !|_taglib! | !|_utils! | !|_views ! !=> Groovy Server Pages! |_lib ! ! !=> Dépendances Java! |_scripts! |_src! | !|_groovy! | !|_java! |_test! |_web-app ! !=> Ressources statiques: images, JS, CSS, etc!
  • 16. Scaffolding !  Génération de CRUD à partir des entités !  Economie de temps !  Popularisé par Ruby on Rails !  Orienté schéma base de données !  Adopté par Grails !  Orienté domaine
  • 17. Scaffolding !  grails create-domain-class !  grails create-controller !  grails create-service !  grails generate-all
  • 19. Scaffolding !  grails generate-all org.bookstore.Book !  BookController !  BookControllerTest !  grails-app/views/book/list.gsp !  grails-app/views/book/show.gsp !  grails-app/views/book/edit.gsp !  grails-app/views/book/create.gsp
  • 20. Scaffolding dynamique class BookController { class BookController { def index = {…} def scaffold = true def list = {…} } def create = {…} def save = {…} def show = {…} def edit = {…} def update = {…} def delete = {…} }
  • 21. GORM : Mapping class Book { String title static belongsTo = [author: Author] static hasMany = [chapters: Chapters] static constraints = { title nullable:false } }
  • 22. GORM : Requêtage Book.list(sort: 'title', order: 'asc') Book.getAll(37, 41, 43) Book.findByTitleLike("Harry P%") Book.withCriteria { eq('title', 'Harry Potter') author { like('Rowli%') } }
  • 23. GORM : Requêtage class Book { static namedQueries = { withPotterInTitle { like 'title', '%Potter%' } } } Book.withPotterInTitle.list()
  • 24. Vues !  Groovy Server Pages !  HTML + Taglib groovy !  Assemblage par Sitemesh !  Commandé par tags GSP !  Taglib Grails (Prototype pour le JS) !  Formulaires, AJAX
  • 25. Vues : exemples <g:formRemote name="myForm" on404="alert('not found!')" update="updateMe" // onSuccess="jsFunc" url="[action:'show']"> Login: <input name="login" type="text"></input> </g:formRemote> <div id="updateMe">this div is updated by the form</div> !  fieldRemote, remoteFunction
  • 26. Vues : exemples <g:each var="book" in="${books}"> <p>Title: ${book.title}</p> <p>Author: ${book.author}</p> </g:each> !  if, else, formatDate, sortableColumn, datePicker, …
  • 27. Contrôleurs !  grails create-controller org.bookstore.Book !  Génère un contrôlleur coquille !  Injection de dépendance !  def leNomDeMonService en attribut de classe !  Helpers !  render as JSON, render as XML
  • 28. Contrôleurs : exemple class AuthorController { def springSecurityService def list = { [ authorInstanceList: Author.list(), authorInstanceTotal: Author.count() ] } }
  • 29. Configuration : dépendances grails.project.dependency.resolution = { repositories { grailsPlugins() grailsHome() grailsCentral() mavenLocal() mavenCentral() mavenRepo "http://snapshots.repository.codehaus.org" } dependencies { runtime 'mysql:mysql-connector-java:5.1.13' } }
  • 30. Configuration : environnements environments { development { dataSource { dbCreate = "create-drop" url = "jdbc:hsqldb:mem:devDB" } } test { dataSource { … } } production { dataSource { … } } }
  • 31. Environnements !  grails run-app => dev !  grails test run-app => test !  grails test-app => test !  grails war => production
  • 32. Extensible !  Dépôt de plugins centralisé !  grails install-plugin … !  spring-security-core !  spring-security-ui !  quartz !  codenarc !  mongodb !  spock !  …
  • 33. Très extensible !  app-engine (GORM en mode JPA) !  groovy-plus-plus !  jquery !  searchable !  gwt !  feeds !  birt-report !  … !  ou : grails create-plugin monPlugin
  • 34. Extensible !  Plugin Grails == Application Grails
  • 37. Est-ce performant ? !  Overhead Groovy : x5-7 !  Utilisez Groovy++ (x3-5) !  Productivité contre vitesse d'exécution !  Pas de compile check ? Pas grave. !  Optimisations Java !  "src/java" ou librairies
  • 38. Et la courbe d'apprentissage ? !  Groovy s'apprend vite !  Bases ~ 2 jours, Courant ~ 1 mois !  Pièges, GORM Gotchas !  Dans l'ensemble, rien ne bloque longtemps !  Au delà de la carrosserie !  Sur le Tao de Grails, la stack tu maîtriseras
  • 39. La communauté est-elle active ? !  7 versions mineures en 1 an !  ~ 60 Users Group sur la planète !  ~ 800 repository GitHub autour de Grails !  ~ 2500 mails par mois sur les ML
  • 40. Y a-t-il du support ?
  • 41. Dans quels cas utiliser Grails ? !  Minimum Viable Product rapide !  Du prototype au produit en douceur !  Reprise d'une application existante !  IHM Web rapide, intégration existant en librairie !  Tout nouveau projet d'appli web !  En toute simplicité "
  • 44. Linkothèque !  Groovy home !  http://groovy.codehaus.org/ !  Grails home !  http://www.grails.org !  Grails plugins !  http://www.grails.org/plugins/ !  An army of solipsists (this week in Grails) !  http://burtbeckwith.com/blog/
  • 46. Merci à tous et bon appétit