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

Last change on this file since 92 was 92, checked in by duh, 14 years ago
  • added sample template data in bootstrap
  • upgraded jQuery
  • improved study capture wizard
  • fixed selenium test
  • Property svn:keywords set to Date Author Rev
File size: 3.0 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    if (nimble.User.count() == 0) {
49        println ".bootstrapping nimble"
50
51        // Create example User account
52        def user = InstanceGenerator.user()
53        user.username = "user"
54        user.pass = 'useR123!'
55        user.passConfirm = 'useR123!'
56        user.enabled = true
57
58        def userProfile = InstanceGenerator.profile()
59        userProfile.fullName = "Test User"
60        userProfile.owner = user
61        user.profile = userProfile
62
63        def savedUser = userService.createUser(user)
64        if (savedUser.hasErrors()) {
65          savedUser.errors.each {
66            log.error(it)
67          }
68          throw new RuntimeException("Error creating example user")
69        }
70
71        // Create example Administrative account
72        def admins = Role.findByName(AdminsService.ADMIN_ROLE)
73        def admin = InstanceGenerator.user()
74        admin.username = "admin"
75        admin.pass = "admiN123!"
76        admin.passConfirm = "admiN123!"
77        admin.enabled = true
78
79        def adminProfile = InstanceGenerator.profile()
80        adminProfile.fullName = "Administrator"
81        adminProfile.owner = admin
82        admin.profile = adminProfile
83
84        def savedAdmin = userService.createUser(admin)
85        if (savedAdmin.hasErrors()) {
86          savedAdmin.errors.each {
87            log.error(it)
88          }
89          throw new RuntimeException("Error creating administrator")
90        }
91
92        adminsService.add(admin)
93
94    }
95  }
96
97  def destroy = {
98
99  }
100
101  private internalBootStap(def servletContext) {
102    nimbleService.init()
103  }
104} 
Note: See TracBrowser for help on using the repository browser.