source: trunk/grails-app/conf/NimbleBootStrap.groovy @ 51

Last change on this file since 51 was 51, checked in by duh, 9 years ago

-re-added nimble snapshot 0.3

File size: 2.8 KB
Line 
1/*
2 *  Nimble, an extensive application base for Grails
3 *  Copyright (C) 2009 Intient Pty Ltd
4 *
5 *  Licensed under the Apache License, Version 2.0 (the "License");
6 *  you may not use this file except in compliance with the License.
7 *  You may obtain a copy of the License at
8 *
9 *  http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17 
18
19import intient.nimble.InstanceGenerator
20
21import intient.nimble.domain.LevelPermission
22import intient.nimble.domain.Role
23import intient.nimble.domain.Group
24import intient.nimble.service.AdminsService
25import intient.nimble.service.UserService
26
27/*
28 * Allows applications using Nimble to undertake process at BootStrap that are related to Nimbe provided objects
29 * such as Users, Role, Groups, Permissions etc.
30 *
31 * Utilizing this BootStrap class ensures that the Nimble environment is populated in the backend data repository correctly
32 * before the application attempts to make any extenstions.
33 */
34class NimbleBootStrap {
35
36  def grailsApplication
37 
38  def nimbleService
39  def userService
40  def adminsService
41
42  def init = {servletContext ->
43
44    // The following must be executed
45    internalBootStap(servletContext)
46
47    // Execute any custom Nimble related BootStrap for your application below
48
49    // Create example User account
50    def user = InstanceGenerator.user()
51    user.username = "user"
52    user.pass = 'useR123!'
53    user.passConfirm = 'useR123!'
54    user.enabled = true
55
56    def userProfile = InstanceGenerator.profile()
57    userProfile.fullName = "Test User"
58    userProfile.owner = user
59    user.profile = userProfile
60
61    def savedUser = userService.createUser(user)
62    if (savedUser.hasErrors()) {
63      savedUser.errors.each {
64        log.error(it)
65      }
66      throw new RuntimeException("Error creating example user")
67    }
68
69    // Create example Administrative account
70    def admins = Role.findByName(AdminsService.ADMIN_ROLE)
71    def admin = InstanceGenerator.user()
72    admin.username = "admin"
73    admin.pass = "admiN123!"
74    admin.passConfirm = "admiN123!"
75    admin.enabled = true
76
77    def adminProfile = InstanceGenerator.profile()
78    adminProfile.fullName = "Administrator"
79    adminProfile.owner = admin
80    admin.profile = adminProfile
81
82    def savedAdmin = userService.createUser(admin)
83    if (savedAdmin.hasErrors()) {
84      savedAdmin.errors.each {
85        log.error(it)
86      }
87      throw new RuntimeException("Error creating administrator")
88    }
89
90    adminsService.add(admin)
91  }
92
93  def destroy = {
94
95  }
96
97  private internalBootStap(def servletContext) {
98    nimbleService.init()
99  }
100} 
Note: See TracBrowser for help on using the repository browser.