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
35 package fr.paris.lutece.plugins.transparency.web;
36
37 import fr.paris.lutece.plugins.transparency.business.Appointment;
38 import fr.paris.lutece.plugins.transparency.business.AppointmentFilter;
39 import fr.paris.lutece.plugins.transparency.business.AppointmentHome;
40 import fr.paris.lutece.plugins.transparency.business.ElectedOfficialHome;
41 import fr.paris.lutece.plugins.transparency.business.LobbyHome;
42 import fr.paris.lutece.portal.service.security.UserNotSignedException;
43 import fr.paris.lutece.portal.service.util.AppPathService;
44 import fr.paris.lutece.portal.service.util.AppPropertiesService;
45 import fr.paris.lutece.portal.web.xpages.XPage;
46 import fr.paris.lutece.portal.util.mvc.xpage.MVCApplication;
47 import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
48 import fr.paris.lutece.portal.util.mvc.xpage.annotations.Controller;
49 import fr.paris.lutece.util.html.Paginator;
50 import fr.paris.lutece.util.string.StringUtil;
51 import java.util.List;
52 import java.util.Map;
53 import javax.servlet.http.HttpServletRequest;
54
55
56
57
58 @Controller( xpageName = "publicmeeting", pageTitleI18nKey = "transparency.xpage.appointment.pageTitle", pagePathI18nKey = "transparency.xpage.appointment.pagePathLabel" )
59 public class AppointmentPublicXPage extends MVCApplication
60 {
61
62 private static final String TEMPLATE_MANAGE_APPOINTMENTS = "/skin/plugins/transparency/manage_public_appointments.html";
63 private static final String TEMPLATE_DETAIL_APPOINTMENT = "/skin/plugins/transparency/detail_public_appointment.html";
64
65
66 private static final String PARAMETER_ID_APPOINTMENT = "id";
67 private static final String PARAMETER_SEARCH_PERIOD = "search_period";
68 private static final String PARAMETER_SEARCH_ELECTED_OFFICIAL = "search_elected_official";
69 private static final String PARAMETER_SEARCH_LOBBY = "search_lobby";
70 private static final String PARAMETER_SEARCH_TITLE = "search_title";
71 private static final String PARAMETER_SORTED_ATTRIBUTE_NAME = "sorted_attribute_name";
72 private static final String PARAMETER_START_DATE = "start_date";
73 private static final String PARAMETER_ASC = "asc_sort";
74
75
76 private static final String MARK_APPOINTMENT_LIST = "appointment_list";
77 private static final String MARK_APPOINTMENT = "appointment";
78 private static final String MARK_BASE_URL = "base_url";
79 private static final String MARK_LOBBY_REFERENCE_START_URL = "lobbyReferenceStartUrl";
80 private static final String MARK_PAGINATOR = "paginator" ;
81 private static final String MARK_SEARCH_FILTER = "search_filter" ;
82
83
84 private static final String PROPERTY_LOBBY_REFERENCE_START_URL_KEY = "lobby.json.detail.startUrl";
85
86
87 private static final String VIEW_MANAGE_APPOINTMENTS = "manageAppointments";
88 private static final String VIEW_DETAIL_APPOINTMENT = "detailAppointment";
89
90
91 private Appointment _appointment;
92 private List<Integer> _appointmentIdsList;
93 private AppointmentFilter _filter = new AppointmentFilter( );
94
95 private int _nItemsPerPage = 10;
96 private String _strCurrentPageIndex = "1";
97
98
99 private static int CONSTANT_DEFAULT_SEARCH_PERIOD = 92 ;
100
101
102
103
104
105
106
107
108
109
110 @View( value = VIEW_MANAGE_APPOINTMENTS, defaultView = true )
111 public XPage getManageAppointments( HttpServletRequest request )
112 {
113 _appointment = null;
114 List<Appointment> appointmentList = null;
115 Paginator<Integer> paginator ;
116
117
118 if ( request.getParameter( Paginator.PARAMETER_PAGE_INDEX ) != null && _appointmentIdsList != null )
119 {
120
121 _strCurrentPageIndex = request.getParameter( Paginator.PARAMETER_PAGE_INDEX );
122 paginator = new Paginator<Integer>( _appointmentIdsList, _nItemsPerPage, getViewFullUrl( VIEW_MANAGE_APPOINTMENTS ),
123 Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
124
125 _filter.setListIds( paginator.getPageItems( ) );
126
127
128 appointmentList = AppointmentHome.getFullAppointmentsList( _filter );
129 }
130 else if ( request.getParameter( PARAMETER_SORTED_ATTRIBUTE_NAME ) != null && _appointmentIdsList != null )
131 {
132
133 if ( request.getParameter( PARAMETER_SORTED_ATTRIBUTE_NAME ).equals( PARAMETER_START_DATE ) )
134 {
135 if ( request.getParameter( PARAMETER_ASC ) != null && request.getParameter( PARAMETER_ASC ).equals( "true" ) )
136 {
137 _filter.setOrderBy( PARAMETER_START_DATE + " ASC " );
138 }
139 else
140 {
141 _filter.setOrderBy( PARAMETER_START_DATE + " DESC " );
142 }
143 }
144
145
146 _strCurrentPageIndex = "1" ;
147 _filter.setListIds( null ) ;
148
149
150 _appointmentIdsList = AppointmentHome.getAppointmentIdsList( _filter );
151
152 paginator = new Paginator<Integer>( _appointmentIdsList, _nItemsPerPage, getViewFullUrl( VIEW_MANAGE_APPOINTMENTS ) ,
153 Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
154
155 _filter.setListIds( paginator.getPageItems( ) );
156
157
158 appointmentList = AppointmentHome.getFullAppointmentsList( _filter );
159 }
160 else
161 {
162
163 String strSearchPeriod = request.getParameter( PARAMETER_SEARCH_PERIOD );
164 String strSearchElectedOfficial = request.getParameter( PARAMETER_SEARCH_ELECTED_OFFICIAL );
165 String strSearchLobby = request.getParameter( PARAMETER_SEARCH_LOBBY );
166 String strSearchTitle = request.getParameter( PARAMETER_SEARCH_TITLE );
167
168
169 if ( strSearchPeriod != null ) _filter.setNumberOfDays( StringUtil.getIntValue( strSearchPeriod, CONSTANT_DEFAULT_SEARCH_PERIOD ) );
170 _filter.setLobbyName( strSearchLobby );
171 _filter.setElectedOfficialName( strSearchElectedOfficial );
172 _filter.setTitle( strSearchTitle );
173
174
175 _strCurrentPageIndex = "1" ;
176 _filter.setListIds( null ) ;
177 _filter.setOrderBy( null );
178
179
180 _appointmentIdsList = AppointmentHome.getAppointmentIdsList( _filter );
181
182 paginator = new Paginator<Integer>( _appointmentIdsList, _nItemsPerPage, getViewFullUrl( VIEW_MANAGE_APPOINTMENTS ) ,
183 Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
184
185 _filter.setListIds( paginator.getPageItems( ) );
186
187
188 appointmentList = AppointmentHome.getFullAppointmentsList( _filter );
189
190 }
191
192 Map<String, Object> model = getModel( );
193 model.put( MARK_APPOINTMENT_LIST, appointmentList );
194 model.put( MARK_PAGINATOR, paginator);
195 model.put( MARK_SEARCH_FILTER, _filter);
196 model.put( MARK_BASE_URL, AppPathService.getBaseUrl( request ) );
197 model.put( MARK_LOBBY_REFERENCE_START_URL, AppPropertiesService.getProperty( PROPERTY_LOBBY_REFERENCE_START_URL_KEY ) );
198
199 return getXPage( TEMPLATE_MANAGE_APPOINTMENTS, request.getLocale( ), model );
200 }
201
202
203
204
205
206
207
208
209 @View( VIEW_DETAIL_APPOINTMENT )
210 public XPage getDetailAppointment( HttpServletRequest request )
211 {
212 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_APPOINTMENT ) );
213
214 if ( _appointment == null || ( _appointment.getId( ) != nId ) )
215 {
216 _appointment = AppointmentHome.findByPrimaryKey( nId );
217 }
218
219 _appointment.setElectedOfficialList( ElectedOfficialHome.getElectedOfficialsListByAppointment( _appointment.getId( ) ) );
220 _appointment.setLobbyList( LobbyHome.getLobbiesListByAppointment( _appointment.getId( ) ) );
221
222 Map<String, Object> model = getModel( );
223 model.put( MARK_APPOINTMENT, _appointment );
224 model.put( MARK_LOBBY_REFERENCE_START_URL, AppPropertiesService.getProperty( PROPERTY_LOBBY_REFERENCE_START_URL_KEY ) );
225
226 return getXPage( TEMPLATE_DETAIL_APPOINTMENT, request.getLocale( ), model );
227 }
228
229 }