View Javadoc
1   /*
2    * Copyright (c) 2002-2018, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.appointment.business.user;
35  
36  import java.util.ArrayList;
37  import java.util.List;
38  
39  import fr.paris.lutece.plugins.appointment.business.appointment.Appointment;
40  import fr.paris.lutece.plugins.appointment.service.AppointmentPlugin;
41  import fr.paris.lutece.portal.service.plugin.Plugin;
42  import fr.paris.lutece.portal.service.plugin.PluginService;
43  import fr.paris.lutece.portal.service.spring.SpringContextService;
44  
45  /**
46   * This class provides instances management methods for User objects
47   * 
48   * @author Laurent Payen
49   *
50   */
51  public final class UserHome
52  {
53  
54      // Static variable pointed at the DAO instance
55      private static IUserDAO _dao = SpringContextService.getBean( IUserDAO.BEAN_NAME );
56      private static Plugin _plugin = PluginService.getPlugin( AppointmentPlugin.PLUGIN_NAME );
57  
58      /**
59       * Private constructor - this class does not need to be instantiated
60       */
61      private UserHome( )
62      {
63      }
64  
65      /**
66       * Create an instance of the User class
67       * 
68       * @param user
69       *            The instance of the User which contains the informations to store
70       * @return The instance of the User which has been created with its primary key.
71       */
72      public static User create( User user )
73      {
74          _dao.insert( user, _plugin );
75  
76          return user;
77      }
78  
79      /**
80       * Update of the User which is specified in parameter
81       * 
82       * @param user
83       *            The instance of the User which contains the data to store
84       * @return The instance of the User which has been updated
85       */
86      public static User update( User user )
87      {
88          _dao.update( user, _plugin );
89  
90          return user;
91      }
92  
93      /**
94       * Delete the User whose identifier is specified in parameter
95       * 
96       * @param nKey
97       *            The User Id
98       */
99      public static void delete( int nKey )
100     {
101         _dao.delete( nKey, _plugin );
102     }
103 
104     /**
105      * Returns an instance of the User whose identifier is specified in parameter
106      * 
107      * @param nKey
108      *            The User primary key
109      * @return an instance of the User
110      */
111     public static User findByPrimaryKey( int nKey )
112     {
113         return _dao.select( nKey, _plugin );
114     }
115 
116     /**
117      * return a user by its firstname, lastname and email
118      * 
119      * @param strFirstName
120      *            the user first name
121      * @param strLastName
122      *            the user last name
123      * @param strEmail
124      *            the user email
125      * @return the user if it exists
126      */
127     public static User findByFirstNameLastNameAndEmail( String strFirstName, String strLastName, String strEmail )
128     {
129         return _dao.findByFirstNameLastNameAndEmail( strFirstName, strLastName, strEmail, _plugin );
130     }
131 
132     /**
133      * return user(s) by its email
134      * 
135      * @param strEmail
136      *            the user email
137      * @return the user(s) if it exists
138      */
139     public static List<User> findByEmail( String strEmail )
140     {
141         return _dao.findByEmail( strEmail, _plugin );
142     }
143 
144     /**
145      * Return the list of the appointments of the User
146      */
147     public List<Appointment> getListAppointments( )
148     {
149         List<Appointment> appointments = new ArrayList<>( );
150 
151         return appointments;
152     }
153 
154 }