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

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

[Internationalisation]

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