View Javadoc
1   /*
2    * Copyright (c) 2002-2020, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.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  * This class manages Form page.
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     // markers
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     // templates
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     // properties for page titles and path label
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     // request parameters
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     // message
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     // XPAGE URL
233 
234     // constant
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     // session filter
257     private static final String SESSION_SEARCH_FIELDS = "search_fields";
258 
259     // properties
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      * Returns the Suggest XPage result content depending on the request parameters and the current mode.
270      *
271      * @param request
272      *            the {@link HttpServletRequest}
273      * @param nMode
274      *            the mode
275      * @param plugin
276      *            {@link Plugin}
277      * @return {@link XPage}
278      * @throws UserNotSignedException
279      *             {@link UserNotSignedException}
280      * @throws SiteMessageException
281      *             {@link SiteMessageException}
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             // clear all filter in session
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      * Display Suggest List
391      * 
392      * @param request
393      *            the {@link HttpServletRequest}
394      * @param nMode
395      *            the mode
396      * @param page
397      *            {@link XPage}
398      * @return {@link XPage}
399      * @throws UserNotSignedException
400      *             {@link UserNotSignedException}
401      * @throws SiteMessageException
402      *             {@link SiteMessageException}
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         // show the suggests list
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      * Display SuggestSubmit List
432      * 
433      * @param request
434      *            the {@link HttpServletRequest}
435      * @param nMode
436      *            the mode
437      * @param page
438      *            {@link XPage}
439      * @return {@link XPage}
440      * @throws UserNotSignedException
441      *             {@link UserNotSignedException}
442      * @throws SiteMessageException
443      *             {@link SiteMessageException}
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         // testAuthorizationAccess
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      * Display view SuggestSubmit
500      * 
501      * @param request
502      *            the {@link HttpServletRequest}
503      * @param nMode
504      *            the mode
505      * @param page
506      *            {@link XPage}
507      * @return {@link XPage}
508      * @throws UserNotSignedException
509      *             {@link UserNotSignedException}
510      * @throws SiteMessageException
511      *             {@link SiteMessageException}
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         // testAuthorizationAccess
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      * Display create SuggestSubmit Form
536      * 
537      * @param request
538      *            the {@link HttpServletRequest}
539      * @param nMode
540      *            the mode
541      * @param page
542      *            {@link XPage}
543      * @return {@link XPage}
544      * @throws UserNotSignedException
545      *             {@link UserNotSignedException}
546      * @throws SiteMessageException
547      *             {@link SiteMessageException}
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             // testAuthorizationAccess
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      * Display create sub comment
582      * 
583      * @param request
584      *            the {@link HttpServletRequest}
585      * @param nMode
586      *            the mode
587      * @param page
588      *            {@link XPage}
589      * @return {@link XPage}
590      * @throws UserNotSignedException
591      *             {@link UserNotSignedException}
592      * @throws SiteMessageException
593      *             {@link SiteMessageException}
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             // testAuthorizationAccess
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      * Display create Report form
643      * 
644      * @param request
645      *            the {@link HttpServletRequest}
646      * @param nMode
647      *            the mode
648      * @param page
649      *            {@link XPage}
650      * @return {@link XPage}
651      * @throws UserNotSignedException
652      *             {@link UserNotSignedException}
653      * @throws SiteMessageException
654      *             {@link SiteMessageException}
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      * Perform Action create Suggest Submit
675      * 
676      * @param request
677      *            the {@link HttpServletRequest}
678      * @param nMode
679      *            the mode
680      * @param page
681      *            {@link XPage}
682      * @throws UserNotSignedException
683      *             {@link UserNotSignedException}
684      * @throws SiteMessageException
685      *             {@link SiteMessageException}
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             // testAuthorizationAccess
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         // Check if terms of used is selected
717         if ( suggest.isEnableTermsOfUse( ) && ( strTermsOfUse == null ) )
718         {
719             SiteMessageService.setMessage( request, MESSAGE_ERROR_MUST_SELECTED_TERMS_OF_USE, SiteMessage.TYPE_STOP );
720         }
721 
722         // Check if a category is selected (in the case or the suggest has some categories)
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         // Check if a type is selected (in the case or the suggest has some type)
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         // Check if the suggest (consultation) has a workflow to execute upon the creation of a new SuggestSubmit element
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      * Do subscribe to a suggest or a suggest submit. If the parameter {@link #PARAMETER_ID_SUBMIT_SUGGEST} has a value, then subscribe to the suggest submit,
773      * otherwise subscribe to the suggest
774      * 
775      * @param request
776      *            The request
777      * @throws SiteMessageException
778      *             If the suggest or the suggest submit does not exist
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      * Do unsubscribe to a suggest or a suggest submit. If the parameter {@link #PARAMETER_ID_SUBMIT_SUGGEST} has a value, then unsubscribe to the suggest
859      * submit, otherwise unsubscribe to the suggest
860      * 
861      * @param request
862      *            The request
863      * @throws SiteMessageException
864      *             If the suggest or the suggest submit does not exist
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      * Perform Action create Comment
946      * 
947      * @param request
948      *            the {@link HttpServletRequest}
949      * @param nMode
950      *            the mode
951      * @param page
952      *            {@link XPage}
953      * @throws UserNotSignedException
954      *             {@link UserNotSignedException}
955      * @throws SiteMessageException
956      *             {@link SiteMessageException}
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             // testAuthorizationAccess
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      * Perform Action Report
1045      * 
1046      * @param request
1047      *            the {@link HttpServletRequest}
1048      * @param nMode
1049      *            the mode
1050      * @param page
1051      *            {@link XPage}
1052      * @throws UserNotSignedException
1053      *             {@link UserNotSignedException}
1054      * @throws SiteMessageException
1055      *             {@link SiteMessageException}
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             // testAuthorizationAccess
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      * Perform Action Vote
1126      * 
1127      * @param request
1128      *            the {@link HttpServletRequest}
1129      * @param nMode
1130      *            the mode
1131      * @param page
1132      *            {@link XPage}
1133      * @throws UserNotSignedException
1134      *             {@link UserNotSignedException}
1135      * @throws SiteMessageException
1136      *             {@link SiteMessageException}
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      * Increment score
1185      *
1186      * @param strVote
1187      *            the value to add at score
1188      * @param nIdSubmitSuggest
1189      *            the id of the suggest submit
1190      * @param plugin
1191      *            the plugin
1192      * @param strUserKey
1193      *            the user key
1194      */
1195     private void doVote( String strVote, int nIdSubmitSuggest, Plugin plugin, String strUserKey )
1196     {
1197         // Increment vote
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      * return the html list of suggest submit
1210      * 
1211      * @param locale
1212      *            the locale
1213      * @param plugin
1214      *            the plugin
1215      * @param suggest
1216      *            the suggest
1217      * @param searchFields
1218      *            the searchFields
1219      * @param urlSuggestXPage
1220      *            the url of the Xpage
1221      * @param luteceUserConnected
1222      *            the lutece UserConnected
1223      * @return the html list of suggest submit
1224      * @throws SiteMessageException
1225      *             SiteMessageException {@link SiteMessageException}
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         // Filter the list
1237         SuggestUtils.initSubmitFilterByPeriod( submitFilter, searchFields.getIdFilterPeriod( ) );
1238         SuggestUtils.initSubmitFilterBySort(
1239                 submitFilter,
1240                 ( searchFields.getIdSuggestSubmitSort( ) != SuggestUtils.CONSTANT_ID_NULL ) ? searchFields.getIdSuggestSubmitSort( ) : suggest
1241                         .getIdDefaultSort( ) );
1242         // add sort by pinned first
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      * return the html list of suggest
1287      *
1288      * @param locale
1289      *            the locale
1290      * @param plugin
1291      *            the plugin
1292      * @param strCurrentPageIndexSuggest
1293      *            the current page index
1294      * @param nItemsPerPageSuggest
1295      *            the number of items per page
1296      * @param urlSuggestXPage
1297      *            the url of the suggest xpage
1298      * @param luteceUserConnected
1299      *            luteceUser
1300      * @return the html list of suggest
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      * return a collection which contains suggest submit and lutece user associate
1326      *
1327      * @param listSuggestSubmit
1328      *            the list of suggest submit
1329      * @param suggest
1330      *            the suggest possessing submits
1331      * @param strSuggestDetail
1332      *            the suggest detail
1333      * @param locale
1334      *            the locale
1335      * @return a collection which contains suggest submit and lutece user associate
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      * return a collection which contains comment and lutece user associate
1375      *
1376      * @param listCommentSubmit
1377      *            the list of comment submit
1378      * @return a collection which contains comment and lutece user associate
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      * the html suggest submit detail
1414      *
1415      * @param request
1416      *            the request
1417      * @param nMode
1418      *            The current mode.
1419      * @param plugin
1420      *            the plugin
1421      * @param suggestSubmit
1422      *            the {@link SuggestSubmit}
1423      *
1424      *
1425      * @param luteceUserConnected
1426      *            the lutece user
1427      * @return the html suggest submit detail
1428      * @throws SiteMessageException
1429      *             SiteMessageException
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         // update number view
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      * return the Html type of vote
1495      *
1496      * @param strVoteTypeTemplateName
1497      *            the template use
1498      * @param suggest
1499      *            the suggest
1500      * @param nIdSuggestSubmit
1501      *            the id of the suggestSubmit
1502      * @param strView
1503      *            the view which is display the vote type
1504      * @param locale
1505      *            the locale
1506      * @return the Html type of vote
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      * return the html form reported
1530      *
1531      * @param request
1532      *            the request
1533      * @param nMode
1534      *            The current mode.
1535      * @param plugin
1536      *            plugin
1537      * @param suggestSubmit
1538      *            the suggestSubmit
1539      *
1540      * @return the html form reported
1541      * @throws SiteMessageException
1542      *             SiteMessageException
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      * return the html list of comment submit for a suggest submit
1565      *
1566      * @param request
1567      *            the request
1568      * @param listCommentSubmit
1569      *            the list of comment submit
1570      * @param suggest
1571      *            the suggest
1572      * @param plugin
1573      *            plugin
1574      * @param nIdSubmitSuggest
1575      *            the id of the suggest submit
1576      * @param luteceUserConnected
1577      *            lutece user connected
1578      * @return the html list of comment submit for a suggest submit
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      * Return the html form for creating suggest submit
1601      *
1602      * @param request
1603      *            The HTTP request
1604      * @param nMode
1605      *            The current mode.
1606      * @param plugin
1607      *            The Plugin
1608      * @param suggest
1609      *            the suggest
1610      * @param nIdDefaultCategory
1611      *            the id of the default category
1612      * @return the html form
1613      * @throws SiteMessageException
1614      *             SiteMessageException
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         // get form Recap
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      * Return the new suggest submit object
1630      *
1631      * @param request
1632      *            The HTTP request
1633      * @param nMode
1634      *            The current mode.
1635      * @param plugin
1636      *            The Plugin
1637      * @param suggest
1638      *            the suggest
1639      * @param nIdCategory
1640      *            the id of the category
1641      * @param nIdType
1642      *            the id of the type
1643      * @param user
1644      *            the lutece user
1645      * @return the new suggest submit object
1646      * @throws SiteMessageException
1647      *             SiteMessageException
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         // perform suggest submit
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             // insert SuggestSubmitInfi=ormation if not exists
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             // something very wrong happened... a database check might be needed
1716             AppLogService.error( ex.getMessage( ) + " for SuggestSubmit " + suggestSubmit.getIdSuggestSubmit( ), ex );
1717             // revert
1718             // we clear the DB form the given formsubmit (FormSubmitHome also
1719             // removes the reponses)
1720             _suggestSubmitService.remove( suggestSubmit.getIdSuggestSubmit( ), plugin, user );
1721             // throw a message to the user
1722             SiteMessageService.setMessage( request, MESSAGE_MESSAGE_SUBMIT_SAVE_ERROR, SiteMessage.TYPE_ERROR );
1723         }
1724 
1725         return suggestSubmit;
1726     }
1727 
1728     /**
1729      * return the new comment submit create
1730      *
1731      * @param request
1732      *            the http request
1733      * @param suggestSubmit
1734      *            the SuggestSubmit
1735      *
1736      * @param strCommentValueSuggest
1737      *            the comment value
1738      * @param plugin
1739      *            the plugin
1740      * @param nIdParentComment
1741      *            the id of the parent of this comment
1742      * @param user
1743      *            the Lutece user associate to the comment
1744      * @return the new comment submit create
1745      * @throws SiteMessageException
1746      *             SiteMessageException
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             // insert SuggestSubmitInfiormation if not exists
1780             SuggestUserInfoService.getService( ).updateSuggestUserInfoByLuteceUser( user, plugin );
1781         }
1782 
1783         _commentSubmitService.create( commentSubmit, plugin );
1784 
1785         return commentSubmit;
1786     }
1787 
1788     /**
1789      * Clear params stores in session
1790      *
1791      * @param session
1792      *            the Http session
1793      */
1794     private void clearSessionFilter( HttpSession session )
1795     {
1796         session.setAttribute( SESSION_SEARCH_FIELDS, null );
1797     }
1798 
1799     /**
1800      *
1801      * method init
1802      * 
1803      * @param request
1804      *            The HTTP request
1805      * @param plugin
1806      *            The plugin
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      * Return the searcheField contains in the request or store in session
1839      * 
1840      * @param request
1841      *            {@link HttpServletRequest}
1842      * @return the SearchField
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         // update search Fields in session
1874         session.setAttribute( SESSION_SEARCH_FIELDS, searchFields );
1875 
1876         return searchFields;
1877     }
1878 
1879     /**
1880      * Add the suggest page frameset
1881      * 
1882      * @param strContentSuggest
1883      * @param request
1884      *            the {@link HttpServletRequest}
1885      * @param page
1886      *            {@link XPage}
1887      * @param suggest
1888      *            {@link Suggest}
1889      * @param model
1890      *            the model
1891      * @param searchFields
1892      *            the searchField
1893      * @param luteceUserConnected
1894      *            the luteceUserConnected
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             // Filter by comment
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             // Filter by popularity
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             // category Block
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             // model
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      * return a new UrlItem Xpage
1986      * 
1987      * @return a new UrlItem Xpage
1988      */
1989     private UrlItem getNewUrlItemPage( )
1990     {
1991         return new UrlItem( _urlSuggestXpageHome.getUrl( ) );
1992     }
1993 
1994     /**
1995      * Test if a user can process action to a suggest
1996      * 
1997      * @param suggest
1998      *            the suggest
1999      * @param request
2000      *            the {@link HttpServletRequest}
2001      * @param user
2002      *            The LuteceUser
2003      * @throws UserNotSignedException
2004      *             {@link UserNotSignedException}
2005      * @throws SiteMessageException
2006      *             {@link SiteMessageException}
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      * Default getLocale() implementation. Could be overriden
2028      * 
2029      * @param request
2030      *            The HTTP request
2031      * @return The Locale
2032      */
2033     protected Locale getLocale( HttpServletRequest request )
2034     {
2035         return LocaleService.getContextUserLocale( request );
2036     }
2037 }