View Javadoc

1   /*
2    * Copyright (c) 2002-2014, 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.digglike.web;
35  
36  import java.math.BigDecimal;
37  import java.sql.Timestamp;
38  import java.util.ArrayList;
39  import java.util.Arrays;
40  import java.util.Collection;
41  import java.util.Date;
42  import java.util.HashMap;
43  import java.util.List;
44  import java.util.Locale;
45  import java.util.Map;
46  
47  import javax.servlet.http.HttpServletRequest;
48  import javax.servlet.http.HttpServletResponse;
49  
50  import org.apache.commons.fileupload.FileItem;
51  import org.apache.commons.lang.StringUtils;
52  
53  import fr.paris.lutece.plugins.digglike.business.Category;
54  import fr.paris.lutece.plugins.digglike.business.CategoryHome;
55  import fr.paris.lutece.plugins.digglike.business.CommentSubmit;
56  import fr.paris.lutece.plugins.digglike.business.DefaultMessage;
57  import fr.paris.lutece.plugins.digglike.business.DefaultMessageHome;
58  import fr.paris.lutece.plugins.digglike.business.Digg;
59  import fr.paris.lutece.plugins.digglike.business.DiggAction;
60  import fr.paris.lutece.plugins.digglike.business.DiggActionHome;
61  import fr.paris.lutece.plugins.digglike.business.DiggFilter;
62  import fr.paris.lutece.plugins.digglike.business.DiggHome;
63  import fr.paris.lutece.plugins.digglike.business.DiggSubmit;
64  import fr.paris.lutece.plugins.digglike.business.DiggSubmitState;
65  import fr.paris.lutece.plugins.digglike.business.DiggSubmitStateHome;
66  import fr.paris.lutece.plugins.digglike.business.DiggSubmitType;
67  import fr.paris.lutece.plugins.digglike.business.DiggSubmitTypeHome;
68  import fr.paris.lutece.plugins.digglike.business.EntryAdditionalAttribute;
69  import fr.paris.lutece.plugins.digglike.business.EntryAdditionalAttributeHome;
70  import fr.paris.lutece.plugins.digglike.business.EntryFilter;
71  import fr.paris.lutece.plugins.digglike.business.EntryHome;
72  import fr.paris.lutece.plugins.digglike.business.EntryType;
73  import fr.paris.lutece.plugins.digglike.business.EntryTypeHome;
74  import fr.paris.lutece.plugins.digglike.business.ExportFormat;
75  import fr.paris.lutece.plugins.digglike.business.FormError;
76  import fr.paris.lutece.plugins.digglike.business.IEntry;
77  import fr.paris.lutece.plugins.digglike.business.ReportedMessageHome;
78  import fr.paris.lutece.plugins.digglike.business.Response;
79  import fr.paris.lutece.plugins.digglike.business.SubmitFilter;
80  import fr.paris.lutece.plugins.digglike.business.VoteType;
81  import fr.paris.lutece.plugins.digglike.business.VoteTypeHome;
82  import fr.paris.lutece.plugins.digglike.service.CategoryResourceIdService;
83  import fr.paris.lutece.plugins.digglike.service.CommentSubmitService;
84  import fr.paris.lutece.plugins.digglike.service.DefaultMessageResourceIdService;
85  import fr.paris.lutece.plugins.digglike.service.DiggSubmitService;
86  import fr.paris.lutece.plugins.digglike.service.DigglikeResourceIdService;
87  import fr.paris.lutece.plugins.digglike.service.ExportFormatResourceIdService;
88  import fr.paris.lutece.plugins.digglike.service.ICommentSubmitService;
89  import fr.paris.lutece.plugins.digglike.service.IDiggSubmitService;
90  import fr.paris.lutece.plugins.digglike.service.digglikesearch.DigglikeSearchService;
91  import fr.paris.lutece.plugins.digglike.service.search.DigglikeIndexer;
92  import fr.paris.lutece.plugins.digglike.utils.DiggIndexerUtils;
93  import fr.paris.lutece.plugins.digglike.utils.DiggUtils;
94  import fr.paris.lutece.plugins.digglike.web.action.DigglikeAdminSearchFields;
95  import fr.paris.lutece.plugins.digglike.web.action.IDigglikeAction;
96  import fr.paris.lutece.portal.business.indexeraction.IndexerAction;
97  import fr.paris.lutece.portal.business.rbac.RBAC;
98  import fr.paris.lutece.portal.business.role.RoleHome;
99  import fr.paris.lutece.portal.business.style.Theme;
100 import fr.paris.lutece.portal.business.user.AdminUser;
101 import fr.paris.lutece.portal.service.admin.AccessDeniedException;
102 import fr.paris.lutece.portal.service.admin.AdminUserService;
103 import fr.paris.lutece.portal.service.fileupload.FileUploadService;
104 import fr.paris.lutece.portal.service.i18n.I18nService;
105 import fr.paris.lutece.portal.service.image.ImageResource;
106 import fr.paris.lutece.portal.service.mailinglist.AdminMailingListService;
107 import fr.paris.lutece.portal.service.message.AdminMessage;
108 import fr.paris.lutece.portal.service.message.AdminMessageService;
109 import fr.paris.lutece.portal.service.message.SiteMessage;
110 import fr.paris.lutece.portal.service.plugin.Plugin;
111 import fr.paris.lutece.portal.service.plugin.PluginService;
112 import fr.paris.lutece.portal.service.portal.ThemesService;
113 import fr.paris.lutece.portal.service.rbac.RBACService;
114 import fr.paris.lutece.portal.service.search.IndexationService;
115 import fr.paris.lutece.portal.service.security.LuteceUser;
116 import fr.paris.lutece.portal.service.security.SecurityService;
117 import fr.paris.lutece.portal.service.template.AppTemplateService;
118 import fr.paris.lutece.portal.service.util.AppLogService;
119 import fr.paris.lutece.portal.service.util.AppPathService;
120 import fr.paris.lutece.portal.service.util.AppPropertiesService;
121 import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupService;
122 import fr.paris.lutece.portal.web.admin.PluginAdminPageJspBean;
123 import fr.paris.lutece.portal.web.pluginaction.DefaultPluginActionResult;
124 import fr.paris.lutece.portal.web.pluginaction.IPluginActionResult;
125 import fr.paris.lutece.portal.web.pluginaction.PluginActionManager;
126 import fr.paris.lutece.portal.web.upload.MultipartHttpServletRequest;
127 import fr.paris.lutece.util.ReferenceList;
128 import fr.paris.lutece.util.date.DateUtil;
129 import fr.paris.lutece.util.html.HtmlTemplate;
130 import fr.paris.lutece.util.html.Paginator;
131 import fr.paris.lutece.util.string.StringUtil;
132 import fr.paris.lutece.util.url.UrlItem;
133 
134 
135 /**
136  * This class provides the user interface to manage form features ( manage,
137  * create, modify, remove)
138  */
139 public class DiggJspBean extends PluginAdminPageJspBean
140 {
141     public static final String MARK_DISABLE_DIGG_SUBMIT_STATE_NUMBER = "disable_state_number";
142     public static final String MARK_WAITING_FOR_PUBLISH_DIGG_SUBMIT_STATE_NUMBER = "waiting_for_publish_state_number";
143     public static final String MARK_PUBLISH_DIGG_SUBMIT_STATE_NUMBER = "publish_state_number";
144     private static final long serialVersionUID = 8034293907026887250L;
145 
146     // templates
147     private static final String TEMPLATE_MANAGE_DIGG = "admin/plugins/digglike/manage_digg.html";
148     private static final String TEMPLATE_MANAGE_DIGG_SUBMIT = "admin/plugins/digglike/manage_digg_submit.html";
149     private static final String TEMPLATE_CREATE_DIGG_SUBMIT = "admin/plugins/digglike/create_digg_submit.html";
150     private static final String TEMPLATE_MANAGE_DIGG_SUBMIT_ORDER = "admin/plugins/digglike/manage_digg_submit_order.html";
151     private static final String TEMPLATE_MANAGE_COMMENT_SUBMIT = "admin/plugins/digglike/manage_comment_submit.html";
152     private static final String TEMPLATE_CREATE_DIGG = "admin/plugins/digglike/create_digg.html";
153     private static final String TEMPLATE_MODIFY_DIGG = "admin/plugins/digglike/modify_digg.html";
154     private static final String TEMPLATE_STATISTICS_DIGG = "admin/plugins/digglike/statistics.html";
155     private static final String TEMPLATE_MANAGE_ADVANCED_PARAMETERS = "admin/plugins/digglike/manage_advanced_parameters.html";
156 
157     // message
158     private static final String MESSAGE_NEW_COMMENT_SUBMIT_INVALID = "digglike.message.newCommentSubmitInvalid";
159     private static final String MESSAGE_CONFIRM_REMOVE_DIGG = "digglike.message.confirmRemoveDigg";
160     private static final String MESSAGE_CONFIRM_REMOVE_DIGG_SUBMIT = "digglike.message.confirmRemoveDiggSubmit";
161     private static final String MESSAGE_CONFIRM_REMOVE_COMMENT_SUBMIT = "digglike.message.confirmRemoveCommentSubmit";
162     private static final String MESSAGE_CONFIRM_REMOVE_DIGG_WITH_DIGG_SUBMIT = "digglike.message.confirmRemoveDiggWithDiggSubmit";
163     private static final String MESSAGE_CONFIRM_DISABLE_DIGG = "digglike.message.confirmDisableDigg";
164     private static final String MESSAGE_CONFIRM_REMOVE_ENTRY = "digglike.message.confirmRemoveEntry";
165     private static final String MESSAGE_CONFIRM_UPDATE_ALL_DIGG_SUBMIT = "digglike.message.confirmUpdateAllDiggSubmit";
166     private static final String MESSAGE_MANDATORY_FIELD = "digglike.message.mandatory.field";
167     private static final String MESSAGE_ILLOGICAL_NUMBER_VOTE_REQUIRED = "digglike.message.illogicalNumberVoteRequired";
168     private static final String MESSAGE_ILLOGICAL_NUMBER_DIGG_SUBMIT_CARACTERS_SHOWN = "digglike.message.illogicalNumberDiggSubmitCaractersShown";
169     private static final String MESSAGE_ILLOGICAL_NUMBER_DIGG_SUBMIT_IN_TOP_SCORE = "digglike.message.illogicalNumberDiggSumitInTopScore";
170     private static final String MESSAGE_ILLOGICAL_NUMBER_DIGG_SUBMIT_IN_TOP_COMMENT = "digglike.message.illogicalNumberDiggSumitInTopComment";
171     private static final String MESSAGE_ILLOGICAL_NUMBER_DIGG_SUBMIT_PER_PAGE = "digglike.message.illogicalNumberDiggSumitPerPage";
172     private static final String MESSAGE_ILLOGICAL_NUMBER_COMMENT_DISPLAY_IN_DIGG_SUBMIT_LIST = "digglike.message.illogicalNumberCommentDisplayInDiggSubmitList";
173     private static final String MESSAGE_ILLOGICAL_NUMBER_CHAR_COMMENT_DISPLAY_IN_DIGG_SUBMIT_LIST = "digglike.message.illogicalNumberCharCommentDisplayInDiggSubmitList";
174     private static final String MESSAGE_ILLOGICAL_NUMBER_DAY_REQUIRED = "digglike.message.illogicalNumberDayRequired";
175     private static final String MESSAGE_CONFIRM_CHANGE_DIGG_SUBMIT_CATEGORY = "digglike.message.confirmChangeDiggSubmitCategory";
176     private static final String MESSAGE_CONFIRM_REMOVE_DIGG_SUBMIT_CATEGORY = "digglike.message.confirmRemoveDiggSubmitCategory";
177     private static final String MESSAGE_ERROR_NO_CATEGORY = "digglike.message.errorNoCategorySelected";
178     private static final String MESSAGE_ERROR_NO_DIGG_SUBMIT_TYPE_SELECTED = "digglike.message.errorNoDiggSubmitTypeSelected";
179     private static final String MESSAGE_MANDATORY_QUESTION = "digglike.message.mandatory.question";
180     private static final String MESSAGE_FORM_ERROR = "digglike.message.formError";
181     private static final String FIELD_TITLE = "digglike.createDigg.labelTitle";
182     private static final String FIELD_LIBELLE_CONTRIBUTION = "digglike.createDigg.labelLibelleContribution";
183     private static final String FIELD_UNAVAILABILITY_MESSAGE = "digglike.createDigg.labelUnavailabilityMessage";
184     private static final String FIELD_VOTE_TYPE = "digglike.createDigg.labelVoteType";
185     private static final String FIELD_LIBELE_VALIDATE_BUTTON = "digglike.createDigg.labelLibelleValidateButton";
186     private static final String FIELD_NUMBER_DIGG_SUBMIT_CARACTERS_SHOWN = "digglike.createDigg.labelNumberDiggSubmitCaractersShown";
187     private static final String FIELD_NUMBER_DIGG_SUBMIT_IN_TOP_SCORE = "digglike.createDigg.labelNumberDiggSubmitInTopScore";
188     private static final String FIELD_NUMBER_DIGG_SUBMIT_IN_TOP_COMMENT = "digglike.createDigg.labelNumberDiggSubmitInTopComment";
189     private static final String FIELD_NUMBER_DIGG_SUBMIT_PER_PAGE = "digglike.createDigg.labelNumberDiggSubmitPerPage";
190     private static final String FIELD_NUMBER_COMMENT_DISPLAY_IN_DIGG_SUBMIT_LIST = "digglike.createDigg.labelNumberCommentDisplayInDiggSubmitList";
191     private static final String FIELD_NUMBER_CHAR_COMMENT_DISPLAY_IN_DIGG_SUBMIT_LIST = "digglike.createDigg.labelNumberCharCommentDisplayInDiggSubmitList";
192 
193     private static final String FIELD_NOTIFICATION_NEW_COMMENT_SENDER_NAME ="digglike.createDigg.labelNotificationNewCommentSenderName";
194     private static final String FIELD_NOTIFICATION_NEW_COMMENT_TITLE="digglike.createDigg.labelNotificationNewCommentTitle";
195     private static final String FIELD_NOTIFICATION_NEW_COMMENT_BODY="digglike.createDigg.labelNotificationNewCommentBody";
196     private static final String FIELD_NOTIFICATION_NEW_DIGG_DUBMIT_SENDER_NAME="digglike.createDigg.labelNotificationNewDiggSubmitSenderName";
197     private static final String FIELD_NOTIFICATION_NEW_DIGG_DUBMIT_TITLE="digglike.createDigg.labelNotificationNewDiggSubmitTitle";
198     private static final String FIELD_NOTIFICATION_NEW_DIGG_DUBMIT_BODY="digglike.createDigg.labelNotificationNewDiggSubmitBody";
199   
200     
201     
202     // properties
203     private static final String PROPERTY_ITEM_PER_PAGE = "digglike.itemsPerPage";
204     private static final String PROPERTY_ALL = "digglike.manageDigg.select.all";
205     private static final String PROPERTY_YES = "digglike.manageDiggSubmit.select.yes";
206     private static final String PROPERTY_NO = "digglike.manageDiggSubmit.select.no";
207     private static final String PROPERTY_ENABLE = "digglike.manageDigg.select.enable";
208     private static final String PROPERTY_DISABLE = "digglike.manageDigg.select.disable";
209     private static final String PROPERTY_NOTHING = "digglike.createDigg.select.nothing";
210     private static final String PROPERTY_MODIFY_DIGG_TITLE = "digglike.modifyDigg.title";
211     private static final String PROPERTY_COPY_DIGG_TITLE = "digglike.copyDigg.title";
212     private static final String PROPERTY_COPY_ENTRY_TITLE = "digglike.copyEntry.title";
213     private static final String PROPERTY_CREATE_DIGG_TITLE = "digglike.createDigg.title";
214     private static final String PROPERTY_CREATE_QUESTION_TITLE = ".createEntry.titleQuestion";
215     private static final String PROPERTY_MODIFY_QUESTION_TITLE = "digglike.modifyEntry.titleQuestion";
216     private static final String PROPERTY_NUMBER_DIGG_SUBMIT_VALUE_SHOWN_CHARACTERS = "digglike.diggSubmitValue.NumberShownCharacters";
217     private static final String PROPERTY_DIGGSUBMIT_HIGHSCORES = "digglike.highscores.diggSubmit.number";
218     private static final String PROPERTY_MANAGE_DIGG_PAGE_TITLE = "digglike.manageDigg.pageTitle";
219     private static final String PROPERTY_MANAGE_ADVANCED_PARAMETERS_PAGE_TITLE = "digglike.manageAdvancedParameters.pageTitle";
220     private static final String PROPERTY_MANAGE_DIGG_SUBMIT_PAGE_TITLE = "digglike.manageDiggSubmit.pageTitle";
221     private static final String PROPERTY_MANAGE_DIGG_SUBMIT_ORDER_PAGE_TITLE = "digglike.manageDiggSubmitOrder.pageTitle";
222     private static final String PROPERTY_CREATE_DIGG_SUBMIT_PAGE_TITLE = "digglike.createDiggSubmit.pageTitle";
223     private static final String PROPERTY_MANAGE_COMMENT_SUBMIT_PAGE_TITLE = "digglike.manageCommentSubmit.pageTitle";
224     private static final String PROPERTY_DEFAULT_ROLE_CODE = "defaultRole.code";
225     // Markers
226     private static final String MARK_WEBAPP_URL = "webapp_url";
227     private static final String MARK_LOCALE = "locale";
228     private static final String MARK_PAGINATOR = "paginator";
229     private static final String MARK_USER_WORKGROUP_REF_LIST = "user_workgroup_list";
230     private static final String MARK_USER_WORKGROUP_SELECTED = "user_workgroup_selected";
231     private static final String MARK_DIGG_STATE_REF_LIST = "digg_state_list";
232     private static final String MARK_DIGG_STATE_SELECTED = "digg_state_selected";
233     private static final String MARK_DIGG_SUBMIT_STATE_REF_LIST = "digg_submit_state_list";
234     private static final String MARK_DIGG_SUBMIT_STATE_SELECTED = "digg_submit_state_selected";
235     private static final String MARK_MAILING_REF_LIST = "mailing_list";
236     private static final String MARK_ENTRY_TYPE_REF_LIST = "entry_type_list";
237     private static final String MARK_REGULAR_EXPRESSION_LIST_REF_LIST = "regular_expression_list";
238     private static final String MARK_ENTRY = "entry";
239     private static final String MARK_ID_ENTRY_FIRST_IN_THE_LIST = "id_entry_first_in_the_list";
240     private static final String MARK_ID_ENTRY_LAST_IN_THE_LIST = "id_entry_last_in_the_list";
241     private static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page";
242     private static final String MARK_DIGG_LIST = "digg_list";
243     private static final String MARK_DIGG_SUBMIT_LIST = "digg_submit_list";
244     private static final String MARK_COMMENT_SUBMIT_LIST = "comment_submit_list";
245     private static final String MARK_VOTE_TYPE_LIST = "vote_type_list";
246     private static final String MARK_CATEGORY_LIST = "category_list";
247     private static final String MARK_DIGG_SUBMIT_TYPE_LIST = "digg_submit_type_list";
248     private static final String MARK_DIGG = "digg";
249     private static final String MARK_DIGG_SUBMIT = "digg_submit";
250     private static final String MARK_ID_DIGG_SUBMIT_PREV = "digg_submit_prev";
251     private static final String MARK_ID_DIGG_SUBMIT_NEXT = "digg_submit_next";
252     private static final String MARK_PERMISSION_CREATE_DIGG = "permission_create_digg";
253     private static final String MARK_PERMISSION_MANAGE_ADVANCED_PARAMETERS = "permission_manage_advanced_parameters";
254     private static final String MARK_ENTRY_TYPE_GROUP = "entry_type_group";
255     private static final String MARK_ENTRY_LIST = "entry_list";
256     private static final String MARK_LIST = "list";
257     private static final String MARK_NUMBER_QUESTION = "number_question";
258     private static final String MARK_NUMBER_ITEMS = "number_items";
259     private static final String MARK_DEFAULT_MESSAGE = "default_message";
260     private static final String MARK_IS_ACTIVE_CAPTCHA = "is_active_captcha";
261     private static final String MARK_YES_VALUE = "yes_value";
262     private static final String MARK_NO_VALUE = "no_value";
263     private static final String MARK_NUMBER_SHOWN_CHARACTERS = "number_shown_characters";
264     private static final String MARK_LIST_DIGG_SUBMIT_SORT = "digg_submit_sort_list";
265     private static final String MARK_DIGG_SUBMIT_SORT_SELECTED = "digg_submit_sort_selected";
266     private static final String MARK_DIGG_SUBMIT_CATEGORY_SELECTED = "digg_submit_category_selected";
267     private static final String MARK_DIGG_SUBMIT_TYPE_SELECTED = "digg_submit_type_selected";
268     private static final String MARK_CATEGORY_FILTER = "category_filter";
269     private static final String MARK_TYPE_FILTER = "type_filter";
270     private static final String MARK_REPORT_REF_LIST = "digg_submit_report_list";
271     private static final String MARK_REPORT_SELECTED = "digg_submit_report_selected";
272     private static final String MARK_CONTAINS_COMMENT_DISABLE_LIST = "digg_submit_contains_comment_disable_list";
273     private static final String MARK_CONTAINS_COMMENT_DISABLE_SELECTED = "digg_submit_contains_comment_disable_selected";
274     private static final String MARK_AUTHENTIFICATION_ENABLE = "authentification_enable";
275     private static final String MARK_ROLE_LIST = "role_list";
276     private static final String MARK_DEFAULT_VALUE_ROLE = "default_value_role";
277     private static final String MARK_COMMENT_SORT_LIST = "comment_sort_list";
278     private static final String MARK_COMMENT_SORT_SELECTED = "comment_sort_selected";
279     private static final String MARK_COMMENT_STATE_LIST = "comment_state_list";
280     private static final String MARK_COMMENT_STATE_SELECTED = "comment_state_selected";
281     private static final String MARK_CONTAINS_SUB_COMMENT_DISABLE_LIST = "comment_contains_sub_comment_disable_list";
282     private static final String MARK_CONTAINS_SUB_COMMENT_DISABLE_SELECTED = "comment_contains_sub_comment_disable_selected";
283     private static final String MARK_DIGG_SUBMIT_ORDER_LIST = "order_list";
284     private static final String MARK_DIGG_SUBMIT_ORDER_LIST_PINNED = "order_list_pinned";
285     private static final String MARK_FIRST_DATE_FILTER = "first_date_filter";
286     private static final String MARK_LAST_DATE_FILTER = "last_date_filter";
287     private static final String MARK_NUMBER_VOTES = "number_votes";
288     private static final String MARK_NUMBER_COMMENTS = "number_comments";
289     private static final String MARK_NUMBER_DIGGSUBMIT_DISABLED = "number_diggsubmit_disabled";
290     private static final String MARK_NUMBER_DIGGSUBMIT_WAITING = "number_diggsubmit_waiting";
291     private static final String MARK_NUMBER_DIGGSUBMIT_PUBLISHED = "number_diggsubmit_published";
292     private static final String MARK_HIGH_SCORES = "high_scores";
293     private static final String MARK_NUMBER_USERS = "number_users";
294     private static final String MARK_URL = "url";
295     private static final String MARK_DEFAULT_THEME = "default_theme";
296     private static final String MARK_THEME_REF_LIST = "theme_list";
297     private static final String MARK_PERMISSION_MANAGE_DEFAULT_MESSAGE = "permission_manage_default_message";
298     private static final String MARK_PERMISSION_MANAGE_CATEGORY = "permission_manage_category";
299     private static final String MARK_PERMISSION_MANAGE_EXPORT_FORMAT = "permission_manage_export_format";
300     private static final String MARK_ID_DEFAULT_DIGG = "id_default_digg";
301     private static final String MARK_QUERY = "query";
302     private static final String MARK_DIGGLIKE_ACTIONS = "digglike_actions";
303     private static final String MARK_ID_PARENT = "id_parent";
304 
305     // Jsp Definition
306     private static final String JSP_DO_DISABLE_DIGG = "jsp/admin/plugins/digglike/DoDisableDigg.jsp";
307     private static final String JSP_DO_REMOVE_DIGG = "jsp/admin/plugins/digglike/DoRemoveDigg.jsp";
308     private static final String JSP_DO_REMOVE_DIGG_SUBMIT = "jsp/admin/plugins/digglike/DoRemoveDiggSubmit.jsp";
309     private static final String JSP_DO_REMOVE_ENTRY = "jsp/admin/plugins/digglike/DoRemoveEntry.jsp";
310     private static final String JSP_MANAGE_DIGG = "jsp/admin/plugins/digglike/ManageDigg.jsp";
311     private static final String JSP_DO_REMOVE_COMMENT_SUBMIT = "jsp/admin/plugins/digglike/DoRemoveCommentSubmit.jsp";
312     //    private static final String JSP_MANAGE_DIGG_SUBMIT_TYPE = "jsp/admin/plugins/digglike/ManageDiggSubmitType.jsp";
313     private static final String JSP_MODIFY_DIGG = "jsp/admin/plugins/digglike/ModifyDigg.jsp";
314     private static final String JSP_MODIFY_ENTRY = "jsp/admin/plugins/digglike/ModifyEntry.jsp";
315     private static final String JSP_MANAGE_DIGG_SUBMIT = "jsp/admin/plugins/digglike/ManageDiggSubmit.jsp";
316     private static final String JSP_MANAGE_DIGG_SUBMIT_ORDER = "jsp/admin/plugins/digglike/ManageDiggSubmitOrder.jsp";
317     private static final String JSP_MANAGE_COMMENT_SUBMIT = "jsp/admin/plugins/digglike/ManageCommentSubmit.jsp";
318     private static final String JSP_MANAGE_ADVANCED_PARAMETERS = "jsp/admin/plugins/digglike/ManageAdvancedParameters.jsp";
319     private static final String JSP_DO_UPDATE_ALL_DIGG_SUBMIT = "jsp/admin/plugins/digglike/DoUpdateAllDiggSubmit.jsp";
320     private static final String JSP_DO_CHANGE_DIGG_SUBMIT_CATEGORY = "jsp/admin/plugins/digglike/DoMassChangeDiggSubmitCategory.jsp";
321 
322     // parameters form
323     private static final String PARAMETER_ID_DIGG = "id_digg";
324     private static final String PARAMETER_ID_DIGG_SUBMIT = "id_digg_submit";
325     private static final String PARAMETER_ID_COMMENT_SUBMIT = "id_comment_submit";
326     private static final String PARAMETER_ID_PARENT = "id_parent";
327     private static final String PARAMETER_STATE_NUMBER = "state_number";
328     private static final String PARAMETER_TITLE = "title";
329     private static final String PARAMETER_LIBELLE_CONTRIBUTION = "libelle_contribution";
330     private static final String PARAMETER_UNAVAILABILITY_MESSAGE = "unavailability_message";
331     private static final String PARAMETER_WORKGROUP = "workgroup";
332     private static final String PARAMETER_ID_VOTE_TYPE = "id_vote_type";
333     private static final String PARAMETER_ACTIVE_PROPOSITION_STATE = "active_digg_proposition_state";
334     private static final String PARAMETER_NUMBER_VOTE_REQUIRED = "number_vote_required";
335     private static final String PARAMETER_NUMBER_DAY_REQUIRED = "number_day_required";
336     private static final String PARAMETER_ACTIVE_DIGG_SUBMIT_AUTHENTIFICATION = "active_digg_submit_authentification";
337     private static final String PARAMETER_ACTIVE_VOTE_AUTHENTIFICATION = "active_vote_authentification";
338     private static final String PARAMETER_ACTIVE_COMMENT_AUTHENTIFICATION = "active_comment_authentification";
339     private static final String PARAMETER_DISABLE_NEW_DIGG_SUBMIT = "disable_new_digg_submit";
340     private static final String PARAMETER_ENABLE_MAIL_NEW_DIGG_SUBMIT = "enable_mail_new_digg_submit";
341     private static final String PARAMETER_ENABLE_MAIL_NEW_COMMENT_SUBMIT = "enable_mail_new_comment_submit";
342     private static final String PARAMETER_ENABLE_MAIL_NEW_REPORTED_SUBMIT = "enable_mail_new_reported_submit";
343     private static final String PARAMETER_ID_MAILING_LIST_DIGG_SUBMIT = "id_mailing_list_digg_submit";
344     private static final String PARAMETER_AUTHORIZED_COMMENT = "authorized_comment";
345     private static final String PARAMETER_DISABLE_NEW_COMMENT = "disable_new_comment";
346     private static final String PARAMETER_ACTIVE_CAPTCHA = "active_captcha";
347     private static final String PARAMETER_LIBELLE_VALIDATE_BUTTON = "libelle_validate_button";
348     private static final String PARAMETER_ID_CATEGORY = "id_category";
349     private static final String PARAMETER_ID_CATEGORY_FILTER = "id_category_filter";
350     private static final String PARAMETER_ID_TYPE_DIGG = "id_type";
351     private static final String PARAMETER_ID_DIGG_SUBMIT_STATE = "id_digg_submit_state";
352     private static final String PARAMETER_ID_DIGG_STATE = "id_digg_state";
353     private static final String PARAMETER_ID_DIGG_SUBMIT_TYPE = "id_digg_submit_type";
354     private static final String PARAMETER_ENABLE = "enable";
355     private static final String PARAMETER_DISABLE = "disable";
356     private static final String PARAMETER_COMMENT_VALUE = "comment_value";
357     private static final String PARAMETER_DELETE = "delete";
358     private static final String PARAMETER_PAGE_INDEX = "page_index";
359     private static final String PARAMETER_ID_ENTRY = "id_entry";
360     private static final String PARAMETER_ID_EXPRESSION = "id_expression";
361     private static final String PARAMETER_CANCEL = "cancel";
362     private static final String PARAMETER_APPLY = "apply";
363     private static final String PARAMETER_NUMBER_DIGG_SUBMIT_IN_TOP_SCORE = "number_digg_submit_in_top_score";
364     private static final String PARAMETER_NUMBER_DIGG_SUBMIT_IN_TOP_COMMENT = "number_digg_submit_in_top_comment";
365     private static final String PARAMETER_NUMBER_DIGG_SUBMIT_CARACTERS_SHOWN = "number_digg_submit_caracters_shown";
366     private static final String PARAMETER_LIMIT_NUMBER_VOTE = "limit_number_vote";
367     private static final String PARAMETER_COMMENT = "comment";
368     private static final String PARAMETER_ID_DIGG_SUBMIT_SORT = "id_digg_submit_sort";
369     private static final String PARAMETER_ID_DIGG_SUBMIT_REPORT = "id_digg_submit_report";
370     private static final String PARAMETER_ID_COMMENT_SORT = "id_comment_sort";
371     private static final String PARAMETER_ID_COMMENT_STATE = "id_comment_state";
372     private static final String PARAMETER_ID_CONTAINS_SUB_COMMENT_DISABLE = "id_contains_sub_comment_disable";
373     private static final String PARAMETER_SHOW_CATEGORY_BLOCK = "show_category_block";
374     private static final String PARAMETER_SHOW_TOP_SCORE_BLOCK = "show_top_score_block";
375     private static final String PARAMETER_SHOW_TOP_COMMENT_BLOCK = "show_top_comment_block";
376     private static final String PARAMETER_ACTIVE_DIGG_SUBMIT_PAGINATOR = "active_digg_submit_paginator";
377     private static final String PARAMETER_NUMBER_DIGG_SUBMIT_PER_PAGE = "number_digg_submit_per_page";
378     private static final String PARAMETER_ROLE = "role";
379     private static final String PARAMETER_HEADER = "header";
380     private static final String CONSTANTE_YES_VALUE = "1";
381     private static final String CONSTANTE_NO_VALUE = "0";
382     private static final String PARAMETER_QUERY = "query";
383     private static final String PARAMETER_DIGG_SUBMIT_ORDER = "digg_submit_order";
384     private static final String PARAMETER_FIRST_DATE_FILTER = "first_date_filter";
385     private static final String PARAMETER_LAST_DATE_FILTER = "last_date_filter";
386     private static final String PARAMETER_THEME_XPAGE = "id_theme_list";
387     private static final String PARAMETER_CONFIRMATION_MESSAGE = "confirmation_message";
388     private static final String PARAMETER_ACTIVE_EDITOR_BBCODE_ON_COMMENT = "active_editor_bbcode_on_comment";
389     private static final String PARAMETER_ID_DEFAULT_SORT = "id_default_sort";
390     private static final String PARAMETER_ID_DEFAULT_DIGG = "id_default_digg";
391     private static final String PARAMETER_SELECTED_DIGG_SUBMIT = "selected_digg_submit";
392     private static final String PARAMETER_DISABLE_VOTE = "disable_vote";
393     private static final String PARAMETER_DISABLE_COMMENT = "disable_comment";
394     private static final String PARAMETER_ENABLE_PIN = "enable_pin";
395     private static final String PARAMETER_ENABLE_REPORTS = "enable_reports";
396     private static final String PARAMETER_ENABLE_TERMS_OF_USE = "enable_terms_of_use";
397     private static final String PARAMETER_TERMS_OF_USE = "terms_of_use";
398     private static final String PARAMETER_DISPLAY_COMMENT_IN_DIGG_SUBMIT_LIST = "display_comment_in_digg_submit_list";
399     private static final String PARAMETER_NUMBER_COMMENT_DISPLAY_IN_DIGG_SUBMIT_LIST = "number_comment_display_in_digg_submit_list";
400     private static final String PARAMETER_NUMBER_CHAR_COMMENT_DISPLAY_IN_DIGG_SUBMIT_LIST = "number_char_comment_display_in_digg_submit_list";
401     private static final String PARAMETER_UPDATE_FILE = "update_file";
402     private static final String PARAMETER_IMAGE_SOURCE = "image_source";
403     private static final String PARAMETER_DESCRIPTION = "description";
404     private static final String PARAMETER_ID_CONTAINS_COMMENT_DISABLE = "id_contains_comment_disable";
405     private static final String PARAMETER_NOTIFICATION_NEW_COMMENT_SENDER_NAME ="notification_new_comment_sender_name";
406     private static final String PARAMETER_NOTIFICATION_NEW_COMMENT_TITLE="notification_new_comment_title";
407     private static final String PARAMETER_NOTIFICATION_NEW_COMMENT_BODY="notification_new_comment_body";
408     private static final String PARAMETER_NOTIFICATION_NEW_DIGG_SUBMIT_SENDER_NAME="notification_new_digg_submit_sender_name";
409     private static final String PARAMETER_NOTIFICATION_NEW_DIGG_SUBMIT_TITLE="notification_new_digg_submit_title";
410     private static final String PARAMETER_NOTIFICATION_NEW_DIGG_SUBMIT_BODY="notification_new_digg_submit_body";
411     // other constants
412     private static final String EMPTY_STRING = "";
413     private static final String JCAPTCHA_PLUGIN = "jcaptcha";
414 
415     // private static final String EXPORT_TMPFILE_PREFIX = "exportDigg";
416     // private static final String EXPORT_TMPFILE_SUFIX = ".part";
417     // private static final String CONSTANT_MIME_TYPE_CSV = "application/csv";
418 
419     // session fields
420     private DigglikeAdminSearchFields _searchFields = new DigglikeAdminSearchFields(  );
421     private int _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_ITEM_PER_PAGE, 50 );
422     private String _strCurrentPageIndexDigg;
423     private int _nItemsPerPageDigg;
424     private String _strCurrentPageIndexDiggSubmit;
425     private String _strCurrentPageIndexCommentSubmit;
426     private int _nItemsPerPageDiggSubmit;
427     private String _strCurrentPageIndexDiggSubmitOrder;
428     private int _nItemsPerPageDiggSubmitOrder;
429     private int _nItemsPerPageCommentSubmit;
430     private String _strCurrentPageIndexEntry;
431     private int _nItemsPerPageEntry;
432     private String _strCurrentPageIndex;
433     private int _nItemsPerPage;
434     private int _nIdDiggState = DiggUtils.CONSTANT_ID_NULL;
435     private int _nIdDigg = DiggUtils.CONSTANT_ID_NULL;
436     private int _nIdDiggSubmit = DiggUtils.CONSTANT_ID_NULL;
437     private int _nIdCommentSort = DiggUtils.CONSTANT_ID_NULL;
438     private int _nIdCommentState = DiggUtils.CONSTANT_ID_NULL;
439     private int _nIdContainsSubCommentDisable = DiggUtils.CONSTANT_ID_NULL;
440     private String _strWorkGroup = AdminWorkgroupService.ALL_GROUPS;
441     private IDiggSubmitService _diggSubmitService = DiggSubmitService.getService(  );
442     private ICommentSubmitService _commentSubmitService = CommentSubmitService.getService(  );
443 
444     /*-------------------------------MANAGEMENT  DIGG-----------------------------*/
445 
446     /**
447      * Return management Digg( list of digg )
448      *
449      * @param request
450      *            The Http request
451      * @return Html digg
452      */
453     public String getManageDigg( HttpServletRequest request )
454     {
455         AdminUser adminUser = getUser(  );
456         Plugin plugin = getPlugin(  );
457         Locale locale = getLocale(  );
458         ReferenceList refListWorkGroups;
459         ReferenceList refListDiggState;
460         List<DiggAction> listActionsForDiggEnable;
461         List<DiggAction> listActionsForDiggDisable;
462         List<DiggAction> listActions;
463 
464         String strWorkGroup = request.getParameter( PARAMETER_WORKGROUP );
465         String strIdDiggState = request.getParameter( PARAMETER_ID_DIGG_STATE );
466         _strCurrentPageIndexDigg = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX,
467                 _strCurrentPageIndexDigg );
468         _nItemsPerPageDigg = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE,
469                 _nItemsPerPageDigg, _nDefaultItemsPerPage );
470 
471         if ( ( strIdDiggState != null ) && !strIdDiggState.equals( EMPTY_STRING ) )
472         {
473             _nIdDiggState = DiggUtils.getIntegerParameter( strIdDiggState );
474         }
475 
476         if ( ( strWorkGroup != null ) && !strWorkGroup.equals( EMPTY_STRING ) )
477         {
478             _strWorkGroup = strWorkGroup;
479         }
480 
481         // build Filter
482         DiggFilter filter = new DiggFilter(  );
483         filter.setIdState( _nIdDiggState );
484         filter.setWorkGroup( _strWorkGroup );
485 
486         List<Digg> listDigg = DiggHome.getDiggList( filter, getPlugin(  ) );
487         listDigg = (List<Digg>) AdminWorkgroupService.getAuthorizedCollection( listDigg, adminUser );
488 
489         refListWorkGroups = AdminWorkgroupService.getUserWorkgroups( adminUser, locale );
490         refListDiggState = getRefListDiggState( locale );
491 
492         Map<String, Object> model = new HashMap<String, Object>(  );
493         Paginator<Digg> paginator = new Paginator<Digg>( listDigg, _nItemsPerPageDigg, getJspManageDigg( request ),
494                 PARAMETER_PAGE_INDEX, _strCurrentPageIndexDigg );
495 
496         listActionsForDiggEnable = DiggActionHome.selectActionsByDiggState( Digg.STATE_ENABLE, plugin, locale );
497         listActionsForDiggDisable = DiggActionHome.selectActionsByDiggState( Digg.STATE_DISABLE, plugin, locale );
498 
499         for ( Digg digg : paginator.getPageItems(  ) )
500         {
501             if ( digg.isActive(  ) )
502             {
503                 listActions = listActionsForDiggEnable;
504             }
505             else
506             {
507                 listActions = listActionsForDiggDisable;
508             }
509 
510             listActions = (List<DiggAction>) RBACService.getAuthorizedActionsCollection( listActions, digg, getUser(  ) );
511             digg.setActions( listActions );
512         }
513 
514         model.put( MARK_PAGINATOR, paginator );
515         model.put( MARK_NB_ITEMS_PER_PAGE, EMPTY_STRING + _nItemsPerPageDigg );
516         model.put( MARK_USER_WORKGROUP_REF_LIST, refListWorkGroups );
517         model.put( MARK_USER_WORKGROUP_SELECTED, _strWorkGroup );
518         model.put( MARK_DIGG_STATE_REF_LIST, refListDiggState );
519         model.put( MARK_DIGG_STATE_SELECTED, _nIdDiggState );
520 
521         model.put( MARK_DIGG_LIST, paginator.getPageItems(  ) );
522 
523         boolean bPermissionAdvancedParameter = RBACService.isAuthorized( Digg.RESOURCE_TYPE,
524                 RBAC.WILDCARD_RESOURCES_ID, DigglikeResourceIdService.PERMISSION_MANAGE_ADVANCED_PARAMETERS, getUser(  ) );
525         boolean bPermissionCreateDigg = RBACService.isAuthorized( Digg.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
526                 DigglikeResourceIdService.PERMISSION_CREATE, getUser(  ) );
527 
528         model.put( MARK_PERMISSION_MANAGE_ADVANCED_PARAMETERS, bPermissionAdvancedParameter );
529         model.put( MARK_PERMISSION_CREATE_DIGG, bPermissionCreateDigg );
530 
531         setPageTitleProperty( PROPERTY_MANAGE_DIGG_PAGE_TITLE );
532 
533         HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_MANAGE_DIGG, locale, model );
534 
535         // ReferenceList refMailingList;
536         // refMailingList=AdminMailingListService.getMailingLists(adminUser);
537         return getAdminPage( templateList.getHtml(  ) );
538     }
539 
540     /**
541      * Returns advanced parameters form
542      *
543      * @param request The Http request
544      * @return Html form
545      */
546     public String getManageAdvancedParameters( HttpServletRequest request )
547     {
548         if ( !RBACService.isAuthorized( Digg.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
549                     DigglikeResourceIdService.PERMISSION_MANAGE_ADVANCED_PARAMETERS, getUser(  ) ) )
550         {
551             return getManageDigg( request );
552         }
553 
554         Map<String, Object> model = new HashMap<String, Object>(  );
555         List<Digg> listDigg = DiggHome.getDiggList( new DiggFilter(  ), getPlugin(  ) );
556         int nIdDefaultDigg = -1;
557 
558         for ( Digg digg : listDigg )
559         {
560             if ( digg.isDefaultDigg(  ) )
561             {
562                 nIdDefaultDigg = digg.getIdDigg(  );
563 
564                 break;
565             }
566         }
567 
568         model.put( MARK_DIGG_LIST, DiggUtils.getRefListDigg( listDigg, true ) );
569         model.put( MARK_ID_DEFAULT_DIGG, nIdDefaultDigg );
570         model.put( MARK_PERMISSION_MANAGE_EXPORT_FORMAT,
571             RBACService.isAuthorized( ExportFormat.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
572                 ExportFormatResourceIdService.PERMISSION_MANAGE, getUser(  ) ) );
573         model.put( MARK_PERMISSION_MANAGE_CATEGORY,
574             RBACService.isAuthorized( Category.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
575                 CategoryResourceIdService.PERMISSION_MANAGE, getUser(  ) ) );
576         model.put( MARK_PERMISSION_MANAGE_DEFAULT_MESSAGE,
577             RBACService.isAuthorized( DefaultMessage.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
578                 DefaultMessageResourceIdService.PERMISSION_MANAGE, getUser(  ) ) );
579 
580         HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_MANAGE_ADVANCED_PARAMETERS, getLocale(  ),
581                 model );
582 
583         setPageTitleProperty( PROPERTY_MANAGE_ADVANCED_PARAMETERS_PAGE_TITLE );
584 
585         return getAdminPage( templateList.getHtml(  ) );
586     }
587 
588     /**
589      * Return management DiggSubmit( list of digg submit)
590      *
591      * @param request The Http request
592      * @param response The Http response
593      * @return Html digg
594      * @throws AccessDeniedException If the user is not authorized to access
595      *             this feature
596      */
597     public IPluginActionResult getManageDiggSubmit( HttpServletRequest request, HttpServletResponse response )
598         throws AccessDeniedException
599     {
600         ReferenceList refListDiggSumitState = initRefListDiggSubmitState( getPlugin(  ), getLocale(  ) );
601         ReferenceList refListAllYesNo;
602         int nNumberShownCharacters = AppPropertiesService.getPropertyInt( PROPERTY_NUMBER_DIGG_SUBMIT_VALUE_SHOWN_CHARACTERS,
603                 100 );
604 
605         String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
606         List<DiggSubmit> listDiggSubmitDisplay = new ArrayList<DiggSubmit>(  );
607         // display could have been an action but it's the default one an will always be here...
608         _strCurrentPageIndexDiggSubmit = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX,
609                 _strCurrentPageIndexDiggSubmit );
610         _nItemsPerPageDiggSubmit = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE,
611                 _nItemsPerPageDiggSubmit, _nDefaultItemsPerPage );
612 
613         if ( ( strIdDigg != null ) && !strIdDigg.equals( EMPTY_STRING ) )
614         {
615             _nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
616         }
617 
618         updateSearchFieldsData( request );
619 
620         Digg digg = DiggHome.findByPrimaryKey( _nIdDigg, getPlugin(  ) );
621 
622         if ( ( digg == null ) ||
623                 !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + digg.getIdDigg(  ),
624                     DigglikeResourceIdService.PERMISSION_MANAGE_DIGG_SUBMIT, getUser(  ) ) )
625         {
626             throw new AccessDeniedException(  );
627         }
628 
629         // fill the selected records
630         String[] selectedDiggSubmit = request.getParameterValues( PARAMETER_SELECTED_DIGG_SUBMIT );
631         List<String> listSelectedDiggSubmit;
632 
633         if ( selectedDiggSubmit != null )
634         {
635             listSelectedDiggSubmit = Arrays.asList( selectedDiggSubmit );
636 
637             if ( AppLogService.isDebugEnabled(  ) )
638             {
639                 AppLogService.debug( "List selected diggSubmit : " + listSelectedDiggSubmit );
640             }
641         }
642         else
643         {
644             listSelectedDiggSubmit = new ArrayList<String>(  );
645         }
646 
647         _searchFields.setSelectedDiggSubmit( listSelectedDiggSubmit );
648 
649         // first - see if there is an invoked action
650         IDigglikeAction action = PluginActionManager.getPluginAction( request, IDigglikeAction.class );
651 
652         if ( action != null )
653         {
654             if ( AppLogService.isDebugEnabled(  ) )
655             {
656                 AppLogService.debug( "Processing directory action " + action.getName(  ) );
657             }
658 
659             return action.process( request, response, getUser(  ), _searchFields );
660         }
661 
662         DefaultPluginActionResult result = new DefaultPluginActionResult(  );
663 
664         // build Filter
665         SubmitFilter filter = DiggUtils.getDiggSubmitFilter( getSearchFields(  ), digg.getIdDefaultSort(  ) );
666 
667         List<Integer> listIdDiggSubmitResult;
668 
669         if ( ( getSearchFields(  ).getQuery(  ) != null ) &&
670                 ( getSearchFields(  ).getQuery(  ).trim(  ) != DiggUtils.EMPTY_STRING ) )
671         {
672             int nId = 0;
673 
674             try
675             {
676                 nId = Integer.parseInt( getSearchFields(  ).getQuery(  ) );
677                 filter.setIdDiggSubmit( nId );
678                 listIdDiggSubmitResult = _diggSubmitService.getDiggSubmitListId( filter, getPlugin(  ) );
679             }
680             catch ( NumberFormatException e )
681             {
682                 // the query is not the id of the digg submit
683                 listIdDiggSubmitResult = DigglikeSearchService.getInstance(  )
684                                                               .getSearchResults( getSearchFields(  ).getQuery(  ),
685                         filter, getPlugin(  ) );
686             }
687         }
688         else
689         {
690             listIdDiggSubmitResult = _diggSubmitService.getDiggSubmitListId( filter, getPlugin(  ) );
691         }
692 
693         ReferenceList refListDiggSort = DiggUtils.getRefListDiggSort( getLocale(  ) );
694         refListAllYesNo = getRefListAllYesNo( getLocale(  ) );
695 
696         Map<String, Object> model = new HashMap<String, Object>(  );
697         Paginator<Integer> paginator = new Paginator<Integer>( listIdDiggSubmitResult, _nItemsPerPageDiggSubmit,
698                 getJspManageDiggSubmit( request ), PARAMETER_PAGE_INDEX, _strCurrentPageIndexDiggSubmit );
699         DiggSubmit diggSubmit;
700 
701         for ( Object idDiggSubmitDisplay : paginator.getPageItems(  ) )
702         {
703             diggSubmit = _diggSubmitService.findByPrimaryKey( (Integer) idDiggSubmitDisplay, false, getPlugin(  ) );
704             listDiggSubmitDisplay.add( diggSubmit );
705         }
706 
707         if ( ( digg.getCategories(  ) != null ) && !digg.getCategories(  ).isEmpty(  ) )
708         {
709             ReferenceList refCategoryList = DiggUtils.getRefListCategory( digg.getCategories(  ) );
710             DiggUtils.addEmptyItem( refCategoryList );
711             model.put( MARK_CATEGORY_LIST, refCategoryList );
712             model.put( MARK_DIGG_SUBMIT_CATEGORY_SELECTED, getSearchFields(  ).getIdCategory(  ) );
713         }
714 
715         if ( ( digg.getDiggSubmitTypes(  ) != null ) && !digg.getDiggSubmitTypes(  ).isEmpty(  ) )
716         {
717             ReferenceList refDiggSubmitTypes = DiggUtils.getRefListType( digg.getDiggSubmitTypes(  ) );
718             DiggUtils.addEmptyItem( refDiggSubmitTypes );
719             model.put( MARK_DIGG_SUBMIT_TYPE_LIST, refDiggSubmitTypes );
720             model.put( MARK_DIGG_SUBMIT_TYPE_SELECTED, getSearchFields(  ).getIdType(  ) );
721         }
722 
723         model.put( MARK_PAGINATOR, paginator );
724         model.put( MARK_NB_ITEMS_PER_PAGE, EMPTY_STRING + _nItemsPerPageDiggSubmit );
725         model.put( MARK_DIGG_SUBMIT_STATE_REF_LIST, refListDiggSumitState );
726         model.put( MARK_DIGG_SUBMIT_STATE_SELECTED, getSearchFields(  ).getIdDiggSumitState(  ) );
727         model.put( MARK_DIGG_SUBMIT_LIST, listDiggSubmitDisplay );
728         model.put( MARK_DIGG, digg );
729         model.put( MARK_DISABLE_DIGG_SUBMIT_STATE_NUMBER, DiggSubmit.STATE_DISABLE );
730         model.put( MARK_PUBLISH_DIGG_SUBMIT_STATE_NUMBER, DiggSubmit.STATE_PUBLISH );
731         model.put( MARK_WAITING_FOR_PUBLISH_DIGG_SUBMIT_STATE_NUMBER, DiggSubmit.STATE_WAITING_FOR_PUBLISH );
732         model.put( MARK_NUMBER_SHOWN_CHARACTERS, nNumberShownCharacters );
733         model.put( MARK_LIST_DIGG_SUBMIT_SORT, refListDiggSort );
734         model.put( MARK_DIGG_SUBMIT_SORT_SELECTED, getSearchFields(  ).getIdDiggSubmitSort(  ) );
735         model.put( MARK_REPORT_REF_LIST, refListAllYesNo );
736         model.put( MARK_REPORT_SELECTED, getSearchFields(  ).getIdDiggSubmitReport(  ) );
737         model.put( MARK_CONTAINS_COMMENT_DISABLE_LIST, refListAllYesNo );
738         model.put( MARK_CONTAINS_COMMENT_DISABLE_SELECTED, getSearchFields(  ).getIdDiggSubmitContainsCommentDisable(  ) );
739         model.put( MARK_QUERY, getSearchFields(  ).getQuery(  ) );
740 
741         PluginActionManager.fillModel( request, getUser(  ), model, IDigglikeAction.class, MARK_DIGGLIKE_ACTIONS );
742 
743         setPageTitleProperty( PROPERTY_MANAGE_DIGG_SUBMIT_PAGE_TITLE );
744 
745         HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_MANAGE_DIGG_SUBMIT, getLocale(  ), model );
746 
747         // ReferenceList refMailingList;
748         // refMailingList=AdminMailingListService.getMailingLists(adminUser);
749         result.setHtmlContent( getAdminPage( templateList.getHtml(  ) ) );
750 
751         return result;
752     }
753 
754     /**
755      * Returns advanced parameters form
756      *
757      * @param request The Http request
758      * @return Html form
759      * @throws AccessDeniedException If the user is not authorized to access
760      *             this feature
761      */
762     public String getManageDiggSubmitOrder( HttpServletRequest request )
763         throws AccessDeniedException
764     {
765         String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
766         int nNumberShownCharacters = AppPropertiesService.getPropertyInt( PROPERTY_NUMBER_DIGG_SUBMIT_VALUE_SHOWN_CHARACTERS,
767                 100 );
768 
769         _strCurrentPageIndexDiggSubmitOrder = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX,
770                 _strCurrentPageIndexDiggSubmitOrder );
771         _nItemsPerPageDiggSubmitOrder = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE,
772                 _nItemsPerPageDiggSubmitOrder, _nDefaultItemsPerPage );
773 
774         List<DiggSubmit> listDiggSubmitDisplay = new ArrayList<DiggSubmit>(  );
775 
776         if ( ( strIdDigg != null ) && !strIdDigg.equals( EMPTY_STRING ) )
777         {
778             _nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
779         }
780 
781         Digg digg = DiggHome.findByPrimaryKey( _nIdDigg, getPlugin(  ) );
782 
783         if ( ( digg == null ) ||
784                 !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + digg.getIdDigg(  ),
785                     DigglikeResourceIdService.PERMISSION_MANAGE_DIGG_SUBMIT, getUser(  ) ) )
786         {
787             throw new AccessDeniedException(  );
788         }
789 
790         // build Filter
791         SubmitFilter filter = DiggUtils.getDiggSubmitFilter( getSearchFields(  ) );
792         //reinit order
793         filter.setSortBy( new ArrayList<Integer>(  ) );
794         DiggUtils.initSubmitFilterBySort( filter, SubmitFilter.SORT_MANUALLY );
795         DiggUtils.initSubmitFilterBySort( filter, SubmitFilter.SORT_BY_PINNED_FIRST );
796 
797         List<Integer> listIdDiggSubmitResult = _diggSubmitService.getDiggSubmitListId( filter, getPlugin( ) );
798 
799         Map<String, Object> model = new HashMap<String, Object>(  );
800         Paginator<Integer> paginator = new Paginator<Integer>( listIdDiggSubmitResult, _nItemsPerPageDiggSubmitOrder,
801                 getJspManageDiggSubmitOrder( request ), PARAMETER_PAGE_INDEX, _strCurrentPageIndexDiggSubmitOrder );
802         DiggSubmit diggSubmit;
803 
804         for ( Object idDiggSubmitDisplay : paginator.getPageItems(  ) )
805         {
806             diggSubmit = _diggSubmitService.findByPrimaryKey( (Integer) idDiggSubmitDisplay, false, getPlugin(  ) );
807             listDiggSubmitDisplay.add( diggSubmit );
808         }
809 
810         model.put( MARK_DIGG_SUBMIT_ORDER_LIST_PINNED, getDiggSubmitOrderList( _nIdDigg, true ) );
811         model.put( MARK_DIGG_SUBMIT_ORDER_LIST, getDiggSubmitOrderList( _nIdDigg, false ) );
812         model.put( MARK_DISABLE_DIGG_SUBMIT_STATE_NUMBER, DiggSubmit.STATE_DISABLE );
813         model.put( MARK_PUBLISH_DIGG_SUBMIT_STATE_NUMBER, DiggSubmit.STATE_PUBLISH );
814         model.put( MARK_WAITING_FOR_PUBLISH_DIGG_SUBMIT_STATE_NUMBER, DiggSubmit.STATE_WAITING_FOR_PUBLISH );
815 
816         model.put( MARK_PAGINATOR, paginator );
817         model.put( MARK_NB_ITEMS_PER_PAGE, EMPTY_STRING + _nItemsPerPageDiggSubmit );
818 
819         model.put( MARK_DIGG_SUBMIT_LIST, listDiggSubmitDisplay );
820         model.put( MARK_DIGG, digg );
821         model.put( MARK_NUMBER_SHOWN_CHARACTERS, nNumberShownCharacters );
822 
823         HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_MANAGE_DIGG_SUBMIT_ORDER, getLocale(  ),
824                 model );
825 
826         setPageTitleProperty( PROPERTY_MANAGE_DIGG_SUBMIT_ORDER_PAGE_TITLE );
827 
828         return getAdminPage( templateList.getHtml(  ) );
829     }
830 
831     /**
832      * Return create digg submit form
833      *
834      * @param request
835      *            The Http request
836      * @return Html comment submit
837      * @throws AccessDeniedException If the user is not authorized to access
838      *             this feature
839      */
840     public String getCreateDiggSubmit( HttpServletRequest request )
841         throws AccessDeniedException
842     {
843         String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
844 
845         if ( ( strIdDigg != null ) && !strIdDigg.equals( EMPTY_STRING ) )
846         {
847             _nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
848         }
849 
850         Digg digg = DiggHome.findByPrimaryKey( _nIdDigg, getPlugin(  ) );
851 
852         if ( ( digg == null ) ||
853                 !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + digg.getIdDigg(  ),
854                     DigglikeResourceIdService.PERMISSION_MANAGE_DIGG_SUBMIT, getUser(  ) ) )
855         {
856             throw new AccessDeniedException(  );
857         }
858 
859         Map<String, Object> model = DiggUtils.getModelHtmlForm( digg, getPlugin(  ), getLocale(  ),
860                 DiggUtils.CONSTANT_ID_NULL, true );
861 
862         HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_CREATE_DIGG_SUBMIT, getLocale(  ), model );
863 
864         setPageTitleProperty( PROPERTY_CREATE_DIGG_SUBMIT_PAGE_TITLE );
865 
866         return getAdminPage( templateList.getHtml(  ) );
867     }
868 
869     /**
870      * Perform the digg creation
871      *
872      * @param request
873      *            The HTTP request
874      * @return The URL to go after performing the action
875      */
876     public String doCreateDiggSubmit( HttpServletRequest request )
877     {
878         String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
879 
880         if ( ( strIdDigg != null ) && !strIdDigg.equals( EMPTY_STRING ) )
881         {
882             _nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
883         }
884 
885         Digg digg = DiggHome.findByPrimaryKey( _nIdDigg, getPlugin(  ) );
886 
887         if ( ( request.getParameter( PARAMETER_CANCEL ) == null ) &&
888                 RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + digg.getIdDigg(  ),
889                     DigglikeResourceIdService.PERMISSION_MANAGE_DIGG_SUBMIT, getUser(  ) ) )
890         {
891             List<Response> listResponse = new ArrayList<Response>(  );
892             String strIdCategory = request.getParameter( PARAMETER_ID_CATEGORY );
893             String strIdType = request.getParameter( PARAMETER_ID_TYPE_DIGG );
894             String strDisableVote = request.getParameter( PARAMETER_DISABLE_VOTE );
895             String strDisableComment = request.getParameter( PARAMETER_DISABLE_COMMENT );
896             String strEnablePin = request.getParameter( PARAMETER_ENABLE_PIN );
897             int nIdCategory = DiggUtils.getIntegerParameter( strIdCategory );
898             int nIdType = DiggUtils.getIntegerParameter( strIdType );
899 
900             //Check if a category is selected (in the case or the digg has some categories)
901             if ( !digg.getCategories(  ).isEmpty(  ) )
902             {
903                 if ( ( strIdCategory == null ) ||
904                         strIdCategory.equals( Integer.toString( DiggUtils.CONSTANT_ID_NULL ) ) )
905                 {
906                     return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_NO_CATEGORY, AdminMessage.TYPE_STOP );
907                 }
908             }
909 
910             //Check if a category is selected (in the case or the digg has some type)
911             if ( !digg.getDiggSubmitTypes(  ).isEmpty(  ) )
912             {
913                 if ( ( strIdType == null ) || strIdType.equals( Integer.toString( DiggUtils.CONSTANT_ID_NULL ) ) )
914                 {
915                     return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_NO_DIGG_SUBMIT_TYPE_SELECTED,
916                         AdminMessage.TYPE_STOP );
917                 }
918             }
919 
920             DiggSubmit diggSubmit = new DiggSubmit(  );
921             diggSubmit.setDigg( digg );
922             diggSubmit.setResponses( listResponse );
923 
924             FormError formError = DiggUtils.getAllResponsesData( request, diggSubmit, getPlugin(  ), getLocale(  ) );
925 
926             if ( formError != null )
927             {
928                 if ( formError.isMandatoryError(  ) )
929                 {
930                     Object[] tabRequiredFields = { formError.getTitleQuestion(  ) };
931 
932                     return AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_QUESTION, tabRequiredFields,
933                         AdminMessage.TYPE_STOP );
934                 }
935 
936                 Object[] tabFormError = { formError.getTitleQuestion(  ), formError.getErrorMessage(  ) };
937 
938                 return AdminMessageService.getMessageUrl( request, MESSAGE_FORM_ERROR, tabFormError,
939                     AdminMessage.TYPE_STOP );
940             }
941 
942             // perform digg submit
943             if ( nIdCategory != DiggUtils.CONSTANT_ID_NULL )
944             {
945                 Category category = CategoryHome.findByPrimaryKey( nIdCategory, getPlugin(  ) );
946                 diggSubmit.setCategory( category );
947             }
948 
949             if ( nIdType != DiggUtils.CONSTANT_ID_NULL )
950             {
951                 DiggSubmitType type = DiggSubmitTypeHome.findByPrimaryKey( nIdType, getPlugin(  ) );
952                 diggSubmit.setDiggSubmitType( type );
953             }
954 
955             diggSubmit.setDisableComment( strDisableComment != null );
956             diggSubmit.setDisableVote( strDisableVote != null );
957             diggSubmit.setPinned( strEnablePin != null );
958             _diggSubmitService.create( diggSubmit, getPlugin(  ), getLocale(  ) );
959         }
960 
961         return getJspManageDiggSubmit( request );
962     }
963 
964     /**
965      * Return management CommentSubmit( list of comment submit)
966      *
967      * @param request
968      *            The Http request
969      * @return Html comment submit
970      * @throws AccessDeniedException If the user is not authorized to access
971      *             this feature
972      */
973     public String getManageCommentSubmit( HttpServletRequest request )
974         throws AccessDeniedException
975     {
976         Plugin plugin = getPlugin(  );
977         Locale locale = getLocale(  );
978 
979         String strIdCommentSort = request.getParameter( PARAMETER_ID_COMMENT_SORT );
980         String strIdCommentState = request.getParameter( PARAMETER_ID_COMMENT_STATE );
981         String strIdContainsSubCommentDisable = request.getParameter( PARAMETER_ID_CONTAINS_SUB_COMMENT_DISABLE );
982 
983         String strCommentIdParent = request.getParameter( PARAMETER_ID_PARENT );
984 
985         if ( ( strIdCommentSort != null ) && !strIdCommentSort.equals( EMPTY_STRING ) )
986         {
987             _nIdCommentSort = DiggUtils.getIntegerParameter( strIdCommentSort );
988         }
989 
990         if ( ( strIdCommentState != null ) && !strIdCommentState.equals( EMPTY_STRING ) )
991         {
992             _nIdCommentState = DiggUtils.getIntegerParameter( strIdCommentState );
993         }
994 
995         if ( ( strIdContainsSubCommentDisable != null ) && !strIdContainsSubCommentDisable.equals( EMPTY_STRING ) )
996         {
997             _nIdContainsSubCommentDisable = DiggUtils.getIntegerParameter( strIdContainsSubCommentDisable );
998         }
999 
1000         int nNumberShownCharacters = AppPropertiesService.getPropertyInt( PROPERTY_NUMBER_DIGG_SUBMIT_VALUE_SHOWN_CHARACTERS,
1001                 100 );
1002         String strIdDiggSubmit = request.getParameter( PARAMETER_ID_DIGG_SUBMIT );
1003         _strCurrentPageIndexCommentSubmit = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX,
1004                 _strCurrentPageIndexCommentSubmit );
1005         _nItemsPerPageCommentSubmit = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE,
1006                 _nItemsPerPageCommentSubmit, _nDefaultItemsPerPage );
1007 
1008         if ( ( strIdDiggSubmit != null ) && !strIdDiggSubmit.equals( EMPTY_STRING ) )
1009         {
1010             _nIdDiggSubmit = DiggUtils.getIntegerParameter( strIdDiggSubmit );
1011         }
1012 
1013         DiggSubmit diggSubmit = _diggSubmitService.findByPrimaryKey( _nIdDiggSubmit, false, plugin );
1014         Digg digg = DiggHome.findByPrimaryKey( diggSubmit.getDigg(  ).getIdDigg(  ), plugin );
1015 
1016         if ( !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + diggSubmit.getDigg(  ).getIdDigg(  ),
1017                     DigglikeResourceIdService.PERMISSION_MANAGE_DIGG_SUBMIT, getUser(  ) ) )
1018         {
1019             throw new AccessDeniedException(  );
1020         }
1021 
1022         //add repoted Message
1023         if ( diggSubmit.isReported(  ) )
1024         {
1025             diggSubmit.setReportedMessages( ReportedMessageHome.getReportedMessageByDiggSubmit( 
1026                     diggSubmit.getIdDiggSubmit(  ), getPlugin(  ) ) );
1027         }
1028 
1029         // build Filter
1030         SubmitFilter filter = DiggUtils.getDiggSubmitFilter( getSearchFields(  ) );
1031 
1032         SubmitFilter commentFilter = new SubmitFilter(  );
1033         commentFilter.setIdDiggSubmit( _nIdDiggSubmit );
1034         commentFilter.setIdDigg( _nIdDigg );
1035         commentFilter.setIdContainsCommentDisable( _nIdContainsSubCommentDisable );
1036         commentFilter.setIdCommentSubmitState( _nIdCommentState );
1037 
1038         DiggUtils.initCommentFilterBySort( commentFilter, _nIdCommentSort );
1039 
1040         List<CommentSubmit> listCommentSubmit = _commentSubmitService.getCommentSubmitList( commentFilter, getPlugin(  ) );
1041 
1042         ReferenceList refListCommentSort = DiggUtils.getRefListCommentSort( locale );
1043 
1044         ReferenceList refCategoryList = DiggUtils.getRefListCategory( digg.getCategories(  ) );
1045         DiggUtils.addEmptyItem( refCategoryList );
1046 
1047         Map<String, Object> model = new HashMap<String, Object>(  );
1048         Paginator<CommentSubmit> paginator = new Paginator<CommentSubmit>( listCommentSubmit,
1049                 _nItemsPerPageCommentSubmit, getJspManageCommentSubmit( request ), PARAMETER_PAGE_INDEX,
1050                 _strCurrentPageIndexCommentSubmit );
1051         ReferenceList refListAllYesNo = getRefListAllYesNo( getLocale(  ) );
1052 
1053         model.put( MARK_COMMENT_SORT_SELECTED, _nIdCommentSort );
1054         model.put( MARK_COMMENT_SORT_LIST, refListCommentSort );
1055         model.put( MARK_COMMENT_STATE_SELECTED, _nIdCommentState );
1056         model.put( MARK_COMMENT_STATE_LIST, DiggUtils.getRefListCommentState( locale ) );
1057         model.put( MARK_CONTAINS_SUB_COMMENT_DISABLE_SELECTED, _nIdContainsSubCommentDisable );
1058         model.put( MARK_CONTAINS_SUB_COMMENT_DISABLE_LIST, refListAllYesNo );
1059         model.put( MARK_PAGINATOR, paginator );
1060         model.put( MARK_NB_ITEMS_PER_PAGE, EMPTY_STRING + _nItemsPerPageCommentSubmit );
1061         model.put( MARK_COMMENT_SUBMIT_LIST, paginator.getPageItems(  ) );
1062         model.put( MARK_DIGG_SUBMIT, diggSubmit );
1063         model.put( MARK_ID_DIGG_SUBMIT_PREV,
1064             _diggSubmitService.findPrevIdDiggSubmitInTheList( _nIdDiggSubmit, filter, plugin ) );
1065         model.put( MARK_ID_DIGG_SUBMIT_NEXT,
1066             _diggSubmitService.findNextIdDiggSubmitInTheList( _nIdDiggSubmit, filter, plugin ) );
1067         model.put( MARK_DISABLE_DIGG_SUBMIT_STATE_NUMBER, DiggSubmit.STATE_DISABLE );
1068         model.put( MARK_PUBLISH_DIGG_SUBMIT_STATE_NUMBER, DiggSubmit.STATE_PUBLISH );
1069         model.put( MARK_WAITING_FOR_PUBLISH_DIGG_SUBMIT_STATE_NUMBER, DiggSubmit.STATE_WAITING_FOR_PUBLISH );
1070         model.put( MARK_NUMBER_SHOWN_CHARACTERS, nNumberShownCharacters );
1071         model.put( MARK_CATEGORY_LIST, refCategoryList );
1072 
1073         model.put( MARK_DIGG, digg );
1074         model.put( MARK_ID_PARENT, strCommentIdParent );
1075 
1076         setPageTitleProperty( PROPERTY_MANAGE_COMMENT_SUBMIT_PAGE_TITLE );
1077 
1078         HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_MANAGE_COMMENT_SUBMIT, locale, model );
1079 
1080         // ReferenceList refMailingList;
1081         // refMailingList=AdminMailingListService.getMailingLists(adminUser);
1082         return getAdminPage( templateList.getHtml(  ) );
1083     }
1084 
1085     /**
1086      * Gets the confirmation page of delete digg submit
1087      *
1088      * @param request
1089      *            The HTTP request
1090      * @return the confirmation page of delete digg submit
1091      */
1092     public String getConfirmRemoveDiggSubmit( HttpServletRequest request )
1093     {
1094         String strIdDiggSubmit = request.getParameter( PARAMETER_ID_DIGG_SUBMIT );
1095         String strComment = request.getParameter( PARAMETER_COMMENT );
1096 
1097         String strMessage;
1098         int nIdDiggSubmit = DiggUtils.getIntegerParameter( strIdDiggSubmit );
1099 
1100         if ( nIdDiggSubmit == -1 )
1101         {
1102             return getHomeUrl( request );
1103         }
1104 
1105         DiggSubmit diggSubmit = _diggSubmitService.findByPrimaryKey( nIdDiggSubmit, false, getPlugin(  ) );
1106 
1107         if ( ( diggSubmit == null ) ||
1108                 !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + diggSubmit.getDigg(  ).getIdDigg(  ),
1109                     DigglikeResourceIdService.PERMISSION_MANAGE_DIGG_SUBMIT, getUser(  ) ) )
1110         {
1111             return getJspManageDigg( request );
1112         }
1113 
1114         strMessage = MESSAGE_CONFIRM_REMOVE_DIGG_SUBMIT;
1115 
1116         UrlItem url = new UrlItem( JSP_DO_REMOVE_DIGG_SUBMIT );
1117 
1118         if ( strComment != null )
1119         {
1120             url.addParameter( strComment, strComment );
1121         }
1122 
1123         url.addParameter( PARAMETER_ID_DIGG_SUBMIT, nIdDiggSubmit );
1124 
1125         return AdminMessageService.getMessageUrl( request, strMessage, url.getUrl(  ), AdminMessage.TYPE_CONFIRMATION );
1126     }
1127 
1128     /**
1129      * Perform the digg submit supression
1130      *
1131      * @param request
1132      *            The HTTP request
1133      * @return The URL to go after performing the action
1134      */
1135     public String doRemoveDiggSubmit( HttpServletRequest request )
1136     {
1137         String strIdDiggSubmit = request.getParameter( PARAMETER_ID_DIGG_SUBMIT );
1138         String strComment = request.getParameter( PARAMETER_COMMENT );
1139         Plugin plugin = getPlugin(  );
1140         int nIdDiggSubmit = DiggUtils.getIntegerParameter( strIdDiggSubmit );
1141 
1142         if ( nIdDiggSubmit == -1 )
1143         {
1144             return getHomeUrl( request );
1145         }
1146 
1147         DiggSubmit diggSubmit = _diggSubmitService.findByPrimaryKey( nIdDiggSubmit, false, getPlugin(  ) );
1148 
1149         if ( ( diggSubmit == null ) ||
1150                 !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + diggSubmit.getDigg(  ).getIdDigg(  ),
1151                     DigglikeResourceIdService.PERMISSION_MANAGE_DIGG_SUBMIT, getUser(  ) ) )
1152         {
1153             return getJspManageDigg( request );
1154         }
1155 
1156         String strUrlBack;
1157 
1158         if ( strComment != null )
1159         {
1160             // on r�cup�re l'url digg submit suivant
1161             strUrlBack = doFindNextDiggSubmit( request );
1162         }
1163         else
1164         {
1165             strUrlBack = getJspManageDiggSubmit( request );
1166         }
1167 
1168         _diggSubmitService.remove( nIdDiggSubmit, plugin );
1169 
1170         return strUrlBack;
1171     }
1172 
1173     /**
1174      * Perform the digg submit change state
1175      *
1176      * @param request
1177      *            The HTTP request
1178      * @return The URL to go after performing the action
1179      */
1180     public String doChangeDiggSubmitState( HttpServletRequest request )
1181     {
1182         String strIdDiggSubmit = request.getParameter( PARAMETER_ID_DIGG_SUBMIT );
1183         String strStateNumber = request.getParameter( PARAMETER_STATE_NUMBER );
1184         String strComment = request.getParameter( PARAMETER_COMMENT );
1185 
1186         Plugin plugin = getPlugin(  );
1187         int nIdDiggSubmit = DiggUtils.getIntegerParameter( strIdDiggSubmit );
1188         int nStateNumber = DiggUtils.getIntegerParameter( strStateNumber );
1189 
1190         DiggSubmit diggSubmit = _diggSubmitService.findByPrimaryKey( nIdDiggSubmit, false, plugin );
1191         DiggSubmitState diggSubmitState = DiggSubmitStateHome.findByNumero( nStateNumber, plugin );
1192 
1193         if ( ( diggSubmit == null ) || ( diggSubmitState == null ) ||
1194                 !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + diggSubmit.getDigg(  ).getIdDigg(  ),
1195                     DigglikeResourceIdService.PERMISSION_MANAGE_DIGG_SUBMIT, getUser(  ) ) )
1196         {
1197             return getJspManageDigg( request );
1198         }
1199 
1200         diggSubmit.setDiggSubmitState( diggSubmitState );
1201         _diggSubmitService.update( diggSubmit, plugin );
1202 
1203         if ( strComment != null )
1204         {
1205             return getJspManageCommentSubmit( request );
1206         }
1207 
1208         return getJspManageDiggSubmit( request );
1209     }
1210 
1211     /**
1212      * Gets the confirmation page of delete directory record
1213      * @param request The HTTP request
1214      * @throws AccessDeniedException the {@link AccessDeniedException}
1215      * @return the confirmation page of delete directory record
1216      */
1217     public String getConfirmMassChangeDiggSubmitCategory( HttpServletRequest request )
1218         throws AccessDeniedException
1219     {
1220         // fill the selected records
1221         String[] selectedDiggSubmit = request.getParameterValues( PARAMETER_SELECTED_DIGG_SUBMIT );
1222         int nIdDiggSubmit;
1223         String strIdCategory = request.getParameter( PARAMETER_ID_CATEGORY );
1224         int nIdCategory = DiggUtils.getIntegerParameter( strIdCategory );
1225         UrlItem url = new UrlItem( JSP_DO_CHANGE_DIGG_SUBMIT_CATEGORY );
1226         url.addParameter( PARAMETER_ID_CATEGORY, nIdCategory );
1227 
1228         //test All ressource selected before update
1229         for ( String strIdDiggSubmit : selectedDiggSubmit )
1230         {
1231             if ( StringUtils.isNotBlank( strIdDiggSubmit ) && StringUtils.isNumeric( strIdDiggSubmit ) )
1232             {
1233                 nIdDiggSubmit = DiggUtils.getIntegerParameter( strIdDiggSubmit );
1234 
1235                 DiggSubmit diggSubmit = DiggSubmitService.getService(  )
1236                                                          .findByPrimaryKey( nIdDiggSubmit, false, getPlugin(  ) );
1237 
1238                 if ( ( diggSubmit == null ) ||
1239                         !RBACService.isAuthorized( Digg.RESOURCE_TYPE,
1240                             DiggUtils.EMPTY_STRING + diggSubmit.getDigg(  ).getIdDigg(  ),
1241                             DigglikeResourceIdService.PERMISSION_MANAGE_DIGG_SUBMIT, getUser(  ) ) )
1242                 {
1243                     throw new AccessDeniedException(  );
1244                 }
1245 
1246                 url.addParameter( PARAMETER_SELECTED_DIGG_SUBMIT, nIdDiggSubmit );
1247             }
1248         }
1249 
1250         if ( nIdCategory != DiggUtils.CONSTANT_ID_NULL )
1251         {
1252             Category category = CategoryHome.findByPrimaryKey( nIdCategory, getPlugin(  ) );
1253             Object[] args = { ( ( category == null ) || ( category.getTitle(  ) == null ) ) ? "" : category.getTitle(  ) };
1254 
1255             return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_CHANGE_DIGG_SUBMIT_CATEGORY, args,
1256                 url.getUrl(  ), AdminMessage.TYPE_CONFIRMATION );
1257         }
1258 
1259         return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_DIGG_SUBMIT_CATEGORY, url.getUrl(  ),
1260             AdminMessage.TYPE_CONFIRMATION );
1261     }
1262 
1263     /**
1264      * Perform the digg submit change state
1265      *
1266      * @param request
1267      *            The HTTP request
1268      * @return The URL to go after performing the action
1269      * @throws AccessDeniedException If the user is not authorized to acces this
1270      *             feature
1271      */
1272     public String doMassChangeDiggSubmitCategory( HttpServletRequest request )
1273         throws AccessDeniedException
1274     {
1275         // fill the selected records
1276         String[] selectedDiggSubmit = request.getParameterValues( PARAMETER_SELECTED_DIGG_SUBMIT );
1277         int nIdDiggSubmit;
1278         String strIdCategory = request.getParameter( PARAMETER_ID_CATEGORY );
1279         int nIdCategory = DiggUtils.getIntegerParameter( strIdCategory );
1280         Category categorySelected = null;
1281 
1282         //test All ressource selected before update
1283         for ( String strIdDiggSubmit : selectedDiggSubmit )
1284         {
1285             if ( StringUtils.isNotBlank( strIdDiggSubmit ) && StringUtils.isNumeric( strIdDiggSubmit ) )
1286             {
1287                 nIdDiggSubmit = DiggUtils.getIntegerParameter( strIdDiggSubmit );
1288 
1289                 DiggSubmit diggSubmit = DiggSubmitService.getService(  )
1290                                                          .findByPrimaryKey( nIdDiggSubmit, false, getPlugin(  ) );
1291 
1292                 if ( ( diggSubmit == null ) ||
1293                         !RBACService.isAuthorized( Digg.RESOURCE_TYPE,
1294                             DiggUtils.EMPTY_STRING + diggSubmit.getDigg(  ).getIdDigg(  ),
1295                             DigglikeResourceIdService.PERMISSION_MANAGE_DIGG_SUBMIT, getUser(  ) ) )
1296                 {
1297                     throw new AccessDeniedException(  );
1298                 }
1299             }
1300         }
1301 
1302         if ( nIdCategory != DiggUtils.CONSTANT_ID_NULL )
1303         {
1304             categorySelected = CategoryHome.findByPrimaryKey( nIdCategory, getPlugin(  ) );
1305         }
1306 
1307         //update all digg submit selected
1308         for ( String strIdDiggSubmittoUpdate : selectedDiggSubmit )
1309         {
1310             if ( StringUtils.isNotBlank( strIdDiggSubmittoUpdate ) && StringUtils.isNumeric( strIdDiggSubmittoUpdate ) )
1311             {
1312                 nIdDiggSubmit = DiggUtils.getIntegerParameter( strIdDiggSubmittoUpdate );
1313 
1314                 DiggSubmit diggSubmit = DiggSubmitService.getService(  )
1315                                                          .findByPrimaryKey( nIdDiggSubmit, false, getPlugin(  ) );
1316                 diggSubmit.setCategory( categorySelected );
1317                 DiggSubmitService.getService(  ).update( diggSubmit, getPlugin(  ) );
1318             }
1319         }
1320 
1321         return getJspManageDiggSubmit( request );
1322     }
1323 
1324     /**
1325      * Perform the digg submit change state
1326      *
1327      * @param request
1328      *            The HTTP request
1329      * @return The URL to go after performing the action
1330      */
1331     public String doChangeDiggSubmitCategory( HttpServletRequest request )
1332     {
1333         String strIdDiggSubmit = request.getParameter( PARAMETER_ID_DIGG_SUBMIT );
1334         String strIdCategory = request.getParameter( PARAMETER_ID_CATEGORY );
1335         String strComment = request.getParameter( PARAMETER_COMMENT );
1336 
1337         Plugin plugin = getPlugin(  );
1338         int nIdDiggSubmit = DiggUtils.getIntegerParameter( strIdDiggSubmit );
1339         int nIdCategory = DiggUtils.getIntegerParameter( strIdCategory );
1340 
1341         DiggSubmit diggSubmit = _diggSubmitService.findByPrimaryKey( nIdDiggSubmit, false, plugin );
1342         Category category = CategoryHome.findByPrimaryKey( nIdCategory, plugin );
1343 
1344         if ( ( diggSubmit == null ) ||
1345                 !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + diggSubmit.getDigg(  ).getIdDigg(  ),
1346                     DigglikeResourceIdService.PERMISSION_MANAGE_DIGG_SUBMIT, getUser(  ) ) )
1347         {
1348             return getJspManageDigg( request );
1349         }
1350 
1351         diggSubmit.setCategory( category );
1352 
1353         _diggSubmitService.update( diggSubmit, plugin );
1354 
1355         if ( strComment != null )
1356         {
1357             return getJspManageCommentSubmit( request );
1358         }
1359 
1360         return getJspManageDiggSubmit( request );
1361     }
1362 
1363     /**
1364      * Perform the comment submit change
1365      *
1366      * @param request
1367      *            The HTTP request
1368      * @return The URL to go after performing the action
1369      */
1370     public String doChangeCommentSubmit( HttpServletRequest request )
1371     {
1372         String strIdParentCommentSubmit = request.getParameter( PARAMETER_ID_PARENT );
1373 
1374         if ( request.getParameter( PARAMETER_DELETE ) != null )
1375         {
1376             String strIdCommentSubmit = request.getParameter( PARAMETER_ID_COMMENT_SUBMIT );
1377 
1378             String strMessage;
1379             int nIdCommentSubmit = DiggUtils.getIntegerParameter( strIdCommentSubmit );
1380 
1381             if ( nIdCommentSubmit == -1 )
1382             {
1383                 return getHomeUrl( request );
1384             }
1385 
1386             strMessage = MESSAGE_CONFIRM_REMOVE_COMMENT_SUBMIT;
1387 
1388             UrlItem url = new UrlItem( JSP_DO_REMOVE_COMMENT_SUBMIT );
1389             url.addParameter( PARAMETER_ID_COMMENT_SUBMIT, nIdCommentSubmit );
1390             url.addParameter( PARAMETER_ID_PARENT, strIdParentCommentSubmit );
1391 
1392             return AdminMessageService.getMessageUrl( request, strMessage, url.getUrl(  ),
1393                 AdminMessage.TYPE_CONFIRMATION );
1394         }
1395         else if ( request.getParameter( PARAMETER_ENABLE ) != null )
1396         {
1397             doEnableCommentSubmit( request );
1398         }
1399         else if ( request.getParameter( PARAMETER_DISABLE ) != null )
1400         {
1401             doDisableCommentSubmit( request );
1402         }
1403 
1404         return getJspManageCommentSubmit( request, strIdParentCommentSubmit );
1405     }
1406 
1407     /**
1408      * Submit an official answer to a diggSubmit
1409      *
1410      * @param request
1411      *            The HTTP request
1412      * @return The URL to go after performing the action
1413      */
1414     public String doSubmitOfficialAnswer( HttpServletRequest request )
1415     {
1416         String strCommentValueDigg = request.getParameter( PARAMETER_COMMENT_VALUE );
1417         int nIdSubmitDigg = Integer.valueOf( request.getParameter( PARAMETER_ID_DIGG_SUBMIT ) );
1418         CommentSubmit commentSubmit = new CommentSubmit(  );
1419         Plugin plugin = getPlugin(  );
1420 
1421         DiggSubmit diggSubmit = _diggSubmitService.findByPrimaryKey( nIdSubmitDigg, false, plugin );
1422 
1423         // Check XSS characters
1424         if ( StringUtil.containsXssCharacters( strCommentValueDigg ) )
1425         {
1426             strCommentValueDigg = "";
1427 
1428             return AdminMessageService.getMessageUrl( request, MESSAGE_NEW_COMMENT_SUBMIT_INVALID, SiteMessage.TYPE_STOP );
1429         }
1430 
1431         commentSubmit.setActive( true );
1432         diggSubmit.setNumberCommentEnable( diggSubmit.getNumberCommentEnable(  ) + 1 );
1433         diggSubmit.setNumberComment( diggSubmit.getNumberComment(  ) + 1 );
1434         _diggSubmitService.update( diggSubmit, plugin );
1435 
1436         commentSubmit.setDateComment( DiggUtils.getCurrentDate(  ) );
1437         commentSubmit.setDiggSubmit( diggSubmit );
1438         commentSubmit.setValue( strCommentValueDigg );
1439         commentSubmit.setOfficialAnswer( true );
1440 
1441         LuteceUser user = null;
1442 
1443         try
1444         {
1445             user = SecurityService.getInstance(  ).getRemoteUser( request );
1446         }
1447         catch ( Exception e )
1448         {
1449             AppLogService.error( "User not identified" );
1450         }
1451 
1452         if ( user != null )
1453         {
1454             commentSubmit.setLuteceUserKey( user.getName(  ) );
1455         }
1456 
1457         _commentSubmitService.create( commentSubmit, plugin );
1458 
1459         return getJspManageCommentSubmit( request );
1460     }
1461 
1462     /**
1463      * Perform the comment submit supression
1464      *
1465      * @param request
1466      *            The HTTP request
1467      * @return The URL to go after performing the action
1468      */
1469     public String doRemoveCommentSubmit( HttpServletRequest request )
1470     {
1471         String strIdCommentSubmit = request.getParameter( PARAMETER_ID_COMMENT_SUBMIT );
1472         Plugin plugin = getPlugin(  );
1473         int nIdCommentSubmit = DiggUtils.getIntegerParameter( strIdCommentSubmit );
1474         CommentSubmit commentSubmit = _commentSubmitService.findByPrimaryKey( nIdCommentSubmit, plugin );
1475 
1476         if ( commentSubmit == null )
1477         {
1478             return getJspManageDigg( request );
1479         }
1480 
1481         DiggSubmit diggSubmit = _diggSubmitService.findByPrimaryKey( commentSubmit.getDiggSubmit(  ).getIdDiggSubmit(  ),
1482                 false, plugin );
1483 
1484         if ( !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + diggSubmit.getDigg(  ).getIdDigg(  ),
1485                     DigglikeResourceIdService.PERMISSION_MANAGE_DIGG_SUBMIT, getUser(  ) ) )
1486         {
1487             return getJspManageDigg( request );
1488         }
1489 
1490         _commentSubmitService.remove( nIdCommentSubmit, plugin );
1491 
1492         if ( commentSubmit.isActive(  ) )
1493         {
1494             diggSubmit.setNumberCommentEnable( diggSubmit.getNumberCommentEnable(  ) - 1 );
1495         }
1496 
1497         diggSubmit.setNumberComment( diggSubmit.getNumberComment(  ) - 1 );
1498         _diggSubmitService.update( diggSubmit, plugin );
1499 
1500         return getJspManageCommentSubmit( request );
1501     }
1502 
1503     /**
1504      * disable the comment submit
1505      *
1506      * @param request
1507      *            The HTTP request
1508      * @return The URL to go after performing the action
1509      */
1510     public String doDisableCommentSubmit( HttpServletRequest request )
1511     {
1512         String strIdCommentSubmit = request.getParameter( PARAMETER_ID_COMMENT_SUBMIT );
1513         Plugin plugin = getPlugin(  );
1514         int nIdCommentSubmit = DiggUtils.getIntegerParameter( strIdCommentSubmit );
1515         CommentSubmit commentSubmit = _commentSubmitService.findByPrimaryKey( nIdCommentSubmit, plugin );
1516 
1517         if ( commentSubmit != null )
1518         {
1519             DiggSubmit diggSubmit = _diggSubmitService.findByPrimaryKey( commentSubmit.getDiggSubmit(  )
1520                                                                                       .getIdDiggSubmit(  ), false,
1521                     plugin );
1522 
1523             if ( !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + diggSubmit.getDigg(  ).getIdDigg(  ),
1524                         DigglikeResourceIdService.PERMISSION_MANAGE_DIGG_SUBMIT, getUser(  ) ) )
1525             {
1526                 return getJspManageDigg( request );
1527             }
1528 
1529             commentSubmit.setActive( false );
1530             _commentSubmitService.update( commentSubmit, plugin );
1531             diggSubmit.setNumberCommentEnable( diggSubmit.getNumberCommentEnable(  ) - 1 );
1532             _diggSubmitService.update( diggSubmit, plugin );
1533         }
1534 
1535         return null;
1536     }
1537 
1538     /**
1539      * enable the comment submit
1540      *
1541      * @param request
1542      *            The HTTP request
1543      * @return The URL to go after performing the action
1544      */
1545     public String doEnableCommentSubmit( HttpServletRequest request )
1546     {
1547         String strIdCommentSubmit = request.getParameter( PARAMETER_ID_COMMENT_SUBMIT );
1548         Plugin plugin = getPlugin(  );
1549         int nIdCommentSubmit = DiggUtils.getIntegerParameter( strIdCommentSubmit );
1550         CommentSubmit commentSubmit = _commentSubmitService.findByPrimaryKey( nIdCommentSubmit, plugin );
1551 
1552         if ( commentSubmit != null )
1553         {
1554             DiggSubmit diggSubmit = _diggSubmitService.findByPrimaryKey( commentSubmit.getDiggSubmit(  )
1555                                                                                       .getIdDiggSubmit(  ), false,
1556                     plugin );
1557 
1558             if ( !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + diggSubmit.getDigg(  ).getIdDigg(  ),
1559                         DigglikeResourceIdService.PERMISSION_MANAGE_DIGG_SUBMIT, getUser(  ) ) )
1560             {
1561                 return getJspManageDigg( request );
1562             }
1563 
1564             commentSubmit.setActive( true );
1565             _commentSubmitService.update( commentSubmit, plugin );
1566             diggSubmit.setNumberCommentEnable( diggSubmit.getNumberCommentEnable(  ) + 1 );
1567             _diggSubmitService.update( diggSubmit, plugin );
1568         }
1569 
1570         return null;
1571     }
1572 
1573     /**
1574      * return the url of the next digg submit
1575      *
1576      * @param request
1577      *            The HTTP request
1578      * @return return the url of the next digg submit
1579      */
1580     public String doFindNextDiggSubmit( HttpServletRequest request )
1581     {
1582         Plugin plugin = getPlugin(  );
1583         SubmitFilter filter = DiggUtils.getDiggSubmitFilter( getSearchFields(  ) );
1584         _nIdDiggSubmit = _diggSubmitService.findNextIdDiggSubmitInTheList( _nIdDiggSubmit, filter, plugin );
1585 
1586         return getJspManageCommentSubmit( request );
1587     }
1588 
1589     /**
1590      * return the url of the prev digg submit
1591      *
1592      * @param request
1593      *            The HTTP request
1594      * @return return the url of the next digg submit
1595      */
1596     public String doFindPrevDiggSubmit( HttpServletRequest request )
1597     {
1598         Plugin plugin = getPlugin(  );
1599         SubmitFilter filter = DiggUtils.getDiggSubmitFilter( getSearchFields(  ) );
1600         _nIdDiggSubmit = _diggSubmitService.findPrevIdDiggSubmitInTheList( _nIdDiggSubmit, filter, plugin );
1601 
1602         return getJspManageCommentSubmit( request );
1603     }
1604 
1605     /**
1606      * Get the request data and if there is no error insert the data in the digg
1607      * specified in parameter. return null if there is no error or else return
1608      * the error page url
1609      *
1610      * @param request
1611      *            the request
1612      * @param digg
1613      *            digg
1614      *
1615      * @return null if there is no error or else return the error page url
1616      */
1617     private String getDiggData( MultipartHttpServletRequest request, Digg digg )
1618     {
1619        
1620     	String strDefaultRole=AppPropertiesService.getProperty( PROPERTY_DEFAULT_ROLE_CODE );
1621     	String strUpdateFile = request.getParameter( PARAMETER_UPDATE_FILE );
1622         String strTitle = request.getParameter( PARAMETER_TITLE );
1623         String strLibelleContribution = request.getParameter( PARAMETER_LIBELLE_CONTRIBUTION );
1624         String strUnavailabilityMessage = request.getParameter( PARAMETER_UNAVAILABILITY_MESSAGE );
1625         String strWorkgroup = request.getParameter( PARAMETER_WORKGROUP );
1626         String strIdVoteType = request.getParameter( PARAMETER_ID_VOTE_TYPE );
1627         String strActivePropositionState = request.getParameter( PARAMETER_ACTIVE_PROPOSITION_STATE );
1628         String strNumberVoteRequired = request.getParameter( PARAMETER_NUMBER_VOTE_REQUIRED );
1629         String strNumberDayRequired = request.getParameter( PARAMETER_NUMBER_DAY_REQUIRED );
1630         String strNumberDiggSubmitInTopScore = request.getParameter( PARAMETER_NUMBER_DIGG_SUBMIT_IN_TOP_SCORE );
1631         String strNumberDiggSubmitCaractersShown = request.getParameter( PARAMETER_NUMBER_DIGG_SUBMIT_CARACTERS_SHOWN );
1632         String strNumberDiggSubmitInTopComment = request.getParameter( PARAMETER_NUMBER_DIGG_SUBMIT_IN_TOP_COMMENT );
1633         String strThemeXpage = request.getParameter( PARAMETER_THEME_XPAGE );
1634 
1635         String strActiveDiggSubmitAuthentification = request.getParameter( PARAMETER_ACTIVE_DIGG_SUBMIT_AUTHENTIFICATION );
1636         String strActiveVoteAuthentification = request.getParameter( PARAMETER_ACTIVE_VOTE_AUTHENTIFICATION );
1637         String strActiveCommentAuthentification = request.getParameter( PARAMETER_ACTIVE_COMMENT_AUTHENTIFICATION );
1638 
1639         String strDisableNewDiggSubmit = request.getParameter( PARAMETER_DISABLE_NEW_DIGG_SUBMIT );
1640         String strEnableMailNewDiggSubmit = request.getParameter( PARAMETER_ENABLE_MAIL_NEW_DIGG_SUBMIT );
1641         String strIdMailingListDiggSubmit = request.getParameter( PARAMETER_ID_MAILING_LIST_DIGG_SUBMIT );
1642 
1643         String strAuthorizedComment = request.getParameter( PARAMETER_AUTHORIZED_COMMENT );
1644         String strActiveEditorBbcode = request.getParameter( PARAMETER_ACTIVE_EDITOR_BBCODE_ON_COMMENT );
1645         String strDisableNewComment = request.getParameter( PARAMETER_DISABLE_NEW_COMMENT );
1646         String strLimitNumberVote = request.getParameter( PARAMETER_LIMIT_NUMBER_VOTE );
1647         String strActiveCaptcha = request.getParameter( PARAMETER_ACTIVE_CAPTCHA );
1648         String strLibelleValidateButton = request.getParameter( PARAMETER_LIBELLE_VALIDATE_BUTTON );
1649         String strShowCategoryBlock = request.getParameter( PARAMETER_SHOW_CATEGORY_BLOCK );
1650         String strShowTopScoreBlock = request.getParameter( PARAMETER_SHOW_TOP_SCORE_BLOCK );
1651         String strShowTopCommentBlock = request.getParameter( PARAMETER_SHOW_TOP_COMMENT_BLOCK );
1652         String strActiveDiggSubmitPaginator = request.getParameter( PARAMETER_ACTIVE_DIGG_SUBMIT_PAGINATOR );
1653         String strNumberDiggSubmitPerPage = request.getParameter( PARAMETER_NUMBER_DIGG_SUBMIT_PER_PAGE );
1654         String strRole = request.getParameter( PARAMETER_ROLE );
1655         String strHeader = request.getParameter( PARAMETER_HEADER );
1656         String strConfirmationMessage = request.getParameter( PARAMETER_CONFIRMATION_MESSAGE );
1657         String strIdDefaultSort = request.getParameter( PARAMETER_ID_DEFAULT_SORT );
1658         String strDisableVote = request.getParameter( PARAMETER_DISABLE_VOTE );
1659         String strDisplayCommentInDiggSubmitList = request.getParameter( PARAMETER_DISPLAY_COMMENT_IN_DIGG_SUBMIT_LIST );
1660         String strNumberCommentDisplayInDiggSubmitList = request.getParameter( PARAMETER_NUMBER_COMMENT_DISPLAY_IN_DIGG_SUBMIT_LIST );
1661         String strNumberCharCommentDisplayInDiggSubmitList = request.getParameter( PARAMETER_NUMBER_CHAR_COMMENT_DISPLAY_IN_DIGG_SUBMIT_LIST );
1662         String strEnableMailNewCommentSubmit = request.getParameter( PARAMETER_ENABLE_MAIL_NEW_COMMENT_SUBMIT );
1663         String strEnableMailNewReportedSubmit = request.getParameter( PARAMETER_ENABLE_MAIL_NEW_REPORTED_SUBMIT );
1664         String strEnableTermsOfUse = request.getParameter( PARAMETER_ENABLE_TERMS_OF_USE );
1665         String strTermsOfUse = request.getParameter( PARAMETER_TERMS_OF_USE );
1666         String strEnableReports = request.getParameter( PARAMETER_ENABLE_REPORTS );
1667         String strDescription = request.getParameter( PARAMETER_DESCRIPTION );
1668         String strNotificationNewCommentSenderName=request.getParameter(PARAMETER_NOTIFICATION_NEW_COMMENT_SENDER_NAME);
1669         String strNotificationNewCommentTitle=request.getParameter(PARAMETER_NOTIFICATION_NEW_COMMENT_TITLE);
1670         String strNotificationNewCommentBody=request.getParameter(PARAMETER_NOTIFICATION_NEW_COMMENT_BODY);
1671         String strNotificationNewDiggSubmitSenderName=request.getParameter(PARAMETER_NOTIFICATION_NEW_DIGG_SUBMIT_SENDER_NAME);
1672         String strNotificationNewDiggSubmitTitle=request.getParameter(PARAMETER_NOTIFICATION_NEW_DIGG_SUBMIT_TITLE);
1673         String strNotificationNewDiggSubmitBody=request.getParameter(PARAMETER_NOTIFICATION_NEW_DIGG_SUBMIT_BODY);
1674         
1675 
1676         int nIdVoteType = DiggUtils.getIntegerParameter( strIdVoteType );
1677         int nIdMailingListDiggSubmit = DiggUtils.getIntegerParameter( strIdMailingListDiggSubmit );
1678         int nNumberDayRequired = DiggUtils.getIntegerParameter( strNumberDayRequired );
1679         int nNumberVoteRequired = DiggUtils.getIntegerParameter( strNumberVoteRequired );
1680         int nNumberDiggSubmitInTopScore = DiggUtils.getIntegerParameter( strNumberDiggSubmitInTopScore );
1681         int nNumberDiggSubmitCaractersShown = DiggUtils.getIntegerParameter( strNumberDiggSubmitCaractersShown );
1682         int nNumberDiggSubmitInTopComment = DiggUtils.getIntegerParameter( strNumberDiggSubmitInTopComment );
1683         int nNumberDiggSubmitPerPage = DiggUtils.getIntegerParameter( strNumberDiggSubmitPerPage );
1684         int nIdDefaultSort = DiggUtils.getIntegerParameter( strIdDefaultSort );
1685         int nNumberCommentDisplayInDiggSubmitList = DiggUtils.getIntegerParameter( strNumberCommentDisplayInDiggSubmitList );
1686         int nNumberCharCommentDisplayInDiggSubmitList = DiggUtils.getIntegerParameter( strNumberCharCommentDisplayInDiggSubmitList );
1687 
1688         String strFieldError = EMPTY_STRING;
1689 
1690         if (  StringUtils.isEmpty(strTitle))
1691         {
1692             strFieldError = FIELD_TITLE;
1693         }
1694 
1695         else if ( StringUtils.isEmpty(strLibelleContribution ) )
1696         {
1697             strFieldError = FIELD_LIBELLE_CONTRIBUTION;
1698         }
1699 
1700         else if ( StringUtils.isEmpty( strUnavailabilityMessage))
1701         {
1702             strFieldError = FIELD_UNAVAILABILITY_MESSAGE;
1703         }
1704         else if ( nIdVoteType == -1 )
1705         {
1706             strFieldError = FIELD_VOTE_TYPE;
1707         }
1708         else if ( StringUtils.isEmpty( strNumberDiggSubmitCaractersShown) )
1709         {
1710             strFieldError = FIELD_NUMBER_DIGG_SUBMIT_CARACTERS_SHOWN;
1711         }
1712         else if ( ( ( ( strShowTopScoreBlock != null ) && strShowTopScoreBlock.trim(  ).equals( CONSTANTE_YES_VALUE ) ) &&
1713                 ( strNumberDiggSubmitInTopScore == null ) ) ||
1714                 strNumberDiggSubmitInTopScore.trim(  ).equals( EMPTY_STRING ) )
1715         {
1716             strFieldError = FIELD_NUMBER_DIGG_SUBMIT_IN_TOP_SCORE;
1717         }
1718 
1719         else if ( ( ( strAuthorizedComment != null ) && strAuthorizedComment.trim(  ).equals( CONSTANTE_YES_VALUE ) ) &&
1720                 ( ( strNumberDiggSubmitInTopComment == null ) ||
1721                 strNumberDiggSubmitInTopComment.trim(  ).equals( EMPTY_STRING ) ) )
1722         {
1723             strFieldError = FIELD_NUMBER_DIGG_SUBMIT_IN_TOP_COMMENT;
1724         }
1725 
1726         else if ( ( ( strActiveDiggSubmitPaginator != null ) &&
1727                 strActiveDiggSubmitPaginator.trim(  ).equals( CONSTANTE_YES_VALUE ) ) &&
1728                 ( ( strNumberDiggSubmitPerPage == null ) || strNumberDiggSubmitPerPage.trim(  ).equals( EMPTY_STRING ) ) )
1729         {
1730             strFieldError = FIELD_NUMBER_DIGG_SUBMIT_PER_PAGE;
1731         }
1732 
1733         else if ( ( strLibelleValidateButton == null ) || strLibelleValidateButton.trim(  ).equals( EMPTY_STRING ) )
1734         {
1735             strFieldError = FIELD_LIBELE_VALIDATE_BUTTON;
1736         }
1737         else if ( ( ( strDisplayCommentInDiggSubmitList != null ) &&
1738                 ( ( strNumberCommentDisplayInDiggSubmitList == null ) ||
1739                 strNumberCommentDisplayInDiggSubmitList.trim(  ).equals( EMPTY_STRING ) ) ) )
1740         {
1741             strFieldError = FIELD_NUMBER_COMMENT_DISPLAY_IN_DIGG_SUBMIT_LIST;
1742         }
1743         else if ( ( ( strDisplayCommentInDiggSubmitList != null ) &&
1744                 ( ( strNumberCharCommentDisplayInDiggSubmitList == null ) ||
1745                 strNumberCharCommentDisplayInDiggSubmitList.trim(  ).equals( EMPTY_STRING ) ) ) )
1746         {
1747             strFieldError = FIELD_NUMBER_CHAR_COMMENT_DISPLAY_IN_DIGG_SUBMIT_LIST;
1748         }
1749        
1750         else if(StringUtils.isEmpty(strNotificationNewCommentTitle))
1751         {
1752         	strFieldError = FIELD_NOTIFICATION_NEW_COMMENT_TITLE;
1753         	
1754         }
1755         else if(StringUtils.isEmpty(strNotificationNewCommentBody))
1756         {
1757         	strFieldError = FIELD_NOTIFICATION_NEW_COMMENT_BODY;
1758         	
1759         }
1760         
1761         else if(StringUtils.isEmpty(strNotificationNewDiggSubmitTitle))
1762         {
1763         	
1764         	strFieldError = FIELD_NOTIFICATION_NEW_DIGG_DUBMIT_TITLE;
1765         }
1766         else if(StringUtils.isEmpty(strNotificationNewDiggSubmitBody))
1767         {
1768         	
1769         	strFieldError = FIELD_NOTIFICATION_NEW_DIGG_DUBMIT_BODY;
1770         }
1771 
1772         if ( !strFieldError.equals( EMPTY_STRING ) )
1773         {
1774             Object[] tabRequiredFields = { I18nService.getLocalizedString( strFieldError, getLocale(  ) ) };
1775 
1776             return AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_FIELD, tabRequiredFields,
1777                 AdminMessage.TYPE_STOP );
1778         }
1779 
1780         if ( nNumberDiggSubmitCaractersShown < 0 )
1781         {
1782             return AdminMessageService.getMessageUrl( request, MESSAGE_ILLOGICAL_NUMBER_DIGG_SUBMIT_CARACTERS_SHOWN,
1783                 AdminMessage.TYPE_STOP );
1784         }
1785 
1786         if ( ( strNumberDiggSubmitInTopScore != null ) &&
1787                 !strNumberDiggSubmitInTopScore.trim(  ).equals( EMPTY_STRING ) && ( nNumberDiggSubmitInTopScore < 0 ) )
1788         {
1789             return AdminMessageService.getMessageUrl( request, MESSAGE_ILLOGICAL_NUMBER_DIGG_SUBMIT_IN_TOP_SCORE,
1790                 AdminMessage.TYPE_STOP );
1791         }
1792 
1793         if ( ( strActivePropositionState != null ) && strActivePropositionState.trim(  ).equals( CONSTANTE_YES_VALUE ) &&
1794                 ( strNumberVoteRequired != null ) && !strNumberVoteRequired.trim(  ).equals( EMPTY_STRING ) &&
1795                 ( nNumberVoteRequired < 0 ) )
1796         {
1797             return AdminMessageService.getMessageUrl( request, MESSAGE_ILLOGICAL_NUMBER_VOTE_REQUIRED,
1798                 AdminMessage.TYPE_STOP );
1799         }
1800 
1801         if ( ( strNumberDayRequired != null ) && !strNumberDayRequired.trim(  ).equals( EMPTY_STRING ) &&
1802                 ( nNumberDayRequired < 0 ) )
1803         {
1804             return AdminMessageService.getMessageUrl( request, MESSAGE_ILLOGICAL_NUMBER_DAY_REQUIRED,
1805                 AdminMessage.TYPE_STOP );
1806         }
1807 
1808         if ( ( strNumberDiggSubmitInTopComment != null ) &&
1809                 !strNumberDiggSubmitInTopComment.trim(  ).equals( EMPTY_STRING ) &&
1810                 ( nNumberDiggSubmitInTopComment < 0 ) )
1811         {
1812             return AdminMessageService.getMessageUrl( request, MESSAGE_ILLOGICAL_NUMBER_DIGG_SUBMIT_IN_TOP_COMMENT,
1813                 AdminMessage.TYPE_STOP );
1814         }
1815 
1816         if ( ( strNumberDiggSubmitPerPage != null ) && !strNumberDiggSubmitPerPage.trim(  ).equals( EMPTY_STRING ) &&
1817                 ( nNumberDiggSubmitPerPage < 0 ) )
1818         {
1819             return AdminMessageService.getMessageUrl( request, MESSAGE_ILLOGICAL_NUMBER_DIGG_SUBMIT_PER_PAGE,
1820                 AdminMessage.TYPE_STOP );
1821         }
1822 
1823         if ( ( strDisplayCommentInDiggSubmitList != null ) && ( strNumberCommentDisplayInDiggSubmitList != null ) &&
1824                 !strNumberCommentDisplayInDiggSubmitList.trim(  ).equals( EMPTY_STRING ) &&
1825                 ( nNumberCommentDisplayInDiggSubmitList < 0 ) )
1826         {
1827             return AdminMessageService.getMessageUrl( request,
1828                 MESSAGE_ILLOGICAL_NUMBER_COMMENT_DISPLAY_IN_DIGG_SUBMIT_LIST, AdminMessage.TYPE_STOP );
1829         }
1830 
1831         if ( ( strDisplayCommentInDiggSubmitList != null ) && ( strNumberCharCommentDisplayInDiggSubmitList != null ) &&
1832                 !strNumberCharCommentDisplayInDiggSubmitList.trim(  ).equals( EMPTY_STRING ) &&
1833                 ( nNumberCommentDisplayInDiggSubmitList < 0 ) )
1834         {
1835             return AdminMessageService.getMessageUrl( request,
1836                 MESSAGE_ILLOGICAL_NUMBER_CHAR_COMMENT_DISPLAY_IN_DIGG_SUBMIT_LIST, AdminMessage.TYPE_STOP );
1837         }
1838 
1839         digg.setTitle( strTitle );
1840         digg.setLibelleContribution( strLibelleContribution );
1841         digg.setUnavailabilityMessage( strUnavailabilityMessage );
1842         digg.setWorkgroup( strWorkgroup );
1843 
1844         if ( digg.getVoteType(  ) == null )
1845         {
1846             digg.setVoteType( new VoteType(  ) );
1847         }
1848 
1849         digg.getVoteType(  ).setIdVoteType( nIdVoteType );
1850 
1851         if ( ( strActivePropositionState != null ) && strActivePropositionState.trim(  ).equals( CONSTANTE_YES_VALUE ) )
1852         {
1853             digg.setActiveDiggPropositionState( true );
1854             digg.setNumberVoteRequired( nNumberVoteRequired );
1855         }
1856         else
1857         {
1858             digg.setActiveDiggPropositionState( false );
1859             digg.setNumberVoteRequired( -1 );
1860         }
1861 
1862         digg.setNumberDayRequired( nNumberDayRequired );
1863         digg.setActiveDiggSubmitAuthentification( strActiveDiggSubmitAuthentification != null );
1864         digg.setActiveVoteAuthentification( strActiveVoteAuthentification != null );
1865         digg.setActiveCommentAuthentification( strActiveCommentAuthentification != null );
1866         digg.setActiveCaptcha( strActiveCaptcha != null );
1867         digg.setDisableNewDiggSubmit( strDisableNewDiggSubmit != null );
1868         digg.setEnableMailNewDiggSubmit( strEnableMailNewDiggSubmit != null );
1869         digg.setEnableMailNewCommentSubmit( strEnableMailNewCommentSubmit != null );
1870         digg.setEnableMailNewReportedSubmit( strEnableMailNewReportedSubmit != null );
1871         digg.setIdMailingListDiggSubmit( nIdMailingListDiggSubmit );
1872         digg.setAuthorizedComment( strAuthorizedComment != null );
1873         digg.setDisableNewComment( strDisableNewComment != null );
1874         digg.setActiveEditorBbcode( strActiveEditorBbcode != null );
1875         digg.setLimitNumberVote( strLimitNumberVote != null );
1876         digg.setShowCategoryBlock( strShowCategoryBlock != null );
1877         digg.setShowTopScoreBlock( strShowTopScoreBlock != null );
1878         digg.setShowTopCommentBlock( strShowTopCommentBlock != null );
1879         digg.setActiveDiggSubmitPaginator( strActiveDiggSubmitPaginator != null );
1880 
1881         if ( strThemeXpage != null )
1882         {
1883             digg.setCodeTheme( strThemeXpage );
1884         }
1885 
1886         digg.setLibelleValidateButton( strLibelleValidateButton );
1887         digg.setNumberDiggSubmitInTopScore( nNumberDiggSubmitInTopScore );
1888         digg.setNumberDiggSubmitInTopComment( nNumberDiggSubmitInTopComment );
1889         digg.setNumberDiggSubmitCaractersShown( nNumberDiggSubmitCaractersShown );
1890         digg.setNumberDiggSubmitPerPage( nNumberDiggSubmitPerPage );
1891         if(strDefaultRole != null && !strRole.equals(strDefaultRole) )
1892         {
1893         	digg.setRole( strRole );
1894         }
1895         else
1896         {
1897         	digg.setRole( null);
1898          }
1899         digg.setHeader( strHeader );
1900         digg.setConfirmationMessage( strConfirmationMessage );
1901         digg.setIdDefaultSort( nIdDefaultSort );
1902         digg.setDisableVote( strDisableVote != null );
1903         digg.setDisplayCommentInDiggSubmitList( strDisplayCommentInDiggSubmitList != null );
1904         digg.setNumberCommentDisplayInDiggSubmitList( nNumberCommentDisplayInDiggSubmitList );
1905         digg.setNumberCharCommentDisplayInDiggSubmitList( nNumberCharCommentDisplayInDiggSubmitList );
1906         digg.setEnableReports( strEnableReports != null );
1907         digg.setEnableTermsOfUse( strEnableTermsOfUse != null );
1908         digg.setTermsOfUse( strTermsOfUse );
1909         digg.setDescription( strDescription );
1910         digg.setNotificationNewCommentSenderName(strNotificationNewCommentSenderName);
1911         digg.setNotificationNewCommentTitle(strNotificationNewCommentTitle);
1912         digg.setNotificationNewCommentBody(strNotificationNewCommentBody);
1913         digg.setNotificationNewDiggSubmitSenderName(strNotificationNewDiggSubmitSenderName);
1914         digg.setNotificationNewDiggSubmitTitle(strNotificationNewDiggSubmitTitle);
1915         digg.setNotificationNewDiggSubmitBody(strNotificationNewDiggSubmitBody);
1916         
1917         if ( ( digg.getIdDigg(  ) == DiggUtils.CONSTANT_ID_NULL ) || ( strUpdateFile != null ) )
1918         {
1919             FileItem imageSource = request.getFile( PARAMETER_IMAGE_SOURCE );
1920             String strImageName = FileUploadService.getFileNameOnly( imageSource );
1921 
1922             ImageResource image = new ImageResource(  );
1923             byte[] baImageSource = imageSource.get(  );
1924 
1925             if ( ( strImageName != null ) && !strImageName.equals( "" ) )
1926             {
1927                 image.setImage( baImageSource );
1928                 image.setMimeType( imageSource.getContentType(  ) );
1929             }
1930 
1931             digg.setImage( image );
1932         }
1933 
1934         return null; // No error
1935     }
1936 
1937     /**
1938      * Gets the digg creation page
1939      *
1940      * @param request
1941      *            The HTTP request
1942      * @return The digg creation page
1943      */
1944     public String getCreateDigg( HttpServletRequest request )
1945     {
1946         if ( !RBACService.isAuthorized( Digg.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
1947                     DigglikeResourceIdService.PERMISSION_CREATE, getUser(  ) ) )
1948         {
1949             return getManageDigg( request );
1950         }
1951 
1952         Plugin plugin = getPlugin(  );
1953         AdminUser adminUser = getUser(  );
1954         Locale locale = getLocale(  );
1955         ReferenceList refListWorkGroups;
1956         ReferenceList refMailingList;
1957         refListWorkGroups = AdminWorkgroupService.getUserWorkgroups( adminUser, locale );
1958         refMailingList = new ReferenceList(  );
1959 
1960         String strNothing = I18nService.getLocalizedString( PROPERTY_NOTHING, locale );
1961         refMailingList.addItem( -1, strNothing );
1962         refMailingList.addAll( AdminMailingListService.getMailingLists( adminUser ) );
1963 
1964         // Style management
1965         String defaultTheme = ThemesService.getGlobalTheme(  );
1966         Collection<Theme> themes = ThemesService.getThemesList(  );
1967         ReferenceList themesRefList = new ReferenceList(  );
1968 
1969         for ( Theme theme : themes )
1970         {
1971             themesRefList.addItem( theme.getCodeTheme(  ), theme.getThemeDescription(  ) );
1972         }
1973 
1974         ReferenceList refListDiggSort = DiggUtils.getRefListDiggSort( locale );
1975         ReferenceList refVoteTypeList = initRefListVoteType( plugin, locale );
1976         DefaultMessage defaultMessage = DefaultMessageHome.find( plugin );
1977         Map<String, Object> model = new HashMap<String, Object>(  );
1978         model.put( MARK_USER_WORKGROUP_REF_LIST, refListWorkGroups );
1979         model.put( MARK_MAILING_REF_LIST, refMailingList );
1980         model.put( MARK_DEFAULT_MESSAGE, defaultMessage );
1981         model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
1982         model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage(  ) );
1983         model.put( MARK_IS_ACTIVE_CAPTCHA, PluginService.isPluginEnable( JCAPTCHA_PLUGIN ) );
1984         model.put( MARK_YES_VALUE, CONSTANTE_YES_VALUE );
1985         model.put( MARK_NO_VALUE, CONSTANTE_NO_VALUE );
1986         model.put( MARK_VOTE_TYPE_LIST, refVoteTypeList );
1987         model.put( MARK_AUTHENTIFICATION_ENABLE, SecurityService.isAuthenticationEnable(  ) );
1988         model.put( MARK_ROLE_LIST, RoleHome.getRolesList(  ) );
1989         model.put( MARK_DEFAULT_VALUE_ROLE, Digg.ROLE_NONE );
1990         model.put( MARK_THEME_REF_LIST, themesRefList );
1991         model.put( MARK_DEFAULT_THEME, defaultTheme );
1992         model.put( MARK_LIST_DIGG_SUBMIT_SORT, refListDiggSort );
1993 
1994         setPageTitleProperty( PROPERTY_CREATE_DIGG_TITLE );
1995 
1996         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_DIGG, locale, model );
1997 
1998         return getAdminPage( template.getHtml(  ) );
1999     }
2000 
2001     /**
2002      * Perform the digg creation
2003      *
2004      * @param request
2005      *            The HTTP request
2006      * @return The URL to go after performing the action
2007      */
2008     public String doCreateDigg( HttpServletRequest request )
2009     {
2010         MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
2011 
2012         if ( ( multipartRequest.getParameter( PARAMETER_CANCEL ) == null ) &&
2013                 RBACService.isAuthorized( Digg.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
2014                     DigglikeResourceIdService.PERMISSION_CREATE, getUser(  ) ) )
2015         {
2016             Plugin plugin = getPlugin(  );
2017             Digg digg = new Digg(  );
2018             String strError = getDiggData( multipartRequest, digg );
2019 
2020             if ( strError != null )
2021             {
2022                 return strError;
2023             }
2024 
2025             digg.setIdDigg( DiggHome.create( digg, plugin ) );
2026 
2027             if ( request.getParameter( PARAMETER_APPLY ) != null )
2028             {
2029                 return getJspModifyDigg( request, digg.getIdDigg(  ) );
2030             }
2031 
2032         }
2033 
2034         return getJspManageDigg( request );
2035     }
2036 
2037     /**
2038      * Gets the digg modification page
2039      *
2040      * @param request
2041      *            The HTTP request
2042      * @return The digg modification page
2043      */
2044     public String getModifyDigg( HttpServletRequest request )
2045     {
2046         Plugin plugin = getPlugin(  );
2047         List<IEntry> listEntry;
2048         int nNumberQuestion;
2049         EntryFilter filter;
2050         String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
2051         int nIdDigg = -1;
2052         int nIdEntryFistInTheList = -1;
2053         int nIdEntryLastInTheList = -1;
2054         Digg digg = null;
2055 
2056         if ( ( strIdDigg != null ) && !strIdDigg.equals( EMPTY_STRING ) )
2057         {
2058             nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
2059             digg = DiggHome.findByPrimaryKey( nIdDigg, plugin );
2060         }
2061 
2062         if ( ( digg == null ) ||
2063                 !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + nIdDigg,
2064                     DigglikeResourceIdService.PERMISSION_MODIFY, getUser(  ) ) )
2065         {
2066             return getManageDigg( request );
2067         }
2068 
2069         // initialisation de la variable de session
2070         _nIdDigg = nIdDigg;
2071         filter = new EntryFilter(  );
2072         filter.setIdDigg( digg.getIdDigg(  ) );
2073         listEntry = EntryHome.getEntryList( filter, plugin );
2074 
2075         if ( listEntry.size(  ) > 0 )
2076         {
2077             nIdEntryFistInTheList = listEntry.get( 0 ).getIdEntry(  );
2078             nIdEntryLastInTheList = listEntry.get( listEntry.size(  ) - 1 ).getIdEntry(  );
2079         }
2080 
2081         nNumberQuestion = EntryHome.getNumberEntryByFilter( filter, plugin );
2082 
2083         _strCurrentPageIndexEntry = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX,
2084                 _strCurrentPageIndexEntry );
2085         _nItemsPerPageEntry = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE,
2086                 _nItemsPerPageEntry, _nDefaultItemsPerPage );
2087 
2088         Paginator<IEntry> paginator = new Paginator<IEntry>( listEntry, _nItemsPerPageEntry,
2089                 AppPathService.getBaseUrl( request ) + JSP_MODIFY_DIGG + "?id_digg=" + digg.getIdDigg(  ),
2090                 PARAMETER_PAGE_INDEX, _strCurrentPageIndexEntry );
2091 
2092         AdminUser adminUser = getUser(  );
2093 
2094         Locale locale = getLocale(  );
2095         ReferenceList refListWorkGroups;
2096         ReferenceList refMailingList;
2097         ReferenceList refEntryType;
2098 
2099         refListWorkGroups = AdminWorkgroupService.getUserWorkgroups( adminUser, locale );
2100 
2101         refMailingList = new ReferenceList(  );
2102 
2103         String strNothing = I18nService.getLocalizedString( PROPERTY_NOTHING, locale );
2104         refMailingList.addItem( -1, strNothing );
2105         refMailingList.addAll( AdminMailingListService.getMailingLists( adminUser ) );
2106 
2107         List<Category> listCategoriesView = CategoryHome.getList( plugin );
2108         List<DiggSubmitType> listDiggSubmitTypeView = DiggSubmitTypeHome.getList( plugin );
2109 
2110         listCategoriesView.removeAll( digg.getCategories(  ) );
2111         listDiggSubmitTypeView.removeAll( digg.getDiggSubmitTypes(  ) );
2112 
2113         ReferenceList refCategoryList = DiggUtils.getRefListCategory( listCategoriesView );
2114         ReferenceList refVoteTypeList = initRefListVoteType( plugin, locale );
2115         ReferenceList refListDiggSort = DiggUtils.getRefListDiggSort( locale );
2116         ReferenceList refListDiggSubmitType = DiggUtils.getRefListType( listDiggSubmitTypeView );
2117 
2118         EntryType entryTypeGroup = new EntryType(  );
2119         refEntryType = initRefListEntryType( plugin, locale );
2120 
2121         // Style management
2122         Collection<Theme> themes = ThemesService.getThemesList(  );
2123         ReferenceList themesRefList = new ReferenceList(  );
2124 
2125         for ( Theme theme : themes )
2126         {
2127             themesRefList.addItem( theme.getCodeTheme(  ), theme.getThemeDescription(  ) );
2128         }
2129 
2130         if ( digg.getCodeTheme(  ) == null )
2131         {
2132             digg.setCodeTheme( ThemesService.getGlobalTheme(  ) );
2133         }
2134 
2135         Map<String, Object> model = new HashMap<String, Object>(  );
2136         model.put( MARK_PAGINATOR, paginator );
2137         model.put( MARK_NB_ITEMS_PER_PAGE, EMPTY_STRING + _nItemsPerPageEntry );
2138         model.put( MARK_USER_WORKGROUP_REF_LIST, refListWorkGroups );
2139         model.put( MARK_MAILING_REF_LIST, refMailingList );
2140         model.put( MARK_ENTRY_TYPE_REF_LIST, refEntryType );
2141         model.put( MARK_ENTRY_TYPE_GROUP, entryTypeGroup );
2142         model.put( MARK_DIGG, digg );
2143         model.put( MARK_ENTRY_LIST, paginator.getPageItems(  ) );
2144         model.put( MARK_NUMBER_QUESTION, nNumberQuestion );
2145         model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
2146         model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage(  ) );
2147         model.put( MARK_IS_ACTIVE_CAPTCHA, PluginService.isPluginEnable( JCAPTCHA_PLUGIN ) );
2148         model.put( MARK_YES_VALUE, CONSTANTE_YES_VALUE );
2149         model.put( MARK_NO_VALUE, CONSTANTE_NO_VALUE );
2150         model.put( MARK_CATEGORY_LIST, refCategoryList );
2151         model.put( MARK_VOTE_TYPE_LIST, refVoteTypeList );
2152         model.put( MARK_DIGG_SUBMIT_TYPE_LIST, refListDiggSubmitType );
2153         model.put( MARK_ID_ENTRY_FIRST_IN_THE_LIST, nIdEntryFistInTheList );
2154         model.put( MARK_ID_ENTRY_LAST_IN_THE_LIST, nIdEntryLastInTheList );
2155         model.put( MARK_AUTHENTIFICATION_ENABLE, SecurityService.isAuthenticationEnable(  ) );
2156         model.put( MARK_ROLE_LIST, RoleHome.getRolesList(  ) );
2157         model.put( MARK_DEFAULT_VALUE_ROLE, Digg.ROLE_NONE );
2158         model.put( MARK_THEME_REF_LIST, themesRefList );
2159         model.put( MARK_LIST_DIGG_SUBMIT_SORT, refListDiggSort );
2160 
2161         setPageTitleProperty( PROPERTY_MODIFY_DIGG_TITLE );
2162 
2163         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_DIGG, locale, model );
2164 
2165         return getAdminPage( template.getHtml(  ) );
2166     }
2167 
2168     /**
2169      * Perform the digg modification
2170      *
2171      * @param request
2172      *            The HTTP request
2173      * @return The URL to go after performing the action
2174      */
2175     public String doModifyDigg( HttpServletRequest request )
2176     {
2177         MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
2178         String strIdDigg = multipartRequest.getParameter( PARAMETER_ID_DIGG );
2179         int nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
2180 
2181         if ( ( multipartRequest.getParameter( PARAMETER_CANCEL ) == null ) && ( nIdDigg != -1 ) &&
2182                 RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + nIdDigg,
2183                     DigglikeResourceIdService.PERMISSION_MODIFY, getUser(  ) ) )
2184         {
2185             Plugin plugin = getPlugin(  );
2186             Digg digg = DiggHome.findByPrimaryKey( nIdDigg, plugin );
2187             String strError = getDiggData( multipartRequest, digg );
2188 
2189             if ( strError != null )
2190             {
2191                 return strError;
2192             }
2193             
2194             DiggHome.update( digg, plugin );
2195 
2196            
2197            
2198             if ( request.getParameter( PARAMETER_APPLY ) != null )
2199             {
2200                 return getJspModifyDigg( request, digg.getIdDigg(  ) );
2201             }
2202         }
2203 
2204         return getJspManageDigg( request );
2205     }
2206 
2207     /**
2208      * Perform add digg submit type association
2209      *
2210      * @param request
2211      *            The HTTP request
2212      * @return The URL to go after performing the action
2213      */
2214     public String doInsertDiggSubmitType( HttpServletRequest request )
2215     {
2216         Plugin plugin = getPlugin(  );
2217         Digg digg;
2218         String strIdDiggSubmitType = request.getParameter( PARAMETER_ID_DIGG_SUBMIT_TYPE );
2219         int nIDiggSubmitType = DiggUtils.getIntegerParameter( strIdDiggSubmitType );
2220         DiggSubmitType diggSubmitType = DiggSubmitTypeHome.findByPrimaryKey( nIDiggSubmitType, plugin );
2221 
2222         digg = DiggHome.findByPrimaryKey( _nIdDigg, plugin );
2223 
2224         if ( ( diggSubmitType != null ) && ( digg != null ) && ( digg.getDiggSubmitTypes(  ) != null ) &&
2225                 !digg.getDiggSubmitTypes(  ).contains( diggSubmitType ) &&
2226                 RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + _nIdDigg,
2227                     DigglikeResourceIdService.PERMISSION_MODIFY, getUser(  ) ) )
2228         {
2229             DiggSubmitTypeHome.createDiggAssociation( _nIdDigg, nIDiggSubmitType, plugin );
2230         }
2231 
2232         if ( _nIdDigg != -1 )
2233         {
2234             return getJspModifyDigg( request, _nIdDigg );
2235         }
2236 
2237         return getJspManageDigg( request );
2238     }
2239 
2240     /**
2241      * remove DiggSubmitType association
2242      * @param request
2243      *            The HTTP request
2244      * @return The URL to go after performing the action
2245      */
2246     public String doRemoveDiggSubmitType( HttpServletRequest request )
2247     {
2248         Plugin plugin = getPlugin(  );
2249         Digg digg;
2250         String strIdDiggSubmitType = request.getParameter( PARAMETER_ID_DIGG_SUBMIT_TYPE );
2251         int nIDiggSubmitType = DiggUtils.getIntegerParameter( strIdDiggSubmitType );
2252         DiggSubmitType diggSubmitType = DiggSubmitTypeHome.findByPrimaryKey( nIDiggSubmitType, plugin );
2253 
2254         digg = DiggHome.findByPrimaryKey( _nIdDigg, plugin );
2255 
2256         if ( ( diggSubmitType != null ) && ( digg != null ) &&
2257                 RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + _nIdDigg,
2258                     DigglikeResourceIdService.PERMISSION_MODIFY, getUser(  ) ) )
2259         {
2260             DiggSubmitTypeHome.removeDiggAssociation( _nIdDigg, nIDiggSubmitType, plugin );
2261         }
2262 
2263         if ( _nIdDigg != -1 )
2264         {
2265             return getJspModifyDigg( request, _nIdDigg );
2266         }
2267 
2268         return getJspManageDigg( request );
2269     }
2270 
2271     /**
2272      * Perform add a category in the digg
2273      *
2274      * @param request
2275      *            The HTTP request
2276      * @return The URL to go after performing the action
2277      */
2278     public String doInsertCategory( HttpServletRequest request )
2279     {
2280         Plugin plugin = getPlugin(  );
2281         Category category;
2282         Digg digg;
2283         String strCategory = request.getParameter( PARAMETER_ID_CATEGORY );
2284         int nIdCategory = DiggUtils.getIntegerParameter( strCategory );
2285         category = CategoryHome.findByPrimaryKey( nIdCategory, plugin );
2286 
2287         digg = DiggHome.findByPrimaryKey( _nIdDigg, plugin );
2288 
2289         if ( ( category != null ) && ( digg != null ) && ( digg.getCategories(  ) != null ) &&
2290                 !digg.getCategories(  ).contains( category ) &&
2291                 RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + _nIdDigg,
2292                     DigglikeResourceIdService.PERMISSION_MODIFY, getUser(  ) ) )
2293         {
2294             CategoryHome.createDiggAssociation( _nIdDigg, nIdCategory, plugin );
2295         }
2296 
2297         if ( _nIdDigg != -1 )
2298         {
2299             return getJspModifyDigg( request, _nIdDigg );
2300         }
2301 
2302         return getJspManageDigg( request );
2303     }
2304 
2305     /**
2306      * Perform add a category in the digg
2307      *
2308      * @param request
2309      *            The HTTP request
2310      * @return The URL to go after performing the action
2311      */
2312     public String doRemoveCategory( HttpServletRequest request )
2313     {
2314         Plugin plugin = getPlugin(  );
2315         Category category;
2316         Digg digg;
2317         String strCategory = request.getParameter( PARAMETER_ID_CATEGORY );
2318         int nIdCategory = DiggUtils.getIntegerParameter( strCategory );
2319         category = CategoryHome.findByPrimaryKey( nIdCategory, plugin );
2320         digg = DiggHome.findByPrimaryKey( _nIdDigg, plugin );
2321 
2322         if ( ( category != null ) && ( digg != null ) && ( digg.getCategories(  ) != null ) &&
2323                 RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + _nIdDigg,
2324                     DigglikeResourceIdService.PERMISSION_MODIFY, getUser(  ) ) )
2325         {
2326             CategoryHome.removeDiggAssociation( _nIdDigg, nIdCategory, plugin );
2327         }
2328 
2329         if ( _nIdDigg != -1 )
2330         {
2331             return getJspModifyDigg( request, _nIdDigg );
2332         }
2333 
2334         return getJspManageDigg( request );
2335     }
2336 
2337     /**
2338      * Gets the confirmation page of delete digg
2339      *
2340      * @param request
2341      *            The HTTP request
2342      * @return the confirmation page of delete digg
2343      */
2344     public String getConfirmRemoveDigg( HttpServletRequest request )
2345     {
2346         Plugin plugin = getPlugin(  );
2347         String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
2348         String strMessage;
2349         int nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
2350 
2351         if ( ( nIdDigg == -1 ) ||
2352                 !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + nIdDigg,
2353                     DigglikeResourceIdService.PERMISSION_DELETE, getUser(  ) ) )
2354         {
2355             return getJspManageDigg( request );
2356         }
2357 
2358         SubmitFilter responseFilter = new SubmitFilter(  );
2359         responseFilter.setIdDigg( nIdDigg );
2360 
2361         int nNumberdiggSubmit = _diggSubmitService.getCountDiggSubmit( responseFilter, plugin );
2362 
2363         if ( nNumberdiggSubmit == 0 )
2364         {
2365             strMessage = MESSAGE_CONFIRM_REMOVE_DIGG;
2366         }
2367         else
2368         {
2369             strMessage = MESSAGE_CONFIRM_REMOVE_DIGG_WITH_DIGG_SUBMIT;
2370         }
2371 
2372         UrlItem url = new UrlItem( JSP_DO_REMOVE_DIGG );
2373         url.addParameter( PARAMETER_ID_DIGG, strIdDigg );
2374 
2375         return AdminMessageService.getMessageUrl( request, strMessage, url.getUrl(  ), AdminMessage.TYPE_CONFIRMATION );
2376     }
2377 
2378     /**
2379      * Perform the digg supression
2380      *
2381      * @param request
2382      *            The HTTP request
2383      * @return The URL to go after performing the action
2384      */
2385     public String doRemoveDigg( HttpServletRequest request )
2386     {
2387         String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
2388         Plugin plugin = getPlugin(  );
2389         int nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
2390 
2391         if ( ( nIdDigg != -1 ) &&
2392                 RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + nIdDigg,
2393                     DigglikeResourceIdService.PERMISSION_DELETE, getUser(  ) ) )
2394         {
2395             DiggHome.remove( nIdDigg, plugin );
2396         }
2397 
2398         return getJspManageDigg( request );
2399     }
2400 
2401     /**
2402      * copy the digg whose key is specified in the Http request
2403      *
2404      * @param request
2405      *            The HTTP request
2406      * @return The URL to go after performing the action
2407      */
2408     public String doCopyDigg( HttpServletRequest request )
2409     {
2410         Plugin plugin = getPlugin(  );
2411         Digg digg;
2412         String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
2413         int nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
2414 
2415         if ( ( nIdDigg == -1 ) ||
2416                 !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + nIdDigg,
2417                     DigglikeResourceIdService.PERMISSION_COPY, getUser(  ) ) )
2418         {
2419             return getJspManageDigg( request );
2420         }
2421 
2422         digg = DiggHome.findByPrimaryKey( nIdDigg, plugin );
2423 
2424         Object[] tabDiggTileCopy = { digg.getTitle(  ) };
2425         String strTitleCopyDigg = I18nService.getLocalizedString( PROPERTY_COPY_DIGG_TITLE, tabDiggTileCopy,
2426                 getLocale(  ) );
2427 
2428         if ( strTitleCopyDigg != null )
2429         {
2430             digg.setTitle( strTitleCopyDigg );
2431         }
2432 
2433         DiggHome.copy( digg, plugin );
2434 
2435         return getJspManageDigg( request );
2436     }
2437 
2438     /**
2439      * Gets the entry creation page
2440      *
2441      * @param request
2442      *            The HTTP request
2443      * @return The entry creation page
2444      */
2445     public String getCreateEntry( HttpServletRequest request )
2446     {
2447         Plugin plugin = getPlugin(  );
2448         IEntry entry;
2449         Digg digg;
2450 
2451         entry = DiggUtils.createEntryByType( request, plugin );
2452         digg = DiggHome.findByPrimaryKey( _nIdDigg, plugin );
2453 
2454         if ( ( entry == null ) || ( digg == null ) ||
2455                 !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + _nIdDigg,
2456                     DigglikeResourceIdService.PERMISSION_MODIFY, getUser(  ) ) )
2457         {
2458             return getManageDigg( request );
2459         }
2460 
2461         entry.setDigg( digg );
2462 
2463         Map<String, Object> model = new HashMap<String, Object>(  );
2464         model.put( MARK_ENTRY, entry );
2465         model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
2466         model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage(  ) );
2467         setPageTitleProperty( PROPERTY_CREATE_QUESTION_TITLE );
2468 
2469         HtmlTemplate template = AppTemplateService.getTemplate( entry.getTemplateCreate(  ), getLocale(  ), model );
2470 
2471         return getAdminPage( template.getHtml(  ) );
2472     }
2473 
2474     /**
2475      * Perform the entry creation
2476      *
2477      * @param request
2478      *            The HTTP request
2479      * @return The URL to go after performing the action
2480      */
2481     public String doCreateEntry( HttpServletRequest request )
2482     {
2483         Plugin plugin = getPlugin(  );
2484         IEntry entry;
2485 
2486         if ( request.getParameter( PARAMETER_CANCEL ) == null )
2487         {
2488             entry = DiggUtils.createEntryByType( request, plugin );
2489 
2490             Digg digg = DiggHome.findByPrimaryKey( _nIdDigg, plugin );
2491 
2492             if ( ( entry == null ) || ( digg == null ) ||
2493                     !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + _nIdDigg,
2494                         DigglikeResourceIdService.PERMISSION_MODIFY, getUser(  ) ) )
2495             {
2496                 return getJspManageDigg( request );
2497             }
2498 
2499             String strError = entry.getRequestData( request, getLocale(  ) );
2500 
2501             if ( strError != null )
2502             {
2503                 return strError;
2504             }
2505 
2506             entry.setDigg( digg );
2507             entry.setIdEntry( EntryHome.create( entry, plugin ) );
2508 
2509             if ( request.getParameter( PARAMETER_APPLY ) != null )
2510             {
2511                 return getJspModifyEntry( request, entry.getIdEntry(  ) );
2512             }
2513         }
2514 
2515         return getJspModifyDigg( request, _nIdDigg );
2516     }
2517 
2518     /**
2519      * Gets the entry modification page
2520      *
2521      * @param request
2522      *            The HTTP request
2523      * @return The entry modification page
2524      */
2525     public String getModifyEntry( HttpServletRequest request )
2526     {
2527         Plugin plugin = getPlugin(  );
2528         IEntry entry;
2529         ReferenceList refListRegularExpression;
2530         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
2531         int nIdEntry = DiggUtils.getIntegerParameter( strIdEntry );
2532         Digg digg = DiggHome.findByPrimaryKey( _nIdDigg, plugin );
2533         entry = EntryHome.findByPrimaryKey( nIdEntry, plugin );
2534         List<EntryAdditionalAttribute> entryAdditionalAttributeList = EntryAdditionalAttributeHome.getList( nIdEntry,
2535                 plugin );
2536 
2537         if ( ( entry == null ) || ( digg == null ) ||
2538                 !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + _nIdDigg,
2539                     DigglikeResourceIdService.PERMISSION_MODIFY, getUser(  ) ) )
2540         {
2541             return getManageDigg( request );
2542         }
2543 
2544         Map<String, Object> model = new HashMap<String, Object>(  );
2545 
2546         for ( EntryAdditionalAttribute entryAdditionalAttribute : entryAdditionalAttributeList )
2547         {
2548             model.put( entryAdditionalAttribute.getName(  ), entryAdditionalAttribute.getValue(  ) );
2549         }
2550 
2551         model.put( MARK_ENTRY, entry );
2552         _strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
2553         _nItemsPerPage = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage,
2554                 _nDefaultItemsPerPage );
2555 
2556         Paginator paginator = entry.getPaginator( _nItemsPerPage,
2557                 AppPathService.getBaseUrl( request ) + JSP_MODIFY_ENTRY + "?id_entry=" + nIdEntry,
2558                 PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
2559 
2560         if ( paginator != null )
2561         {
2562             model.put( MARK_NB_ITEMS_PER_PAGE, EMPTY_STRING + _nItemsPerPage );
2563             model.put( MARK_NUMBER_ITEMS, paginator.getItemsCount(  ) );
2564             model.put( MARK_LIST, paginator.getPageItems(  ) );
2565             model.put( MARK_PAGINATOR, paginator );
2566         }
2567 
2568         refListRegularExpression = entry.getReferenceListRegularExpression( entry, plugin );
2569 
2570         if ( refListRegularExpression != null )
2571         {
2572             model.put( MARK_REGULAR_EXPRESSION_LIST_REF_LIST, refListRegularExpression );
2573         }
2574 
2575         model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
2576         model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage(  ) );
2577         setPageTitleProperty( PROPERTY_MODIFY_QUESTION_TITLE );
2578 
2579         HtmlTemplate template = AppTemplateService.getTemplate( entry.getTemplateModify(  ), getLocale(  ), model );
2580 
2581         return getAdminPage( template.getHtml(  ) );
2582     }
2583 
2584     /**
2585      * Perform the entry modification
2586      *
2587      * @param request
2588      *            The HTTP request
2589      * @return The URL to go after performing the action
2590      */
2591     public String doModifyEntry( HttpServletRequest request )
2592     {
2593         Plugin plugin = getPlugin(  );
2594         IEntry entry;
2595         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
2596         int nIdEntry = DiggUtils.getIntegerParameter( strIdEntry );
2597 
2598         entry = EntryHome.findByPrimaryKey( nIdEntry, plugin );
2599 
2600         Digg digg = DiggHome.findByPrimaryKey( _nIdDigg, plugin );
2601 
2602         if ( ( entry == null ) || ( digg == null ) ||
2603                 !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + _nIdDigg,
2604                     DigglikeResourceIdService.PERMISSION_MODIFY, getUser(  ) ) )
2605         {
2606             return getJspManageDigg( request );
2607         }
2608 
2609         if ( request.getParameter( PARAMETER_CANCEL ) == null )
2610         {
2611             String strError = entry.getRequestData( request, getLocale(  ) );
2612 
2613             if ( strError != null )
2614             {
2615                 return strError;
2616             }
2617 
2618             EntryHome.update( entry, plugin );
2619         }
2620 
2621         if ( request.getParameter( PARAMETER_APPLY ) != null )
2622         {
2623             return getJspModifyEntry( request, nIdEntry );
2624         }
2625 
2626         return getJspModifyDigg( request, digg.getIdDigg(  ) );
2627     }
2628 
2629     /**
2630      * Gets the confirmation page of delete entry
2631      *
2632      * @param request
2633      *            The HTTP request
2634      * @return the confirmation page of delete entry
2635      */
2636     public String getConfirmRemoveEntry( HttpServletRequest request )
2637     {
2638         String strMessage;
2639         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
2640         int nIdEntry = DiggUtils.getIntegerParameter( strIdEntry );
2641 
2642         if ( nIdEntry == -1 )
2643         {
2644             return getHomeUrl( request );
2645         }
2646 
2647         strMessage = MESSAGE_CONFIRM_REMOVE_ENTRY;
2648 
2649         UrlItem url = new UrlItem( JSP_DO_REMOVE_ENTRY );
2650         url.addParameter( PARAMETER_ID_ENTRY, strIdEntry + "#list" );
2651 
2652         return AdminMessageService.getMessageUrl( request, strMessage, url.getUrl(  ), AdminMessage.TYPE_CONFIRMATION );
2653     }
2654 
2655     /**
2656      * Perform the entry supression
2657      *
2658      * @param request
2659      *            The HTTP request
2660      * @return The URL to go after performing the action
2661      */
2662     public String doRemoveEntry( HttpServletRequest request )
2663     {
2664         Plugin plugin = getPlugin(  );
2665         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
2666         int nIdEntry = DiggUtils.getIntegerParameter( strIdEntry );
2667         Digg digg = DiggHome.findByPrimaryKey( _nIdDigg, plugin );
2668 
2669         if ( ( nIdEntry == -1 ) || ( digg == null ) ||
2670                 !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + _nIdDigg,
2671                     DigglikeResourceIdService.PERMISSION_MODIFY, getUser(  ) ) )
2672         {
2673             return getJspManageDigg( request );
2674         }
2675 
2676         EntryHome.remove( nIdEntry, plugin );
2677 
2678         return getJspModifyDigg( request, digg.getIdDigg(  ) );
2679     }
2680 
2681     /**
2682      * copy the entry whose key is specified in the Http request
2683      *
2684      * @param request
2685      *            The HTTP request
2686      * @return The URL to go after performing the action
2687      */
2688     public String doCopyEntry( HttpServletRequest request )
2689     {
2690         Plugin plugin = getPlugin(  );
2691         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
2692         int nIdEntry = DiggUtils.getIntegerParameter( strIdEntry );
2693         IEntry entry;
2694         entry = EntryHome.findByPrimaryKey( nIdEntry, plugin );
2695 
2696         Digg digg = DiggHome.findByPrimaryKey( _nIdDigg, plugin );
2697 
2698         if ( ( entry == null ) || ( digg == null ) ||
2699                 !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + _nIdDigg,
2700                     DigglikeResourceIdService.PERMISSION_MODIFY, getUser(  ) ) )
2701         {
2702             return getJspManageDigg( request );
2703         }
2704 
2705         Object[] tabEntryTileCopy = { entry.getTitle(  ) };
2706         String strTitleCopyEntry = I18nService.getLocalizedString( PROPERTY_COPY_ENTRY_TITLE, tabEntryTileCopy,
2707                 getLocale(  ) );
2708 
2709         if ( strTitleCopyEntry != null )
2710         {
2711             entry.setTitle( strTitleCopyEntry );
2712         }
2713 
2714         EntryHome.copy( entry, plugin );
2715 
2716         return getJspModifyDigg( request, digg.getIdDigg(  ) );
2717     }
2718 
2719     /**
2720      * Move up the entry
2721      *
2722      * @param request
2723      *            The HTTP request
2724      * @return The URL to go after performing the action
2725      */
2726     public String doMoveUpEntry( HttpServletRequest request )
2727     {
2728         Plugin plugin = getPlugin(  );
2729         IEntry entry;
2730         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
2731         int nIdEntry = DiggUtils.getIntegerParameter( strIdEntry );
2732 
2733         entry = EntryHome.findByPrimaryKey( nIdEntry, plugin );
2734 
2735         Digg digg = DiggHome.findByPrimaryKey( _nIdDigg, plugin );
2736 
2737         if ( ( entry == null ) || ( digg == null ) ||
2738                 !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + _nIdDigg,
2739                     DigglikeResourceIdService.PERMISSION_MODIFY, getUser(  ) ) )
2740         {
2741             return getJspManageDigg( request );
2742         }
2743 
2744         List<IEntry> listEntry;
2745         EntryFilter filter = new EntryFilter(  );
2746         filter.setIdDigg( entry.getDigg(  ).getIdDigg(  ) );
2747         listEntry = EntryHome.getEntryList( filter, plugin );
2748 
2749         int nIndexEntry = DiggUtils.getIndexEntryInTheEntryList( nIdEntry, listEntry );
2750 
2751         if ( nIndexEntry != 0 )
2752         {
2753             int nNewPosition;
2754             IEntry entryToInversePosition;
2755             entryToInversePosition = listEntry.get( nIndexEntry - 1 );
2756             entryToInversePosition = EntryHome.findByPrimaryKey( entryToInversePosition.getIdEntry(  ), plugin );
2757             nNewPosition = entryToInversePosition.getPosition(  );
2758             entryToInversePosition.setPosition( entry.getPosition(  ) );
2759             entry.setPosition( nNewPosition );
2760             EntryHome.update( entry, plugin );
2761             EntryHome.update( entryToInversePosition, plugin );
2762         }
2763 
2764         return getJspModifyDigg( request, digg.getIdDigg(  ) );
2765     }
2766 
2767     /**
2768      * Move down the entry
2769      *
2770      * @param request
2771      *            The HTTP request
2772      * @return The URL to go after performing the action
2773      */
2774     public String doMoveDownEntry( HttpServletRequest request )
2775     {
2776         Plugin plugin = getPlugin(  );
2777         IEntry entry;
2778 
2779         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
2780         int nIdEntry = DiggUtils.getIntegerParameter( strIdEntry );
2781 
2782         entry = EntryHome.findByPrimaryKey( nIdEntry, plugin );
2783 
2784         Digg digg = DiggHome.findByPrimaryKey( _nIdDigg, plugin );
2785 
2786         if ( ( entry == null ) || ( digg == null ) ||
2787                 !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + _nIdDigg,
2788                     DigglikeResourceIdService.PERMISSION_MODIFY, getUser(  ) ) )
2789         {
2790             return getJspManageDigg( request );
2791         }
2792 
2793         List<IEntry> listEntry;
2794         EntryFilter filter = new EntryFilter(  );
2795         filter.setIdDigg( entry.getDigg(  ).getIdDigg(  ) );
2796         listEntry = EntryHome.getEntryList( filter, plugin );
2797 
2798         int nIndexEntry = DiggUtils.getIndexEntryInTheEntryList( nIdEntry, listEntry );
2799 
2800         if ( nIndexEntry != ( listEntry.size(  ) - 1 ) )
2801         {
2802             int nNewPosition;
2803             IEntry entryToInversePosition;
2804             entryToInversePosition = listEntry.get( nIndexEntry + 1 );
2805             entryToInversePosition = EntryHome.findByPrimaryKey( entryToInversePosition.getIdEntry(  ), plugin );
2806             nNewPosition = entryToInversePosition.getPosition(  );
2807             entryToInversePosition.setPosition( entry.getPosition(  ) );
2808             entry.setPosition( nNewPosition );
2809             EntryHome.update( entry, plugin );
2810             EntryHome.update( entryToInversePosition, plugin );
2811         }
2812 
2813         return getJspModifyDigg( request, digg.getIdDigg(  ) );
2814     }
2815 
2816     /**
2817      * Gets the confirmation page of disable digg
2818      *
2819      * @param request
2820      *            The HTTP request
2821      * @return the confirmation page of disable digg
2822      */
2823     public String getConfirmDisableDigg( HttpServletRequest request )
2824     {
2825         String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
2826         int nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
2827 
2828         if ( nIdDigg == -1 )
2829         {
2830             return getHomeUrl( request );
2831         }
2832 
2833         String strMessage;
2834         strMessage = MESSAGE_CONFIRM_DISABLE_DIGG;
2835 
2836         UrlItem url = new UrlItem( JSP_DO_DISABLE_DIGG );
2837         url.addParameter( PARAMETER_ID_DIGG, strIdDigg );
2838 
2839         return AdminMessageService.getMessageUrl( request, strMessage, url.getUrl(  ), AdminMessage.TYPE_CONFIRMATION );
2840     }
2841 
2842     /**
2843      * Perform disable digg
2844      *
2845      * @param request
2846      *            The HTTP request
2847      * @return The URL to go after performing the action
2848      */
2849     public String doDisableDigg( HttpServletRequest request )
2850     {
2851         Digg digg;
2852         Plugin plugin = getPlugin(  );
2853         String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
2854         int nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
2855         digg = DiggHome.findByPrimaryKey( nIdDigg, plugin );
2856 
2857         if ( ( digg != null ) &&
2858                 RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + nIdDigg,
2859                     DigglikeResourceIdService.PERMISSION_CHANGE_STATE, getUser(  ) ) )
2860         {
2861             digg.setActive( false );
2862             DiggHome.update( digg, getPlugin(  ) );
2863 
2864             if ( digg.getDiggsSubmit(  ) != null )
2865             {
2866                 for ( DiggSubmit submit : digg.getDiggsSubmit(  ) )
2867                 {
2868                     String strIdDiggSubmit = Integer.toString( submit.getIdDiggSubmit(  ) );
2869                     IndexationService.addIndexerAction( strIdDiggSubmit + "_" + DigglikeIndexer.SHORT_NAME,
2870                         AppPropertiesService.getProperty( DigglikeIndexer.PROPERTY_INDEXER_NAME ),
2871                         IndexerAction.TASK_DELETE );
2872 
2873                     DiggIndexerUtils.addIndexerAction( strIdDiggSubmit, IndexerAction.TASK_DELETE );
2874                 }
2875             }
2876         }
2877 
2878         return getJspManageDigg( request );
2879     }
2880 
2881     /**
2882      * Perform enable form
2883      *
2884      * @param request
2885      *            The HTTP request
2886      * @return The URL to go after performing the action
2887      */
2888     public String doEnableDigg( HttpServletRequest request )
2889     {
2890         Digg digg;
2891         Plugin plugin = getPlugin(  );
2892         String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
2893         int nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
2894         digg = DiggHome.findByPrimaryKey( nIdDigg, plugin );
2895 
2896         if ( ( digg != null ) &&
2897                 RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + nIdDigg,
2898                     DigglikeResourceIdService.PERMISSION_CHANGE_STATE, getUser(  ) ) )
2899         {
2900             digg.setActive( true );
2901             DiggHome.update( digg, getPlugin(  ) );
2902 
2903             if ( digg.getDiggsSubmit(  ) != null )
2904             {
2905                 for ( DiggSubmit submit : digg.getDiggsSubmit(  ) )
2906                 {
2907                     String strIdDiggSubmit = Integer.toString( submit.getIdDiggSubmit(  ) );
2908                     IndexationService.addIndexerAction( strIdDiggSubmit,
2909                         AppPropertiesService.getProperty( DigglikeIndexer.PROPERTY_INDEXER_NAME ),
2910                         IndexerAction.TASK_CREATE );
2911 
2912                     DiggIndexerUtils.addIndexerAction( strIdDiggSubmit, IndexerAction.TASK_CREATE );
2913                 }
2914             }
2915         }
2916 
2917         return getJspManageDigg( request );
2918     }
2919 
2920     /**
2921      * return url of the jsp manage digg
2922      *
2923      * @param request
2924      *            The HTTP request
2925      * @return url of the jsp manage digg
2926      */
2927     private String getJspManageDigg( HttpServletRequest request )
2928     {
2929         return AppPathService.getBaseUrl( request ) + JSP_MANAGE_DIGG;
2930     }
2931 
2932     //    /**
2933     //     * return url of the jsp manage diggSubmitType
2934     //     *
2935     //     * @param request
2936     //     *            The HTTP request
2937     //     * @return url of the jsp manage digg
2938     //     */
2939     //    private String getJspManageDiggSubmitType( HttpServletRequest request )
2940     //    {
2941     //        return AppPathService.getBaseUrl( request ) + JSP_MANAGE_DIGG_SUBMIT_TYPE;
2942     //    }
2943 
2944     /**
2945      * return url of the jsp manage digg submit
2946      *
2947      * @param request
2948      *            The HTTP request
2949      * @return url of the jsp manage digg submit
2950      */
2951     public static String getJspManageDiggSubmit( HttpServletRequest request )
2952     {
2953         return AppPathService.getBaseUrl( request ) + JSP_MANAGE_DIGG_SUBMIT;
2954     }
2955 
2956     /**
2957      * return url of the jsp manage digg submit order
2958      *
2959      * @param request
2960      *            The HTTP request
2961      * @return url of the jsp manage digg submit order
2962      */
2963     public static String getJspManageDiggSubmitOrder( HttpServletRequest request )
2964     {
2965         return AppPathService.getBaseUrl( request ) + JSP_MANAGE_DIGG_SUBMIT_ORDER;
2966     }
2967 
2968     /**
2969      * return url of the jsp manage comment submit
2970      *
2971      * @param request
2972      *            The HTTP request
2973      * @param strIdParentCommentSubmit strIdParentCommentSubmit
2974      * @return url of the jsp manage comment submit
2975      */
2976     private String getJspManageCommentSubmit( HttpServletRequest request, String strIdParentCommentSubmit )
2977     {
2978         String strUrlReturn = ( strIdParentCommentSubmit == null ) ? JSP_MANAGE_COMMENT_SUBMIT
2979                                                                    : ( JSP_MANAGE_COMMENT_SUBMIT + "?" +
2980             PARAMETER_ID_PARENT + "=" + strIdParentCommentSubmit );
2981 
2982         return AppPathService.getBaseUrl( request ) + strUrlReturn;
2983     }
2984 
2985     /**
2986      * return url of the jsp manage comment submit
2987      *
2988      * @param request
2989      *            The HTTP request
2990      * @param strIdParentCommentSubmit strIdParentCommentSubmit
2991      * @return url of the jsp manage comment submit
2992      */
2993     private String getJspManageCommentSubmit( HttpServletRequest request )
2994     {
2995         return getJspManageCommentSubmit( request, null );
2996     }
2997 
2998     /**
2999      * return url of the jsp modify digg
3000      *
3001      * @param request
3002      *            The HTTP request
3003      * @param nIdDigg
3004      *            the key of digg to modify
3005      * @return return url of the jsp modify digg
3006      */
3007     private String getJspModifyDigg( HttpServletRequest request, int nIdDigg )
3008     {
3009         return AppPathService.getBaseUrl( request ) + JSP_MODIFY_DIGG + "?id_digg=" + nIdDigg;
3010     }
3011 
3012     /**
3013      * return url of the jsp modify entry
3014      *
3015      * @param request
3016      *            The HTTP request
3017      * @param nIdEntry
3018      *            the key of entry to modify
3019      * @return return url of the jsp modify entry
3020      */
3021     private String getJspModifyEntry( HttpServletRequest request, int nIdEntry )
3022     {
3023         return AppPathService.getBaseUrl( request ) + JSP_MODIFY_ENTRY + "?id_entry=" + nIdEntry;
3024     }
3025 
3026     /**
3027      * return url of the jsp manage advanced parameters
3028      *
3029      * @param request
3030      *            The HTTP request
3031      * @return url of the jsp manage advanced parameters
3032      */
3033     private String getJspManageAdvancedParameters( HttpServletRequest request )
3034     {
3035         return AppPathService.getBaseUrl( request ) + JSP_MANAGE_ADVANCED_PARAMETERS;
3036     }
3037 
3038     /**
3039      * Init reference list whidth the different entry type
3040      *
3041      * @param plugin
3042      *            the plugin
3043      * @param locale
3044      *            the locale
3045      * @return reference list of entry type
3046      */
3047     private ReferenceList initRefListEntryType( Plugin plugin, Locale locale )
3048     {
3049         ReferenceList refListEntryType = new ReferenceList(  );
3050         List<EntryType> listEntryType = EntryTypeHome.getList( plugin );
3051 
3052         for ( EntryType entryType : listEntryType )
3053         {
3054             refListEntryType.addItem( entryType.getIdType(  ), entryType.getTitle(  ) );
3055         }
3056 
3057         return refListEntryType;
3058     }
3059 
3060     /**
3061      * Init reference list whidth the different vote type
3062      *
3063      * @param plugin
3064      *            the plugin
3065      * @param locale
3066      *            the locale
3067      * @return reference list of vote type
3068      */
3069     private ReferenceList initRefListVoteType( Plugin plugin, Locale locale )
3070     {
3071         ReferenceList refListVoteType = new ReferenceList(  );
3072         List<VoteType> listVoteType = VoteTypeHome.getList( plugin );
3073 
3074         for ( VoteType voteType : listVoteType )
3075         {
3076             refListVoteType.addItem( voteType.getIdVoteType(  ), voteType.getTitle(  ) );
3077         }
3078 
3079         return refListVoteType;
3080     }
3081 
3082     /**
3083      * Init reference list whidth the different digg submit state
3084      *
3085      * @param plugin
3086      *            the plugin
3087      * @param locale
3088      *            the locale
3089      * @return reference the different digg submit state
3090      */
3091     private ReferenceList initRefListDiggSubmitState( Plugin plugin, Locale locale )
3092     {
3093         ReferenceList refListDiggSubmitState = new ReferenceList(  );
3094         String strAll = I18nService.getLocalizedString( PROPERTY_ALL, locale );
3095         List<DiggSubmitState> listDiggSubmitState = DiggSubmitStateHome.getList( plugin );
3096         refListDiggSubmitState.addItem( -1, strAll );
3097 
3098         for ( DiggSubmitState diggSubmitState : listDiggSubmitState )
3099         {
3100             refListDiggSubmitState.addItem( diggSubmitState.getIdDiggSubmitState(  ), diggSubmitState.getTitle(  ) );
3101         }
3102 
3103         return refListDiggSubmitState;
3104     }
3105 
3106     /**
3107      * Delete association between entry and regular expression
3108      *
3109      * @param request
3110      *            the Http Request
3111      * @return The URL to go after performing the action
3112      */
3113     public String doRemoveRegularExpression( HttpServletRequest request )
3114     {
3115         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
3116         String strIdExpression = request.getParameter( PARAMETER_ID_EXPRESSION );
3117 
3118         int nIdEntry = DiggUtils.getIntegerParameter( strIdEntry );
3119         int nIdExpression = DiggUtils.getIntegerParameter( strIdExpression );
3120 
3121         if ( ( nIdEntry != -1 ) && ( nIdExpression != -1 ) )
3122         {
3123             EntryHome.deleteVerifyBy( nIdEntry, nIdExpression, getPlugin(  ) );
3124         }
3125 
3126         if ( nIdEntry != -1 )
3127         {
3128             return getJspModifyEntry( request, nIdEntry );
3129         }
3130 
3131         return getHomeUrl( request );
3132     }
3133 
3134     /**
3135      * insert association between entry and regular expression
3136      *
3137      * @param request
3138      *            the Http Request
3139      * @return The URL to go after performing the action
3140      */
3141     public String doInsertRegularExpression( HttpServletRequest request )
3142     {
3143         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
3144         String strIdExpression = request.getParameter( PARAMETER_ID_EXPRESSION );
3145 
3146         int nIdEntry = DiggUtils.getIntegerParameter( strIdEntry );
3147         int nIdExpression = DiggUtils.getIntegerParameter( strIdExpression );
3148 
3149         if ( ( nIdEntry != -1 ) && ( nIdExpression != -1 ) )
3150         {
3151             EntryHome.insertVerifyBy( nIdEntry, nIdExpression, getPlugin(  ) );
3152         }
3153 
3154         if ( nIdEntry != -1 )
3155         {
3156             return getJspModifyEntry( request, nIdEntry );
3157         }
3158 
3159         return getHomeUrl( request );
3160     }
3161 
3162     /**
3163      * get reference list of digg state
3164      *
3165      * @param locale
3166      *            the locale
3167      * @return reference list of digg state
3168      */
3169     private ReferenceList getRefListDiggState( Locale locale )
3170     {
3171         ReferenceList refListState = new ReferenceList(  );
3172         String strAll = I18nService.getLocalizedString( PROPERTY_ALL, locale );
3173         String strEnable = I18nService.getLocalizedString( PROPERTY_ENABLE, locale );
3174         String strDisable = I18nService.getLocalizedString( PROPERTY_DISABLE, locale );
3175 
3176         refListState.addItem( -1, strAll );
3177         refListState.addItem( 1, strEnable );
3178         refListState.addItem( 0, strDisable );
3179 
3180         return refListState;
3181     }
3182 
3183     /**
3184      * get reference list contains values All,Yes,No
3185      *
3186      * @param locale
3187      *            the locale
3188      * @return reference list contains values All,Yes,No
3189      */
3190     private ReferenceList getRefListAllYesNo( Locale locale )
3191     {
3192         ReferenceList refList = new ReferenceList(  );
3193         String strAll = I18nService.getLocalizedString( PROPERTY_ALL, locale );
3194         String strYes = I18nService.getLocalizedString( PROPERTY_YES, locale );
3195         String strNo = I18nService.getLocalizedString( PROPERTY_NO, locale );
3196 
3197         refList.addItem( -1, strAll );
3198         refList.addItem( 1, strYes );
3199         refList.addItem( 0, strNo );
3200 
3201         return refList;
3202     }
3203 
3204     /**
3205      * Modify the order in the list of diggSubmit
3206      *
3207      * @param request
3208      *            The Http request
3209      * @return The Jsp URL of the process result
3210      */
3211     public String doModifyDiggSubmitOrder( HttpServletRequest request )
3212     {
3213         int nIdDiggSubmit = Integer.parseInt( request.getParameter( PARAMETER_ID_DIGG_SUBMIT ) );
3214 
3215         DiggSubmit diggSubmit = _diggSubmitService.findByPrimaryKey( nIdDiggSubmit, false, getPlugin(  ) );
3216         int nIdDigg = Integer.parseInt( request.getParameter( PARAMETER_ID_DIGG ) );
3217 
3218         if ( diggSubmit != null )
3219         {
3220             int nNewOrder = Integer.parseInt( request.getParameter( PARAMETER_DIGG_SUBMIT_ORDER ) );
3221 
3222             _diggSubmitService.updateDiggSubmitOrder( diggSubmit.getDiggSubmitOrder(  ), nNewOrder,
3223                 diggSubmit.getDigg(  ).getIdDigg(  ), diggSubmit.isPinned(  ), getPlugin(  ) );
3224         }
3225 
3226         return getJspManageDiggSubmitOrder( request ) + "?" + PARAMETER_ID_DIGG + "=" + nIdDigg;
3227     }
3228 
3229     /**
3230      * Builts a list of sequence numbers
3231      *
3232      * @param nIdDigg
3233      *            the id of the Digg
3234      * @return the list of sequence numbers
3235      */
3236     private ReferenceList getDiggSubmitOrderList( int nIdDigg, boolean bListPinned )
3237     {
3238         int nMax = _diggSubmitService.getMaxOrderList( nIdDigg, bListPinned, getPlugin(  ) );
3239         ReferenceList list = new ReferenceList(  );
3240 
3241         for ( int i = 1; i < ( nMax + 1 ); i++ )
3242         {
3243             list.addItem( i, Integer.toString( i ) );
3244         }
3245 
3246         return list;
3247     }
3248 
3249     /**
3250      * Gets the form statistics page
3251      *
3252      * @param request
3253      *            the http request
3254      * @return the form test page
3255      */
3256     public String getStatistics( HttpServletRequest request )
3257     {
3258         Plugin plugin = getPlugin(  );
3259         Locale locale = getLocale(  );
3260         Timestamp tFirstDateFilter = null;
3261         Timestamp tLastDateFilter = null;
3262         DiggFilter diggFilter = new DiggFilter(  );
3263         diggFilter.setIdState( Digg.STATE_ENABLE );
3264 
3265         List<Digg> listDigg = DiggHome.getDiggList( diggFilter, plugin );
3266 
3267         String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
3268         String strFirstDateFilter = request.getParameter( PARAMETER_FIRST_DATE_FILTER );
3269         String strLastDateFilter = request.getParameter( PARAMETER_LAST_DATE_FILTER );
3270         String strIdCategory = request.getParameter( PARAMETER_ID_CATEGORY_FILTER );
3271         String strIdType = request.getParameter( PARAMETER_ID_TYPE_DIGG );
3272 
3273         int nIdCategory = DiggUtils.getIntegerParameter( strIdCategory );
3274         int nIdType = DiggUtils.getIntegerParameter( strIdType );
3275 
3276         if ( ( strIdDigg != null ) && !strIdDigg.equals( EMPTY_STRING ) )
3277         {
3278             _nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
3279         }
3280         else if ( listDigg.size(  ) > 0 )
3281         {
3282             _nIdDigg = listDigg.get( 0 ).getIdDigg(  );
3283         }
3284 
3285         Digg digg = DiggHome.findByPrimaryKey( _nIdDigg, plugin );
3286 
3287         if ( ( strFirstDateFilter != null ) && !strFirstDateFilter.equals( "" ) )
3288         {
3289             try
3290             {
3291                 tFirstDateFilter = new Timestamp( DateUtil.formatDate( strFirstDateFilter, locale ).getTime(  ) );
3292             }
3293             catch ( Exception e )
3294             {
3295                 tFirstDateFilter = null;
3296             }
3297         }
3298 
3299         if ( ( strLastDateFilter != null ) && !strLastDateFilter.equals( "" ) )
3300         {
3301             try
3302             {
3303                 tLastDateFilter = new Timestamp( DateUtil.formatDate( strLastDateFilter, locale ).getTime(  ) );
3304             }
3305             catch ( Exception e )
3306             {
3307                 tLastDateFilter = null;
3308             }
3309         }
3310 
3311         // build Filter
3312         SubmitFilter filter = new SubmitFilter(  );
3313         filter.setIdDigg( _nIdDigg );
3314         filter.setDateFirst( tFirstDateFilter );
3315         filter.setDateLast( tLastDateFilter );
3316         filter.setIdCategory( nIdCategory );
3317         filter.setIdType( nIdType );
3318 
3319         // number of comments
3320         filter.setIdDiggSubmitState( DiggSubmit.STATE_PUBLISH );
3321 
3322         int nNbComments = _commentSubmitService.getCountCommentSubmit( filter, plugin );
3323 
3324         // number of votes
3325         filter.setIdDiggSubmitState( DiggSubmit.STATE_PUBLISH );
3326 
3327         int nNbVotes = 0;
3328 
3329         List<DiggSubmit> listDiggSubmit = _diggSubmitService.getDiggSubmitList( filter, plugin );
3330         List<String> listUsersKey = new ArrayList<String>(  );
3331 
3332         for ( DiggSubmit d : listDiggSubmit )
3333         {
3334             nNbVotes += d.getNumberVote(  );
3335 
3336             if ( !listUsersKey.contains( d.getLuteceUserKey(  ) ) )
3337             {
3338                 listUsersKey.add( d.getLuteceUserKey(  ) );
3339             }
3340         }
3341 
3342         // number of digg submit
3343         filter.setIdDiggSubmitState( DiggSubmit.STATE_DISABLE );
3344 
3345         int nNbDiggSubmitDisabled = _diggSubmitService.getCountDiggSubmit( filter, plugin );
3346         filter.setIdDiggSubmitState( DiggSubmit.STATE_WAITING_FOR_PUBLISH );
3347 
3348         int nNbDiggSubmitWaiting = _diggSubmitService.getCountDiggSubmit( filter, plugin );
3349         filter.setIdDiggSubmitState( DiggSubmit.STATE_PUBLISH );
3350 
3351         int nNbDiggSubmitPublished = _diggSubmitService.getCountDiggSubmit( filter, plugin );
3352 
3353         // high scores
3354         DiggUtils.initSubmitFilterBySort( filter, SubmitFilter.SORT_BY_SCORE_DESC );
3355 
3356         int nNumberMaxDiggSubmit = AppPropertiesService.getPropertyInt( PROPERTY_DIGGSUBMIT_HIGHSCORES, 10 );
3357         listDiggSubmit = _diggSubmitService.getDiggSubmitList( filter, plugin, nNumberMaxDiggSubmit );
3358 
3359         ReferenceList refDiggList = DiggUtils.getRefListDigg( listDigg, false );
3360 
3361         Map<String, Object> model = new HashMap<String, Object>(  );
3362 
3363         model.put( MARK_FIRST_DATE_FILTER,
3364             ( tFirstDateFilter == null ) ? null : new Date( tFirstDateFilter.getTime(  ) ) );
3365         model.put( MARK_LAST_DATE_FILTER, ( tLastDateFilter == null ) ? null : new Date( tLastDateFilter.getTime(  ) ) );
3366         model.put( MARK_DIGG, digg );
3367 
3368         if ( nNbDiggSubmitPublished != 0 )
3369         {
3370             float fV = (float) nNbVotes / nNbDiggSubmitPublished;
3371             float fC = (float) nNbComments / nNbDiggSubmitPublished;
3372 
3373             BigDecimal bd = new BigDecimal( fV );
3374             bd = bd.setScale( 2, BigDecimal.ROUND_HALF_UP );
3375 
3376             BigDecimal bd2 = new BigDecimal( fC );
3377             bd2 = bd2.setScale( 2, BigDecimal.ROUND_HALF_UP );
3378 
3379             model.put( MARK_NUMBER_VOTES, bd.toString(  ) );
3380             model.put( MARK_NUMBER_COMMENTS, bd2.toString(  ) );
3381         }
3382 
3383         if ( ( digg.getCategories(  ) != null ) && !digg.getCategories(  ).isEmpty(  ) )
3384         {
3385             ReferenceList refCategoryList = DiggUtils.getRefListCategory( digg.getCategories(  ) );
3386             DiggUtils.addEmptyItem( refCategoryList );
3387             model.put( MARK_CATEGORY_LIST, refCategoryList );
3388             model.put( MARK_DIGG_SUBMIT_CATEGORY_SELECTED, nIdCategory );
3389 
3390             if ( nIdCategory != DiggUtils.CONSTANT_ID_NULL )
3391             {
3392                 model.put( MARK_CATEGORY_FILTER, CategoryHome.findByPrimaryKey( nIdCategory, plugin ) );
3393             }
3394         }
3395 
3396         if ( ( digg.getDiggSubmitTypes(  ) != null ) && !digg.getDiggSubmitTypes(  ).isEmpty(  ) )
3397         {
3398             ReferenceList refDiggSubmitTypes = DiggUtils.getRefListType( digg.getDiggSubmitTypes(  ) );
3399             DiggUtils.addEmptyItem( refDiggSubmitTypes );
3400             model.put( MARK_DIGG_SUBMIT_TYPE_LIST, refDiggSubmitTypes );
3401             model.put( MARK_DIGG_SUBMIT_TYPE_SELECTED, nIdType );
3402 
3403             if ( nIdType != DiggUtils.CONSTANT_ID_NULL )
3404             {
3405                 model.put( MARK_TYPE_FILTER, DiggSubmitTypeHome.findByPrimaryKey( nIdType, plugin ) );
3406             }
3407         }
3408 
3409         model.put( MARK_NUMBER_DIGGSUBMIT_DISABLED, nNbDiggSubmitDisabled );
3410         model.put( MARK_NUMBER_DIGGSUBMIT_WAITING, nNbDiggSubmitWaiting );
3411         model.put( MARK_NUMBER_DIGGSUBMIT_PUBLISHED, nNbDiggSubmitPublished );
3412         model.put( MARK_NUMBER_USERS, listUsersKey.size(  ) );
3413         model.put( MARK_HIGH_SCORES, listDiggSubmit );
3414         model.put( MARK_DIGG_LIST, refDiggList );
3415         model.put( MARK_URL, AppPathService.getBaseUrl( request ) + JSP_MANAGE_COMMENT_SUBMIT + "?id_digg_submit=" );
3416 
3417         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_STATISTICS_DIGG, locale, model );
3418 
3419         return getAdminPage( template.getHtml(  ) );
3420     }
3421 
3422     /**
3423      * Gets the confirmation page of update all digg submit
3424      *
3425      * @param request
3426      *            The HTTP request
3427      * @return the confirmation page of update all digg submit
3428      */
3429     public String getConfirmUpdateAllDisplayOfDiggSubmit( HttpServletRequest request )
3430     {
3431         String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
3432         int nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
3433 
3434         if ( ( nIdDigg == -1 ) ||
3435                 !RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + nIdDigg,
3436                     DigglikeResourceIdService.PERMISSION_UPDATE_ALL_DIGG_SUBMIT, getUser(  ) ) )
3437         {
3438             return getJspManageDigg( request );
3439         }
3440 
3441         UrlItem url = new UrlItem( JSP_DO_UPDATE_ALL_DIGG_SUBMIT );
3442         url.addParameter( PARAMETER_ID_DIGG, strIdDigg );
3443 
3444         return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_UPDATE_ALL_DIGG_SUBMIT, url.getUrl(  ),
3445             AdminMessage.TYPE_CONFIRMATION );
3446     }
3447 
3448     /**
3449      * Do update all digg submit
3450      *
3451      * @param request
3452      *            The HTTP request
3453      * @return The URL to go after performing the action
3454      */
3455     public String doUpdateAllDisplayOfDiggSubmit( HttpServletRequest request )
3456     {
3457         Plugin plugin = getPlugin(  );
3458         String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
3459         int nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
3460 
3461         if ( RBACService.isAuthorized( Digg.RESOURCE_TYPE, EMPTY_STRING + nIdDigg,
3462                     DigglikeResourceIdService.PERMISSION_UPDATE_ALL_DIGG_SUBMIT, getUser(  ) ) )
3463         {
3464             _diggSubmitService.updateAllDisplayOfDiggSubmit( nIdDigg, plugin, getLocale(  ) );
3465         }
3466 
3467         return getJspManageDigg( request );
3468     }
3469 
3470     /**
3471      * Do modify advanced parameters
3472      * @param request the request
3473      * @return url
3474      */
3475     public String doModifyAdvancedParameters( HttpServletRequest request )
3476     {
3477         Digg digg;
3478         Plugin plugin = getPlugin(  );
3479         String strIdDefaultDigg = request.getParameter( PARAMETER_ID_DEFAULT_DIGG );
3480         int nIdDefaultDigg = DiggUtils.getIntegerParameter( strIdDefaultDigg );
3481 
3482         if ( !RBACService.isAuthorized( Digg.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
3483                     DigglikeResourceIdService.PERMISSION_MANAGE_ADVANCED_PARAMETERS, getUser(  ) ) )
3484         {
3485             return getManageDigg( request );
3486         }
3487 
3488         //find default Digg
3489         DiggFilter filter = new DiggFilter(  );
3490         filter.setIdDefaultDigg( DiggFilter.ID_TRUE );
3491 
3492         List<Digg> listDefaultDigg = DiggHome.getDiggList( filter, plugin );
3493 
3494         //update default digg
3495         for ( Digg defaultDigg : listDefaultDigg )
3496         {
3497             digg = DiggHome.findByPrimaryKey( defaultDigg.getIdDigg(  ), plugin );
3498             digg.setDefaultDigg( false );
3499             DiggHome.update( digg, plugin );
3500         }
3501 
3502         if ( nIdDefaultDigg != DiggUtils.CONSTANT_ID_NULL )
3503         {
3504             Digg diggDefault = DiggHome.findByPrimaryKey( nIdDefaultDigg, plugin );
3505 
3506             if ( diggDefault != null )
3507             {
3508                 diggDefault.setDefaultDigg( true );
3509                 DiggHome.update( diggDefault, plugin );
3510             }
3511         }
3512 
3513         return getJspManageAdvancedParameters( request );
3514     }
3515 
3516     private void updateSearchFieldsData( HttpServletRequest request )
3517     {
3518         String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
3519         String strIdDiggSumitState = request.getParameter( PARAMETER_ID_DIGG_SUBMIT_STATE );
3520         String strIdDiggSubmitSort = request.getParameter( PARAMETER_ID_DIGG_SUBMIT_SORT );
3521         String strIdDiggSubmitReport = request.getParameter( PARAMETER_ID_DIGG_SUBMIT_REPORT );
3522         String strIdCategory = request.getParameter( PARAMETER_ID_CATEGORY_FILTER );
3523         String strIdType = request.getParameter( PARAMETER_ID_TYPE_DIGG );
3524         String strIdContainsCommentDisable = request.getParameter( PARAMETER_ID_CONTAINS_COMMENT_DISABLE );
3525 
3526         String strQuery = request.getParameter( PARAMETER_QUERY );
3527 
3528         if ( ( strIdDigg != null ) && !strIdDigg.equals( EMPTY_STRING ) )
3529         {
3530             getSearchFields(  ).setIdDigg( DiggUtils.getIntegerParameter( strIdDigg ) );
3531         }
3532 
3533         if ( ( strIdDiggSubmitSort != null ) && !strIdDiggSubmitSort.equals( EMPTY_STRING ) )
3534         {
3535             getSearchFields(  ).setIdDiggSubmitSort( DiggUtils.getIntegerParameter( strIdDiggSubmitSort ) );
3536         }
3537 
3538         if ( ( strIdDiggSubmitReport != null ) && !strIdDiggSubmitReport.equals( EMPTY_STRING ) )
3539         {
3540             getSearchFields(  ).setIdDiggSubmitReport( DiggUtils.getIntegerParameter( strIdDiggSubmitReport ) );
3541         }
3542 
3543         if ( ( strIdDiggSumitState != null ) && !strIdDiggSumitState.equals( EMPTY_STRING ) )
3544         {
3545             getSearchFields(  ).setIdDiggSumitState( DiggUtils.getIntegerParameter( strIdDiggSumitState ) );
3546         }
3547 
3548         if ( ( strIdCategory != null ) && !strIdCategory.equals( EMPTY_STRING ) )
3549         {
3550             getSearchFields(  ).setIdCategory( DiggUtils.getIntegerParameter( strIdCategory ) );
3551         }
3552 
3553         if ( ( strIdType != null ) && !strIdType.equals( EMPTY_STRING ) )
3554         {
3555             getSearchFields(  ).setIdType( DiggUtils.getIntegerParameter( strIdType ) );
3556         }
3557 
3558         if ( ( strIdContainsCommentDisable != null ) && !strIdContainsCommentDisable.equals( EMPTY_STRING ) )
3559         {
3560             getSearchFields(  )
3561                 .setIdDiggSubmitContainsCommentDisable( DiggUtils.getIntegerParameter( strIdContainsCommentDisable ) );
3562         }
3563 
3564         if ( strQuery != null )
3565         {
3566             getSearchFields(  ).setQuery( strQuery );
3567         }
3568     }
3569 
3570     private DigglikeAdminSearchFields getSearchFields(  )
3571     {
3572         return _searchFields;
3573     }
3574 }