use groovy&grails in your spring boot projects

46
La importancia de un buen título en presentaciones Use Groovy & Grails in your Spring Boot projects, don't be afraid! @fatimacasau

Upload: paradigma-tecnologico

Post on 18-Jul-2015

386 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Use Groovy & Grails in your Spring Boot projects, don't be afraid!

@fatimacasau

Page 2: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Fátima Casaú Pérez

Software Engineer for over 7 years ago

Java Architect & Scrum Master in Paradigma Tecnológico

Specialized in Groovy & Grails environments

Recently, Spring Boot world

@fatimacasau

Use Groovy & Grails in your Spring Boot projects, don't be afraid!@fatimacasau

Page 3: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

What is Spring Boot?

What is Groovy?

Where could you use Groovy in your Spring Boot Projects?● Gradle● Tests● Groovy Templates● Anywhere?● GORM● GSP’s

Overview

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 4: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Spring Boot

Use Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 5: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Standalone

Auto-configuration - CoC

No XML

Embedded Container and Database

Bootstrapping

Groovy!!

Run quickly - Spring Boot CLI

projects.spring.io/spring-boot

Spring Boot

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 6: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Spring Boot application in a single tweet

DEMO...

Page 7: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

GVM

gvmtool.net

> gvm install springboot

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 8: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

HelloWorld.groovy

1  @Controller2  class ThisWillActuallyRun {3     @RequestMapping("/")4     @ResponseBody5     String home() {6         "Hello World!"7     }8  }

Page 9: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Groovy

Use Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 10: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Dynamic language

Optionally typed

@TypeChecked & @CompileStatic

Java Platform

Easy & expressive syntax

Powerful featuresclosures, DSL, meta-programming, functional programming, scripting, ...

Groovy

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 11: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Where could you use Groovy?

Use Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 12: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Gradle

Use Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 13: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Powerful build tool

Support multi-project

Dependency management (based on Apache Ivy)

Support and Integration with Maven & Ivy repositories

Based on Groovy DSL

Build by convention

Ant tasks

Gradle

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 14: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Building a Spring Boot application with Gradle

DEMO...

Page 15: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

GVM

> gvm install gradle> gradle build> gradle tasks

Page 16: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

build.gradle

1  buildscript {2     repositories {3         mavenCentral()4     }5     dependencies {6         classpath("org.springframework.boot:spring­boot­gradle­plugin:1.2.2.RELEASE")7     }8  }9  10  apply plugin: 'groovy'11  apply plugin: 'idea'12  apply plugin: 'spring­boot'13  14  jar {15      baseName = 'helloworld'16      version = '0.1.0'17  }18  19  repositories {20      mavenCentral()21  }22  23  dependencies {24      compile("org.springframework.boot:spring­boot­starter­web")25  }

Page 17: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Testing with Spock

Use Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 18: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Spock framework & specification

Expressive

Groovy DSL’s

Easy to read tests

Well documented

Powerful assertions

Testing with Spock

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 19: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Testing with Spock

DEMO...

Page 20: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

GoogleSpec.groovy

1 void "test Google Maps API where address is ‘Madrid’"(){2    setup: “Google Maps API Host & Uri” 3        def rest = new RESTClient("https://maps.googleapis.com")4        def uri = "/maps/api/geocode/json"5    when: “Call the API with address = ‘madrid’”6        def result = rest.get(path: uri, query: [address:'madrid'])7    then: “HttpStatus is OK, return a list of results and field status = OK”8        result9        result.status == HttpStatus.OK.value()10        !result.data.results.isEmpty()11        result.data.status == ‘OK’12        result.data.toString().contains('Madrid')        13  }

Page 21: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

GoogleSpec.groovy

