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

Last change on this file since 87 was 54, checked in by keesvb, 10 years ago

Added fix for postgres problems, refactored JQuery code in tag library

  • 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
50        // Create example User account
51        def user = InstanceGenerator.user()
52        user.username = "user"
53        user.pass = 'useR123!'
54        user.passConfirm = 'useR123!'
55        user.enabled = true
56
57        def userProfile = InstanceGenerator.profile()
58        userProfile.fullName = "Test User"
59        userProfile.owner = user
60        user.profile = userProfile
61
62        def savedUser = userService.createUser(user)
63        if (savedUser.hasErrors()) {
64          savedUser.errors.each {
65            log.error(it)
66          }
67          throw new RuntimeException("Error creating example user")
68        }
69
70        // Create example Administrative account
71        def admins = Role.findByName(AdminsService.ADMIN_ROLE)
72        def admin = InstanceGenerator.user()
73        admin.username = "admin"
74        admin.pass = "admiN123!"
75        admin.passConfirm = "admiN123!"
76        admin.enabled = true
77
78        def adminProfile = InstanceGenerator.profile()
79        adminProfile.fullName = "Administrator"
80        adminProfile.owner = admin
81        admin.profile = adminProfile
82
83        def savedAdmin = userService.createUser(admin)
84        if (savedAdmin.hasErrors()) {
85          savedAdmin.errors.each {
86            log.error(it)
87          }
88          throw new RuntimeException("Error creating administrator")
89        }
90
91        adminsService.add(admin)
92
93    }
94  }
95
96  def destroy = {
97
98  }
99
100  private internalBootStap(def servletContext) {
101    nimbleService.init()
102  }
103} 
Note: See TracBrowser for help on using the repository browser.