JUG Nantes - Telosys Tools - Avril 2014

67
Development accelerator ... ou comment faire un « départ lancé » un « départ lancé » JUG Nantes 14 avril 2014 Ver 1.2

Transcript of JUG Nantes - Telosys Tools - Avril 2014

Page 1: JUG Nantes - Telosys Tools - Avril 2014

Development

accelerator... ou comment faire

un « départ lancé »un « départ lancé »

JUG Nantes

14 avril 2014

Ver 1.2

Page 2: JUG Nantes - Telosys Tools - Avril 2014

Qui sommes nous ?

Laurent Guérin (Project Leader) @[email protected]

Benoit Wilcox (Commiter)@WilcoxBenoit

Ludovic Chaboud (Commiter) @ludovic_chaboud

Telosys Tools @telosys http://tools.telosys.org 2

@[email protected]

@[email protected]

Telosys Team

http://labs.sogeti.com/

Page 3: JUG Nantes - Telosys Tools - Avril 2014

Un parcours en 3 étapes

Telosys Tools @telosys http://tools.telosys.org 3

Page 4: JUG Nantes - Telosys Tools - Avril 2014

Principes Généraux

1

Telosys Tools @telosys http://tools.telosys.org 4

Page 5: JUG Nantes - Telosys Tools - Avril 2014

La juste part du développeur

Application

Framework 1 Framework 2

Code stéréotypé

& répétitif

Développeur Générateur

Telosys Tools @telosys http://tools.telosys.org 5

Plate-forme ( ie Java EE )

Comment réduire le volume de code à réaliser ?Frameworks & « boilerplate » � réduction du code technique

(code générique, « factorisable ») Mais il reste toujours une partie du code qui est spécifique et répétitive (et sans valeur ajoutée) La génération de code permet d’automatiser cette partie

Page 6: JUG Nantes - Telosys Tools - Avril 2014

• Model Driven Architecture (cf OMG)• Approche « Model First »

=> concevoir et maintenir un modèle(UML, DSL, …)

Génération de code - Approche « MDA »

MODELService

name

Port

name

0..n+port 0..nPort Type

nameBinding

name1

+binding

1

1

+type

1

Param

name

Output

Input

StartWithExtensions

BindingOperation

name

0..n+operation 0..n0..1 +input0..10..1+output 0..1

Operation

name0..1

+input

0..10..10..1

0..n+operation 0..n

11

X M I( XML )

Telosys Tools @telosys http://tools.telosys.org 6

Code

Part

name

Message

name

0..n+part 0..n

1+message 1

Output

BindingFaultFault

name1

+message

11

name

0..n

name 0..1+output

0..1

0..n+fault 0..n

11

1

+fault 0..n

Template TOOL

Processus lourd, ne permet pas un démarrage rapide

Page 7: JUG Nantes - Telosys Tools - Avril 2014

• Littéralement « échafaudage »• Définition Wikipedia : (incomplète)

• Largement utilisé dans certains écosystèmes

Génération de code - Approche « Scaffolding »

Scaffolding is a meta-programming method of building database-backed software applications.

Telosys Tools @telosys http://tools.telosys.org 7

• Largement utilisé dans certains écosystèmes– Ruby ( RoR - Ruby On Rails )– Groovy ( Grails – Groovy on Rails )

• Et pour Java?– Spring ROO (Boite noire, lié à Spring, AspectJ )– DALI / Eclipse (JPA mapping only)– AppFuse (command line + web)

Page 8: JUG Nantes - Telosys Tools - Avril 2014

• Approche « Database First »• Efficace (permet un démarrage rapide)• Outil de type « boite noire », généralement non adaptable

Génération de code - Approche « Scaffolding »

Database

TOOL

Code

Metadata

Telosys Tools @telosys http://tools.telosys.org 8

Pas de templates :- Comment personnaliser la génération de code ?

Pas de modèle :- Comment ajouter des informations (en + des méta-data) ?- Comment modifier (durablement) les méta-data ?

noms/types des attributs Java, règles de validation (min, max, regexp, …), représentation des Booléens (1/0, "T"/"F", … ), etc

Page 9: JUG Nantes - Telosys Tools - Avril 2014

Telosys Tools: une nouvelle approche

