Cristian Olaru - Grails 3 - Step By Step [2017, PDF, ENG]
Год издания: 2017
Автор: Cristian Olaru
Жанр или тематика: Программирование
Издательство: Lean Publishing
ISBN: Отсутствует
Серия: Leanpub
Язык: Английский
Формат: PDF
Качество: Издательский макет или текст (eBook)
Интерактивное оглавление: Да
Количество страниц: 218
Описание: We try to describe in this book how a complete greenfield application can be implemented with Grails 3 in a fast way using profiles and plugins - and we do this in the sample application that is accompanying this book.
If you have developed multiple applications over time, than you have recognized a set of principles and good practices that can be reused again and again.
Grails 3 framework has inside a lot of such good technical principles that make it a good starter for your new applications. With Grails 3 you have an established architecture from the beginning and you can implement new features in an easy way using scaffolding and the plugins ecosystem. And this is more valuable in these times when you have to get to the market first, before your competitors.
Оглавление
How this book is organized . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i
First part - Grails 3 Essentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i
Second part - Practical example with Grails 3 . . . . . . . . . . . . . . . . . . . . . ii
PART 1 - Grails 3 Essentials . . . . . . . . . . . . . . . . . . . . . 1
1. Introduction to Grails 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1 Some history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1.1 Java history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1.2 Java EE history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.1.3 Spring history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.1.4 Groovy history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.1.5 Grails history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2 Grails application architecture . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2.1 A classical layered architecture . . . . . . . . . . . . . . . . . . . . . . . 9
1.3 New technologies inside Grails 3 . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.3.1 Spring Boot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.3.2 Gradle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.3.3 Gorm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.3.4 LogBack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.4 Modularity aspects of Grails . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.4.1 Plugins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.4.2 Profiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2. Set your free working environment . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.1 Install Java SDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.2 Install Grails 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.3 Start a muti-build Grails 3 project . . . . . . . . . . . . . . . . . . . . . . . . 25
2.4 IDE support for Grails 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.5 Add a plugin to the multi-build project . . . . . . . . . . . . . . . . . . . . . 31
2.6 Sandbox for Groovy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.7 Source control with Git . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
2.8 Deployment in AWS Cloud . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
2.9 Continuous Delivery with Jenkins . . . . . . . . . . . . . . . . . . . . . . . . 47
3. A greenfield project and a way of working . . . . . . . . . . . . . . . . . . . . . . 53
3.1 Structuring the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
3.2 A way of specifying application requirements . . . . . . . . . . . . . . . . . . 57
3.3 Main techniques used in the sample project . . . . . . . . . . . . . . . . . . . 68
3.3.1 TDD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
3.3.2 BDD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
3.3.3 DDD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
3.3.4 Clean Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
3.3.5 Lean Startup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
3.4 A greenfield application specification . . . . . . . . . . . . . . . . . . . . . . 71
3.4.1 Admin application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
3.4.2 Web application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
3.4.3 Microservice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
3.4.4 Features to be implemented . . . . . . . . . . . . . . . . . . . . . . . . . 75
PART 2 - Practical example with Grails 3 . . . . . . . . 78
4. The Admin Portal - Web Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
4.1 Specification for the admin portal . . . . . . . . . . . . . . . . . . . . . . . . 79
4.2 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
4.2.1 Grails 3 security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
4.2.2 Spring Security Core plugin . . . . . . . . . . . . . . . . . . . . . . . . . 81
4.2.3 Advanced Grails security . . . . . . . . . . . . . . . . . . . . . . . . . . 86
4.2.4 Spring Security AppInfo plugin . . . . . . . . . . . . . . . . . . . . . . . 87
4.3 Modeling the domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
4.3.1 Domain entities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
4.3.2 Relationships between entities . . . . . . . . . . . . . . . . . . . . . . . . 91
4.3.3 Modeling with TDD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
4.4 UI Scaffolding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
4.4.1 Scaffolding plugin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
4.4.2 Fields plugin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
4.5 Persistence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
4.5.1 Populate the database at bootstrap . . . . . . . . . . . . . . . . . . . . . 107
4.5.2 Configuring data sources . . . . . . . . . . . . . . . . . . . . . . . . . . 107
4.5.3 Production database with AWS RDS . . . . . . . . . . . . . . . . . . . . 109
4.6 To do list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
5. A Web Rich Client - Angular Profile . . . . . . . . . . . . . . . . . . . . . . . . . . 113
5.1 Specification for the web application . . . . . . . . . . . . . . . . . . . . . . . 113
5.2 Server side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
5.2.1 Domain module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
5.2.2 The REST API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
5.2.3 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
5.3 Client side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
5.3.1 Introduction in AngularJS framework . . . . . . . . . . . . . . . . . . . 121
5.3.2 Scaffolding the client side . . . . . . . . . . . . . . . . . . . . . . . . . . 127
5.3.3 Introducing the new style . . . . . . . . . . . . . . . . . . . . . . . . . . 130
5.3.4 Asset pipeline plugin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140CONTENTS
5.4 Production ready . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
5.4.1 Buy and host your domain on Elastic Beanstalk . . . . . . . . . . . . . . 142
5.4.2 S3 alternative for hosting your client app . . . . . . . . . . . . . . . . . . 142
5.4.3 Add HTTPS support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
5.4.4 SEO - Search Engine Optimization . . . . . . . . . . . . . . . . . . . . . 145
5.4.5 Analytics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
5.5 To do list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
6. The Mobile Application - Rest API Profile . . . . . . . . . . . . . . . . . . . . . . . 148
6.1 About this chapter content . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
6.2 Introduction to Ionic 2 and Hybrid Mobile Applications . . . . . . . . . . . . 148
6.2.1 Install Ionic 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
6.2.2 Generate client app . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
6.2.3 Angular 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
6.2.4 Cordova . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
6.2.5 Ionic Native . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
6.3 Rest API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
6.3.1 From verbs to nouns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
6.3.2 Swagger specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
6.3.3 REST Security on the server side . . . . . . . . . . . . . . . . . . . . . . 170
6.3.4 REST Security on the client side . . . . . . . . . . . . . . . . . . . . . . . 173
6.4 To the app store . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
6.4.1 Google Play Store . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
6.4.2 Apple App Store . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
6.4.3 Windows App Store . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
6.5 To do list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
7. Microservice - Rest API Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
7.1 About this chapter content . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
7.2 Introduction to microservices . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
7.3 Scheduling a job with Quartz . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
7.4 Expose a REST service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
7.5 Starting the microservice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
7.6 Microservice security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
7.7 To do list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209