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.indicator.web;
35
36 import fr.paris.lutece.plugins.indicator.business.IndicatorHistory;
37 import fr.paris.lutece.plugins.indicator.business.IndicatorHistoryHome;
38 import fr.paris.lutece.portal.service.message.AdminMessage;
39 import fr.paris.lutece.portal.service.message.AdminMessageService;
40 import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
41 import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
42 import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
43 import fr.paris.lutece.util.url.UrlItem;
44
45 import java.util.List;
46 import java.util.Map;
47 import java.util.concurrent.ConcurrentHashMap;
48
49 import javax.servlet.http.HttpServletRequest;
50
51
52
53
54
55 @Controller( controllerJsp = "ManageHistory.jsp", controllerPath = "jsp/admin/plugins/indicator/", right = "INDICATOR_MANAGEMENT" )
56 public class IndicatorHistoryJspBean extends ManageIndicatorJspBean
57 {
58
59
60
61
62 private static final String TEMPLATE_MANAGE_HISTORY = "/admin/plugins/indicator/manage_history.html";
63 private static final String TEMPLATE_CREATE_HISTORY = "/admin/plugins/indicator/create_history.html";
64 private static final String TEMPLATE_MODIFY_HISTORY = "/admin/plugins/indicator/modify_history.html";
65
66
67 private static final String PARAMETER_KEY = "key";
68 private static final String PARAMETER_TIMECODE = "timecode";
69
70
71 private static final String PROPERTY_PAGE_TITLE_MANAGE_HISTORY = "indicator.manage_history.pageTitle";
72 private static final String PROPERTY_PAGE_TITLE_MODIFY_HISTORY = "indicator.modify_history.pageTitle";
73 private static final String PROPERTY_PAGE_TITLE_CREATE_HISTORY = "indicator.create_history.pageTitle";
74
75
76 private static final String MARK_INDICATORHISTORY_LIST = "history_list";
77 private static final String MARK_INDICATORHISTORY = "history";
78 private static final String MARK_KEY = "key";
79 private static final String JSP_MANAGE_HISTORY = "jsp/admin/plugins/indicator/ManageHistory.jsp";
80
81
82 private static final String MESSAGE_CONFIRM_REMOVE_HISTORY = "indicator.message.confirmRemoveIndicatorHistory";
83 private static final String VALIDATION_ATTRIBUTES_PREFIX = "indicator.model.entity.history.attribute.";
84
85
86 private static final String VIEW_MANAGE_HISTORY = "manageIndicatorHistorys";
87 private static final String VIEW_CREATE_HISTORY = "createIndicatorHistory";
88 private static final String VIEW_MODIFY_HISTORY = "modifyIndicatorHistory";
89
90
91 private static final String ACTION_CREATE_HISTORY = "createIndicatorHistory";
92 private static final String ACTION_MODIFY_HISTORY = "modifyIndicatorHistory";
93 private static final String ACTION_REMOVE_HISTORY = "removeIndicatorHistory";
94 private static final String ACTION_CONFIRM_REMOVE_HISTORY = "confirmRemoveIndicatorHistory";
95
96
97 private static final String INFO_HISTORY_CREATED = "indicator.info.history.created";
98 private static final String INFO_HISTORY_UPDATED = "indicator.info.history.updated";
99 private static final String INFO_HISTORY_REMOVED = "indicator.info.history.removed";
100 private static final long serialVersionUID = 1L;
101
102
103 private IndicatorHistory _history;
104
105
106
107
108
109
110 @View( value = VIEW_MANAGE_HISTORY, defaultView = true )
111 public String getManageHistory( HttpServletRequest request )
112 {
113 _history = null;
114
115 String strKey = request.getParameter( PARAMETER_KEY );
116 List<IndicatorHistory> listIndicatorHistorys = (List<IndicatorHistory>) IndicatorHistoryHome.getIndicatorHistorysList( strKey );
117 Map<String, Object> model = getPaginatedListModel( request, MARK_INDICATORHISTORY_LIST, listIndicatorHistorys,
118 JSP_MANAGE_HISTORY );
119 model.put( MARK_KEY, strKey );
120
121 return getPage( PROPERTY_PAGE_TITLE_MANAGE_HISTORY, TEMPLATE_MANAGE_HISTORY, model );
122 }
123
124
125
126
127
128
129
130 @View( VIEW_CREATE_HISTORY )
131 public String getCreateIndicatorHistory( HttpServletRequest request )
132 {
133 String strKey = request.getParameter( PARAMETER_KEY );
134 _history = ( _history != null ) ? _history : new IndicatorHistory( );
135 _history.setIndKey( strKey );
136
137 Map<String, Object> model = getModel( );
138 model.put( MARK_INDICATORHISTORY, _history );
139
140 return getPage( PROPERTY_PAGE_TITLE_CREATE_HISTORY, TEMPLATE_CREATE_HISTORY, model );
141 }
142
143
144
145
146
147
148
149 @Action( ACTION_CREATE_HISTORY )
150 public String doCreateIndicatorHistory( HttpServletRequest request )
151 {
152 populate( _history, request );
153
154
155 if ( !validateBean( _history, VALIDATION_ATTRIBUTES_PREFIX ) )
156 {
157 Map<String, String> mapParameters = new ConcurrentHashMap<String, String>( );
158 mapParameters.put( PARAMETER_KEY, _history.getIndKey( ) );
159
160 return redirect( request, VIEW_CREATE_HISTORY, mapParameters );
161 }
162
163 try
164 {
165 IndicatorHistoryHome.create( _history );
166 addInfo( INFO_HISTORY_CREATED, getLocale( ) );
167
168 Map<String, String> mapParameters = new ConcurrentHashMap<String, String>( );
169 mapParameters.put( PARAMETER_KEY, _history.getIndKey( ) );
170
171 return redirect( request, VIEW_MANAGE_HISTORY, mapParameters );
172 }
173 catch ( Exception e )
174 {
175 if ( e.getCause( ) != null )
176 {
177 addError( e.getCause( ).getMessage( ) );
178 }
179 else
180 {
181 addError( e.getMessage( ) );
182 }
183
184 Map<String, String> mapParameters = new ConcurrentHashMap<String, String>( );
185 mapParameters.put( PARAMETER_KEY, _history.getIndKey( ) );
186
187 return redirect( request, VIEW_CREATE_HISTORY, mapParameters );
188 }
189 }
190
191
192
193
194
195
196
197
198 @Action( ACTION_CONFIRM_REMOVE_HISTORY )
199 public String getConfirmRemoveIndicatorHistory( HttpServletRequest request )
200 {
201 String strKey = request.getParameter( PARAMETER_KEY );
202 String strTimecode = request.getParameter( PARAMETER_TIMECODE );
203 UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_HISTORY ) );
204 url.addParameter( PARAMETER_KEY, strKey );
205 url.addParameter( PARAMETER_TIMECODE, strTimecode );
206
207 String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_HISTORY,
208 url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
209
210 return redirect( request, strMessageUrl );
211 }
212
213
214
215
216
217
218
219 @Action( ACTION_REMOVE_HISTORY )
220 public String doRemoveIndicatorHistory( HttpServletRequest request )
221 {
222 String strKey = request.getParameter( PARAMETER_KEY );
223 String strTimecode = request.getParameter( PARAMETER_TIMECODE );
224 IndicatorHistoryHome.remove( strKey, strTimecode );
225 addInfo( INFO_HISTORY_REMOVED, getLocale( ) );
226
227 Map<String, String> mapParameters = new ConcurrentHashMap<String, String>( );
228 mapParameters.put( PARAMETER_KEY, strKey );
229
230 return redirect( request, VIEW_MANAGE_HISTORY, mapParameters );
231 }
232
233
234
235
236
237
238
239 @View( VIEW_MODIFY_HISTORY )
240 public String getModifyIndicatorHistory( HttpServletRequest request )
241 {
242 String strKey = request.getParameter( PARAMETER_KEY );
243 String strTimecode = request.getParameter( PARAMETER_TIMECODE );
244
245 if ( ( _history == null ) || ( !_history.getIndKey( ).equals( strKey ) ) ||
246 ( _history.getTimeCode( ).equals( strTimecode ) ) )
247 {
248 _history = IndicatorHistoryHome.findByPrimaryKey( strKey, strTimecode );
249 }
250
251 Map<String, Object> model = getModel( );
252 model.put( MARK_INDICATORHISTORY, _history );
253
254 return getPage( PROPERTY_PAGE_TITLE_MODIFY_HISTORY, TEMPLATE_MODIFY_HISTORY, model );
255 }
256
257
258
259
260
261
262
263 @Action( ACTION_MODIFY_HISTORY )
264 public String doModifyIndicatorHistory( HttpServletRequest request )
265 {
266 populate( _history, request );
267
268
269 if ( !validateBean( _history, VALIDATION_ATTRIBUTES_PREFIX ) )
270 {
271 Map<String, String> mapParameters = new ConcurrentHashMap<String, String>( );
272 mapParameters.put( PARAMETER_KEY, _history.getIndKey( ) );
273 mapParameters.put( PARAMETER_TIMECODE, _history.getTimeCode( ) );
274
275 return redirect( request, VIEW_MODIFY_HISTORY, mapParameters );
276 }
277
278 IndicatorHistoryHome.update( _history );
279 addInfo( INFO_HISTORY_UPDATED, getLocale( ) );
280
281 Map<String, String> mapParameters = new ConcurrentHashMap<String, String>( );
282 mapParameters.put( PARAMETER_KEY, _history.getIndKey( ) );
283
284 return redirect( request, VIEW_MANAGE_HISTORY, mapParameters );
285 }
286 }