« Database first » scaffolding avec un modèle léger et des templates� ADAPTABLE

Telosys Tools @telosys http://tools.telosys.org 9

Page 10: JUG Nantes - Telosys Tools - Avril 2014

Philosophie

Keep it simple Keep it simple Keep it simple Keep it simple and pragmaticand pragmaticand pragmaticand pragmatic

Telosys Tools @telosys http://tools.telosys.org 10

Page 11: JUG Nantes - Telosys Tools - Avril 2014

Plugin

Code Generator

Environnement de travail : Eclipse + plugin + templates

Model Editor

Workspace

Community templates

GitHub

downloadtemplates

installplugin

Telosys Tools @telosys http://tools.telosys.org 11

Code GeneratorModel Editor

Template Editor

Database Editor

Model Generator

Page 12: JUG Nantes - Telosys Tools - Avril 2014

Que peut-on générer ?

Tout fichier de type « texte » : Java, XML, JSP, PHP, Scala, JavaScript, HTML, etc…

Principe :

1 entity N templates N targets

1 bean

Telosys Tools @telosys http://tools.telosys.org 12

N entities 1 template 1 target

model(all entitieswith links)

1 controller

1 web page

1 list

Page 13: JUG Nantes - Telosys Tools - Avril 2014

Ça ressemble à quoi un template ?

http://velocity.apache.org/

Objets du model« entities »

Velocity Template Language (VTL) • Références aux objets : $, ${…}• Directives : #set, #if, #foreach, …• Commentaire : ## #* .. *#

Telosys Tools @telosys http://tools.telosys.org 13

Objets de l’environnement

Page 14: JUG Nantes - Telosys Tools - Avril 2014

Ce n’est pas magique

� Ne pas chercher à tout générer (il faut savoir s’arrêter)

code codegénéré non généré

Application

Code stéréotypé

& répétitif

Telosys Tools @telosys http://tools.telosys.org 14

� Estimer le gain de productivité

Page 15: JUG Nantes - Telosys Tools - Avril 2014

Démo1

Telosys Tools @telosys http://tools.telosys.org 15

Page 16: JUG Nantes - Telosys Tools - Avril 2014

AngularJSSpring MVC – JPA

2

Telosys Tools @telosys http://tools.telosys.org 16

Page 17: JUG Nantes - Telosys Tools - Avril 2014

• Fonctionnalités de CRUD : – Création, Recherche, Modification, Suppression d’entités

• Internationalisation (i18n) :– Libellés français / anglais– Gestion des dates

Fonctionnalités

Telosys Tools @telosys http://tools.telosys.org 17

Page 18: JUG Nantes - Telosys Tools - Avril 2014

Architecture générale

Tomcat Server

Webapp

Spring MVC + JPA

bookstore-

spring

2 Projets

Telosys Tools @telosys http://tools.telosys.org 18

Base de données relationnelle

Spring MVC + JPA

Webapp

AngularJS

spring

bookstore-

angularjs

Page 19: JUG Nantes - Telosys Tools - Avril 2014

Application 1 :

Spring MVC+

Spring MVC + AngularJS

Telosys Tools @telosys http://tools.telosys.org 19

+Spring Data JPA

Page 20: JUG Nantes - Telosys Tools - Avril 2014

Application 1

Spring MVC + Spring Data JPA

Base de donnéesrelationnelle

JPA

Spring

Data JPA

Spring

MVC

Web REST

Telosys Tools @telosys http://tools.telosys.org 20

Utilisateur

Page 21: JUG Nantes - Telosys Tools - Avril 2014

Spring MVC + Spring Data JPA

Présentation

Spring MVC

Service

JPA

Persistance

Spring

3 couches

Telosys Tools @telosys http://tools.telosys.org 21

Contrôleurs

Pages WebService DAO

Page 22: JUG Nantes - Telosys Tools - Avril 2014

Points de vigilance sur JPA (Java Persistence API)

Spring MVC + Spring Data JPA

Présentation

Spring MVC

Service

JPA

Persistance

Spring

Telosys Tools @telosys http://tools.telosys.org 22

Contrôleurs

Pages WebService DAO

Page 23: JUG Nantes - Telosys Tools - Avril 2014

Points de vigilance sur JPA (Java Persistence API)

