View Javadoc
1   /*
2    * Copyright (c) 2002-2017, 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.directory.web;
35  
36  import au.com.bytecode.opencsv.CSVReader;
37  import fr.paris.lutece.plugins.directory.business.Category;
38  import fr.paris.lutece.plugins.directory.business.Directory;
39  import fr.paris.lutece.plugins.directory.business.DirectoryAction;
40  import fr.paris.lutece.plugins.directory.business.DirectoryActionHome;
41  import fr.paris.lutece.plugins.directory.business.DirectoryFilter;
42  import fr.paris.lutece.plugins.directory.business.DirectoryHome;
43  import fr.paris.lutece.plugins.directory.business.DirectoryRemovalListenerService;
44  import fr.paris.lutece.plugins.directory.business.DirectoryXslFilter;
45  import fr.paris.lutece.plugins.directory.business.DirectoryXslHome;
46  import fr.paris.lutece.plugins.directory.business.Entry;
47  import fr.paris.lutece.plugins.directory.business.EntryFilter;
48  import fr.paris.lutece.plugins.directory.business.EntryHome;
49  import fr.paris.lutece.plugins.directory.business.EntryRemovalListenerService;
50  import fr.paris.lutece.plugins.directory.business.EntryTypeDownloadUrl;
51  import fr.paris.lutece.plugins.directory.business.EntryTypeHome;
52  import fr.paris.lutece.plugins.directory.business.Field;
53  import fr.paris.lutece.plugins.directory.business.FieldHome;
54  import fr.paris.lutece.plugins.directory.business.IEntry;
55  import fr.paris.lutece.plugins.directory.business.Record;
56  import fr.paris.lutece.plugins.directory.business.RecordField;
57  import fr.paris.lutece.plugins.directory.business.RecordFieldFilter;
58  import fr.paris.lutece.plugins.directory.business.RecordFieldHome;
59  import fr.paris.lutece.plugins.directory.service.DirectoryResourceIdService;
60  import fr.paris.lutece.plugins.directory.service.DirectoryService;
61  import fr.paris.lutece.plugins.directory.service.RecordRemovalListenerService;
62  import fr.paris.lutece.plugins.directory.service.directorysearch.DirectorySearchService;
63  import fr.paris.lutece.plugins.directory.service.parameter.DirectoryParameterService;
64  import fr.paris.lutece.plugins.directory.service.parameter.EntryParameterService;
65  import fr.paris.lutece.plugins.directory.service.record.IRecordService;
66  import fr.paris.lutece.plugins.directory.service.record.RecordService;
67  import fr.paris.lutece.plugins.directory.service.security.DirectoryUserAttributesManager;
68  import fr.paris.lutece.plugins.directory.service.upload.DirectoryAsynchronousUploadHandler;
69  import fr.paris.lutece.plugins.directory.utils.DirectoryErrorException;
70  import fr.paris.lutece.plugins.directory.utils.DirectoryUtils;
71  import fr.paris.lutece.plugins.directory.web.action.DirectoryActionResult;
72  import fr.paris.lutece.plugins.directory.web.action.DirectoryAdminSearchFields;
73  import fr.paris.lutece.plugins.directory.web.action.IDirectoryAction;
74  import fr.paris.lutece.plugins.workflowcore.business.action.Action;
75  import fr.paris.lutece.plugins.workflowcore.business.state.State;
76  import fr.paris.lutece.portal.business.rbac.RBAC;
77  import fr.paris.lutece.portal.business.role.RoleHome;
78  import fr.paris.lutece.portal.business.user.AdminUser;
79  import fr.paris.lutece.portal.service.admin.AccessDeniedException;
80  import fr.paris.lutece.portal.service.admin.AdminUserService;
81  import fr.paris.lutece.portal.service.fileupload.FileUploadService;
82  import fr.paris.lutece.portal.service.i18n.I18nService;
83  import fr.paris.lutece.portal.service.mailinglist.AdminMailingListService;
84  import fr.paris.lutece.portal.service.message.AdminMessage;
85  import fr.paris.lutece.portal.service.message.AdminMessageService;
86  import fr.paris.lutece.portal.service.plugin.Plugin;
87  import fr.paris.lutece.portal.service.plugin.PluginService;
88  import fr.paris.lutece.portal.service.portal.PortalService;
89  import fr.paris.lutece.portal.service.rbac.RBACService;
90  import fr.paris.lutece.portal.service.security.SecurityService;
91  import fr.paris.lutece.portal.service.spring.SpringContextService;
92  import fr.paris.lutece.portal.service.template.AppTemplateService;
93  import fr.paris.lutece.portal.service.util.AppLogService;
94  import fr.paris.lutece.portal.service.util.AppPathService;
95  import fr.paris.lutece.portal.service.util.AppPropertiesService;
96  import fr.paris.lutece.portal.service.workflow.WorkflowService;
97  import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupService;
98  import fr.paris.lutece.portal.web.admin.PluginAdminPageJspBean;
99  import fr.paris.lutece.portal.web.constants.Messages;
100 import fr.paris.lutece.portal.web.pluginaction.DefaultPluginActionResult;
101 import fr.paris.lutece.portal.web.pluginaction.IPluginActionResult;
102 import fr.paris.lutece.portal.web.pluginaction.PluginActionManager;
103 import fr.paris.lutece.portal.web.resource.ExtendableResourcePluginActionManager;
104 import fr.paris.lutece.portal.web.upload.MultipartHttpServletRequest;
105 import fr.paris.lutece.portal.web.util.LocalizedPaginator;
106 import fr.paris.lutece.util.ReferenceItem;
107 import fr.paris.lutece.util.ReferenceList;
108 import fr.paris.lutece.util.filesystem.FileSystemUtil;
109 import fr.paris.lutece.util.html.HtmlTemplate;
110 import fr.paris.lutece.util.html.Paginator;
111 import fr.paris.lutece.util.sql.TransactionManager;
112 import fr.paris.lutece.util.string.StringUtil;
113 import fr.paris.lutece.util.url.UrlItem;
114 
115 import org.apache.commons.fileupload.FileItem;
116 import org.apache.commons.lang.StringEscapeUtils;
117 import org.apache.commons.lang.StringUtils;
118 
119 import java.io.IOException;
120 import java.io.InputStreamReader;
121 import java.io.UnsupportedEncodingException;
122 import java.util.ArrayList;
123 import java.util.Arrays;
124 import java.util.Collection;
125 import java.util.HashMap;
126 import java.util.Iterator;
127 import java.util.List;
128 import java.util.Locale;
129 import java.util.Map;
130 
131 import javax.servlet.http.HttpServletRequest;
132 import javax.servlet.http.HttpServletResponse;
133 import javax.servlet.http.HttpSession;
134 
135 /**
136  * This class provides the user interface to manage form features ( manage, create, modify, remove)
137  */
138 public class DirectoryJspBean extends PluginAdminPageJspBean
139 {
140     /**
141      * Generated serial version UID
142      */
143     private static final long serialVersionUID = -8417121042985481292L;
144 
145     // Templates
146     private static final String TEMPLATE_MANAGE_DIRECTORY = "admin/plugins/directory/manage_directory.html";
147     private static final String TEMPLATE_MANAGE_DIRECTORY_RECORD = "admin/plugins/directory/manage_directory_record.html";
148     private static final String TEMPLATE_CREATE_DIRECTORY_RECORD = "admin/plugins/directory/create_directory_record.html";
149     private static final String TEMPLATE_MODIFY_DIRECTORY_RECORD = "admin/plugins/directory/modify_directory_record.html";
150     private static final String TEMPLATE_CREATE_DIRECTORY = "admin/plugins/directory/create_directory.html";
151     private static final String TEMPLATE_MODIFY_DIRECTORY = "admin/plugins/directory/modify_directory.html";
152     private static final String TEMPLATE_CREATE_FIELD = "admin/plugins/directory/create_field.html";
153     private static final String TEMPLATE_MOVE_ENTRY = "admin/plugins/directory/move_entry.html";
154     private static final String TEMPLATE_MODIFY_FIELD = "admin/plugins/directory/modify_field.html";
155     private static final String TEMPLATE_IMPORT_DIRECTORY_RECORD = "admin/plugins/directory/import_directory_record.html";
156     private static final String TEMPLATE_INDEX_ALL_DIRECTORY = "admin/plugins/directory/index_all_directory.html";
157     private static final String TEMPLATE_TASKS_FORM_WORKFLOW = "admin/plugins/directory/tasks_form_workflow.html";
158     private static final String TEMPLATE_RESOURCE_HISTORY = "admin/plugins/directory/resource_history.html";
159     private static final String TEMPLATE_VIEW_DIRECTORY_RECORD = "admin/plugins/directory/view_directory_record.html";
160     private static final String TEMPLATE_MANAGE_MASS_PRINT = "admin/plugins/directory/select_mass_print.html";
161     private static final String TEMPLATE_DISPLAY_MASS_PRINT = "admin/plugins/directory/display_mass_print.html";
162     private static final String TEMPLATE_MANAGE_ADVANCED_PARAMETERS = "admin/plugins/directory/manage_advanced_parameters.html";
163     private static final String TEMPLATE_VIEW_MYLUTECE_USER = "admin/plugins/directory/view_mylutece_user.html";
164     private static final String TEMPLATE_IMPORT_FIELD = "admin/plugins/directory/import_field.html";
165     private static final String TEMPLATE_ACTION_RESULT = "admin/plugins/directory/action_result.html";
166 
167     // Messages (I18n keys)
168     private static final String MESSAGE_CONFIRM_REMOVE_DIRECTORY = "directory.message.confirm_remove_directory";
169     private static final String MESSAGE_CONFIRM_REMOVE_DIRECTORY_RECORD = "directory.message.confirm_remove_directory_record";
170     private static final String MESSAGE_CONFIRM_REMOVE_ALL_DIRECTORY_RECORD = "directory.message.confirm_remove_all_directory_record";
171     private static final String MESSAGE_CONFIRM_REMOVE_DIRECTORY_WITH_RECORD = "directory.message.confirm_remove_directory_with_record";
172     private static final String MESSAGE_CONFIRM_DISABLE_DIRECTORY = "directory.message.confirm_disable_directory";
173     private static final String MESSAGE_CONFIRM_DISABLE_DIRECTORY_RECORD = "directory.message.confirm_disable_directory_record";
174     private static final String MESSAGE_CONFIRM_REMOVE_ENTRY = "directory.message.confirm_remove_entry";
175     private static final String MESSAGE_CONFIRM_REMOVE_FIELD = "directory.message.confirm_remove_field";
176     private static final String MESSAGE_CONFIRM_REMOVE_GROUP_WITH_ANY_ENTRY = "directory.message.confirm_remove_group_with_any_entry";
177     private static final String MESSAGE_CONFIRM_REMOVE_GROUP_WITH_ENTRY = "directory.message.confirm_remove_group_with_entry";
178     private static final String MESSAGE_MANDATORY_FIELD = "directory.message.mandatory.field";
179     private static final String MESSAGE_FIELD_VALUE_FIELD = "directory.message.field_value_field";
180     private static final String MESSAGE_DIRECTORY_ERROR = DirectoryUtils.MESSAGE_DIRECTORY_ERROR;
181     private static final String MESSAGE_DIRECTORY_ERROR_MANDATORY_FIELD = DirectoryUtils.MESSAGE_DIRECTORY_ERROR_MANDATORY_FIELD;
182     private static final String MESSAGE_SELECT_GROUP = "directory.message.select_group";
183     private static final String MESSAGE_NUMERIC_FIELD = "directory.message.numeric.field";
184     private static final String MESSAGE_ERROR_CSV_FILE_IMPORT = "directory.message.error_csv_file_import";
185     private static final String MESSAGE_ERROR_CSV_NUMBER_SEPARATOR = "directory.message.error_csv_number_delimiter";
186     private static final String MESSAGE_CANNOT_REMOVE_DIRECTORY = "directory.message.can_not_remove_directory";
187     private static final String MESSAGE_CANNOT_REMOVE_RECORD = "directory.message.can_not_remove_record";
188     private static final String MESSAGE_CANNOT_REMOVE_ENTRY = "directory.message.can_not_remove_entry";
189     private static final String MESSAGE_WORKFLOW_CHANGE = "directory.message.workflow_change";
190     private static final String MESSAGE_CONFIRM_CHANGE_STATES_RECORD = "directory.message.confirm_change_states_record";
191     private static final String MESSAGE_ACCESS_DENIED = "Acces denied";
192     private static final String MESSAGE_NO_DIRECTORY_STATE = "directory.message.no_automatic_record_removal";
193 
194     // private static final String MESSAGE_CANNOT_CREATE_ENTRY_DIRECTORY_IS_NOT_EMPTY = "directory.message.can_not_create_entry_directory_is_not_empty";
195     private static final String MESSAGE_CANNOT_REMOVE_ENTRY_DIRECTORY_IS_NOT_EMPTY = "directory.message.can_not_remove_entry_directory_is_not_empty";
196     private static final String MESSAGE_CANNOT_REMOVE_FIELD_DIRECTORY_IS_NOT_EMPTY = "directory.message.can_not_remove_field_directory_is_not_empty";
197     private static final String MESSAGE_CONFIRM_INDEX_ALL_DIRECTORY = "directory.message.confirm_index_all_directory";
198     private static final String MESSAGE_ERROR_NOT_SELECTED_STATE = "directory.message.not_selected_state";
199     private static final String MESSAGE_ERROR_NO_RECORD = "directory.message.no_record";
200     private static final String MESSAGE_ERROR_EXPORT_ENCODING_NOT_SUPPORTED = "directory.message.error.export.encoding.not_supported";
201     private static final String MESSAGE_ERROR_GENERIC_MESSAGE = "directory.message.error.genericMessage";
202     private static final String FIELD_TITLE = "directory.create_directory.label_title";
203 
204     // private static final String FIELD_FRONT_OFFICE_TITLE = "directory.create_directory.label_title_front";
205     private static final String FIELD_DESCRIPTION = "directory.create_directory.label_description";
206     private static final String FIELD_TITLE_FIELD = "directory.create_field.label_title";
207     private static final String FIELD_VALUE_FIELD = "directory.create_field.label_value";
208     private static final String FIELD_UNAVAILABILITY_MESSAGE = "directory.create_directory.label_unavailability_message";
209     private static final String FIELD_ID_FORM_SEARCH_TEMPLATE = "directory.create_directory.label_form_search_template";
210     private static final String FIELD_ID_RESULT_LIST_TEMPLATE = "directory.create_directory.label_result_list_template";
211     private static final String FIELD_ID_RESULT_RECORD_TEMPLATE = "directory.create_directory.label_result_record_template";
212     private static final String FIELD_NUMBER_RECORD_PER_PAGE = "directory.create_directory.label_number_record_per_page";
213     private static final String FIELD_FILE_IMPORT = "directory.import_directory_record.label_file";
214     private static final String FIELD_THUMBNAIL = "little_thumbnail";
215     private static final String FIELD_BIG_THUMBNAIL = "big_thumbnail";
216     private static final String FIELD_IMAGE = "image_full_size";
217 
218     // properties
219     private static final String PROPERTY_ALL = "directory.manage_directory.select.all";
220     private static final String PROPERTY_YES = "directory.manage_directory.select.yes";
221     private static final String PROPERTY_NO = "directory.manage_directory.select.no";
222     private static final String PROPERTY_NOTHING = "directory.create_directory.select.nothing";
223     private static final String PROPERTY_MODIFY_DIRECTORY_TITLE = "directory.modify_directory.title";
224     private static final String PROPERTY_MANAGE_DIRECTORY_RECORD_PAGE_TITLE = "directory.manage_directory_record.page_title";
225     private static final String PROPERTY_CREATE_DIRECTORY_RECORD_PAGE_TITLE = "directory.create_directory_record.page_title";
226     private static final String PROPERTY_MODIFY_DIRECTORY_RECORD_PAGE_TITLE = "directory.modify_directory_record.page_title";
227     private static final String PROPERTY_IMPORT_DIRECTORY_RECORD_PAGE_TITLE = "directory.import_directory_record.page_title";
228     private static final String PROPERTY_INDEX_ALL_DIRECTORY_PAGE_TITLE = "directory.index_all_directory.page_title";
229     private static final String PROPERTY_MANAGE_DIRECTORY_PAGE_TITLE = "directory.manage_directory.page_title";
230     private static final String PROPERTY_CREATE_DIRECTORY_PAGE_TITLE = "directory.create_directory.page_title";
231     private static final String PROPERTY_CREATE_ENTRY_COMMENT_PAGE_TITLE = "directory.create_entry.page_title_comment";
232     private static final String PROPERTY_CREATE_ENTRY_FIELD_PAGE_TITLE = "directory.create_entry.page_title_field";
233     private static final String PROPERTY_MODIFY_ENTRY_COMMENT_PAGE_TITLE = "directory.modify_entry.page_title_comment";
234     private static final String PROPERTY_MODIFY_ENTRY_FIELD_PAGE_TITLE = "directory.modify_entry.page_title_field";
235     private static final String PROPERTY_MODIFY_ENTRY_GROUP_PAGE_TITLE = "directory.modify_entry.page_title_group";
236     private static final String PROPERTY_CREATE_FIELD_PAGE_TITLE = "directory.create_field.page_title";
237     private static final String PROPERTY_MODIFY_FIELD_PAGE_TITLE = "directory.modify_field.page_title";
238     private static final String PROPERTY_COPY_DIRECTORY_TITLE = "directory.copy_directory.title";
239     private static final String PROPERTY_COPY_ENTRY_TITLE = "directory.copy_entry.title";
240     private static final String PROPERTY_IMPORT_CSV_DELIMITER = "directory.import.csv.delimiter";
241     private static final String PROPERTY_LINE = "directory.import_directory_record.line";
242     private static final String PROPERTY_TASKS_FORM_WORKFLOW_PAGE_TITLE = "directory.tasks_form_workflow.page_title";
243     private static final String PROPERTY_RESOURCE_HISTORY_PAGE_TITLE = "directory.resource_history.page_title";
244     private static final String PROPERTY_MASS_PRINT_PAGE_TITLE = "directory.mass_print.page_title";
245     private static final String PROPERTY_ENTRY_AUTORIZE_FOR_ENTRY_DIRECTORY = "directory.entry_type_directory.entry_autorize";
246     private static final String PROPERTY_ENTRY_TYPE_DIRECTORY = "directory.entry_type.directory";
247     private static final String PROPERTY_ENTRY_TYPE_GEOLOCATION = "directory.entry_type.geolocation";
248     private static final String PROPERTY_ENTRY_TYPE_IMAGE = "directory.resource_rss.entry_type_image";
249     private static final String PROPERTY_ENTRY_TYPE_MYLUTECE_USER = "directory.entry_type.mylutece_user";
250     private static final String PROPERTY_ENTRY_TYPE_REMOTE_MYLUTECE_USER = "directory.entry_type.remote_mylutece_user";
251     private static final String PROPERTY_ENTRY_TYPE_NUMBERING = "directory.entry_type.numbering";
252     private static final String PROPERTY_IMPORT_FIELD_PAGE_TITLE = "directory.import_field.page_title";
253     private static final String PROPERTY_FIRST_ITEM_ENTRY_GROUP = "directory.modify_directory.entryGroup.firstItem";
254 
255     // Markers
256     private static final String MARK_HISTORY_LIST = "history_list";
257     private static final String MARK_ID_DIRECTORY = "idDirectory";
258     private static final String MARK_ID_STATE = "idState";
259     private static final String MARK_WEBAPP_URL = "webapp_url";
260     private static final String MARK_EXTENT_CURRENT = "extent_current_val";
261     private static final String MARK_VISIBLE_LAYER = "visible_layer_val";
262     private static final String MARK_LOCALE = "locale";
263     private static final String MARK_PAGINATOR = "paginator";
264     private static final String MARK_USER_WORKGROUP_REF_LIST = "user_workgroup_list";
265     private static final String MARK_USER_WORKGROUP_SELECTED = "user_workgroup_selected";
266     private static final String MARK_ACTIVE_REF_LIST = "active_list";
267     private static final String MARK_ACTIVE_SELECTED = "active_selected";
268     private static final String MARK_ENTRY_TYPE_LIST = "entry_type_list";
269     private static final String MARK_REGULAR_EXPRESSION_LIST_REF_LIST = "regular_expression_list";
270     private static final String MARK_ENTRY = "entry";
271     private static final String MARK_FIELD = "field";
272     private static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page";
273     private static final String MARK_DIRECTORY_LIST = "directory_list";
274     private static final String MARK_ENTRY_LIST_GEOLOCATION = "entry_list_geolocation";
275     private static final String MARK_IS_ACTIVE_MYLUTECE_AUTHENTIFICATION = "is_active_mylutece_authentification";
276     private static final String MARK_MYLUTECE_USER_INFOS_LIST = "mylutece_user_infos_list";
277     private static final String MARK_MYLUTECE_USER_LOGIN = "mylutece_user_login";
278     private static final String MARK_IS_USER_ATTRIBUTES_SERVICE_ENABLE = "is_user_attributes_service_enable";
279     private static final String MARK_SORT_ORDER = "asc_sort";
280 
281     // private static final String MARK_DIRECTORY_RECORD_LIST = "directory_record_list";
282     private static final String MARK_DIRECTORY = "directory";
283     private static final String MARK_DIRECTORY_RECORD = "directory_record";
284     private static final String MARK_PERMISSION_CREATE_DIRECTORY = "permission_create_directory";
285     private static final String MARK_ENTRY_LIST = "entry_list";
286     private static final String MARK_ENTRY_GROUP_LIST = "entry_group_list";
287     private static final String MARK_ENTRY_LIST_FORM_MAIN_SEARCH = "entry_list_form_main_search";
288     private static final String MARK_ENTRY_LIST_FORM_COMPLEMENTARY_SEARCH = "entry_list_form_complementary_search";
289     private static final String MARK_ENTRY_LIST_SEARCH_RESULT = "entry_list_search_result";
290     private static final String MARK_LIST = "list";
291     private static final String MARK_FORM_SEARCH_TEMPLATE_LIST = "form_search_template_list";
292     private static final String MARK_RESULT_LIST_TEMPLATE_LIST = "result_list_template_list";
293     private static final String MARK_RESULT_RECORD_TEMPLATE_LIST = "result_record_template_list";
294     private static final String MARK_NUMBER_FIELD = "number_field";
295     private static final String MARK_NUMBER_ITEMS = "number_items";
296     private static final String MARK_NUMBER_RECORD = "number_record";
297     private static final String MARK_ROLE_REF_LIST = "role_list";
298     private static final String MARK_MAP_ID_ENTRY_LIST_RECORD_FIELD = "map_id_entry_list_record_field";
299     private static final String MARK_ID_ENTRY_TYPE_DIRECTORY = "id_entry_type_directory";
300     private static final String MARK_ID_ENTRY_TYPE_GEOLOCATION = "id_entry_type_geolocation";
301     private static final String MARK_ID_ENTRY_TYPE_IMAGE = "id_entry_type_image";
302     private static final String MARK_ID_ENTRY_TYPE_MYLUTECE_USER = "id_entry_type_mylutece_user";
303     private static final String MARK_ID_ENTRY_TYPE_REMOTE_MYLUTECE_USER = "id_entry_type_remote_mylutece_user";
304     private static final String MARK_ID_ENTRY_TYPE_NUMBERING = "id_entry_type_numbering";
305     private static final String MARK_SHOW_DATE_CREATION_RECORD = "show_date_creation_record";
306     private static final String MARK_SHOW_DATE_CREATION_RESULT = "show_date_creation_result";
307     private static final String MARK_RECORD_DATE_CREATION = "date_creation";
308     private static final String MARK_DATE_CREATION_SEARCH = "date_creation_search";
309     private static final String MARK_DATE_CREATION_BEGIN_SEARCH = "date_creation_begin_search";
310     private static final String MARK_DATE_CREATION_END_SEARCH = "date_creation_end_search";
311     private static final String MARK_PERMISSION_MANAGE_ADVANCED_PARAMETERS = "permission_manage_advanced_parameters";
312     private static final String MARK_LIST_PARAM_DEFAULT_VALUES = "list_param_default_values";
313     private static final String MARK_DIRECTORY_ACTIONS = "directory_actions";
314     private static final String MARK_SHOW_DATE_MODIFICATION_RECORD = "show_date_modification_record";
315     private static final String MARK_SHOW_DATE_MODIFICATION_RESULT = "show_date_modification_result";
316     private static final String MARK_RECORD_DATE_MODIFICATION = "date_modification";
317     private static final String MARK_DATE_MODIFICATION_SEARCH = "date_modification_search";
318     private static final String MARK_DATE_MODIFICATION_BEGIN_SEARCH = "date_modification_begin_search";
319     private static final String MARK_DATE_MODIFICATION_END_SEARCH = "date_modification_end_search";
320     private static final String MARK_MAP_CHILD = "mapChild";
321 
322     /** mark for gru */
323     private static final String MARK_POSITION_GRU_FIRST_NAME = "pfn";
324     private static final String MARK_POSITION_GRU_LAST_NAME = "pln";
325     private static final String MARK_POSITION_GRU_GUID = "pguid";
326     private static final String MARK_POSITION_GRU_CID = "pcid";
327     private static final String MARK_POSITION_GRU_EMAIL = "pem";
328 
329     // private static final String MARK_URL_ACTION = "url_action";
330     private static final String MARK_STR_ERROR = "str_error";
331     private static final String MARK_NUMBER_LINES_IMPORTED = "number_lines_imported";
332     private static final String MARK_NUMBER_LINES_ERROR = "number_lines_error";
333     private static final String MARK_FINISH_IMPORT = "finish_import";
334     private static final String MARK_WORKFLOW_REF_LIST = "workflow_list";
335     private static final String MARK_WORKFLOW_STATE_REF_LIST = "workflow_state_list";
336     private static final String MARK_WORKFLOW_SELECTED = "workflow_selected";
337     private static final String MARK_RECORD = "record";
338     private static final String MARK_RESOURCE_ACTIONS_LIST = "resource_actions_list";
339     private static final String MARK_RESOURCE_ACTIONS = "resource_actions";
340     private static final String MARK_TASKS_FORM = "tasks_form";
341     private static final String MARK_ID_ACTION = "id_action";
342     private static final String MARK_LIST_IDS_DIRECTORY_RECORD = "list_ids_directory_record";
343     private static final String MARK_RESOURCE_HISTORY = "resource_history";
344     private static final String MARK_HISTORY_WORKFLOW_ENABLED = "history_workflow";
345     private static final String MARK_PERMISSION_CREATE_RECORD = "permission_create_record";
346     private static final String MARK_PERMISSION_MASS_PRINT = "permission_mass_print";
347     private static final String MARK_PERMISSION_VISUALISATION_MYLUTECE_USER = "permission_visualisation_mylutece_user";
348     private static final String MARK_IS_WORKFLOW_ENABLED = "is_workflow_enabled";
349     private static final String MARK_IS_ASSOCIATION_ENTRY_WORKGROUP = "is_association_entry_workgroup";
350     private static final String MARK_IS_ASSOCIATION_ENTRY_ROLE = "is_association_entry_role";
351     private static final String MARK_IS_AUTHENTIFICATION_ENABLED = "is_authentification_enabled";
352     private static final String MARK_WORKFLOW_STATE_SEARCH = "workflow_state_filter_search";
353     private static final String MARK_WORKFLOW_STATE_SEARCH_SELECTED = "workflow_state_filter_search_selected";
354     private static final String MARK_SEARCH_STATE_WORKFLOW = "search_state_workflow";
355     private static final String MARK_WORKFLOW_STATE_SEARCH_DEFAULT = "search_state_workflow_default";
356     private static final String MARK_STATE_LIST = "state_list";
357     private static final String MARK_ENTRY_LIST_ASSOCIATE = "entry_list_associate";
358     private static final String MARK_DIRECTORY_LIST_ASSOCIATE = "directory_list_associate";
359     private static final String MARK_DIRECTORY_ENTRY_LIST_ASSOCIATE = "directory_entry_list_associate";
360     private static final String MARK_DIRECTORY_ASSOCIATE = "id_directory_associate";
361     private static final String MARK_THUMBNAIL_FIELD = "thumbnail_field";
362     private static final String MARK_BIG_THUMBNAIL_FIELD = "big_thumbnail_field";
363     private static final String MARK_IMAGE_FIELD = "image_field";
364     private static final String MARK_HAS_THUMBNAIL = "has_thumbnail";
365     private static final String MARK_HAS_BIG_THUMBNAIL = "has_big_thumbnail";
366     private static final String MARK_SHOW_ACTION_RESULT = "show_action_result";
367     private static final String MARK_ITEM_NAVIGATOR = "item_navigator";
368     private static final String MARK_ACTION = "action";
369 
370     // JSP URL
371     private static final String JSP_DO_DISABLE_DIRECTORY = "jsp/admin/plugins/directory/DoDisableDirectory.jsp";
372     private static final String JSP_DO_DISABLE_DIRECTORY_RECORD = "jsp/admin/plugins/directory/DoDisableDirectoryRecord.jsp";
373     private static final String JSP_DO_REMOVE_DIRECTORY = "jsp/admin/plugins/directory/DoRemoveDirectory.jsp";
374     private static final String JSP_DO_REMOVE_ALL_DIRECTORY_RECORD = "jsp/admin/plugins/directory/DoRemoveAllDirectoryRecord.jsp";
375     private static final String JSP_DO_REMOVE_DIRECTORY_RECORD = "jsp/admin/plugins/directory/DoRemoveDirectoryRecord.jsp";
376     private static final String JSP_DO_INDEX_ALL_DIRECTORY = "jsp/admin/plugins/directory/DoIndexAllDirectory.jsp";
377     private static final String JSP_DO_REMOVE_FIELD = "jsp/admin/plugins/directory/DoRemoveField.jsp";
378     private static final String JSP_DO_REMOVE_ENTRY = "jsp/admin/plugins/directory/DoRemoveEntry.jsp";
379     private static final String JSP_MANAGE_DIRECTORY = "jsp/admin/plugins/directory/ManageDirectory.jsp";
380     private static final String JSP_IMPORT_DIRECTORY_RECORD = "jsp/admin/plugins/directory/ImportDirectoryRecord.jsp";
381     private static final String JSP_IMPORT_FIELD = "jsp/admin/plugins/directory/ImportField.jsp";
382     private static final String JSP_MODIFY_DIRECTORY = "jsp/admin/plugins/directory/ModifyDirectory.jsp";
383     private static final String JSP_MODIFY_ENTRY = "jsp/admin/plugins/directory/ModifyEntry.jsp";
384     private static final String JSP_MODIFY_FIELD = "jsp/admin/plugins/directory/ModifyField.jsp";
385     private static final String JSP_TASKS_FORM_WORKFLOW = "jsp/admin/plugins/directory/TasksFormWorkflow.jsp";
386     private static final String JSP_DISPLAY_PRINT_HISTORY = "jsp/admin/plugins/directory/DisplayMassPrint.jsp";
387     private static final String JSP_MANAGE_ADVANCED_PARAMETERS = "jsp/admin/plugins/directory/ManageAdvancedParameters.jsp";
388     private static final String JSP_DO_CHANGE_STATES_RECORD = "jsp/admin/plugins/directory/DoChangeStatesRecord.jsp";
389     private static final String JSP_ACTION_RESULT = "jsp/admin/plugins/directory/ActionResult.jsp";
390     private static final String JSP_DO_VISUALISATION_RECORD = "jsp/admin/plugins/directory/DoVisualisationRecord.jsp";
391     private static final String JSP_RESOURCE_HISTORY = "jsp/admin/plugins/directory/ResourceHistory.jsp";
392     private static final String JSP_MODIFY_DIRECTORY_RECORD = "jsp/admin/plugins/directory/ModifyDirectoryRecord.jsp";
393     private static final String JSP_CREATE_DIRECTORY_RECORD = "jsp/admin/plugins/directory/CreateDirectoryRecord.jsp";
394 
395     // Parameters
396     private static final String PARAMETER_ID_DIRECTORY = DirectoryUtils.PARAMETER_ID_DIRECTORY;
397     private static final String PARAMETER_ID_DIRECTORY_RECORD = "id_directory_record";
398     private static final String PARAMETER_TITLE = "title";
399     private static final String PARAMETER_FRONT_OFFICE_TITLE = "front_office_title";
400     private static final String PARAMETER_DESCRIPTION = "description";
401     private static final String PARAMETER_UNAVAILABILITY_MESSAGE = "unavailability_message";
402     private static final String PARAMETER_ACTIVE = "active";
403     private static final String PARAMETER_WORKGROUP = "workgroup";
404     private static final String PARAMETER_ROLE_KEY = "role_key";
405     private static final String PARAMETER_ID_FORM_SEARCH_TEMPLATE = "id_form_search_template";
406     private static final String PARAMETER_ID_RESULT_LIST_TEMPLATE = "id_result_list_template";
407     private static final String PARAMETER_ID_RESULT_RECORD_TEMPLATE = "id_result_record_template";
408     private static final String PARAMETER_NUMBER_RECORD_PER_PAGE = "number_record_per_page";
409     private static final String PARAMETER_PAGE_INDEX = "page_index";
410     private static final String PARAMETER_ID_ENTRY = "id_entry";
411     private static final String PARAMETER_MOVE_BUTTON = "move";
412     private static final String PARAMETER_ID_ENTRY_GROUP = "id_entry_group";
413     private static final String PARAMETER_ORDER_ID = "order_id";
414     private static final String PARAMETER_ID_FIELD = "id_field";
415     private static final String PARAMETER_ID_EXPRESSION = "id_expression";
416     private static final String PARAMETER_CANCEL = "cancel";
417     private static final String PARAMETER_APPLY = "apply";
418     private static final String PARAMETER_VALUE = "value";
419     private static final String PARAMETER_DEFAULT_VALUE = "default_value";
420     private static final String PARAMETER_SESSION = DirectoryUtils.PARAMETER_SESSION;
421     private static final String PARAMETER_RESET_SEARCH = "resetsearch";
422     private static final String PARAMETER_DATE_SHOWN_IN_RESULT_LIST = "date_shown_in_result_list";
423     private static final String PARAMETER_DATE_SHOWN_IN_RESULT_RECORD = "date_shown_in_result_record";
424     private static final String PARAMETER_DATE_SHOWN_IN_HISTORY = "date_shown_in_history";
425     private static final String PARAMETER_DATE_SHOWN_IN_SEARCH = "date_shown_in_search";
426     private static final String PARAMETER_DATE_SHOWN_IN_ADVANCED_SEARCH = "date_shown_in_advanced_search";
427     private static final String PARAMETER_DATE_SHOWN_IN_MULTI_SEARCH = "date_shown_in_multi_search";
428     private static final String PARAMETER_DATE_SHOWN_IN_EXPORT = "date_shown_in_export";
429     private static final String PARAMETER_DATE_MODIFICATION_SHOWN_IN_RESULT_LIST = "date_modification_shown_in_result_list";
430     private static final String PARAMETER_DATE_MODIFICATION_SHOWN_IN_RESULT_RECORD = "date_modification_shown_in_result_record";
431     private static final String PARAMETER_DATE_MODIFICATION_SHOWN_IN_HISTORY = "date_modification_shown_in_history";
432     private static final String PARAMETER_DATE_MODIFICATION_SHOWN_IN_SEARCH = "date_modification_shown_in_search";
433     private static final String PARAMETER_DATE_MODIFICATION_SHOWN_IN_ADVANCED_SEARCH = "date_modification_shown_in_advanced_search";
434     private static final String PARAMETER_DATE_MODIFICATION_SHOWN_IN_MULTI_SEARCH = "date_modification_shown_in_multi_search";
435     private static final String PARAMETER_DATE_MODIFICATION_SHOWN_IN_EXPORT = "date_modification_shown_in_export";
436     private static final String PARAMETER_ID_SORT_ENTRY = "id_sort_entry";
437     private static final String PARAMETER_ASC_SORT = "asc_sort";
438     private static final String PARAMETER_ID_SORT_ENTRY_FRONT = "id_sort_entry_front";
439     private static final String PARAMETER_ASC_SORT_FRONT = "asc_sort_front";
440     private static final String PARAMETER_ACTIVATE_DIRECTORY_RECORD = "activate_directory_record";
441     private static final String PARAMETER_IS_INDEXED = "is_indexed";
442     private static final String PARAMETER_SELECTED_RECORD = "selected_record";
443     private static final String PARAMETER_ANCHOR_LIST = "list";
444     private static final String PARAMETER_IS_SEARCH_OPERATOR_OR = "is_search_operator_or";
445     /** parames for gru */
446     private static final String PARAMETER_GRU_FIRST_NAME = "fn";
447     private static final String PARAMETER_GRU_LAST_NAME = "ln";
448     private static final String PARAMETER_GRU_GUID = "guid";
449     private static final String PARAMETER_GRU_CID = "cid";
450     private static final String PARAMETER_GRU_EMAIL = "em";
451 
452     // fn=abdou&cid=302714&ln=fall&guid=680a9e86-ffdc-45e6-a3c6-e3020b487624&ph=0858812641&em=fallphenix1987@gmail.com
453 
454     // private static final String PARAMETER_NUMBER_LINES_IMPORTED = "number_lines_imported";
455     // private static final String PARAMETER_NUMBER_LINES_ERROR = "number_lines_error";
456     private static final String PARAMETER_FILE_IMPORT = "file_import";
457     private static final String PARAMETER_WORKFLOW = "id_workflow_list";
458     private static final String PARAMETER_WORKFLOW_STATE = "id_workflow_state";
459     private static final String PARAMETER_WORKFLOW_STATE_SEARCH = "workflow_state_filter_search";
460     private static final String PARAMETER_ID_ACTION = "id_action";
461     private static final String PARAMETER_ID_STATE = "id_state";
462     private static final String IS_DISPLAY_STATE_SEARCH = "1";
463     private static final String IS_DISPLAY_STATE_SEARCH_COMPLEMENTARY = "2";
464     private static final String IS_NOT_DISPLAY_STATE_SEARCH = "3";
465     private static final String ZERO = "0";
466 
467     // Misc
468     private static final String CONSTANT_EXTENSION_CSV_FILE = ".csv";
469     private static final String CONSTANT_MIME_TYPE_CSV = "application/csv";
470     private static final String CONSTANT_MIME_TYPE_TEXT_CSV = "text/csv";
471     private static final String CONSTANT_MIME_TYPE_OCTETSTREAM = "application/octet-stream";
472     private static final String MYLUTECE_PLUGIN = "mylutece";
473 
474     // Import
475     private static final int IMPORT_FIELD_NB_COLUMN_MAX = 2;
476 
477     // defaults
478     private String DEFAULT_TYPE_IMAGE = "10";
479 
480     // session fields
481     private DirectoryAdminSearchFields _searchFields = new DirectoryAdminSearchFields( );
482     private DirectoryActionResult _directoryActionResult = new DirectoryActionResult( );
483     private IRecordService _recordService = SpringContextService.getBean( RecordService.BEAN_SERVICE );
484 
485     /*-------------------------------MANAGEMENT  DIRECTORY-----------------------------*/
486 
487     /**
488      * Gets the DirectoryAdminSearchFields
489      * 
490      * @return searchFields
491      */
492     public DirectoryAdminSearchFields getSearchFields( )
493     {
494         return _searchFields;
495     }
496 
497     /**
498      * Return management directory ( list of directory )
499      * 
500      * @param request
501      *            The Http request
502      * @return Html directory
503      */
504     public String getManageDirectory( HttpServletRequest request )
505     {
506         // here is search/manage processing
507         List<DirectoryAction> listActionsForDirectoryEnable;
508         List<DirectoryAction> listActionsForDirectoryDisable;
509         List<DirectoryAction> listActions;
510 
511         String strWorkGroup = request.getParameter( PARAMETER_WORKGROUP );
512         String strActive = request.getParameter( PARAMETER_ACTIVE );
513         _searchFields.setCurrentPageIndexDirectory( Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX,
514                 _searchFields.getCurrentPageIndexDirectory( ) ) );
515         _searchFields.setItemsPerPageDirectory( Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE,
516                 _searchFields.getItemsPerPageDirectory( ), _searchFields.getDefaultItemsPerPage( ) ) );
517 
518         if ( ( strActive != null ) && !strActive.equals( DirectoryUtils.EMPTY_STRING ) )
519         {
520             _searchFields.setIdActive( DirectoryUtils.convertStringToInt( strActive ) );
521         }
522 
523         if ( ( strWorkGroup != null ) && !strWorkGroup.equals( DirectoryUtils.EMPTY_STRING ) )
524         {
525             _searchFields.setWorkGroup( strWorkGroup );
526         }
527 
528         // build Filter
529         DirectoryFilter filter = new DirectoryFilter( );
530         filter.setIsDisabled( _searchFields.getIdActive( ) );
531         filter.setWorkGroup( _searchFields.getWorkGroup( ) );
532         filter.setOrder( request.getParameter( MARK_SORT_ORDER ) );
533 
534         List<Directory> listDirectory = DirectoryHome.getDirectoryList( filter, getPlugin( ) );
535         listDirectory = (List<Directory>) AdminWorkgroupService.getAuthorizedCollection( listDirectory, getUser( ) );
536 
537         Map<String, Object> model = new HashMap<String, Object>( );
538         LocalizedPaginator<Directory> paginator = new LocalizedPaginator<Directory>( listDirectory, _searchFields.getItemsPerPageDirectory( ),
539                 getJspManageDirectory( request ), PARAMETER_PAGE_INDEX, _searchFields.getCurrentPageIndexDirectory( ), getLocale( ) );
540 
541         listActionsForDirectoryEnable = DirectoryActionHome.selectActionsByFormState( Directory.STATE_ENABLE, getPlugin( ), getLocale( ) );
542         listActionsForDirectoryDisable = DirectoryActionHome.selectActionsByFormState( Directory.STATE_DISABLE, getPlugin( ), getLocale( ) );
543 
544         for ( Directory directory : paginator.getPageItems( ) )
545         {
546             if ( directory.isEnabled( ) )
547             {
548                 listActions = listActionsForDirectoryEnable;
549             }
550             else
551             {
552                 listActions = listActionsForDirectoryDisable;
553             }
554 
555             listActions = (List<DirectoryAction>) RBACService.getAuthorizedActionsCollection( listActions, directory, getUser( ) );
556             directory.setActions( listActions );
557         }
558 
559         boolean bPermissionAdvancedParameter = RBACService.isAuthorized( Directory.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
560                 DirectoryResourceIdService.PERMISSION_MANAGE_ADVANCED_PARAMETERS, getUser( ) );
561 
562         model.put( MARK_PAGINATOR, paginator );
563         model.put( MARK_NB_ITEMS_PER_PAGE, Integer.toString( _searchFields.getItemsPerPageDirectory( ) ) );
564         model.put( MARK_USER_WORKGROUP_REF_LIST, AdminWorkgroupService.getUserWorkgroups( getUser( ), getLocale( ) ) );
565         model.put( MARK_USER_WORKGROUP_SELECTED, _searchFields.getWorkGroup( ) );
566         model.put( MARK_ACTIVE_REF_LIST, getRefListActive( getLocale( ) ) );
567         model.put( MARK_ACTIVE_SELECTED, _searchFields.getIdActive( ) );
568         model.put( MARK_DIRECTORY_LIST, paginator.getPageItems( ) );
569         model.put( MARK_PERMISSION_CREATE_DIRECTORY,
570                 RBACService.isAuthorized( Directory.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, DirectoryResourceIdService.PERMISSION_CREATE, getUser( ) ) );
571         model.put( MARK_PERMISSION_MANAGE_ADVANCED_PARAMETERS, bPermissionAdvancedParameter );
572 
573         setPageTitleProperty( PROPERTY_MANAGE_DIRECTORY_PAGE_TITLE );
574 
575         HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_MANAGE_DIRECTORY, getLocale( ), model );
576 
577         return getAdminPage( templateList.getHtml( ) );
578     }
579 
580     /**
581      * Get the request data and if there is no error insert the data in the directory specified in parameter. return null if there is no error or else return
582      * the error page url
583      * 
584      * @param request
585      *            the request
586      * @param directory
587      *            directory
588      * @param locale
589      *            the locale
590      * @return null if there is no error or else return the error page url
591      */
592     private String getDirectoryData( HttpServletRequest request, Directory directory, Locale locale )
593     {
594         String strTitle = request.getParameter( PARAMETER_TITLE );
595         String strFrontOfficeTitle = request.getParameter( PARAMETER_FRONT_OFFICE_TITLE );
596         String strDescription = request.getParameter( PARAMETER_DESCRIPTION );
597         String strUnavailabilityMessage = request.getParameter( PARAMETER_UNAVAILABILITY_MESSAGE );
598         String strWorkgroup = request.getParameter( PARAMETER_WORKGROUP );
599         String strRoleKey = request.getParameter( PARAMETER_ROLE_KEY );
600 
601         String strIdFormSearchTemplate = request.getParameter( PARAMETER_ID_FORM_SEARCH_TEMPLATE );
602         String strIdResultListTemplate = request.getParameter( PARAMETER_ID_RESULT_LIST_TEMPLATE );
603         String strIdResultRecordTemplate = request.getParameter( PARAMETER_ID_RESULT_RECORD_TEMPLATE );
604         String strNumberRecordPerPage = request.getParameter( PARAMETER_NUMBER_RECORD_PER_PAGE );
605         String strWorkflow = request.getParameter( PARAMETER_WORKFLOW );
606         String strWorkflowState = request.getParameter( PARAMETER_WORKFLOW_STATE );
607         String strDisplaySearchStateWorkflow = request.getParameter( PARAMETER_WORKFLOW_STATE_SEARCH );
608 
609         String strIdSortEntry = request.getParameter( PARAMETER_ID_SORT_ENTRY );
610         String strAscSort = request.getParameter( PARAMETER_ASC_SORT );
611         String strIdSortEntryFront = request.getParameter( PARAMETER_ID_SORT_ENTRY_FRONT );
612         String strAscSortFront = request.getParameter( PARAMETER_ASC_SORT_FRONT );
613         String strRecordActivated = request.getParameter( PARAMETER_ACTIVATE_DIRECTORY_RECORD );
614         String strIsIndexed = request.getParameter( PARAMETER_IS_INDEXED );
615         String strSearchOperatorOr = request.getParameter( PARAMETER_IS_SEARCH_OPERATOR_OR );
616 
617         // creation date field
618         String strShowDateInResultList = request.getParameter( PARAMETER_DATE_SHOWN_IN_RESULT_LIST );
619         String strShowDateInResultRecord = request.getParameter( PARAMETER_DATE_SHOWN_IN_RESULT_RECORD );
620         String strShowDateInHistory = request.getParameter( PARAMETER_DATE_SHOWN_IN_HISTORY );
621         String strShowDateInSearch = request.getParameter( PARAMETER_DATE_SHOWN_IN_SEARCH );
622         String strShowDateInAdvancedSearch = request.getParameter( PARAMETER_DATE_SHOWN_IN_ADVANCED_SEARCH );
623         String strShowDateInMultiSearch = request.getParameter( PARAMETER_DATE_SHOWN_IN_MULTI_SEARCH );
624         String strShowDateInExport = request.getParameter( PARAMETER_DATE_SHOWN_IN_EXPORT );
625 
626         // creation date field
627         String strShowDateModificationInResultList = request.getParameter( PARAMETER_DATE_MODIFICATION_SHOWN_IN_RESULT_LIST );
628         String strShowDateModificationInResultRecord = request.getParameter( PARAMETER_DATE_MODIFICATION_SHOWN_IN_RESULT_RECORD );
629         String strShowDateModificationInHistory = request.getParameter( PARAMETER_DATE_MODIFICATION_SHOWN_IN_HISTORY );
630         String strShowDateModificationInSearch = request.getParameter( PARAMETER_DATE_MODIFICATION_SHOWN_IN_SEARCH );
631         String strShowDateModificationInAdvancedSearch = request.getParameter( PARAMETER_DATE_MODIFICATION_SHOWN_IN_ADVANCED_SEARCH );
632         String strShowDateModificationInMultiSearch = request.getParameter( PARAMETER_DATE_MODIFICATION_SHOWN_IN_MULTI_SEARCH );
633         String strShowDateModificationInExport = request.getParameter( PARAMETER_DATE_MODIFICATION_SHOWN_IN_EXPORT );
634 
635         int nIdResultListTemplate = DirectoryUtils.convertStringToInt( strIdResultListTemplate );
636         int nIdResultRecordTemplate = DirectoryUtils.convertStringToInt( strIdResultRecordTemplate );
637         int nIdFormSearchTemplate = DirectoryUtils.convertStringToInt( strIdFormSearchTemplate );
638         int nNumberRecordPerPage = DirectoryUtils.convertStringToInt( strNumberRecordPerPage );
639         int nIdWorkflow = DirectoryUtils.convertStringToInt( strWorkflow );
640         int nIdWorkflowState = DirectoryUtils.convertStringToInt( strWorkflowState );
641 
642         String strFieldError = DirectoryUtils.EMPTY_STRING;
643 
644         if ( ( strTitle == null ) || strTitle.trim( ).equals( DirectoryUtils.EMPTY_STRING ) )
645         {
646             strFieldError = FIELD_TITLE;
647         }
648 
649         else
650             if ( ( strDescription == null ) || strDescription.trim( ).equals( DirectoryUtils.EMPTY_STRING ) )
651             {
652                 strFieldError = FIELD_DESCRIPTION;
653             }
654 
655             else
656                 if ( ( strUnavailabilityMessage == null ) || strUnavailabilityMessage.trim( ).equals( DirectoryUtils.EMPTY_STRING ) )
657                 {
658                     strFieldError = FIELD_UNAVAILABILITY_MESSAGE;
659                 }
660                 else
661                     if ( nIdFormSearchTemplate == DirectoryUtils.CONSTANT_ID_NULL )
662                     {
663                         strFieldError = FIELD_ID_FORM_SEARCH_TEMPLATE;
664                     }
665 
666                     else
667                         if ( nIdResultListTemplate == DirectoryUtils.CONSTANT_ID_NULL )
668                         {
669                             strFieldError = FIELD_ID_RESULT_LIST_TEMPLATE;
670                         }
671                         else
672                             if ( nIdResultRecordTemplate == DirectoryUtils.CONSTANT_ID_NULL )
673                             {
674                                 strFieldError = FIELD_ID_RESULT_RECORD_TEMPLATE;
675                             }
676                             else
677                                 if ( ( strNumberRecordPerPage == null ) || strNumberRecordPerPage.trim( ).equals( DirectoryUtils.EMPTY_STRING ) )
678                                 {
679                                     strFieldError = FIELD_NUMBER_RECORD_PER_PAGE;
680                                 }
681 
682         if ( !strFieldError.equals( DirectoryUtils.EMPTY_STRING ) )
683         {
684             Object [ ] tabRequiredFields = {
685                 I18nService.getLocalizedString( strFieldError, getLocale( ) )
686             };
687 
688             return AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_FIELD, tabRequiredFields, AdminMessage.TYPE_STOP );
689         }
690 
691         if ( nNumberRecordPerPage == -1 )
692         {
693             strFieldError = FIELD_NUMBER_RECORD_PER_PAGE;
694         }
695 
696         if ( !strFieldError.equals( DirectoryUtils.EMPTY_STRING ) )
697         {
698             Object [ ] tabRequiredFields = {
699                 I18nService.getLocalizedString( strFieldError, locale )
700             };
701 
702             return AdminMessageService.getMessageUrl( request, MESSAGE_NUMERIC_FIELD, tabRequiredFields, AdminMessage.TYPE_STOP );
703         }
704 
705         RecordFieldFilter recordFilter = new RecordFieldFilter( );
706         recordFilter.setIdDirectory( directory.getIdDirectory( ) );
707 
708         int nCountRecord = _recordService.getCountRecord( recordFilter, getPlugin( ) );
709 
710         if ( ( directory.getIdWorkflow( ) != nIdWorkflow ) && ( nCountRecord != 0 ) )
711         {
712             return AdminMessageService.getMessageUrl( request, MESSAGE_WORKFLOW_CHANGE, AdminMessage.TYPE_STOP );
713         }
714 
715         directory.setTitle( strTitle );
716 
717         if ( strFrontOfficeTitle == null )
718         {
719             strFrontOfficeTitle = StringUtils.EMPTY;
720         }
721 
722         directory.setFrontOfficeTitle( strFrontOfficeTitle );
723         directory.setDescription( strDescription );
724         directory.setUnavailabilityMessage( strUnavailabilityMessage );
725         directory.setWorkgroup( strWorkgroup );
726         directory.setRoleKey( strRoleKey );
727         directory.setIdFormSearchTemplate( nIdFormSearchTemplate );
728         directory.setIdResultListTemplate( nIdResultListTemplate );
729         directory.setIdResultRecordTemplate( nIdResultRecordTemplate );
730         directory.setNumberRecordPerPage( nNumberRecordPerPage );
731         directory.setIdWorkflow( nIdWorkflow );
732 
733         if ( nIdWorkflow > DirectoryUtils.CONSTANT_ID_NULL )
734         {
735             directory.setIdWorkflowStateToRemove( nIdWorkflowState );
736         }
737         else
738         {
739             directory.setIdWorkflowStateToRemove( DirectoryUtils.CONSTANT_ID_NULL );
740         }
741 
742         if ( ( strDisplaySearchStateWorkflow != null ) && strDisplaySearchStateWorkflow.equals( IS_DISPLAY_STATE_SEARCH ) )
743         {
744             directory.setDisplayComplementarySearchState( false );
745             directory.setDisplaySearchState( true );
746         }
747         else
748             if ( ( strDisplaySearchStateWorkflow != null ) && strDisplaySearchStateWorkflow.equals( IS_DISPLAY_STATE_SEARCH_COMPLEMENTARY ) )
749             {
750                 directory.setDisplayComplementarySearchState( true );
751                 directory.setDisplaySearchState( false );
752             }
753             else
754                 if ( ( strDisplaySearchStateWorkflow != null ) && strDisplaySearchStateWorkflow.equals( IS_NOT_DISPLAY_STATE_SEARCH ) )
755                 {
756                     directory.setDisplayComplementarySearchState( false );
757                     directory.setDisplaySearchState( false );
758                 }
759 
760         directory.setDateShownInResultList( strShowDateInResultList != null );
761         directory.setDateShownInResultRecord( strShowDateInResultRecord != null );
762         directory.setDateShownInHistory( strShowDateInHistory != null );
763         directory.setDateShownInSearch( strShowDateInSearch != null );
764         directory.setDateShownInAdvancedSearch( strShowDateInAdvancedSearch != null );
765         directory.setDateShownInMultiSearch( strShowDateInMultiSearch != null );
766         directory.setDateShownInExport( strShowDateInExport != null );
767 
768         directory.setDateModificationShownInResultList( strShowDateModificationInResultList != null );
769         directory.setDateModificationShownInResultRecord( strShowDateModificationInResultRecord != null );
770         directory.setDateModificationShownInHistory( strShowDateModificationInHistory != null );
771         directory.setDateModificationShownInSearch( strShowDateModificationInSearch != null );
772         directory.setDateModificationShownInAdvancedSearch( strShowDateModificationInAdvancedSearch != null );
773         directory.setDateModificationShownInMultiSearch( strShowDateModificationInMultiSearch != null );
774         directory.setDateModificationShownInExport( strShowDateModificationInExport != null );
775 
776         if ( ( strIdSortEntry != null ) && ( !strIdSortEntry.equals( DirectoryUtils.EMPTY_STRING ) ) )
777         {
778             directory.setIdSortEntry( strIdSortEntry );
779         }
780         else
781         {
782             directory.setIdSortEntry( null );
783         }
784 
785         if ( ( strIdSortEntryFront != null ) && ( !strIdSortEntryFront.equals( DirectoryUtils.EMPTY_STRING ) ) )
786         {
787             directory.setIdSortEntryFront( strIdSortEntryFront );
788         }
789         else
790         {
791             directory.setIdSortEntryFront( null );
792         }
793 
794         directory.setAscendingSort( strAscSort != null );
795         directory.setAscendingSortFront( strAscSortFront != null );
796         directory.setRecordActivated( strRecordActivated != null );
797         directory.setIndexed( strIsIndexed != null );
798         directory.setSearchOperatorOr( strSearchOperatorOr != null );
799 
800         return null; // No error
801     }
802 
803     /**
804      * Gets the directory creation page
805      * 
806      * @param request
807      *            The HTTP request
808      * @throws AccessDeniedException
809      *             the {@link AccessDeniedException}
810      * @return The directory creation page
811      */
812     public String getCreateDirectory( HttpServletRequest request ) throws AccessDeniedException
813     {
814         AdminUser adminUser = getUser( );
815         Locale locale = getLocale( );
816 
817         if ( !RBACService.isAuthorized( Directory.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, DirectoryResourceIdService.PERMISSION_CREATE, adminUser ) )
818         {
819             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
820         }
821 
822         DirectoryXslFilter filter = new DirectoryXslFilter( );
823 
824         filter.setIdCategory( Category.ID_CATEGORY_STYLE_FORM_SEARCH );
825 
826         ReferenceList refListStyleFormSearch = DirectoryXslHome.getRefList( filter, getPlugin( ) );
827 
828         filter.setIdCategory( Category.ID_CATEGORY_STYLE_RESULT_LIST );
829 
830         ReferenceList refListStyleResultList = DirectoryXslHome.getRefList( filter, getPlugin( ) );
831 
832         filter.setIdCategory( Category.ID_CATEGORY_STYLE_RESULT_RECORD );
833 
834         ReferenceList refListStyleResultRecord = DirectoryXslHome.getRefList( filter, getPlugin( ) );
835 
836         Map<String, Object> model = new HashMap<String, Object>( );
837         model.put( MARK_USER_WORKGROUP_REF_LIST, AdminWorkgroupService.getUserWorkgroups( adminUser, locale ) );
838 
839         if ( WorkflowService.getInstance( ).isAvailable( ) )
840         {
841             model.put( MARK_WORKFLOW_REF_LIST, WorkflowService.getInstance( ).getWorkflowsEnabled( adminUser, locale ) );
842             model.put( MARK_WORKFLOW_STATE_SEARCH_SELECTED, IS_NOT_DISPLAY_STATE_SEARCH );
843         }
844 
845         if ( SecurityService.isAuthenticationEnable( ) )
846         {
847             model.put( MARK_ROLE_REF_LIST, RoleHome.getRolesList( ) );
848         }
849 
850         // Default Values
851         ReferenceList listParamDefaultValues = DirectoryParameterService.getService( ).findDefaultValueParameters( );
852 
853         model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
854         model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage( ) );
855         model.put( MARK_FORM_SEARCH_TEMPLATE_LIST, refListStyleFormSearch );
856         model.put( MARK_RESULT_LIST_TEMPLATE_LIST, refListStyleResultList );
857         model.put( MARK_RESULT_RECORD_TEMPLATE_LIST, refListStyleResultRecord );
858         model.put( MARK_LIST_PARAM_DEFAULT_VALUES, listParamDefaultValues );
859 
860         setPageTitleProperty( PROPERTY_CREATE_DIRECTORY_PAGE_TITLE );
861 
862         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_DIRECTORY, locale, model );
863 
864         return getAdminPage( template.getHtml( ) );
865     }
866 
867     /**
868      * Perform the directory creation
869      * 
870      * @param request
871      *            The HTTP request
872      * @throws AccessDeniedException
873      *             the {@link AccessDeniedException}
874      * @return The URL to go after performing the action
875      */
876     public String doCreateDirectory( HttpServletRequest request ) throws AccessDeniedException
877     {
878         if ( !RBACService.isAuthorized( Directory.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, DirectoryResourceIdService.PERMISSION_CREATE, getUser( ) ) )
879         {
880             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
881         }
882 
883         if ( ( request.getParameter( PARAMETER_CANCEL ) == null ) )
884         {
885             Plugin plugin = getPlugin( );
886             Directory directory = new Directory( );
887             String strError = getDirectoryData( request, directory, getLocale( ) );
888 
889             if ( strError != null )
890             {
891                 return strError;
892             }
893 
894             directory.setDateCreation( DirectoryUtils.getCurrentTimestamp( ) );
895             DirectoryHome.create( directory, plugin );
896         }
897 
898         return getJspManageDirectory( request );
899     }
900 
901     /**
902      * Gets the directory modification page
903      * 
904      * @param request
905      *            The HTTP request
906      * @throws AccessDeniedException
907      *             the {@link AccessDeniedException}
908      * @return The directory modification page
909      */
910     public String getModifyDirectory( HttpServletRequest request ) throws AccessDeniedException
911     {
912         List<IEntry> listEntry = new ArrayList<IEntry>( );
913         List<IEntry> listEntryFirstLevel;
914         int nNumberField;
915         EntryFilter filter;
916         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
917         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
918         Directory directory = null;
919 
920         if ( nIdDirectory != -1 )
921         {
922             directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
923             _searchFields.setIdDirectory( nIdDirectory );
924         }
925 
926         if ( ( directory == null )
927                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_MODIFY, getUser( ) )
928                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
929         {
930             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
931         }
932 
933         filter = new EntryFilter( );
934 
935         filter.setIdDirectory( nIdDirectory );
936         filter.setIsEntryParentNull( EntryFilter.FILTER_TRUE );
937         listEntryFirstLevel = EntryHome.getEntryList( filter, getPlugin( ) );
938 
939         filter.setIsEntryParentNull( EntryFilter.ALL_INT );
940         filter.setIsComment( EntryFilter.FILTER_FALSE );
941         filter.setIsGroup( EntryFilter.FILTER_FALSE );
942 
943         nNumberField = EntryHome.getNumberEntryByFilter( filter, getPlugin( ) );
944 
945         if ( listEntryFirstLevel.size( ) != 0 )
946         {
947             listEntryFirstLevel.get( 0 ).setFirstInTheList( true );
948             listEntryFirstLevel.get( listEntryFirstLevel.size( ) - 1 ).setLastInTheList( true );
949         }
950 
951         for ( IEntry entry : listEntryFirstLevel )
952         {
953             listEntry.add( entry );
954 
955             if ( entry.getEntryType( ).getGroup( ) )
956             {
957                 filter = new EntryFilter( );
958                 filter.setIdEntryParent( entry.getIdEntry( ) );
959                 entry.setChildren( EntryHome.getEntryList( filter, getPlugin( ) ) );
960 
961                 if ( !entry.getChildren( ).isEmpty( ) )
962                 {
963                     entry.getChildren( ).get( 0 ).setFirstInTheList( true );
964                     entry.getChildren( ).get( entry.getChildren( ).size( ) - 1 ).setLastInTheList( true );
965                 }
966 
967                 for ( IEntry entryChild : entry.getChildren( ) )
968                 {
969                     listEntry.add( entryChild );
970                 }
971             }
972         }
973 
974         // Get ReferenceList of entry group for mass actions
975         filter = new EntryFilter( );
976         filter.setIdDirectory( nIdDirectory );
977         filter.setIsGroup( EntryFilter.FILTER_TRUE );
978 
979         List<IEntry> listEntryGroup = EntryHome.getEntryList( filter, getPlugin( ) );
980         ReferenceList entryGroupReferenceList = ReferenceList.convert( listEntryGroup, "idEntry", "title", true );
981         ReferenceItem emptyItem = new ReferenceItem( );
982         emptyItem.setCode( "-1" );
983         emptyItem.setName( StringEscapeUtils.escapeHtml( I18nService.getLocalizedString( PROPERTY_FIRST_ITEM_ENTRY_GROUP, getLocale( ) ) ) );
984         entryGroupReferenceList.add( 0, emptyItem );
985 
986         // /////////////
987         Map<String, List<Integer>> mapIdParentOrdersChildren = new HashMap<String, List<Integer>>( );
988 
989         // List of entry first level order
990         List<Integer> listOrderEntryFirstLevel = new ArrayList<Integer>( );
991         List<IEntry> listEntryFirstLevelMap = new ArrayList<IEntry>( );
992         listEntryFirstLevelMap.addAll( listEntryFirstLevel );
993         initOrderFirstLevel( listEntryFirstLevelMap, listOrderEntryFirstLevel );
994 
995         mapIdParentOrdersChildren.put( "0", listOrderEntryFirstLevel );
996 
997         if ( listEntryFirstLevelMap.size( ) != 0 )
998         {
999             listEntryFirstLevelMap.get( 0 ).setFirstInTheList( true );
1000             listEntryFirstLevelMap.get( listEntryFirstLevelMap.size( ) - 1 ).setLastInTheList( true );
1001         }
1002 
1003         // fillEntryListWithEntryFirstLevel( plugin, listEntry, listEntryFirstLevelMap );
1004         populateEntryMap( listEntry, mapIdParentOrdersChildren );
1005 
1006         _searchFields.setCurrentPageIndexEntry( Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _searchFields.getCurrentPageIndexEntry( ) ) );
1007 
1008         _searchFields.setItemsPerPageEntry( Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, _searchFields.getItemsPerPageEntry( ),
1009                 _searchFields.getDefaultItemsPerPage( ) ) );
1010 
1011         LocalizedPaginator<IEntry> paginator = new LocalizedPaginator<IEntry>( listEntry, _searchFields.getItemsPerPageEntry( ),
1012                 AppPathService.getBaseUrl( request ) + JSP_MODIFY_DIRECTORY + "?id_directory=" + nIdDirectory, PARAMETER_PAGE_INDEX,
1013                 _searchFields.getCurrentPageIndexEntry( ), getLocale( ) );
1014 
1015         AdminUser adminUser = getUser( );
1016 
1017         Locale locale = getLocale( );
1018         ReferenceList refListWorkGroups;
1019         ReferenceList refMailingList;
1020 
1021         refListWorkGroups = AdminWorkgroupService.getUserWorkgroups( adminUser, locale );
1022 
1023         refMailingList = new ReferenceList( );
1024 
1025         String strNothing = I18nService.getLocalizedString( PROPERTY_NOTHING, locale );
1026         refMailingList.addItem( -1, strNothing );
1027         refMailingList.addAll( AdminMailingListService.getMailingLists( adminUser ) );
1028 
1029         DirectoryXslFilter directoryXslFilter = new DirectoryXslFilter( );
1030 
1031         directoryXslFilter.setIdCategory( Category.ID_CATEGORY_STYLE_FORM_SEARCH );
1032 
1033         ReferenceList refListStyleFormSearch = DirectoryXslHome.getRefList( directoryXslFilter, getPlugin( ) );
1034 
1035         directoryXslFilter.setIdCategory( Category.ID_CATEGORY_STYLE_RESULT_LIST );
1036 
1037         ReferenceList refListStyleResultList = DirectoryXslHome.getRefList( directoryXslFilter, getPlugin( ) );
1038 
1039         directoryXslFilter.setIdCategory( Category.ID_CATEGORY_STYLE_RESULT_RECORD );
1040 
1041         ReferenceList refListStyleResultRecord = DirectoryXslHome.getRefList( directoryXslFilter, getPlugin( ) );
1042 
1043         Map<String, Object> model = new HashMap<String, Object>( );
1044         model.put( MARK_PAGINATOR, paginator );
1045         model.put( MARK_NB_ITEMS_PER_PAGE, DirectoryUtils.EMPTY_STRING + _searchFields.getItemsPerPageEntry( ) );
1046         model.put( MARK_USER_WORKGROUP_REF_LIST, refListWorkGroups );
1047 
1048         if ( SecurityService.isAuthenticationEnable( ) )
1049         {
1050             model.put( MARK_ROLE_REF_LIST, RoleHome.getRolesList( ) );
1051         }
1052 
1053         if ( WorkflowService.getInstance( ).isAvailable( ) )
1054         {
1055             ReferenceList referenceList = WorkflowService.getInstance( ).getWorkflowsEnabled( adminUser, locale );
1056             model.put( MARK_WORKFLOW_REF_LIST, referenceList );
1057             model.put( MARK_WORKFLOW_SELECTED, directory.getIdWorkflow( ) );
1058 
1059             ReferenceList refListWorkflowState = new ReferenceList( );
1060             ReferenceItem refItem = new ReferenceItem( );
1061             refItem.setCode( Integer.toString( DirectoryUtils.CONSTANT_ID_NULL ) );
1062             refItem.setName( I18nService.getLocalizedString( MESSAGE_NO_DIRECTORY_STATE, AdminUserService.getLocale( request ) ) );
1063             refListWorkflowState.add( refItem );
1064 
1065             if ( directory.getIdWorkflow( ) > DirectoryUtils.CONSTANT_ID_NULL )
1066             {
1067                 Collection<State> listWorkflowState = WorkflowService.getInstance( ).getAllStateByWorkflow( directory.getIdWorkflow( ),
1068                         AdminUserService.getAdminUser( request ) );
1069 
1070                 if ( ( listWorkflowState != null ) && ( listWorkflowState.size( ) > 0 ) )
1071                 {
1072                     for ( State state : listWorkflowState )
1073                     {
1074                         refItem = new ReferenceItem( );
1075                         refItem.setCode( Integer.toString( state.getId( ) ) );
1076                         refItem.setName( state.getName( ) );
1077                         refListWorkflowState.add( refItem );
1078                     }
1079                 }
1080             }
1081 
1082             model.put( MARK_WORKFLOW_STATE_REF_LIST, refListWorkflowState );
1083 
1084             if ( !referenceList.isEmpty( ) )
1085             {
1086                 model.put( MARK_WORKFLOW_STATE_SEARCH, true );
1087 
1088                 /*
1089                  * ReferenceList referenceList=new ReferenceList(); referenceList.addItem(1, strName)
1090                  */
1091                 if ( directory.isDisplaySearchState( ) )
1092                 {
1093                     model.put( MARK_WORKFLOW_STATE_SEARCH_SELECTED, IS_DISPLAY_STATE_SEARCH );
1094                 }
1095                 else
1096                     if ( directory.isDisplayComplementarySearchState( ) )
1097                     {
1098                         model.put( MARK_WORKFLOW_STATE_SEARCH_SELECTED, IS_DISPLAY_STATE_SEARCH_COMPLEMENTARY );
1099                     }
1100                     else
1101                     {
1102                         model.put( MARK_WORKFLOW_STATE_SEARCH_SELECTED, IS_NOT_DISPLAY_STATE_SEARCH );
1103                     }
1104             }
1105         }
1106 
1107         model.put( MARK_FORM_SEARCH_TEMPLATE_LIST, refListStyleFormSearch );
1108         model.put( MARK_RESULT_LIST_TEMPLATE_LIST, refListStyleResultList );
1109         model.put( MARK_RESULT_RECORD_TEMPLATE_LIST, refListStyleResultRecord );
1110         model.put( MARK_ENTRY_TYPE_LIST, EntryTypeHome.getList( getPlugin( ) ) );
1111         model.put( MARK_DIRECTORY, directory );
1112         model.put( MARK_ENTRY_LIST, paginator.getPageItems( ) );
1113         model.put( MARK_ENTRY_GROUP_LIST, entryGroupReferenceList );
1114         model.put( MARK_NUMBER_FIELD, nNumberField );
1115         model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
1116         model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage( ) );
1117         model.put( MARK_IS_ACTIVE_MYLUTECE_AUTHENTIFICATION, PluginService.isPluginEnable( MYLUTECE_PLUGIN ) );
1118         model.put( MARK_IS_USER_ATTRIBUTES_SERVICE_ENABLE, DirectoryUserAttributesManager.getManager( ).isEnabled( ) );
1119         model.put( MARK_ID_ENTRY_TYPE_MYLUTECE_USER, AppPropertiesService.getPropertyInt( PROPERTY_ENTRY_TYPE_MYLUTECE_USER, 19 ) );
1120         model.put( MARK_ID_ENTRY_TYPE_REMOTE_MYLUTECE_USER, AppPropertiesService.getPropertyInt( PROPERTY_ENTRY_TYPE_REMOTE_MYLUTECE_USER, 21 ) );
1121         setPageTitleProperty( PROPERTY_MODIFY_DIRECTORY_TITLE );
1122         model.put( MARK_MAP_CHILD, mapIdParentOrdersChildren );
1123 
1124         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_DIRECTORY, locale, model );
1125 
1126         return getAdminPage( template.getHtml( ) );
1127     }
1128 
1129     /**
1130      * Perform the directory modification
1131      * 
1132      * @param request
1133      *            The HTTP request
1134      * @throws AccessDeniedException
1135      *             the {@link AccessDeniedException}
1136      * @return The URL to go after performing the action
1137      */
1138     public String doModifyDirectory( HttpServletRequest request ) throws AccessDeniedException
1139     {
1140         if ( request.getParameter( PARAMETER_CANCEL ) == null )
1141         {
1142             String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
1143             int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
1144             Directory directory;
1145 
1146             if ( nIdDirectory != -1 )
1147             {
1148                 directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
1149 
1150                 if ( ( directory == null )
1151                         || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_MODIFY, getUser( ) )
1152                         || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
1153                 {
1154                     throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
1155                 }
1156 
1157                 int nOldIdWorkflow = directory.getIdWorkflow( );
1158                 String strError = getDirectoryData( request, directory, getLocale( ) );
1159 
1160                 if ( strError != null )
1161                 {
1162                     return strError;
1163                 }
1164 
1165                 // If the directory has changed, then we reset the workflow state to remove records
1166                 if ( nOldIdWorkflow != directory.getIdWorkflow( ) )
1167                 {
1168                     directory.setIdWorkflowStateToRemove( DirectoryUtils.CONSTANT_ID_NULL );
1169                 }
1170 
1171                 directory.setIdDirectory( nIdDirectory );
1172                 DirectoryHome.update( directory, getPlugin( ) );
1173 
1174                 if ( request.getParameter( PARAMETER_APPLY ) != null )
1175                 {
1176                     return getJspModifyDirectory( request, nIdDirectory );
1177                 }
1178             }
1179         }
1180 
1181         return getJspManageDirectory( request );
1182     }
1183 
1184     /**
1185      * Change the attribute's order (move up or move down in the list)
1186      * 
1187      * @param request
1188      *            the request
1189      * @return The URL of the form management page
1190      */
1191     public String doChangeOrderEntry( HttpServletRequest request )
1192     {
1193         // gets the entry which needs to be changed (order)
1194         Plugin plugin = getPlugin( );
1195 
1196         String strEntryId = StringUtils.EMPTY;
1197         String strOrderToSet = StringUtils.EMPTY;
1198         Integer nEntryId = 0;
1199         Integer nOrderToSet = 0;
1200         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
1201         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
1202         IEntry entry;
1203 
1204         // To execute mass action "Move into"
1205         if ( ( request.getParameter( PARAMETER_MOVE_BUTTON + ".x" ) != null ) || ( request.getParameter( PARAMETER_MOVE_BUTTON ) != null ) )
1206         {
1207             String strIdNewParent = request.getParameter( PARAMETER_ID_ENTRY_GROUP );
1208             Integer nIdNewParent = 0;
1209 
1210             if ( StringUtils.isNotBlank( strIdNewParent ) )
1211             {
1212                 nIdNewParent = DirectoryUtils.convertStringToInt( strIdNewParent );
1213             }
1214 
1215             // gets the entries which needs to be changed
1216             String [ ] entryToMoveList = request.getParameterValues( PARAMETER_ID_ENTRY );
1217 
1218             IEntry entryParent = EntryHome.findByPrimaryKey( nIdNewParent, plugin );
1219             List<IEntry> listEntry = new ArrayList<IEntry>( );
1220 
1221             if ( entryParent == null )
1222             {
1223                 EntryFilter filter = new EntryFilter( );
1224                 filter.setIdDirectory( nIdDirectory );
1225                 listEntry = EntryHome.getEntryList( filter, plugin );
1226             }
1227 
1228             Integer nListEntrySize = listEntry.size( );
1229 
1230             if ( entryToMoveList != null )
1231             {
1232                 // for each entry, move it into selected group
1233                 for ( String strIdEntryToMove : entryToMoveList )
1234                 {
1235                     IEntry entryToMove = EntryHome.findByPrimaryKey( DirectoryUtils.convertStringToInt( strIdEntryToMove ), plugin );
1236                     entryParent = EntryHome.findByPrimaryKey( nIdNewParent, plugin );
1237 
1238                     if ( ( entryToMove == null ) )
1239                     {
1240                         return AdminMessageService.getMessageUrl( request, MESSAGE_SELECT_GROUP, AdminMessage.TYPE_STOP );
1241                     }
1242 
1243                     // if entryParent is null, move out selected entries
1244                     if ( ( entryParent == null ) && ( entryToMove.getParent( ) != null ) )
1245                     {
1246                         doMoveOutEntry( plugin, nIdDirectory, nListEntrySize, entryToMove );
1247                     }
1248 
1249                     // Move entry into group if not allready in
1250                     else
1251                         if ( ( entryParent != null )
1252                                 && ( ( entryToMove.getParent( ) == null ) || ( ( entryToMove.getParent( ) != null ) && ( entryToMove.getParent( ).getIdEntry( ) != entryParent
1253                                         .getIdEntry( ) ) ) ) )
1254                         {
1255                             this.doMoveEntryIntoGroup( plugin, entryToMove, entryParent );
1256                         }
1257                 }
1258             }
1259         }
1260 
1261         // To change order of one entry
1262         else
1263         {
1264             EntryFilter filter = new EntryFilter( );
1265             filter.setIdDirectory( nIdDirectory );
1266 
1267             List<IEntry> entryList = EntryHome.getEntryList( filter, getPlugin( ) );
1268 
1269             for ( int i = 0; i < entryList.size( ); i++ )
1270             {
1271                 entry = entryList.get( i );
1272                 nEntryId = entry.getIdEntry( );
1273                 strEntryId = request.getParameter( PARAMETER_MOVE_BUTTON + "_" + nEntryId.toString( ) );
1274 
1275                 if ( StringUtils.isNotBlank( strEntryId ) )
1276                 {
1277                     strEntryId = nEntryId.toString( );
1278                     strOrderToSet = request.getParameter( PARAMETER_ORDER_ID + "_" + nEntryId.toString( ) );
1279                     i = entryList.size( );
1280                 }
1281             }
1282 
1283             if ( StringUtils.isNotBlank( strEntryId ) )
1284             {
1285                 nEntryId = DirectoryUtils.convertStringToInt( strEntryId );
1286             }
1287 
1288             if ( StringUtils.isNotBlank( strOrderToSet ) )
1289             {
1290                 nOrderToSet = DirectoryUtils.convertStringToInt( strOrderToSet );
1291             }
1292 
1293             IEntry entryToChangeOrder = EntryHome.findByPrimaryKey( nEntryId, plugin );
1294             int nActualOrder = entryToChangeOrder.getPosition( );
1295 
1296             // does nothing if the order to set is equal to the actual order
1297             if ( nOrderToSet != nActualOrder )
1298             {
1299                 // entry goes up in the list
1300                 if ( nOrderToSet < entryToChangeOrder.getPosition( ) )
1301                 {
1302                     moveUpEntryOrder( plugin, nOrderToSet, entryToChangeOrder, entryToChangeOrder.getDirectory( ).getIdDirectory( ) );
1303                 }
1304 
1305                 // entry goes down in the list
1306                 else
1307                 {
1308                     moveDownEntryOrder( plugin, nOrderToSet, entryToChangeOrder, entryToChangeOrder.getDirectory( ).getIdDirectory( ) );
1309                 }
1310             }
1311         }
1312 
1313         UrlItem url = new UrlItem( AppPathService.getBaseUrl( request ) + JSP_MODIFY_DIRECTORY );
1314         url.addParameter( PARAMETER_ID_DIRECTORY, nIdDirectory );
1315         url.setAnchor( PARAMETER_ANCHOR_LIST );
1316 
1317         return url.getUrl( );
1318     }
1319 
1320     /**
1321      * Move out entry (no parent)
1322      * 
1323      * @param plugin
1324      *            the plugin
1325      * @param nIdDirectory
1326      *            the id directory
1327      * @param nListEntrySize
1328      *            the number of entry
1329      * @param entryToMove
1330      *            the entry to move
1331      */
1332     private void doMoveOutEntry( Plugin plugin, int nIdDirectory, Integer nListEntrySize, IEntry entryToMove )
1333     {
1334         this.moveDownEntryOrder( plugin, nListEntrySize, entryToMove, nIdDirectory );
1335         entryToMove.setParent( null );
1336         EntryHome.update( entryToMove, plugin );
1337     }
1338 
1339     /**
1340      * Gets the confirmation page of delete directory
1341      * 
1342      * @param request
1343      *            The HTTP request
1344      * @throws AccessDeniedException
1345      *             the {@link AccessDeniedException}
1346      * @return the confirmation page of delete directory
1347      */
1348     public String getConfirmRemoveDirectory( HttpServletRequest request ) throws AccessDeniedException
1349     {
1350         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
1351         String strMessage;
1352         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
1353         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
1354 
1355         if ( ( directory == null )
1356                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_DELETE, getUser( ) )
1357                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
1358         {
1359             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
1360         }
1361 
1362         RecordFieldFilter recordFieldFilter = new RecordFieldFilter( );
1363         recordFieldFilter.setIdDirectory( nIdDirectory );
1364 
1365         int nNumberRecord = _recordService.getCountRecord( recordFieldFilter, getPlugin( ) );
1366         strMessage = ( nNumberRecord == 0 ) ? MESSAGE_CONFIRM_REMOVE_DIRECTORY : MESSAGE_CONFIRM_REMOVE_DIRECTORY_WITH_RECORD;
1367 
1368         UrlItem url = new UrlItem( JSP_DO_REMOVE_DIRECTORY );
1369         url.addParameter( PARAMETER_ID_DIRECTORY, strIdDirectory );
1370 
1371         return AdminMessageService.getMessageUrl( request, strMessage, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
1372     }
1373 
1374     /**
1375      * Perform the directory suppression
1376      * 
1377      * @param request
1378      *            The HTTP request
1379      * @throws AccessDeniedException
1380      *             the {@link AccessDeniedException}
1381      * @return The URL to go after performing the action
1382      */
1383     public String doRemoveDirectory( HttpServletRequest request ) throws AccessDeniedException
1384     {
1385         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
1386         ArrayList<String> listErrors = new ArrayList<String>( );
1387 
1388         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
1389         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
1390 
1391         if ( ( directory == null )
1392                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_DELETE, getUser( ) )
1393                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
1394         {
1395             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
1396         }
1397 
1398         if ( !DirectoryRemovalListenerService.getService( ).checkForRemoval( strIdDirectory, listErrors, getLocale( ) ) )
1399         {
1400             String strCause = AdminMessageService.getFormattedList( listErrors, getLocale( ) );
1401             Object [ ] args = {
1402                 strCause
1403             };
1404 
1405             return AdminMessageService.getMessageUrl( request, MESSAGE_CANNOT_REMOVE_DIRECTORY, args, AdminMessage.TYPE_STOP );
1406         }
1407 
1408         DirectoryHome.remove( nIdDirectory, getPlugin( ) );
1409 
1410         return getJspManageDirectory( request );
1411     }
1412 
1413     /**
1414      * Gets the confirmation page of remove all Directory Record
1415      * 
1416      * @param request
1417      *            The HTTP request
1418      * @throws AccessDeniedException
1419      *             the {@link AccessDeniedException}
1420      * @return the confirmation page of delete all Directory Record
1421      */
1422     public String getConfirmRemoveAllDirectoryRecord( HttpServletRequest request ) throws AccessDeniedException
1423     {
1424         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
1425 
1426         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
1427         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
1428 
1429         if ( ( directory == null )
1430                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_DELETE_ALL_RECORD, getUser( ) )
1431                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
1432         {
1433             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
1434         }
1435 
1436         UrlItem url = new UrlItem( JSP_DO_REMOVE_ALL_DIRECTORY_RECORD );
1437         url.addParameter( PARAMETER_ID_DIRECTORY, strIdDirectory );
1438 
1439         return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_ALL_DIRECTORY_RECORD, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
1440     }
1441 
1442     /**
1443      * Remove all directory record of the directory
1444      * 
1445      * @param request
1446      *            The HTTP request
1447      * @throws AccessDeniedException
1448      *             the {@link AccessDeniedException}
1449      * @return The URL to go after performing the action
1450      */
1451     public String doRemoveAllDirectoryRecord( HttpServletRequest request ) throws AccessDeniedException
1452     {
1453         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
1454         Plugin plugin = getPlugin( );
1455         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
1456         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
1457 
1458         if ( ( directory == null )
1459                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_DELETE_ALL_RECORD, getUser( ) )
1460                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
1461         {
1462             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
1463         }
1464 
1465         RecordFieldFilter recordFilter = new RecordFieldFilter( );
1466         recordFilter.setIdDirectory( nIdDirectory );
1467 
1468         for ( Integer nRecordId : _recordService.getListRecordId( recordFilter, plugin ) )
1469         {
1470             _recordService.remove( nRecordId, plugin );
1471         }
1472 
1473         /* Depreciated, this function does not remove the associated files */
1474         /* RecordHome.removeByIdDirectory( nIdDirectory, plugin ); */
1475         return getJspManageDirectory( request );
1476     }
1477 
1478     /**
1479      * copy the directory whose key is specified in the Http request
1480      * 
1481      * @param request
1482      *            The HTTP request
1483      * @throws AccessDeniedException
1484      *             the {@link AccessDeniedException}
1485      * @return The URL to go after performing the action
1486      */
1487     public String doCopyDirectory( HttpServletRequest request ) throws AccessDeniedException
1488     {
1489         Plugin plugin = getPlugin( );
1490         Directory directory;
1491         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
1492         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
1493         directory = DirectoryHome.findByPrimaryKey( nIdDirectory, plugin );
1494 
1495         if ( ( directory == null )
1496                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_COPY, getUser( ) )
1497                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
1498         {
1499             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
1500         }
1501 
1502         Object [ ] tabFormTitleCopy = {
1503             directory.getTitle( )
1504         };
1505         String strTitleCopyForm = I18nService.getLocalizedString( PROPERTY_COPY_DIRECTORY_TITLE, tabFormTitleCopy, getLocale( ) );
1506 
1507         if ( strTitleCopyForm != null )
1508         {
1509             directory.setTitle( strTitleCopyForm );
1510         }
1511 
1512         DirectoryHome.copy( directory, plugin );
1513 
1514         return getJspManageDirectory( request );
1515     }
1516 
1517     /**
1518      * Gets the entry creation page
1519      * 
1520      * @param request
1521      *            The HTTP request
1522      * @throws AccessDeniedException
1523      *             the {@link AccessDeniedException}
1524      * @return The entry creation page
1525      */
1526     public String getCreateEntry( HttpServletRequest request ) throws AccessDeniedException
1527     {
1528         Plugin plugin = getPlugin( );
1529         IEntry entry;
1530         entry = DirectoryUtils.createEntryByType( request, plugin );
1531 
1532         boolean bAssociationEntryWorkgroup;
1533         boolean bAssociationEntryRole;
1534 
1535         int nIdDirectory = _searchFields.getIdDirectory( );
1536         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, plugin );
1537 
1538         if ( ( entry == null )
1539                 || ( directory == null )
1540                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
1541                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
1542         {
1543             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
1544         }
1545 
1546         entry.setDirectory( directory );
1547 
1548         // test if an entry is already asoociated with a role or a workgroup
1549         EntryFilter filter = new EntryFilter( );
1550         filter.setIdDirectory( _searchFields.getIdDirectory( ) );
1551         filter.setIsRoleAssociated( EntryFilter.FILTER_TRUE );
1552         bAssociationEntryRole = ( EntryHome.getNumberEntryByFilter( filter, plugin ) != 0 );
1553         filter.setIsRoleAssociated( EntryFilter.ALL_INT );
1554         filter.setIsWorkgroupAssociated( EntryFilter.FILTER_TRUE );
1555         bAssociationEntryWorkgroup = ( EntryHome.getNumberEntryByFilter( filter, plugin ) != 0 );
1556 
1557         Map<String, Object> model = new HashMap<String, Object>( );
1558 
1559         // For Entry Type Directory
1560         String strAutorizeEntryType = AppPropertiesService.getProperty( PROPERTY_ENTRY_AUTORIZE_FOR_ENTRY_DIRECTORY );
1561         String [ ] strTabAutorizeEntryType = strAutorizeEntryType.split( "," );
1562 
1563         ReferenceList listEntryAssociateWithoutJavascript = new ReferenceList( );
1564         List<List<IEntry>> listEntryWithJavascript = new ArrayList<List<IEntry>>( );
1565 
1566         for ( ReferenceItem item : DirectoryHome.getDirectoryList( plugin ) )
1567         {
1568             List<IEntry> listEntry = new ArrayList<IEntry>( );
1569             Directory directoryTmp = DirectoryHome.findByPrimaryKey( DirectoryUtils.convertStringToInt( item.getCode( ) ), plugin );
1570             EntryFilter entryFilter = new EntryFilter( );
1571             entryFilter.setIdDirectory( directoryTmp.getIdDirectory( ) );
1572 
1573             for ( IEntry entryTmp : EntryHome.getEntryList( entryFilter, plugin ) )
1574             {
1575                 boolean bEntryAutorize = false;
1576 
1577                 for ( int i = 0; ( i < strTabAutorizeEntryType.length ) && !bEntryAutorize; i++ )
1578                 {
1579                     if ( entryTmp.getEntryType( ).getIdType( ) == DirectoryUtils.convertStringToInt( strTabAutorizeEntryType [i] ) )
1580                     {
1581                         bEntryAutorize = true;
1582                     }
1583                 }
1584 
1585                 if ( bEntryAutorize )
1586                 {
1587                     listEntryAssociateWithoutJavascript.addItem( entryTmp.getIdEntry( ), directoryTmp.getTitle( ) + " - " + entryTmp.getTitle( ) );
1588                     listEntry.add( entryTmp );
1589                 }
1590             }
1591 
1592             listEntryWithJavascript.add( listEntry );
1593         }
1594 
1595         // Default Values
1596         ReferenceList listParamDefaultValues = EntryParameterService.getService( ).findAll( );
1597 
1598         model.put( MARK_DIRECTORY_ENTRY_LIST_ASSOCIATE, listEntryAssociateWithoutJavascript );
1599         model.put( MARK_DIRECTORY_LIST_ASSOCIATE, DirectoryHome.getDirectoryList( plugin ) );
1600         model.put( MARK_ENTRY_LIST_ASSOCIATE, listEntryWithJavascript );
1601 
1602         model.put( MARK_ENTRY, entry );
1603         model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
1604         model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage( ) );
1605         model.put( MARK_IS_ASSOCIATION_ENTRY_WORKGROUP, bAssociationEntryWorkgroup );
1606         model.put( MARK_IS_ASSOCIATION_ENTRY_ROLE, bAssociationEntryRole );
1607         model.put( MARK_IS_AUTHENTIFICATION_ENABLED, SecurityService.isAuthenticationEnable( ) );
1608         model.put( MARK_LIST_PARAM_DEFAULT_VALUES, listParamDefaultValues );
1609 
1610         if ( entry.getEntryType( ).getComment( ) )
1611         {
1612             setPageTitleProperty( PROPERTY_CREATE_ENTRY_COMMENT_PAGE_TITLE );
1613         }
1614         else
1615         {
1616             setPageTitleProperty( PROPERTY_CREATE_ENTRY_FIELD_PAGE_TITLE );
1617         }
1618 
1619         HtmlTemplate template = AppTemplateService.getTemplate( entry.getTemplateCreate( ), getLocale( ), model );
1620 
1621         return getAdminPage( template.getHtml( ) );
1622     }
1623 
1624     /**
1625      * Perform the entry creation
1626      * 
1627      * @param request
1628      *            The HTTP request
1629      * @throws AccessDeniedException
1630      *             the {@link AccessDeniedException}
1631      * @return The URL to go after performing the action
1632      */
1633     public String doCreateEntry( HttpServletRequest request ) throws AccessDeniedException
1634     {
1635         IEntry entry;
1636 
1637         int nIdDirectory = _searchFields.getIdDirectory( );
1638         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
1639 
1640         if ( ( directory == null )
1641                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
1642                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
1643         {
1644             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
1645         }
1646 
1647         if ( ( request.getParameter( PARAMETER_CANCEL ) == null ) )
1648         {
1649             entry = DirectoryUtils.createEntryByType( request, getPlugin( ) );
1650 
1651             if ( entry == null )
1652             {
1653                 return getJspManageDirectory( request );
1654             }
1655 
1656             String strError = entry.getEntryData( request, getLocale( ) );
1657 
1658             if ( strError != null )
1659             {
1660                 return strError;
1661             }
1662 
1663             entry.setDirectory( directory );
1664             entry.setIdEntry( EntryHome.create( entry, getPlugin( ) ) );
1665 
1666             if ( entry.getFields( ) != null )
1667             {
1668                 for ( Field field : entry.getFields( ) )
1669                 {
1670                     field.setEntry( entry );
1671                     FieldHome.create( field, getPlugin( ) );
1672                 }
1673             }
1674 
1675             if ( request.getParameter( PARAMETER_APPLY ) != null )
1676             {
1677                 return getJspModifyEntry( request, entry.getIdEntry( ) );
1678             }
1679         }
1680 
1681         return getJspModifyDirectory( request, _searchFields.getIdDirectory( ) );
1682     }
1683 
1684     /**
1685      * Gets the entry modification page
1686      * 
1687      * @param request
1688      *            The HTTP request
1689      * @throws AccessDeniedException
1690      *             the {@link AccessDeniedException}
1691      * @return The entry modification page
1692      */
1693     public String getModifyEntry( HttpServletRequest request ) throws AccessDeniedException
1694     {
1695         boolean bAssociationEntryWorkgroup;
1696         boolean bAssociationEntryRole;
1697         Plugin plugin = getPlugin( );
1698         IEntry entry;
1699         ReferenceList refListRegularExpression;
1700         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
1701         int nIdEntry = DirectoryUtils.convertStringToInt( strIdEntry );
1702         entry = EntryHome.findByPrimaryKey( nIdEntry, plugin );
1703 
1704         int nIdDirectory = _searchFields.getIdDirectory( );
1705         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, plugin );
1706 
1707         if ( ( entry == null )
1708                 || ( directory == null )
1709                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
1710                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
1711         {
1712             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
1713         }
1714 
1715         _searchFields.setIdEntry( nIdEntry );
1716 
1717         List<Field> listField = new ArrayList<Field>( );
1718 
1719         for ( Field field : entry.getFields( ) )
1720         {
1721             field = FieldHome.findByPrimaryKey( field.getIdField( ), plugin );
1722             listField.add( field );
1723         }
1724 
1725         entry.setFields( listField );
1726 
1727         HashMap<String, Object> model = new HashMap<String, Object>( );
1728 
1729         int nIdTypeImage = DirectoryUtils.convertStringToInt( AppPropertiesService.getProperty( PROPERTY_ENTRY_TYPE_IMAGE, DEFAULT_TYPE_IMAGE ) );
1730 
1731         if ( entry.getEntryType( ).getIdType( ) == nIdTypeImage )
1732         {
1733             for ( Field field : entry.getFields( ) )
1734             {
1735                 if ( ( field.getValue( ) != null ) && ( field.getValue( ).equals( FIELD_THUMBNAIL ) ) )
1736                 {
1737                     model.put( MARK_THUMBNAIL_FIELD, field );
1738                     model.put( MARK_HAS_THUMBNAIL, true );
1739                 }
1740 
1741                 else
1742                     if ( ( field.getValue( ) != null ) && ( field.getValue( ).equals( FIELD_BIG_THUMBNAIL ) ) )
1743                     {
1744                         model.put( MARK_BIG_THUMBNAIL_FIELD, field );
1745                         model.put( MARK_HAS_BIG_THUMBNAIL, true );
1746                     }
1747 
1748                     else
1749                         if ( ( field.getValue( ) != null ) && ( field.getValue( ).equals( FIELD_IMAGE ) ) )
1750                         {
1751                             model.put( MARK_IMAGE_FIELD, field );
1752                         }
1753             }
1754         }
1755 
1756         model.put( MARK_ENTRY, entry );
1757         _searchFields.setCurrentPageIndex( Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _searchFields.getCurrentPageIndex( ) ) );
1758         _searchFields.setItemsPerPage( Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, _searchFields.getItemsPerPage( ),
1759                 _searchFields.getDefaultItemsPerPage( ) ) );
1760 
1761         LocalizedPaginator paginator = entry.getPaginator( _searchFields.getItemsPerPage( ), AppPathService.getBaseUrl( request ) + JSP_MODIFY_ENTRY
1762                 + "?id_entry=" + nIdEntry, PARAMETER_PAGE_INDEX, _searchFields.getCurrentPageIndex( ), getLocale( ) );
1763 
1764         if ( paginator != null )
1765         {
1766             model.put( MARK_NB_ITEMS_PER_PAGE, DirectoryUtils.EMPTY_STRING + _searchFields.getItemsPerPage( ) );
1767             model.put( MARK_NUMBER_ITEMS, paginator.getItemsCount( ) );
1768             model.put( MARK_LIST, paginator.getPageItems( ) );
1769             model.put( MARK_PAGINATOR, paginator );
1770         }
1771 
1772         refListRegularExpression = entry.getReferenceListRegularExpression( entry, plugin );
1773 
1774         if ( refListRegularExpression != null )
1775         {
1776             model.put( MARK_REGULAR_EXPRESSION_LIST_REF_LIST, refListRegularExpression );
1777         }
1778 
1779         model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
1780         model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage( ) );
1781 
1782         if ( entry.getEntryType( ).getComment( ) )
1783         {
1784             setPageTitleProperty( PROPERTY_MODIFY_ENTRY_COMMENT_PAGE_TITLE );
1785         }
1786         else
1787             if ( entry.getEntryType( ).getGroup( ) )
1788             {
1789                 setPageTitleProperty( PROPERTY_MODIFY_ENTRY_GROUP_PAGE_TITLE );
1790             }
1791             else
1792             {
1793                 setPageTitleProperty( PROPERTY_MODIFY_ENTRY_FIELD_PAGE_TITLE );
1794             }
1795 
1796         // test if an entry is already asoociated with a role or a workgroup
1797         EntryFilter filter = new EntryFilter( );
1798         filter.setIdDirectory( _searchFields.getIdDirectory( ) );
1799         filter.setIsRoleAssociated( EntryFilter.FILTER_TRUE );
1800         bAssociationEntryRole = ( EntryHome.getNumberEntryByFilter( filter, plugin ) != 0 );
1801         filter.setIsRoleAssociated( EntryFilter.ALL_INT );
1802         filter.setIsWorkgroupAssociated( EntryFilter.FILTER_TRUE );
1803         bAssociationEntryWorkgroup = ( EntryHome.getNumberEntryByFilter( filter, plugin ) != 0 );
1804 
1805         // For Entry Type Directory
1806         String strAutorizeEntryType = AppPropertiesService.getProperty( PROPERTY_ENTRY_AUTORIZE_FOR_ENTRY_DIRECTORY );
1807         String [ ] strTabAutorizeEntryType = strAutorizeEntryType.split( "," );
1808 
1809         ReferenceList listEntryAssociateWithoutJavascript = new ReferenceList( );
1810         List<List<IEntry>> listEntryWithJavascript = new ArrayList<List<IEntry>>( );
1811 
1812         for ( ReferenceItem item : DirectoryHome.getDirectoryList( plugin ) )
1813         {
1814             List<IEntry> listEntry = new ArrayList<IEntry>( );
1815             Directory directoryTmp = DirectoryHome.findByPrimaryKey( DirectoryUtils.convertStringToInt( item.getCode( ) ), plugin );
1816             EntryFilter entryFilter = new EntryFilter( );
1817             entryFilter.setIdDirectory( directoryTmp.getIdDirectory( ) );
1818 
1819             for ( IEntry entryTmp : EntryHome.getEntryList( entryFilter, plugin ) )
1820             {
1821                 boolean bEntryAutorize = false;
1822 
1823                 for ( int i = 0; ( i < strTabAutorizeEntryType.length ) && !bEntryAutorize; i++ )
1824                 {
1825                     if ( entryTmp.getEntryType( ).getIdType( ) == DirectoryUtils.convertStringToInt( strTabAutorizeEntryType [i] ) )
1826                     {
1827                         bEntryAutorize = true;
1828                     }
1829                 }
1830 
1831                 if ( bEntryAutorize )
1832                 {
1833                     listEntryAssociateWithoutJavascript.addItem( entryTmp.getIdEntry( ), directoryTmp.getTitle( ) + " - " + entryTmp.getTitle( ) );
1834                     listEntry.add( entryTmp );
1835                 }
1836             }
1837 
1838             listEntryWithJavascript.add( listEntry );
1839         }
1840 
1841         model.put( MARK_DIRECTORY_ENTRY_LIST_ASSOCIATE, listEntryAssociateWithoutJavascript );
1842         model.put( MARK_DIRECTORY_LIST_ASSOCIATE, DirectoryHome.getDirectoryList( plugin ) );
1843 
1844         if ( ( entry.getEntryAssociate( ) != DirectoryUtils.CONSTANT_ID_NULL ) && ( EntryHome.findByPrimaryKey( entry.getEntryAssociate( ), plugin ) != null ) )
1845         {
1846             model.put( MARK_DIRECTORY_ASSOCIATE, EntryHome.findByPrimaryKey( entry.getEntryAssociate( ), plugin ).getDirectory( ).getIdDirectory( ) );
1847         }
1848 
1849         model.put( MARK_ENTRY_LIST_ASSOCIATE, listEntryWithJavascript );
1850         model.put( MARK_IS_ASSOCIATION_ENTRY_WORKGROUP, bAssociationEntryWorkgroup );
1851         model.put( MARK_IS_ASSOCIATION_ENTRY_ROLE, bAssociationEntryRole );
1852         model.put( MARK_IS_AUTHENTIFICATION_ENABLED, SecurityService.isAuthenticationEnable( ) );
1853         model.put( MARK_ID_DIRECTORY, _searchFields.getIdDirectory( ) );
1854 
1855         HtmlTemplate template = AppTemplateService.getTemplate( entry.getTemplateModify( ), getLocale( ), model );
1856 
1857         return getAdminPage( template.getHtml( ) );
1858     }
1859 
1860     /**
1861      * Perform the entry modification
1862      * 
1863      * @param request
1864      *            The HTTP request
1865      * @throws AccessDeniedException
1866      *             the {@link AccessDeniedException}
1867      * @return The URL to go after performing the action
1868      */
1869     public String doModifyEntry( HttpServletRequest request ) throws AccessDeniedException
1870     {
1871         Plugin plugin = getPlugin( );
1872         IEntry entry;
1873         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
1874         int nIdEntry = DirectoryUtils.convertStringToInt( strIdEntry );
1875 
1876         int nIdDirectory = _searchFields.getIdDirectory( );
1877         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, plugin );
1878 
1879         if ( ( nIdEntry == -1 )
1880                 || ( directory == null )
1881                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
1882                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
1883         {
1884             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
1885         }
1886 
1887         entry = EntryHome.findByPrimaryKey( nIdEntry, plugin );
1888 
1889         if ( request.getParameter( PARAMETER_CANCEL ) == null )
1890         {
1891             String strError = entry.getEntryData( request, getLocale( ) );
1892 
1893             if ( strError != null )
1894             {
1895                 return strError;
1896             }
1897 
1898             EntryHome.update( entry, plugin );
1899 
1900             if ( entry.getFields( ) != null )
1901             {
1902                 for ( Field field : entry.getFields( ) )
1903                 {
1904                     // Check if the field already exists in the database
1905                     Field fieldStored = FieldHome.findByPrimaryKey( field.getIdField( ), plugin );
1906 
1907                     if ( fieldStored != null )
1908                     {
1909                         // If it exists, update
1910                         FieldHome.update( field, plugin );
1911                     }
1912                     else
1913                     {
1914                         // If it does not exist, create
1915                         FieldHome.create( field, plugin );
1916                     }
1917                 }
1918             }
1919         }
1920 
1921         if ( request.getParameter( PARAMETER_APPLY ) == null )
1922         {
1923             return getJspModifyDirectory( request, _searchFields.getIdDirectory( ) );
1924         }
1925 
1926         return getJspModifyEntry( request, nIdEntry );
1927     }
1928 
1929     /**
1930      * Gets the confirmation page of delete entry
1931      * 
1932      * @param request
1933      *            The HTTP request
1934      * @throws AccessDeniedException
1935      *             the {@link AccessDeniedException}
1936      * @return the confirmation page of delete entry
1937      */
1938     public String getConfirmRemoveEntry( HttpServletRequest request ) throws AccessDeniedException
1939     {
1940         IEntry entry;
1941         Plugin plugin = getPlugin( );
1942         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
1943         String strMessage;
1944         int nIdEntry = DirectoryUtils.convertStringToInt( strIdEntry );
1945 
1946         int nIdDirectory = _searchFields.getIdDirectory( );
1947         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, plugin );
1948 
1949         if ( ( nIdEntry == -1 )
1950                 || ( directory == null )
1951                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
1952                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
1953         {
1954             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
1955         }
1956 
1957         entry = EntryHome.findByPrimaryKey( nIdEntry, plugin );
1958 
1959         if ( entry.getEntryType( ).getGroup( ) )
1960         {
1961             strMessage = ( !entry.getChildren( ).isEmpty( ) ) ? MESSAGE_CONFIRM_REMOVE_GROUP_WITH_ENTRY : MESSAGE_CONFIRM_REMOVE_GROUP_WITH_ANY_ENTRY;
1962         }
1963         else
1964         {
1965             strMessage = MESSAGE_CONFIRM_REMOVE_ENTRY;
1966         }
1967 
1968         UrlItem url = new UrlItem( JSP_DO_REMOVE_ENTRY );
1969         url.addParameter( PARAMETER_ID_ENTRY, strIdEntry + "#list" );
1970 
1971         return AdminMessageService.getMessageUrl( request, strMessage, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
1972     }
1973 
1974     /**
1975      * Perform the entry supression
1976      * 
1977      * @param request
1978      *            The HTTP request
1979      * @throws AccessDeniedException
1980      *             the {@link AccessDeniedException}
1981      * @return The URL to go after performing the action
1982      */
1983     public String doRemoveEntry( HttpServletRequest request ) throws AccessDeniedException
1984     {
1985         Plugin plugin = getPlugin( );
1986         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
1987         ArrayList<String> listErrors = new ArrayList<String>( );
1988 
1989         int nIdEntry = DirectoryUtils.convertStringToInt( strIdEntry );
1990         IEntry entry = EntryHome.findByPrimaryKey( nIdEntry, getPlugin( ) );
1991 
1992         int nIdDirectory = _searchFields.getIdDirectory( );
1993         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, plugin );
1994 
1995         if ( ( entry == null )
1996                 || ( directory == null )
1997                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
1998                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
1999         {
2000             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2001         }
2002 
2003         RecordFieldFilter recordFieldFilter = new RecordFieldFilter( );
2004         recordFieldFilter.setIdDirectory( _searchFields.getIdDirectory( ) );
2005 
2006         if ( !EntryRemovalListenerService.getService( ).checkForRemoval( strIdEntry, listErrors, getLocale( ) ) )
2007         {
2008             String strCause = AdminMessageService.getFormattedList( listErrors, getLocale( ) );
2009             Object [ ] args = {
2010                 strCause
2011             };
2012 
2013             return AdminMessageService.getMessageUrl( request, MESSAGE_CANNOT_REMOVE_ENTRY, args, AdminMessage.TYPE_STOP );
2014         }
2015 
2016         // remove all recordField associated
2017         RecordFieldFilter filterField = new RecordFieldFilter( );
2018         filterField.setIdEntry( nIdEntry );
2019         RecordFieldHome.removeByFilter( filterField, true, plugin );
2020 
2021         // remove entry
2022         List<IEntry> listEntry;
2023         EntryFilter filter = new EntryFilter( );
2024         filter.setIdDirectory( entry.getDirectory( ).getIdDirectory( ) );
2025         listEntry = EntryHome.getEntryList( filter, plugin );
2026         this.moveDownEntryOrder( plugin, listEntry.size( ), entry, entry.getDirectory( ).getIdDirectory( ) );
2027         EntryHome.remove( nIdEntry, plugin );
2028 
2029         return getJspModifyDirectory( request, _searchFields.getIdDirectory( ) );
2030     }
2031 
2032     /**
2033      * copy the entry whose key is specified in the Http request
2034      * 
2035      * @param request
2036      *            The HTTP request
2037      * @throws AccessDeniedException
2038      *             the {@link AccessDeniedException}
2039      * @return The URL to go after performing the action
2040      */
2041     public String doCopyEntry( HttpServletRequest request ) throws AccessDeniedException
2042     {
2043         Plugin plugin = getPlugin( );
2044         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
2045         IEntry entry;
2046         int nIdEntry = DirectoryUtils.convertStringToInt( strIdEntry );
2047         entry = EntryHome.findByPrimaryKey( nIdEntry, plugin );
2048 
2049         int nIdDirectory = _searchFields.getIdDirectory( );
2050         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, plugin );
2051 
2052         if ( ( entry == null )
2053                 || ( directory == null )
2054                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
2055                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2056         {
2057             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2058         }
2059 
2060         RecordFieldFilter recordFieldFilter = new RecordFieldFilter( );
2061         recordFieldFilter.setIdDirectory( _searchFields.getIdDirectory( ) );
2062 
2063         Object [ ] tabEntryTitleCopy = {
2064             entry.getTitle( )
2065         };
2066         String strTitleCopyEntry = I18nService.getLocalizedString( PROPERTY_COPY_ENTRY_TITLE, tabEntryTitleCopy, getLocale( ) );
2067 
2068         if ( strTitleCopyEntry != null )
2069         {
2070             entry.setTitle( strTitleCopyEntry );
2071         }
2072 
2073         EntryHome.copy( entry, plugin );
2074 
2075         return getJspModifyDirectory( request, _searchFields.getIdDirectory( ) );
2076     }
2077 
2078     /**
2079      * Gets the list of questions group
2080      * 
2081      * @param request
2082      *            The HTTP request
2083      * @throws AccessDeniedException
2084      *             the {@link AccessDeniedException}
2085      * @return the list of questions group
2086      */
2087     public String getMoveEntry( HttpServletRequest request ) throws AccessDeniedException
2088     {
2089         Plugin plugin = getPlugin( );
2090         IEntry entry;
2091         List<IEntry> listGroup;
2092         EntryFilter filter;
2093         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
2094         int nIdEntry = DirectoryUtils.convertStringToInt( strIdEntry );
2095         entry = EntryHome.findByPrimaryKey( nIdEntry, plugin );
2096 
2097         int nIdDirectory = _searchFields.getIdDirectory( );
2098         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, plugin );
2099 
2100         if ( ( entry == null )
2101                 || ( directory == null )
2102                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
2103                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2104         {
2105             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2106         }
2107 
2108         _searchFields.setIdEntry( nIdEntry );
2109 
2110         // recup group
2111         filter = new EntryFilter( );
2112         filter.setIdDirectory( entry.getDirectory( ).getIdDirectory( ) );
2113         filter.setIsGroup( EntryFilter.FILTER_TRUE );
2114         listGroup = EntryHome.getEntryList( filter, plugin );
2115 
2116         Map<String, Object> model = new HashMap<String, Object>( );
2117         model.put( MARK_ENTRY, entry );
2118         model.put( MARK_ENTRY_LIST, listGroup );
2119 
2120         setPageTitleProperty( DirectoryUtils.EMPTY_STRING );
2121 
2122         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MOVE_ENTRY, getLocale( ), model );
2123 
2124         return getAdminPage( template.getHtml( ) );
2125     }
2126 
2127     /**
2128      * Move the entry in the questions group specified in parameter
2129      * 
2130      * @param request
2131      *            The HTTP request
2132      * @throws AccessDeniedException
2133      *             the {@link AccessDeniedException}
2134      * @return The URL to go after performing the action
2135      */
2136     public String doMoveEntry( HttpServletRequest request ) throws AccessDeniedException
2137     {
2138         Plugin plugin = getPlugin( );
2139         IEntry entryToMove;
2140         IEntry entryGroup;
2141         String strIdEntryGroup = request.getParameter( PARAMETER_ID_ENTRY );
2142         int nIdEntryGroup = DirectoryUtils.convertStringToInt( strIdEntryGroup );
2143 
2144         int nIdDirectory = _searchFields.getIdDirectory( );
2145         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, plugin );
2146 
2147         if ( ( directory == null )
2148                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
2149                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2150         {
2151             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2152         }
2153 
2154         entryToMove = EntryHome.findByPrimaryKey( _searchFields.getIdEntry( ), plugin );
2155         entryGroup = EntryHome.findByPrimaryKey( nIdEntryGroup, plugin );
2156 
2157         if ( ( entryToMove == null ) || ( entryGroup == null ) )
2158         {
2159             return AdminMessageService.getMessageUrl( request, MESSAGE_SELECT_GROUP, AdminMessage.TYPE_STOP );
2160         }
2161 
2162         doMoveEntryIntoGroup( plugin, entryToMove, entryGroup );
2163 
2164         return getJspModifyDirectory( request, _searchFields.getIdDirectory( ) );
2165     }
2166 
2167     /**
2168      * Move EntryToMove into entryGroup
2169      * 
2170      * @param plugin
2171      *            the plugin
2172      * @param entryToMove
2173      *            the entry to move
2174      * @param entryGroup
2175      *            the entry parent
2176      */
2177     private void doMoveEntryIntoGroup( Plugin plugin, IEntry entryToMove, IEntry entryGroup )
2178     {
2179         int nPosition;
2180 
2181         // if ( ( entryGroup.getChildren( ) != null ) && ( !entryGroup.getChildren( ).isEmpty( ) ) )
2182         // {
2183         // nPosition = entryGroup.getPosition( ) + entryGroup.getChildren( ).size( ) + 1;
2184         // }
2185         if ( entryToMove.getPosition( ) < entryGroup.getPosition( ) )
2186         {
2187             nPosition = entryGroup.getPosition( );
2188             this.moveDownEntryOrder( plugin, nPosition, entryToMove, entryToMove.getDirectory( ).getIdDirectory( ) );
2189         }
2190         else
2191         {
2192             nPosition = entryGroup.getPosition( ) + entryGroup.getChildren( ).size( ) + 1;
2193             this.moveUpEntryOrder( plugin, nPosition, entryToMove, entryToMove.getDirectory( ).getIdDirectory( ) );
2194         }
2195 
2196         entryToMove.setParent( entryGroup );
2197         EntryHome.update( entryToMove, plugin );
2198     }
2199 
2200     /**
2201      * Move up the entry
2202      * 
2203      * @param request
2204      *            The HTTP request
2205      * @throws AccessDeniedException
2206      *             the {@link AccessDeniedException}
2207      * @return The URL to go after performing the action
2208      */
2209     public String doMoveUpEntry( HttpServletRequest request ) throws AccessDeniedException
2210     {
2211         Plugin plugin = getPlugin( );
2212         IEntry entry;
2213 
2214         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
2215         int nIdEntry = DirectoryUtils.convertStringToInt( strIdEntry );
2216         entry = EntryHome.findByPrimaryKey( nIdEntry, plugin );
2217 
2218         int nIdDirectory = _searchFields.getIdDirectory( );
2219         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, plugin );
2220 
2221         if ( ( entry == null )
2222                 || ( directory == null )
2223                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
2224                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2225         {
2226             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2227         }
2228 
2229         List<IEntry> listEntry;
2230         EntryFilter filter = new EntryFilter( );
2231         filter.setIdDirectory( entry.getDirectory( ).getIdDirectory( ) );
2232 
2233         if ( entry.getParent( ) != null )
2234         {
2235             filter.setIdEntryParent( entry.getParent( ).getIdEntry( ) );
2236         }
2237         else
2238         {
2239             filter.setIsEntryParentNull( EntryFilter.FILTER_TRUE );
2240         }
2241 
2242         listEntry = EntryHome.getEntryList( filter, plugin );
2243 
2244         int nIndexEntry = DirectoryUtils.getIndexEntryInTheEntryList( nIdEntry, listEntry );
2245 
2246         if ( nIndexEntry != 0 )
2247         {
2248             int nNewPosition;
2249             IEntry entryToInversePosition;
2250             entryToInversePosition = listEntry.get( nIndexEntry - 1 );
2251             entryToInversePosition = EntryHome.findByPrimaryKey( entryToInversePosition.getIdEntry( ), plugin );
2252 
2253             nNewPosition = entryToInversePosition.getPosition( );
2254             entryToInversePosition.setPosition( entry.getPosition( ) );
2255             entry.setPosition( nNewPosition );
2256             EntryHome.update( entry, plugin );
2257             EntryHome.update( entryToInversePosition, plugin );
2258         }
2259 
2260         return getJspModifyDirectory( request, _searchFields.getIdDirectory( ) );
2261     }
2262 
2263     /**
2264      * Move down the entry
2265      * 
2266      * @param request
2267      *            The HTTP request
2268      * @throws AccessDeniedException
2269      *             the {@link AccessDeniedException}
2270      * @return The URL to go after performing the action
2271      */
2272     public String doMoveDownEntry( HttpServletRequest request ) throws AccessDeniedException
2273     {
2274         Plugin plugin = getPlugin( );
2275         IEntry entry;
2276 
2277         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
2278         int nIdEntry = DirectoryUtils.convertStringToInt( strIdEntry );
2279         entry = EntryHome.findByPrimaryKey( nIdEntry, plugin );
2280 
2281         int nIdDirectory = _searchFields.getIdDirectory( );
2282         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, plugin );
2283 
2284         if ( ( entry == null )
2285                 || ( directory == null )
2286                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
2287                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2288         {
2289             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2290         }
2291 
2292         List<IEntry> listEntry;
2293         EntryFilter filter = new EntryFilter( );
2294         filter.setIdDirectory( entry.getDirectory( ).getIdDirectory( ) );
2295 
2296         if ( entry.getParent( ) != null )
2297         {
2298             filter.setIdEntryParent( entry.getParent( ).getIdEntry( ) );
2299         }
2300         else
2301         {
2302             filter.setIsEntryParentNull( EntryFilter.FILTER_TRUE );
2303         }
2304 
2305         listEntry = EntryHome.getEntryList( filter, plugin );
2306 
2307         int nIndexEntry = DirectoryUtils.getIndexEntryInTheEntryList( nIdEntry, listEntry );
2308 
2309         if ( nIndexEntry != ( listEntry.size( ) - 1 ) )
2310         {
2311             int nNewPosition;
2312             IEntry entryToInversePosition;
2313             entryToInversePosition = listEntry.get( nIndexEntry + 1 );
2314             entryToInversePosition = EntryHome.findByPrimaryKey( entryToInversePosition.getIdEntry( ), plugin );
2315 
2316             nNewPosition = entryToInversePosition.getPosition( );
2317             entryToInversePosition.setPosition( entry.getPosition( ) );
2318             entry.setPosition( nNewPosition );
2319             EntryHome.update( entry, plugin );
2320             EntryHome.update( entryToInversePosition, plugin );
2321         }
2322 
2323         return getJspModifyDirectory( request, _searchFields.getIdDirectory( ) );
2324     }
2325 
2326     /**
2327      * Move out the entry
2328      * 
2329      * @param request
2330      *            The HTTP request
2331      * @throws AccessDeniedException
2332      *             the {@link AccessDeniedException}
2333      * @return The URL to go after performing the action
2334      */
2335     public String doMoveOutEntry( HttpServletRequest request ) throws AccessDeniedException
2336     {
2337         Plugin plugin = getPlugin( );
2338         IEntry entry;
2339         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
2340         int nIdEntry = DirectoryUtils.convertStringToInt( strIdEntry );
2341         entry = EntryHome.findByPrimaryKey( nIdEntry, plugin );
2342 
2343         int nIdDirectory = _searchFields.getIdDirectory( );
2344         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, plugin );
2345 
2346         if ( ( entry == null )
2347                 || ( directory == null )
2348                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
2349                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2350         {
2351             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2352         }
2353 
2354         List<IEntry> listEntry;
2355         EntryFilter filter = new EntryFilter( );
2356         filter.setIdDirectory( entry.getDirectory( ).getIdDirectory( ) );
2357         listEntry = EntryHome.getEntryList( filter, plugin );
2358 
2359         Integer nListEntrySize = listEntry.size( );
2360 
2361         this.doMoveOutEntry( plugin, entry.getDirectory( ).getIdDirectory( ), nListEntrySize, entry );
2362 
2363         return getJspModifyDirectory( request, _searchFields.getIdDirectory( ) );
2364     }
2365 
2366     /**
2367      * Gets the confirmation page of disable directory
2368      * 
2369      * @param request
2370      *            The HTTP request
2371      * @throws AccessDeniedException
2372      *             the {@link AccessDeniedException}
2373      * @return the confirmation page of disable directory
2374      */
2375     public String getConfirmDisableDirectory( HttpServletRequest request ) throws AccessDeniedException
2376     {
2377         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
2378         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
2379         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
2380 
2381         String strMessage;
2382 
2383         if ( ( directory == null )
2384                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_CHANGE_STATE, getUser( ) )
2385                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2386         {
2387             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2388         }
2389 
2390         strMessage = MESSAGE_CONFIRM_DISABLE_DIRECTORY;
2391 
2392         UrlItem url = new UrlItem( JSP_DO_DISABLE_DIRECTORY );
2393         url.addParameter( PARAMETER_ID_DIRECTORY, strIdDirectory );
2394 
2395         return AdminMessageService.getMessageUrl( request, strMessage, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
2396     }
2397 
2398     /**
2399      * Perform disable directory
2400      * 
2401      * @param request
2402      *            The HTTP request
2403      * @throws AccessDeniedException
2404      *             the {@link AccessDeniedException}
2405      * @return The URL to go after performing the action
2406      */
2407     public String doDisableDirectory( HttpServletRequest request ) throws AccessDeniedException
2408     {
2409         Directory directory;
2410         Plugin plugin = getPlugin( );
2411         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
2412         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
2413         directory = DirectoryHome.findByPrimaryKey( nIdDirectory, plugin );
2414 
2415         if ( ( directory == null )
2416                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_CHANGE_STATE, getUser( ) )
2417                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2418         {
2419             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2420         }
2421 
2422         directory.setEnabled( false );
2423         DirectoryHome.update( directory, getPlugin( ) );
2424 
2425         return getJspManageDirectory( request );
2426     }
2427 
2428     /**
2429      * Perform enable directory
2430      * 
2431      * @param request
2432      *            The HTTP request
2433      * @throws AccessDeniedException
2434      *             the {@link AccessDeniedException}
2435      * @return The URL to go after performing the action
2436      */
2437     public String doEnableDirectory( HttpServletRequest request ) throws AccessDeniedException
2438     {
2439         Directory directory;
2440         Plugin plugin = getPlugin( );
2441         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
2442         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
2443         directory = DirectoryHome.findByPrimaryKey( nIdDirectory, plugin );
2444 
2445         if ( ( directory == null )
2446                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_CHANGE_STATE, getUser( ) )
2447                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2448         {
2449             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2450         }
2451 
2452         directory.setEnabled( true );
2453         DirectoryHome.update( directory, getPlugin( ) );
2454 
2455         return getJspManageDirectory( request );
2456     }
2457 
2458     /**
2459      * Gets the field creation page
2460      * 
2461      * @param request
2462      *            The HTTP request
2463      * @throws AccessDeniedException
2464      *             the {@link AccessDeniedException}
2465      * @return the field creation page
2466      */
2467     public String getCreateField( HttpServletRequest request ) throws AccessDeniedException
2468     {
2469         Field field = new Field( );
2470         IEntry entry = EntryHome.findByPrimaryKey( _searchFields.getIdEntry( ), getPlugin( ) );
2471 
2472         int nIdDirectory = _searchFields.getIdDirectory( );
2473         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
2474 
2475         if ( ( entry == null )
2476                 || ( directory == null )
2477                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
2478                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2479         {
2480             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2481         }
2482 
2483         field.setEntry( entry );
2484 
2485         Map<String, Object> model = new HashMap<String, Object>( );
2486         Locale locale = getLocale( );
2487         model.put( MARK_FIELD, field );
2488         model.put( MARK_USER_WORKGROUP_REF_LIST, AdminWorkgroupService.getUserWorkgroups( getUser( ), locale ) );
2489 
2490         if ( SecurityService.isAuthenticationEnable( ) )
2491         {
2492             model.put( MARK_ROLE_REF_LIST, RoleHome.getRolesList( ) );
2493         }
2494 
2495         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_FIELD, locale, model );
2496         setPageTitleProperty( PROPERTY_CREATE_FIELD_PAGE_TITLE );
2497 
2498         return getAdminPage( template.getHtml( ) );
2499     }
2500 
2501     /**
2502      * Gets the field modification page
2503      * 
2504      * @param request
2505      *            The HTTP request
2506      * @param bWithConditionalQuestion
2507      *            true if the field is associate to conditionals questions
2508      * @throws AccessDeniedException
2509      *             the {@link AccessDeniedException}
2510      * @return the field modification page
2511      */
2512     public String getModifyField( HttpServletRequest request, boolean bWithConditionalQuestion ) throws AccessDeniedException
2513     {
2514         Field field = null;
2515         IEntry entry = null;
2516         Plugin plugin = getPlugin( );
2517         String strIdField = request.getParameter( PARAMETER_ID_FIELD );
2518         int nIdField = DirectoryUtils.convertStringToInt( strIdField );
2519         field = FieldHome.findByPrimaryKey( nIdField, getPlugin( ) );
2520 
2521         int nIdDirectory = _searchFields.getIdDirectory( );
2522         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, plugin );
2523 
2524         if ( ( field == null )
2525                 || ( directory == null )
2526                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
2527                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2528         {
2529             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2530         }
2531 
2532         entry = EntryHome.findByPrimaryKey( field.getEntry( ).getIdEntry( ), plugin );
2533 
2534         field.setEntry( entry );
2535 
2536         Map<String, Object> model = new HashMap<String, Object>( );
2537         Locale locale = getLocale( );
2538         model.put( MARK_FIELD, field );
2539         model.put( MARK_USER_WORKGROUP_REF_LIST, AdminWorkgroupService.getUserWorkgroups( getUser( ), locale ) );
2540 
2541         if ( SecurityService.isAuthenticationEnable( ) )
2542         {
2543             model.put( MARK_ROLE_REF_LIST, RoleHome.getRolesList( ) );
2544         }
2545 
2546         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_FIELD, locale, model );
2547         setPageTitleProperty( PROPERTY_MODIFY_FIELD_PAGE_TITLE );
2548 
2549         return getAdminPage( template.getHtml( ) );
2550     }
2551 
2552     /**
2553      * Perform creation field
2554      * 
2555      * @param request
2556      *            The HTTP request
2557      * @throws AccessDeniedException
2558      *             the {@link AccessDeniedException}
2559      * @return The URL to go after performing the action
2560      */
2561     public String doCreateField( HttpServletRequest request ) throws AccessDeniedException
2562     {
2563         int nIdDirectory = _searchFields.getIdDirectory( );
2564         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
2565 
2566         if ( ( directory == null )
2567                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
2568                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2569         {
2570             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2571         }
2572 
2573         if ( request.getParameter( PARAMETER_CANCEL ) == null )
2574         {
2575             IEntry entry = new Entry( );
2576             entry.setIdEntry( _searchFields.getIdEntry( ) );
2577 
2578             Field field = new Field( );
2579             field.setEntry( entry );
2580 
2581             String strError = getFieldData( request, field );
2582 
2583             if ( strError != null )
2584             {
2585                 return strError;
2586             }
2587 
2588             FieldHome.create( field, getPlugin( ) );
2589         }
2590 
2591         return getJspModifyEntry( request, _searchFields.getIdEntry( ) );
2592     }
2593 
2594     /**
2595      * Perform modification field
2596      * 
2597      * @param request
2598      *            The HTTP request
2599      * @throws AccessDeniedException
2600      *             the {@link AccessDeniedException}
2601      * @return The URL to go after performing the action
2602      */
2603     public String doModifyField( HttpServletRequest request ) throws AccessDeniedException
2604     {
2605         Plugin plugin = getPlugin( );
2606         Field field = null;
2607         String strIdField = request.getParameter( PARAMETER_ID_FIELD );
2608         int nIdField = DirectoryUtils.convertStringToInt( strIdField );
2609         field = FieldHome.findByPrimaryKey( nIdField, plugin );
2610 
2611         int nIdDirectory = _searchFields.getIdDirectory( );
2612         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, plugin );
2613 
2614         if ( ( field == null )
2615                 || ( directory == null )
2616                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
2617                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2618         {
2619             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2620         }
2621 
2622         if ( request.getParameter( PARAMETER_CANCEL ) == null )
2623         {
2624             String strError = getFieldData( request, field );
2625 
2626             if ( strError != null )
2627             {
2628                 return strError;
2629             }
2630 
2631             FieldHome.update( field, getPlugin( ) );
2632         }
2633 
2634         if ( request.getParameter( PARAMETER_APPLY ) == null )
2635         {
2636             return getJspModifyEntry( request, field.getEntry( ).getIdEntry( ) );
2637         }
2638 
2639         return getJspModifyField( request, nIdField );
2640     }
2641 
2642     /**
2643      * Get the request data and if there is no error insert the data in the field specified in parameter. return null if there is no error or else return the
2644      * error page url
2645      * 
2646      * @param request
2647      *            the request
2648      * @param field
2649      *            field
2650      * @return null if there is no error or else return the error page url
2651      */
2652     private String getFieldData( HttpServletRequest request, Field field )
2653     {
2654         String strTitle = request.getParameter( PARAMETER_TITLE );
2655         String strValue = request.getParameter( PARAMETER_VALUE );
2656         String strDefaultValue = request.getParameter( PARAMETER_DEFAULT_VALUE );
2657 
2658         String strFieldError = DirectoryUtils.EMPTY_STRING;
2659 
2660         if ( ( strTitle == null ) || DirectoryUtils.EMPTY_STRING.equals( strTitle ) )
2661         {
2662             strFieldError = FIELD_TITLE_FIELD;
2663         }
2664         else
2665             if ( ( strValue == null ) || DirectoryUtils.EMPTY_STRING.equals( strValue ) )
2666             {
2667                 strFieldError = FIELD_VALUE_FIELD;
2668             }
2669             else
2670                 if ( !StringUtil.checkCodeKey( strValue ) )
2671                 {
2672                     return AdminMessageService.getMessageUrl( request, MESSAGE_FIELD_VALUE_FIELD, AdminMessage.TYPE_STOP );
2673                 }
2674 
2675         String strRoleKey = request.getParameter( PARAMETER_ROLE_KEY );
2676         String strWorkgroupKey = request.getParameter( PARAMETER_WORKGROUP );
2677 
2678         if ( !strFieldError.equals( DirectoryUtils.EMPTY_STRING ) )
2679         {
2680             Object [ ] tabRequiredFields = {
2681                 I18nService.getLocalizedString( strFieldError, getLocale( ) )
2682             };
2683 
2684             return AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_FIELD, tabRequiredFields, AdminMessage.TYPE_STOP );
2685         }
2686 
2687         field.setTitle( strTitle );
2688         field.setValue( strValue );
2689         field.setDefaultValue( strDefaultValue != null );
2690         field.setRoleKey( strRoleKey );
2691         field.setWorkgroup( strWorkgroupKey );
2692 
2693         return null; // No error
2694     }
2695 
2696     /**
2697      * Gets the confirmation page of delete field
2698      * 
2699      * @param request
2700      *            The HTTP request
2701      * @throws AccessDeniedException
2702      *             the {@link AccessDeniedException}
2703      * @return the confirmation page of delete field
2704      */
2705     public String getConfirmRemoveField( HttpServletRequest request ) throws AccessDeniedException
2706     {
2707         int nIdDirectory = _searchFields.getIdDirectory( );
2708         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
2709 
2710         if ( ( request.getParameter( PARAMETER_ID_FIELD ) == null )
2711                 || ( directory == null )
2712                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
2713                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2714         {
2715             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2716         }
2717 
2718         String strIdField = request.getParameter( PARAMETER_ID_FIELD );
2719         UrlItem url = new UrlItem( JSP_DO_REMOVE_FIELD );
2720         url.addParameter( PARAMETER_ID_FIELD, strIdField + "#list" );
2721 
2722         return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_FIELD, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
2723     }
2724 
2725     /**
2726      * Perform suppression field
2727      * 
2728      * @param request
2729      *            The HTTP request
2730      * @throws AccessDeniedException
2731      *             the {@link AccessDeniedException}
2732      * @return The URL to go after performing the action
2733      */
2734     public String doRemoveField( HttpServletRequest request ) throws AccessDeniedException
2735     {
2736         String strIdField = request.getParameter( PARAMETER_ID_FIELD );
2737         int nIdField = DirectoryUtils.convertStringToInt( strIdField );
2738 
2739         int nIdDirectory = _searchFields.getIdDirectory( );
2740         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
2741 
2742         if ( ( nIdField == -1 )
2743                 || ( directory == null )
2744                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
2745                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2746         {
2747             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2748         }
2749 
2750         RecordFieldFilter recordFieldFilter = new RecordFieldFilter( );
2751         recordFieldFilter.setIdField( nIdField );
2752 
2753         if ( ( RecordFieldHome.getCountRecordField( recordFieldFilter, getPlugin( ) ) != 0 ) )
2754         {
2755             return AdminMessageService.getMessageUrl( request, MESSAGE_CANNOT_REMOVE_FIELD_DIRECTORY_IS_NOT_EMPTY, AdminMessage.TYPE_STOP );
2756         }
2757 
2758         FieldHome.remove( nIdField, getPlugin( ) );
2759 
2760         return getJspModifyEntry( request, _searchFields.getIdEntry( ) );
2761     }
2762 
2763     /**
2764      * Move up the field
2765      * 
2766      * @param request
2767      *            The HTTP request
2768      * @throws AccessDeniedException
2769      *             the {@link AccessDeniedException}
2770      * @return The URL to go after performing the action
2771      */
2772     public String doMoveUpField( HttpServletRequest request ) throws AccessDeniedException
2773     {
2774         Plugin plugin = getPlugin( );
2775         List<Field> listField;
2776         Field field;
2777         String strIdField = request.getParameter( PARAMETER_ID_FIELD );
2778         int nIdField = DirectoryUtils.convertStringToInt( strIdField );
2779         field = FieldHome.findByPrimaryKey( nIdField, plugin );
2780 
2781         int nIdDirectory = _searchFields.getIdDirectory( );
2782         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, plugin );
2783 
2784         if ( ( field == null )
2785                 || ( directory == null )
2786                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
2787                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2788         {
2789             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2790         }
2791 
2792         listField = FieldHome.getFieldListByIdEntry( field.getEntry( ).getIdEntry( ), plugin );
2793 
2794         int nIndexField = DirectoryUtils.getIndexFieldInTheFieldList( nIdField, listField );
2795 
2796         if ( nIndexField != 0 )
2797         {
2798             int nNewPosition;
2799             Field fieldToInversePosition;
2800             fieldToInversePosition = listField.get( nIndexField - 1 );
2801             nNewPosition = fieldToInversePosition.getPosition( );
2802             fieldToInversePosition.setPosition( field.getPosition( ) );
2803             field.setPosition( nNewPosition );
2804             FieldHome.update( field, plugin );
2805             FieldHome.update( fieldToInversePosition, plugin );
2806         }
2807 
2808         return getJspModifyEntry( request, _searchFields.getIdEntry( ) );
2809     }
2810 
2811     /**
2812      * Move down the field
2813      * 
2814      * @param request
2815      *            The HTTP request
2816      * @throws AccessDeniedException
2817      *             the {@link AccessDeniedException}
2818      * @return The URL to go after performing the action
2819      */
2820     public String doMoveDownField( HttpServletRequest request ) throws AccessDeniedException
2821     {
2822         Plugin plugin = getPlugin( );
2823         List<Field> listField;
2824         Field field;
2825         String strIdField = request.getParameter( PARAMETER_ID_FIELD );
2826         int nIdField = DirectoryUtils.convertStringToInt( strIdField );
2827         field = FieldHome.findByPrimaryKey( nIdField, plugin );
2828 
2829         int nIdDirectory = _searchFields.getIdDirectory( );
2830         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, plugin );
2831 
2832         if ( ( field == null )
2833                 || ( directory == null )
2834                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
2835                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2836         {
2837             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2838         }
2839 
2840         listField = FieldHome.getFieldListByIdEntry( field.getEntry( ).getIdEntry( ), plugin );
2841 
2842         int nIndexField = DirectoryUtils.getIndexFieldInTheFieldList( nIdField, listField );
2843 
2844         if ( nIndexField != ( listField.size( ) - 1 ) )
2845         {
2846             int nNewPosition;
2847             Field fieldToInversePosition;
2848             fieldToInversePosition = listField.get( nIndexField + 1 );
2849             nNewPosition = fieldToInversePosition.getPosition( );
2850             fieldToInversePosition.setPosition( field.getPosition( ) );
2851             field.setPosition( nNewPosition );
2852             FieldHome.update( field, plugin );
2853             FieldHome.update( fieldToInversePosition, plugin );
2854         }
2855 
2856         return getJspModifyEntry( request, _searchFields.getIdEntry( ) );
2857     }
2858 
2859     /**
2860      * Delete association between field and regular expression
2861      * 
2862      * @param request
2863      *            the Http Request
2864      * @throws AccessDeniedException
2865      *             the {@link AccessDeniedException}
2866      * @return The URL to go after performing the action
2867      */
2868     public String doRemoveRegularExpression( HttpServletRequest request ) throws AccessDeniedException
2869     {
2870         String strIdExpression = request.getParameter( PARAMETER_ID_EXPRESSION );
2871         String strIdField = request.getParameter( PARAMETER_ID_FIELD );
2872         int nIdField = DirectoryUtils.convertStringToInt( strIdField );
2873         int nIdExpression = DirectoryUtils.convertStringToInt( strIdExpression );
2874 
2875         int nIdDirectory = _searchFields.getIdDirectory( );
2876         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
2877 
2878         if ( ( nIdExpression == DirectoryUtils.CONSTANT_ID_NULL )
2879                 || ( nIdField == DirectoryUtils.CONSTANT_ID_NULL )
2880                 || ( directory == null )
2881                 || ( !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
2882                         getUser( ) ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2883         {
2884             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2885         }
2886 
2887         FieldHome.removeVerifyBy( nIdField, nIdExpression, getPlugin( ) );
2888 
2889         return getJspModifyEntry( request, _searchFields.getIdEntry( ) );
2890     }
2891 
2892     /**
2893      * insert association between field and regular expression
2894      * 
2895      * @param request
2896      *            the Http Request
2897      * @throws AccessDeniedException
2898      *             the {@link AccessDeniedException}
2899      * @return The URL to go after performing the action
2900      */
2901     public String doInsertRegularExpression( HttpServletRequest request ) throws AccessDeniedException
2902     {
2903         String strIdExpression = request.getParameter( PARAMETER_ID_EXPRESSION );
2904         String strIdField = request.getParameter( PARAMETER_ID_FIELD );
2905         int nIdField = DirectoryUtils.convertStringToInt( strIdField );
2906         int nIdExpression = DirectoryUtils.convertStringToInt( strIdExpression );
2907 
2908         int nIdDirectory = _searchFields.getIdDirectory( );
2909         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
2910 
2911         if ( ( nIdExpression == DirectoryUtils.CONSTANT_ID_NULL )
2912                 || ( nIdField == DirectoryUtils.CONSTANT_ID_NULL )
2913                 || ( directory == null )
2914                 || ( !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY,
2915                         getUser( ) ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
2916         {
2917             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
2918         }
2919 
2920         FieldHome.createVerifyBy( nIdField, nIdExpression, getPlugin( ) );
2921 
2922         return getJspModifyEntry( request, _searchFields.getIdEntry( ) );
2923     }
2924 
2925     /**
2926      * Get the map query and return on manage directory record
2927      * 
2928      * @param request
2929      *            the Http Request
2930      * @throws AccessDeniedException
2931      *             the {@link AccessDeniedException}
2932      * @return The URL to go after performing the action
2933      * @deprecated Use fr.paris.lutece.plugins.directory.web.action. SearchRecordDirectoryAction instead
2934      */
2935     @Deprecated
2936     public String doSearchDirectoryRecord( HttpServletRequest request ) throws AccessDeniedException
2937     {
2938         AppLogService
2939                 .error( "Calling doSearchDirectoryRecord which no longer work. Use fr.paris.lutece.plugins.directory.web.action.SearchRecordDirectoryAction instead." );
2940 
2941         return null;
2942     }
2943 
2944     /**
2945      * Return management of directory record ( list of directory record ).
2946      * 
2947      * @param request
2948      *            The Http request
2949      * @param response
2950      *            the Http response
2951      * @throws AccessDeniedException
2952      *             the {@link AccessDeniedException}
2953      * @return IPluginActionResult
2954      */
2955     public IPluginActionResult getManageDirectoryRecord( HttpServletRequest request, HttpServletResponse response ) throws AccessDeniedException
2956     {
2957         String strExtentCurrent = request.getParameter( MARK_EXTENT_CURRENT ) == null ? "" : request.getParameter( MARK_EXTENT_CURRENT );
2958         String strVisibleLayer = request.getParameter( MARK_VISIBLE_LAYER ) == null ? "" : request.getParameter( MARK_VISIBLE_LAYER );
2959 
2960         HttpSession session = request.getSession( false );
2961 
2962         if ( !strExtentCurrent.isEmpty( ) && !strVisibleLayer.isEmpty( ) )
2963         {
2964             session.setAttribute( MARK_EXTENT_CURRENT, strExtentCurrent );
2965             session.setAttribute( MARK_VISIBLE_LAYER, strVisibleLayer );
2966         }
2967 
2968         // fill the selected records
2969         String [ ] selectedRecords = request.getParameterValues( PARAMETER_SELECTED_RECORD );
2970         List<String> listSelectedRecords;
2971 
2972         if ( selectedRecords != null )
2973         {
2974             listSelectedRecords = Arrays.asList( selectedRecords );
2975 
2976             if ( AppLogService.isDebugEnabled( ) )
2977             {
2978                 AppLogService.debug( "List selected record : " + listSelectedRecords );
2979             }
2980         }
2981         else
2982         {
2983             listSelectedRecords = new ArrayList<String>( );
2984         }
2985 
2986         _searchFields.setSelectedRecords( listSelectedRecords );
2987 
2988         // first - see if there is an invoked action
2989         IDirectoryAction action = PluginActionManager.getPluginAction( request, IDirectoryAction.class );
2990 
2991         if ( action != null )
2992         {
2993             if ( AppLogService.isDebugEnabled( ) )
2994             {
2995                 AppLogService.debug( "Processing directory action " + action.getName( ) );
2996             }
2997 
2998             return action.process( request, response, getUser( ), _searchFields );
2999         }
3000 
3001         // display could have been an action but it's the default one an will always be here...
3002         DefaultPluginActionResult result = new DefaultPluginActionResult( );
3003         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
3004         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
3005         boolean bWorkflowServiceEnable = WorkflowService.getInstance( ).isAvailable( );
3006         AdminUser adminUser = getUser( );
3007         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
3008 
3009         if ( ( directory == null )
3010                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_MANAGE_RECORD, getUser( ) )
3011                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
3012         {
3013             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
3014         }
3015 
3016         if ( ( request.getParameter( PARAMETER_SESSION ) == null ) || Boolean.parseBoolean( request.getParameter( PARAMETER_RESET_SEARCH ) ) )
3017         {
3018             reInitDirectoryRecordFilter( );
3019         }
3020 
3021         _searchFields.setRedirectUrl( request );
3022         _searchFields.setCurrentPageIndexDirectoryRecord( Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX,
3023                 _searchFields.getCurrentPageIndexDirectoryRecord( ) ) );
3024         _searchFields.setItemsPerPageDirectoryRecord( Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE,
3025                 _searchFields.getItemsPerPageDirectoryRecord( ), _searchFields.getDefaultItemsPerPage( ) ) );
3026 
3027         // build entryFilter
3028         EntryFilter entryFilter = new EntryFilter( );
3029         entryFilter.setIdDirectory( directory.getIdDirectory( ) );
3030         entryFilter.setIsGroup( EntryFilter.FILTER_FALSE );
3031         entryFilter.setIsComment( EntryFilter.FILTER_FALSE );
3032 
3033         List<IEntry> listEntryFormMainSearch = new ArrayList<IEntry>( );
3034         List<IEntry> listEntryFormComplementarySearch = new ArrayList<IEntry>( );
3035         List<IEntry> listEntryResultSearch = new ArrayList<IEntry>( );
3036         List<IEntry> listEntryGeolocation = new ArrayList<IEntry>( );
3037 
3038         for ( IEntry entry : EntryHome.getEntryList( entryFilter, getPlugin( ) ) )
3039         {
3040             IEntry entryTmp = EntryHome.findByPrimaryKey( entry.getIdEntry( ), getPlugin( ) );
3041 
3042             if ( entryTmp.isWorkgroupAssociated( ) )
3043             {
3044                 entryTmp.setFields( DirectoryUtils.getAuthorizedFieldsByWorkgroup( entryTmp.getFields( ), getUser( ) ) );
3045             }
3046 
3047             if ( entryTmp.isIndexed( ) )
3048             {
3049                 if ( !entryTmp.isShownInAdvancedSearch( ) )
3050                 {
3051                     listEntryFormMainSearch.add( entryTmp );
3052                 }
3053                 else
3054                 {
3055                     listEntryFormComplementarySearch.add( entryTmp );
3056                 }
3057             }
3058 
3059             if ( entry.isShownInResultList( ) )
3060             {
3061                 listEntryResultSearch.add( entryTmp );
3062 
3063                 // add geolocation entries
3064                 if ( entry.getEntryType( ).getIdType( ) == AppPropertiesService.getPropertyInt( PROPERTY_ENTRY_TYPE_GEOLOCATION, 16 ) )
3065                 {
3066                     listEntryGeolocation.add( entry );
3067                 }
3068             }
3069         }
3070 
3071         _searchFields.setSortParameters( request, directory, getPlugin( ) );
3072 
3073         List<Integer> listResultRecordId = DirectoryUtils.getListResults( request, directory, bWorkflowServiceEnable, true, _searchFields, getUser( ),
3074                 getLocale( ) );
3075 
3076         // Store the list of id records in session
3077         _searchFields.setListIdsResultRecord( listResultRecordId );
3078 
3079         // HACK : We copy the list so workflow does not clear the paginator list.
3080         LocalizedPaginator<Integer> paginator = new LocalizedPaginator<Integer>( new ArrayList<Integer>( listResultRecordId ),
3081                 _searchFields.getItemsPerPageDirectoryRecord( ), DirectoryUtils.getJspManageDirectoryRecord( request, nIdDirectory ), PARAMETER_PAGE_INDEX,
3082                 _searchFields.getCurrentPageIndexDirectoryRecord( ), getLocale( ) );
3083 
3084         // get only record for page items.
3085         List<Record> lRecord = _recordService.loadListByListId( paginator.getPageItems( ), getPlugin( ) );
3086 
3087         boolean bHistoryEnabled = WorkflowService.getInstance( ).isAvailable( ) && ( directory.getIdWorkflow( ) != DirectoryUtils.CONSTANT_ID_NULL );
3088         RecordFieldFilter recordFieldFilter = new RecordFieldFilter( );
3089         recordFieldFilter.setIsEntryShownInResultList( RecordFieldFilter.FILTER_TRUE );
3090 
3091         bWorkflowServiceEnable = ( directory.getIdWorkflow( ) != DirectoryUtils.CONSTANT_ID_NULL ) && bWorkflowServiceEnable;
3092 
3093         List<Map<String, Object>> listResourceActions = new ArrayList<Map<String, Object>>( lRecord.size( ) );
3094 
3095         List<DirectoryAction> listActionsForDirectoryEnable = DirectoryActionHome.selectActionsRecordByFormState( Directory.STATE_ENABLE, getPlugin( ),
3096                 getLocale( ) );
3097         List<DirectoryAction> listActionsForDirectoryDisable = DirectoryActionHome.selectActionsRecordByFormState( Directory.STATE_DISABLE, getPlugin( ),
3098                 getLocale( ) );
3099 
3100         listActionsForDirectoryEnable = (List<DirectoryAction>) RBACService
3101                 .getAuthorizedActionsCollection( listActionsForDirectoryEnable, directory, getUser( ) );
3102         listActionsForDirectoryDisable = (List<DirectoryAction>) RBACService.getAuthorizedActionsCollection( listActionsForDirectoryDisable, directory,
3103                 getUser( ) );
3104 
3105         // Get asynchronous file names put at false for better performance
3106         // since it must call a webservice to get the file name
3107         boolean bGetFileName = false;
3108 
3109         for ( Record record : lRecord )
3110         {
3111             listResourceActions.add( DirectoryService.getInstance( ).getResourceAction( record, directory, listEntryResultSearch, adminUser,
3112                     listActionsForDirectoryEnable, listActionsForDirectoryDisable, bGetFileName, getPlugin( ) ) );
3113         }
3114 
3115         Map<String, Object> model = new HashMap<String, Object>( );
3116 
3117         model.put( MARK_SHOW_DATE_CREATION_RESULT, directory.isDateShownInResultList( ) );
3118         model.put( MARK_SHOW_DATE_MODIFICATION_RESULT, directory.isDateModificationShownInResultList( ) );
3119         model.put( MARK_ID_ENTRY_TYPE_IMAGE, AppPropertiesService.getPropertyInt( PROPERTY_ENTRY_TYPE_IMAGE, 10 ) );
3120         model.put( MARK_ID_ENTRY_TYPE_DIRECTORY, AppPropertiesService.getPropertyInt( PROPERTY_ENTRY_TYPE_DIRECTORY, 12 ) );
3121         model.put( MARK_ID_ENTRY_TYPE_GEOLOCATION, AppPropertiesService.getPropertyInt( PROPERTY_ENTRY_TYPE_GEOLOCATION, 16 ) );
3122         model.put( MARK_ID_ENTRY_TYPE_MYLUTECE_USER, AppPropertiesService.getPropertyInt( PROPERTY_ENTRY_TYPE_MYLUTECE_USER, 19 ) );
3123         model.put( MARK_ID_ENTRY_TYPE_NUMBERING, AppPropertiesService.getPropertyInt( PROPERTY_ENTRY_TYPE_NUMBERING, 11 ) );
3124         model.put( MARK_ENTRY_LIST_GEOLOCATION, listEntryGeolocation );
3125         model.put( MARK_WORKFLOW_STATE_SEARCH_DEFAULT, _searchFields.get_nIdWorkflowSate( ) );
3126         model.put( MARK_PAGINATOR, paginator );
3127         model.put( MARK_NB_ITEMS_PER_PAGE, Integer.toString( _searchFields.getItemsPerPageDirectoryRecord( ) ) );
3128         model.put( MARK_ENTRY_LIST_FORM_MAIN_SEARCH, listEntryFormMainSearch );
3129         model.put( MARK_ENTRY_LIST_FORM_COMPLEMENTARY_SEARCH, listEntryFormComplementarySearch );
3130         model.put( MARK_ENTRY_LIST_SEARCH_RESULT, listEntryResultSearch );
3131 
3132         model.put( MARK_MAP_ID_ENTRY_LIST_RECORD_FIELD, _searchFields.getMapQuery( ) );
3133         model.put( MARK_DATE_CREATION_SEARCH, _searchFields.getDateCreationRecord( ) );
3134         model.put( MARK_DATE_CREATION_BEGIN_SEARCH, _searchFields.getDateCreationBeginRecord( ) );
3135         model.put( MARK_DATE_CREATION_END_SEARCH, _searchFields.getDateCreationEndRecord( ) );
3136         model.put( MARK_DATE_MODIFICATION_SEARCH, _searchFields.getDateModificationRecord( ) );
3137         model.put( MARK_DATE_MODIFICATION_BEGIN_SEARCH, _searchFields.getDateModificationBeginRecord( ) );
3138         model.put( MARK_DATE_MODIFICATION_END_SEARCH, _searchFields.getDateModificationEndRecord( ) );
3139 
3140         model.put( MARK_DIRECTORY, directory );
3141         // model.put( MARK_DIRECTORY_RECORD_LIST, listRecordResult );
3142         // model.put( MARK_NUMBER_RECORD, paginator.getItemsCount( ) );
3143         model.put( MARK_NUMBER_RECORD, listResultRecordId.size( ) );
3144         model.put( MARK_RESOURCE_ACTIONS_LIST, listResourceActions );
3145         model.put( MARK_HISTORY_WORKFLOW_ENABLED, bHistoryEnabled );
3146         model.put( MARK_PERMISSION_CREATE_RECORD,
3147                 RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_CREATE_RECORD, getUser( ) ) );
3148         model.put( MARK_PERMISSION_MASS_PRINT,
3149                 RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_MASS_PRINT, getUser( ) ) );
3150         model.put( MARK_PERMISSION_VISUALISATION_MYLUTECE_USER, RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory,
3151                 DirectoryResourceIdService.PERMISSION_VISUALISATION_MYLUTECE_USER, getUser( ) ) );
3152 
3153         model.put( MARK_LOCALE, getLocale( ) );
3154         model.put( MARK_IS_WORKFLOW_ENABLED, bWorkflowServiceEnable );
3155         model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
3156 
3157         model.put( MARK_EXTENT_CURRENT, session.getAttribute( MARK_EXTENT_CURRENT ) );
3158         model.put( MARK_VISIBLE_LAYER, session.getAttribute( MARK_VISIBLE_LAYER ) );
3159 
3160         if ( directory.isDisplayComplementarySearchState( ) || directory.isDisplaySearchState( ) )
3161         {
3162             ReferenceList referenceList = new ReferenceList( );
3163             referenceList.addItem( -1, "" );
3164 
3165             Collection<State> colState = WorkflowService.getInstance( ).getAllStateByWorkflow( directory.getIdWorkflow( ), adminUser );
3166 
3167             if ( colState != null )
3168             {
3169                 for ( State stateWorkflow : colState )
3170                 {
3171                     referenceList.addItem( stateWorkflow.getId( ), stateWorkflow.getName( ) );
3172                 }
3173             }
3174 
3175             model.put( MARK_SEARCH_STATE_WORKFLOW, referenceList );
3176         }
3177 
3178         PluginActionManager.fillModel( request, adminUser, model, IDirectoryAction.class, MARK_DIRECTORY_ACTIONS );
3179 
3180         setPageTitleProperty( PROPERTY_MANAGE_DIRECTORY_RECORD_PAGE_TITLE );
3181 
3182         HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_MANAGE_DIRECTORY_RECORD, getLocale( ), model );
3183 
3184         result.setHtmlContent( getAdminPage( templateList.getHtml( ) ) );
3185 
3186         return result;
3187     }
3188 
3189     /**
3190      * Export Directory record
3191      * 
3192      * @param request
3193      *            the Http Request
3194      * @param response
3195      *            the Http response
3196      * @throws AccessDeniedException
3197      *             the {@link AccessDeniedException}
3198      * @deprecated use fr.paris.lutece.plugins.directory.web.action. ExportDirectoryAction instead
3199      */
3200     @Deprecated
3201     public void doExportDirectoryRecord( HttpServletRequest request, HttpServletResponse response ) throws AccessDeniedException
3202     {
3203         AppLogService
3204                 .error( "Calling doExportDirectoryRecord which no longer work. Use fr.paris.lutece.plugins.directory.web.action.ExportDirectoryAction instead." );
3205     }
3206 
3207     /**
3208      * Return the interface for import directory record
3209      * 
3210      * @param request
3211      *            The Http request
3212      * @throws AccessDeniedException
3213      *             the {@link AccessDeniedException}
3214      * @return Html directory
3215      *
3216      */
3217     public String getImportDirectoryRecord( HttpServletRequest request ) throws AccessDeniedException
3218     {
3219         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
3220 
3221         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
3222         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
3223 
3224         if ( ( directory == null )
3225                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_IMPORT_RECORD, getUser( ) )
3226                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
3227         {
3228             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
3229         }
3230 
3231         Map<String, Object> model = new HashMap<String, Object>( );
3232 
3233         if ( request.getParameter( PARAMETER_SESSION ) != null )
3234         {
3235             if ( _searchFields.getError( ) != null )
3236             {
3237                 model.put( MARK_STR_ERROR, _searchFields.getError( ).toString( ) );
3238             }
3239 
3240             model.put( MARK_NUMBER_LINES_ERROR, _searchFields.getCountLineFailure( ) );
3241             model.put( MARK_NUMBER_LINES_IMPORTED, _searchFields.getCountLine( ) - _searchFields.getCountLineFailure( ) );
3242             model.put( MARK_FINISH_IMPORT, true );
3243             _searchFields.setCountLine( 0 );
3244             _searchFields.setCountLineFailure( 0 );
3245             _searchFields.setError( null );
3246         }
3247 
3248         model.put( MARK_LOCALE, getLocale( ) );
3249         model.put( MARK_DIRECTORY, directory );
3250         setPageTitleProperty( PROPERTY_IMPORT_DIRECTORY_RECORD_PAGE_TITLE );
3251 
3252         HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_IMPORT_DIRECTORY_RECORD, getLocale( ), model );
3253 
3254         return getAdminPage( templateList.getHtml( ) );
3255     }
3256 
3257     /**
3258      * ImportDirectory record
3259      * 
3260      * @param request
3261      *            the Http Request
3262      * @throws AccessDeniedException
3263      *             the {@link AccessDeniedException}
3264      * @return The URL to go after performing the action
3265      */
3266     public String doImportDirectoryRecord( HttpServletRequest request ) throws AccessDeniedException
3267     {
3268         MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
3269         FileItem fileItem = multipartRequest.getFile( PARAMETER_FILE_IMPORT );
3270         String strMimeType = FileSystemUtil.getMIMEType( FileUploadService.getFileNameOnly( fileItem ) );
3271 
3272         if ( ( fileItem == null ) || ( fileItem.getName( ) == null ) || DirectoryUtils.EMPTY_STRING.equals( fileItem.getName( ) ) )
3273         {
3274             Object [ ] tabRequiredFields = {
3275                 I18nService.getLocalizedString( FIELD_FILE_IMPORT, getLocale( ) )
3276             };
3277 
3278             return AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_FIELD, tabRequiredFields, AdminMessage.TYPE_STOP );
3279         }
3280 
3281         if ( ( !strMimeType.equals( CONSTANT_MIME_TYPE_CSV ) && !strMimeType.equals( CONSTANT_MIME_TYPE_OCTETSTREAM ) && !strMimeType
3282                 .equals( CONSTANT_MIME_TYPE_TEXT_CSV ) ) || !fileItem.getName( ).toLowerCase( ).endsWith( CONSTANT_EXTENSION_CSV_FILE ) )
3283         {
3284             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_CSV_FILE_IMPORT, AdminMessage.TYPE_STOP );
3285         }
3286 
3287         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
3288         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
3289         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
3290 
3291         if ( ( directory == null )
3292                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_MANAGE_RECORD, getUser( ) )
3293                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
3294         {
3295             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
3296         }
3297 
3298         Character strCsvSeparator = AppPropertiesService.getProperty( PROPERTY_IMPORT_CSV_DELIMITER ).charAt( 0 );
3299         _searchFields.setError( new StringBuffer( ) );
3300 
3301         EntryFilter filter = new EntryFilter( );
3302         filter.setIdDirectory( nIdDirectory );
3303         filter.setIsComment( EntryFilter.FILTER_FALSE );
3304         filter.setIsEntryParentNull( EntryFilter.FILTER_TRUE );
3305 
3306         List<IEntry> listEntry = new ArrayList<IEntry>( );
3307 
3308         List<IEntry> listEntryFirstLevel = EntryHome.getEntryList( filter, getPlugin( ) );
3309 
3310         filter.setIsEntryParentNull( EntryFilter.ALL_INT );
3311 
3312         for ( IEntry entry : listEntryFirstLevel )
3313         {
3314             if ( !entry.getEntryType( ).getGroup( ) )
3315             {
3316                 listEntry.add( EntryHome.findByPrimaryKey( entry.getIdEntry( ), getPlugin( ) ) );
3317             }
3318 
3319             filter.setIdEntryParent( entry.getIdEntry( ) );
3320 
3321             List<IEntry> listChildren = EntryHome.getEntryList( filter, getPlugin( ) );
3322 
3323             for ( IEntry entryChild : listChildren )
3324             {
3325                 listEntry.add( EntryHome.findByPrimaryKey( entryChild.getIdEntry( ), getPlugin( ) ) );
3326             }
3327         }
3328 
3329         Object [ ] tabEntry = listEntry.toArray( );
3330 
3331         try
3332         {
3333             InputStreamReader inputStreamReader = new InputStreamReader( fileItem.getInputStream( ) );
3334             CSVReader csvReader = new CSVReader( inputStreamReader, strCsvSeparator, '\"' );
3335 
3336             String [ ] nextLine;
3337 
3338             _searchFields.setCountLine( 0 );
3339             _searchFields.setCountLineFailure( 0 );
3340 
3341             while ( ( nextLine = csvReader.readNext( ) ) != null )
3342             {
3343                 _searchFields.setCountLine( _searchFields.getCountLine( ) + 1 );
3344 
3345                 if ( nextLine.length != tabEntry.length )
3346                 {
3347                     _searchFields.getError( ).append( I18nService.getLocalizedString( PROPERTY_LINE, getLocale( ) ) );
3348                     _searchFields.getError( ).append( _searchFields.getCountLine( ) );
3349                     _searchFields.getError( ).append( " > " );
3350                     _searchFields.getError( ).append( I18nService.getLocalizedString( MESSAGE_ERROR_CSV_NUMBER_SEPARATOR, getLocale( ) ) );
3351                     _searchFields.getError( ).append( "<br/>" );
3352                     _searchFields.setCountLineFailure( _searchFields.getCountLineFailure( ) + 1 );
3353                 }
3354                 else
3355                 {
3356                     Record record = new Record( );
3357                     record.setDirectory( directory );
3358 
3359                     List<RecordField> listRecordField = new ArrayList<RecordField>( );
3360 
3361                     try
3362                     {
3363                         for ( int i = 0; i < nextLine.length; i++ )
3364                         {
3365                             ( (IEntry) tabEntry [i] ).getImportRecordFieldData( record, nextLine [i], true, listRecordField, getLocale( ) );
3366                         }
3367 
3368                         record.setListRecordField( listRecordField );
3369                         record.setDateCreation( DirectoryUtils.getCurrentTimestamp( ) );
3370                         // Autopublication
3371                         record.setEnabled( true );
3372                         _recordService.create( record, getPlugin( ) );
3373                     }
3374                     catch( DirectoryErrorException error )
3375                     {
3376                         _searchFields.getError( ).append( I18nService.getLocalizedString( PROPERTY_LINE, getLocale( ) ) );
3377                         _searchFields.getError( ).append( _searchFields.getCountLine( ) );
3378                         _searchFields.getError( ).append( " > " );
3379 
3380                         if ( error.isMandatoryError( ) )
3381                         {
3382                             Object [ ] tabRequiredFields = {
3383                                 error.getTitleField( )
3384                             };
3385                             _searchFields.getError( ).append(
3386                                     I18nService.getLocalizedString( MESSAGE_DIRECTORY_ERROR_MANDATORY_FIELD, tabRequiredFields, getLocale( ) ) );
3387                         }
3388                         else
3389                         {
3390                             Object [ ] tabRequiredFields = {
3391                                     error.getTitleField( ), error.getErrorMessage( )
3392                             };
3393                             _searchFields.getError( ).append( I18nService.getLocalizedString( MESSAGE_DIRECTORY_ERROR, tabRequiredFields, getLocale( ) ) );
3394                         }
3395 
3396                         _searchFields.getError( ).append( "<br/>" );
3397                         _searchFields.setCountLineFailure( _searchFields.getCountLineFailure( ) + 1 );
3398                     }
3399                 }
3400             }
3401         }
3402 
3403         catch( IOException e )
3404         {
3405             AppLogService.error( e );
3406         }
3407 
3408         return getJspImportDirectoryRecord( request, nIdDirectory );
3409     }
3410 
3411     /**
3412      * Return the interface for index all directory
3413      * 
3414      * @param request
3415      *            The Http request
3416      * @throws AccessDeniedException
3417      *             the {@link AccessDeniedException}
3418      * @return Html directory
3419      */
3420     public String getIndexAllDirectory( HttpServletRequest request ) throws AccessDeniedException
3421     {
3422         if ( !RBACService.isAuthorized( Directory.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, DirectoryResourceIdService.PERMISSION_INDEX_ALL_DIRECTORY,
3423                 getUser( ) ) )
3424         {
3425             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
3426         }
3427 
3428         Map<String, Object> model = new HashMap<String, Object>( );
3429 
3430         model.put( MARK_LOCALE, getLocale( ) );
3431 
3432         setPageTitleProperty( PROPERTY_INDEX_ALL_DIRECTORY_PAGE_TITLE );
3433 
3434         HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_INDEX_ALL_DIRECTORY, getLocale( ), model );
3435 
3436         return getAdminPage( templateList.getHtml( ) );
3437     }
3438 
3439     /**
3440      * Gets the confirmation page of indexing all directory
3441      * 
3442      * @param request
3443      *            The HTTP request
3444      * @throws AccessDeniedException
3445      *             the {@link AccessDeniedException}
3446      * @return the confirmation page of delete directory record
3447      */
3448     public String getConfirmIndexAllDirectory( HttpServletRequest request ) throws AccessDeniedException
3449     {
3450         if ( !RBACService.isAuthorized( Directory.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, DirectoryResourceIdService.PERMISSION_INDEX_ALL_DIRECTORY,
3451                 getUser( ) ) )
3452         {
3453             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
3454         }
3455 
3456         UrlItem url = new UrlItem( JSP_DO_INDEX_ALL_DIRECTORY );
3457 
3458         return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_INDEX_ALL_DIRECTORY, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
3459     }
3460 
3461     /**
3462      * Start indexing
3463      * 
3464      * @param request
3465      *            The HTTP request
3466      * @throws AccessDeniedException
3467      *             the {@link AccessDeniedException}
3468      * @return The URL to go after performing the action
3469      */
3470     public String doIndexAllDirectory( HttpServletRequest request ) throws AccessDeniedException
3471     {
3472         if ( !RBACService.isAuthorized( Directory.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, DirectoryResourceIdService.PERMISSION_INDEX_ALL_DIRECTORY,
3473                 getUser( ) ) )
3474         {
3475             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
3476         }
3477 
3478         if ( request.getParameter( PARAMETER_CANCEL ) == null )
3479         {
3480             DirectorySearchService.getInstance( ).processIndexing( true );
3481         }
3482 
3483         return getHomeUrl( request );
3484     }
3485 
3486     /**
3487      * Return management of directory record ( list of directory record )
3488      * 
3489      * @param request
3490      *            The Http request
3491      * @throws AccessDeniedException
3492      *             the {@link AccessDeniedException}
3493      * @return Html directory
3494      */
3495     public String getCreateDirectoryRecord( HttpServletRequest request ) throws AccessDeniedException
3496     {
3497         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
3498         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
3499         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
3500 
3501         if ( ( directory == null )
3502                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_CREATE_RECORD, getUser( ) )
3503                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
3504         {
3505             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
3506         }
3507 
3508         Map<String, Object> model = new HashMap<String, Object>( );
3509 
3510         /**
3511          * Map of idEntry, RecordFields 1) The user has uploaded/deleted a file - The updated map is stored in the session 2) The user has not uploaded/delete
3512          * a file - The map is filled with the data from the database - The asynchronous uploaded files map is reinitialized
3513          */
3514         Map<String, List<RecordField>> map = null;
3515 
3516         // Get the map of <idEntry, RecordFields from session if it exists :
3517         /**
3518          * 1) Case when the user has uploaded a file, the the map is stored in the session
3519          */
3520         HttpSession session = request.getSession( false );
3521 
3522         if ( session != null )
3523         {
3524             map = (Map<String, List<RecordField>>) session.getAttribute( DirectoryUtils.SESSION_DIRECTORY_LIST_SUBMITTED_RECORD_FIELDS );
3525 
3526             if ( map != null )
3527             {
3528                 model.put( MARK_MAP_ID_ENTRY_LIST_RECORD_FIELD, map );
3529                 // IMPORTANT : Remove the map from the session
3530                 session.removeAttribute( DirectoryUtils.SESSION_DIRECTORY_LIST_SUBMITTED_RECORD_FIELDS );
3531             }
3532         }
3533 
3534         // Get the map idEntry, RecordFields classically from the database
3535         /** 2) The user has not uploaded/delete a file */
3536         if ( map == null )
3537         {
3538             // Remove asynchronous uploaded file from session
3539             DirectoryAsynchronousUploadHandler.getHandler( ).removeSessionFiles( request.getSession( ).getId( ) );
3540         }
3541 
3542         List<IEntry> listEntry = DirectoryUtils.getFormEntries( nIdDirectory, getPlugin( ), getUser( ) );
3543 
3544         model.put( MARK_ENTRY_LIST, listEntry );
3545 
3546         if ( SecurityService.isAuthenticationEnable( ) )
3547         {
3548             model.put( MARK_ROLE_REF_LIST, RoleHome.getRolesList( ) );
3549         }
3550 
3551         model.put( MARK_DIRECTORY, directory );
3552         model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
3553         model.put( MARK_LOCALE, getLocale( ) );
3554         setPageTitleProperty( PROPERTY_CREATE_DIRECTORY_RECORD_PAGE_TITLE );
3555 
3556         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_DIRECTORY_RECORD, getLocale( ), model );
3557 
3558         return getAdminPage( template.getHtml( ) );
3559     }
3560 
3561     /**
3562      * Gets the creates the directory record with initial values.
3563      *
3564      * @param request
3565      *            the request
3566      * @return the creates the directory record with initial values
3567      * @throws AccessDeniedException
3568      *             the access denied exception
3569      */
3570     @SuppressWarnings( "unchecked" )
3571     public String getCreateDirectoryRecordWithInitialValues( HttpServletRequest request ) throws AccessDeniedException
3572     {
3573         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
3574         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
3575         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
3576 
3577         if ( ( directory == null )
3578                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_CREATE_RECORD, getUser( ) )
3579                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
3580         {
3581             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
3582         }
3583 
3584         Map<String, Object> model = new HashMap<String, Object>( );
3585 
3586         /**
3587          * Map of idEntry, RecordFields 1) The user has uploaded/deleted a file - The updated map is stored in the session 2) The user has not uploaded/delete
3588          * a file - The map is filled with the data from the database - The asynchronous uploaded files map is reinitialized
3589          */
3590         Map<String, List<RecordField>> map = null;
3591 
3592         // Get the map of <idEntry, RecordFields from session if it exists :
3593         /**
3594          * 1) Case when the user has uploaded a file, the the map is stored in the session
3595          */
3596         HttpSession session = request.getSession( false );
3597 
3598         if ( session != null )
3599         {
3600             map = (Map<String, List<RecordField>>) session.getAttribute( DirectoryUtils.SESSION_DIRECTORY_LIST_SUBMITTED_RECORD_FIELDS );
3601 
3602             if ( map != null )
3603             {
3604                 model.put( MARK_MAP_ID_ENTRY_LIST_RECORD_FIELD, map );
3605                 // IMPORTANT : Remove the map from the session
3606                 session.removeAttribute( DirectoryUtils.SESSION_DIRECTORY_LIST_SUBMITTED_RECORD_FIELDS );
3607             }
3608         }
3609 
3610         // Get the map idEntry, RecordFields classically from the database
3611         /** 2) The user has not uploaded/delete a file */
3612         if ( map == null )
3613         {
3614             // Remove asynchronous uploaded file from session
3615             DirectoryAsynchronousUploadHandler.getHandler( ).removeSessionFiles( request.getSession( ).getId( ) );
3616         }
3617 
3618         List<IEntry> listEntry = DirectoryUtils.getFormEntries( nIdDirectory, getPlugin( ), getUser( ) );
3619 
3620         // setValue inital
3621 
3622         // /jsp/admin/plugins/directory/CreateDirectoryRecordWithInitialValues.jsp?id_directory=1&fn=abdou&cid=302714&ln=fall&guid=680a9e86-ffdc-45e6-a3c6-e3020b487624&ph=0858812641&em=fallphenix1987@gmail.com
3623         // &pfn=1&pln=2&pem=3&pguid=4&pcid=5
3624 
3625         String fn = request.getParameter( PARAMETER_GRU_FIRST_NAME );
3626         String ln = request.getParameter( PARAMETER_GRU_LAST_NAME );
3627         String em = request.getParameter( PARAMETER_GRU_EMAIL );
3628         String guid = request.getParameter( PARAMETER_GRU_GUID );
3629         String cid = request.getParameter( PARAMETER_GRU_CID );
3630 
3631         int pfn = ( StringUtils.isNumeric( request.getParameter( MARK_POSITION_GRU_FIRST_NAME ) ) ) ? Integer.parseInt( request
3632                 .getParameter( MARK_POSITION_GRU_FIRST_NAME ) ) : 1;
3633         int pln = ( StringUtils.isNumeric( request.getParameter( MARK_POSITION_GRU_LAST_NAME ) ) ) ? Integer.parseInt( request
3634                 .getParameter( MARK_POSITION_GRU_LAST_NAME ) ) : 2;
3635         int pem = ( StringUtils.isNumeric( request.getParameter( MARK_POSITION_GRU_EMAIL ) ) ) ? Integer.parseInt( request
3636                 .getParameter( MARK_POSITION_GRU_EMAIL ) ) : 3;
3637         int pguid = ( StringUtils.isNumeric( request.getParameter( MARK_POSITION_GRU_GUID ) ) ) ? Integer.parseInt( request
3638                 .getParameter( MARK_POSITION_GRU_GUID ) ) : 4;
3639         int pcid = ( StringUtils.isNumeric( request.getParameter( MARK_POSITION_GRU_CID ) ) ) ? Integer
3640                 .parseInt( request.getParameter( MARK_POSITION_GRU_CID ) ) : 5;
3641 
3642         listEntry.get( pfn - 1 ).getFields( ).get( 0 ).setValue( fn );
3643         listEntry.get( pln - 1 ).getFields( ).get( 0 ).setValue( ln );
3644         listEntry.get( pem - 1 ).getFields( ).get( 0 ).setValue( em );
3645         listEntry.get( pguid - 1 ).getFields( ).get( 0 ).setValue( guid );
3646         listEntry.get( pcid - 1 ).getFields( ).get( 0 ).setValue( cid );
3647 
3648         model.put( MARK_ENTRY_LIST, listEntry );
3649 
3650         if ( SecurityService.isAuthenticationEnable( ) )
3651         {
3652             model.put( MARK_ROLE_REF_LIST, RoleHome.getRolesList( ) );
3653         }
3654 
3655         model.put( MARK_DIRECTORY, directory );
3656         model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
3657         model.put( MARK_LOCALE, getLocale( ) );
3658         setPageTitleProperty( PROPERTY_CREATE_DIRECTORY_RECORD_PAGE_TITLE );
3659 
3660         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_DIRECTORY_RECORD, getLocale( ), model );
3661 
3662         return getAdminPage( template.getHtml( ) );
3663     }
3664 
3665     /**
3666      * Perform the directory record creation
3667      * 
3668      * @param request
3669      *            The HTTP request
3670      * @throws AccessDeniedException
3671      *             the {@link AccessDeniedException}
3672      * @return The URL to go after performing the action
3673      */
3674     public String doCreateDirectoryRecord( HttpServletRequest request ) throws AccessDeniedException
3675     {
3676         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
3677         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
3678         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
3679 
3680         if ( ( directory == null )
3681                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_CREATE_RECORD, getUser( ) )
3682                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
3683         {
3684             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
3685         }
3686 
3687         if ( request.getParameter( PARAMETER_CANCEL ) == null )
3688         {
3689             Record record = new Record( );
3690             record.setDirectory( directory );
3691 
3692             String strRedirectUrl = getDirectoryRecordData( record, request );
3693 
3694             if ( StringUtils.isNotBlank( strRedirectUrl ) )
3695             {
3696                 return strRedirectUrl;
3697             }
3698 
3699             record.setDateCreation( DirectoryUtils.getCurrentTimestamp( ) );
3700             // Autopublication
3701             record.setEnabled( directory.isRecordActivated( ) );
3702 
3703             TransactionManager.beginTransaction( getPlugin( ) );
3704 
3705             try
3706             {
3707                 _recordService.create( record, getPlugin( ) );
3708 
3709                 if ( WorkflowService.getInstance( ).isAvailable( ) && ( directory.getIdWorkflow( ) != DirectoryUtils.CONSTANT_ID_NULL ) )
3710                 {
3711                     WorkflowService.getInstance( ).getState( record.getIdRecord( ), Record.WORKFLOW_RESOURCE_TYPE, directory.getIdWorkflow( ),
3712                             Integer.valueOf( directory.getIdDirectory( ) ) );
3713                     WorkflowService.getInstance( ).executeActionAutomatic( record.getIdRecord( ), Record.WORKFLOW_RESOURCE_TYPE, directory.getIdWorkflow( ),
3714                             Integer.valueOf( directory.getIdDirectory( ) ) );
3715                 }
3716 
3717                 TransactionManager.commitTransaction( getPlugin( ) );
3718             }
3719             catch( Exception ex )
3720             {
3721                 // something very wrong happened... a database check might be needed
3722                 AppLogService.error( ex.getMessage( ) + " for Record " + record.getIdRecord( ), ex );
3723                 // revert
3724                 TransactionManager.rollBack( getPlugin( ) );
3725 
3726                 // throw a message to the user
3727                 return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_GENERIC_MESSAGE, AdminMessage.TYPE_STOP );
3728             }
3729         }
3730 
3731         return DirectoryUtils.getJspManageDirectoryRecord( request, nIdDirectory );
3732     }
3733 
3734     /**
3735      * Return management of directory record ( list of directory record )
3736      * 
3737      * @param request
3738      *            The Http request
3739      * @throws AccessDeniedException
3740      *             the {@link AccessDeniedException}
3741      * @return Html directory
3742      */
3743     public String getModifyDirectoryRecord( HttpServletRequest request ) throws AccessDeniedException
3744     {
3745         String strIdDirectoryRecord = request.getParameter( PARAMETER_ID_DIRECTORY_RECORD );
3746         int nIdDirectoryRecord = DirectoryUtils.convertStringToInt( strIdDirectoryRecord );
3747         Record record = _recordService.findByPrimaryKey( nIdDirectoryRecord, getPlugin( ) );
3748 
3749         int nIdDirectory = record.getDirectory( ).getIdDirectory( );
3750         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
3751 
3752         if ( ( record == null )
3753                 || ( directory == null )
3754                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY_RECORD,
3755                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( record, getUser( ) )
3756                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
3757         {
3758             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
3759         }
3760 
3761         // List of entries to display
3762         List<IEntry> listEntry = DirectoryUtils.getFormEntries( record.getDirectory( ).getIdDirectory( ), getPlugin( ), getUser( ) );
3763 
3764         /**
3765          * Map of idEntry, RecordFields 1) The user has uploaded/deleted a file - The updated map is stored in the session 2) The user has not uploaded/delete
3766          * a file - The map is filled with the data from the database - The asynchronous uploaded files map is reinitialized
3767          */
3768         Map<String, List<RecordField>> map = null;
3769 
3770         // Get the map of <idEntry, RecordFields from session if it exists :
3771         /**
3772          * 1) Case when the user has uploaded a file, the the map is stored in the session
3773          */
3774         HttpSession session = request.getSession( false );
3775 
3776         if ( session != null )
3777         {
3778             map = (Map<String, List<RecordField>>) session.getAttribute( DirectoryUtils.SESSION_DIRECTORY_LIST_SUBMITTED_RECORD_FIELDS );
3779             // IMPORTANT : Remove the map from the session
3780             session.removeAttribute( DirectoryUtils.SESSION_DIRECTORY_LIST_SUBMITTED_RECORD_FIELDS );
3781         }
3782 
3783         // Get the map idEntry, RecordFields classically from the database
3784         /** 2) The user has not uploaded/delete a file */
3785         if ( map == null )
3786         {
3787             map = DirectoryUtils.getMapIdEntryListRecordField( listEntry, nIdDirectoryRecord, getPlugin( ) );
3788             // Reinit the asynchronous uploaded file map
3789             DirectoryAsynchronousUploadHandler.getHandler( ).reinitMap( request, map, getPlugin( ) );
3790         }
3791 
3792         Map<String, Object> model = new HashMap<String, Object>( );
3793 
3794         model.put( MARK_ENTRY_LIST, listEntry );
3795         model.put( MARK_MAP_ID_ENTRY_LIST_RECORD_FIELD, map );
3796         model.put( MARK_DIRECTORY, directory );
3797 
3798         if ( PortalService.isExtendActivated( ) )
3799         {
3800             ExtendableResourcePluginActionManager.fillModel( request, AdminUserService.getAdminUser( request ), model, record.getIdExtendableResource( ),
3801                     record.getExtendableResourceType( ) );
3802         }
3803 
3804         if ( SecurityService.isAuthenticationEnable( ) )
3805         {
3806             model.put( MARK_ROLE_REF_LIST, RoleHome.getRolesList( ) );
3807         }
3808 
3809         model.put( MARK_DIRECTORY_RECORD, record );
3810         model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
3811         model.put( MARK_LOCALE, getLocale( ) );
3812         setPageTitleProperty( PROPERTY_MODIFY_DIRECTORY_RECORD_PAGE_TITLE );
3813 
3814         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_DIRECTORY_RECORD, getLocale( ), model );
3815 
3816         return getAdminPage( template.getHtml( ) );
3817     }
3818 
3819     /**
3820      * Perform the directory record creation
3821      * 
3822      * @param request
3823      *            The HTTP request
3824      * @throws AccessDeniedException
3825      *             the {@link AccessDeniedException}
3826      * @return The URL to go after performing the action
3827      */
3828     public String doModifyDirectoryRecord( HttpServletRequest request ) throws AccessDeniedException
3829     {
3830         String strIdDirectoryRecord = request.getParameter( PARAMETER_ID_DIRECTORY_RECORD );
3831         int nIdDirectoryRecord = DirectoryUtils.convertStringToInt( strIdDirectoryRecord );
3832         Record record = _recordService.findByPrimaryKey( nIdDirectoryRecord, getPlugin( ) );
3833 
3834         int nIdDirectory = record.getDirectory( ).getIdDirectory( );
3835         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
3836 
3837         if ( ( record == null )
3838                 || ( directory == null )
3839                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_MODIFY_RECORD,
3840                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( record, getUser( ) )
3841                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
3842         {
3843             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
3844         }
3845 
3846         if ( request.getParameter( PARAMETER_CANCEL ) == null )
3847         {
3848             String strRedirectUrl = getDirectoryRecordData( record, request );
3849 
3850             if ( StringUtils.isNotBlank( strRedirectUrl ) )
3851             {
3852                 return strRedirectUrl;
3853             }
3854 
3855             try
3856             {
3857                 _recordService.updateWidthRecordField( record, getPlugin( ) );
3858             }
3859             catch( Exception ex )
3860             {
3861                 // something very wrong happened... a database check might be needed
3862                 AppLogService.error( ex.getMessage( ) + " when updating Record " + record.getIdRecord( ), ex );
3863 
3864                 // throw a message to the user
3865                 return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_GENERIC_MESSAGE, AdminMessage.TYPE_STOP );
3866             }
3867         }
3868 
3869         return getRedirectUrl( request );
3870     }
3871 
3872     /**
3873      * Gets the confirmation page of delete directory record
3874      * 
3875      * @param request
3876      *            The HTTP request
3877      * @throws AccessDeniedException
3878      *             the {@link AccessDeniedException}
3879      * @return the confirmation page of delete directory record
3880      */
3881     public String getConfirmRemoveDirectoryRecord( HttpServletRequest request ) throws AccessDeniedException
3882     {
3883         String [ ] listIdsDirectoryRecord = request.getParameterValues( PARAMETER_ID_DIRECTORY_RECORD );
3884 
3885         if ( ( listIdsDirectoryRecord != null ) && ( listIdsDirectoryRecord.length > 0 ) )
3886         {
3887             String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
3888 
3889             // If the id directory is not in the parameter, then fetch it from the first record
3890             // assuming all records are from the same directory
3891             if ( StringUtils.isBlank( strIdDirectory ) || !StringUtils.isNumeric( strIdDirectory ) )
3892             {
3893                 String strIdDirectoryRecord = listIdsDirectoryRecord [0];
3894                 int nIdDirectoryRecord = DirectoryUtils.convertStringToInt( strIdDirectoryRecord );
3895                 Record record = _recordService.findByPrimaryKey( nIdDirectoryRecord, getPlugin( ) );
3896                 strIdDirectory = Integer.toString( record.getDirectory( ).getIdDirectory( ) );
3897             }
3898 
3899             int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
3900             Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
3901 
3902             UrlItem url = new UrlItem( JSP_DO_REMOVE_DIRECTORY_RECORD );
3903             url.addParameter( DirectoryUtils.PARAMETER_ID_DIRECTORY, nIdDirectory );
3904 
3905             for ( String strIdDirectoryRecord : listIdsDirectoryRecord )
3906             {
3907                 int nIdDirectoryRecord = DirectoryUtils.convertStringToInt( strIdDirectoryRecord );
3908                 Record record = _recordService.findByPrimaryKey( nIdDirectoryRecord, getPlugin( ) );
3909 
3910                 if ( ( record == null )
3911                         || ( directory == null )
3912                         || ( record.getDirectory( ).getIdDirectory( ) != nIdDirectory )
3913                         || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ),
3914                                 DirectoryResourceIdService.PERMISSION_DELETE_RECORD, getUser( ) ) || !AdminWorkgroupService.isAuthorized( record, getUser( ) )
3915                         || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
3916                 {
3917                     throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
3918                 }
3919 
3920                 url.addParameter( PARAMETER_ID_DIRECTORY_RECORD, nIdDirectoryRecord );
3921             }
3922 
3923             return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_DIRECTORY_RECORD, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
3924         }
3925 
3926         return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
3927     }
3928 
3929     /**
3930      * Perform the directory record supression
3931      * 
3932      * @param request
3933      *            The HTTP request
3934      * @throws AccessDeniedException
3935      *             the {@link AccessDeniedException}
3936      * @return The URL to go after performing the action
3937      */
3938     public String doRemoveDirectoryRecord( HttpServletRequest request ) throws AccessDeniedException
3939     {
3940         String [ ] listIdsDirectoryRecord = request.getParameterValues( PARAMETER_ID_DIRECTORY_RECORD );
3941 
3942         if ( ( listIdsDirectoryRecord != null ) && ( listIdsDirectoryRecord.length > 0 ) )
3943         {
3944             String strIdDirectory = request.getParameter( DirectoryUtils.PARAMETER_ID_DIRECTORY );
3945             int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
3946             Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
3947             List<String> listErrors = new ArrayList<String>( );
3948 
3949             for ( String strIdDirectoryRecord : listIdsDirectoryRecord )
3950             {
3951                 int nIdDirectoryRecord = DirectoryUtils.convertStringToInt( strIdDirectoryRecord );
3952                 Record record = _recordService.findByPrimaryKey( nIdDirectoryRecord, getPlugin( ) );
3953 
3954                 if ( ( record == null )
3955                         || ( directory == null )
3956                         || ( record.getDirectory( ).getIdDirectory( ) != nIdDirectory )
3957                         || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ),
3958                                 DirectoryResourceIdService.PERMISSION_DELETE_RECORD, getUser( ) ) || !AdminWorkgroupService.isAuthorized( record, getUser( ) )
3959                         || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
3960                 {
3961                     throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
3962                 }
3963 
3964                 if ( !RecordRemovalListenerService.getService( ).checkForRemoval( strIdDirectoryRecord, listErrors, getLocale( ) ) )
3965                 {
3966                     String strCause = AdminMessageService.getFormattedList( listErrors, getLocale( ) );
3967                     Object [ ] args = {
3968                         strCause
3969                     };
3970 
3971                     return AdminMessageService.getMessageUrl( request, MESSAGE_CANNOT_REMOVE_RECORD, args, AdminMessage.TYPE_STOP );
3972                 }
3973 
3974                 try
3975                 {
3976                     _recordService.remove( nIdDirectoryRecord, getPlugin( ) );
3977                 }
3978                 catch( Exception ex )
3979                 {
3980                     // something very wrong happened... a database check might be needed
3981                     AppLogService.error( ex.getMessage( ) + " when deleting Record " + record.getIdRecord( ), ex );
3982 
3983                     // throw a message to the user
3984                     return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_GENERIC_MESSAGE, AdminMessage.TYPE_STOP );
3985                 }
3986 
3987                 WorkflowService.getInstance( ).doRemoveWorkFlowResource( nIdDirectoryRecord, Record.WORKFLOW_RESOURCE_TYPE );
3988             }
3989 
3990             return DirectoryUtils.getJspManageDirectoryRecord( request, nIdDirectory );
3991         }
3992 
3993         return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
3994     }
3995 
3996     /**
3997      * copy the directory whose key is specified in the Http request
3998      * 
3999      * @param request
4000      *            The HTTP request
4001      * @throws AccessDeniedException
4002      *             the {@link AccessDeniedException}
4003      * @return The URL to go after performing the action
4004      */
4005     public String doCopyDirectoryRecord( HttpServletRequest request ) throws AccessDeniedException
4006     {
4007         String strIdDirectoryRecord = request.getParameter( PARAMETER_ID_DIRECTORY_RECORD );
4008         int nIdDirectoryRecord = DirectoryUtils.convertStringToInt( strIdDirectoryRecord );
4009         Record record = _recordService.findByPrimaryKey( nIdDirectoryRecord, getPlugin( ) );
4010 
4011         int nIdDirectory = record.getDirectory( ).getIdDirectory( );
4012         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
4013 
4014         if ( ( record == null )
4015                 || ( directory == null )
4016                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_COPY_RECORD,
4017                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( record, getUser( ) )
4018                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
4019         {
4020             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
4021         }
4022 
4023         record.setDateCreation( DirectoryUtils.getCurrentTimestamp( ) );
4024 
4025         try
4026         {
4027             _recordService.copy( record, getPlugin( ) );
4028         }
4029         catch( Exception ex )
4030         {
4031             // something very wrong happened... a database check might be needed
4032             AppLogService.error( ex.getMessage( ) + " when copying Record " + record.getIdRecord( ), ex );
4033 
4034             // Revert
4035             _recordService.remove( record.getIdRecord( ), getPlugin( ) );
4036 
4037             // throw a message to the user
4038             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_GENERIC_MESSAGE, AdminMessage.TYPE_STOP );
4039         }
4040 
4041         if ( WorkflowService.getInstance( ).isAvailable( ) && ( directory.getIdWorkflow( ) != DirectoryUtils.CONSTANT_ID_NULL ) )
4042         {
4043             WorkflowService.getInstance( ).getState( record.getIdRecord( ), Record.WORKFLOW_RESOURCE_TYPE, directory.getIdWorkflow( ),
4044                     Integer.valueOf( directory.getIdDirectory( ) ) );
4045             WorkflowService.getInstance( ).executeActionAutomatic( record.getIdRecord( ), Record.WORKFLOW_RESOURCE_TYPE, directory.getIdWorkflow( ),
4046                     Integer.valueOf( directory.getIdDirectory( ) ) );
4047         }
4048 
4049         return getRedirectUrl( request );
4050     }
4051 
4052     /**
4053      * Gets the confirmation page of disable directory record
4054      * 
4055      * @param request
4056      *            The HTTP request
4057      * @throws AccessDeniedException
4058      *             the {@link AccessDeniedException}
4059      * @return the confirmation page of disable directory record
4060      */
4061     public String getConfirmDisableDirectoryRecord( HttpServletRequest request ) throws AccessDeniedException
4062     {
4063         String strIdDirectoryRecord = request.getParameter( PARAMETER_ID_DIRECTORY_RECORD );
4064         int nIdDirectoryRecord = DirectoryUtils.convertStringToInt( strIdDirectoryRecord );
4065         Record record = _recordService.findByPrimaryKey( nIdDirectoryRecord, getPlugin( ) );
4066         String strMessage;
4067 
4068         int nIdDirectory = record.getDirectory( ).getIdDirectory( );
4069         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
4070 
4071         if ( ( record == null )
4072                 || ( directory == null )
4073                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ),
4074                         DirectoryResourceIdService.PERMISSION_CHANGE_STATE_RECORD, getUser( ) ) || !AdminWorkgroupService.isAuthorized( record, getUser( ) )
4075                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
4076         {
4077             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
4078         }
4079 
4080         strMessage = MESSAGE_CONFIRM_DISABLE_DIRECTORY_RECORD;
4081 
4082         UrlItem url = new UrlItem( JSP_DO_DISABLE_DIRECTORY_RECORD );
4083         url.addParameter( PARAMETER_ID_DIRECTORY_RECORD, strIdDirectoryRecord );
4084 
4085         return AdminMessageService.getMessageUrl( request, strMessage, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
4086     }
4087 
4088     /**
4089      * Perform disable directory record
4090      * 
4091      * @param request
4092      *            The HTTP request
4093      * @throws AccessDeniedException
4094      *             the {@link AccessDeniedException}
4095      * @return The URL to go after performing the action
4096      */
4097     public String doDisableDirectoryRecord( HttpServletRequest request ) throws AccessDeniedException
4098     {
4099         String strIdDirectoryRecord = request.getParameter( PARAMETER_ID_DIRECTORY_RECORD );
4100         int nIdDirectoryRecord = DirectoryUtils.convertStringToInt( strIdDirectoryRecord );
4101         Record record = _recordService.findByPrimaryKey( nIdDirectoryRecord, getPlugin( ) );
4102 
4103         int nIdDirectory = record.getDirectory( ).getIdDirectory( );
4104         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
4105 
4106         if ( ( record == null )
4107                 || ( directory == null )
4108                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ),
4109                         DirectoryResourceIdService.PERMISSION_CHANGE_STATE_RECORD, getUser( ) ) || !AdminWorkgroupService.isAuthorized( record, getUser( ) )
4110                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
4111         {
4112             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
4113         }
4114 
4115         record.setEnabled( false );
4116 
4117         try
4118         {
4119             _recordService.update( record, getPlugin( ) );
4120         }
4121         catch( Exception ex )
4122         {
4123             // something very wrong happened... a database check might be needed
4124             AppLogService.error( ex.getMessage( ) + " when disabling Record " + record.getIdRecord( ), ex );
4125 
4126             // throw a message to the user
4127             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_GENERIC_MESSAGE, AdminMessage.TYPE_STOP );
4128         }
4129 
4130         return getRedirectUrl( request );
4131     }
4132 
4133     /**
4134      * Perform enable directory record
4135      * 
4136      * @param request
4137      *            The HTTP request
4138      * @throws AccessDeniedException
4139      *             the {@link AccessDeniedException}
4140      * @return The URL to go after performing the action
4141      */
4142     public String doEnableDirectoryRecord( HttpServletRequest request ) throws AccessDeniedException
4143     {
4144         String strIdDirectoryRecord = request.getParameter( PARAMETER_ID_DIRECTORY_RECORD );
4145         int nIdDirectoryRecord = DirectoryUtils.convertStringToInt( strIdDirectoryRecord );
4146         Record record = _recordService.findByPrimaryKey( nIdDirectoryRecord, getPlugin( ) );
4147 
4148         int nIdDirectory = record.getDirectory( ).getIdDirectory( );
4149         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
4150 
4151         if ( ( record == null )
4152                 || ( directory == null )
4153                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ),
4154                         DirectoryResourceIdService.PERMISSION_CHANGE_STATE_RECORD, getUser( ) ) || !AdminWorkgroupService.isAuthorized( record, getUser( ) )
4155                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
4156         {
4157             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
4158         }
4159 
4160         record.setEnabled( true );
4161 
4162         try
4163         {
4164             _recordService.update( record, getPlugin( ) );
4165         }
4166         catch( Exception ex )
4167         {
4168             // something very wrong happened... a database check might be needed
4169             AppLogService.error( ex.getMessage( ) + " when enabling Record " + record.getIdRecord( ), ex );
4170 
4171             // throw a message to the user
4172             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_GENERIC_MESSAGE, AdminMessage.TYPE_STOP );
4173         }
4174 
4175         return getRedirectUrl( request );
4176     }
4177 
4178     /**
4179      * return the tasks form
4180      * 
4181      * @param request
4182      *            the request
4183      * @return the tasks form
4184      */
4185     public String getTasksForm( HttpServletRequest request )
4186     {
4187         String [ ] listIdsDirectoryRecord = request.getParameterValues( DirectoryUtils.PARAMETER_ID_DIRECTORY_RECORD );
4188         String strIdAction = request.getParameter( PARAMETER_ID_ACTION );
4189 
4190         if ( ( listIdsDirectoryRecord != null ) && ( listIdsDirectoryRecord.length > 0 ) && StringUtils.isNotBlank( strIdAction )
4191                 && StringUtils.isNumeric( strIdAction ) )
4192         {
4193             int nIdAction = DirectoryUtils.convertStringToInt( strIdAction );
4194 
4195             /*
4196              * DIRECTORY-126 : Add new direction action : Mass Workflow action Only the first record task form is displayed because the id resource is not
4197              * relevant when displaying the task form.
4198              */
4199             String strIdDirectoryRecord = listIdsDirectoryRecord [0];
4200             int nIdRecord = DirectoryUtils.convertStringToInt( strIdDirectoryRecord );
4201             String strHtmlTasksForm = WorkflowService.getInstance( ).getDisplayTasksForm( nIdRecord, Record.WORKFLOW_RESOURCE_TYPE, nIdAction, request,
4202                     getLocale( ) );
4203 
4204             Map<String, Object> model = new HashMap<String, Object>( );
4205 
4206             model.put( MARK_TASKS_FORM, strHtmlTasksForm );
4207             model.put( MARK_ID_ACTION, nIdAction );
4208             model.put( MARK_LIST_IDS_DIRECTORY_RECORD, listIdsDirectoryRecord );
4209             model.put( MARK_SHOW_ACTION_RESULT, request.getParameter( DirectoryUtils.PARAMETER_SHOW_ACTION_RESULT ) );
4210 
4211             setPageTitleProperty( PROPERTY_TASKS_FORM_WORKFLOW_PAGE_TITLE );
4212 
4213             HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_TASKS_FORM_WORKFLOW, getLocale( ), model );
4214 
4215             return getAdminPage( templateList.getHtml( ) );
4216         }
4217 
4218         return getManageDirectory( request );
4219     }
4220 
4221     /**
4222      * save the tasks form
4223      * 
4224      * @param request
4225      *            the httpRequest
4226      * @return The URL to go after performing the action
4227      */
4228     public String doSaveTasksForm( HttpServletRequest request )
4229     {
4230         String [ ] listIdsDirectoryRecord = request.getParameterValues( DirectoryUtils.PARAMETER_ID_DIRECTORY_RECORD );
4231 
4232         if ( ( listIdsDirectoryRecord != null ) && ( listIdsDirectoryRecord.length > 0 ) )
4233         {
4234             String strIdDirectory = request.getParameter( DirectoryUtils.PARAMETER_ID_DIRECTORY );
4235 
4236             // If the id directory is not in the parameter, then fetch it from the first record
4237             // assuming all records are from the same directory
4238             if ( StringUtils.isBlank( strIdDirectory ) || !StringUtils.isNumeric( strIdDirectory ) )
4239             {
4240                 String strIdDirectoryRecord = listIdsDirectoryRecord [0];
4241                 int nIdDirectoryRecord = DirectoryUtils.convertStringToInt( strIdDirectoryRecord );
4242                 Record record = _recordService.findByPrimaryKey( nIdDirectoryRecord, getPlugin( ) );
4243                 strIdDirectory = Integer.toString( record.getDirectory( ).getIdDirectory( ) );
4244             }
4245 
4246             int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
4247 
4248             if ( request.getParameter( PARAMETER_CANCEL ) == null )
4249             {
4250                 String strShowActionResult = request.getParameter( DirectoryUtils.PARAMETER_SHOW_ACTION_RESULT );
4251                 boolean bShowActionResult = StringUtils.isNotBlank( strShowActionResult );
4252 
4253                 // Case when the user is uploading a file
4254                 String strUploadAction = DirectoryAsynchronousUploadHandler.getHandler( ).getUploadAction( request );
4255 
4256                 if ( StringUtils.isNotBlank( strUploadAction ) )
4257                 {
4258                     Map<String, List<RecordField>> mapRecordFields = null;
4259 
4260                     /**
4261                      * 1) Case when the user has uploaded a file, the the map is stored in the session
4262                      */
4263                     HttpSession session = request.getSession( );
4264                     mapRecordFields = (Map<String, List<RecordField>>) session.getAttribute( DirectoryUtils.SESSION_DIRECTORY_TASKS_SUBMITTED_RECORD_FIELDS );
4265 
4266                     /** 2) The user has not uploaded/delete a file */
4267                     if ( mapRecordFields == null )
4268                     {
4269                         mapRecordFields = new HashMap<String, List<RecordField>>( );
4270                     }
4271 
4272                     String strIdAction = request.getParameter( PARAMETER_ID_ACTION );
4273                     int nIdAction = DirectoryUtils.convertStringToInt( strIdAction );
4274 
4275                     try
4276                     {
4277                         DirectoryAsynchronousUploadHandler.getHandler( ).doUploadAction( request, strUploadAction, mapRecordFields, null, getPlugin( ) );
4278                     }
4279                     catch( DirectoryErrorException error )
4280                     {
4281                         String strErrorMessage = DirectoryUtils.EMPTY_STRING;
4282 
4283                         if ( error.isMandatoryError( ) )
4284                         {
4285                             Object [ ] tabRequiredFields = {
4286                                 error.getTitleField( )
4287                             };
4288                             strErrorMessage = AdminMessageService.getMessageUrl( request, MESSAGE_DIRECTORY_ERROR_MANDATORY_FIELD, tabRequiredFields,
4289                                     AdminMessage.TYPE_STOP );
4290                         }
4291                         else
4292                         {
4293                             Object [ ] tabRequiredFields = {
4294                                     error.getTitleField( ), error.getErrorMessage( )
4295                             };
4296                             strErrorMessage = AdminMessageService.getMessageUrl( request, MESSAGE_DIRECTORY_ERROR, tabRequiredFields, AdminMessage.TYPE_STOP );
4297                         }
4298 
4299                         return strErrorMessage;
4300                     }
4301 
4302                     // Store the map in the session
4303                     session.setAttribute( DirectoryUtils.SESSION_DIRECTORY_TASKS_SUBMITTED_RECORD_FIELDS, mapRecordFields );
4304 
4305                     return getJspTasksForm( request, listIdsDirectoryRecord, nIdAction, bShowActionResult );
4306                 }
4307 
4308                 String strIdAction = request.getParameter( DirectoryUtils.PARAMETER_ID_ACTION );
4309                 int nIdAction = DirectoryUtils.convertStringToInt( strIdAction );
4310 
4311                 String strError = _directoryActionResult.doSaveTaskForm( nIdDirectory, nIdAction, listIdsDirectoryRecord, getPlugin( ), getLocale( ), request );
4312 
4313                 if ( StringUtils.isNotBlank( strError ) )
4314                 {
4315                     return strError;
4316                 }
4317 
4318                 if ( bShowActionResult )
4319                 {
4320                     return getJspActionResults( request, nIdDirectory, nIdAction );
4321                 }
4322             }
4323 
4324             return getRedirectUrl( request );
4325         }
4326 
4327         return getJspManageDirectory( request );
4328     }
4329 
4330     /**
4331      * return the resource history
4332      * 
4333      * @param request
4334      *            the httpRequest
4335      * @throws AccessDeniedException
4336      *             AccessDeniedException
4337      * @return the resource history
4338      */
4339     public String getResourceHistory( HttpServletRequest request ) throws AccessDeniedException
4340     {
4341         String strIdRecord = request.getParameter( PARAMETER_ID_DIRECTORY_RECORD );
4342         int nIdRecord = DirectoryUtils.convertStringToInt( strIdRecord );
4343 
4344         Record record = _recordService.findByPrimaryKey( nIdRecord, getPlugin( ) );
4345         int nIdDirectory = record.getDirectory( ).getIdDirectory( );
4346         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
4347         int nIdWorkflow = ( DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) ) ).getIdWorkflow( );
4348 
4349         // Get asynchronous file names
4350         boolean bGetFileName = true;
4351 
4352         if ( ( record == null )
4353                 || ( directory == null )
4354                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ), DirectoryResourceIdService.PERMISSION_HISTORY_RECORD,
4355                         getUser( ) ) || !AdminWorkgroupService.isAuthorized( record, getUser( ) )
4356                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
4357         {
4358             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
4359         }
4360 
4361         EntryFilter filter;
4362         filter = new EntryFilter( );
4363         filter.setIdDirectory( record.getDirectory( ).getIdDirectory( ) );
4364         filter.setIsShownInHistory( EntryFilter.FILTER_TRUE );
4365 
4366         List<IEntry> listEntry = EntryHome.getEntryList( filter, getPlugin( ) );
4367 
4368         // List directory actions
4369         List<DirectoryAction> listActionsForDirectoryEnable = DirectoryActionHome.selectActionsRecordByFormState( Directory.STATE_ENABLE, getPlugin( ),
4370                 getLocale( ) );
4371         List<DirectoryAction> listActionsForDirectoryDisable = DirectoryActionHome.selectActionsRecordByFormState( Directory.STATE_DISABLE, getPlugin( ),
4372                 getLocale( ) );
4373 
4374         listActionsForDirectoryEnable = (List<DirectoryAction>) RBACService.getAuthorizedActionsCollection( listActionsForDirectoryEnable,
4375                 record.getDirectory( ), getUser( ) );
4376         listActionsForDirectoryDisable = (List<DirectoryAction>) RBACService.getAuthorizedActionsCollection( listActionsForDirectoryDisable,
4377                 record.getDirectory( ), getUser( ) );
4378 
4379         _searchFields.setRedirectUrl( request );
4380         _searchFields.setItemNavigatorHistory( nIdRecord, AppPathService.getBaseUrl( request ) + JSP_RESOURCE_HISTORY,
4381                 DirectoryUtils.PARAMETER_ID_DIRECTORY_RECORD );
4382 
4383         boolean bHistoryEnabled = WorkflowService.getInstance( ).isAvailable( ) && ( directory.getIdWorkflow( ) != DirectoryUtils.CONSTANT_ID_NULL );
4384 
4385         Map<String, Object> model = new HashMap<String, Object>( );
4386 
4387         if ( directory != null )
4388         {
4389             if ( directory.isDateShownInHistory( ) )
4390             {
4391                 model.put( MARK_RECORD_DATE_CREATION, record.getDateCreation( ) );
4392             }
4393 
4394             if ( directory.isDateModificationShownInHistory( ) )
4395             {
4396                 model.put( MARK_RECORD_DATE_MODIFICATION, record.getDateModification( ) );
4397             }
4398         }
4399 
4400         model.put( MARK_RECORD, record );
4401         model.put( MARK_ENTRY_LIST, listEntry );
4402         model.put( MARK_DIRECTORY, directory );
4403         model.put( MARK_MAP_ID_ENTRY_LIST_RECORD_FIELD, DirectoryUtils.getMapIdEntryListRecordField( listEntry, nIdRecord, getPlugin( ), bGetFileName ) );
4404 
4405         model.put( MARK_RESOURCE_HISTORY,
4406                 WorkflowService.getInstance( ).getDisplayDocumentHistory( nIdRecord, Record.WORKFLOW_RESOURCE_TYPE, nIdWorkflow, request, getLocale( ) ) );
4407         model.put(
4408                 MARK_RESOURCE_ACTIONS,
4409                 DirectoryService.getInstance( ).getResourceAction( record, directory, listEntry, getUser( ), listActionsForDirectoryEnable,
4410                         listActionsForDirectoryDisable, bGetFileName, getPlugin( ) ) );
4411         model.put( MARK_ITEM_NAVIGATOR, _searchFields.getItemNavigatorHistory( ) );
4412         model.put( MARK_HISTORY_WORKFLOW_ENABLED, bHistoryEnabled );
4413 
4414         setPageTitleProperty( PROPERTY_RESOURCE_HISTORY_PAGE_TITLE );
4415 
4416         HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_RESOURCE_HISTORY, getLocale( ), model );
4417 
4418         return getAdminPage( templateList.getHtml( ) );
4419     }
4420 
4421     /**
4422      * return the record visualisation
4423      * 
4424      * @param request
4425      *            the Http request
4426      * @return the record visualisation
4427      * @throws AccessDeniedException
4428      *             AccessDeniedException
4429      */
4430     public String getRecordVisualisation( HttpServletRequest request ) throws AccessDeniedException
4431     {
4432         String strIdRecord = request.getParameter( PARAMETER_ID_DIRECTORY_RECORD );
4433         int nIdRecord = DirectoryUtils.convertStringToInt( strIdRecord );
4434         EntryFilter filter;
4435 
4436         Record record = _recordService.findByPrimaryKey( nIdRecord, getPlugin( ) );
4437 
4438         int nIdDirectory = record.getDirectory( ).getIdDirectory( );
4439         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
4440 
4441         if ( ( record == null )
4442                 || ( directory == null )
4443                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ),
4444                         DirectoryResourceIdService.PERMISSION_VISUALISATION_RECORD, getUser( ) ) || !AdminWorkgroupService.isAuthorized( record, getUser( ) )
4445                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
4446         {
4447             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
4448         }
4449 
4450         filter = new EntryFilter( );
4451         filter.setIdDirectory( record.getDirectory( ).getIdDirectory( ) );
4452         filter.setIsGroup( EntryFilter.FILTER_TRUE );
4453 
4454         List<IEntry> listEntry = DirectoryUtils.getFormEntries( record.getDirectory( ).getIdDirectory( ), getPlugin( ), getUser( ) );
4455 
4456         // List directory actions
4457         List<DirectoryAction> listActionsForDirectoryEnable = DirectoryActionHome.selectActionsRecordByFormState( Directory.STATE_ENABLE, getPlugin( ),
4458                 getLocale( ) );
4459         List<DirectoryAction> listActionsForDirectoryDisable = DirectoryActionHome.selectActionsRecordByFormState( Directory.STATE_DISABLE, getPlugin( ),
4460                 getLocale( ) );
4461 
4462         listActionsForDirectoryEnable = (List<DirectoryAction>) RBACService
4463                 .getAuthorizedActionsCollection( listActionsForDirectoryEnable, directory, getUser( ) );
4464         listActionsForDirectoryDisable = (List<DirectoryAction>) RBACService.getAuthorizedActionsCollection( listActionsForDirectoryDisable, directory,
4465                 getUser( ) );
4466 
4467         _searchFields.setRedirectUrl( request );
4468         _searchFields.setItemNavigatorViewRecords( nIdRecord, AppPathService.getBaseUrl( request ) + JSP_DO_VISUALISATION_RECORD,
4469                 DirectoryUtils.PARAMETER_ID_DIRECTORY_RECORD );
4470 
4471         boolean bHistoryEnabled = WorkflowService.getInstance( ).isAvailable( ) && ( directory.getIdWorkflow( ) != DirectoryUtils.CONSTANT_ID_NULL );
4472 
4473         // Get asynchronous file names
4474         boolean bGetFileName = true;
4475 
4476         Map<String, Object> model = new HashMap<String, Object>( );
4477 
4478         model.put( MARK_RECORD, record );
4479         model.put( MARK_ENTRY_LIST, listEntry );
4480         model.put( MARK_DIRECTORY, directory );
4481         model.put( MARK_LOCALE, getLocale( ) );
4482         model.put( MARK_ID_ENTRY_TYPE_GEOLOCATION, AppPropertiesService.getPropertyInt( PROPERTY_ENTRY_TYPE_GEOLOCATION, 16 ) );
4483         model.put( MARK_ID_ENTRY_TYPE_IMAGE, AppPropertiesService.getPropertyInt( PROPERTY_ENTRY_TYPE_IMAGE, 10 ) );
4484         model.put( MARK_ID_ENTRY_TYPE_MYLUTECE_USER, AppPropertiesService.getPropertyInt( PROPERTY_ENTRY_TYPE_MYLUTECE_USER, 19 ) );
4485         model.put( MARK_PERMISSION_VISUALISATION_MYLUTECE_USER, RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ),
4486                 DirectoryResourceIdService.PERMISSION_VISUALISATION_MYLUTECE_USER, getUser( ) ) );
4487         model.put( MARK_MAP_ID_ENTRY_LIST_RECORD_FIELD, DirectoryUtils.getMapIdEntryListRecordField( listEntry, nIdRecord, getPlugin( ) ) );
4488 
4489         model.put( MARK_SHOW_DATE_CREATION_RECORD, directory.isDateShownInResultRecord( ) );
4490         model.put( MARK_SHOW_DATE_MODIFICATION_RECORD, directory.isDateModificationShownInResultRecord( ) );
4491         model.put(
4492                 MARK_RESOURCE_ACTIONS,
4493                 DirectoryService.getInstance( ).getResourceAction( record, directory, listEntry, getUser( ), listActionsForDirectoryEnable,
4494                         listActionsForDirectoryDisable, bGetFileName, getPlugin( ) ) );
4495         model.put( MARK_ITEM_NAVIGATOR, _searchFields.getItemNavigatorViewRecords( ) );
4496         model.put( MARK_HISTORY_WORKFLOW_ENABLED, bHistoryEnabled );
4497 
4498         HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_VIEW_DIRECTORY_RECORD, getLocale( ), model );
4499 
4500         return getAdminPage( templateList.getHtml( ) );
4501     }
4502 
4503     /**
4504      * Get the html for action result
4505      * 
4506      * @param request
4507      *            the HTTP request
4508      * @return the html code
4509      */
4510     public String getActionResult( HttpServletRequest request )
4511     {
4512         String strIdDirectory = request.getParameter( DirectoryUtils.PARAMETER_ID_DIRECTORY );
4513         String strIdAction = request.getParameter( DirectoryUtils.PARAMETER_ID_ACTION );
4514 
4515         if ( StringUtils.isNotBlank( strIdDirectory ) && StringUtils.isNumeric( strIdDirectory ) && StringUtils.isNotBlank( strIdAction )
4516                 && StringUtils.isNumeric( strIdAction ) )
4517         {
4518             int nIdAction = DirectoryUtils.convertStringToInt( strIdAction );
4519             int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
4520             Map<String, Object> model = new HashMap<String, Object>( );
4521 
4522             // Add directory to the model
4523             Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
4524 
4525             if ( directory == null )
4526             {
4527                 return getManageDirectory( request );
4528             }
4529 
4530             model.put( MARK_DIRECTORY, directory );
4531 
4532             // Add the action to the model
4533             for ( Action action : WorkflowService.getInstance( ).getMassActions( directory.getIdWorkflow( ) ) )
4534             {
4535                 if ( action.getId( ) == nIdAction )
4536                 {
4537                     model.put( MARK_ACTION, action );
4538 
4539                     break;
4540                 }
4541             }
4542 
4543             // Add the entries list to show in the model
4544             EntryFilter entryFilter = new EntryFilter( );
4545             entryFilter.setIdDirectory( nIdDirectory );
4546             entryFilter.setIsGroup( EntryFilter.FILTER_FALSE );
4547             entryFilter.setIsComment( EntryFilter.FILTER_FALSE );
4548             entryFilter.setIsShownInResultList( EntryFilter.FILTER_TRUE );
4549 
4550             List<IEntry> listEntries = EntryHome.getEntryList( entryFilter, getPlugin( ) );
4551             model.put( MARK_ENTRY_LIST, listEntries );
4552 
4553             _directoryActionResult.fillModel( model, listEntries, getPlugin( ), getUser( ), directory );
4554 
4555             model.put( MARK_LOCALE, request.getLocale( ) );
4556 
4557             HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_ACTION_RESULT, getLocale( ), model );
4558 
4559             return getAdminPage( templateList.getHtml( ) );
4560         }
4561 
4562         return getManageDirectory( request );
4563     }
4564 
4565     /**
4566      * return url of the jsp manage directory
4567      * 
4568      * @param request
4569      *            The HTTP request
4570      * @return url of the jsp manage directory
4571      */
4572     private String getJspManageDirectory( HttpServletRequest request )
4573     {
4574         return AppPathService.getBaseUrl( request ) + JSP_MANAGE_DIRECTORY;
4575     }
4576 
4577     /**
4578      * return url of the jsp modify directory
4579      * 
4580      * @param request
4581      *            The HTTP request
4582      * @param nIdDirectory
4583      *            the key of directory to modify
4584      * @return return url of the jsp modify directorys
4585      */
4586     private String getJspModifyDirectory( HttpServletRequest request, int nIdDirectory )
4587     {
4588         return AppPathService.getBaseUrl( request ) + JSP_MODIFY_DIRECTORY + "?" + PARAMETER_ID_DIRECTORY + "=" + nIdDirectory;
4589     }
4590 
4591     /**
4592      * return url of the jsp modify entry
4593      * 
4594      * @param request
4595      *            The HTTP request
4596      * @param nIdEntry
4597      *            the key of the entry to modify
4598      * @return return url of the jsp modify entry
4599      */
4600     private String getJspModifyEntry( HttpServletRequest request, int nIdEntry )
4601     {
4602         return AppPathService.getBaseUrl( request ) + JSP_MODIFY_ENTRY + "?" + PARAMETER_ID_ENTRY + "=" + nIdEntry;
4603     }
4604 
4605     /**
4606      * return url of the jsp modify field
4607      * 
4608      * @param request
4609      *            The HTTP request
4610      * @param nIdField
4611      *            the key of the field to modify
4612      * @return return url of the jsp modify field
4613      */
4614     private String getJspModifyField( HttpServletRequest request, int nIdField )
4615     {
4616         return AppPathService.getBaseUrl( request ) + JSP_MODIFY_FIELD + "?" + PARAMETER_ID_FIELD + "=" + nIdField;
4617     }
4618 
4619     /**
4620      * return url of the jsp print mass
4621      * 
4622      * @param request
4623      *            The HTTP request
4624      * @param nIdDirectory
4625      *            the directory id
4626      * @param strIdStateList
4627      *            the list of id state
4628      * @return url of the jsp print mass
4629      */
4630     private String getJspPrintMass( HttpServletRequest request, int nIdDirectory, String strIdStateList )
4631     {
4632         return AppPathService.getBaseUrl( request ) + JSP_DISPLAY_PRINT_HISTORY + "?" + PARAMETER_ID_DIRECTORY + "=" + nIdDirectory + "&" + PARAMETER_ID_STATE
4633                 + "=" + strIdStateList;
4634     }
4635 
4636     /**
4637      * return url of the jsp import directory record
4638      * 
4639      * @param request
4640      *            The HTTP request
4641      * @param nIdDirectory
4642      *            the directory id
4643      * @return url of the jsp import directory record
4644      */
4645     private String getJspImportDirectoryRecord( HttpServletRequest request, int nIdDirectory )
4646     {
4647         return AppPathService.getBaseUrl( request ) + JSP_IMPORT_DIRECTORY_RECORD + "?" + PARAMETER_ID_DIRECTORY + "=" + nIdDirectory + "&" + PARAMETER_SESSION
4648                 + "=" + PARAMETER_SESSION;
4649     }
4650 
4651     /**
4652      * return url of the jsp manage directory
4653      * 
4654      * @param request
4655      *            The HTTP request
4656      * @return url of the jsp manage directory
4657      */
4658     private String getJspManageAdvancedParameters( HttpServletRequest request )
4659     {
4660         return AppPathService.getBaseUrl( request ) + JSP_MANAGE_ADVANCED_PARAMETERS;
4661     }
4662 
4663     /**
4664      * Return url of the jsp action results
4665      * 
4666      * @param request
4667      *            the HTTP request
4668      * @param nIdDirectory
4669      *            the id directory
4670      * @param nIdAction
4671      *            the id action
4672      * @return the JSP
4673      */
4674     private String getJspActionResults( HttpServletRequest request, int nIdDirectory, int nIdAction )
4675     {
4676         UrlItem url = new UrlItem( AppPathService.getBaseUrl( request ) + JSP_ACTION_RESULT );
4677         url.addParameter( DirectoryUtils.PARAMETER_ID_DIRECTORY, nIdDirectory );
4678         url.addParameter( PARAMETER_ID_ACTION, nIdAction );
4679 
4680         return url.getUrl( );
4681     }
4682 
4683     /**
4684      * return url of the jsp create directory record
4685      * 
4686      * @param request
4687      *            The HTTP request
4688      * @param nIdDirectory
4689      *            the key of directory
4690      * @return return url of the jsp create directory record
4691      */
4692     private String getJspCreateDirectoryRecord( HttpServletRequest request, int nIdDirectory )
4693     {
4694         return AppPathService.getBaseUrl( request ) + JSP_CREATE_DIRECTORY_RECORD + "?" + PARAMETER_ID_DIRECTORY + "=" + nIdDirectory;
4695     }
4696 
4697     /**
4698      * return url of the jsp modify directory record
4699      * 
4700      * @param request
4701      *            The HTTP request
4702      * @param nIdDirectory
4703      *            the key of directory
4704      * @param nIdDirectoryRecord
4705      *            the key of directory record to modify
4706      * @return return url of the jsp modify directory record
4707      */
4708     private String getJspModifyDirectoryRecord( HttpServletRequest request, int nIdDirectory, int nIdDirectoryRecord )
4709     {
4710         return AppPathService.getBaseUrl( request ) + JSP_MODIFY_DIRECTORY_RECORD + "?" + PARAMETER_ID_DIRECTORY + "=" + nIdDirectory + "&"
4711                 + PARAMETER_ID_DIRECTORY_RECORD + "=" + nIdDirectoryRecord;
4712     }
4713 
4714     /**
4715      * return a reference list wich contains the different state of directory
4716      * 
4717      * @param locale
4718      *            the locale
4719      * @return reference list of directory state
4720      */
4721     private ReferenceList getRefListActive( Locale locale )
4722     {
4723         ReferenceList refListState = new ReferenceList( );
4724         String strAll = I18nService.getLocalizedString( PROPERTY_ALL, locale );
4725         String strYes = I18nService.getLocalizedString( PROPERTY_YES, locale );
4726         String strNo = I18nService.getLocalizedString( PROPERTY_NO, locale );
4727 
4728         refListState.addItem( -1, strAll );
4729         refListState.addItem( 1, strYes );
4730         refListState.addItem( 0, strNo );
4731 
4732         return refListState;
4733     }
4734 
4735     /**
4736      * reinit directory recordFilter
4737      */
4738     private void reInitDirectoryRecordFilter( )
4739     {
4740         _searchFields.setItemsPerPageDirectoryRecord( 0 );
4741         _searchFields.setCurrentPageIndexDirectory( null );
4742         _searchFields.setMapQuery( null );
4743         _searchFields.setItemNavigatorViewRecords( null );
4744         _searchFields.setItemNavigatorHistory( null );
4745         _searchFields.setSortEntry( null );
4746         _searchFields.setSortOrder( RecordFieldFilter.ORDER_NONE );
4747     }
4748 
4749     /**
4750      * Do process the workflow actions
4751      * 
4752      * @param request
4753      *            the HTTP request
4754      * @return the JSP return
4755      */
4756     public String doProcessAction( HttpServletRequest request )
4757     {
4758         String [ ] listIdsDirectoryRecord = request.getParameterValues( DirectoryUtils.PARAMETER_ID_DIRECTORY_RECORD );
4759 
4760         if ( ( listIdsDirectoryRecord != null ) && ( listIdsDirectoryRecord.length > 0 ) )
4761         {
4762             String strShowActionResult = request.getParameter( DirectoryUtils.PARAMETER_SHOW_ACTION_RESULT );
4763             boolean bShowActionResult = StringUtils.isNotBlank( strShowActionResult );
4764 
4765             String strIdAction = request.getParameter( DirectoryUtils.PARAMETER_ID_ACTION );
4766             int nIdAction = DirectoryUtils.convertStringToInt( strIdAction );
4767 
4768             if ( WorkflowService.getInstance( ).isDisplayTasksForm( nIdAction, getLocale( ) ) )
4769             {
4770                 return getJspTasksForm( request, listIdsDirectoryRecord, nIdAction, bShowActionResult );
4771             }
4772 
4773             String strIdDirectory = request.getParameter( DirectoryUtils.PARAMETER_ID_DIRECTORY );
4774 
4775             // If the id directory is not in the parameter, then fetch it from the first record
4776             // assuming all records are from the same directory
4777             if ( StringUtils.isBlank( strIdDirectory ) || !StringUtils.isNumeric( strIdDirectory ) )
4778             {
4779                 String strIdDirectoryRecord = listIdsDirectoryRecord [0];
4780                 int nIdDirectoryRecord = DirectoryUtils.convertStringToInt( strIdDirectoryRecord );
4781                 Record record = _recordService.findByPrimaryKey( nIdDirectoryRecord, getPlugin( ) );
4782                 strIdDirectory = Integer.toString( record.getDirectory( ).getIdDirectory( ) );
4783             }
4784 
4785             int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
4786 
4787             _directoryActionResult.doProcessAction( nIdDirectory, nIdAction, listIdsDirectoryRecord, getPlugin( ), getLocale( ), request );
4788 
4789             if ( bShowActionResult )
4790             {
4791                 return getJspActionResults( request, nIdDirectory, nIdAction );
4792             }
4793 
4794             return getRedirectUrl( request );
4795         }
4796 
4797         return getRedirectUrl( request );
4798     }
4799 
4800     /**
4801      * return url of the jsp manage commentaire
4802      * 
4803      * @param request
4804      *            The HTTP request
4805      * @param listIdsTestResource
4806      *            the list if id resource
4807      * @param nIdAction
4808      *            the id action
4809      * @param bShowActionResult
4810      *            true if it must show the action result, false otherwise
4811      * @return url of the jsp manage commentaire
4812      */
4813     private String getJspTasksForm( HttpServletRequest request, String [ ] listIdsTestResource, int nIdAction, boolean bShowActionResult )
4814     {
4815         UrlItem url = new UrlItem( AppPathService.getBaseUrl( request ) + JSP_TASKS_FORM_WORKFLOW );
4816         url.addParameter( DirectoryUtils.PARAMETER_ID_ACTION, nIdAction );
4817 
4818         if ( bShowActionResult )
4819         {
4820             url.addParameter( DirectoryUtils.PARAMETER_SHOW_ACTION_RESULT, DirectoryUtils.CONSTANT_TRUE );
4821         }
4822 
4823         if ( ( listIdsTestResource != null ) && ( listIdsTestResource.length > 0 ) )
4824         {
4825             for ( String strIdTestResource : listIdsTestResource )
4826             {
4827                 url.addParameter( DirectoryUtils.PARAMETER_ID_DIRECTORY_RECORD, strIdTestResource );
4828             }
4829         }
4830 
4831         String strUploadAction = DirectoryAsynchronousUploadHandler.getHandler( ).getUploadAction( request );
4832 
4833         if ( StringUtils.isNotBlank( strUploadAction ) )
4834         {
4835             url.addParameter( strUploadAction, strUploadAction );
4836         }
4837 
4838         return url.getUrl( );
4839     }
4840 
4841     /**
4842      * Display the states for print mass
4843      * 
4844      * @param request
4845      *            la requete
4846      * @return The URL to go after performing the action
4847      * @throws AccessDeniedException
4848      *             AccessDeniedException
4849      */
4850     public String getMassPrint( HttpServletRequest request ) throws AccessDeniedException
4851     {
4852         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
4853         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
4854         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
4855         Map<String, Object> model = new HashMap<String, Object>( );
4856 
4857         if ( ( directory.getIdWorkflow( ) != DirectoryUtils.CONSTANT_ID_NULL ) && WorkflowService.getInstance( ).isAvailable( ) )
4858         {
4859             Collection<State> listState = WorkflowService.getInstance( ).getAllStateByWorkflow( directory.getIdWorkflow( ),
4860                     AdminUserService.getAdminUser( request ) );
4861             model.put( MARK_STATE_LIST, listState );
4862         }
4863 
4864         model.put( MARK_DIRECTORY, directory );
4865         setPageTitleProperty( PROPERTY_MASS_PRINT_PAGE_TITLE );
4866 
4867         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_MASS_PRINT, getLocale( ), model );
4868 
4869         return getAdminPage( template.getHtml( ) );
4870     }
4871 
4872     /**
4873      * Verify Print Mass
4874      * 
4875      * @param request
4876      *            la requete
4877      * @return The URL to go after performing the action
4878      * @throws AccessDeniedException
4879      *             AccessDeniedException
4880      */
4881     public String doMassPrint( HttpServletRequest request ) throws AccessDeniedException
4882     {
4883         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
4884         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
4885         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
4886         Map<String, String[]> mapIdState = request.getParameterMap( );
4887         WorkflowService workflowService = WorkflowService.getInstance( );
4888 
4889         List<State> listAllState = (List<State>) workflowService.getAllStateByWorkflow( directory.getIdWorkflow( ), AdminUserService.getAdminUser( request ) );
4890 
4891         List<State> listState = new ArrayList<State>( );
4892 
4893         for ( State state : listAllState )
4894         {
4895             if ( mapIdState.containsKey( Integer.toString( state.getId( ) ) ) )
4896             {
4897                 listState.add( state );
4898             }
4899         }
4900 
4901         if ( mapIdState.isEmpty( ) )
4902         {
4903             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_NOT_SELECTED_STATE, AdminMessage.TYPE_STOP );
4904         }
4905 
4906         Iterator<State> it = listState.iterator( );
4907         boolean bFind = false;
4908         Integer nIntIdDirectory = Integer.valueOf( directory.getIdDirectory( ) );
4909 
4910         while ( !bFind && it.hasNext( ) )
4911         {
4912             bFind = ( workflowService.getAuthorizedResourceList( Record.WORKFLOW_RESOURCE_TYPE, directory.getIdWorkflow( ), it.next( ).getId( ),
4913                     nIntIdDirectory, getUser( ) ).size( ) > 0 );
4914         }
4915 
4916         if ( !bFind )
4917         {
4918             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_NO_RECORD, AdminMessage.TYPE_STOP );
4919         }
4920 
4921         return getJspPrintHistory( request, listState, nIdDirectory );
4922     }
4923 
4924     /**
4925      * return url of the jsp
4926      * 
4927      * @param request
4928      *            The HTTP request
4929      * @param listState
4930      *            A state list
4931      * @param nIdDirectory
4932      *            The directory id
4933      * @return url of the jsp
4934      */
4935     private String getJspPrintHistory( HttpServletRequest request, List<State> listState, int nIdDirectory )
4936     {
4937         String strIdState = new String( );
4938 
4939         for ( State state : listState )
4940         {
4941             strIdState = strIdState.concat( state.getId( ) + "," );
4942         }
4943 
4944         if ( strIdState.length( ) > 0 )
4945         {
4946             strIdState = strIdState.substring( 0, strIdState.length( ) - 1 );
4947         }
4948 
4949         return AppPathService.getBaseUrl( request ) + JSP_DISPLAY_PRINT_HISTORY + "?" + PARAMETER_ID_DIRECTORY + "=" + nIdDirectory + "&" + PARAMETER_ID_STATE
4950                 + "=" + strIdState;
4951     }
4952 
4953     /**
4954      * Display Print Mass
4955      * 
4956      * @param request
4957      *            la requete
4958      * @return The URL to go after performing the action
4959      * @throws AccessDeniedException
4960      *             AccessDeniedException
4961      */
4962     public String getDisplayMassPrint( HttpServletRequest request ) throws AccessDeniedException
4963     {
4964         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
4965         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
4966         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
4967         String strIdState = request.getParameter( PARAMETER_ID_STATE );
4968         String [ ] tabIdState = strIdState.split( "," );
4969 
4970         WorkflowService workflowService = WorkflowService.getInstance( );
4971 
4972         Map<String, Object> model = new HashMap<String, Object>( );
4973         List<Integer> recordList;
4974 
4975         List<String> listStrIdState = Arrays.asList( tabIdState );
4976 
4977         List<State> listAllState = (List<State>) workflowService.getAllStateByWorkflow( directory.getIdWorkflow( ), AdminUserService.getAdminUser( request ) );
4978 
4979         List<Integer> listIdState = new ArrayList<Integer>( );
4980 
4981         for ( State state : listAllState )
4982         {
4983             if ( listStrIdState.contains( Integer.toString( state.getId( ) ) ) )
4984             {
4985                 listIdState.add( Integer.valueOf( state.getId( ) ) );
4986             }
4987         }
4988 
4989         RecordFieldFilter recordFieldFilter = new RecordFieldFilter( );
4990         recordFieldFilter.setIdDirectory( directory.getIdDirectory( ) );
4991 
4992         List<Integer> listResultRecordId = DirectorySearchService.getInstance( ).getSearchResults( directory, _searchFields.getMapQuery( ),
4993                 _searchFields.getDateCreationRecord( ), _searchFields.getDateCreationBeginRecord( ), _searchFields.getDateCreationEndRecord( ),
4994                 _searchFields.getDateModificationRecord( ), _searchFields.getDateModificationBeginRecord( ), _searchFields.getDateModificationEndRecord( ),
4995                 recordFieldFilter, getPlugin( ) );
4996 
4997         List<Integer> listTmpResultRecordId = workflowService.getAuthorizedResourceList( Record.WORKFLOW_RESOURCE_TYPE, directory.getIdWorkflow( ),
4998                 listIdState, Integer.valueOf( directory.getIdDirectory( ) ), getUser( ) );
4999         List<Integer> lListResult = DirectoryUtils.retainAll( listResultRecordId, listTmpResultRecordId );
5000 
5001         _searchFields.setCurrentPageIndexPrintMass( Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX,
5002                 _searchFields.getCurrentPageIndexPrintMass( ) ) );
5003         _searchFields.setItemsPerPagePrintMass( Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE,
5004                 _searchFields.getItemsPerPagePrintMass( ), _searchFields.getDefaultItemsPerPage( ) ) );
5005 
5006         LocalizedPaginator<Integer> paginator = new LocalizedPaginator<Integer>( lListResult, _searchFields.getItemsPerPagePrintMass( ), getJspPrintMass(
5007                 request, nIdDirectory, strIdState ), PARAMETER_PAGE_INDEX, _searchFields.getCurrentPageIndexPrintMass( ), getLocale( ) );
5008 
5009         recordList = paginator.getPageItems( );
5010 
5011         EntryFilter filter;
5012         filter = new EntryFilter( );
5013         filter.setIdDirectory( nIdDirectory );
5014         filter.setIsShownInHistory( EntryFilter.FILTER_TRUE );
5015 
5016         List<IEntry> listEntry = EntryHome.getEntryList( filter, getPlugin( ) );
5017 
5018         List<Map<String, Object>> listRecordHistory = new ArrayList<Map<String, Object>>( );
5019 
5020         for ( Integer nIdRecord : recordList )
5021         {
5022             Map<String, Object> resource = new HashMap<String, Object>( );
5023             resource.put( MARK_MAP_ID_ENTRY_LIST_RECORD_FIELD, DirectoryUtils.getMapIdEntryListRecordField( listEntry, nIdRecord, getPlugin( ), false ) );
5024 
5025             resource.put(
5026                     MARK_RESOURCE_HISTORY,
5027                     WorkflowService.getInstance( ).getDisplayDocumentHistory( nIdRecord, Record.WORKFLOW_RESOURCE_TYPE, directory.getIdWorkflow( ), request,
5028                             getLocale( ) ) );
5029             listRecordHistory.add( resource );
5030         }
5031 
5032         model.put( MARK_HISTORY_LIST, listRecordHistory );
5033         model.put( MARK_ENTRY_LIST, listEntry );
5034 
5035         model.put( MARK_ID_DIRECTORY, strIdDirectory );
5036         model.put( MARK_ID_STATE, strIdState );
5037 
5038         model.put( MARK_PAGINATOR, paginator );
5039         model.put( MARK_NB_ITEMS_PER_PAGE, Integer.toString( _searchFields.getItemsPerPagePrintMass( ) ) );
5040 
5041         HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_DISPLAY_MASS_PRINT, getLocale( ), model );
5042 
5043         return getAdminPage( templateList.getHtml( ) );
5044     }
5045 
5046     /**
5047      * Returns advanced parameters form
5048      *
5049      * @param request
5050      *            The Http request
5051      * @return Html form
5052      */
5053     public String getManageAdvancedParameters( HttpServletRequest request )
5054     {
5055         if ( !RBACService.isAuthorized( Directory.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, DirectoryResourceIdService.PERMISSION_MANAGE_ADVANCED_PARAMETERS,
5056                 getUser( ) ) )
5057         {
5058             return getManageDirectory( request );
5059         }
5060 
5061         Map<String, Object> model = DirectoryService.getInstance( ).getManageAdvancedParameters( getUser( ) );
5062 
5063         model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
5064         model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage( ) );
5065 
5066         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_ADVANCED_PARAMETERS, getLocale( ), model );
5067 
5068         return getAdminPage( template.getHtml( ) );
5069     }
5070 
5071     /**
5072      * Modify directory parameter default values
5073      * 
5074      * @param request
5075      *            HttpServletRequest
5076      * @return JSP return
5077      * @throws AccessDeniedException
5078      *             AccessDeniedException
5079      */
5080     public String doModifyDirectoryParameterDefaultValues( HttpServletRequest request ) throws AccessDeniedException
5081     {
5082         if ( !RBACService.isAuthorized( Directory.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, DirectoryResourceIdService.PERMISSION_MANAGE_ADVANCED_PARAMETERS,
5083                 getUser( ) ) )
5084         {
5085             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
5086         }
5087 
5088         ReferenceList listParams = DirectoryParameterService.getService( ).findDefaultValueParameters( );
5089 
5090         for ( ReferenceItem param : listParams )
5091         {
5092             String strParamValue = request.getParameter( param.getCode( ) );
5093 
5094             if ( StringUtils.isBlank( strParamValue ) )
5095             {
5096                 strParamValue = ZERO;
5097             }
5098 
5099             param.setName( strParamValue );
5100             DirectoryParameterService.getService( ).update( param );
5101         }
5102 
5103         return getJspManageAdvancedParameters( request );
5104     }
5105 
5106     /**
5107      * Modify entry parameter default values
5108      * 
5109      * @param request
5110      *            HttpServletRequest
5111      * @return JSP return
5112      * @throws AccessDeniedException
5113      *             AccessDeniedException
5114      */
5115     public String doModifyEntryParameterDefaultValues( HttpServletRequest request ) throws AccessDeniedException
5116     {
5117         if ( !RBACService.isAuthorized( Directory.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, DirectoryResourceIdService.PERMISSION_MANAGE_ADVANCED_PARAMETERS,
5118                 getUser( ) ) )
5119         {
5120             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
5121         }
5122 
5123         ReferenceList listParams = EntryParameterService.getService( ).findAll( );
5124 
5125         for ( ReferenceItem param : listParams )
5126         {
5127             String strParamValue = request.getParameter( param.getCode( ) );
5128 
5129             if ( StringUtils.isBlank( strParamValue ) )
5130             {
5131                 strParamValue = ZERO;
5132             }
5133 
5134             param.setName( strParamValue );
5135             EntryParameterService.getService( ).update( param );
5136         }
5137 
5138         return getJspManageAdvancedParameters( request );
5139     }
5140 
5141     /**
5142      * Modify directory parameter default values
5143      * 
5144      * @param request
5145      *            HttpServletRequest
5146      * @return JSP return
5147      * @throws AccessDeniedException
5148      *             AccessDeniedException
5149      */
5150     public String doModifyExportEncodingParameters( HttpServletRequest request ) throws AccessDeniedException
5151     {
5152         if ( !RBACService.isAuthorized( Directory.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, DirectoryResourceIdService.PERMISSION_MANAGE_ADVANCED_PARAMETERS,
5153                 getUser( ) ) )
5154         {
5155             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
5156         }
5157 
5158         ReferenceList listParams = DirectoryParameterService.getService( ).findExportEncodingParameters( );
5159 
5160         for ( ReferenceItem param : listParams )
5161         {
5162             String strParamValue = request.getParameter( param.getCode( ) );
5163 
5164             if ( StringUtils.isNotBlank( strParamValue ) )
5165             {
5166                 // Test if the encoding is supported
5167                 try
5168                 {
5169                     strParamValue.getBytes( strParamValue );
5170                 }
5171                 catch( UnsupportedEncodingException e )
5172                 {
5173                     Object [ ] tabRequiredFields = {
5174                         strParamValue
5175                     };
5176 
5177                     return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_EXPORT_ENCODING_NOT_SUPPORTED, tabRequiredFields, AdminMessage.TYPE_STOP );
5178                 }
5179             }
5180             else
5181             {
5182                 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
5183             }
5184 
5185             param.setName( strParamValue );
5186             DirectoryParameterService.getService( ).update( param );
5187         }
5188 
5189         return getJspManageAdvancedParameters( request );
5190     }
5191 
5192     /**
5193      * return the record visualisation
5194      * 
5195      * @param request
5196      *            the Http request
5197      * @return the record visualisation
5198      * @throws AccessDeniedException
5199      *             AccessDeniedException
5200      */
5201     public String getMyLuteceUserVisualisation( HttpServletRequest request ) throws AccessDeniedException
5202     {
5203         String strIdRecord = request.getParameter( PARAMETER_ID_DIRECTORY_RECORD );
5204         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
5205         int nIdRecord = DirectoryUtils.convertStringToInt( strIdRecord );
5206         int nIdEntry = DirectoryUtils.convertStringToInt( strIdEntry );
5207         Record record = _recordService.findByPrimaryKey( nIdRecord, getPlugin( ) );
5208 
5209         int nIdDirectory = record.getDirectory( ).getIdDirectory( );
5210         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
5211 
5212         if ( ( record == null )
5213                 || ( directory == null )
5214                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ),
5215                         DirectoryResourceIdService.PERMISSION_VISUALISATION_MYLUTECE_USER, getUser( ) )
5216                 || !AdminWorkgroupService.isAuthorized( record, getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
5217         {
5218             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
5219         }
5220 
5221         String strUserGuid = DirectoryService.getInstance( ).getUserGuid( nIdRecord, nIdEntry );
5222         ReferenceList listUserInfos = DirectoryService.getInstance( ).getUserInfos( strUserGuid, nIdEntry );
5223 
5224         Map<String, Object> model = new HashMap<String, Object>( );
5225         model.put( MARK_MYLUTECE_USER_LOGIN, strUserGuid );
5226         model.put( MARK_MYLUTECE_USER_INFOS_LIST, listUserInfos );
5227 
5228         HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_VIEW_MYLUTECE_USER, getLocale( ), model );
5229 
5230         return getAdminPage( templateList.getHtml( ) );
5231     }
5232 
5233     /**
5234      * Return the interface for import field
5235      * 
5236      * @param request
5237      *            The Http request
5238      * @throws AccessDeniedException
5239      *             the {@link AccessDeniedException}
5240      * @return Html directory
5241      */
5242     public String getImportField( HttpServletRequest request ) throws AccessDeniedException
5243     {
5244         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
5245         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
5246         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
5247         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
5248         int nIdEntry = DirectoryUtils.convertStringToInt( strIdEntry );
5249         IEntry entry = EntryHome.findByPrimaryKey( nIdEntry, getPlugin( ) );
5250 
5251         if ( ( directory == null ) || ( entry == null )
5252                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_IMPORT_FIELD, getUser( ) )
5253                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
5254         {
5255             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
5256         }
5257 
5258         Map<String, Object> model = new HashMap<String, Object>( );
5259 
5260         if ( request.getParameter( PARAMETER_SESSION ) != null )
5261         {
5262             if ( _searchFields.getError( ) != null )
5263             {
5264                 model.put( MARK_STR_ERROR, _searchFields.getError( ).toString( ) );
5265             }
5266 
5267             model.put( MARK_NUMBER_LINES_ERROR, _searchFields.getCountLineFailure( ) );
5268             model.put( MARK_NUMBER_LINES_IMPORTED, _searchFields.getCountLine( ) - _searchFields.getCountLineFailure( ) );
5269             model.put( MARK_FINISH_IMPORT, true );
5270             _searchFields.setCountLine( 0 );
5271             _searchFields.setCountLineFailure( 0 );
5272             _searchFields.setError( null );
5273         }
5274 
5275         model.put( MARK_LOCALE, getLocale( ) );
5276         model.put( MARK_DIRECTORY, directory );
5277         model.put( MARK_ENTRY, entry );
5278         setPageTitleProperty( PROPERTY_IMPORT_FIELD_PAGE_TITLE );
5279 
5280         HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_IMPORT_FIELD, getLocale( ), model );
5281 
5282         return getAdminPage( templateList.getHtml( ) );
5283     }
5284 
5285     /**
5286      * ImportDirectory record
5287      * 
5288      * @param request
5289      *            the Http Request
5290      * @throws AccessDeniedException
5291      *             the {@link AccessDeniedException}
5292      * @return The URL to go after performing the action
5293      */
5294     public String doImportField( HttpServletRequest request ) throws AccessDeniedException
5295     {
5296         MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
5297         FileItem fileItem = multipartRequest.getFile( PARAMETER_FILE_IMPORT );
5298         String strMimeType = FileSystemUtil.getMIMEType( FileUploadService.getFileNameOnly( fileItem ) );
5299 
5300         if ( ( fileItem == null ) || ( fileItem.getName( ) == null ) || DirectoryUtils.EMPTY_STRING.equals( fileItem.getName( ) ) )
5301         {
5302             Object [ ] tabRequiredFields = {
5303                 I18nService.getLocalizedString( FIELD_FILE_IMPORT, getLocale( ) )
5304             };
5305 
5306             return AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_FIELD, tabRequiredFields, AdminMessage.TYPE_STOP );
5307         }
5308 
5309         if ( ( !strMimeType.equals( CONSTANT_MIME_TYPE_CSV ) && !strMimeType.equals( CONSTANT_MIME_TYPE_OCTETSTREAM ) && !strMimeType
5310                 .equals( CONSTANT_MIME_TYPE_TEXT_CSV ) ) || !fileItem.getName( ).toLowerCase( ).endsWith( CONSTANT_EXTENSION_CSV_FILE ) )
5311         {
5312             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_CSV_FILE_IMPORT, AdminMessage.TYPE_STOP );
5313         }
5314 
5315         String strIdEntry = request.getParameter( PARAMETER_ID_ENTRY );
5316         int nIdEntry = DirectoryUtils.convertStringToInt( strIdEntry );
5317         IEntry entry = EntryHome.findByPrimaryKey( nIdEntry, getPlugin( ) );
5318         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
5319         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
5320         Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
5321 
5322         if ( ( entry == null ) || ( directory == null )
5323                 || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, strIdDirectory, DirectoryResourceIdService.PERMISSION_MODIFY, getUser( ) )
5324                 || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
5325         {
5326             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
5327         }
5328 
5329         Character strCsvSeparator = AppPropertiesService.getProperty( PROPERTY_IMPORT_CSV_DELIMITER ).charAt( 0 );
5330         _searchFields.setError( new StringBuffer( ) );
5331 
5332         try
5333         {
5334             InputStreamReader inputStreamReader = new InputStreamReader( fileItem.getInputStream( ) );
5335             CSVReader csvReader = new CSVReader( inputStreamReader, strCsvSeparator, '\"' );
5336 
5337             String [ ] nextLine;
5338 
5339             _searchFields.setCountLine( 0 );
5340             _searchFields.setCountLineFailure( 0 );
5341 
5342             while ( ( nextLine = csvReader.readNext( ) ) != null )
5343             {
5344                 _searchFields.setCountLine( _searchFields.getCountLine( ) + 1 );
5345 
5346                 if ( nextLine.length != IMPORT_FIELD_NB_COLUMN_MAX )
5347                 {
5348                     _searchFields.getError( ).append( I18nService.getLocalizedString( PROPERTY_LINE, getLocale( ) ) );
5349                     _searchFields.getError( ).append( _searchFields.getCountLine( ) );
5350                     _searchFields.getError( ).append( " > " );
5351                     _searchFields.getError( ).append( I18nService.getLocalizedString( MESSAGE_ERROR_CSV_NUMBER_SEPARATOR, getLocale( ) ) );
5352                     _searchFields.getError( ).append( "<br/>" );
5353                     _searchFields.setCountLineFailure( _searchFields.getCountLineFailure( ) + 1 );
5354                 }
5355                 else
5356                 {
5357                     Field field = new Field( );
5358                     field.setEntry( entry );
5359 
5360                     try
5361                     {
5362                         getImportFieldData( request, field, nextLine );
5363                         FieldHome.create( field, getPlugin( ) );
5364                     }
5365                     catch( DirectoryErrorException error )
5366                     {
5367                         _searchFields.getError( ).append( I18nService.getLocalizedString( PROPERTY_LINE, getLocale( ) ) );
5368                         _searchFields.getError( ).append( _searchFields.getCountLine( ) );
5369                         _searchFields.getError( ).append( " > " );
5370 
5371                         if ( error.isMandatoryError( ) )
5372                         {
5373                             Object [ ] tabRequiredFields = {
5374                                 error.getTitleField( )
5375                             };
5376                             _searchFields.getError( ).append(
5377                                     I18nService.getLocalizedString( MESSAGE_DIRECTORY_ERROR_MANDATORY_FIELD, tabRequiredFields, getLocale( ) ) );
5378                         }
5379                         else
5380                         {
5381                             Object [ ] tabRequiredFields = {
5382                                     error.getTitleField( ), error.getErrorMessage( )
5383                             };
5384                             _searchFields.getError( ).append( I18nService.getLocalizedString( MESSAGE_DIRECTORY_ERROR, tabRequiredFields, getLocale( ) ) );
5385                         }
5386 
5387                         _searchFields.getError( ).append( "<br/>" );
5388                         _searchFields.setCountLineFailure( _searchFields.getCountLineFailure( ) + 1 );
5389                     }
5390                 }
5391             }
5392         }
5393 
5394         catch( IOException e )
5395         {
5396             AppLogService.error( e );
5397         }
5398 
5399         return AppPathService.getBaseUrl( request ) + JSP_IMPORT_FIELD + DirectoryUtils.CONSTANT_INTERROGATION_MARK + PARAMETER_ID_DIRECTORY
5400                 + DirectoryUtils.CONSTANT_EQUAL + nIdDirectory + DirectoryUtils.CONSTANT_AMPERSAND + PARAMETER_ID_ENTRY + DirectoryUtils.CONSTANT_EQUAL
5401                 + nIdEntry + DirectoryUtils.CONSTANT_AMPERSAND + PARAMETER_SESSION + "=" + PARAMETER_SESSION;
5402     }
5403 
5404     /**
5405      * Gets the confirmation page of changing the state of the records
5406      * 
5407      * @param request
5408      *            The HTTP request
5409      * @throws AccessDeniedException
5410      *             the {@link AccessDeniedException}
5411      * @return the confirmation page of changing the state of the records
5412      */
5413     public String getConfirmChangeStatesRecord( HttpServletRequest request ) throws AccessDeniedException
5414     {
5415         String [ ] listIdsDirectoryRecord = request.getParameterValues( PARAMETER_ID_DIRECTORY_RECORD );
5416 
5417         if ( ( listIdsDirectoryRecord != null ) && ( listIdsDirectoryRecord.length > 0 ) )
5418         {
5419             String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
5420 
5421             // If the id directory is not in the parameter, then fetch it from the first record
5422             // assuming all records are from the same directory
5423             if ( StringUtils.isBlank( strIdDirectory ) || !StringUtils.isNumeric( strIdDirectory ) )
5424             {
5425                 String strIdDirectoryRecord = listIdsDirectoryRecord [0];
5426                 int nIdDirectoryRecord = DirectoryUtils.convertStringToInt( strIdDirectoryRecord );
5427                 Record record = _recordService.findByPrimaryKey( nIdDirectoryRecord, getPlugin( ) );
5428                 strIdDirectory = Integer.toString( record.getDirectory( ).getIdDirectory( ) );
5429             }
5430 
5431             int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
5432             Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
5433 
5434             UrlItem url = new UrlItem( JSP_DO_CHANGE_STATES_RECORD );
5435             url.addParameter( DirectoryUtils.PARAMETER_ID_DIRECTORY, nIdDirectory );
5436 
5437             for ( String strIdDirectoryRecord : listIdsDirectoryRecord )
5438             {
5439                 int nIdDirectoryRecord = DirectoryUtils.convertStringToInt( strIdDirectoryRecord );
5440                 Record record = _recordService.findByPrimaryKey( nIdDirectoryRecord, getPlugin( ) );
5441 
5442                 if ( ( record == null )
5443                         || ( directory == null )
5444                         || ( record.getDirectory( ).getIdDirectory( ) != nIdDirectory )
5445                         || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ),
5446                                 DirectoryResourceIdService.PERMISSION_CHANGE_STATE_RECORD, getUser( ) )
5447                         || !AdminWorkgroupService.isAuthorized( record, getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
5448                 {
5449                     throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
5450                 }
5451 
5452                 url.addParameter( PARAMETER_ID_DIRECTORY_RECORD, nIdDirectoryRecord );
5453             }
5454 
5455             return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_CHANGE_STATES_RECORD, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
5456         }
5457 
5458         return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
5459     }
5460 
5461     /**
5462      * Perform the directory record supression
5463      * 
5464      * @param request
5465      *            The HTTP request
5466      * @throws AccessDeniedException
5467      *             the {@link AccessDeniedException}
5468      * @return The URL to go after performing the action
5469      */
5470     public String doChangeStatesRecord( HttpServletRequest request ) throws AccessDeniedException
5471     {
5472         String [ ] listIdsDirectoryRecord = request.getParameterValues( PARAMETER_ID_DIRECTORY_RECORD );
5473 
5474         if ( ( listIdsDirectoryRecord != null ) && ( listIdsDirectoryRecord.length > 0 ) )
5475         {
5476             String strIdDirectory = request.getParameter( DirectoryUtils.PARAMETER_ID_DIRECTORY );
5477             int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
5478             Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, getPlugin( ) );
5479 
5480             for ( String strIdDirectoryRecord : listIdsDirectoryRecord )
5481             {
5482                 int nIdDirectoryRecord = DirectoryUtils.convertStringToInt( strIdDirectoryRecord );
5483                 Record record = _recordService.findByPrimaryKey( nIdDirectoryRecord, getPlugin( ) );
5484 
5485                 if ( ( record == null )
5486                         || ( directory == null )
5487                         || ( record.getDirectory( ).getIdDirectory( ) != nIdDirectory )
5488                         || !RBACService.isAuthorized( Directory.RESOURCE_TYPE, Integer.toString( nIdDirectory ),
5489                                 DirectoryResourceIdService.PERMISSION_CHANGE_STATE_RECORD, getUser( ) )
5490                         || !AdminWorkgroupService.isAuthorized( record, getUser( ) ) || !AdminWorkgroupService.isAuthorized( directory, getUser( ) ) )
5491                 {
5492                     throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
5493                 }
5494 
5495                 record.setEnabled( !record.isEnabled( ) );
5496                 _recordService.update( record, getPlugin( ) );
5497             }
5498 
5499             return DirectoryUtils.getJspManageDirectoryRecord( request, nIdDirectory );
5500         }
5501 
5502         return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
5503     }
5504 
5505     /**
5506      * Get the request data and if there is no error insert the data in the field specified in parameter. return null if there is no error or else return the
5507      * error page url
5508      * 
5509      * @param request
5510      *            the request
5511      * @param field
5512      *            field
5513      * @param listImportValue
5514      *            the list of imports values
5515      * @throws DirectoryErrorException
5516      *             DirectoryErrorException
5517      */
5518     private void getImportFieldData( HttpServletRequest request, Field field, String [ ] listImportValue ) throws DirectoryErrorException
5519     {
5520         String strTitle = listImportValue [0];
5521         String strValue = listImportValue [1];
5522 
5523         if ( ( strTitle == null ) || DirectoryUtils.EMPTY_STRING.equals( strTitle ) )
5524         {
5525             throw new DirectoryErrorException( I18nService.getLocalizedString( FIELD_TITLE_FIELD, getLocale( ) ) );
5526         }
5527         else
5528             if ( ( strValue == null ) || DirectoryUtils.EMPTY_STRING.equals( strValue ) )
5529             {
5530                 throw new DirectoryErrorException( I18nService.getLocalizedString( FIELD_VALUE_FIELD, getLocale( ) ) );
5531             }
5532             else
5533                 if ( !StringUtil.checkCodeKey( strValue ) )
5534                 {
5535                     throw new DirectoryErrorException( I18nService.getLocalizedString( FIELD_VALUE_FIELD, getLocale( ) ), I18nService.getLocalizedString(
5536                             MESSAGE_FIELD_VALUE_FIELD, getLocale( ) ) );
5537                 }
5538 
5539         field.setTitle( strTitle );
5540         field.setValue( strValue );
5541         field.setDefaultValue( false );
5542     }
5543 
5544     /**
5545      * Get the redirect url
5546      * 
5547      * @param request
5548      *            the http servlet request
5549      * @return the redirect url
5550      */
5551     public String getRedirectUrl( HttpServletRequest request )
5552     {
5553         if ( StringUtils.isNotBlank( _searchFields.getRedirectUrl( ) ) )
5554         {
5555             return _searchFields.getRedirectUrl( );
5556         }
5557 
5558         return getJspManageDirectory( request );
5559     }
5560 
5561     /**
5562      * Fill the directory record with data
5563      * 
5564      * @param record
5565      *            the record to fill
5566      * @param request
5567      *            the HTTP request
5568      * @return empty string if there is no redirect (in error cases or upload file cases), an url to redirect otherwise
5569      */
5570     private String getDirectoryRecordData( Record record, HttpServletRequest request )
5571     {
5572         String strUploadAction = DirectoryAsynchronousUploadHandler.getHandler( ).getUploadAction( request );
5573 
5574         try
5575         {
5576             DirectoryUtils.getDirectoryRecordData( request, record, getPlugin( ), getLocale( ) );
5577         }
5578         catch( DirectoryErrorException error )
5579         {
5580             // Case if the user does not upload a file, then throw the error message
5581             if ( StringUtils.isBlank( strUploadAction ) )
5582             {
5583                 String strErrorMessage = DirectoryUtils.EMPTY_STRING;
5584 
5585                 if ( error.isMandatoryError( ) )
5586                 {
5587                     Object [ ] tabRequiredFields = {
5588                         error.getTitleField( )
5589                     };
5590                     strErrorMessage = AdminMessageService.getMessageUrl( request, MESSAGE_DIRECTORY_ERROR_MANDATORY_FIELD, tabRequiredFields,
5591                             AdminMessage.TYPE_STOP );
5592                 }
5593                 else
5594                 {
5595                     Object [ ] tabRequiredFields = {
5596                             error.getTitleField( ), error.getErrorMessage( )
5597                     };
5598                     strErrorMessage = AdminMessageService.getMessageUrl( request, MESSAGE_DIRECTORY_ERROR, tabRequiredFields, AdminMessage.TYPE_STOP );
5599                 }
5600 
5601                 return strErrorMessage;
5602             }
5603         }
5604 
5605         // Special case for upload fields : if no action is specified, a submit
5606         // button associated with an upload might have been pressed :
5607         if ( StringUtils.isNotBlank( strUploadAction ) )
5608         {
5609             Map<String, List<RecordField>> mapListRecordFields = DirectoryUtils.buildMapIdEntryListRecordField( record );
5610 
5611             // Upload the file
5612             try
5613             {
5614                 DirectoryAsynchronousUploadHandler.getHandler( ).doUploadAction( request, strUploadAction, mapListRecordFields, record, getPlugin( ) );
5615             }
5616             catch( DirectoryErrorException error )
5617             {
5618                 String strErrorMessage = DirectoryUtils.EMPTY_STRING;
5619 
5620                 if ( error.isMandatoryError( ) )
5621                 {
5622                     Object [ ] tabRequiredFields = {
5623                         error.getTitleField( )
5624                     };
5625                     strErrorMessage = AdminMessageService.getMessageUrl( request, MESSAGE_DIRECTORY_ERROR_MANDATORY_FIELD, tabRequiredFields,
5626                             AdminMessage.TYPE_STOP );
5627                 }
5628                 else
5629                 {
5630                     Object [ ] tabRequiredFields = {
5631                             error.getTitleField( ), error.getErrorMessage( )
5632                     };
5633                     strErrorMessage = AdminMessageService.getMessageUrl( request, MESSAGE_DIRECTORY_ERROR, tabRequiredFields, AdminMessage.TYPE_STOP );
5634                 }
5635 
5636                 return strErrorMessage;
5637             }
5638 
5639             // Put the map idEntry, RecordFields in the session
5640             request.getSession( ).setAttribute( DirectoryUtils.SESSION_DIRECTORY_LIST_SUBMITTED_RECORD_FIELDS, mapListRecordFields );
5641 
5642             // Check whether it is an update or a creation
5643             if ( ( record.getIdRecord( ) != DirectoryUtils.CONSTANT_ID_NULL ) && ( record.getIdRecord( ) != DirectoryUtils.CONSTANT_ID_ZERO ) )
5644             {
5645                 return getJspModifyDirectoryRecord( request, record.getDirectory( ).getIdDirectory( ), record.getIdRecord( ) );
5646             }
5647 
5648             return getJspCreateDirectoryRecord( request, record.getDirectory( ).getIdDirectory( ) );
5649         }
5650 
5651         return StringUtils.EMPTY;
5652     }
5653 
5654     /**
5655      * Init the list of the attribute's orders (first level only)
5656      * 
5657      * @param listEntryFirstLevel
5658      *            the list of all the attributes of the first level
5659      * @param orderFirstLevel
5660      *            the list to set
5661      */
5662     private void initOrderFirstLevel( List<IEntry> listEntryFirstLevel, List<Integer> orderFirstLevel )
5663     {
5664         for ( IEntry entry : listEntryFirstLevel )
5665         {
5666             orderFirstLevel.add( entry.getPosition( ) );
5667         }
5668     }
5669 
5670     // /**
5671     // * @param plugin the plugin
5672     // * @param listEntry the list of all entry
5673     // * @param listEntryFirstLevel the list of entry first level
5674     // */
5675     // private void fillEntryListWithEntryFirstLevel( Plugin plugin, List<IEntry> listEntry,
5676     // List<IEntry> listEntryFirstLevel )
5677     // {
5678     // EntryFilter filter;
5679     //
5680     // for ( IEntry entry : listEntryFirstLevel )
5681     // {
5682     // listEntry.add( entry );
5683     //
5684     // if ( entry.getEntryType( ).getGroup( ) )
5685     // {
5686     // filter = new EntryFilter( );
5687     // filter.setIdEntryParent( entry.getIdEntry( ) );
5688     // entry.setChildren( EntryHome.getEntryList( filter, plugin ) );
5689     //
5690     // if ( entry.getChildren( ).size( ) != 0 )
5691     // {
5692     // entry.getChildren( ).get( 0 ).setFirstInTheList( true );
5693     // entry.getChildren( ).get( entry.getChildren( ).size( ) - 1 ).setLastInTheList( true );
5694     // }
5695     //
5696     // for ( IEntry entryChild : entry.getChildren( ) )
5697     // {
5698     // listEntry.add( entryChild );
5699     // }
5700     // }
5701     // }
5702     // }
5703 
5704     /**
5705      * Populate map with ( idParent : List<Orders> ) except for entry with parent null
5706      * 
5707      * @param listEntry
5708      *            the list of all entry
5709      * @param mapIdParentOrdersChildren
5710      *            map with (idParent : List<Orders>)
5711      */
5712     private void populateEntryMap( List<IEntry> listEntry, Map<String, List<Integer>> mapIdParentOrdersChildren )
5713     {
5714         List<Integer> listOrder;
5715 
5716         for ( IEntry entry : listEntry )
5717         {
5718             if ( entry.getParent( ) != null )
5719             {
5720                 Integer key = Integer.valueOf( entry.getParent( ).getIdEntry( ) );
5721                 String strKey = key.toString( );
5722 
5723                 if ( mapIdParentOrdersChildren.get( strKey ) != null )
5724                 {
5725                     mapIdParentOrdersChildren.get( key.toString( ) ).add( entry.getPosition( ) );
5726                 }
5727                 else
5728                 {
5729                     listOrder = new ArrayList<Integer>( );
5730                     listOrder.add( entry.getPosition( ) );
5731                     mapIdParentOrdersChildren.put( key.toString( ), listOrder );
5732                 }
5733             }
5734         }
5735     }
5736 
5737     /**
5738      * Change the attribute's order to a greater one (move down in the list)
5739      * 
5740      * @param plugin
5741      *            the plugin
5742      * @param nOrderToSet
5743      *            the new order for the attribute
5744      * @param entryToChangeOrder
5745      *            the attribute which will change
5746      * @param nIdDirectory
5747      *            the id of the directory
5748      */
5749     private void moveDownEntryOrder( Plugin plugin, int nOrderToSet, IEntry entryToChangeOrder, int nIdDirectory )
5750     {
5751         if ( entryToChangeOrder.getParent( ) == null )
5752         {
5753             int nNbChild = 0;
5754             int nNewOrder = 0;
5755 
5756             List<IEntry> listEntryFirstLevel = EntryHome.findEntriesWithoutParent( plugin, nIdDirectory );
5757 
5758             List<Integer> orderFirstLevel = new ArrayList<Integer>( );
5759             initOrderFirstLevel( listEntryFirstLevel, orderFirstLevel );
5760 
5761             Integer nbChildEntryToChangeOrder = 0;
5762 
5763             if ( entryToChangeOrder.getChildren( ) != null )
5764             {
5765                 nbChildEntryToChangeOrder = entryToChangeOrder.getChildren( ).size( );
5766             }
5767 
5768             for ( IEntry entry : listEntryFirstLevel )
5769             {
5770                 for ( int i = 0; i < orderFirstLevel.size( ); i++ )
5771                 {
5772                     if ( ( orderFirstLevel.get( i ) == entry.getPosition( ) ) && ( entry.getPosition( ) > entryToChangeOrder.getPosition( ) )
5773                             && ( entry.getPosition( ) <= nOrderToSet ) )
5774                     {
5775                         if ( nNbChild == 0 )
5776                         {
5777                             nNewOrder = orderFirstLevel.get( i - 1 );
5778 
5779                             if ( orderFirstLevel.get( i - 1 ) != entryToChangeOrder.getPosition( ) )
5780                             {
5781                                 nNewOrder -= nbChildEntryToChangeOrder;
5782                             }
5783                         }
5784                         else
5785                         {
5786                             nNewOrder += ( nNbChild + 1 );
5787                         }
5788 
5789                         entry.setPosition( nNewOrder );
5790                         EntryHome.update( entry, plugin );
5791                         nNbChild = 0;
5792 
5793                         if ( entry.getChildren( ) != null )
5794                         {
5795                             for ( IEntry child : entry.getChildren( ) )
5796                             {
5797                                 nNbChild++;
5798                                 child.setPosition( nNewOrder + nNbChild );
5799                                 EntryHome.update( child, plugin );
5800                             }
5801                         }
5802                     }
5803                 }
5804             }
5805 
5806             entryToChangeOrder.setPosition( nNewOrder + nNbChild + 1 );
5807             EntryHome.update( entryToChangeOrder, plugin );
5808             nNbChild = 0;
5809 
5810             for ( IEntry child : entryToChangeOrder.getChildren( ) )
5811             {
5812                 nNbChild++;
5813                 child.setPosition( entryToChangeOrder.getPosition( ) + nNbChild );
5814                 EntryHome.update( child, plugin );
5815             }
5816         }
5817         else
5818         {
5819             EntryFilter filter = new EntryFilter( );
5820             filter.setIdDirectory( nIdDirectory );
5821 
5822             List<IEntry> listAllEntry = EntryHome.getEntryList( filter, plugin );
5823 
5824             for ( IEntry entry : listAllEntry )
5825             {
5826                 if ( ( entry.getPosition( ) > entryToChangeOrder.getPosition( ) ) && ( entry.getPosition( ) <= nOrderToSet ) )
5827                 {
5828                     entry.setPosition( entry.getPosition( ) - 1 );
5829                     EntryHome.update( entry, plugin );
5830                 }
5831             }
5832 
5833             entryToChangeOrder.setPosition( nOrderToSet );
5834             EntryHome.update( entryToChangeOrder, plugin );
5835         }
5836     }
5837 
5838     /**
5839      * Change the attribute's order to a lower one (move up in the list)
5840      * 
5841      * @param plugin
5842      *            the plugin
5843      * @param nOrderToSet
5844      *            the new order for the attribute
5845      * @param entryToChangeOrder
5846      *            the attribute which will change
5847      * @param nIdDirectory
5848      *            the id of the form
5849      */
5850     private void moveUpEntryOrder( Plugin plugin, int nOrderToSet, IEntry entryToChangeOrder, int nIdDirectory )
5851     {
5852         if ( entryToChangeOrder.getParent( ) == null )
5853         {
5854             List<Integer> orderFirstLevel = new ArrayList<Integer>( );
5855 
5856             int nNbChild = 0;
5857             int nNewOrder = nOrderToSet;
5858             int nEntryToMoveOrder = entryToChangeOrder.getPosition( );
5859 
5860             EntryFilter filter = new EntryFilter( );
5861             filter.setIdDirectory( nIdDirectory );
5862 
5863             List<IEntry> listEntryFirstLevel = EntryHome.findEntriesWithoutParent( plugin, nIdDirectory );
5864             // the list of all the orders in the first level
5865             initOrderFirstLevel( listEntryFirstLevel, orderFirstLevel );
5866 
5867             for ( IEntry entry : listEntryFirstLevel )
5868             {
5869                 Integer entryInitialPosition = entry.getPosition( );
5870 
5871                 for ( int i = 0; i < orderFirstLevel.size( ); i++ )
5872                 {
5873                     if ( ( orderFirstLevel.get( i ) == entryInitialPosition ) && ( entryInitialPosition < nEntryToMoveOrder )
5874                             && ( entryInitialPosition >= nOrderToSet ) )
5875                     {
5876                         if ( entryToChangeOrder.getPosition( ) == nEntryToMoveOrder )
5877                         {
5878                             entryToChangeOrder.setPosition( nNewOrder );
5879                             EntryHome.update( entryToChangeOrder, plugin );
5880 
5881                             for ( IEntry child : entryToChangeOrder.getChildren( ) )
5882                             {
5883                                 nNbChild++;
5884                                 child.setPosition( entryToChangeOrder.getPosition( ) + nNbChild );
5885                                 EntryHome.update( child, plugin );
5886                             }
5887                         }
5888 
5889                         nNewOrder = nNewOrder + nNbChild + 1;
5890                         entry.setPosition( nNewOrder );
5891                         EntryHome.update( entry, plugin );
5892                         nNbChild = 0;
5893 
5894                         if ( entry.getChildren( ) != null )
5895                         {
5896                             for ( IEntry child : entry.getChildren( ) )
5897                             {
5898                                 nNbChild++;
5899                                 child.setPosition( nNewOrder + nNbChild );
5900                                 EntryHome.update( child, plugin );
5901                             }
5902                         }
5903                     }
5904                 }
5905             }
5906         }
5907         else
5908         {
5909             EntryFilter filter = new EntryFilter( );
5910             filter.setIdDirectory( nIdDirectory );
5911 
5912             List<IEntry> listAllEntry = EntryHome.getEntryList( filter, plugin );
5913 
5914             for ( IEntry entry : listAllEntry )
5915             {
5916                 if ( ( entry.getPosition( ) < entryToChangeOrder.getPosition( ) ) && ( entry.getPosition( ) >= nOrderToSet ) )
5917                 {
5918                     entry.setPosition( entry.getPosition( ) + 1 );
5919                     EntryHome.update( entry, plugin );
5920                 }
5921             }
5922 
5923             entryToChangeOrder.setPosition( nOrderToSet );
5924             EntryHome.update( entryToChangeOrder, plugin );
5925         }
5926     }
5927 
5928     /**
5929      * Updates the entries position for a directory
5930      * 
5931      * @param request
5932      *            The HTTP request
5933      * @throws AccessDeniedException
5934      *             the {@link AccessDeniedException}
5935      * @return The URL to go after performing the action
5936      */
5937     public String updateEntryOrder( HttpServletRequest request ) throws AccessDeniedException
5938     {
5939         Plugin plugin = getPlugin( );
5940         String strIdDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
5941         int nIdDirectory = DirectoryUtils.convertStringToInt( strIdDirectory );
5942 
5943         EntryFilter filter = new EntryFilter( );
5944         filter.setIdDirectory( nIdDirectory );
5945         filter.setIsEntryParentNull( EntryFilter.FILTER_TRUE );
5946 
5947         List<IEntry> listEntryFirstLevel = EntryHome.getEntryList( filter, plugin );
5948 
5949         int position = 1;
5950 
5951         for ( IEntry entry : listEntryFirstLevel )
5952         {
5953             entry.setPosition( position );
5954             EntryHome.update( entry, plugin );
5955             position++;
5956 
5957             EntryFilter filterSecondLevel = new EntryFilter( );
5958             filterSecondLevel.setIdEntryParent( entry.getIdEntry( ) );
5959 
5960             List<IEntry> listEntrySecondLevel = EntryHome.getEntryList( filterSecondLevel, plugin );
5961 
5962             if ( listEntrySecondLevel != null )
5963             {
5964                 for ( IEntry entrySecondLevel : listEntrySecondLevel )
5965                 {
5966                     entrySecondLevel.setPosition( position );
5967                     EntryHome.update( entrySecondLevel, plugin );
5968                     position++;
5969                 }
5970             }
5971         }
5972 
5973         return getJspModifyDirectory( request, nIdDirectory );
5974     }
5975 }