1 /*
2 * Copyright (c) 2002-2022, City of 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.slot;
35
36 import java.time.LocalDate;
37 import java.time.LocalDateTime;
38 import java.util.List;
39
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 Slot objects
47 *
48 * @author Laurent Payen
49 *
50 */
51 public final class SlotHome
52 {
53 // Static variable pointed at the DAO instance
54 private static ISlotDAO _dao = SpringContextService.getBean( "appointment.slotDAO" );
55 private static Plugin _plugin = PluginService.getPlugin( AppointmentPlugin.PLUGIN_NAME );
56
57 /**
58 * Private constructor - this class does not need to be instantiated
59 */
60 private SlotHome( )
61 {
62 }
63
64 /**
65 * Create an instance of the Slot class
66 *
67 * @param slot
68 * The instance of the Slot which contains the informations to store
69 * @return The instance of the Slot which has been created with its primary key.
70 */
71 public static Slotef="../../../../../../../fr/paris/lutece/plugins/appointment/business/slot/Slot.html#Slot">Slot create( Slot slot )
72 {
73 _dao.insert( slot, _plugin );
74
75 return slot;
76 }
77
78 /**
79 * Update of the Slot which is specified in parameter
80 *
81 * @param slot
82 * The instance of the Slot which contains the data to store
83 * @return The instance of the Slot which has been updated
84 */
85 public static Slotef="../../../../../../../fr/paris/lutece/plugins/appointment/business/slot/Slot.html#Slot">Slot update( Slot slot )
86 {
87 _dao.update( slot, _plugin );
88
89 return slot;
90 }
91
92 /**
93 * Delete the Slot whose identifier is specified in parameter
94 *
95 * @param nKey
96 * The Slot Id
97 */
98 public static void delete( int nKey )
99 {
100 _dao.delete( nKey, _plugin );
101 }
102
103 /**
104 * Delete a appointment from the table
105 *
106 * @param nIdForm
107 * identifier of the form
108 */
109 public static void deleteByIdForm( int nIdForm )
110 {
111
112 _dao.deleteByIdForm( nIdForm, _plugin );
113 }
114
115 /**
116 * Returns an instance of the Slot whose identifier is specified in parameter
117 *
118 * @param nKey
119 * The Slot primary key
120 * @return an instance of the Slot
121 */
122 public static Slot findByPrimaryKey( int nKey )
123 {
124 return _dao.select( nKey, _plugin );
125 }
126
127 /**
128 * Returns a list of slots for a date range
129 *
130 * @param nIdForm
131 * the Form Id
132 * @param startingDateTime
133 * the starting Date
134 * @param endingDateTime
135 * the ending Date
136 * @return a list of slots whose dates are included in the given period
137 */
138 public static List<Slot> findByIdFormAndDateRange( int nIdForm, LocalDateTime startingDateTime, LocalDateTime endingDateTime )
139 {
140 return _dao.findByIdFormAndDateRange( nIdForm, startingDateTime, endingDateTime, _plugin );
141 }
142
143 /**
144 * Returns all the slot containing an appointment for the date range
145 *
146 * @param nIdForm
147 * the Form Id
148 * @param startingDateTime
149 * the starting date
150 * @param endingDateTime
151 * the ending date
152 * @param plugin
153 * the plugin
154 * @return a list of slots whose dates are included in the given period and is containing an appointment
155 */
156 public static List<Slot> findSlotWithAppointmentByDateRange( int nIdForm, LocalDateTime startingDateTime, LocalDateTime endingDateTime )
157 {
158
159 return _dao.findSlotWithAppointmentByDateRange( nIdForm, startingDateTime, endingDateTime, _plugin );
160
161 }
162
163 /**
164 * Returns a list of specific slots for a form
165 *
166 * @param nIdForm
167 * the Form Id
168 * @return a list of slots found
169 */
170 public static List<Slot> findIsSpecificByIdForm( int nIdForm )
171 {
172 return _dao.findIsSpecificByIdForm( nIdForm, _plugin );
173 }
174
175 /**
176 * Returns a list of slots of a form
177 *
178 * @param nIdForm
179 * the form id
180 * @return a list of all the slots of the form
181 */
182 public static List<Slot> findByIdForm( int nIdForm )
183 {
184 return _dao.findByIdForm( nIdForm, _plugin );
185 }
186
187 /**
188 * Returns a list of open slots for a date range
189 *
190 * @param nIdForm
191 * the Form Id
192 * @param startingDateTime
193 * the starting Date
194 * @param endingDateTime
195 * the ending Date
196 * @return a list of open slots whose dates are included in the given period
197 */
198 public static List<Slot> findOpenSlotsByIdFormAndDateRange( int nIdForm, LocalDateTime startingDateTime, LocalDateTime endingDateTime )
199 {
200 return _dao.findOpenSlotsByIdFormAndDateRange( nIdForm, startingDateTime, endingDateTime, _plugin );
201 }
202
203 /**
204 * Returns a list of open slots
205 *
206 * @param nIdForm
207 * the Form Id
208 * @return a list of open slots
209 */
210 public static List<Slot> findOpenSlotsByIdForm( int nIdForm )
211 {
212 return _dao.findOpenSlotsByIdForm( nIdForm, _plugin );
213 }
214
215 /**
216 * Return the Slot that have the max date
217 *
218 * @param nIdForm
219 * the form id
220 * @return the slot
221 */
222 public static Slot findSlotWithTheMaxDate( int nIdForm )
223 {
224 return _dao.findSlotWithMaxDate( nIdForm, _plugin );
225 }
226
227 /**
228 * Returns a list of slots of a form
229 *
230 * @param nIdAppointment
231 * the appointment id
232 * @return a list of all the slots of the form
233 */
234 public static List<Slot> findByIdAppointment( int nIdAppointment )
235 {
236 return _dao.findByIdAppointment( nIdAppointment, _plugin );
237 }
238
239 /**
240 * Update Potential Remaining Places
241 *
242 * @param nbPotentialRemainingPlaces
243 * @param nIdSlot
244 */
245 public static void updatePotentialRemainingPlaces( int nbPotentialRemainingPlaces, int nIdSlot )
246 {
247
248 _dao.updatePotentialRemainingPlaces( nbPotentialRemainingPlaces, nIdSlot, _plugin );
249
250 }
251
252 /**
253 * Reset Potential Remaining Places
254 *
255 * @param nbPotentialRemainingPlaces
256 * @param nIdSlot
257 */
258 public static void resetPotentialRemainingPlaces( )
259 {
260
261 _dao.resetPotentialRemainingPlaces( _plugin );
262
263 }
264
265 /**
266 * Return the specific slot dates from the form
267 *
268 * @param nIdForm
269 * the id Form
270 * @param plugin
271 * the plugin
272 * @return list of date
273 */
274 public static List<LocalDate> findSpecificSlotDates( int nIdForm )
275 {
276
277 return _dao.findSpecificSlotDates( nIdForm, _plugin );
278 }
279
280 }