SlideShare a Scribd company logo
1 of 8
BootStrap.groovy
BootStrap.groovy
Grails allows to simulate example data (this is called bootstrapping).
To create example data, you can use the class BootStrap.groovy from the
directory ./grails-app/conf with some data
This class is automatically executed whenever the server is started and can be
used to create some example data for testing.
class User {
String username
String name
static hasMany = [roles: Role]
static constraints = {
username(nullable: false, blank: false, unique: true)
name(nullable: false, blank: false, unique: true)
}
}
class Role {
String name
static constraints = {
name(nullable: false, blank: false, unique: true)
}
}
Domain
BootStrap.groovy
class BootStrap {
def init = { servletContext ->
User user1 = new User(username: 'user1', name: 'Regular')
User user2 = new User(username: 'user2', name: 'Super')
User user3 = new User(username: 'user3', name: 'Über')
User user4 = new User(username: 'user4', name: 'Admin')
Role role1 = new Role(name: 'Observer')
Role role2 = new Role(name: 'Executor')
Role role3 = new Role(name: 'Collector')
Role role4 = new Role(name: 'Administrator')
user1.addToRoles(role1)
user2.addToRoles(role1)
user2.addToRoles(role2)
user3.addToRoles(role1)
user3.addToRoles(role2)
user3.addToRoles(role3)
user4.addToRoles(role4)
role1.save() role2.save() role3.save() role4.save() role1.save() user2.save() user3.save()
user4.save()
}
}
grails {
mail {
host = "smtpserver"
port = 123
username = 'username'
password = 'password'
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}
grails.mail.default.from = "abc@xyz.com"
grails.mail.disabled=true
app.startup.mail.to = "abc@xyz.com"
Config.groovy
def init = { servletContext ->
println "Application starting up... "
def toMail = ConfigurationHolder.config.app.startup.mail.to
def mailSubject = "Application starting up on
${InetAddress.localHost.hostName}";
String mailBody = '''
Application started at ''' + new SimpleDateFormat("dd-MMM-yyy hh:mm:ss").format(new
Date()) + '''<br/>''' +
'''<a href=' ''' + ConfigurationHolder.config.grails.serverURL + ''' '> ''' +
ConfigurationHolder.config.grails.serverURL + '''</a><br/><br/><br/>
@Note : This is an automatically generated email.
'''
sendNotification(toMail, mailSubject, mailBody )
}
def destroy = {
println "Application shutting down... "
def toMail = ConfigurationHolder.config.app.startup.mail.to
def mailSubject = "Application starting up on
${InetAddress.localHost.hostName}";
String mailBody = '''
Application shutting down at ''' + new SimpleDateFormat("dd-MMM-yyy
hh:mm:ss").format(new Date()) + '''<br/>''' +
'''<a href=' ''' + ConfigurationHolder.config.grails.serverURL + ''' '> ''' +
ConfigurationHolder.config.grails.serverURL + '''</a><br/><br/><br/>
@Note : This is an automatically generated email.
'''
sendNotification(toMail, mailSubject, mailBody )
}
def sendNotification(String toMail, String mailSubject, String mailBody)
{
println "### sending email ###"
mailService.sendMail {
to toMail
subject mailSubject
body mailBody
}
}

More Related Content

What's hot

Implement Search Screen Using Knockoutjs
Implement Search Screen Using KnockoutjsImplement Search Screen Using Knockoutjs
Implement Search Screen Using Knockoutjs
Neeraj Kaushik
 
Java Script Promise
Java Script PromiseJava Script Promise
Java Script Promise
Alok Guha
 

What's hot (20)

Implement Search Screen Using Knockoutjs
Implement Search Screen Using KnockoutjsImplement Search Screen Using Knockoutjs
Implement Search Screen Using Knockoutjs
 
TDD in the wild
TDD in the wildTDD in the wild
TDD in the wild
 
NodeJs
NodeJsNodeJs
NodeJs
 
RegistryModClass
RegistryModClassRegistryModClass
RegistryModClass
 
Mule esb How to use Jackson in Json to Object converter
Mule esb How to use Jackson in Json to Object converterMule esb How to use Jackson in Json to Object converter
Mule esb How to use Jackson in Json to Object converter
 
Mule esb - How to convert from Json to Object in 5 minutes
Mule esb - How to convert from Json to Object in 5 minutesMule esb - How to convert from Json to Object in 5 minutes
Mule esb - How to convert from Json to Object in 5 minutes
 
Mongoose getting started-Mongo Db with Node js
Mongoose getting started-Mongo Db with Node jsMongoose getting started-Mongo Db with Node js
Mongoose getting started-Mongo Db with Node js
 
Implementações paralelas
Implementações paralelasImplementações paralelas
Implementações paralelas
 
Mongoose: MongoDB object modelling for Node.js
Mongoose: MongoDB object modelling for Node.jsMongoose: MongoDB object modelling for Node.js
Mongoose: MongoDB object modelling for Node.js
 
Mule esb How to convert from Object to Json in 5 minutes
Mule esb How to convert from Object to Json in 5 minutesMule esb How to convert from Object to Json in 5 minutes
Mule esb How to convert from Object to Json in 5 minutes
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)
 
Node.js - Best practices
Node.js  - Best practicesNode.js  - Best practices
Node.js - Best practices
 
Nodejs mongoose
Nodejs mongooseNodejs mongoose
Nodejs mongoose
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Postman On Steroids
Postman On SteroidsPostman On Steroids
Postman On Steroids
 
Java Script Promise
Java Script PromiseJava Script Promise
Java Script Promise
 
What is nodejs
What is nodejsWhat is nodejs
What is nodejs
 
Web Services
Web ServicesWeb Services
Web Services
 
Mule esb How to use Jackson in Object to Json converter
Mule esb How to use Jackson in Object to Json converterMule esb How to use Jackson in Object to Json converter
Mule esb How to use Jackson in Object to Json converter
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
 

Similar to Boot strap.groovy

名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
Tsuyoshi Yamamoto
 
VPN Access Runbook
VPN Access RunbookVPN Access Runbook
VPN Access Runbook
Taha Shakeel
 

Similar to Boot strap.groovy (20)

Тестирование и Django
Тестирование и DjangoТестирование и Django
Тестирование и Django
 
Reliable Javascript
Reliable Javascript Reliable Javascript
Reliable Javascript
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Tugas 2
Tugas 2Tugas 2
Tugas 2
 
07 application security fundamentals - part 2 - security mechanisms - data ...
07   application security fundamentals - part 2 - security mechanisms - data ...07   application security fundamentals - part 2 - security mechanisms - data ...
07 application security fundamentals - part 2 - security mechanisms - data ...
 
201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harian201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harian
 
Fia fabila
Fia fabilaFia fabila
Fia fabila
 
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
 
VPN Access Runbook
VPN Access RunbookVPN Access Runbook
VPN Access Runbook
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
 
UA Testing with Selenium and PHPUnit - ZendCon 2013
UA Testing with Selenium and PHPUnit - ZendCon 2013UA Testing with Selenium and PHPUnit - ZendCon 2013
UA Testing with Selenium and PHPUnit - ZendCon 2013
 
Testing in JavaScript
Testing in JavaScriptTesting in JavaScript
Testing in JavaScript
 
Rapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirageRapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirage
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
JavaExamples
JavaExamplesJavaExamples
JavaExamples
 
201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing
 
Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113
 
XamarinとAWSをつないでみた話
XamarinとAWSをつないでみた話XamarinとAWSをつないでみた話
XamarinとAWSをつないでみた話
 
The State of Lithium
The State of LithiumThe State of Lithium
The State of Lithium
 

More from Vijay Shukla

More from Vijay Shukla (20)

Introduction of webpack 4
Introduction of webpack 4Introduction of webpack 4
Introduction of webpack 4
 
Preview of Groovy 3
Preview of Groovy 3Preview of Groovy 3
Preview of Groovy 3
 
Jython
JythonJython
Jython
 
Groovy closures
Groovy closuresGroovy closures
Groovy closures
 
Groovy
GroovyGroovy
Groovy
 
Grails services
Grails servicesGrails services
Grails services
 
Grails plugin
Grails pluginGrails plugin
Grails plugin
 
Grails domain
Grails domainGrails domain
Grails domain
 
Grails custom tag lib
Grails custom tag libGrails custom tag lib
Grails custom tag lib
 
Grails
GrailsGrails
Grails
 
Gorm
GormGorm
Gorm
 
Controller
ControllerController
Controller
 
Config BuildConfig
Config BuildConfigConfig BuildConfig
Config BuildConfig
 
Command object
Command objectCommand object
Command object
 
Vertx
VertxVertx
Vertx
 
Custom plugin
Custom pluginCustom plugin
Custom plugin
 
Spring security
Spring securitySpring security
Spring security
 
REST
RESTREST
REST
 
Config/BuildConfig
Config/BuildConfigConfig/BuildConfig
Config/BuildConfig
 
GORM
GORMGORM
GORM
 

Recently uploaded

Recently uploaded (20)

WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration Tooling
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeCon
 

Boot strap.groovy

  • 2. BootStrap.groovy Grails allows to simulate example data (this is called bootstrapping). To create example data, you can use the class BootStrap.groovy from the directory ./grails-app/conf with some data This class is automatically executed whenever the server is started and can be used to create some example data for testing.
  • 3. class User { String username String name static hasMany = [roles: Role] static constraints = { username(nullable: false, blank: false, unique: true) name(nullable: false, blank: false, unique: true) } } class Role { String name static constraints = { name(nullable: false, blank: false, unique: true) } } Domain
  • 4. BootStrap.groovy class BootStrap { def init = { servletContext -> User user1 = new User(username: 'user1', name: 'Regular') User user2 = new User(username: 'user2', name: 'Super') User user3 = new User(username: 'user3', name: 'Über') User user4 = new User(username: 'user4', name: 'Admin') Role role1 = new Role(name: 'Observer') Role role2 = new Role(name: 'Executor') Role role3 = new Role(name: 'Collector') Role role4 = new Role(name: 'Administrator') user1.addToRoles(role1) user2.addToRoles(role1) user2.addToRoles(role2) user3.addToRoles(role1) user3.addToRoles(role2) user3.addToRoles(role3) user4.addToRoles(role4) role1.save() role2.save() role3.save() role4.save() role1.save() user2.save() user3.save() user4.save() } }
  • 5. grails { mail { host = "smtpserver" port = 123 username = 'username' password = 'password' props = ["mail.smtp.auth":"true", "mail.smtp.socketFactory.port":"465", "mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory", "mail.smtp.socketFactory.fallback":"false"] } } grails.mail.default.from = "abc@xyz.com" grails.mail.disabled=true app.startup.mail.to = "abc@xyz.com" Config.groovy
  • 6. def init = { servletContext -> println "Application starting up... " def toMail = ConfigurationHolder.config.app.startup.mail.to def mailSubject = "Application starting up on ${InetAddress.localHost.hostName}"; String mailBody = ''' Application started at ''' + new SimpleDateFormat("dd-MMM-yyy hh:mm:ss").format(new Date()) + '''<br/>''' + '''<a href=' ''' + ConfigurationHolder.config.grails.serverURL + ''' '> ''' + ConfigurationHolder.config.grails.serverURL + '''</a><br/><br/><br/> @Note : This is an automatically generated email. ''' sendNotification(toMail, mailSubject, mailBody ) }
  • 7. def destroy = { println "Application shutting down... " def toMail = ConfigurationHolder.config.app.startup.mail.to def mailSubject = "Application starting up on ${InetAddress.localHost.hostName}"; String mailBody = ''' Application shutting down at ''' + new SimpleDateFormat("dd-MMM-yyy hh:mm:ss").format(new Date()) + '''<br/>''' + '''<a href=' ''' + ConfigurationHolder.config.grails.serverURL + ''' '> ''' + ConfigurationHolder.config.grails.serverURL + '''</a><br/><br/><br/> @Note : This is an automatically generated email. ''' sendNotification(toMail, mailSubject, mailBody ) }
  • 8. def sendNotification(String toMail, String mailSubject, String mailBody) { println "### sending email ###" mailService.sendMail { to toMail subject mailSubject body mailBody } }