• Concepts mal maîtrisés voir inconnus des développeu rs– Session Hibernate / Entity Manager :

• Objets « attachés » et « détachés »• Mise à jour différée de la base de données

– Règles de persistance des liens entre les objets• Notion « owning side » et « inverse side »

Spring MVC + Spring Data JPA

Telosys Tools @telosys http://tools.telosys.org 23

• Notion « owning side » et « inverse side »• Problème de performances

– Chargement à la volée : • problème du « N+1 requêtes »• Erreurs techniques si l’objet est « détaché »

• Comportements masqués et objets « pollués »– Chargement à la volée :

• Utilisation d’objets « proxy » et de collections « proxy »

Page 24: JUG Nantes - Telosys Tools - Avril 2014

Notre solution :Isoler JPA dans la couche de persistance

Spring MVC + Spring Data JPA

Présentation Service

JPA

Contrôleurs

Pages WebService DAO

Persistance

Telosys Tools @telosys http://tools.telosys.org 24

Pages Web

Objets

d’affichageMapping Entités JPA

Transactions

Page 25: JUG Nantes - Telosys Tools - Avril 2014

Spring MVC + Spring Data JPA

Partie générée par Telosys :

« Controller »

BookController

« Service »

BookService« DAO »

BookJpaRepository

Base de données

relationnelle« Controller »

BookRestController

Telosys Tools @telosys http://tools.telosys.org 25

BookController

Utilisateur

REST

Pages

GET, POST,PUT, DELETE

BookRestController

Web

Page 26: JUG Nantes - Telosys Tools - Avril 2014

Aspects techniques

• Web : Twitter bootstrap 3, Tiles• RESTful : GET, POST, PUT, DELETE• Tests unitaires : Couverture de 90%• Analyse SONAR : Rules compliance : 91%

Telosys Tools @telosys http://tools.telosys.org 26

Page 27: JUG Nantes - Telosys Tools - Avril 2014

Organisation et dépendances des bundles

Spring MVCfront-springmvc

Service

Présentation

Servicesservice-springdatajpa

Telosys Tools @telosys http://tools.telosys.org 27

Spring Data JPApersistence-springdatajpa

Database

Persistance

Database

Page 28: JUG Nantes - Telosys Tools - Avril 2014

Spring MVC + Spring Data JPA

Démo2

Telosys Tools @telosys http://tools.telosys.org 28

Page 29: JUG Nantes - Telosys Tools - Avril 2014

Application 2 :

AngularJS

AngularJS + Spring MVC REST

Telosys Tools @telosys http://tools.telosys.org 29

AngularJS

Page 30: JUG Nantes - Telosys Tools - Avril 2014

• Fonctionnalités de CRUD : – Création, Recherche, Modification, Suppression d’entités

• Internationalisation (i18n) :– Libellés français / anglais– Gestion des dates

Fonctionnalités

Telosys Tools @telosys http://tools.telosys.org 30

Page 31: JUG Nantes - Telosys Tools - Avril 2014

AngularJS + Spring MVC REST

Application 1

Base de données

relationnelle

JPA

Spring

Data JPA

Spring

MVC

REST

Telosys Tools @telosys http://tools.telosys.org 31

Application 2

relationnelle

AngularJS

Utilisateur

Web

Page 32: JUG Nantes - Telosys Tools - Avril 2014

AngularJS + Spring MVC REST

URLs des services REST• Récupérer la liste des entités :

– GET : /rest/[entity]

• Récupérer une entité :– GET : /rest/[entity]/[id]

• Créer une entité :– POST : /rest /[entity ]

Telosys Tools @telosys http://tools.telosys.org 32

– POST : /rest /[entity ]

• Modifier une entité :– PUT : /rest/[entity]/[id]

• Supprimer une entité :– DELETE : /rest/[entity]/[id]

Page 33: JUG Nantes - Telosys Tools - Avril 2014

AngularJS + Spring MVC REST

Partie générée par Telosys :

« Controller »

BookCtrl_____________________________________________

load

loadAll

save

delete_____________________________________________

$scope.book

REST

« Service »

Book______________________________________

get

getAll

create

update

delete GET,

Telosys Tools @telosys http://tools.telosys.org 33

$scope.book

