source: trunk/grails-app/controllers/dbnp/query/QueryController.groovy @ 205

Last change on this file since 205 was 205, checked in by jahn, 10 years ago

Everything related to search and querying is moved in to

dbnp.studycatpuring.query (for controllers) and
views.query

The reason for moving this is that apparently searchable has been found to overwrite files in the searchable directory.
searchable/ is still kept but not used any longer.

Furthermore, for the time being, the advanced search option is removed because it is not part of the prototype.

File size: 5.2 KB
Line 
1package dbnp.query
2
3import org.compass.core.engine.SearchEngineQueryParseException
4
5/*
6 * Copyright 2007 the original author or authors.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 *      http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21
22/**
23 * Basic web interface for Grails Searchable Plugin
24 *
25 * @author Adem and Jahn
26 */
27class QueryController {
28
29    def searchableService
30
31    def selectsample = {
32
33
34            // produce error message here if studies don't contain samples!
35            // redirect back or use error
36
37
38            println "in selectsample: "
39            params.each{println it}
40
41            // prepare showing all studies selected in the previous view
42            def selectedStudies = []
43            def selectedStudyIds = params['selectedStudyIds']
44
45            if(selectedStudyIds!=null)
46            {
47                 def list = selectedStudyIds.findAll(/(\d)+/)
48                 selectedStudies = list.collect{ dbnp.studycapturing.Study.get(it) }
49            }
50            else
51            {
52                 def tmpList = []
53                 def studyList = dbnp.studycapturing.Study.list()
54                 selectedStudyIds = []
55                 params.each{ key,values->
56                     if (values=="on")  tmpList.add(key)
57                 }
58
59                 for (i in studyList)
60                     if (tmpList.contains(i.getId().toString()))
61                     {
62                         selectedStudyIds.add(i.id)
63                         selectedStudies.add(i)
64                     }
65           }
66
67
68        // subgroups
69        // provide list of subgroups depending on the type of subgrouping
70        // selected by the user
71        def subgroups = []
72        def submitButton = params["submit"]  // this button's value determines the kind of subgrouping
73
74        switch(submitButton)
75        {
76             case "Subject Groups":
77                  render(params)
78                  render("Subject Groups")
79                  def studyGroups = []
80                  if(selectedStudies!=null)
81                  {
82                     selectedStudies.each{ study ->
83                         study.groups.each{ group -> studyGroups.add[group] }
84                     }
85                     println "study groups: "
86                     studyGroups.each{x-> println x}
87                  }
88
89                  // testing:
90                  // there is a lack of data in the mockup (subject groups are still missing)
91                  // as long as there are no groups in the boot script,
92                  // we use this
93                  subgroups = studyGroups.size()<=0 ?
94                       ["subject group 1","subject group 2"] : studyGroups
95
96                  render(view:"selectsample",model:[selectedStudies:selectedStudies,selectedStudyIds:selectedStudyIds,subgroups:subgroups])
97                  break
98
99             case "Event Groups":
100                  def eventGroups = []
101                  if(selectedStudies!=null)
102                  {
103                    selectedStudies.each{ study ->
104                         println study.id
105                         println study.samplingEvents.each{ eventGroups.add(it) }
106                    }
107                  }
108                  subgroups=eventGroups
109                  render(view:"selectsample",model:[selectedStudies:selectedStudies,selectedStudyIds:selectedStudyIds,subgroups:subgroups])
110                  break
111
112             case "Starting Time Groups":
113
114                  def timeGroups = []
115                  if(selectedStudies!=null)
116                  {
117                    selectedStudies.each{ study ->
118                         println study.samplingEvents.each{
119                             def timeDiff = it.getPrettyDuration( study.startDate, it.startTime )
120                             if( !timeGroups.contains(timeDiff) ) timeGroups.add(timeDiff)
121                         }
122                    }
123                  }
124                  subgroups=timeGroups
125                  render("Starting Time Groups")
126                  render(view:"selectsample",model:[selectedStudies:selectedStudies,selectedStudyIds:selectedStudyIds,subgroups:subgroups])
127                  break
128
129             case ">> Execute and continue with biomarker selection":
130                  render("Starting Time Groups")
131                  break
132             case "<< Back to study selection":
133                  break
134        }
135        render(view:"selectsample",model:[selectedStudies:selectedStudies,selectedStudyIds:selectedStudyIds,subgroups:subgroups])
136    }
137
138
139
140    /**
141     * Index page with search form and results
142     */
143    def results = {
144        if (!params.q?.trim()) {
145            return [:]
146        }
147        try {
148            return [searchResult: searchableService.search(params.q, params)]
149        } catch (SearchEngineQueryParseException ex) {
150            return [parseException: true]
151        }
152    }
153
154
155    /**
156     * Index page with search form and results
157     */
158    def index = {
159    }
160
161
162    /**
163     * Perform a bulk index of every searchable object in the database
164     */
165    def indexAll = {
166        Thread.start {
167            searchableService.index()
168        }
169        render("bulk index started in a background thread")
170    }
171
172    /**
173     * Perform a bulk index of every searchable object in the database
174     */
175    def unindexAll = {
176        searchableService.unindex()
177        render("unindexAll done")
178    }
179
180
181    def subjectGroups = { render ("hello") }
182
183
184}
Note: See TracBrowser for help on using the repository browser.