source: ether_ndacc/trunk/web/src/com/ether/Controller.java @ 204

Last change on this file since 204 was 204, checked in by vmipsl, 13 years ago

[Internationalisation]

File size: 19.7 KB
Line 
1package com.ether;
2
3import com.ether.annotation.ControllerMethod;
4import com.ether.annotation.ParamName;
5import com.ether.instrument.Instrument;
6import com.ether.station.Station;
7import org.apache.commons.logging.Log;
8import org.apache.commons.logging.LogFactory;
9import org.springframework.beans.factory.annotation.Required;
10import org.springframework.web.servlet.ModelAndView;
11
12import javax.servlet.http.HttpServletRequest;
13import javax.servlet.http.HttpServletResponse;
14import java.util.HashMap;
15import java.util.List;
16import java.util.Map;
17
18/**
19 * @author vmipsl
20 * @date 17 feb 2011
21 */
22public class Controller
23        extends ControllerEther
24{
25    /** *********************************************************** **/
26    /** *********************** VIEWS ***************************** **/
27    /** *********************************************************** **/
28
29    /**
30     * Default view if url's methodName is unknown
31     *
32     * @return
33     * @throws WebException
34     */
35    @ControllerMethod(view = VIEW_INIT)
36    public Map<String, Object> home()
37            throws WebException
38    {
39        return new HashMap<String, Object>();
40    }
41
42    @ControllerMethod(view = VIEW_DATA_OHP)
43    public Map<String, Object> viewDataOhp()
44            throws WebException
45    {
46        return new HashMap<String, Object>();
47    }
48
49
50    @ControllerMethod(view = VIEW_ECC)
51    public Map<String, Object> selectEcc( @ParamName("dateinf") final String dateinf,
52                                          @ParamName("station") String station,
53                                          @ParamName("instrument") final String instrument )
54            throws WebException
55    {
56        try
57        {
58            final List<String> plotsList = _plotService.getPlotsByDateByInstrumentByStation( instrument, dateinf, "yyyyMMdd", station );
59
60            //dateinf="02021980";
61            //List<String> ListDates = _plotService.getLastDate(instrument);
62            final List<String> listeDates = _serviceTools.getListeDates();
63            String rep = "";
64            String year = dateinf.substring( 0, 4 );
65
66            if( station.compareTo( "OHP" ) == 0 || station.compareTo( "ohp" ) == 0 )
67            {
68                rep = "./resources/visu/ohp/ecc";
69                station = "OHP";
70                if( year.compareTo( "1970" ) == 0 ) year = "2007";
71            }
72            else if( station.compareTo( "LA REUNION" ) == 0 || station.compareTo( "reunion" ) == 0 )
73            {
74                rep = "./resources/visu/reu/ecc";
75                //rep="./resources/visu/ohp/lidar/o3_strato";
76                station = "LA REUNION";
77                if( year.compareTo( "1970" ) == 0 ) year = "2006";
78                //year="2006";
79            }
80            else if( station.compareTo( "DDU" ) == 0 || station.compareTo( "ddu" ) == 0 )
81            {
82                rep = "./resources/visu/ddu/ecc";
83                //rep="./resources/visu/ohp/lidar/o3_strato";
84                station = "DDU";
85                if( year.compareTo( "1970" ) == 0 ) year = "1991";
86                //year="2006";
87            }
88
89            final Map<String, Object> model = new HashMap<String, Object>();
90            model.put( "plotsList", plotsList );
91            model.put( "listeDates", listeDates );
92            model.put( "firstDate", dateinf );
93            final String month = dateinf.substring( 4, 6 );
94            model.put( "month", month );
95            model.put( "year", year );
96            model.put( "station", station );
97            model.put( "rep", rep );
98            return model;
99        }
100        catch( ServiceException e )
101        {
102            throw new WebException( WebException.WebCode.SERVICE_PROBLEM, e );
103        }
104    }
105
106    public ModelAndView viewLidarO3s( final HttpServletRequest request, final HttpServletResponse response )
107            throws WebException
108    {
109        try
110        {
111            final List<String> listeDates = _serviceTools.getListeDates();
112
113            final ModelAndView modelAndView = new ModelAndView( VIEW_LIDAR_O3S );
114            modelAndView.addObject( "listeDates", listeDates );
115
116            return modelAndView;
117
118        }
119        catch( ServiceException e )
120        {
121            throw new WebException( WebException.WebCode.SERVICE_PROBLEM, e );
122        }
123    }
124
125    public ModelAndView selectLidarO3s( final HttpServletRequest request, final HttpServletResponse response )
126            throws WebException
127    {
128        try
129        {
130            String dateinf = request.getParameter( "dateinf" );
131            String station = request.getParameter( "station" );
132
133            final String instrument = request.getParameter( "instrument" );
134
135            List<String> plotsList = _plotService.getPlotsByDateByInstrumentByStation( instrument, dateinf, "yyyyMMdd", station );
136
137            //dateinf="02021980";
138            //List<String> ListDates = _plotService.getLastDate(instrument);
139            final List<String> listeDates = _serviceTools.getListeDates();
140            String rep = "";
141            String year = dateinf.substring( 0, 4 );
142            String month = dateinf.substring( 4, 6 );
143
144            if( station.compareTo( "OHP" ) == 0 || station.compareTo( "ohp" ) == 0 )
145            {
146                rep = "./resources/visu/ohp/lidar/o3_strato";
147                station = "OHP";
148                if( year.compareTo( "1970" ) == 0 )
149                {
150
151                    year = "1991";
152                }
153            }
154            else if( station.compareTo( "REU" ) == 0 || station.compareTo( "reu" ) == 0 || station.compareTo( "LA REUNION" ) == 0 || station.compareTo( "REUNION" ) == 0 )
155            {
156                rep = "./resources/visu/reu/lidar/o3_strato";
157                station = "LA REUNION";
158                if( year.compareTo( "1970" ) == 0 ) year = "2006";
159                //year="2006";
160            }
161
162            else
163            {
164                rep = "./resources/visu/ddu/lidar/o3_strato";
165                station = "DDU";
166                if( year.compareTo( "1970" ) == 0 )
167                {
168                    year = "1991";
169                    //month="04";
170                }
171                //year="2006";
172            }
173
174            final ModelAndView modelAndView = new ModelAndView( VIEW_LIDAR_O3S );
175            //plotsList=null;
176            modelAndView.addObject( "plotsList", plotsList );
177
178            modelAndView.addObject( "listeDates", listeDates );
179            modelAndView.addObject( "firstDate", dateinf );
180
181
182            modelAndView.addObject( "month", month );
183            modelAndView.addObject( "year", year );
184            modelAndView.addObject( "station", station );
185            modelAndView.addObject( "rep", rep );
186
187            return modelAndView;
188
189        }
190        catch( ServiceException e )
191        {
192            throw new WebException( WebException.WebCode.SERVICE_PROBLEM, e );
193        }
194    }
195
196    public ModelAndView selectLidarO3t( final HttpServletRequest request, final HttpServletResponse response )
197            throws WebException
198    {
199        try
200        {
201            String dateinf = request.getParameter( "dateinf" );
202            String station = request.getParameter( "station" );
203
204            final String instrument = request.getParameter( "instrument" );
205
206            List<String> plotsList = _plotService.getPlotsByDateByInstrumentByStation( instrument, dateinf, "yyyyMMdd", station );
207
208            //dateinf="02021980";
209            //List<String> ListDates = _plotService.getLastDate(instrument);
210            final List<String> listeDates = _serviceTools.getListeDates();
211            String rep = "";
212            String year = dateinf.substring( 0, 4 );
213            String month = dateinf.substring( 4, 6 );
214
215            if( station.compareTo( "OHP" ) == 0 || station.compareTo( "ohp" ) == 0 )
216            {
217                rep = "./resources/visu/ohp/lidar/o3_tropo";
218                station = "OHP";
219                if( year.compareTo( "1970" ) == 0 )
220                {
221                    year = "2007";
222                    month = "05";
223                    dateinf = year + month + "01";
224                }
225            }
226            //else if (station.compareTo("reunion")==0) {
227            else
228            {
229                rep = "./resources/visu/reu/lidar/o3_tropo";
230                //rep="./resources/visu/ohp/lidar/o3_strato";
231                station = "LA REUNION";
232                if( year.compareTo( "1970" ) == 0 )
233                {
234                    year = "2006";
235
236                }
237                //year="2006";
238            }
239
240
241            final ModelAndView modelAndView = new ModelAndView( VIEW_LIDAR_O3T );
242            //plotsList=null;
243            modelAndView.addObject( "plotsList", plotsList );
244
245            modelAndView.addObject( "listeDates", listeDates );
246            modelAndView.addObject( "firstDate", dateinf );
247
248            //String month = dateinf.substring(4,6);
249            modelAndView.addObject( "month", month );
250            modelAndView.addObject( "year", year );
251            modelAndView.addObject( "station", station );
252            modelAndView.addObject( "rep", rep );
253
254            return modelAndView;
255
256        }
257        catch( ServiceException e )
258        {
259            throw new WebException( WebException.WebCode.SERVICE_PROBLEM, e );
260        }
261    }
262
263    public ModelAndView selectLidarTemp( final HttpServletRequest request, final HttpServletResponse response )
264            throws WebException
265    {
266        try
267        {
268            String dateinf = request.getParameter( "dateinf" );
269            String station = request.getParameter( "station" );
270
271            final String instrument = request.getParameter( "instrument" );
272
273            List<String> plotsList = _plotService.getPlotsByDateByInstrumentByStation( instrument, dateinf, "yyyyMMdd", station );
274
275            //dateinf="02021980";
276            //List<String> ListDates = _plotService.getLastDate(instrument);
277            final List<String> listeDates = _serviceTools.getListeDates();
278            String rep = "";
279            String year = dateinf.substring( 0, 4 );
280            String month = dateinf.substring( 4, 6 );
281
282            if( station.compareTo( "OHP" ) == 0 || station.compareTo( "ohp" ) == 0 )
283            {
284                rep = "./resources/visu/ohp/lidar/temp";
285                station = "OHP";
286                if( year.compareTo( "1970" ) == 0 )
287                {
288                    year = "2009";
289                    month = "01";
290                }
291            }
292
293            if( station.compareTo( "REU" ) == 0 || station.compareTo( "reu" ) == 0 )
294            {
295                rep = "./resources/visu/reu/lidar/temp";
296                station = "REU";
297                if( year.compareTo( "1970" ) == 0 )
298                {
299                    year = "1994";
300                    month = "05";
301                }
302            }
303
304            final ModelAndView modelAndView = new ModelAndView( VIEW_LIDAR_TEMP );
305            //plotsList=null;
306            modelAndView.addObject( "plotsList", plotsList );
307
308            modelAndView.addObject( "listeDates", listeDates );
309            modelAndView.addObject( "firstDate", dateinf );
310
311            //String month = dateinf.substring(4,6);
312            modelAndView.addObject( "month", month );
313            modelAndView.addObject( "year", year );
314            modelAndView.addObject( "station", station );
315            modelAndView.addObject( "rep", rep );
316
317            return modelAndView;
318
319        }
320        catch( ServiceException e )
321        {
322            throw new WebException( WebException.WebCode.SERVICE_PROBLEM, e );
323        }
324    }
325
326
327    public ModelAndView selectLidarAerosols( final HttpServletRequest request, final HttpServletResponse response )
328            throws WebException
329    {
330        try
331        {
332            String dateinf = request.getParameter( "dateinf" );
333            String station = request.getParameter( "station" );
334
335            final String instrument = request.getParameter( "instrument" );
336
337            List<String> plotsList = _plotService.getPlotsByDateByInstrumentByStation( instrument, dateinf, "yyyyMMdd", station );
338
339            //dateinf="02021980";
340            //List<String> ListDates = _plotService.getLastDate(instrument);
341            final List<String> listeDates = _serviceTools.getListeDates();
342            String rep = "";
343            String year = dateinf.substring( 0, 4 );
344            String month = dateinf.substring( 4, 6 );
345
346            if( station.compareTo( "OHP" ) == 0 || station.compareTo( "ohp" ) == 0 )
347            {
348                rep = "./resources/visu/ohp/lidar/aerosols";
349                station = "OHP";
350                if( year.compareTo( "1970" ) == 0 )
351                {
352                    year = "2009";
353                    month = "01";
354                }
355            }
356
357            if( station.compareTo( "DDU" ) == 0 || station.compareTo( "ddu" ) == 0 )
358            {
359                rep = "./resources/visu/ddu/lidar/aerosols";
360                station = "DDU";
361                if( year.compareTo( "1970" ) == 0 )
362                {
363                    year = "2010";
364                    month = "01";
365                }
366            }
367
368            final ModelAndView modelAndView = new ModelAndView( VIEW_LIDAR_AEROSOLS );
369            //plotsList=null;
370            modelAndView.addObject( "plotsList", plotsList );
371
372            modelAndView.addObject( "listeDates", listeDates );
373            modelAndView.addObject( "firstDate", dateinf );
374
375            //String month = dateinf.substring(4,6);
376            modelAndView.addObject( "month", month );
377            modelAndView.addObject( "year", year );
378            modelAndView.addObject( "station", station );
379            modelAndView.addObject( "rep", rep );
380
381            return modelAndView;
382
383        }
384        catch( ServiceException e )
385        {
386            throw new WebException( WebException.WebCode.SERVICE_PROBLEM, e );
387        }
388    }
389
390    public ModelAndView viewSpectroUV( final HttpServletRequest request, final HttpServletResponse response )
391            throws WebException
392    {
393        try
394        {
395            String dateinf = request.getParameter( "dateinf" );
396            //List<String> m = new ArrayList<String>(12);
397
398            String m[];
399            m = new String[12];
400            String fname, iname, year;
401
402            final String instrument = request.getParameter( "instrument" );
403            String especes = request.getParameter( "especes" );
404
405            if( especes.equals( "nan" ) )
406            {
407                especes = "uvauvb";
408            }
409
410            if( dateinf.equals( "nan" ) )
411            {
412                year = "2008";
413                dateinf = "2008";
414
415            }
416
417            List<String> plotsList = _plotService.getPlotsByDateByInstrument( instrument, dateinf, "yyyy" );
418            final List<String> listeDates = _serviceTools.getListeDates();
419
420            final ModelAndView modelAndView = new ModelAndView( VIEW_SPECTRO_UV );
421            modelAndView.addObject( "plotsList", plotsList );
422
423            modelAndView.addObject( "listeDates", listeDates );
424            modelAndView.addObject( "firstDate", dateinf );
425            modelAndView.addObject( "especes", especes );
426            year = dateinf.substring( 0, 4 );
427
428            modelAndView.addObject( "year", year );
429            modelAndView.addObject( "m", m );
430
431            fname = "vasp_";
432            fname = fname.concat( especes );
433            fname = fname.concat( "_" );
434            fname = fname.concat( year );
435
436            iname = fname.concat( "01_plot1.jpg" );
437            if( plotsList.contains( iname ) ) m[0] = iname;
438            else m[0] = "no";
439
440            iname = fname.concat( "02_plot1.jpg" );
441            if( plotsList.contains( iname ) ) m[1] = iname;
442            else m[1] = "no";
443
444            iname = fname.concat( "03_plot1.jpg" );
445            if( plotsList.contains( iname ) ) m[2] = iname;
446            else m[2] = "no";
447
448            iname = fname.concat( "04_plot1.jpg" );
449            if( plotsList.contains( iname ) ) m[3] = iname;
450            else m[3] = "no";
451
452            iname = fname.concat( "05_plot1.jpg" );
453            if( plotsList.contains( iname ) ) m[4] = iname;
454            else m[4] = "no";
455
456            iname = fname.concat( "06_plot1.jpg" );
457            if( plotsList.contains( iname ) ) m[5] = iname;
458            else m[5] = "no";
459
460            iname = fname.concat( "07_plot1.jpg" );
461            if( plotsList.contains( iname ) ) m[6] = iname;
462            else m[6] = "no";
463
464            iname = fname.concat( "08_plot1.jpg" );
465            if( plotsList.contains( iname ) ) m[7] = iname;
466            else m[7] = "no";
467
468            iname = fname.concat( "09_plot1.jpg" );
469            if( plotsList.contains( iname ) ) m[8] = iname;
470            else m[8] = "no";
471
472            iname = fname.concat( "10_plot1.jpg" );
473            if( plotsList.contains( iname ) ) m[9] = iname;
474            else m[9] = "no";
475
476            iname = fname.concat( "11_plot1.jpg" );
477            if( plotsList.contains( iname ) ) m[10] = iname;
478            else m[10] = "no";
479
480            iname = fname.concat( "12_plot1.jpg" );
481            if( plotsList.contains( iname ) ) m[11] = iname;
482            else m[11] = "no";
483
484            return modelAndView;
485
486        }
487        catch( ServiceException e )
488        {
489            throw new WebException( WebException.WebCode.SERVICE_PROBLEM, e );
490        }
491    }
492
493
494    public ModelAndView viewInstruments( final HttpServletRequest request, final HttpServletResponse response )
495            throws WebException
496    {
497        try
498        {
499            final List<Instrument> instruments = _instrumentService.getAllInstruments();
500
501            final ModelAndView modelAndView = new ModelAndView( VIEW_INSTRUMENT );
502            modelAndView.addObject( "instruments", instruments );
503            return modelAndView;
504
505        }
506        catch( ServiceException e )
507        {
508            throw new WebException( WebException.WebCode.SERVICE_PROBLEM, e );
509        }
510    }
511
512    public ModelAndView viewStation( final HttpServletRequest request, final HttpServletResponse response )
513            throws WebException
514    {
515        try
516        {
517            final Long stationId = Long.valueOf( request.getParameter( "stationId" ) );
518            final Station station = _stationService.getStationById( stationId );
519
520            final ModelAndView modelAndView = new ModelAndView( VIEW_STATION );
521            modelAndView.addObject( "station", station );
522            return modelAndView;
523
524        }
525        catch( ServiceException e )
526        {
527            throw new WebException( WebException.WebCode.SERVICE_PROBLEM, e );
528        }
529    }
530
531    @Required
532    public void setStationService( final StationService stationService )
533    {
534        _stationService = stationService;
535    }
536
537    @Required
538    public void setInstrumentService( final InstrumentService instrumentService )
539    {
540        _instrumentService = instrumentService;
541    }
542
543    @Required
544    public void setServiceTools( final ServiceTools serviceTools )
545    {
546        _serviceTools = serviceTools;
547    }
548
549    @Required
550    public void setPlotService( final PlotService plotService )
551    {
552        _plotService = plotService;
553    }
554
555    private static final Log LOGGER = LogFactory.getLog( Controller.class );
556
557    private static final String VIEW_INIT = "init";
558
559    private static final String VIEW_INSTRUMENT = "instrument";
560    private static final String VIEW_STATION = "station";
561    private static final String VIEW_LIDAR_O3S = "visus_lidar_o3s";
562    private static final String VIEW_LIDAR_O3T = "visus_lidar_o3t";
563    private static final String VIEW_ECC = "visus_ecc";
564    private static final String VIEW_SPECTRO_UV = "visus_spectro";
565    private static final String VIEW_LIDAR_TEMP = "visus_lidar_temp";
566    private static final String VIEW_LIDAR_AEROSOLS = "visus_lidar_aerosols";
567    private static final String VIEW_DATA_OHP = "data_ohp";
568
569    //services que le controller peut utiliser
570    private StationService _stationService;
571    private InstrumentService _instrumentService;
572    private ServiceTools _serviceTools;
573    private PlotService _plotService;
574}
Note: See TracBrowser for help on using the repository browser.