$scope.books

delete

Page de modification

book_form.html

Page de recherche

book_list.html

GET,POST,PUT,DELETE

Utilisateur

Web

Page 34: JUG Nantes - Telosys Tools - Avril 2014

Aspects techniques

• Basé sur le projet de démarrage « Seed » de Angular :– https://github.com/angular/angular-seed

• Gestion de l’internationalisation (i18n) :

Telosys Tools @telosys http://tools.telosys.org 34

• Gestion de l’internationalisation (i18n) :– https://github.com/angular-translate/angular-translate

• Intégration de Twitter bootstrap 3 avec AngularStrap :– http://mgcrea.github.io/angular-strap

Page 35: JUG Nantes - Telosys Tools - Avril 2014

Organisation et dépendances des bundles

Spring MVCfront-springmvc

Service

Présentation

AngularJSfront-angularjs

MVC Javascript

Service layer

Telosys Tools @telosys http://tools.telosys.org 35

Spring Data JPApersistence-springdatajpa

Database

Service

Persistance

Database

Service layerservice-springdatajpa

Page 36: JUG Nantes - Telosys Tools - Avril 2014

AngularJS + Spring MVC REST

Démo2

Telosys Tools @telosys http://tools.telosys.org 36

Page 37: JUG Nantes - Telosys Tools - Avril 2014

RestfullSpring DataHATEOAS

3

Telosys Tools @telosys http://tools.telosys.org 37

Page 38: JUG Nantes - Telosys Tools - Avril 2014

Spring Data REST dans l'écosystème Spring

Spring Data REST

Spring MVCSpring Data

JPA

Spring Data

Neo4J

Spring Data

MongoDB

Spring Data Commons

Spring Data

Gemfire

Telosys Tools @telosys http://tools.telosys.org 38

Page 39: JUG Nantes - Telosys Tools - Avril 2014

Spring Data, un socle commun

Spring Data REST

Spring MVCSpring Data

JPA

Spring Data

Neo4J

Spring Data

MongoDB

Spring Data Commons

Spring Data

Gemfire

Telosys Tools @telosys http://tools.telosys.org 39

Spring Data Commons• Couche d'abstraction partagée par les différents projets

•Ex : Repository, Génération dynamique des requêtes à partir des nom de méthodes, audit …

Page 40: JUG Nantes - Telosys Tools - Avril 2014

Spring Data : Différents fournisseurs de données

• API de manipulation d'une source de données spécifiques

Spring Data REST

Spring MVCSpring Data

JPA

Spring Data

Neo4J

Spring Data

MongoDB

Spring Data Commons

Spring Data

Gemfire

Telosys Tools @telosys http://tools.telosys.org 40

• API de manipulation d'une source de données spécifiques• Implémentation implicite des opérations les plus courantes (CRUD)

• Plusieurs fournisseurs de données :• JPA, MongoDB, Neo4J, Gemfire, Redis, Hadoop, SolR, Couchbase, elasticsearch, cassandra et dynamoDB

• Supportés par Spring Data REST :• JPA, MongoDB, Neo4J et Gemfire (cache distribué, VMWare)

Page 41: JUG Nantes - Telosys Tools - Avril 2014

Spring Data REST

Spring Data REST

Spring MVCSpring Data

JPA

Spring Data

Neo4J

Spring Data

MongoDB

Spring Data Commons

Spring Data

Gemfire

Telosys Tools @telosys http://tools.telosys.org 41

Spring Data REST• S'appui sur Spring MVC pour l'exposition de services. • Les services exposés sont RESTful, approche HATEAOS• S'appui sur les interfaces Repository pour la génération des services CRUD et de l'API /search

Page 42: JUG Nantes - Telosys Tools - Avril 2014

Spring Data REST

Spring Data REST

Spring MVCSpring Data

JPA

Spring Data

Neo4J

Spring Data

MongoDB

Spring Data Commons

Spring Data

Gemfire

Telosys Tools @telosys http://tools.telosys.org 42

Stack de l'application générée• Spring Data REST 2.0.1.RELEASE• Spring Data JPA 1.5.1.RELEASE• Hibernate 4.2

Page 43: JUG Nantes - Telosys Tools - Avril 2014

Spring Data REST

Book@Entity