1 void "test Google Maps API with different values"(){2    setup: “Google Maps API Host & Uri”3      def rest = new RESTClient("https://maps.googleapis.com")4      def uri = "/maps/api/geocode/json"5    expect: “result & status when call the REST API”6      def result = rest.get(path: uri, query: [address:address])7      resultsIsEmpty == result.data.results.isEmpty()8      result.data.status == status9    where: “address takes different values with different results & status”10      address | resultsIsEmpty | status11      'Madrid'| false          | 'OK'12      'abdkji'| true           | 'ZERO_RESULTS'13      '186730'| false          | 'ZERO_RESULTS' // This fails!14         15  }

Page 22: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

Assertion failed:  

assert      resultsIsEmpty == result.data.results.isEmpty()

        |               |    |      |     |       |            false           false       |     |       true                                 |      |     [...]                                 |      |                                 |      ...                                 ...

docs.spockframework.org

Page 23: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Groovy templates

Use Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 24: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Groovy Template Framework

Based MarkupBuilder

Groovy DSL’s

Render readable views

Replace variables easily

Groovy templates

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 25: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Groovy Templates

DEMO...

Page 26: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

1 ul {2    people.each { p ­>3       li(p.name)4    }5 }

With the following model

6 def model = [people: [7                        new Person(name:'Bob'), 8                        new Person(name:'Alice')9              ]]

Renders the following

10 <ul><li>Bob</li><li>Alice</li></ul>

Page 27: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Anywhere!

Use Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 28: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Anywhere

Mix Java & Groovy easily

More expressive, simple & flexible than Java

Extension of JDK -> GDK

@CompileStatic @TypeChecked

Controllers, Services, Model,...

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 29: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Groovy Controller

DEMO...

Page 30: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

HelloWorld.groovy

 1  2 @Controller 3 class ThisWillActuallyRun { 4    @RequestMapping("/") 5    @ResponseBody 6    String home() { 7        "Hello World!" 8    } 9 }

@groovy.transform.CompileStatic

Page 31: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

GORM

Use Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 32: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Automatic mapping for entities

Dynamic finders, criterias, persistence methods, validation, mappings, constraints…

Expressive and simple code

implicit getters & setters

implicit constructors

implicit primary key

For Hibernate

For MongoDB

GORM: Grails Object Relational Mapping

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 33: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

GORM for Hibernate

DEMO...

Page 34: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

Customer.groovy

1 @Entity2 public class Customer {34     String firstName;5     String lastName;67     static constraints = {8         firstName blank:false9         lastName blank:false10     }11     static mapping = {12         firstName column: 'first_name'13         lastName column: 'last_name'14     }15 }

Page 35: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

1  [[firstName:"Jack", lastName:"Bauer"],2   [firstName:"Michelle", lastName:"Dessler"]].each {3       new Customer(it).save()4  }5 6  def customers = Customer.findAll()7 8  customers.each {9     println it10 }11 12 def customer = Customer.get(1L)13 14 customers = Customer.findByLastName("Bauer")15 customers.each {println it}

Page 36: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

GSP's

Use Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 37: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Groovy Server Pages is used by Grails

Large list of useful Tag Libraries

Easy to define new Tags

Not only viewsLayouts & Templates

Reuse Code

GSP's: Groovy Server Pages

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 38: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

GSP's in Spring Boot

DEMO...

Page 39: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

1 <g:if test="${session.role == 'admin'}">2    <%­­ show administrative functions ­­%>3 </g:if>4 <g:else>5    <%­­ show basic functions ­­%>6 </g:else>

___________________________________________________________________ 1  <g:each in="${[1,2,3]}" var="num"> 2     <p>Number ${num}</p> 3  </g:each>

___________________________________________________________________1 <g:findAll in="${books}" expr="it.author == 'Stephen King'">2      <p>Title: ${it.title}</p>3 </g:findAll>

___________________________________________________________________1  <g:dateFormat format="dd­MM­yyyy" date="${new Date()}" />

___________________________________________________________________1  <g:render template="bookTemplate" model="[book: myBook]" />

Page 40: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Conclusions

Use Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 41: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

If you use Groovy…

Less code

More features

Cool Tests

Cool utilities

Why not? Please try to use Groovy!

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 42: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

One moment...

Page 43: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

MVC Spring based Apps

Convention Over Configuration

Bootstrapping

Groovy

GORM

GSP’s ...

It's sounds like Grails!

@fatimacasauUse Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 44: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Why do you not use Grails?

Use Groovy & Grails in your Spring Boot projects, don't be afraid!

Page 45: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

Thanks!!@fatimacasau

Page 46: Use Groovy&Grails in your spring boot projects

La importancia de un buen título en presentaciones

We are hiring!JEE, Python, PHP, MongoDB, Cassandra, Big Data, Scala, NoSQL, AngularJS, Javascript,

iOS, Android, HTML, CSS3… and Commitment, Ping Pong, Arcade… SEND US YOUR CV