1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.calendar.business.portlet;
35
36 import fr.paris.lutece.plugins.calendar.service.AgendaResource;
37 import fr.paris.lutece.plugins.calendar.service.CalendarService;
38 import fr.paris.lutece.plugins.calendar.web.Constants;
39 import fr.paris.lutece.portal.business.portlet.Portlet;
40 import fr.paris.lutece.portal.service.spring.SpringContextService;
41 import fr.paris.lutece.util.sql.DAOUtil;
42
43 import java.util.ArrayList;
44 import java.util.Date;
45 import java.util.List;
46
47
48
49
50
51 public final class CalendarPortletDAO implements ICalendarPortletDAO
52 {
53
54 private static final String SQL_QUERY_SELECT = "SELECT id_portlet FROM core_portlet WHERE id_portlet = ?";
55 private static final String SQL_QUERY_SELECT_AGENDAS_BY_PORTLET = "select code_agenda_name from calendar_portlet where id_portlet = ?";
56 private static final String SQL_QUERY_INSERT_AGENDA = "INSERT INTO calendar_portlet( id_portlet, code_agenda_name, date_begin, date_end ) VALUES ( ?,?,?,? )";
57 private static final String SQL_QUERY_INSERT_AGENDA_DAYS = "INSERT INTO calendar_portlet( id_portlet, code_agenda_name, number_days ,date_begin , date_end ) VALUES ( ?,?,?,?,? )";
58 private static final String SQL_QUERY_DELETE_AGENDA = " DELETE FROM calendar_portlet WHERE id_portlet = ? AND code_agenda_name = ?";
59 private static final String SQL_QUERY_DELETE = "DELETE FROM calendar_portlet WHERE id_portlet = ?";
60 private static final String SQL_QUERY_SELECT_AGENDAS_BY_PORTLET_BY_DATE = "SELECT date_begin,date_end FROM calendar_portlet WHERE id_portlet = ?";
61 private static final String SQL_QUERY_BEGIN_DATE_BY_PORTLET = "SELECT date_begin FROM calendar_portlet where id_portlet = ?";
62 private static final String SQL_QUERY_END_DATE_BY_PORTLET = "SELECT date_end FROM calendar_portlet where id_portlet = ?";
63 private static final String SQL_QUERY_NUMBER_DAYS_BY_PORTLET = "SELECT number_days FROM calendar_portlet WHERE id_portlet = ?";
64
65
66
67
68
69
70
71
72
73 public void insert( Portlet portlet )
74 {
75
76 }
77
78
79
80
81
82 public void delete( int nPortletId )
83 {
84 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE );
85 daoUtil.setInt( 1, nPortletId );
86 daoUtil.executeUpdate( );
87 daoUtil.free( );
88 }
89
90
91
92
93
94
95
96 public Portlet load( int nPortletId )
97 {
98 CalendarPortlet portlet = new CalendarPortlet( );
99
100 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT );
101
102 daoUtil.setInt( 1, nPortletId );
103
104 daoUtil.executeQuery( );
105
106 if ( daoUtil.next( ) )
107 {
108 portlet.setId( nPortletId );
109 }
110
111 daoUtil.free( );
112
113 return portlet;
114 }
115
116
117
118
119
120
121
122 public void store( Portlet portlet )
123 {
124
125 }
126
127
128
129
130
131
132
133
134 public void insertAgendaInterval( int nPortletId, String strAgendaId, String dDateBegin, String dDateEnd )
135 {
136 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT_AGENDA );
137 daoUtil.setInt( 1, nPortletId );
138 daoUtil.setString( 2, strAgendaId );
139 daoUtil.setString( 3, dDateBegin );
140 daoUtil.setString( 4, dDateEnd );
141
142 daoUtil.executeUpdate( );
143 daoUtil.free( );
144 }
145
146
147
148
149
150
151 public void removeAgenda( int nPortletId, String strAgendaId )
152 {
153 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_AGENDA );
154 daoUtil.setInt( 1, nPortletId );
155 daoUtil.setString( 2, strAgendaId );
156
157 daoUtil.executeUpdate( );
158 daoUtil.free( );
159 }
160
161
162
163
164
165
166 public List<AgendaResource> findAgendasInPortlet( int nPortletId )
167 {
168 CalendarService calendarService = SpringContextService.getBean( Constants.BEAN_CALENDAR_CALENDARSERVICE );
169 List<AgendaResource> listSelectedAgendas = new ArrayList<AgendaResource>( );
170 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_AGENDAS_BY_PORTLET );
171 daoUtil.setInt( 1, nPortletId );
172 daoUtil.executeQuery( );
173
174 while ( daoUtil.next( ) )
175 {
176 AgendaResource agendaResource = calendarService.getAgendaResource( daoUtil.getString( 1 ) );
177 if ( agendaResource != null )
178 {
179 listSelectedAgendas.add( agendaResource );
180 }
181 }
182
183 daoUtil.free( );
184
185 return listSelectedAgendas;
186 }
187
188
189
190
191
192
193
194
195 public List<AgendaResource> findAgendaBetween( int nPortletId, Date dateBegin, Date dateEnd )
196 {
197 CalendarService calendarService = SpringContextService.getBean( Constants.BEAN_CALENDAR_CALENDARSERVICE );
198 List<AgendaResource> listSelectedAgendas = new ArrayList<AgendaResource>( );
199 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_AGENDAS_BY_PORTLET_BY_DATE );
200 daoUtil.setInt( 1, nPortletId );
201 daoUtil.executeQuery( );
202
203 while ( daoUtil.next( ) )
204 {
205 AgendaResource agendaResource = calendarService.getAgendaResource( daoUtil.getString( 1 ) );
206 if ( agendaResource != null )
207 {
208 listSelectedAgendas.add( agendaResource );
209 }
210 }
211
212 daoUtil.free( );
213
214 return listSelectedAgendas;
215 }
216
217
218
219
220
221
222 public Date getBeginDate( int nPortletId )
223 {
224 Date dateBegin = null;
225 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_BEGIN_DATE_BY_PORTLET );
226 daoUtil.setInt( 1, nPortletId );
227 daoUtil.executeQuery( );
228
229 while ( daoUtil.next( ) )
230 {
231 try
232 {
233 dateBegin = new Date( daoUtil.getDate( 1 ).getTime( ) );
234 }
235 catch ( NullPointerException e )
236 {
237 }
238 }
239
240 daoUtil.free( );
241
242 return dateBegin;
243 }
244
245
246
247
248
249
250 public Date getEndDate( int nPortletId )
251 {
252 Date dateEnd = null;
253 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_END_DATE_BY_PORTLET );
254 daoUtil.setInt( 1, nPortletId );
255 daoUtil.executeQuery( );
256
257 while ( daoUtil.next( ) )
258 {
259 try
260 {
261 dateEnd = new Date( daoUtil.getDate( 1 ).getTime( ) );
262 }
263 catch ( NullPointerException e )
264 {
265 }
266 }
267
268 daoUtil.free( );
269
270 return dateEnd;
271 }
272
273
274
275
276
277
278
279 public int getRepetitionDays( int nPortletId )
280 {
281 int nNumberDays = 0;
282 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NUMBER_DAYS_BY_PORTLET );
283 daoUtil.setInt( 1, nPortletId );
284 daoUtil.executeQuery( );
285
286 while ( daoUtil.next( ) )
287 {
288 nNumberDays = daoUtil.getInt( 1 );
289 }
290
291 daoUtil.free( );
292
293 return nNumberDays;
294 }
295
296
297
298
299
300
301
302
303 public void insertCalendar( int nPortletId, String strAgendaId, int nDays )
304 {
305 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT_AGENDA_DAYS );
306 daoUtil.setInt( 1, nPortletId );
307 daoUtil.setString( 2, strAgendaId );
308 daoUtil.setInt( 3, nDays );
309 daoUtil.setString( 4, Constants.EMPTY_NULL );
310 daoUtil.setString( 5, Constants.EMPTY_NULL );
311 daoUtil.executeUpdate( );
312 daoUtil.free( );
313 }
314 }