source: trunk/grails-app/controllers/SearchableController.groovy @ 203

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

Added some features: subgrouping by event groups and times, select all and select none, autmatic checking of all samples belonging to a subject and of all samples and subjects belonging to a study. Beatufied some outputs.

Ideally, there should be some extra functionality for automatically putting samples into the right subgroup and for selecting the correct subgroup upon checking its commading subject or study.

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