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

Last change on this file since 41 was 40, checked in by keesvb, 14 years ago

changed study and experiment schema, added mysql production database

File size: 3.1 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 
18import org.codehaus.groovy.grails.commons.GrailsApplication
19import grails.util.GrailsUtil
20
21import intient.nimble.InstanceGenerator
22
23import intient.nimble.domain.LevelPermission
24import intient.nimble.domain.Role
25import intient.nimble.domain.Group
26import intient.nimble.service.AdminsService
27import intient.nimble.service.UserService
28
29/*
30 * Allows applications using Nimble to undertake process at BootStrap that are related to Nimbe provided objects
31 * such as Users, Role, Groups, Permissions etc.
32 *
33 * Utilizing this BootStrap class ensures that the Nimble environment is populated in the backend data repository correctly
34 * before the application attempts to make any extenstions.
35 */
36class NimbleBootStrap {
37
38  def grailsApplication
39 
40  def nimbleService
41  def userService
42  def adminsService
43
44  def init = {servletContext ->
45
46    // The following must be executed
47    internalBootStap(servletContext)
48
49    // Execute any custom Nimble related BootStrap for your application below
50
51    if ( GrailsUtil.getEnvironment().equals(GrailsApplication.ENV_DEVELOPMENT)) {
52
53        // Create example User account
54        def user = InstanceGenerator.user()
55        user.username = "user"
56        user.pass = 'useR123!'
57        user.passConfirm = 'useR123!'
58        user.enabled = true
59
60        def userProfile = InstanceGenerator.profile()
61        userProfile.fullName = "Test User"
62        userProfile.owner = user
63        user.profile = userProfile
64
65        def savedUser = userService.createUser(user)
66        if (savedUser.hasErrors()) {
67          savedUser.errors.each {
68            log.error(it)
69          }
70          throw new RuntimeException("Error creating example user")
71        }
72
73        // Create example Administrative account
74        def admins = Role.findByName(AdminsService.ADMIN_ROLE)
75        def admin = InstanceGenerator.user()
76        admin.username = "admin"
77        admin.pass = "admiN123!"
78        admin.passConfirm = "admiN123!"
79        admin.enabled = true
80
81        def adminProfile = InstanceGenerator.profile()
82        adminProfile.fullName = "Administrator"
83        adminProfile.owner = admin
84        admin.profile = adminProfile
85
86        def savedAdmin = userService.createUser(admin)
87        if (savedAdmin.hasErrors()) {
88          savedAdmin.errors.each {
89            log.error(it)
90          }
91          throw new RuntimeException("Error creating administrator")
92        }
93
94        adminsService.add(admin)
95
96    }
97
98  }
99
100  def destroy = {
101
102  }
103
104  private internalBootStap(def servletContext) {
105    nimbleService.init()
106  }
107} 
Note: See TracBrowser for help on using the repository browser.