Telosys Tools @telosys http://tools.telosys.org 43

Page 44: JUG Nantes - Telosys Tools - Avril 2014

Spring Data REST

Book@Entity

BookRepositoryCrudRepository

Telosys Tools @telosys http://tools.telosys.org 44

Page 45: JUG Nantes - Telosys Tools - Avril 2014

Spring Data REST

Book@Entity

BookRepositoryCrudRepository

Spring Data REST@Controller, Dispatcher

Servlet…

Telosys Tools @telosys http://tools.telosys.org 45

Page 46: JUG Nantes - Telosys Tools - Avril 2014

Spring Data REST

Book@Entity

BookRepositoryCrudRepository

Spring Data REST@Controller, Dispatcher

Servlet…

Telosys Tools @telosys http://tools.telosys.org 46

API CRUD• GET

• POST

• PUT

• DELETE

Page 47: JUG Nantes - Telosys Tools - Avril 2014

Spring Data REST

Book@Entity

BookRepositoryCrudRepository

Spring Data REST@Controller,

ServletDispatcher …

Telosys Tools @telosys http://tools.telosys.org 47

API CRUD• GET

• POST

• PUT

• DELETE

API Search/search

Toutes les méthodes

définies dans l'interface

BookRepository.

Page 48: JUG Nantes - Telosys Tools - Avril 2014

Spring Data REST

Book@Entity

BookRepositoryCrudRepository

Spring Data REST@Controller,

ServletDispatcher …

Telosys Tools @telosys http://tools.telosys.org 48

API CRUD• GET

• POST

• PUT

• DELETE

API Search/search

Toutes les méthodes

définies dans l'interface

BookRepository.

Json Schema/schema

Description des

propriétés de l'entité.

Page 49: JUG Nantes - Telosys Tools - Avril 2014

Spring Data REST

Book@Entity

BookRepositoryCrudRepository

Spring Data REST@Controller,

ServletDispatcher …

Partie générée par

Telosys Tools

• Entités

• Repositories

• "FindBy" pour Many-To-One

• Validators

• Configuration de l'application

Telosys Tools @telosys http://tools.telosys.org 49

API CRUD• GET

• POST

• PUT

• PATCH

• DELETE

API Search/search

Toutes les méthodes

définies dans l'interface

BookRepository.

Json Schema/schema

Description des

propriétés de l'entité.

Page 50: JUG Nantes - Telosys Tools - Avril 2014

HATEOAS ?

" HATEOAS – theword, there's nopronounciation for. "

Telosys Tools @telosys http://tools.telosys.org 50

pronounciation for. "(Ben Hale, SpringOne2GX 2012)

Page 51: JUG Nantes - Telosys Tools - Avril 2014

HATEOAS ?

" HATEOAS – theword, there's nopronounciation for. "

(Ben Hale, SpringOne2GX 2012)

Telosys Tools @telosys http://tools.telosys.org 51

Hypermedia As The Engine Of Application State

Page 52: JUG Nantes - Telosys Tools - Avril 2014

HATEOAS ?

Telosys Tools @telosys http://tools.telosys.org 52

Model of RESTful maturity by L.Richardson

Page 53: JUG Nantes - Telosys Tools - Avril 2014

HATEOAS ?

Un format ? Un standard ?

Telosys Tools @telosys http://tools.telosys.org 53

Page 54: JUG Nantes - Telosys Tools - Avril 2014

HATEOAS ?

Collection+JSON – Hypermedia Type

HAL – Hypertext Application Language

Un format ? Un standard ?

Telosys Tools @telosys http://tools.telosys.org 54

Json-LD : JSON for Linking Data W3C depuis 16/01/2014

SIREN

JSON Schema & JSON Hyper-Schema

Page 55: JUG Nantes - Telosys Tools - Avril 2014

HATEOAS ?

Un format ?

Collection+JSON – Hypermedia Type

HAL – Hypertext Application Language

Un standard ?

Telosys Tools @telosys http://tools.telosys.org 55

Json-LD : JSON for Linking Data W3C depuis 16/01/2014

SIREN

JSON Schema & JSON Hyper-Schema

Page 56: JUG Nantes - Telosys Tools - Avril 2014

HATEOAS ?

