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.suggest.web;
35
36 import java.io.IOException;
37 import java.util.ArrayList;
38 import java.util.Collection;
39 import java.util.HashMap;
40 import java.util.List;
41 import java.util.Locale;
42 import java.util.Map;
43 import java.util.regex.Pattern;
44
45 import javax.servlet.http.HttpServletRequest;
46 import javax.servlet.http.HttpSession;
47
48 import org.apache.commons.lang3.StringUtils;
49
50 import fr.paris.lutece.plugins.suggest.business.Category;
51 import fr.paris.lutece.plugins.suggest.business.CategoryHome;
52 import fr.paris.lutece.plugins.suggest.business.CommentSubmit;
53 import fr.paris.lutece.plugins.suggest.business.Suggest;
54 import fr.paris.lutece.plugins.suggest.business.SuggestFilter;
55 import fr.paris.lutece.plugins.suggest.business.SuggestHome;
56 import fr.paris.lutece.plugins.suggest.business.SuggestSubmit;
57 import fr.paris.lutece.plugins.suggest.business.SuggestSubmitState;
58 import fr.paris.lutece.plugins.suggest.business.SuggestSubmitStateHome;
59 import fr.paris.lutece.plugins.suggest.business.SuggestSubmitType;
60 import fr.paris.lutece.plugins.suggest.business.SuggestSubmitTypeHome;
61 import fr.paris.lutece.plugins.suggest.business.SuggestUserInfo;
62 import fr.paris.lutece.plugins.suggest.business.FormError;
63 import fr.paris.lutece.plugins.suggest.business.ReportedMessage;
64 import fr.paris.lutece.plugins.suggest.business.ReportedMessageHome;
65 import fr.paris.lutece.plugins.suggest.business.Response;
66 import fr.paris.lutece.plugins.suggest.business.SearchFields;
67 import fr.paris.lutece.plugins.suggest.business.SubmitFilter;
68 import fr.paris.lutece.plugins.suggest.business.VoteHome;
69 import fr.paris.lutece.plugins.suggest.business.VoteType;
70 import fr.paris.lutece.plugins.suggest.business.VoteTypeHome;
71 import fr.paris.lutece.plugins.suggest.service.CommentSubmitService;
72 import fr.paris.lutece.plugins.suggest.service.SuggestSubmitService;
73 import fr.paris.lutece.plugins.suggest.service.SuggestUserInfoService;
74 import fr.paris.lutece.plugins.suggest.service.SuggestService;
75 import fr.paris.lutece.plugins.suggest.service.ICommentSubmitService;
76 import fr.paris.lutece.plugins.suggest.service.ISuggestSubmitService;
77 import fr.paris.lutece.plugins.suggest.service.suggestsearch.SuggestSearchService;
78 import fr.paris.lutece.plugins.suggest.service.workflow.SuggestWorkflowService;
79 import fr.paris.lutece.plugins.suggest.service.subscription.SuggestSubscriptionProviderService;
80 import fr.paris.lutece.plugins.suggest.utils.SuggestUtils;
81 import fr.paris.lutece.portal.service.captcha.CaptchaSecurityService;
82 import fr.paris.lutece.portal.service.content.XPageAppService;
83 import fr.paris.lutece.portal.service.i18n.I18nService;
84 import fr.paris.lutece.portal.service.message.SiteMessage;
85 import fr.paris.lutece.portal.service.message.SiteMessageException;
86 import fr.paris.lutece.portal.service.message.SiteMessageService;
87 import fr.paris.lutece.portal.service.plugin.Plugin;
88 import fr.paris.lutece.portal.service.plugin.PluginService;
89 import fr.paris.lutece.portal.service.portal.PortalService;
90 import fr.paris.lutece.portal.service.security.LuteceUser;
91 import fr.paris.lutece.portal.service.security.SecurityService;
92 import fr.paris.lutece.portal.service.security.UserNotSignedException;
93 import fr.paris.lutece.portal.service.template.AppTemplateService;
94 import fr.paris.lutece.portal.service.util.AppLogService;
95 import fr.paris.lutece.portal.service.util.AppPathService;
96 import fr.paris.lutece.portal.service.util.AppPropertiesService;
97 import fr.paris.lutece.portal.service.workflow.WorkflowService;
98 import fr.paris.lutece.portal.web.LocalVariables;
99 import fr.paris.lutece.portal.web.l10n.LocaleService;
100 import fr.paris.lutece.portal.web.xpages.XPage;
101 import fr.paris.lutece.portal.web.xpages.XPageApplication;
102 import fr.paris.lutece.util.ReferenceList;
103 import fr.paris.lutece.util.html.HtmlTemplate;
104 import fr.paris.lutece.util.html.Paginator;
105 import fr.paris.lutece.util.url.UrlItem;
106
107
108
109
110 public class SuggestApp implements XPageApplication
111 {
112
113
114
115 private static final long serialVersionUID = -1994396667980739722L;
116 public static final String ANCHOR_SUGGEST_SUBMIT = "suggest";
117 public static final String ANCHOR_FRAMESET_CONTENT_SUGGEST = "frameset_content_suggest";
118 public static final String PARAMETER_CLEAR_FILTER = "clear_filter";
119 public static final String PARAMETER_SUGGEST_DETAIL = "suggest_detail";
120 public static final String ACTION_VIEW_SUGGEST_SUBMIT = "view_suggest_submit";
121
122
123 private static final String MARK_SUGGEST = "suggest";
124 private static final String MARK_CONTENT_SUGGEST = "content_suggest";
125 private static final String MARK_LIST_SUGGEST_SUBMIT = "list_suggest_submit";
126 private static final String MARK_LABEL_SUGGEST = "label_suggest";
127 private static final String MARK_HEADER_SUGGEST = "header_suggest";
128 private static final String MARK_LIST_CATEGORIES_SUGGEST = "list_categories_suggest";
129 private static final String MARK_ID_SUGGEST = "id_suggest";
130 private static final String MARK_SUGGEST_LIST = "list_suggest";
131 private static final String MARK_LIST_SUBMIT_TOP_COMMENT = "list_top_comment_suggest";
132 private static final String MARK_LIST_SUBMIT_TOP_POPULARITY_SUGGEST = "list_top_popularity_suggest";
133 private static final String MARK_ID_SUGGEST_SUBMIT = "id_suggest_submit";
134 private static final String MARK_LIST_COMMENT_SUBMIT_SUGGEST = "list_comment";
135 private static final String MARK_LIST_SUB_COMMENT_SUBMIT_SUGGEST = "list_sub_comment";
136 private static final String MARK_SUGGEST_COMMENT = "suggest_comment";
137 private static final String MARK_AUTHORIZED_COMMENT = "authorized_comment";
138 private static final String MARK_AUTHORIZED_VOTE = "authorized_vote";
139 private static final String MARK_DISPLAY_COMMENT_IN_LIST = "display_comment_in_list";
140 private static final String MARK_ENABLE_SUGGEST_REPORTS = "enable_suggest_reports";
141 private static final String MARK_SUGGEST_SUBMIT = "suggest_submit";
142 private static final String MARK_COMMENT_SUBMIT = "comment_submit";
143 private static final String MARK_LUTECE_USER = "lutece_user";
144 private static final String MARK_LUTECE_USER_CONNECTED = "lutece_user_connected";
145 private static final String MARK_UNAVAILABILITY_MESSAGE = "unavailability_message";
146 private static final String MARK_NUMBER_SHOWN_CHARACTERS = "number_shown_characters";
147 private static final String MARK_DISABLE_NEW_SUGGEST_SUBMIT = "disable_new_suggest_submit";
148 private static final String MARK_DISABLE_NEW_COMMENT_SUBMIT = "disable_new_comment_submit";
149 private static final String MARK_QUERY = "query";
150 private static final String MARK_ID_FILTER_CATEGORY_SUGGEST = "id_filter_category";
151 private static final String MARK_ID_FILTER_TYPE = "id_filter_type";
152 private static final String MARK_TYPE_SELECTED = "type_selected";
153 private static final String MARK_ID_FILTER_PERIOD = "id_filter_period";
154 private static final String MARK_LIST_SUGGEST_SUBMIT_SORT = "list_suggest_submit_sort";
155 private static final String MARK_LIST_FILTER_BY_PERIOD = "list_filter_by_period";
156 private static final String MARK_ID_SUGGEST_SUBMIT_SORT = "id_suggest_submit_sort";
157 private static final String MARK_SHOW_CATEGORY_BLOCK = "show_category_block";
158 private static final String MARK_SHOW_TOP_SCORE_BLOCK = "show_top_score_block";
159 private static final String MARK_SHOW_TOP_COMMENT_BLOCK = "show_top_comment_block";
160 private static final String MARK_SUGGEST_SUBMIT_VOTE_TYPE = "suggest_submit_vote_type";
161
162 private static final String MARK_PAGINATOR = "paginator";
163 private static final String MARK_JCAPTCHA = "jcaptcha";
164 private static final String MARK_MAX_AMOUNT_COMMENTS = "number_comments";
165 private static final String MARK_MAX_AMOUNT_COMMENTS_CHAR = "cumber_char_comments";
166 private static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page";
167 private static final String MARK_ACTIVE_EDITOR_BBCODE = "active_editor_bbcode";
168 private static final String MARK_VIEW = "view";
169 private static final String MARK_USER_SUBSCRIBED = "user_subscribed";
170 private static final String MARK_IS_EXTEND_INSTALLED = "isExtendInstalled";
171
172
173 private static final String TEMPLATE_XPAGE_FRAME_SUGGEST = "skin/plugins/suggest/suggest_frame.html";
174 private static final String TEMPLATE_XPAGE_LIST_SUBMIT_SUGGEST = "skin/plugins/suggest/suggest_list_submit.html";
175 private static final String TEMPLATE_XPAGE_FORM_SUGGEST = "skin/plugins/suggest/suggest_form.html";
176 private static final String TEMPLATE_XPAGE_LIST_SUGGEST = "skin/plugins/suggest/suggest_list.html";
177 private static final String TEMPLATE_XPAGE_DETAIL_SUBMIT_SUGGEST = "skin/plugins/suggest/suggest_detail.html";
178 private static final String TEMPLATE_XPAGE_SUGGEST_REPORTED = "skin/plugins/suggest/suggest_reported.html";
179 private static final String TEMPLATE_XPAGE_SUGGEST_SUB_COMMENT = "skin/plugins/suggest/suggest_sub_comment.html";
180 private static final String TEMPLATE_XPAGE_COMMENT_SUBMIT_SUGGEST = "skin/plugins/suggest/suggest_comment.html";
181 private static final String JCAPTCHA_PLUGIN = "jcaptcha";
182
183
184 private static final String PROPERTY_XPAGE_PAGETITLE = "suggest.xpage.pagetitle";
185 private static final String PROPERTY_XPAGE_PATHLABEL = "suggest.xpage.pathlabel";
186 private static final String PROPERTY_NUMBER_SUGGEST_SUBMIT_VALUE_SHOWN_CHARACTERS = "suggest.suggestSubmitValue.NumberShownCharacters";
187 private static final String PROPERTY_PAGE_APPLICATION_ID = "suggest.xpage.applicationId";
188 private static final String PROPERTY_ITEM_PER_PAGE = "suggest.itemsPerPage.front";
189
190
191 private static final String PARAMETER_ID_SUGGEST = "id_suggest";
192 private static final String PARAMETER_ID_SUBMIT_SUGGEST = "id_suggest_submit";
193 private static final String PARAMETER_COMMENT_SUGGEST = "suggest_comment";
194 private static final String PARAMETER_COMMENT_VALUE_SUGGEST = "comment_value";
195 private static final String PARAMETER_REPORTED_VALUE = "reported_value";
196 private static final String PARAMETER_ID_FILTER_PERIOD = "id_filter_period";
197 private static final String PARAMETER_ID_SUGGEST_SUBMIT_SORT = "id_suggest_submit_sort";
198 private static final String PARAMETER_VOTE_SUGGEST = "vote";
199 private static final String PARAMETER_ID_FILTER_CATEGORY_SUGGEST = "id_filter_category";
200 private static final String PARAMETER_ID_FILTER_SUGGEST_SUBMIT_TYPE = "id_filter_type";
201 private static final String PARAMETER_LUTECE_USER_NAME_FILTER = "lutece_user_name_filter";
202 private static final String PARAMETER_ID_CATEGORY_SUGGEST = "id_category";
203 private static final String PARAMETER_ID_TYPE_SUGGEST = "id_type";
204 private static final String PARAMETER_VOTED = "voted";
205 private static final String PARAMETER_QUERY = "query";
206 private static final String PARAMETER_FILTER_PAGE_INDEX = "filter_page_index";
207 private static final String PARAMETER_PAGE_INDEX = "page_index";
208 private static final String PARAMETER_COMMENT_ID_PARENT = "id_suggest_comment";
209 private static final String PARAMETER_ACTION = "action";
210 private static final String PARAMETER_VIEW = "view";
211 private static final String PARAMETER_TERMS_OF_USE = "terms_of_use";
212 private static final String PARAMETER_PAGE = "page";
213
214
215 private static final String MESSAGE_FORM_ERROR = "suggest.message.formError";
216 private static final String MESSAGE_MANDATORY_QUESTION = "suggest.message.mandatory.question";
217 private static final String MESSAGE_ERROR = "suggest.message.Error";
218 private static final String MESSAGE_MANDATORY_COMMENT = "suggest.message.mandatoryComment";
219 private static final String MESSAGE_MANDATORY_REPORTED = "suggest.message.mandatoryReported";
220 private static final String MESSAGE_CAPTCHA_ERROR = "suggest.message.captchaError";
221 private static final String MESSAGE_NEW_SUGGEST_SUBMIT = "suggest.message.newSuggestSubmit";
222 private static final String MESSAGE_NEW_SUGGEST_SUBMIT_DISABLE = "suggest.message.newSuggestSubmitDisable";
223 private static final String MESSAGE_MESSAGE_SUBMIT_SAVE_ERROR = "suggest.message.submitSaveError";
224 private static final String MESSAGE_NEW_COMMENT_SUBMIT = "suggest.message.newCommentSubmit";
225 private static final String MESSAGE_NEW_COMMENT_SUBMIT_DISABLE = "suggest.message.newCommentSubmitDisable";
226 private static final String MESSAGE_NEW_REPORTED_SUBMIT = "suggest.message.newReportedSubmit";
227 private static final String MESSAGE_ERROR_NO_CATEGORY = "suggest.message.errorNoCategorySelected";
228 private static final String MESSAGE_ERROR_NO_SUGGEST_SUBMIT_TYPE_SELECTED = "suggest.message.errorNoSuggestSubmitTypeSelected";
229 private static final String MESSAGE_ERROR_MUST_SELECTED_TERMS_OF_USE = "suggest.message.youMustSelectTermsOfUse";
230 private static final String MESSAGE_ACCESS_DENIED = "suggest.message.accessDenied";
231
232
233
234
235 private static final String EMPTY_STRING = "";
236 private static final String CONSTANTE_PARAMETER_TRUE_VALUE = "1";
237 private static final String PATH_TYPE_VOTE_FOLDER = "skin/plugins/suggest/";
238 private static final String ACTION_VIEW_SUGGEST_LIST = "view_suggest_list";
239 private static final String ACTION_VIEW_SUGGEST_SUBMIT_LIST = "view_suggest_submit_list";
240 private static final String ACTION_CREATE_SUGGEST_SUBMIT = "create_suggest_submit";
241 private static final String ACTION_DO_CREATE_SUGGEST_SUBMIT = "do_create_suggest_submit";
242 private static final String ACTION_DO_CREATE_COMMENT = "do_create_comment";
243 private static final String ACTION_DO_CREATE_REPORT = "do_create_report";
244 private static final String ACTION_DO_VOTE = "do_vote";
245 private static final String ACTION_CREATE_REPORT = "create_report";
246 private static final String ACTION_CREATE_SUB_COMMENT = "create_sub_comment";
247 private static final String ACTION_SUBSCRIBE_SUGGEST = "subscribe_suggest";
248 private static final String ACTION_UNSUBSCRIBE_SUGGEST = "unsubscribe_suggest";
249 private static final String CONSTANT_VIEW_LIST_SUGGEST_SUBMIT = "view_suggest_submit_list";
250 private static final String CONSTANT_VIEW_SUGGEST_SUBMIT = "view_suggest_submit";
251 private static final String CONSTANT_VIEW_REPORT = "view_report";
252 private static final String CONSTANT_VIEW_CREATE_SUGGEST_SUBMIT = "view_create_suggest_submit";
253 private static final String CONSTANT_SUGGEST = "suggest";
254 private static final Pattern DO_VOTE_CASES = Pattern.compile( "-2|-1|1|2" );
255
256
257 private static final String SESSION_SEARCH_FIELDS = "search_fields";
258
259
260 private int _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_ITEM_PER_PAGE, 50 );
261 private Plugin _plugin;
262 private int _nIdSuggestSubmitStatePublish = SuggestUtils.CONSTANT_ID_NULL;
263 private UrlItem _urlSuggestXpageHome;
264 private int _nNumberShownCharacters = SuggestUtils.CONSTANT_ID_NULL;
265 private ISuggestSubmitService _suggestSubmitService = SuggestSubmitService.getService( );
266 private ICommentSubmitService _commentSubmitService = CommentSubmitService.getService( );
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283 public XPage getPage( HttpServletRequest request, int nMode, Plugin plugin ) throws UserNotSignedException, SiteMessageException
284 {
285 XPage page = new XPage( );
286 init( request, plugin );
287
288 if ( request.getParameter( PARAMETER_CLEAR_FILTER ) != null )
289 {
290
291 clearSessionFilter( request.getSession( ) );
292 }
293
294 String strAction = request.getParameter( PARAMETER_ACTION );
295
296 if ( ACTION_VIEW_SUGGEST_LIST.equals( strAction ) )
297 {
298 page = getViewSuggestList( page, nMode, request );
299 }
300 else
301 if ( ACTION_VIEW_SUGGEST_SUBMIT_LIST.equals( strAction ) )
302 {
303 page = getViewSuggestSubmitList( page, nMode, request );
304 }
305
306 else
307 if ( ACTION_VIEW_SUGGEST_SUBMIT.equals( strAction ) )
308 {
309 page = getViewSuggestSubmit( page, nMode, request );
310 }
311
312 else
313 if ( ACTION_CREATE_SUGGEST_SUBMIT.equals( strAction ) )
314 {
315 page = getViewCreateSuggestSubmit( page, nMode, request );
316 }
317 else
318 if ( ACTION_CREATE_REPORT.equals( strAction ) )
319 {
320 page = getViewCreateReport( page, nMode, request );
321 }
322 else
323 if ( ACTION_CREATE_SUB_COMMENT.equals( strAction ) )
324 {
325 page = getViewCreateSubComment( page, nMode, request );
326 }
327
328 else
329 if ( ACTION_DO_CREATE_SUGGEST_SUBMIT.equals( strAction ) )
330 {
331 doCreateSuggestSubmit( page, nMode, request );
332 page = getViewSuggestSubmitList( page, nMode, request );
333 }
334 else
335 if ( ACTION_DO_CREATE_COMMENT.equals( strAction ) )
336 {
337 doCreateComment( page, nMode, request );
338 page = getViewSuggestSubmit( page, nMode, request );
339 }
340 else
341 if ( ACTION_DO_CREATE_REPORT.equals( strAction ) )
342 {
343 doReport( page, nMode, request );
344 page = getViewSuggestSubmit( page, nMode, request );
345 }
346
347 else
348 if ( ACTION_DO_VOTE.equals( strAction ) )
349 {
350 doVote( page, nMode, request );
351
352 String strView = request.getParameter( PARAMETER_VIEW );
353
354 if ( ( strView != null ) && strView.equals( CONSTANT_VIEW_SUGGEST_SUBMIT ) )
355 {
356 page = getViewSuggestSubmit( page, nMode, request );
357 }
358 else
359 {
360 page = getViewSuggestSubmitList( page, nMode, request );
361 }
362 }
363 else
364 if ( ACTION_SUBSCRIBE_SUGGEST.equals( strAction ) )
365 {
366 doSubscribeSuggest( request );
367 }
368 else
369 if ( ACTION_UNSUBSCRIBE_SUGGEST.equals( strAction ) )
370 {
371 doUnsubscribeSuggest( request );
372 }
373 else
374 {
375 if ( ( request.getParameter( PARAMETER_ID_SUGGEST ) != null )
376 || ( SuggestService.getInstance( ).getIdDefaultSuggest( ) != SuggestUtils.CONSTANT_ID_NULL ) )
377 {
378 page = getViewSuggestSubmitList( page, nMode, request );
379 }
380 else
381 {
382 page = getViewSuggestList( page, nMode, request );
383 }
384 }
385
386 return page;
387 }
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404 public XPage getViewSuggestList( XPage page, int nMode, HttpServletRequest request ) throws UserNotSignedException, SiteMessageException
405 {
406 Map<String, Object> model = new HashMap<>( );
407 LuteceUser luteceUserConnected = SecurityService.getInstance( ).getRegisteredUser( request );
408
409 String strContentSuggest = EMPTY_STRING;
410 page.setTitle( I18nService.getLocalizedString( PROPERTY_XPAGE_PAGETITLE, getLocale( request ) ) );
411 page.setPathLabel( I18nService.getLocalizedString( PROPERTY_XPAGE_PATHLABEL, getLocale( request ) ) );
412
413
414 String strCurrentPageIndexSuggest = "";
415 strCurrentPageIndexSuggest = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, strCurrentPageIndexSuggest );
416
417 int nItemsPerPageSuggest = _nDefaultItemsPerPage;
418 nItemsPerPageSuggest = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, nItemsPerPageSuggest, _nDefaultItemsPerPage );
419
420 strContentSuggest = getHtmlListSuggest( getLocale( request ), _plugin, strCurrentPageIndexSuggest, nItemsPerPageSuggest, getNewUrlItemPage( ),
421 luteceUserConnected );
422
423 model.put( MARK_CONTENT_SUGGEST, strContentSuggest );
424
425 page.setContent( strContentSuggest );
426
427 return page;
428 }
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445 public XPage getViewSuggestSubmitList( XPage page, int nMode, HttpServletRequest request ) throws UserNotSignedException, SiteMessageException
446 {
447 String strIdSuggest = request.getParameter( PARAMETER_ID_SUGGEST );
448
449 int nIdSuggest = SuggestUtils.getIntegerParameter( strIdSuggest );
450 Suggest suggest = SuggestHome.findByPrimaryKey( nIdSuggest, _plugin );
451 LuteceUser luteceUserConnected = SecurityService.getInstance( ).getRegisteredUser( request );
452
453 Map<String, Object> model = new HashMap<>( );
454 model.put( MARK_VIEW, CONSTANT_VIEW_LIST_SUGGEST_SUBMIT );
455
456 if ( suggest == null )
457 {
458 suggest = SuggestHome.findByPrimaryKey( SuggestService.getInstance( ).getIdDefaultSuggest( ), _plugin );
459 }
460
461
462 testUserAuthorizationAccess( suggest, request, luteceUserConnected );
463
464 if ( luteceUserConnected != null )
465 {
466 model.put( MARK_LUTECE_USER_CONNECTED, luteceUserConnected );
467
468 String strIdFilterCategory = request.getParameter( PARAMETER_ID_FILTER_CATEGORY_SUGGEST );
469 int nIdCategory = -1;
470
471 if ( StringUtils.isNotEmpty( strIdFilterCategory ) && StringUtils.isNumeric( strIdFilterCategory ) )
472 {
473 nIdCategory = Integer.parseInt( strIdFilterCategory );
474 }
475
476 if ( nIdCategory > 0 )
477 {
478 model.put( MARK_USER_SUBSCRIBED,
479 SuggestSubscriptionProviderService.getService( ).hasUserSubscribedToSuggestCategory( luteceUserConnected, nIdCategory ) );
480 }
481 else
482 {
483 model.put( MARK_USER_SUBSCRIBED, SuggestSubscriptionProviderService.getService( ).hasUserSubscribedToSuggest( luteceUserConnected, nIdSuggest ) );
484 }
485 }
486
487 UrlItem urlSuggestXpage = getNewUrlItemPage( );
488 urlSuggestXpage.addParameter( PARAMETER_ACTION, CONSTANT_VIEW_LIST_SUGGEST_SUBMIT );
489 urlSuggestXpage.addParameter( PARAMETER_ID_SUGGEST, nIdSuggest );
490
491 SearchFields searchFields = getSearchFields( request );
492 addSuggestPageFrameset( getHtmlListSuggestSubmit( getLocale( request ), _plugin, suggest, searchFields, urlSuggestXpage, luteceUserConnected ),
493 request, page, suggest, model, searchFields, luteceUserConnected );
494
495 return page;
496 }
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513 public XPage getViewSuggestSubmit( XPage page, int nMode, HttpServletRequest request ) throws UserNotSignedException, SiteMessageException
514 {
515 Map<String, Object> model = new HashMap<>( );
516 LuteceUser luteceUserConnected = SecurityService.getInstance( ).getRegisteredUser( request );
517 String strIdSubmitSuggest = request.getParameter( PARAMETER_ID_SUBMIT_SUGGEST );
518 int nIdSubmitSuggest = SuggestUtils.getIntegerParameter( strIdSubmitSuggest );
519 SuggestSubmit suggestSubmit = _suggestSubmitService.findByPrimaryKey( nIdSubmitSuggest, true, _plugin );
520 suggestSubmit.setSuggest( SuggestHome.findByPrimaryKey( suggestSubmit.getSuggest( ).getIdSuggest( ), _plugin ) );
521
522
523 testUserAuthorizationAccess( suggestSubmit.getSuggest( ), request, luteceUserConnected );
524
525 model.put( MARK_VIEW, CONSTANT_VIEW_SUGGEST_SUBMIT );
526
527 SearchFields searchFields = getSearchFields( request );
528 addSuggestPageFrameset( getHtmlSuggestSubmitDetail( request, nMode, _plugin, suggestSubmit, luteceUserConnected ), request, page,
529 suggestSubmit.getSuggest( ), model, searchFields, luteceUserConnected );
530
531 return page;
532 }
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549 public XPage getViewCreateSuggestSubmit( XPage page, int nMode, HttpServletRequest request ) throws UserNotSignedException, SiteMessageException
550 {
551
552 LuteceUser luteceUserConnected = SecurityService.getInstance( ).getRegisteredUser( request );
553 String strIdSuggest = request.getParameter( PARAMETER_ID_SUGGEST );
554 int nIdSuggest = SuggestUtils.getIntegerParameter( strIdSuggest );
555 Suggest suggest = SuggestHome.findByPrimaryKey( nIdSuggest, _plugin );
556
557 if ( suggest.isActiveSuggestSubmitAuthentification( ) && SecurityService.isAuthenticationEnable( ) )
558 {
559 luteceUserConnected = SecurityService.getInstance( ).getRemoteUser( request );
560
561 if ( luteceUserConnected == null )
562 {
563 throw new UserNotSignedException( );
564 }
565
566
567 testUserAuthorizationAccess( suggest, request, luteceUserConnected );
568 }
569
570 Map<String, Object> model = new HashMap<>( );
571 model.put( MARK_VIEW, CONSTANT_VIEW_CREATE_SUGGEST_SUBMIT );
572
573 SearchFields searchFields = getSearchFields( request );
574 addSuggestPageFrameset( getHtmlForm( request, nMode, _plugin, suggest, searchFields.getIdFilterCategory( ) ), request, page, suggest, model,
575 searchFields, luteceUserConnected );
576
577 return page;
578 }
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595 public XPage getViewCreateSubComment( XPage page, int nMode, HttpServletRequest request ) throws UserNotSignedException, SiteMessageException
596 {
597
598 String strIdParentComment = request.getParameter( PARAMETER_COMMENT_ID_PARENT );
599 int nIdParentComment = SuggestUtils.getIntegerParameter( strIdParentComment );
600 LuteceUser luteceUserConnected = SecurityService.getInstance( ).getRegisteredUser( request );
601
602 String strIdSuggest = request.getParameter( PARAMETER_ID_SUGGEST );
603 int nIdSuggest = SuggestUtils.getIntegerParameter( strIdSuggest );
604 Suggest suggest = SuggestHome.findByPrimaryKey( nIdSuggest, _plugin );
605
606 if ( suggest.isActiveCommentAuthentification( ) && SecurityService.isAuthenticationEnable( ) )
607 {
608 luteceUserConnected = SecurityService.getInstance( ).getRemoteUser( request );
609
610 if ( luteceUserConnected == null )
611 {
612 throw new UserNotSignedException( );
613 }
614
615
616 testUserAuthorizationAccess( suggest, request, luteceUserConnected );
617 }
618
619 Map<String, Object> model = new HashMap<>( );
620
621 CaptchaSecurityService captchaSecurityService = new CaptchaSecurityService( );
622
623 if ( suggest != null && suggest.isActiveCaptcha( ) && PluginService.isPluginEnable( JCAPTCHA_PLUGIN ) )
624 {
625 model.put( MARK_JCAPTCHA, captchaSecurityService.getHtmlCode( ) );
626 }
627
628 model.put( MARK_LUTECE_USER_CONNECTED, luteceUserConnected );
629 model.put( MARK_ID_SUGGEST, strIdSuggest );
630 CommentSubmit commentSubmit = _commentSubmitService.findByPrimaryKey( nIdParentComment, _plugin );
631 model.put( MARK_COMMENT_SUBMIT, commentSubmit );
632 model.put( MARK_DISABLE_NEW_COMMENT_SUBMIT, suggest.isDisableNewComment( ) );
633 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_XPAGE_SUGGEST_SUB_COMMENT, getLocale( request ), model );
634 page.setTitle( I18nService.getLocalizedString( PROPERTY_XPAGE_PAGETITLE, getLocale( request ) ) );
635 page.setPathLabel( I18nService.getLocalizedString( PROPERTY_XPAGE_PATHLABEL, getLocale( request ) ) );
636 page.setContent( template.getHtml( ) );
637
638 return page;
639 }
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656 public XPage getViewCreateReport( XPage page, int nMode, HttpServletRequest request ) throws UserNotSignedException, SiteMessageException
657 {
658 Map<String, Object> model = new HashMap<>( );
659 LuteceUser luteceUserConnected = SecurityService.getInstance( ).getRegisteredUser( request );
660 String strIdSubmitSuggest = request.getParameter( PARAMETER_ID_SUBMIT_SUGGEST );
661 int nIdSubmitSuggest = SuggestUtils.getIntegerParameter( strIdSubmitSuggest );
662 SuggestSubmit suggestSubmit = _suggestSubmitService.findByPrimaryKey( nIdSubmitSuggest, true, _plugin );
663 suggestSubmit.setSuggest( SuggestHome.findByPrimaryKey( suggestSubmit.getSuggest( ).getIdSuggest( ), _plugin ) );
664 model.put( MARK_VIEW, CONSTANT_VIEW_REPORT );
665
666 SearchFields searchFields = getSearchFields( request );
667 addSuggestPageFrameset( getHtmlReported( request, nMode, _plugin, suggestSubmit ), request, page, suggestSubmit.getSuggest( ), model, searchFields,
668 luteceUserConnected );
669
670 return page;
671 }
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687 public void doCreateSuggestSubmit( XPage page, int nMode, HttpServletRequest request ) throws UserNotSignedException, SiteMessageException
688 {
689 String strIdSuggest = request.getParameter( PARAMETER_ID_SUGGEST );
690
691 int nIdSuggest = SuggestUtils.getIntegerParameter( strIdSuggest );
692 LuteceUser luteceUserConnected = null;
693
694 Suggest suggest = SuggestHome.findByPrimaryKey( nIdSuggest, _plugin );
695
696 if ( suggest.isActiveSuggestSubmitAuthentification( ) && SecurityService.isAuthenticationEnable( ) )
697 {
698 luteceUserConnected = SecurityService.getInstance( ).getRemoteUser( request );
699
700 if ( luteceUserConnected == null )
701 {
702 throw new UserNotSignedException( );
703 }
704
705
706 testUserAuthorizationAccess( suggest, request, luteceUserConnected );
707 }
708
709 String strIdCategory = request.getParameter( PARAMETER_ID_CATEGORY_SUGGEST );
710 String strIdType = request.getParameter( PARAMETER_ID_TYPE_SUGGEST );
711 String strMessage = MESSAGE_NEW_SUGGEST_SUBMIT;
712 int nIdCategory = SuggestUtils.getIntegerParameter( strIdCategory );
713 int nIdType = SuggestUtils.getIntegerParameter( strIdType );
714 String strTermsOfUse = request.getParameter( PARAMETER_TERMS_OF_USE );
715
716
717 if ( suggest.isEnableTermsOfUse( ) && ( strTermsOfUse == null ) )
718 {
719 SiteMessageService.setMessage( request, MESSAGE_ERROR_MUST_SELECTED_TERMS_OF_USE, SiteMessage.TYPE_STOP );
720 }
721
722
723 if ( !suggest.getCategories( ).isEmpty( ) )
724 {
725 if ( ( strIdCategory == null ) || strIdCategory.equals( Integer.toString( SuggestUtils.CONSTANT_ID_NULL ) ) )
726 {
727 SiteMessageService.setMessage( request, MESSAGE_ERROR_NO_CATEGORY, SiteMessage.TYPE_STOP );
728 }
729 }
730
731
732 if ( !suggest.getSuggestSubmitTypes( ).isEmpty( ) )
733 {
734 if ( ( strIdType == null ) || strIdType.equals( Integer.toString( SuggestUtils.CONSTANT_ID_NULL ) ) )
735 {
736 SiteMessageService.setMessage( request, MESSAGE_ERROR_NO_SUGGEST_SUBMIT_TYPE_SELECTED, SiteMessage.TYPE_STOP );
737 }
738 }
739
740 SuggestSubmit suggestSubmit = doInsertSuggestSubmit( request, nMode, _plugin, suggest, nIdCategory, nIdType, luteceUserConnected );
741
742
743 if ( WorkflowService.getInstance( ).isAvailable( ) && suggest.getIdWorkflow( ) > 0 )
744 {
745 SuggestWorkflowService.processActionOnSuggestSubmitCreation( suggest, suggestSubmit, luteceUserConnected );
746 }
747
748 if ( suggest.isDisableNewSuggestSubmit( ) )
749 {
750 strMessage = MESSAGE_NEW_SUGGEST_SUBMIT_DISABLE;
751 }
752
753 if ( suggest.isEnableMailNewSuggestSubmit( ) && ( suggest.getIdMailingListSuggestSubmit( ) != SuggestUtils.CONSTANT_ID_NULL ) )
754 {
755 SuggestUtils.sendNotificationNewSuggestSubmit( suggest, suggestSubmit, getLocale( request ), request );
756 }
757
758 Map<String, Object> parameters = new HashMap<>( );
759 parameters.put( PARAMETER_ID_SUGGEST, nIdSuggest );
760 parameters.put( PARAMETER_ACTION, CONSTANT_VIEW_LIST_SUGGEST_SUBMIT );
761
762 if ( !StringUtils.isEmpty( suggest.getConfirmationMessage( ) ) )
763 {
764 Object [ ] args = {
765 ( suggest.getConfirmationMessage( ) == null ) ? "" : suggest.getConfirmationMessage( )
766 };
767 SiteMessageService.setMessage( request, strMessage, args, null, getNewUrlItemPage( ).getUrl( ), null, SiteMessage.TYPE_INFO, parameters );
768 }
769 }
770
771
772
773
774
775
776
777
778
779
780 public void doSubscribeSuggest( HttpServletRequest request ) throws SiteMessageException
781 {
782 LuteceUser luteceUserConnected = SecurityService.getInstance( ).getRegisteredUser( request );
783 String strIdSubmitSuggest = request.getParameter( PARAMETER_ID_SUBMIT_SUGGEST );
784
785 UrlItem urlItem = new UrlItem( request.getRequestURL( ).toString( ) );
786 urlItem.addParameter( PARAMETER_PAGE, CONSTANT_SUGGEST );
787 urlItem.addParameter( PARAMETER_ID_SUGGEST, request.getParameter( PARAMETER_ID_SUGGEST ) );
788
789 if ( StringUtils.isNotEmpty( strIdSubmitSuggest ) )
790 {
791 int nIdSubmitSuggest = SuggestUtils.getIntegerParameter( strIdSubmitSuggest );
792 SuggestSubmit suggestSubmit = _suggestSubmitService.findByPrimaryKey( nIdSubmitSuggest, true, _plugin );
793
794 if ( suggestSubmit == null )
795 {
796 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
797
798 return;
799 }
800
801 SuggestSubscriptionProviderService.getService( ).createSuggestSubmitSubscription( luteceUserConnected, nIdSubmitSuggest );
802
803 urlItem.addParameter( PARAMETER_ID_SUBMIT_SUGGEST, strIdSubmitSuggest );
804 urlItem.addParameter( PARAMETER_ACTION, ACTION_VIEW_SUGGEST_SUBMIT );
805 }
806 else
807 {
808 String strIdFilterCategory = request.getParameter( PARAMETER_ID_FILTER_CATEGORY_SUGGEST );
809 int nIdCategory = -1;
810
811 if ( StringUtils.isNotEmpty( strIdFilterCategory ) && StringUtils.isNumeric( strIdFilterCategory ) )
812 {
813 nIdCategory = Integer.parseInt( strIdFilterCategory );
814 }
815
816 if ( nIdCategory > 0 )
817 {
818 if ( CategoryHome.findByPrimaryKey( nIdCategory, _plugin ) == null )
819 {
820 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
821
822 return;
823 }
824
825 SuggestSubscriptionProviderService.getService( ).createSuggestCategorySubscription( luteceUserConnected, nIdCategory );
826 urlItem.addParameter( PARAMETER_ID_FILTER_CATEGORY_SUGGEST, strIdFilterCategory );
827 }
828 else
829 {
830 String strIdSuggest = request.getParameter( PARAMETER_ID_SUGGEST );
831 int nIdSuggest = SuggestUtils.getIntegerParameter( strIdSuggest );
832
833 if ( SuggestHome.findByPrimaryKey( nIdSuggest, _plugin ) == null )
834 {
835 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
836
837 return;
838 }
839
840 SuggestSubscriptionProviderService.getService( ).createSuggestSubscription( luteceUserConnected, nIdSuggest );
841 }
842
843 urlItem.addParameter( PARAMETER_ACTION, ACTION_VIEW_SUGGEST_SUBMIT_LIST );
844 }
845
846 try
847 {
848 LocalVariables.getResponse( ).sendRedirect( urlItem.getUrl( ) );
849 }
850 catch( IOException e )
851 {
852 AppLogService.error( e.getMessage( ), e );
853 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
854 }
855 }
856
857
858
859
860
861
862
863
864
865
866 public void doUnsubscribeSuggest( HttpServletRequest request ) throws SiteMessageException
867 {
868 LuteceUser luteceUserConnected = SecurityService.getInstance( ).getRegisteredUser( request );
869 String strIdSubmitSuggest = request.getParameter( PARAMETER_ID_SUBMIT_SUGGEST );
870
871 UrlItem urlItem = new UrlItem( request.getRequestURL( ).toString( ) );
872 urlItem.addParameter( PARAMETER_PAGE, CONSTANT_SUGGEST );
873 urlItem.addParameter( PARAMETER_ID_SUGGEST, request.getParameter( PARAMETER_ID_SUGGEST ) );
874
875 if ( StringUtils.isNotEmpty( strIdSubmitSuggest ) )
876 {
877 int nIdSubmitSuggest = SuggestUtils.getIntegerParameter( strIdSubmitSuggest );
878 SuggestSubmit suggestSubmit = _suggestSubmitService.findByPrimaryKey( nIdSubmitSuggest, true, _plugin );
879
880 if ( suggestSubmit == null )
881 {
882 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
883
884 return;
885 }
886
887 SuggestSubscriptionProviderService.getService( ).removeSuggestSubmitSubscription( luteceUserConnected, nIdSubmitSuggest );
888
889 urlItem.addParameter( PARAMETER_ID_SUBMIT_SUGGEST, strIdSubmitSuggest );
890 urlItem.addParameter( PARAMETER_ACTION, ACTION_VIEW_SUGGEST_SUBMIT );
891 }
892 else
893 {
894 String strIdFilterCategory = request.getParameter( PARAMETER_ID_FILTER_CATEGORY_SUGGEST );
895 int nIdCategory = -1;
896
897 if ( StringUtils.isNotEmpty( strIdFilterCategory ) && StringUtils.isNumeric( strIdFilterCategory ) )
898 {
899 nIdCategory = Integer.parseInt( strIdFilterCategory );
900 }
901
902 if ( nIdCategory > 0 )
903 {
904 if ( CategoryHome.findByPrimaryKey( nIdCategory, _plugin ) == null )
905 {
906 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
907
908 return;
909 }
910
911 SuggestSubscriptionProviderService.getService( ).createSuggestCategorySubscription( luteceUserConnected, nIdCategory );
912 urlItem.addParameter( PARAMETER_ID_FILTER_CATEGORY_SUGGEST, strIdFilterCategory );
913 }
914 else
915 {
916 String strIdSuggest = request.getParameter( PARAMETER_ID_SUGGEST );
917 int nIdSuggest = SuggestUtils.getIntegerParameter( strIdSuggest );
918 Suggest suggest = SuggestHome.findByPrimaryKey( nIdSuggest, _plugin );
919
920 if ( suggest == null )
921 {
922 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
923
924 return;
925 }
926
927 SuggestSubscriptionProviderService.getService( ).removeSuggestSubscription( luteceUserConnected, nIdSuggest );
928 }
929
930 urlItem.addParameter( PARAMETER_ACTION, ACTION_VIEW_SUGGEST_SUBMIT_LIST );
931 }
932
933 try
934 {
935 LocalVariables.getResponse( ).sendRedirect( urlItem.getUrl( ) );
936 }
937 catch( IOException e )
938 {
939 AppLogService.error( e.getMessage( ), e );
940 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
941 }
942 }
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958 public void doCreateComment( XPage page, int nMode, HttpServletRequest request ) throws UserNotSignedException, SiteMessageException
959 {
960 String strIdSubmitSuggest = request.getParameter( PARAMETER_ID_SUBMIT_SUGGEST );
961 int nIdSubmitSuggest = SuggestUtils.getIntegerParameter( strIdSubmitSuggest );
962 SuggestSubmit suggestSubmit = _suggestSubmitService.findByPrimaryKey( nIdSubmitSuggest, true, _plugin );
963 Suggest suggest = null;
964
965 if ( suggestSubmit != null )
966 {
967 suggest = SuggestHome.findByPrimaryKey( suggestSubmit.getSuggest( ).getIdSuggest( ), _plugin );
968 suggestSubmit.setSuggest( suggest );
969 }
970
971 LuteceUser luteceUserConnected = null;
972
973 if ( ( suggest == null ) || ( suggestSubmit == null ) || !suggest.isAuthorizedComment( ) || suggestSubmit.isDisableComment( ) )
974 {
975 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
976
977 return;
978 }
979
980 if ( suggest.isActiveCommentAuthentification( ) && SecurityService.isAuthenticationEnable( ) )
981 {
982 luteceUserConnected = SecurityService.getInstance( ).getRemoteUser( request );
983
984 if ( luteceUserConnected == null )
985 {
986 throw new UserNotSignedException( );
987 }
988
989
990 testUserAuthorizationAccess( suggest, request, luteceUserConnected );
991 }
992
993 String strCommentValueSuggest = request.getParameter( PARAMETER_COMMENT_VALUE_SUGGEST );
994 String strMessage = MESSAGE_NEW_COMMENT_SUBMIT;
995 String strIdParentComment = request.getParameter( PARAMETER_COMMENT_ID_PARENT );
996 int nIdParentComment = SubmitFilter.ID_PARENT_NULL;
997
998 if ( ( strIdParentComment != null ) && ( !strIdParentComment.trim( ).equals( EMPTY_STRING ) ) )
999 {
1000 nIdParentComment = SuggestUtils.getIntegerParameter( strIdParentComment );
1001 }
1002
1003 if ( ( strCommentValueSuggest == null ) || strCommentValueSuggest.trim( ).equals( EMPTY_STRING ) )
1004 {
1005 SiteMessageService.setMessage( request, MESSAGE_MANDATORY_COMMENT, SiteMessage.TYPE_STOP );
1006 }
1007
1008 if ( suggest.isActiveCaptcha( ) && PluginService.isPluginEnable( JCAPTCHA_PLUGIN ) )
1009 {
1010 CaptchaSecurityService captchaSecurityService = new CaptchaSecurityService( );
1011
1012 if ( !captchaSecurityService.validate( request ) )
1013 {
1014 SiteMessageService.setMessage( request, MESSAGE_CAPTCHA_ERROR, SiteMessage.TYPE_STOP );
1015 }
1016 }
1017
1018 CommentSubmit commentSubmit = doInsertComment( request, suggestSubmit, strCommentValueSuggest, _plugin, luteceUserConnected, nIdParentComment );
1019
1020 if ( suggest.isEnableMailNewCommentSubmit( ) && ( suggest.getIdMailingListSuggestSubmit( ) != SuggestUtils.CONSTANT_ID_NULL ) )
1021 {
1022 SuggestUtils.sendNotificationNewCommentSubmit( suggest, commentSubmit, getLocale( request ), request );
1023 strMessage = MESSAGE_NEW_COMMENT_SUBMIT_DISABLE;
1024 }
1025
1026 if ( !StringUtils.isEmpty( suggest.getConfirmationMessage( ) ) )
1027 {
1028 Map<String, Object> parameters = new HashMap<>( );
1029
1030 parameters.put( PARAMETER_ID_SUBMIT_SUGGEST, nIdSubmitSuggest );
1031 parameters.put( PARAMETER_ID_SUGGEST, suggest.getIdSuggest( ) );
1032 parameters.put( PARAMETER_COMMENT_SUGGEST, CONSTANTE_PARAMETER_TRUE_VALUE );
1033 parameters.put( PARAMETER_ACTION, CONSTANT_VIEW_SUGGEST_SUBMIT );
1034
1035 Object [ ] args = {
1036 ( suggest.getConfirmationMessage( ) == null ) ? "" : suggest.getConfirmationMessage( )
1037 };
1038 SiteMessageService.setMessage( request, strMessage, args, null, getNewUrlItemPage( ).getUrl( ), null, SiteMessage.TYPE_INFO, parameters );
1039 }
1040 }
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057 public void doReport( XPage page, int nMode, HttpServletRequest request ) throws UserNotSignedException, SiteMessageException
1058 {
1059 String strIdSubmitSuggest = request.getParameter( PARAMETER_ID_SUBMIT_SUGGEST );
1060 int nIdSubmitSuggest = SuggestUtils.getIntegerParameter( strIdSubmitSuggest );
1061
1062 SuggestSubmit suggestSubmit = _suggestSubmitService.findByPrimaryKey( nIdSubmitSuggest, true, _plugin );
1063 Suggest suggest = null;
1064
1065 if ( suggestSubmit != null )
1066 {
1067 suggest = SuggestHome.findByPrimaryKey( suggestSubmit.getSuggest( ).getIdSuggest( ), _plugin );
1068 suggestSubmit.setSuggest( suggest );
1069 }
1070
1071 String strReportedValue = request.getParameter( PARAMETER_REPORTED_VALUE );
1072
1073 if ( ( strReportedValue == null ) || strReportedValue.trim( ).equals( EMPTY_STRING ) )
1074 {
1075 SiteMessageService.setMessage( request, MESSAGE_MANDATORY_REPORTED, SiteMessage.TYPE_STOP );
1076 }
1077
1078 if ( ( suggestSubmit == null ) || ( suggest == null ) || !suggest.isEnableReports( ) )
1079 {
1080 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
1081
1082 return;
1083 }
1084
1085 LuteceUser luteceUserConnected = null;
1086
1087 if ( suggest.isActiveCommentAuthentification( ) && SecurityService.isAuthenticationEnable( ) )
1088 {
1089 luteceUserConnected = SecurityService.getInstance( ).getRemoteUser( request );
1090
1091 if ( luteceUserConnected == null )
1092 {
1093 throw new UserNotSignedException( );
1094 }
1095
1096
1097 testUserAuthorizationAccess( suggest, request, luteceUserConnected );
1098 }
1099
1100 SuggestUtils.doReportSuggestSubmit( suggestSubmit, _plugin );
1101
1102 ReportedMessage/ReportedMessage.html#ReportedMessage">ReportedMessage reportedMessage = new ReportedMessage( );
1103 reportedMessage.setSuggestSubmit( suggestSubmit );
1104 reportedMessage.setValue( strReportedValue );
1105
1106 ReportedMessageHome.create( reportedMessage, _plugin );
1107
1108 if ( suggest.isEnableMailNewReportedSubmit( ) && ( suggest.getIdMailingListSuggestSubmit( ) != SuggestUtils.CONSTANT_ID_NULL ) )
1109 {
1110 SuggestUtils.sendNotificationNewReportedMessage( suggest, reportedMessage, getLocale( request ), request );
1111 }
1112
1113 Map<String, Object> parameters = new HashMap<>( );
1114 parameters.put( PARAMETER_ID_SUBMIT_SUGGEST, nIdSubmitSuggest );
1115 parameters.put( PARAMETER_ID_SUGGEST, suggest.getIdSuggest( ) );
1116 parameters.put( PARAMETER_ACTION, CONSTANT_VIEW_SUGGEST_SUBMIT );
1117
1118 UrlItem urlItemPage = getNewUrlItemPage( );
1119 urlItemPage.setAnchor( ANCHOR_SUGGEST_SUBMIT + nIdSubmitSuggest );
1120
1121 SiteMessageService.setMessage( request, MESSAGE_NEW_REPORTED_SUBMIT, null, null, urlItemPage.getUrl( ), null, SiteMessage.TYPE_INFO, parameters );
1122 }
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138 public void doVote( XPage page, int nMode, HttpServletRequest request ) throws UserNotSignedException, SiteMessageException
1139 {
1140 String strVote = request.getParameter( PARAMETER_VOTE_SUGGEST );
1141 String strIdSubmitSuggest = request.getParameter( PARAMETER_ID_SUBMIT_SUGGEST );
1142 int nIdSubmitSuggest = SuggestUtils.getIntegerParameter( strIdSubmitSuggest );
1143 SuggestSubmit suggestSubmit = _suggestSubmitService.findByPrimaryKey( nIdSubmitSuggest, true, _plugin );
1144 Suggest suggest = SuggestHome.findByPrimaryKey( suggestSubmit.getSuggest( ).getIdSuggest( ), _plugin );
1145 suggestSubmit.setSuggest( suggest );
1146
1147 LuteceUser luteceUserConnected = null;
1148
1149 if ( suggest.isLimitNumberVote( ) )
1150 {
1151 if ( suggest.isActiveVoteAuthentification( ) && SecurityService.isAuthenticationEnable( ) )
1152 {
1153 luteceUserConnected = SecurityService.getInstance( ).getRemoteUser( request );
1154
1155 if ( luteceUserConnected == null )
1156 {
1157 throw new UserNotSignedException( );
1158 }
1159 else
1160 if ( ( suggest.getRole( ) != null ) && !SecurityService.getInstance( ).isUserInRole( request, suggest.getRole( ) ) )
1161 {
1162 SiteMessageService.setMessage( request, MESSAGE_ACCESS_DENIED, SiteMessage.TYPE_STOP );
1163 }
1164
1165 if ( VoteHome.getUserNumberVoteOnSuggestSubmit( nIdSubmitSuggest, luteceUserConnected.getName( ), _plugin ) == 0 )
1166 {
1167 doVote( strVote, nIdSubmitSuggest, _plugin, luteceUserConnected.getName( ) );
1168 }
1169 }
1170 else
1171 if ( request.getSession( ).getAttribute( EMPTY_STRING + nIdSubmitSuggest ) == null )
1172 {
1173 doVote( strVote, nIdSubmitSuggest, _plugin, null );
1174 request.getSession( ).setAttribute( EMPTY_STRING + nIdSubmitSuggest, PARAMETER_VOTED );
1175 }
1176 }
1177 else
1178 {
1179 doVote( strVote, nIdSubmitSuggest, _plugin, null );
1180 }
1181 }
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195 private void doVote( String strVote, int nIdSubmitSuggest, Plugin plugin, String strUserKey )
1196 {
1197
1198 int nScore;
1199
1200 if ( ( strVote != null ) && DO_VOTE_CASES.matcher( strVote ).find( ) )
1201 {
1202 nScore = Integer.parseInt( strVote );
1203 SuggestUtils.doVoteSuggestSubmit( nIdSubmitSuggest, nScore, strUserKey, plugin );
1204 }
1205
1206 }
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227 private String getHtmlListSuggestSubmit( Locale locale, Plugin plugin, Suggest suggest, SearchFields searchFields, UrlItem urlSuggestXPage,
1228 LuteceUser luteceUserConnected )
1229 {
1230 Map<String, Object> model = new HashMap<>( );
1231
1232 List<Integer> listIdSuggestSubmit;
1233
1234 SubmitFiltersiness/SubmitFilter.html#SubmitFilter">SubmitFilter submitFilter = new SubmitFilter( );
1235
1236
1237 SuggestUtils.initSubmitFilterByPeriod( submitFilter, searchFields.getIdFilterPeriod( ) );
1238 SuggestUtils.initSubmitFilterBySort(
1239 submitFilter,
1240 ( searchFields.getIdSuggestSubmitSort( ) != SuggestUtils.CONSTANT_ID_NULL ) ? searchFields.getIdSuggestSubmitSort( ) : suggest
1241 .getIdDefaultSort( ) );
1242
1243 SuggestUtils.initSubmitFilterBySort( submitFilter, SubmitFilter.SORT_BY_PINNED_FIRST );
1244
1245 submitFilter.setIdSuggest( suggest.getIdSuggest( ) );
1246
1247 submitFilter.setIdSuggestSubmitState( _nIdSuggestSubmitStatePublish );
1248 submitFilter.setIdCategory( searchFields.getIdFilterCategory( ) );
1249 submitFilter.setIdType( searchFields.getIdFilterSuggestSubmitType( ) );
1250 submitFilter.setLuteceUserKey( searchFields.getLuteceUserName( ) );
1251
1252 listIdSuggestSubmit = SuggestSearchService.getInstance( ).getSearchResults( searchFields.getQuery( ), submitFilter, plugin );
1253
1254 if ( suggest.isActiveSuggestSubmitPaginator( ) && ( suggest.getNumberSuggestSubmitPerPage( ) > 0 ) )
1255 {
1256 Paginator<Integer> paginator = new Paginator<>( listIdSuggestSubmit, suggest.getNumberSuggestSubmitPerPage( ), urlSuggestXPage.getUrl( ),
1257 PARAMETER_FILTER_PAGE_INDEX, searchFields.getPageIndex( ) );
1258 listIdSuggestSubmit = paginator.getPageItems( );
1259 model.put( MARK_PAGINATOR, paginator );
1260 }
1261
1262 model.put( MARK_SUGGEST, suggest );
1263 model.put( MARK_LIST_SUGGEST_SUBMIT, getSuggestSubmitDisplayList( listIdSuggestSubmit, suggest, locale, plugin ) );
1264
1265 model.put( MARK_AUTHORIZED_COMMENT, suggest.isAuthorizedComment( ) );
1266 model.put( MARK_AUTHORIZED_VOTE, !suggest.isDisableVote( ) );
1267 model.put( MARK_DISPLAY_COMMENT_IN_LIST, suggest.isDisplayCommentInSuggestSubmitList( ) );
1268 model.put( MARK_ENABLE_SUGGEST_REPORTS, suggest.isEnableReports( ) );
1269 model.put( MARK_ID_SUGGEST, suggest.getIdSuggest( ) );
1270
1271 if ( suggest.isAuthorizedComment( ) )
1272 {
1273 model.put( MARK_MAX_AMOUNT_COMMENTS, suggest.getNumberCommentDisplayInSuggestSubmitList( ) );
1274 model.put( MARK_MAX_AMOUNT_COMMENTS_CHAR, suggest.getNumberCharCommentDisplayInSuggestSubmitList( ) );
1275 }
1276
1277 model.put( MARK_LUTECE_USER_CONNECTED, luteceUserConnected );
1278 model.put( MARK_IS_EXTEND_INSTALLED, PortalService.isExtendActivated( ) );
1279
1280 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_XPAGE_LIST_SUBMIT_SUGGEST, locale, model );
1281
1282 return template.getHtml( );
1283 }
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302 private String getHtmlListSuggest( Locale locale, Plugin plugin, String strCurrentPageIndexSuggest, int nItemsPerPageSuggest, UrlItem urlSuggestXPage,
1303 LuteceUser luteceUserConnected )
1304 {
1305 SuggestFilterst/business/SuggestFilter.html#SuggestFilter">SuggestFilter filter = new SuggestFilter( );
1306 filter.setIdState( Suggest.STATE_ENABLE );
1307
1308 List<Suggest> listSuggest = SuggestHome.getSuggestList( filter, plugin );
1309 HashMap<String, Object> model = new HashMap<>( );
1310 Paginator<Suggest> paginator = new Paginator<>( listSuggest, nItemsPerPageSuggest, urlSuggestXPage.getUrl( ), PARAMETER_PAGE_INDEX,
1311 strCurrentPageIndexSuggest );
1312
1313 model.put( MARK_PAGINATOR, paginator );
1314 model.put( MARK_NB_ITEMS_PER_PAGE, EMPTY_STRING + nItemsPerPageSuggest );
1315
1316 model.put( MARK_SUGGEST_LIST, paginator.getPageItems( ) );
1317 model.put( MARK_LUTECE_USER_CONNECTED, luteceUserConnected );
1318
1319 HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_XPAGE_LIST_SUGGEST, locale, model );
1320
1321 return templateList.getHtml( );
1322 }
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337 private Collection<HashMap> getSuggestSubmitDisplayList( Collection<Integer> listSuggestSubmit, Suggest suggest, Locale locale, Plugin plugin )
1338 {
1339 SuggestUserInfo luteceUserInfo;
1340 SuggestSubmit suggestSubmit;
1341 Collection<HashMap> listHashSuggest = new ArrayList<>( );
1342
1343 for ( Integer idSuggestSubmit : listSuggestSubmit )
1344 {
1345 HashMap<String, Object> modelSuggest = new HashMap<>( );
1346
1347 luteceUserInfo = null;
1348 suggestSubmit = _suggestSubmitService.findByPrimaryKey( idSuggestSubmit,
1349 ( suggest.isAuthorizedComment( ) && suggest.isDisplayCommentInSuggestSubmitList( ) ),
1350 suggest.getNumberCommentDisplayInSuggestSubmitList( ), plugin );
1351 modelSuggest.put( MARK_SUGGEST_SUBMIT, suggestSubmit );
1352
1353 if ( SecurityService.isAuthenticationEnable( ) && ( suggestSubmit.getLuteceUserKey( ) != null ) )
1354 {
1355 luteceUserInfo = SuggestUserInfoService.getService( ).findSuggestUserInfoByKey( suggestSubmit.getLuteceUserKey( ), plugin );
1356 }
1357
1358 modelSuggest.put( MARK_LUTECE_USER, luteceUserInfo );
1359 SuggestUtils.addAvatarToModel( modelSuggest, luteceUserInfo );
1360
1361 if ( !suggest.isDisableVote( ) )
1362 {
1363 modelSuggest.put( MARK_SUGGEST_SUBMIT_VOTE_TYPE,
1364 getHtmlSuggestSubmitVoteType( suggest, suggestSubmit, CONSTANT_VIEW_LIST_SUGGEST_SUBMIT, locale ) );
1365 }
1366
1367 listHashSuggest.add( modelSuggest );
1368 }
1369
1370 return listHashSuggest;
1371 }
1372
1373
1374
1375
1376
1377
1378
1379
1380 private Collection<HashMap> getCommentSubmitDisplayList( Collection<CommentSubmit> listCommentSubmit, Plugin plugin )
1381 {
1382 Collection<HashMap> listHashComment = new ArrayList<>( );
1383 SuggestUserInfo luteceUserInfo;
1384
1385 for ( CommentSubmit commentSubmit : listCommentSubmit )
1386 {
1387 HashMap<String, Object> modelComment = new HashMap<>( );
1388
1389 luteceUserInfo = null;
1390
1391 modelComment.put( MARK_COMMENT_SUBMIT, commentSubmit );
1392
1393 if ( SecurityService.isAuthenticationEnable( ) && ( commentSubmit.getLuteceUserKey( ) != null ) )
1394 {
1395 luteceUserInfo = SuggestUserInfoService.getService( ).findSuggestUserInfoByKey( commentSubmit.getLuteceUserKey( ), plugin );
1396 }
1397
1398 modelComment.put( MARK_LUTECE_USER, luteceUserInfo );
1399 SuggestUtils.addAvatarToModel( modelComment, luteceUserInfo );
1400
1401 modelComment.put(
1402 MARK_LIST_SUB_COMMENT_SUBMIT_SUGGEST,
1403 ( ( commentSubmit.getComments( ) != null ) && !commentSubmit.getComments( ).isEmpty( ) ) ? getCommentSubmitDisplayList(
1404 commentSubmit.getComments( ), plugin ) : null );
1405
1406 listHashComment.add( modelComment );
1407 }
1408
1409 return listHashComment;
1410 }
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431 private String getHtmlSuggestSubmitDetail( HttpServletRequest request, int nMode, Plugin plugin, SuggestSubmit suggestSubmit, LuteceUser luteceUserConnected )
1432 throws SiteMessageException
1433 {
1434 SuggestUserInfo luteceUserInfo = null;
1435 HashMap<String, Object> model = new HashMap<>( );
1436
1437 if ( ( suggestSubmit == null ) || ( suggestSubmit.getSuggestSubmitState( ).getNumber( ) == SuggestSubmit.STATE_DISABLE ) )
1438 {
1439 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
1440
1441 return null;
1442 }
1443
1444
1445 suggestSubmit.setNumberView( suggestSubmit.getNumberView( ) + 1 );
1446 _suggestSubmitService.update( suggestSubmit, false, plugin );
1447
1448 if ( SecurityService.isAuthenticationEnable( ) && ( suggestSubmit.getLuteceUserKey( ) != null ) )
1449 {
1450 luteceUserInfo = SuggestUserInfoService.getService( ).findSuggestUserInfoByKey( suggestSubmit.getLuteceUserKey( ), plugin );
1451 }
1452
1453 if ( luteceUserConnected != null )
1454 {
1455 model.put( MARK_USER_SUBSCRIBED,
1456 SuggestSubscriptionProviderService.getService( )
1457 .hasUserSubscribedToSuggestSubmit( luteceUserConnected, suggestSubmit.getIdSuggestSubmit( ) ) );
1458 }
1459
1460 model.put( MARK_ID_SUGGEST, suggestSubmit.getSuggest( ).getIdSuggest( ) );
1461 model.put( MARK_SUGGEST_SUBMIT, suggestSubmit );
1462 model.put( MARK_LUTECE_USER, luteceUserInfo );
1463 SuggestUtils.addAvatarToModel( model, luteceUserInfo );
1464
1465 model.put( MARK_LUTECE_USER_CONNECTED, luteceUserConnected );
1466 model.put( MARK_SUGGEST_SUBMIT_VOTE_TYPE,
1467 getHtmlSuggestSubmitVoteType( suggestSubmit.getSuggest( ), suggestSubmit, CONSTANT_VIEW_SUGGEST_SUBMIT, getLocale( request ) ) );
1468
1469 model.put( MARK_AUTHORIZED_COMMENT, suggestSubmit.getSuggest( ).isAuthorizedComment( ) );
1470 model.put( MARK_AUTHORIZED_VOTE, !suggestSubmit.getSuggest( ).isDisableVote( ) );
1471 model.put( MARK_ENABLE_SUGGEST_REPORTS, suggestSubmit.getSuggest( ).isEnableReports( ) );
1472 model.put( MARK_IS_EXTEND_INSTALLED, PortalService.isExtendActivated( ) );
1473
1474 if ( suggestSubmit.getSuggest( ).isAuthorizedComment( ) && !suggestSubmit.isDisableComment( ) )
1475 {
1476 model.put(
1477 MARK_LIST_COMMENT_SUBMIT_SUGGEST,
1478 getHtmlCommentSubmitList( request, suggestSubmit.getComments( ), suggestSubmit.getSuggest( ), suggestSubmit.getIdSuggestSubmit( ),
1479 luteceUserConnected, plugin ) );
1480 }
1481 CaptchaSecurityService captchaSecurityService = new CaptchaSecurityService( );
1482
1483 if ( suggestSubmit.getSuggest( ).isActiveCaptcha( ) && PluginService.isPluginEnable( JCAPTCHA_PLUGIN ) )
1484 {
1485 model.put( MARK_JCAPTCHA, captchaSecurityService.getHtmlCode( ) );
1486 }
1487
1488 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_XPAGE_DETAIL_SUBMIT_SUGGEST, getLocale( request ), model );
1489
1490 return template.getHtml( );
1491 }
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508 private String getHtmlSuggestSubmitVoteType( Suggest suggest, SuggestSubmit suggestSubmit, String strView, Locale locale )
1509 {
1510 if ( !suggest.isDisableVote( ) && !suggestSubmit.isDisableVote( ) )
1511 {
1512 VoteType voteType = VoteTypeHome.findByPrimaryKey( suggest.getVoteType( ).getIdVoteType( ), _plugin );
1513
1514 String strFilePath = PATH_TYPE_VOTE_FOLDER + voteType.getTemplateFileName( );
1515 HashMap<String, Object> model = new HashMap<>( );
1516 model.put( MARK_ID_SUGGEST, suggest.getIdSuggest( ) );
1517 model.put( MARK_ID_SUGGEST_SUBMIT, suggestSubmit.getIdSuggestSubmit( ) );
1518 model.put( MARK_VIEW, strView );
1519
1520 HtmlTemplate template = AppTemplateService.getTemplate( strFilePath, locale, model );
1521
1522 return template.getHtml( );
1523 }
1524
1525 return null;
1526 }
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544 private String getHtmlReported( HttpServletRequest request, int nMode, Plugin plugin, SuggestSubmit suggestSubmit ) throws SiteMessageException
1545 {
1546 HashMap<String, Object> model = new HashMap<>( );
1547
1548 if ( ( suggestSubmit == null ) || ( suggestSubmit.getSuggestSubmitState( ).getNumber( ) == SuggestSubmit.STATE_DISABLE ) )
1549 {
1550 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
1551
1552 return null;
1553 }
1554
1555 model.put( MARK_ID_SUGGEST, suggestSubmit.getSuggest( ).getIdSuggest( ) );
1556 model.put( MARK_SUGGEST_SUBMIT, suggestSubmit );
1557
1558 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_XPAGE_SUGGEST_REPORTED, getLocale( request ), model );
1559
1560 return template.getHtml( );
1561 }
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580 private String getHtmlCommentSubmitList( HttpServletRequest request, List<CommentSubmit> listCommentSubmit, Suggest suggest, int nIdSubmitSuggest,
1581 LuteceUser luteceUserConnected, Plugin plugin )
1582 {
1583 HashMap<String, Object> model = new HashMap<>( );
1584
1585 model.put( MARK_SUGGEST, suggest );
1586 model.put( MARK_ID_SUGGEST, suggest.getIdSuggest( ) );
1587 model.put( MARK_ID_SUGGEST_SUBMIT, nIdSubmitSuggest );
1588 model.put( MARK_SUGGEST_COMMENT, CONSTANTE_PARAMETER_TRUE_VALUE );
1589 model.put( MARK_LIST_COMMENT_SUBMIT_SUGGEST, getCommentSubmitDisplayList( listCommentSubmit, plugin ) );
1590 model.put( MARK_DISABLE_NEW_COMMENT_SUBMIT, suggest.isDisableNewComment( ) );
1591 model.put( MARK_ACTIVE_EDITOR_BBCODE, suggest.isActiveEditorBbcode( ) );
1592 model.put( MARK_LUTECE_USER_CONNECTED, luteceUserConnected );
1593
1594 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_XPAGE_COMMENT_SUBMIT_SUGGEST, getLocale( request ), model );
1595
1596 return template.getHtml( );
1597 }
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616 private String getHtmlForm( HttpServletRequest request, int nMode, Plugin plugin, Suggest suggest, int nIdDefaultCategory ) throws SiteMessageException
1617 {
1618 Map<String, Object> model = SuggestUtils.getModelHtmlForm( suggest, plugin, getLocale( request ), nIdDefaultCategory, false );
1619
1620
1621 model.put( MARK_DISABLE_NEW_SUGGEST_SUBMIT, suggest.isDisableNewSuggestSubmit( ) );
1622
1623 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_XPAGE_FORM_SUGGEST, getLocale( request ), model );
1624
1625 return template.getHtml( );
1626 }
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649 private SuggestSubmit doInsertSuggestSubmit( HttpServletRequest request, int nMode, Plugin plugin, Suggest suggest, int nIdCategory, int nIdType,
1650 LuteceUser user ) throws SiteMessageException
1651 {
1652 Locale locale = getLocale( request );
1653 List<Response> listResponse = new ArrayList<>( );
1654
1655 if ( suggest.isActiveCaptcha( ) && PluginService.isPluginEnable( JCAPTCHA_PLUGIN ) )
1656 {
1657 CaptchaSecurityService captchaSecurityService = new CaptchaSecurityService( );
1658
1659 if ( !captchaSecurityService.validate( request ) )
1660 {
1661 SiteMessageService.setMessage( request, MESSAGE_CAPTCHA_ERROR, SiteMessage.TYPE_STOP );
1662 }
1663 }
1664
1665 SuggestSubmitness/SuggestSubmit.html#SuggestSubmit">SuggestSubmit suggestSubmit = new SuggestSubmit( );
1666 suggestSubmit.setSuggest( suggest );
1667 suggestSubmit.setResponses( listResponse );
1668
1669 FormError formError = SuggestUtils.getAllResponsesData( request, suggestSubmit, plugin, locale );
1670
1671 if ( formError != null )
1672 {
1673 if ( formError.isMandatoryError( ) )
1674 {
1675 Object [ ] tabRequiredFields = {
1676 formError.getTitleQuestion( )
1677 };
1678 SiteMessageService.setMessage( request, MESSAGE_MANDATORY_QUESTION, tabRequiredFields, SiteMessage.TYPE_STOP );
1679 }
1680 else
1681 {
1682 Object [ ] tabFormError = {
1683 formError.getTitleQuestion( ), formError.getErrorMessage( )
1684 };
1685 SiteMessageService.setMessage( request, MESSAGE_FORM_ERROR, tabFormError, SiteMessage.TYPE_STOP );
1686 }
1687 }
1688
1689
1690 if ( nIdCategory != SuggestUtils.CONSTANT_ID_NULL )
1691 {
1692 Category category = CategoryHome.findByPrimaryKey( nIdCategory, plugin );
1693 suggestSubmit.setCategory( category );
1694 }
1695
1696 if ( nIdType != SuggestUtils.CONSTANT_ID_NULL )
1697 {
1698 SuggestSubmitType type = SuggestSubmitTypeHome.findByPrimaryKey( nIdType, plugin );
1699 suggestSubmit.setSuggestSubmitType( type );
1700 }
1701
1702 if ( user != null )
1703 {
1704 suggestSubmit.setLuteceUserKey( user.getName( ) );
1705
1706 SuggestUserInfoService.getService( ).updateSuggestUserInfoByLuteceUser( user, plugin );
1707 }
1708
1709 try
1710 {
1711 _suggestSubmitService.create( suggestSubmit, plugin, locale, user );
1712 }
1713 catch( Exception ex )
1714 {
1715
1716 AppLogService.error( ex.getMessage( ) + " for SuggestSubmit " + suggestSubmit.getIdSuggestSubmit( ), ex );
1717
1718
1719
1720 _suggestSubmitService.remove( suggestSubmit.getIdSuggestSubmit( ), plugin, user );
1721
1722 SiteMessageService.setMessage( request, MESSAGE_MESSAGE_SUBMIT_SAVE_ERROR, SiteMessage.TYPE_ERROR );
1723 }
1724
1725 return suggestSubmit;
1726 }
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748 public CommentSubmit doInsertComment( HttpServletRequest request, SuggestSubmit suggestSubmit, String strCommentValueSuggest, Plugin plugin,
1749 LuteceUser user, int nIdParentComment ) throws SiteMessageException
1750 {
1751 CommentSubmitness/CommentSubmit.html#CommentSubmit">CommentSubmit commentSubmit = new CommentSubmit( );
1752
1753 if ( ( suggestSubmit == null ) || ( suggestSubmit.getSuggestSubmitState( ).getNumber( ) == SuggestSubmit.STATE_DISABLE ) )
1754 {
1755 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
1756
1757 return null;
1758 }
1759
1760 suggestSubmit.setNumberComment( suggestSubmit.getNumberComment( ) + 1 );
1761
1762 if ( !suggestSubmit.getSuggest( ).isDisableNewComment( ) )
1763 {
1764 commentSubmit.setActive( true );
1765 suggestSubmit.setNumberCommentEnable( suggestSubmit.getNumberCommentEnable( ) + 1 );
1766 }
1767
1768 _suggestSubmitService.update( suggestSubmit, plugin );
1769
1770 commentSubmit.setDateComment( SuggestUtils.getCurrentDate( ) );
1771 commentSubmit.setSuggestSubmit( suggestSubmit );
1772 commentSubmit.setValue( strCommentValueSuggest );
1773 commentSubmit.setOfficialAnswer( false );
1774 commentSubmit.setIdParent( nIdParentComment );
1775
1776 if ( user != null )
1777 {
1778 commentSubmit.setLuteceUserKey( user.getName( ) );
1779
1780 SuggestUserInfoService.getService( ).updateSuggestUserInfoByLuteceUser( user, plugin );
1781 }
1782
1783 _commentSubmitService.create( commentSubmit, plugin );
1784
1785 return commentSubmit;
1786 }
1787
1788
1789
1790
1791
1792
1793
1794 private void clearSessionFilter( HttpSession session )
1795 {
1796 session.setAttribute( SESSION_SEARCH_FIELDS, null );
1797 }
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808 public void init( HttpServletRequest request, Plugin plugin )
1809 {
1810 _plugin = plugin;
1811
1812 if ( _nIdSuggestSubmitStatePublish == SuggestUtils.CONSTANT_ID_NULL )
1813 {
1814 SuggestSubmitState suggestSubmitStatePublish = SuggestSubmitStateHome.findByNumero( SuggestSubmit.STATE_PUBLISH, plugin );
1815
1816 if ( suggestSubmitStatePublish != null )
1817 {
1818 _nIdSuggestSubmitStatePublish = suggestSubmitStatePublish.getIdSuggestSubmitState( );
1819 }
1820 }
1821
1822 String strPortalUrl = AppPathService.getPortalUrl( );
1823
1824 if ( _urlSuggestXpageHome == null )
1825 {
1826 _urlSuggestXpageHome = new UrlItem( strPortalUrl );
1827 _urlSuggestXpageHome.addParameter( XPageAppService.PARAM_XPAGE_APP, AppPropertiesService.getProperty( PROPERTY_PAGE_APPLICATION_ID ) );
1828 }
1829
1830 if ( _nNumberShownCharacters == SuggestUtils.CONSTANT_ID_NULL )
1831 {
1832 _nNumberShownCharacters = AppPropertiesService.getPropertyInt( PROPERTY_NUMBER_SUGGEST_SUBMIT_VALUE_SHOWN_CHARACTERS, 100 );
1833 }
1834 }
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844 private SearchFields getSearchFields( HttpServletRequest request )
1845 {
1846 HttpSession session = request.getSession( );
1847 String strQuery = request.getParameter( PARAMETER_QUERY );
1848 String strIdFilterPeriod = request.getParameter( PARAMETER_ID_FILTER_PERIOD );
1849 String strIdSuggestSubmitSort = request.getParameter( PARAMETER_ID_SUGGEST_SUBMIT_SORT );
1850 String strIdFilterCategory = request.getParameter( PARAMETER_ID_FILTER_CATEGORY_SUGGEST );
1851 String strFilterPageIndex = request.getParameter( PARAMETER_FILTER_PAGE_INDEX );
1852 String strIdFilterSuggestSubmitType = request.getParameter( PARAMETER_ID_FILTER_SUGGEST_SUBMIT_TYPE );
1853 String strLuteceUserName = request.getParameter( PARAMETER_LUTECE_USER_NAME_FILTER );
1854
1855 int nIdFilterPeriod = SuggestUtils.getIntegerParameter( strIdFilterPeriod );
1856 int nIdSuggestSubmitSort = SuggestUtils.getIntegerParameter( strIdSuggestSubmitSort );
1857 int nIdFilterCategory = SuggestUtils.getIntegerParameter( strIdFilterCategory );
1858 int nIdFilterSuggestSubmitType = SuggestUtils.getIntegerParameter( strIdFilterSuggestSubmitType );
1859
1860 SearchSearchFieldsearchFields = ( session.getAttribute( SESSION_SEARCH_FIELDS ) != null ) ? (SearchFields) session.getAttribute( SESSION_SEARCH_FIELDS )
1861 : new SearchFields( );
1862 searchFields.setQuery( ( strQuery != null ) ? strQuery : searchFields.getQuery( ) );
1863
1864 searchFields.setIdFilterPeriod( ( strIdFilterPeriod != null ) ? nIdFilterPeriod : searchFields.getIdFilterPeriod( ) );
1865 searchFields.setIdSuggestSubmitSort( ( strIdSuggestSubmitSort != null ) ? nIdSuggestSubmitSort : searchFields.getIdSuggestSubmitSort( ) );
1866 searchFields.setIdFilterCategory( ( strIdFilterCategory != null ) ? nIdFilterCategory : searchFields.getIdFilterCategory( ) );
1867 searchFields.setIdFilterSuggestSubmitType( ( strIdFilterSuggestSubmitType != null ) ? nIdFilterSuggestSubmitType : searchFields
1868 .getIdFilterSuggestSubmitType( ) );
1869 searchFields.setPageIndex( ( strFilterPageIndex != null ) ? strFilterPageIndex : searchFields.getPageIndex( ) );
1870
1871 searchFields.setLuteceUserName( ( strLuteceUserName != null ) ? strLuteceUserName : searchFields.getLuteceUserName( ) );
1872
1873
1874 session.setAttribute( SESSION_SEARCH_FIELDS, searchFields );
1875
1876 return searchFields;
1877 }
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896 private void addSuggestPageFrameset( String strContentSuggest, HttpServletRequest request, XPage page, Suggest suggest, Map<String, Object> model,
1897 SearchFields searchFields, LuteceUser luteceUserConnected )
1898 {
1899 page.setTitle( I18nService.getLocalizedString( PROPERTY_XPAGE_PAGETITLE, getLocale( request ) ) );
1900 page.setPathLabel( I18nService.getLocalizedString( PROPERTY_XPAGE_PATHLABEL, getLocale( request ) ) );
1901
1902 if ( suggest.isActive( ) )
1903 {
1904
1905 if ( suggest.isAuthorizedComment( ) && suggest.isShowTopCommentBlock( ) )
1906 {
1907 SubmitFilteritFilter.html#SubmitFilter">SubmitFilter submmitFilterTopComment = new SubmitFilter( );
1908 submmitFilterTopComment.setIdSuggest( suggest.getIdSuggest( ) );
1909 submmitFilterTopComment.setIdSuggestSubmitState( _nIdSuggestSubmitStatePublish );
1910 submmitFilterTopComment.setIdCategory( searchFields.getIdFilterCategory( ) );
1911
1912 SuggestUtils.initSubmitFilterBySort( submmitFilterTopComment, SubmitFilter.SORT_BY_NUMBER_COMMENT_DESC );
1913
1914 List<SuggestSubmit> listSuggestSubmitTopComment = _suggestSubmitService.getSuggestSubmitList( submmitFilterTopComment, _plugin,
1915 suggest.getNumberSuggestSubmitInTopComment( ) );
1916 model.put( MARK_LIST_SUBMIT_TOP_COMMENT, listSuggestSubmitTopComment );
1917 }
1918
1919
1920 if ( suggest.isShowTopScoreBlock( ) )
1921 {
1922 SubmitFilterilter.html#SubmitFilter">SubmitFilter submmitFilterTopPopularity = new SubmitFilter( );
1923 submmitFilterTopPopularity.setIdSuggest( suggest.getIdSuggest( ) );
1924
1925 SuggestUtils.initSubmitFilterBySort( submmitFilterTopPopularity, SubmitFilter.SORT_BY_SCORE_DESC );
1926
1927 submmitFilterTopPopularity.setIdSuggestSubmitState( _nIdSuggestSubmitStatePublish );
1928 submmitFilterTopPopularity.setIdCategory( searchFields.getIdFilterCategory( ) );
1929
1930 List<SuggestSubmit> listSuggestSubmitTopPopularity = _suggestSubmitService.getSuggestSubmitList( submmitFilterTopPopularity, _plugin,
1931 suggest.getNumberSuggestSubmitInTopScore( ) );
1932 model.put( MARK_LIST_SUBMIT_TOP_POPULARITY_SUGGEST, listSuggestSubmitTopPopularity );
1933 }
1934
1935
1936 if ( suggest.isShowCategoryBlock( ) )
1937 {
1938 model.put( MARK_LIST_CATEGORIES_SUGGEST, suggest.getCategories( ) );
1939 }
1940
1941 ReferenceList refListSuggestSort = SuggestUtils.getRefListSuggestSort( getLocale( request ), true );
1942 ReferenceList refListFilterByPeriod = SuggestUtils.getRefListFilterByPeriod( getLocale( request ) );
1943
1944
1945 model.put( MARK_ID_SUGGEST, suggest.getIdSuggest( ) );
1946 model.put( MARK_QUERY, searchFields.getQuery( ) );
1947 model.put( MARK_ID_SUGGEST_SUBMIT_SORT, searchFields.getIdSuggestSubmitSort( ) );
1948 model.put( MARK_ID_FILTER_PERIOD, searchFields.getIdFilterPeriod( ) );
1949 model.put( MARK_ID_FILTER_CATEGORY_SUGGEST, searchFields.getIdFilterCategory( ) );
1950 model.put( MARK_ID_FILTER_TYPE, searchFields.getIdFilterSuggestSubmitType( ) );
1951
1952 if ( searchFields.getIdFilterSuggestSubmitType( ) != SuggestUtils.CONSTANT_ID_NULL )
1953 {
1954 model.put( MARK_TYPE_SELECTED, SuggestSubmitTypeHome.findByPrimaryKey( searchFields.getIdFilterSuggestSubmitType( ), _plugin ) );
1955 }
1956
1957 model.put( MARK_CONTENT_SUGGEST, strContentSuggest );
1958 model.put( MARK_LABEL_SUGGEST, suggest.getLibelleContribution( ) );
1959 model.put( MARK_HEADER_SUGGEST, suggest.getHeader( ) );
1960
1961 model.put( MARK_AUTHORIZED_COMMENT, suggest.isAuthorizedComment( ) );
1962 model.put( MARK_AUTHORIZED_VOTE, !suggest.isDisableVote( ) );
1963 model.put( MARK_NUMBER_SHOWN_CHARACTERS, _nNumberShownCharacters );
1964
1965 model.put( MARK_LIST_SUGGEST_SUBMIT_SORT, refListSuggestSort );
1966 model.put( MARK_LIST_FILTER_BY_PERIOD, refListFilterByPeriod );
1967
1968 model.put( MARK_SHOW_CATEGORY_BLOCK, suggest.isShowCategoryBlock( ) );
1969 model.put( MARK_SHOW_TOP_SCORE_BLOCK, suggest.isShowTopScoreBlock( ) );
1970 model.put( MARK_SHOW_TOP_COMMENT_BLOCK, suggest.isShowTopCommentBlock( ) );
1971 model.put( MARK_IS_EXTEND_INSTALLED, PortalService.isExtendActivated( ) );
1972 }
1973 else
1974 {
1975 model.put( MARK_UNAVAILABILITY_MESSAGE, suggest.getUnavailabilityMessage( ) );
1976 }
1977
1978 model.put( MARK_LUTECE_USER_CONNECTED, luteceUserConnected );
1979
1980 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_XPAGE_FRAME_SUGGEST, getLocale( request ), model );
1981 page.setContent( template.getHtml( ) );
1982 }
1983
1984
1985
1986
1987
1988
1989 private UrlItem getNewUrlItemPage( )
1990 {
1991 return new UrlItem( _urlSuggestXpageHome.getUrl( ) );
1992 }
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008 private void testUserAuthorizationAccess( Suggest suggest, HttpServletRequest request, LuteceUser user ) throws UserNotSignedException,
2009 SiteMessageException
2010 {
2011 if ( ( suggest.getRole( ) != null ) && !Suggest.ROLE_NONE.equals( suggest.getRole( ) ) )
2012 {
2013 if ( user == null )
2014 {
2015 throw new UserNotSignedException( );
2016 }
2017
2018 else
2019 if ( !SecurityService.getInstance( ).isUserInRole( request, suggest.getRole( ) ) )
2020 {
2021 SiteMessageService.setMessage( request, MESSAGE_ACCESS_DENIED, SiteMessage.TYPE_STOP );
2022 }
2023 }
2024 }
2025
2026
2027
2028
2029
2030
2031
2032
2033 protected Locale getLocale( HttpServletRequest request )
2034 {
2035 return LocaleService.getContextUserLocale( request );
2036 }
2037 }