source: trunk/grails-app/conf/BootStrap.groovy @ 1426

Last change on this file since 1426 was 1426, checked in by work@…, 10 years ago
  • Resolved part of improvement #225
  • refactored the template model out of GSCF into the GDT (Grails Domain Templates) plugin version 0.0.1
  • still work needs to be done (move template editor into gdt, etcetera)
  • fix template owner
  • some methods are missing from Template, but most of it works
  • Property svn:keywords set to Author Date Rev
File size: 2.8 KB
Line 
1import dbnp.authentication.SecRole
2import dbnp.authentication.SecUser
3import org.codehaus.groovy.grails.commons.GrailsApplication
4import nl.grails.plugins.gdt.*
5import dbnp.studycapturing.Study
6import dbnp.studycapturing.Subject
7import dbnp.studycapturing.Sample
8import dbnp.rest.common.CommunicationManager
9import org.codehaus.groovy.grails.commons.*
10
11/**
12 * Application Bootstrapper
13 * @Author Jeroen Wesbeek
14 * @Since 20091021
15 *
16 * Revision information:
17 * $Rev: 1426 $
18 * $Author: work@osx.eu $
19 * $Date: 2011-01-21 18:37:02 +0000 (vr, 21 jan 2011) $
20 */
21class BootStrap {
22        // user spring security
23        def springSecurityService
24
25        // inject the datasource
26        def dataSource
27
28        def init = { servletContext ->
29                // grom what's happening
30                "bootstrapping application".grom()
31
32                // get configuration
33                def config = ConfigurationHolder.config
34
35                // define timezone
36                System.setProperty('user.timezone', 'CET')
37
38                // set up authentication (if required)
39                if (!SecRole.count() || !SecUser.count()) BootStrapAuthentication.initDefaultAuthentication(springSecurityService)
40
41                // set up the SAM communication manager
42                // this should probably more dynamic and put into the modules
43                // section instead of the bootstrap as not all instances will
44                // probably run WITH sam. GSCF should be able to run independently
45                // from other modules. Part of gscf ticket #185
46                if (config.modules) {
47                        // register SAM REST methods
48                        "Registering SAM REST methods".grom()
49                        CommunicationManager.registerModule('gscf', config.grails.serverURL, config.modules)
50                        CommunicationManager.registerRestWrapperMethodsFromSAM()
51                }
52
53                // automatically handle database upgrades
54                DatabaseUpgrade.handleUpgrades(dataSource)
55
56                // developmental bootstrapping:
57                //      - templates
58                //      - ontologies
59                //      - and/or studies
60                if (grails.util.GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT || grails.util.GrailsUtil.environment == GrailsApplication.ENV_TEST || grails.util.GrailsUtil.environment == "dbnpdemo") {
61                        // add ontologies?
62                        if (!Ontology.count()) BootStrapTemplates.initTemplateOntologies()
63
64                        // add templates?
65                        if (!Template.count()) BootStrapTemplates.initTemplates()
66
67                        // add example studies?
68                        if (!Study.count() && grails.util.GrailsUtil.environment != "demo") BootStrapStudies.addExampleStudies(SecUser.findByUsername('user'), SecUser.findByUsername('admin'))
69                }
70
71                /**
72                 * attach ontologies in runtime. Possible problem is that you need
73                 * an internet connection when bootstrapping though.
74                 * @see dbnp.studycapturing.Subject
75                 * @see dbnp.studycapturing.Sample
76                 */
77                TemplateEntity.getField(Subject.domainFields, 'species').ontologies = [Ontology.getOrCreateOntologyByNcboId(1132)]
78                TemplateEntity.getField(Sample.domainFields, 'material').ontologies = [Ontology.getOrCreateOntologyByNcboId(1005)]
79        }
80
81        def destroy = {
82                "stopping application...".grom()
83        }
84} 
Note: See TracBrowser for help on using the repository browser.