Collection+JSON – Hypermedia Type

HAL – Hypertext Application Language

Un format ? Un standard ?

Telosys Tools @telosys http://tools.telosys.org 56

Json-LD : JSON for Linking Data W3C depuis 16/01/2014

SIREN

JSON Schema & JSON Hyper-Schema

Page 57: JUG Nantes - Telosys Tools - Avril 2014

HAL : Hypertext Application Language

Telosys Tools @telosys http://tools.telosys.org 57

Page 58: JUG Nantes - Telosys Tools - Avril 2014

HAL : Hypertext Application Language : Example

{"isbn": "2-212-12232-2","title": "Programmer en Java","price": 35,"quantity": 23,"discount": false,"availability": true,"bestSeller": true,"_links": {

Telosys Tools @telosys http://tools.telosys.org 58

"_links": {"self": {"href": "http://localhost:8080/bookstore-rest/books/1" },"author": {"href": "http://localhost:8080/bookstore-rest/books/1/author"},"page_extract": {

"href": "http://localhost:8080/bookstore-rest/books/1/author/extract{?page}","templated" : true

}}

}

Page 59: JUG Nantes - Telosys Tools - Avril 2014

HAL : Hypertext Application Language : Example

{"isbn": "2-212-12232-2","title": "Programmer en Java","price": 35,"quantity": 23,"discount": false,"availability": true,"bestSeller": true,"_links": {

Telosys Tools @telosys http://tools.telosys.org 59

"_links": {"self": {"href": "http://localhost:8080/bookstore-rest/books/1" },"author": {"href": "http://localhost:8080/bookstore-rest/books/1/author"},"page_extract": {

"href": "http://localhost:8080/bookstore-rest/books/1/author/extract{?page}","templated" : true

}}

}

Liens,actions

Page 60: JUG Nantes - Telosys Tools - Avril 2014

HAL : Hypertext Application Language

• Pour implémenter ou consommer des services "HAL" …

Telosys Tools @telosys http://tools.telosys.org 60

Page 61: JUG Nantes - Telosys Tools - Avril 2014

Démo3

Telosys Tools @telosys http://tools.telosys.org 61

Page 62: JUG Nantes - Telosys Tools - Avril 2014

Arrivée

4

Telosys Tools @telosys http://tools.telosys.org 62

Page 63: JUG Nantes - Telosys Tools - Avril 2014

Et maintenantà vous de jouer !

Vous pouvez…

Telosys Tools @telosys http://tools.telosys.org 63

Vous pouvez…

- Tester- Créer vos templates- Contribuer- Supporter

Page 64: JUG Nantes - Telosys Tools - Avril 2014

Ressources en ligne

Tutorials : https://sites.google.com/site/telosystutorial/

Templates : https://github.com/telosys-tools

Telosys Tools @telosys http://tools.telosys.org 64

Templates : https://github.com/telosys-tools

Code généré : https://github.com/telosys-tools-demo

Applications déployées : - http://bookstore-spring.telosys-tools-demo.cloudbees.net/- http://bookstore-angularjs.telosys-tools-demo.cloudbees.net/

Page 65: JUG Nantes - Telosys Tools - Avril 2014

Roadmap

2014 Plugin :- Modèle sans base de données ( DSL )- Amélioration de l’IHM du plugin ( links, customization )

Nouveaux templates bundles :- Spring JDBC - Struts 2 (?)- PHP / CodeIgniter (?)

Telosys Tools @telosys http://tools.telosys.org 65

- PHP / CodeIgniter (?)

2015

Telosys Tools Studio (outil autonome / socle Eclipse )

Page 66: JUG Nantes - Telosys Tools - Avril 2014

Sondage / roadmap

� Quels templates voudriez-vous ?( pour quelles cibles de génération ) :

• Struts• JSF• Wicket• Scala• PHP• autre…

Telosys Tools @telosys http://tools.telosys.org 66

• autre… � Gradle est-il une priorité ?� Un outil 100% en ligne de commande ?� Un outil 100% web (SaaS / cloud) ?

Vous pouvez répondre avec Twitter � @telosys

Page 67: JUG Nantes - Telosys Tools - Avril 2014

Vous avez des questions ?

Telosys Tools @telosys http://tools.telosys.org 67