source: ether_megapoli/trunk/service/implementation/com/ether/EtherServiceImpl.java @ 482

Last change on this file since 482 was 482, checked in by vmipsl, 12 years ago

BO insertion données _ insertion code medias package insertion

File size: 17.2 KB
Line 
1package com.ether;
2
3import com.ether.dao.JeuDAO;
4import com.ether.dao.McoDAO;
5import com.ether.dao.MeasureDAO;
6import com.ether.dao.ParameterDAO;
7import com.ether.dao.PersonDAO;
8import com.ether.dao.PlateformDAO;
9import com.ether.dao.UserDAO;
10import com.ether.dao.ValueDAO;
11import com.ether.mco.Mco;
12import com.ether.mco.McoFilter;
13import com.ether.user.User;
14import com.ether.user.UserFilter;
15import com.ether.user.UserState;
16import com.medias.annuaire.Personne;
17import com.medias.database.objects.Jeu;
18import com.medias.database.objects.Parametre;
19import com.medias.database.objects.Plateforme;
20import org.apache.commons.logging.Log;
21import org.apache.commons.logging.LogFactory;
22import org.jetbrains.annotations.NotNull;
23import org.jetbrains.annotations.Nullable;
24import org.springframework.beans.factory.annotation.Required;
25import org.springframework.transaction.annotation.Transactional;
26
27import java.util.ArrayList;
28import java.util.Date;
29import java.util.List;
30
31/**
32 * @author vmipsl
33 * @date 07 mar 2011
34 */
35public class EtherServiceImpl
36        implements EtherService
37{
38    @Nullable
39    @Transactional(readOnly = true)
40    public List<Plateforme> getAllPlateforms()
41            throws ServiceException
42    {
43        try
44        {
45            return _plateformDAO.getAllPlateforms();
46        }
47        catch( PersistenceException e )
48        {
49            throw new ServiceException( ServiceException.ServiceCode.PLATEFORM_NOT_FOUND, e );
50        }
51    }
52
53    @Nullable
54    @Transactional(readOnly = true)
55    public Plateforme getPlateformById( @Nullable final Integer plateformId )
56            throws ServiceException
57    {
58        if( null == plateformId )
59            return null;
60        try
61        {
62            return _plateformDAO.getPlateformById( plateformId );
63        }
64        catch( PersistenceException e )
65        {
66            throw new ServiceException( ServiceException.ServiceCode.PLATEFORM_NOT_FOUND, e );
67        }
68    }
69
70    @Nullable
71    @Transactional(readOnly = true)
72    public Parametre getParameterById( @Nullable final Integer parameterId )
73            throws ServiceException
74    {
75        if( null == parameterId )
76            return null;
77        try
78        {
79            return _parameterDAO.getParameterById( parameterId );
80        }
81        catch( PersistenceException e )
82        {
83            throw new ServiceException( ServiceException.ServiceCode.PARAMETER_NOT_FOUND, e );
84        }
85    }
86
87    @NotNull
88    @Transactional(readOnly = true)
89    public List<Parametre> getParametersByPlateformId( @NotNull final Integer plateformId )
90            throws ServiceException
91    {
92        try
93        {
94            return _parameterDAO.getParametersByPlateformId( plateformId );
95        }
96        catch( PersistenceException e )
97        {
98            throw new ServiceException( ServiceException.ServiceCode.PARAMETER_NOT_FOUND, e );
99        }
100    }
101
102    @NotNull
103    @Transactional(readOnly = true)
104    public <T1, T2, T3> Data<T1[], T2[], T3[]> getListsByPlateformByParameterByPeriodForTimeSerie( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd )
105            throws ServiceException
106    {
107        try
108        {
109            return _valueDAO.getListsByPlateformByParameterByPeriodForTimeSerie( plateformId, parameterId, dateBegin, dateEnd );
110        }
111        catch( PersistenceException e )
112        {
113            throw new ServiceException( ServiceException.ServiceCode.VALUE_NOT_FOUND, e );
114        }
115    }
116
117    @NotNull
118    @Transactional(readOnly = true)
119    public <T1, T2, T3> Data<List<T1>, List<T2>, List<T3>> getListsByPlateformByParameterByPeriodFor2D( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd )
120            throws ServiceException
121    {
122        try
123        {
124            return _valueDAO.getListsByPlateformByParameterByPeriodFor2D( plateformId, parameterId, dateBegin, dateEnd );
125        }
126        catch( PersistenceException e )
127        {
128            throw new ServiceException( ServiceException.ServiceCode.VALUE_NOT_FOUND, e );
129        }
130    }
131
132    @NotNull
133    @Transactional(readOnly = true)
134    public <T1, T2, T3> Data<T1[], T2[], T3[]> getArraysByPlateformByParameterByPeriodFor2D( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd )
135            throws ServiceException
136    {
137        try
138        {
139            return _valueDAO.getArraysByPlateformByParameterByPeriodFor2D( plateformId, parameterId, dateBegin, dateEnd );
140        }
141        catch( PersistenceException e )
142        {
143            throw new ServiceException( ServiceException.ServiceCode.VALUE_NOT_FOUND, e );
144        }
145    }
146
147    @NotNull
148    @Transactional(readOnly = true)
149    public Integer getNumberValuesByPlateformByParameterByPeriod( @NotNull final List<Pair<Integer, Integer>> pairs, @Nullable final Date beginDate, @Nullable final Date endDate )
150            throws ServiceException
151    {
152        try
153        {
154            Integer number = 0;
155            for( final Pair pair : pairs )
156                number += _valueDAO.getNumberValuesByPlateformByParameterByPeriod( (Integer) pair.getFirstValue(), (Integer) pair.getSecondValue(), beginDate, endDate );
157
158            return number;
159        }
160        catch( PersistenceException e )
161        {
162            throw new ServiceException( ServiceException.ServiceCode.VALUE_NOT_FOUND, e );
163        }
164    }
165
166    @Nullable
167    @Transactional(readOnly = true)
168    public Date getFirstDate()
169            throws ServiceException
170    {
171        try
172        {
173            return _measureDAO.getFirstDate();
174        }
175        catch( PersistenceException e )
176        {
177            throw new ServiceException( ServiceException.ServiceCode.DATE_NOT_FOUND, e );
178        }
179    }
180
181    @Nullable
182    @Transactional(readOnly = true)
183    public Date getLastDate()
184            throws ServiceException
185    {
186        try
187        {
188            return _measureDAO.getLastDate();
189        }
190        catch( PersistenceException e )
191        {
192            throw new ServiceException( ServiceException.ServiceCode.DATE_NOT_FOUND, e );
193        }
194    }
195
196    @Nullable
197    @Transactional(readOnly = true)
198    public User getUserById( @NotNull final Integer userId )
199            throws ServiceException
200    {
201        try
202        {
203            return _userDAO.selectByPrimaryKey( userId );
204        }
205        catch( PersistenceException e )
206        {
207            throw new ServiceException( ServiceException.ServiceCode.USER_NOT_FOUND, e );
208        }
209    }
210
211    @Nullable
212    @Transactional(readOnly = true)
213    public User getUserByEmail( @NotNull final String userEmail )
214            throws ServiceException
215    {
216        try
217        {
218            return _userDAO.getUserByEmail( userEmail );
219        }
220        catch( PersistenceException e )
221        {
222            throw new ServiceException( ServiceException.ServiceCode.USER_NOT_FOUND, e );
223        }
224    }
225
226    @NotNull
227    @Transactional(rollbackFor = Exception.class)
228    public Integer createUser( @NotNull final User user )
229            throws ServiceException
230    {
231        try
232        {
233            return _userDAO.insert( user );
234        }
235        catch( PersistenceException e )
236        {
237            throw new ServiceException( ServiceException.ServiceCode.PERSISTENCE, e );
238        }
239    }
240
241    @NotNull
242    @Transactional(readOnly = true)
243    public List<User> getAllUsers()
244            throws ServiceException
245    {
246        try
247        {
248            return _userDAO.selectAll();
249        }
250        catch( PersistenceException e )
251        {
252            throw new ServiceException( ServiceException.ServiceCode.USER_NOT_FOUND, e );
253        }
254    }
255
256    @NotNull
257    @Transactional(readOnly = true)
258    public List<User> getAllUsersByNameOrder()
259            throws ServiceException
260    {
261        try
262        {
263            return _userDAO.getAllUsersByNameOrder();
264        }
265        catch( PersistenceException e )
266        {
267            throw new ServiceException( ServiceException.ServiceCode.USER_NOT_FOUND, e );
268        }
269    }
270
271    @NotNull
272    @Transactional(readOnly = true)
273    public List<User> getUsersByState( @NotNull final UserState userState )
274            throws ServiceException
275    {
276        try
277        {
278            return _userDAO.getUsersByState( userState );
279        }
280        catch( PersistenceException e )
281        {
282            throw new ServiceException( ServiceException.ServiceCode.USER_NOT_FOUND, e );
283        }
284    }
285
286    @Transactional(rollbackFor = Exception.class)
287    public void removeUserById( @NotNull final Integer userId )
288            throws ServiceException
289    {
290        try
291        {
292            _userDAO.deleteByPrimaryKey( userId );
293        }
294        catch( PersistenceException e )
295        {
296            throw new ServiceException( ServiceException.ServiceCode.PERSISTENCE, e );
297        }
298    }
299
300    @Transactional(rollbackFor = Exception.class)
301    public void updateUser( @NotNull final User user )
302            throws ServiceException
303    {
304        try
305        {
306            _userDAO.update( user );
307        }
308        catch( PersistenceException e )
309        {
310            throw new ServiceException( ServiceException.ServiceCode.PERSISTENCE, e );
311        }
312    }
313
314    @Transactional(rollbackFor = Exception.class)
315    public void acceptOrRefuseUser( @NotNull final Integer userId, final boolean isAccepted )
316            throws ServiceException
317    {
318        try
319        {
320            final User user = _userDAO.selectByPrimaryKey( userId );
321            if( isAccepted )
322                user.setState( UserState.ACCEPTED );
323            else
324                user.setState( UserState.REFUSED );
325            _userDAO.update( user );
326        }
327        catch( PersistenceException e )
328        {
329            throw new ServiceException( ServiceException.ServiceCode.PERSISTENCE, e );
330        }
331    }
332
333    @Nullable
334    @Transactional(readOnly = true)
335    public Personne getPeopleByEmail( @NotNull final String email )
336            throws ServiceException
337    {
338        try
339        {
340            return _personDAO.getPersonByEmail( email );
341        }
342        catch( PersistenceException e )
343        {
344            throw new ServiceException( ServiceException.ServiceCode.PERSON_NOT_FOUND, e );
345        }
346    }
347
348    @Transactional(readOnly = true)
349    public PaginatedResult<User> searchUsers( @NotNull final UserFilter filter )
350            throws ServiceException
351    {
352        try
353        {
354            return _userDAO.search( filter );
355        }
356        catch( PersistenceException e )
357        {
358            throw new ServiceException( ServiceException.ServiceCode.USER_NOT_FOUND, e );
359        }
360    }
361
362    @Transactional(readOnly = true)
363    public PaginatedResult<Mco> searchMcos( @NotNull final McoFilter filter )
364            throws ServiceException
365    {
366        try
367        {
368            return _mcoDAO.search( filter );
369        }
370        catch( PersistenceException e )
371        {
372            throw new ServiceException( ServiceException.ServiceCode.REQUEST_NOT_FOUND, e );
373        }
374    }
375
376    @Nullable
377    @Transactional(readOnly = true)
378    public Mco getMcoByCode( @NotNull final String code )
379            throws ServiceException
380    {
381        try
382        {
383            return _mcoDAO.getMcoByCode( code );
384        }
385        catch( PersistenceException e )
386        {
387            throw new ServiceException( ServiceException.ServiceCode.REQUEST_NOT_FOUND, e );
388        }
389    }
390
391    @NotNull
392    @Transactional(rollbackFor = Exception.class)
393    public Integer createMco( @NotNull final Mco mco )
394            throws ServiceException
395    {
396        try
397        {
398            return _mcoDAO.insert( mco );
399        }
400        catch( PersistenceException e )
401        {
402            throw new ServiceException( ServiceException.ServiceCode.PERSISTENCE, e );
403        }
404    }
405
406    @Transactional(rollbackFor = Exception.class)
407    public void removeMcoById( @NotNull final Integer mcoId )
408            throws ServiceException
409    {
410        try
411        {
412            _mcoDAO.deleteByPrimaryKey( mcoId );
413        }
414        catch( PersistenceException e )
415        {
416            throw new ServiceException( ServiceException.ServiceCode.PERSISTENCE, e );
417        }
418    }
419
420    @Transactional(rollbackFor = Exception.class)
421    public void updateMco( @NotNull final Mco mco )
422            throws ServiceException
423    {
424        try
425        {
426            _mcoDAO.update( mco );
427        }
428        catch( PersistenceException e )
429        {
430            throw new ServiceException( ServiceException.ServiceCode.PERSISTENCE, e );
431        }
432    }
433
434    @Nullable
435    @Transactional(readOnly = true)
436    public Mco getMcoById( @NotNull final Integer requestId )
437            throws ServiceException
438    {
439        try
440        {
441            return _mcoDAO.selectByPrimaryKey( requestId );
442        }
443        catch( PersistenceException e )
444        {
445            throw new ServiceException( ServiceException.ServiceCode.REQUEST_NOT_FOUND, e );
446        }
447    }
448
449    /**
450     * This method manage the sub-menus for the list of parameters (to avoid multiple "Particle Concentration" by example)
451     * The fullParameters must be ordered with parameterName ascendant
452     *
453     * @param fullParameters
454     * @return
455     */
456    @NotNull
457    public List<List<Parametre>> manageMenusForParameterList( @NotNull final List<Parametre> fullParameters )
458    {
459        final List<List<Parametre>> parameterListWithMenu = new ArrayList<List<Parametre>>();
460
461        int i = 0;
462        while( i < fullParameters.size() )
463        {
464            final Parametre fullParameter = fullParameters.get( i );
465            final int firstIndex = fullParameters.indexOf( fullParameter );
466            final int lastIndex = fullParameters.lastIndexOf( fullParameter );
467            final List<Parametre> parameters = fullParameters.subList( firstIndex, lastIndex + 1 );
468            parameterListWithMenu.add( parameters );
469            i += parameters.size();
470        }
471
472        return parameterListWithMenu;
473    }
474
475    @Nullable
476    @Transactional(readOnly = true)
477    public List<Parametre> getAllParametersOrderByCategoryByName()
478            throws ServiceException
479    {
480        try
481        {
482            return _parameterDAO.getAllParametersOrderByCategoryByName();
483        }
484        catch( PersistenceException e )
485        {
486            throw new ServiceException( ServiceException.ServiceCode.PARAMETER_NOT_FOUND, e );
487        }
488    }
489
490    @Nullable
491    @Transactional(readOnly = true)
492    public List<Date> getAllMeasureDateByPlateformId( @NotNull final Integer plateformId )
493            throws ServiceException
494    {
495        try
496        {
497            return _measureDAO.getAllMeasureDateByPlateformId( plateformId );
498        }
499        catch( PersistenceException e )
500        {
501            throw new ServiceException( ServiceException.ServiceCode.DATE_NOT_FOUND, e );
502        }
503    }
504
505    @Nullable
506    @Transactional(readOnly = true)
507    public PaginatedResult<Jeu> searchJeux( @NotNull final JeuFilter filter )
508            throws ServiceException
509    {
510        try
511        {
512            return _jeuDAO.search( filter );
513        }
514        catch( PersistenceException e )
515        {
516            throw new ServiceException( ServiceException.ServiceCode.JEU_NOT_FOUND, e );
517        }
518    }
519
520    @Transactional(rollbackFor = Exception.class)
521    public void removeJeuById( @NotNull final Integer jeuId )
522            throws ServiceException
523    {
524        // TODO lancer moulinette à VP
525        final String bob = "bib";
526//        try
527//        {
528//            _jeuDAO.deleteByPrimaryKey( jeuId );
529//        }
530//        catch( PersistenceException e )
531//        {
532//            throw new ServiceException( ServiceException.ServiceCode.PERSISTENCE, e );
533//        }
534    }
535
536    @Nullable
537    @Transactional(readOnly = true)
538    public Jeu getJeuById( @NotNull final Integer jeuId )
539            throws ServiceException
540    {
541        try
542        {
543            return _jeuDAO.selectByPrimaryKey( jeuId );
544        }
545        catch( PersistenceException e )
546        {
547            throw new ServiceException( ServiceException.ServiceCode.JEU_NOT_FOUND, e );
548        }
549    }
550
551    @Required
552    public void setPlateformDAO( final PlateformDAO plateformDAO )
553    {
554        _plateformDAO = plateformDAO;
555    }
556
557    @Required
558    public void setParameterDAO( final ParameterDAO parameterDAO )
559    {
560        _parameterDAO = parameterDAO;
561    }
562
563    @Required
564    public void setValueDAO( final ValueDAO valueDAO )
565    {
566        _valueDAO = valueDAO;
567    }
568
569    @Required
570    public void setMeasureDAO( final MeasureDAO measureDAO )
571    {
572        _measureDAO = measureDAO;
573    }
574
575    @Required
576    public void setUserDAO( final UserDAO userDAO )
577    {
578        _userDAO = userDAO;
579    }
580
581    @Required
582    public void setPersonDAO( final PersonDAO personDAO )
583    {
584        _personDAO = personDAO;
585    }
586
587    @Required
588    public void setMcoDAO( final McoDAO mcoDAO )
589    {
590        _mcoDAO = mcoDAO;
591    }
592
593    @Required
594    public void setJeuDAO( final JeuDAO jeuDAO )
595    {
596        _jeuDAO = jeuDAO;
597    }
598
599    private static final Log LOGGER = LogFactory.getLog( EtherServiceImpl.class );
600
601    private PlateformDAO _plateformDAO;
602    private ParameterDAO _parameterDAO;
603    private ValueDAO _valueDAO;
604    private MeasureDAO _measureDAO;
605    private UserDAO _userDAO;
606    private PersonDAO _personDAO;
607    private McoDAO _mcoDAO;
608    private JeuDAO _jeuDAO;
609}
Note: See TracBrowser for help on using the repository browser.