1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.document.web;
35
36 import fr.paris.lutece.plugins.document.business.Document;
37 import fr.paris.lutece.plugins.document.business.DocumentFilter;
38 import fr.paris.lutece.plugins.document.business.DocumentHome;
39 import fr.paris.lutece.plugins.document.business.DocumentMassAction;
40 import fr.paris.lutece.plugins.document.business.DocumentPageTemplate;
41 import fr.paris.lutece.plugins.document.business.DocumentPageTemplateHome;
42 import fr.paris.lutece.plugins.document.business.DocumentType;
43 import fr.paris.lutece.plugins.document.business.DocumentTypeHome;
44 import fr.paris.lutece.plugins.document.business.IndexerAction;
45 import fr.paris.lutece.plugins.document.business.spaces.DocumentSpace;
46 import fr.paris.lutece.plugins.document.business.spaces.DocumentSpaceHome;
47 import fr.paris.lutece.plugins.document.business.spaces.SpaceAction;
48 import fr.paris.lutece.plugins.document.business.spaces.SpaceActionHome;
49 import fr.paris.lutece.plugins.document.business.workflow.DocumentAction;
50 import fr.paris.lutece.plugins.document.business.workflow.DocumentActionHome;
51 import fr.paris.lutece.plugins.document.business.workflow.DocumentState;
52 import fr.paris.lutece.plugins.document.business.workflow.DocumentStateHome;
53 import fr.paris.lutece.plugins.document.service.DocumentException;
54 import fr.paris.lutece.plugins.document.service.DocumentMassActionResourceService;
55 import fr.paris.lutece.plugins.document.service.DocumentService;
56 import fr.paris.lutece.plugins.document.service.DocumentTypeResourceIdService;
57 import fr.paris.lutece.plugins.document.service.category.CategoryService;
58 import fr.paris.lutece.plugins.document.service.category.CategoryService.CategoryDisplay;
59 import fr.paris.lutece.plugins.document.service.metadata.MetadataHandler;
60 import fr.paris.lutece.plugins.document.service.publishing.PublishingService;
61 import fr.paris.lutece.plugins.document.service.search.DocumentIndexer;
62 import fr.paris.lutece.plugins.document.service.spaces.DocumentSpacesService;
63 import fr.paris.lutece.plugins.document.utils.DocumentIndexerUtils;
64 import fr.paris.lutece.plugins.document.utils.IntegerUtils;
65 import fr.paris.lutece.portal.business.resourceenhancer.ResourceEnhancer;
66 import fr.paris.lutece.portal.business.right.Right;
67 import fr.paris.lutece.portal.business.right.RightHome;
68 import fr.paris.lutece.portal.business.user.AdminUser;
69 import fr.paris.lutece.portal.service.admin.AccessDeniedException;
70 import fr.paris.lutece.portal.service.admin.PasswordResetException;
71 import fr.paris.lutece.portal.service.html.XmlTransformerService;
72 import fr.paris.lutece.portal.service.i18n.I18nService;
73 import fr.paris.lutece.portal.service.mailinglist.AdminMailingListService;
74 import fr.paris.lutece.portal.service.message.AdminMessage;
75 import fr.paris.lutece.portal.service.message.AdminMessageService;
76 import fr.paris.lutece.portal.service.plugin.PluginService;
77 import fr.paris.lutece.portal.service.rbac.RBACService;
78 import fr.paris.lutece.portal.service.search.IndexationService;
79 import fr.paris.lutece.portal.service.template.AppTemplateService;
80 import fr.paris.lutece.portal.service.util.AppLogService;
81 import fr.paris.lutece.portal.service.util.AppPathService;
82 import fr.paris.lutece.portal.service.util.AppPropertiesService;
83 import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupService;
84 import fr.paris.lutece.portal.web.admin.PluginAdminPageJspBean;
85 import fr.paris.lutece.portal.web.constants.Messages;
86 import fr.paris.lutece.portal.web.constants.Parameters;
87 import fr.paris.lutece.portal.web.pluginaction.DefaultPluginActionResult;
88 import fr.paris.lutece.portal.web.pluginaction.IPluginActionResult;
89 import fr.paris.lutece.portal.web.resource.ExtendableResourcePluginActionManager;
90 import fr.paris.lutece.portal.web.upload.MultipartHttpServletRequest;
91 import fr.paris.lutece.portal.web.util.LocalizedPaginator;
92 import fr.paris.lutece.util.ReferenceList;
93 import fr.paris.lutece.util.UniqueIDGenerator;
94 import fr.paris.lutece.util.date.DateUtil;
95 import fr.paris.lutece.util.html.HtmlTemplate;
96 import fr.paris.lutece.util.html.Paginator;
97 import fr.paris.lutece.util.sort.AttributeComparator;
98 import fr.paris.lutece.util.url.UrlItem;
99
100 import org.apache.commons.collections.CollectionUtils;
101 import org.apache.commons.lang3.ArrayUtils;
102 import org.apache.commons.lang3.StringUtils;
103
104 import java.text.DateFormat;
105 import java.text.ParseException;
106 import java.text.SimpleDateFormat;
107
108 import java.util.ArrayList;
109 import java.util.Collection;
110 import java.util.Collections;
111 import java.util.Date;
112 import java.util.HashMap;
113 import java.util.List;
114 import java.util.Map;
115
116 import javax.servlet.http.HttpServletRequest;
117
118 import javax.xml.transform.Source;
119
120
121
122
123
124 public class DocumentJspBean extends PluginAdminPageJspBean
125 {
126 public static final String RIGHT_DOCUMENT_MANAGEMENT = "DOCUMENT_MANAGEMENT";
127 public static final String PARAMETER_SPACE_ID_FILTER = "id_space_filter";
128 private static final long serialVersionUID = 3884593136805763150L;
129 private static final String SPACE_TREE_XSL_UNIQUE_PREFIX = UniqueIDGenerator.getNewId( ) + "SpacesTree";
130 private static final String DOCUMENT_STYLE_PREFIX_ID = UniqueIDGenerator.getNewId( ) + "document-";
131
132
133 private static final String TEMPLATE_MANAGE_DOCUMENTS = "admin/plugins/document/manage_documents.html";
134 private static final String TEMPLATE_CREATE_DOCUMENT = "admin/plugins/document/create_document.html";
135 private static final String TEMPLATE_MODIFY_DOCUMENT = "admin/plugins/document/modify_document.html";
136 private static final String TEMPLATE_PREVIEW_DOCUMENT = "admin/plugins/document/preview_document.html";
137 private static final String TEMPLATE_MOVE_DOCUMENT = "admin/plugins/document/move_document.html";
138 private static final String TEMPLATE_DOCUMENT_PAGE_TEMPLATE_ROW = "admin/plugins/document/page_template_list_row.html";
139 private static final String TEMPLATE_FORM_CATEGORY = "admin/plugins/document/category/list_category.html";
140 private static final String TEMPLATE_MASS_ARCHIVAL = "admin/plugins/document/mass_archival.html";
141
142
143 private static final String MARK_DOCUMENT = "document";
144 private static final String MARK_PREVIEW = "preview";
145 private static final String MARK_DOCUMENTS_LIST = "documents_list";
146 private static final String MARK_DOCUMENT_TYPES_LIST = "document_types_list";
147 private static final String MARK_MASS_ACTION = "mass_action";
148 private static final String MARK_DOCUMENT_TYPES_FILTER_LIST = "document_types_filter_list";
149 private static final String MARK_STATES_FILTER_LIST = "states_filter_list";
150 private static final String MARK_SPACES_TREE = "spaces_tree";
151 private static final String MARK_CURRENT_SPACE_ID = "current_space_id";
152 private static final String MARK_SPACE_ACTIONS_LIST = "space_actions_list";
153 private static final String MARK_SPACE = "space";
154 private static final String MARK_STATE_ID = "id_state";
155 private static final String MARK_CHILD_SPACES_LIST = "child_spaces_list";
156 private static final String MARK_FIELDS = "fields";
157 private static final String MARK_CURRENT_DATE = "current_date";
158 private static final String MARK_DOCUMENT_TYPE = "document_type";
159 private static final String MARK_DATE_MIN = "date_min";
160 private static final String MARK_DATE_MAX = "date_max";
161 private static final String MARK_DEFAULT_DOCUMENT_TYPE = "default_document_type";
162 private static final String MARK_DEFAULT_STATE = "default_state";
163 private static final String MARK_PAGINATOR = "paginator";
164 private static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page";
165 private static final String MARK_VIEW_TYPE = "view_type";
166 private static final String MARK_VIEW_TYPES_LIST = "view_types_list";
167 private static final String MARK_WEBAPP_URL = "webapp_url";
168 private static final String MARK_LOCALE = "locale";
169 private static final String MARK_CATEGORY = "category";
170 private static final String MARK_CATEGORY_LIST = "category_list";
171 private static final String MARK_METADATA = "metadata";
172 private static final String MARK_SUBMIT_BUTTON_DISABLED = "submit_button_disabled";
173 private static final String MARK_DATE_VALIDITY_BEGIN = "date_validity_begin";
174 private static final String MARK_DATE_VALIDITY_END = "date_validity_end";
175 private static final String MARK_MAILINGLISTS_LIST = "mailinglists_list";
176 private static final String MARK_DOCUMENT_PAGE_TEMPLATES_LIST = "page_template_list";
177 private static final String MARK_DOCUMENT_PAGE_TEMPLATE = "document_page_template";
178 private static final String MARK_INDEX_ROW = "index_row";
179 private static final String MARK_DOCUMENT_PAGE_TEMPLATE_CHECKED = "checked";
180 private static final String MARK_SPACES_BROWSER = "spaces_browser";
181 private static final String MARK_SELECTED_CRITERIA = "selected_criteria";
182 private static final String MARK_IS_FILES2DOCS_PLUGIN_ACTIVE = "is_files2docs_plugin_active";
183
184
185 private static final String PARAMETER_DOCUMENT_TYPE_CODE = "document_type_code";
186 private static final String PARAMETER_DATE_MIN = "date_min";
187 private static final String PARAMETER_DATE_MAX = "date_max";
188 private static final String PARAMETER_DOCUMENT_ID = "id_document";
189 private static final String PARAMETER_STATE_ID = "id_state";
190 private static final String PARAMETER_ACTION_ID = "id_action";
191 private static final String PARAMETER_VIEW_TYPE = "view_type";
192 private static final String PARAMETER_DOCUMENT_TYPE_CODE_FILTER = "document_type_code_filter";
193 private static final String PARAMETER_STATE_ID_FILTER = "id_state_filter";
194 private static final String PARAMETER_SELECTION = "selection";
195 private static final String PARAMETER_DOCUMENT_SELECTION = "document_selection";
196 private static final String PARAMETER_HEADER_REFERER = "referer";
197 private static final String PARAMETER_FROM_URL = "fromUrl";
198 private static final String PARAMETER_ARCHIVAL_CRITERIA = "archival_criteria";
199 private static final String PARAMETER_ACTION = "action";
200
201
202 private static final String PROPERTY_FILTER_ALL = "document.manage_documents.filter.labelAll";
203 private static final String PROPERTY_DOCUMENTS_PER_PAGE = "document.documentsPerPage";
204 private static final String PROPERTY_DEFAULT_VIEW_TYPE = "document.manageDocuments.defaultViewType";
205 private static final String PROPERTY_PREVIEW_DOCUMENT_PAGE_TITLE = "document.preview_document.pageTitle";
206 private static final String PROPERTY_MOVE_DOCUMENT_PAGE_TITLE = "document.move_document.pageTitle";
207 private static final String PROPERTY_RESOURCE_TYPE = "document";
208 private static final String PROPERTY_WORKFLOW_AUTOVALIDATION = "document.workflow.auto_validation";
209
210
211 private static final String JSP_DELETE_DOCUMENT = "DoDeleteDocument.jsp";
212 private static final String JSP_PREVIEW_DOCUMENT = "PreviewDocument.jsp";
213 private static final String JSP_ARCHIVE_DOCUMENT = "DoArchiveDocument.jsp";
214 private static final String JSP_DO_REMOVE_SELECTION = "jsp/admin/plugins/document/DoRemoveSelection.jsp";
215 private static final String JSP_DO_ARCHIVE_SELECTION = "DoArchiveSelection.jsp";
216 private static final String JSP_DOCUMENTS_PUBLISHING = "ManageDocumentPublishing.jsp";
217
218
219 private static final String MESSAGE_CONFIRM_DELETE = "document.message.confirmDeleteDocument";
220 private static final String MESSAGE_CONFIRM_MASS_ARCHIVE = "document.message.confirmMassArchivalDocument";
221 private static final String MESSAGE_NO_MASS_ARCHIVE = "document.message.noMassArchivalDocument";
222 private static final String MESSAGE_INVALID_DOCUMENT_ID = "document.message.invalidDocumentId";
223 private static final String MESSAGE_DOCUMENT_NOT_FOUND = "document.message.documentNotFound";
224 private static final String MESSAGE_DOCUMENT_NOT_AUTHORIZED = "document.message.documentNotAuthorized";
225 private static final String MESSAGE_MOVING_NOT_AUTHORIZED = "document.message.movingNotAuthorized";
226 private static final String MESSAGE_DOCUMENT_IS_PUBLISHED = "document.message.documentIsPublished";
227 private static final String MESSAGE_ERROR_DOCUMENT_IS_PUBLISHED = "document.message.errorDocumentIsPublished";
228 private static final String MESSAGE_DOCUMENT_ERROR = "document.message.documentError";
229 private static final String MESSAGE_CONFIRM_DELETE_SELECTION = "document.message.confirmDeleteSelection";
230 private static final String MESSAGE_CONFIRM_ARCHIVE_SELECTION = "document.message.selectionPublished";
231 private static final String MESSAGE_ERROR_DOCUMENT_SELECTED_IS_PUBLISHED = "document.message.errorDocumentSelectedIsPublished";
232
233
234 private static final String CONSTANT_REMOVE = "remove";
235 private static final String CONSTANT_VALIDATE = "validate";
236 private static final String CONSTANT_ARCHIVE = "archive";
237 private static final String CONSTANT_REFUSE = "refuse";
238 private static final String CONSTANT_UNARCHIVE = "unarchive";
239 private static final String CONSTANT_SUBMIT = "submit";
240 private static final String CONSTANT_AND = "&";
241 private static final String CONSTANT_AND_HTML = "%26";
242 private static final String PATH_JSP = "jsp/admin/plugins/document/";
243 private static final String XSL_PARAMETER_CURRENT_SPACE = "current-space-id";
244 private static final String FILTER_ALL = "-1";
245 private static final String PAGE_INDEX_FIRST = "1";
246 private static final String CONSTANT_DATE_FORMAT = "dd/MM/yyyy";
247 private static final String CONSTANT_FILES2DOC_PLUGIN_NAME = "files2docs" ;
248
249 private String _strCurrentDocumentTypeFilter;
250 private String _strCurrentStateFilter;
251 private String _strCurrentSpaceId;
252 private String _strCurrentPageIndex;
253 private int _nItemsPerPage;
254 private String _strViewType;
255 private int _nDefaultItemsPerPage;
256 private String[] _multiSelectionValues;
257 private String _strFeatureUrl;
258 private String _strSavedReferer;
259
260
261
262
263 public DocumentJspBean( )
264 {
265 _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_DOCUMENTS_PER_PAGE, 10 );
266 }
267
268
269
270
271
272
273 public String getManageDocuments( HttpServletRequest request )
274 {
275 this._strSavedReferer = null;
276 setPageTitleProperty( null );
277
278 AdminUser user = getUser( );
279
280
281 DocumentFilternt/business/DocumentFilter.html#DocumentFilter">DocumentFilter filter = new DocumentFilter( );
282 _strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
283 _strCurrentDocumentTypeFilter = getDocumentType( request, filter );
284 _strCurrentStateFilter = getState( request, filter );
285 _strCurrentSpaceId = getSpaceId( request, filter );
286 _nItemsPerPage = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage,
287 _nDefaultItemsPerPage );
288 _strViewType = getViewType( request );
289
290
291 if ( !DocumentSpacesService.getInstance( )
292 .isAuthorizedViewByWorkgroup( IntegerUtils.convert( _strCurrentSpaceId ), user ) ||
293 !DocumentSpacesService.getInstance( )
294 .isAuthorizedViewByRole( IntegerUtils.convert( _strCurrentSpaceId ), user ) )
295 {
296 filter.setIdSpace( DocumentSpacesService.getInstance( ).getUserDefaultSpace( user ) );
297 _strCurrentSpaceId = Integer.toString( filter.getIdSpace( ) );
298 }
299
300
301 Collection<Integer> listDocumentIds = DocumentHome.findPrimaryKeysByFilter( filter, getLocale( ) );
302
303
304 String strXmlSpaces = DocumentSpacesService.getInstance( ).getXmlSpacesList( user );
305 Source sourceXsl = DocumentSpacesService.getInstance( ).getTreeXsl( );
306 Map<String, String> htXslParameters = new HashMap<String, String>( );
307 htXslParameters.put( XSL_PARAMETER_CURRENT_SPACE, _strCurrentSpaceId );
308
309 XmlTransformerService xmlTransformerService = new XmlTransformerService( );
310 String strSpacesTree = xmlTransformerService.transformBySourceWithXslCache( strXmlSpaces, sourceXsl,
311 SPACE_TREE_XSL_UNIQUE_PREFIX, htXslParameters, null );
312
313 List<SpaceAction> listSpaceActions = SpaceActionHome.getActionsList( getLocale( ) );
314 int nCurrentSpaceId = IntegerUtils.convert( _strCurrentSpaceId );
315 DocumentSpace currentSpace = DocumentSpaceHome.findByPrimaryKey( nCurrentSpaceId );
316 listSpaceActions = (List<SpaceAction>) RBACService.getAuthorizedActionsCollection( listSpaceActions,
317 currentSpace, getUser( ) );
318
319
320
321 ReferenceList listDocumentTypes = DocumentSpaceHome.getAllowedDocumentTypes( IntegerUtils.convert(
322 _strCurrentSpaceId ) );
323 listDocumentTypes = RBACService.getAuthorizedReferenceList( listDocumentTypes, DocumentType.RESOURCE_TYPE,
324 DocumentTypeResourceIdService.PERMISSION_VIEW, user );
325 listDocumentTypes.addItem( FILTER_ALL, I18nService.getLocalizedString( PROPERTY_FILTER_ALL, getLocale( ) ) );
326
327
328 ReferenceList listStates = DocumentStateHome.getDocumentStatesList( getLocale( ) );
329 listStates.addItem( FILTER_ALL, I18nService.getLocalizedString( PROPERTY_FILTER_ALL, getLocale( ) ) );
330
331
332 Collection<DocumentSpace> listChildSpaces = DocumentSpaceHome.findChilds( nCurrentSpaceId );
333 listChildSpaces = AdminWorkgroupService.getAuthorizedCollection( listChildSpaces, user );
334
335
336 ReferenceList listCreateDocumentTypes = DocumentSpaceHome.getAllowedDocumentTypes( IntegerUtils.convert(
337 _strCurrentSpaceId ) );
338 listCreateDocumentTypes = RBACService.getAuthorizedReferenceList( listCreateDocumentTypes,
339 DocumentType.RESOURCE_TYPE, DocumentTypeResourceIdService.PERMISSION_CREATE, user );
340
341 LocalizedPaginator<Integer> paginator = new LocalizedPaginator<Integer>( (List<Integer>) listDocumentIds,
342 _nItemsPerPage, getHomeUrl( request ), Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex,
343 getLocale( ) );
344
345 List<Document> listDocuments = new ArrayList<Document>( );
346
347 for ( Integer documentId : paginator.getPageItems( ) )
348 {
349 Document document = DocumentHome.findByPrimaryKeyWithoutBinaries( documentId );
350
351 if ( document != null )
352 {
353 document.setLocale( getLocale( ) );
354 DocumentService.getInstance( ).getActions( document, getLocale( ), getUser( ) );
355
356 DocumentService.getInstance( ).getPublishedStatus( document );
357 listDocuments.add( document );
358 }
359 }
360
361 String strSortedAttributeName = request.getParameter( Parameters.SORTED_ATTRIBUTE_NAME );
362 String strAscSort = null;
363
364 if ( strSortedAttributeName != null )
365 {
366 strAscSort = request.getParameter( Parameters.SORTED_ASC );
367
368 boolean bIsAscSort = Boolean.parseBoolean( strAscSort );
369
370 Collections.sort( listDocuments, new AttributeComparator( strSortedAttributeName, bIsAscSort ) );
371 }
372
373 HashMap<String, Object> model = new HashMap<String, Object>( );
374 model.put( MARK_SPACES_TREE, strSpacesTree );
375 model.put( MARK_SPACE_ACTIONS_LIST, listSpaceActions );
376 model.put( MARK_SPACE, currentSpace );
377 model.put( MARK_PAGINATOR, paginator );
378 model.put( MARK_NB_ITEMS_PER_PAGE, StringUtils.EMPTY + _nItemsPerPage );
379 model.put( MARK_VIEW_TYPES_LIST, DocumentSpaceHome.getViewTypeList( getLocale( ) ) );
380 model.put( MARK_VIEW_TYPE, _strViewType );
381 model.put( MARK_DOCUMENTS_LIST, listDocuments );
382 model.put( MARK_DOCUMENT_TYPES_FILTER_LIST, listDocumentTypes );
383 model.put( MARK_DEFAULT_DOCUMENT_TYPE, _strCurrentDocumentTypeFilter );
384 model.put( MARK_STATES_FILTER_LIST, listStates );
385 model.put( MARK_DEFAULT_STATE, _strCurrentStateFilter );
386 model.put( MARK_CHILD_SPACES_LIST, listChildSpaces );
387 model.put( MARK_DOCUMENT_TYPES_LIST, listCreateDocumentTypes );
388 model.put( MARK_CURRENT_SPACE_ID, _strCurrentSpaceId );
389 model.put( MARK_MASS_ACTION,
390 RBACService.isAuthorized( new DocumentMassAction( ),
391 DocumentMassActionResourceService.PERMISSION_MASS_ARCHIVE, user ) );
392
393 model.put( MARK_IS_FILES2DOCS_PLUGIN_ACTIVE , PluginService.isPluginEnable( CONSTANT_FILES2DOC_PLUGIN_NAME ) );
394
395 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_DOCUMENTS, getLocale( ), model );
396
397 return getAdminPage( template.getHtml( ) );
398 }
399
400
401
402
403
404
405 public String getCreateDocument( HttpServletRequest request )
406 {
407 saveReferer( request );
408
409 String strDocumentTypeCode = request.getParameter( PARAMETER_DOCUMENT_TYPE_CODE );
410
411 if ( ( _strCurrentSpaceId == null ) ||
412 ( !DocumentService.getInstance( )
413 .isAuthorizedAdminDocument( IntegerUtils.convert( _strCurrentSpaceId ),
414 strDocumentTypeCode, DocumentTypeResourceIdService.PERMISSION_CREATE, getUser( ) ) ) )
415 {
416 return getManageDocuments( request );
417 }
418
419 DocumentType documentType = DocumentTypeHome.findByPrimaryKey( strDocumentTypeCode );
420 DateFormat dateFormat = new SimpleDateFormat( CONSTANT_DATE_FORMAT, getLocale( ) );
421 String strCurrentDate = dateFormat.format( new Date( ) );
422 Map<String, Object> model = new HashMap<String, Object>( );
423 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
424 model.put( MARK_LOCALE, getLocale( ).getLanguage( ) );
425 model.put( MARK_DOCUMENT_TYPE, documentType.getCode( ) );
426
427 model.put( MARK_CATEGORY, getCategoryCreateForm( request ) );
428 model.put( MARK_METADATA, getMetadataCreateForm( request, strDocumentTypeCode ) );
429 model.put( MARK_FIELDS,
430 DocumentService.getInstance( )
431 .getCreateForm( strDocumentTypeCode, getLocale( ), AppPathService.getBaseUrl( request ) ) );
432 model.put( MARK_CURRENT_DATE, strCurrentDate );
433
434
435 int nIndexRow = 1;
436 StringBuffer strPageTemplatesRow = new StringBuffer( );
437
438
439 for ( DocumentPageTemplate documentPageTemplate : DocumentPageTemplateHome.getPageTemplatesList( ) )
440 {
441 strPageTemplatesRow.append( getTemplatesPageList( documentPageTemplate.getId( ), 0,
442 Integer.toString( nIndexRow ) ) );
443 nIndexRow++;
444 }
445
446
447 ResourceEnhancer.getCreateResourceModelAddOn( model );
448
449 model.put( MARK_DOCUMENT_PAGE_TEMPLATES_LIST, strPageTemplatesRow );
450
451 ReferenceList listMailingLists = AdminMailingListService.getMailingLists( getUser( ) );
452 model.put( MARK_MAILINGLISTS_LIST, listMailingLists );
453
454 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_DOCUMENT, getLocale( ), model );
455
456 return getAdminPage( template.getHtml( ) );
457 }
458
459
460
461
462
463
464 private String getCategoryCreateForm( HttpServletRequest request )
465 {
466 AdminUser user = getUser( );
467 HashMap<String, Collection<CategoryDisplay>> model = new HashMap<String, Collection<CategoryDisplay>>( );
468 model.put( MARK_CATEGORY_LIST, CategoryService.getAllCategoriesDisplay( user ) );
469
470 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_FORM_CATEGORY, getLocale( ), model );
471
472 return template.getHtml( );
473 }
474
475
476
477
478
479
480
481 private String getCategoryModifyForm( HttpServletRequest request, Document document )
482 {
483 HashMap<String, Collection<CategoryDisplay>> model = new HashMap<String, Collection<CategoryDisplay>>( );
484 Collection<CategoryDisplay> listCategoryDisplay = CategoryService.getAllCategoriesDisplay( document.getCategories( ),
485 getUser( ) );
486
487 model.put( MARK_CATEGORY_LIST, listCategoryDisplay );
488
489 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_FORM_CATEGORY, getLocale( ), model );
490
491 return template.getHtml( );
492 }
493
494
495
496
497
498
499
500 private String getMetadataCreateForm( HttpServletRequest request, String strDocumentTypeCode )
501 {
502 MetadataHandler hMetadata = getMetadataHandler( strDocumentTypeCode );
503
504 return ( hMetadata != null ) ? hMetadata.getCreateForm( request ) : StringUtils.EMPTY;
505 }
506
507
508
509
510
511
512
513 private String getMetadataModifyForm( HttpServletRequest request, Document document )
514 {
515 MetadataHandler hMetadata = getMetadataHandler( document.getCodeDocumentType( ) );
516
517 return ( hMetadata != null ) ? hMetadata.getModifyForm( request, document.getXmlMetadata( ) ) : StringUtils.EMPTY;
518 }
519
520
521
522
523
524
525 private MetadataHandler getMetadataHandler( String strDocumentTypeCode )
526 {
527 DocumentType documentType = DocumentTypeHome.findByPrimaryKey( strDocumentTypeCode );
528
529 return documentType.metadataHandler( );
530 }
531
532
533
534
535
536
537 public String doCreateDocument( HttpServletRequest request )
538 {
539 saveReferer( request );
540
541 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
542
543 AdminUser user = getUser( );
544
545 String strDocumentTypeCode = request.getParameter( PARAMETER_DOCUMENT_TYPE_CODE );
546
547 if ( !DocumentService.getInstance( )
548 .isAuthorizedAdminDocument( IntegerUtils.convert( _strCurrentSpaceId ),
549 strDocumentTypeCode, DocumentTypeResourceIdService.PERMISSION_CREATE, user ) )
550 {
551 return getHomeUrl( request );
552 }
553
554 Documentcument/business/Document.html#Document">Document document = new Document( );
555 document.setCodeDocumentType( strDocumentTypeCode );
556
557 String strError = DocumentService.getInstance( ).getDocumentData( multipartRequest, document, getLocale( ) );
558
559 if ( strError != null )
560 {
561 return strError;
562 }
563
564 document.setSpaceId( IntegerUtils.convert( _strCurrentSpaceId ) );
565 document.setStateId( 1 );
566 document.setCreatorId( getUser( ).getUserId( ) );
567
568 try
569 {
570 DocumentService.getInstance( ).createDocument( document, getUser( ) );
571 }
572 catch ( DocumentException e )
573 {
574 return getErrorMessageUrl( request, e.getI18nMessage( ) );
575 }
576
577
578 ResourceEnhancer.doCreateResourceAddOn( request, PROPERTY_RESOURCE_TYPE, document.getId( ) );
579
580
581
582 if ( AppPropertiesService.getPropertyBoolean( PROPERTY_WORKFLOW_AUTOVALIDATION, false ) )
583 {
584 String strDocumentId = Integer.toString( document.getId( ) );
585
586 try
587 {
588 DocumentService.getInstance( )
589 .changeDocumentState( document, getUser( ), DocumentState.STATE_WAITING_FOR_APPROVAL );
590
591
592 document = DocumentHome.findByPrimaryKeyWithoutBinaries( IntegerUtils.convert( strDocumentId ) );
593
594 DocumentService.getInstance( )
595 .validateDocument( document, getUser( ), DocumentState.STATE_VALIDATE );
596 }
597 catch ( DocumentException e )
598 {
599 return getErrorMessageUrl( request, e.getI18nMessage( ) );
600 }
601
602 IndexationService.addIndexerAction( strDocumentId, DocumentIndexer.INDEXER_NAME, IndexerAction.TASK_MODIFY,
603 IndexationService.ALL_DOCUMENT );
604
605 DocumentIndexerUtils.addIndexerAction( strDocumentId, IndexerAction.TASK_MODIFY, IndexationService.ALL_DOCUMENT );
606 }
607
608 return getHomeUrl( request );
609 }
610
611
612
613
614
615
616 public String getModifyDocument( HttpServletRequest request )
617 {
618 saveReferer( request );
619
620 String strDocumentId = request.getParameter( PARAMETER_DOCUMENT_ID );
621 Document document = DocumentHome.findByPrimaryKeyWithoutBinaries( IntegerUtils.convert( strDocumentId ) );
622
623 if ( ( document == null ) ||
624 !DocumentService.getInstance( )
625 .isAuthorizedAdminDocument( document.getSpaceId( ),
626 document.getCodeDocumentType( ), DocumentTypeResourceIdService.PERMISSION_MODIFY, getUser( ) ) )
627 {
628 return getManageDocuments( request );
629 }
630
631 String strStateId = ( request.getParameter( PARAMETER_STATE_ID ) != null )
632 ? request.getParameter( PARAMETER_STATE_ID ) : StringUtils.EMPTY;
633 Map<String, Object> model = new HashMap<String, Object>( );
634 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
635 model.put( MARK_LOCALE, getLocale( ).getLanguage( ) );
636 model.put( MARK_DOCUMENT, document );
637
638
639 model.put( MARK_DATE_VALIDITY_BEGIN,
640 ( document.getDateValidityBegin( ) == null ) ? StringUtils.EMPTY
641 : DateUtil.getDateString(
642 new Date( document.getDateValidityBegin( ).getTime( ) ), getLocale( ) ) );
643 model.put( MARK_DATE_VALIDITY_END,
644 ( document.getDateValidityEnd( ) == null ) ? StringUtils.EMPTY
645 : DateUtil.getDateString(
646 new Date( document.getDateValidityEnd( ).getTime( ) ), getLocale( ) ) );
647
648
649 int nIndexRow = 1;
650 StringBuffer strPageTemplatesRow = new StringBuffer( );
651
652
653 for ( DocumentPageTemplate documentPageTemplate : DocumentPageTemplateHome.getPageTemplatesList( ) )
654 {
655 strPageTemplatesRow.append( getTemplatesPageList( documentPageTemplate.getId( ),
656 document.getPageTemplateDocumentId( ), Integer.toString( nIndexRow ) ) );
657 nIndexRow++;
658 }
659
660 model.put( MARK_DOCUMENT_PAGE_TEMPLATES_LIST, strPageTemplatesRow );
661
662 ReferenceList listMailingLists = AdminMailingListService.getMailingLists( getUser( ) );
663 model.put( MARK_MAILINGLISTS_LIST, listMailingLists );
664
665 model.put( MARK_CATEGORY, getCategoryModifyForm( request, document ) );
666 model.put( MARK_METADATA, getMetadataModifyForm( request, document ) );
667 model.put( MARK_FIELDS,
668 DocumentService.getInstance( ).getModifyForm( document, getLocale( ), AppPathService.getBaseUrl( request ) ) );
669 model.put( MARK_STATE_ID, strStateId );
670
671 ExtendableResourcePluginActionManager.fillModel( request, getUser( ), model, strDocumentId,
672 Document.PROPERTY_RESOURCE_TYPE );
673
674 ResourceEnhancer.getModifyResourceModelAddOn( model, PROPERTY_RESOURCE_TYPE, document.getId( ) );
675
676 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_DOCUMENT, getLocale( ), model );
677
678 return getAdminPage( template.getHtml( ) );
679 }
680
681
682
683
684
685
686 public String doModifyDocument( HttpServletRequest request )
687 {
688 saveReferer( request );
689
690 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
691 String strDocumentId = multipartRequest.getParameter( PARAMETER_DOCUMENT_ID );
692 Document document = DocumentHome.findByPrimaryKey( IntegerUtils.convert( strDocumentId ) );
693
694 if ( ( document == null ) ||
695 !DocumentService.getInstance( )
696 .isAuthorizedAdminDocument( document.getSpaceId( ),
697 document.getCodeDocumentType( ), DocumentTypeResourceIdService.PERMISSION_MODIFY, getUser( ) ) )
698 {
699 return getHomeUrl( request );
700 }
701
702 String strError = DocumentService.getInstance( ).getDocumentData( multipartRequest, document, getLocale( ) );
703
704 if ( strError != null )
705 {
706 return strError;
707 }
708
709 try
710 {
711 DocumentService.getInstance( ).modifyDocument( document, getUser( ) );
712 }
713 catch ( DocumentException e )
714 {
715 return getErrorMessageUrl( request, e.getI18nMessage( ) );
716 }
717
718
719 String strStateId = multipartRequest.getParameter( PARAMETER_STATE_ID );
720
721 if ( IntegerUtils.isNumeric( strStateId ) )
722 {
723 int nStateId = IntegerUtils.convert( strStateId );
724
725 try
726 {
727 DocumentService.getInstance( ).changeDocumentState( document, getUser( ), nStateId );
728 }
729 catch ( DocumentException e )
730 {
731 return getErrorMessageUrl( request, e.getI18nMessage( ) );
732 }
733 }
734
735 ResourceEnhancer.doModifyResourceAddOn( request, PROPERTY_RESOURCE_TYPE, document.getId( ) );
736
737
738
739 if ( AppPropertiesService.getPropertyBoolean( PROPERTY_WORKFLOW_AUTOVALIDATION, false ) )
740 {
741 try
742 {
743 DocumentService.getInstance( )
744 .changeDocumentState( document, getUser( ), DocumentState.STATE_WAITING_FOR_APPROVAL );
745
746
747 document = DocumentHome.findByPrimaryKeyWithoutBinaries( IntegerUtils.convert( strDocumentId ) );
748
749 DocumentService.getInstance( )
750 .validateDocument( document, getUser( ), DocumentState.STATE_VALIDATE );
751 }
752 catch ( DocumentException e )
753 {
754 return getErrorMessageUrl( request, e.getI18nMessage( ) );
755 }
756
757 IndexationService.addIndexerAction( strDocumentId, DocumentIndexer.INDEXER_NAME, IndexerAction.TASK_MODIFY,
758 IndexationService.ALL_DOCUMENT );
759
760 DocumentIndexerUtils.addIndexerAction( strDocumentId, IndexerAction.TASK_MODIFY, IndexationService.ALL_DOCUMENT );
761 }
762
763 return getHomeUrl( request );
764 }
765
766
767
768
769
770
771 public String deleteDocument( HttpServletRequest request )
772 {
773 saveReferer( request );
774
775 String strDocumentId = request.getParameter( PARAMETER_DOCUMENT_ID );
776 int nDocumentId = IntegerUtils.convert( strDocumentId );
777 Document document = DocumentHome.findByPrimaryKeyWithoutBinaries( nDocumentId );
778
779 if ( !DocumentService.getInstance( )
780 .isAuthorizedAdminDocument( document.getSpaceId( ), document.getCodeDocumentType( ),
781 DocumentTypeResourceIdService.PERMISSION_DELETE, getUser( ) ) )
782 {
783 return getHomeUrl( request );
784 }
785
786 Object[] messageArgs = { document.getTitle( ) };
787 UrlItem url = new UrlItem( PATH_JSP + JSP_DELETE_DOCUMENT );
788 url.addParameter( PARAMETER_DOCUMENT_ID, nDocumentId );
789
790 return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_DELETE, messageArgs, url.getUrl( ),
791 AdminMessage.TYPE_CONFIRMATION );
792 }
793
794
795
796
797
798
799 public String doDeleteDocument( HttpServletRequest request )
800 {
801 saveReferer( request );
802
803 String strDocumentId = request.getParameter( PARAMETER_DOCUMENT_ID );
804 int nDocumentId = IntegerUtils.convert( strDocumentId );
805 Document document = DocumentHome.findByPrimaryKeyWithoutBinaries( nDocumentId );
806
807 if ( ( document != null ) &&
808 !DocumentService.getInstance( )
809 .isAuthorizedAdminDocument( document.getSpaceId( ),
810 document.getCodeDocumentType( ), DocumentTypeResourceIdService.PERMISSION_DELETE, getUser( ) ) )
811 {
812 return getHomeUrl( request );
813 }
814
815
816 boolean bPublishedDocument = PublishingService.getInstance( ).isAssigned( nDocumentId );
817
818 if ( bPublishedDocument )
819 {
820 return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_DOCUMENT_IS_PUBLISHED,
821 AdminMessage.TYPE_STOP );
822 }
823
824 DocumentHome.remove( nDocumentId );
825
826 ResourceEnhancer.doDeleteResourceAddOn( request, PROPERTY_RESOURCE_TYPE, nDocumentId );
827
828 return getHomeUrl( request );
829 }
830
831
832
833
834
835
836 public String doChangeState( HttpServletRequest request )
837 {
838 saveReferer( request );
839
840 String strDocumentId = request.getParameter( PARAMETER_DOCUMENT_ID );
841 String strActionId = request.getParameter( PARAMETER_ACTION_ID );
842 int nDocumentId = -1;
843 int nActionId = -1;
844
845 try
846 {
847 nDocumentId = Integer.parseInt( strDocumentId );
848 nActionId = Integer.parseInt( strActionId );
849 }
850 catch ( NumberFormatException ne )
851 {
852 AppLogService.error( ne );
853 }
854
855 Document document = DocumentHome.findByPrimaryKeyWithoutBinaries( nDocumentId );
856 DocumentAction action = DocumentActionHome.findByPrimaryKey( nActionId );
857
858 if ( ( action == null ) || ( action.getFinishDocumentState( ) == null ) || ( document == null ) ||
859 !DocumentService.getInstance( )
860 .isAuthorizedAdminDocument( document.getSpaceId( ),
861 document.getCodeDocumentType( ), action.getPermission( ), getUser( ) ) )
862 {
863 return getHomeUrl( request );
864 }
865
866 try
867 {
868 DocumentService.getInstance( )
869 .changeDocumentState( document, getUser( ), action.getFinishDocumentState( ).getId( ) );
870 }
871 catch ( DocumentException e )
872 {
873 return getErrorMessageUrl( request, e.getI18nMessage( ) );
874 }
875
876 return getHomeUrl( request );
877 }
878
879
880
881
882
883
884 public String doValidateDocument( HttpServletRequest request )
885 {
886 saveReferer( request );
887
888 String strDocumentId = request.getParameter( PARAMETER_DOCUMENT_ID );
889 String strActionId = request.getParameter( PARAMETER_ACTION_ID );
890 int nDocumentId = -1;
891 int nActionId = -1;
892
893 try
894 {
895 nDocumentId = Integer.parseInt( strDocumentId );
896 nActionId = Integer.parseInt( strActionId );
897 }
898 catch ( NumberFormatException ne )
899 {
900 AppLogService.error( ne );
901 }
902
903 Document document = DocumentHome.findByPrimaryKeyWithoutBinaries( nDocumentId );
904 DocumentAction action = DocumentActionHome.findByPrimaryKey( nActionId );
905
906 if ( ( action == null ) || ( action.getFinishDocumentState( ) == null ) || ( document == null ) ||
907 !DocumentService.getInstance( )
908 .isAuthorizedAdminDocument( document.getSpaceId( ),
909 document.getCodeDocumentType( ), action.getPermission( ), getUser( ) ) )
910 {
911 return getHomeUrl( request );
912 }
913
914 try
915 {
916 DocumentService.getInstance( )
917 .validateDocument( document, getUser( ), action.getFinishDocumentState( ).getId( ) );
918 }
919 catch ( DocumentException e )
920 {
921 return getErrorMessageUrl( request, e.getI18nMessage( ) );
922 }
923
924 String strIdDocument = Integer.toString( nDocumentId );
925 IndexationService.addIndexerAction( strIdDocument, DocumentIndexer.INDEXER_NAME, IndexerAction.TASK_MODIFY,
926 IndexationService.ALL_DOCUMENT );
927
928 DocumentIndexerUtils.addIndexerAction( strIdDocument, IndexerAction.TASK_MODIFY, IndexationService.ALL_DOCUMENT );
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945 return getHomeUrl( request );
946 }
947
948
949
950
951
952
953 public String doConfirmArchiveDocument( HttpServletRequest request )
954 {
955 saveReferer( request );
956
957 String strDocumentId = request.getParameter( PARAMETER_DOCUMENT_ID );
958 String strActionId = request.getParameter( PARAMETER_ACTION_ID );
959 int nDocumentId = -1;
960 int nActionId = -1;
961
962 try
963 {
964 nDocumentId = Integer.parseInt( strDocumentId );
965 nActionId = Integer.parseInt( strActionId );
966 }
967 catch ( NumberFormatException ne )
968 {
969 AppLogService.error( ne );
970 }
971
972 Document document = DocumentHome.findByPrimaryKeyWithoutBinaries( nDocumentId );
973 DocumentAction action = DocumentActionHome.findByPrimaryKey( nActionId );
974
975 if ( ( action == null ) || ( action.getFinishDocumentState( ) == null ) || ( document == null ) ||
976 !DocumentService.getInstance( )
977 .isAuthorizedAdminDocument( document.getSpaceId( ),
978 document.getCodeDocumentType( ), action.getPermission( ), getUser( ) ) )
979 {
980 return getHomeUrl( request );
981 }
982
983 UrlItem url = new UrlItem( JSP_ARCHIVE_DOCUMENT );
984 url.addParameter( PARAMETER_DOCUMENT_ID, nDocumentId );
985 url.addParameter( PARAMETER_ACTION_ID, nActionId );
986
987
988 boolean bPublishedDocument = PublishingService.getInstance( ).isAssigned( nDocumentId );
989
990 if ( bPublishedDocument )
991 {
992 return AdminMessageService.getMessageUrl( request, MESSAGE_DOCUMENT_IS_PUBLISHED,
993 PATH_JSP + url.getUrl( ), AdminMessage.TYPE_QUESTION );
994 }
995
996 return url.getUrl( );
997 }
998
999
1000
1001
1002
1003
1004 public String doRemoveSelection( HttpServletRequest request )
1005 {
1006 int nDocumentId;
1007
1008 for ( String strIdDocument : _multiSelectionValues )
1009 {
1010 try
1011 {
1012 nDocumentId = Integer.parseInt( strIdDocument );
1013
1014 Document document = DocumentHome.findByPrimaryKeyWithoutBinaries( nDocumentId );
1015
1016 if ( !DocumentService.getInstance( )
1017 .isAuthorizedAdminDocument( document.getSpaceId( ),
1018 document.getCodeDocumentType( ), DocumentTypeResourceIdService.PERMISSION_DELETE,
1019 getUser( ) ) )
1020 {
1021 return getHomeUrl( request );
1022 }
1023
1024 if ( ( document.getStateId( ) == DocumentState.STATE_WRITING ) ||
1025 ( document.getStateId( ) == DocumentState.STATE_ARCHIVED ) )
1026 {
1027
1028 boolean bPublishedDocument = PublishingService.getInstance( ).isAssigned( nDocumentId );
1029
1030 if ( bPublishedDocument )
1031 {
1032 return AdminMessageService.getMessageUrl( request,
1033 MESSAGE_ERROR_DOCUMENT_SELECTED_IS_PUBLISHED, AdminMessage.TYPE_STOP );
1034 }
1035
1036 DocumentHome.remove( nDocumentId );
1037 }
1038 }
1039 catch ( NumberFormatException ne )
1040 {
1041 AppLogService.error( ne );
1042 }
1043 }
1044
1045 return getHomeUrl( request );
1046 }
1047
1048
1049
1050
1051
1052
1053 public String doArchiveSelection( HttpServletRequest request )
1054 {
1055 int nDocumentId;
1056
1057 for ( String strIdDocument : _multiSelectionValues )
1058 {
1059 try
1060 {
1061 nDocumentId = Integer.parseInt( strIdDocument );
1062
1063 Document document = DocumentHome.findByPrimaryKeyWithoutBinaries( nDocumentId );
1064
1065 if ( isAuthorized( DocumentAction.ACTION_ARCHIVE, document ) )
1066 {
1067 try
1068 {
1069 DocumentService.getInstance( )
1070 .archiveDocument( document, getUser( ), DocumentState.STATE_ARCHIVED );
1071 }
1072 catch ( DocumentException e )
1073 {
1074 return getErrorMessageUrl( request, e.getI18nMessage( ) );
1075 }
1076 }
1077 }
1078 catch ( NumberFormatException ne )
1079 {
1080 AppLogService.error( ne );
1081 }
1082 }
1083
1084 return getHomeUrl( request );
1085 }
1086
1087
1088
1089
1090
1091
1092 public String doActionSelectionDocument( HttpServletRequest request )
1093 {
1094 String strAction = request.getParameter( PARAMETER_SELECTION );
1095 String[] strIdDocuments = (String[]) request.getParameterMap( ).get( PARAMETER_DOCUMENT_SELECTION );
1096 _multiSelectionValues = strIdDocuments;
1097
1098 int nbDocumentsAffected = 0;
1099
1100 if ( !ArrayUtils.isEmpty( strIdDocuments ) )
1101 {
1102 if ( strAction.equals( CONSTANT_REMOVE ) )
1103 {
1104 UrlItem url = new UrlItem( JSP_DO_REMOVE_SELECTION );
1105
1106 return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_DELETE_SELECTION, url.getUrl( ),
1107 AdminMessage.TYPE_CONFIRMATION );
1108 }
1109 else if ( strAction.equals( CONSTANT_ARCHIVE ) )
1110 {
1111 UrlItem url = new UrlItem( JSP_DO_ARCHIVE_SELECTION );
1112
1113 for ( String strIdDocument : _multiSelectionValues )
1114 {
1115 int nIdDocument = IntegerUtils.convert( strIdDocument );
1116
1117 Document document = DocumentHome.findByPrimaryKey( nIdDocument );
1118
1119
1120 boolean bPublishedDocument = PublishingService.getInstance( ).isAssigned( nIdDocument );
1121
1122 if ( ( document != null ) && ( document.getStateId( ) == DocumentState.STATE_VALIDATE ) &&
1123 ( bPublishedDocument ) )
1124 {
1125 return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_ARCHIVE_SELECTION,
1126 PATH_JSP + url.getUrl( ), AdminMessage.TYPE_QUESTION );
1127 }
1128 }
1129
1130 for ( String strIdDocument : _multiSelectionValues )
1131 {
1132 int nIdDocument = IntegerUtils.convert( strIdDocument );
1133
1134 Document document = DocumentHome.findByPrimaryKey( nIdDocument );
1135
1136 try
1137 {
1138 if ( ( document != null ) && ( document.getStateId( ) == DocumentState.STATE_VALIDATE ) &&
1139 isAuthorized( DocumentAction.ACTION_ARCHIVE, document ) )
1140 {
1141 DocumentService.getInstance( )
1142 .archiveDocument( document, getUser( ), DocumentState.STATE_ARCHIVED );
1143 }
1144 }
1145 catch ( DocumentException e )
1146 {
1147 return getErrorMessageUrl( request, e.getI18nMessage( ) );
1148 }
1149 }
1150 }
1151 else
1152 {
1153 for ( String strIdDocument : strIdDocuments )
1154 {
1155 int nIdDocument = IntegerUtils.convert( strIdDocument );
1156 int nActionId = -1;
1157 Document document = DocumentHome.findByPrimaryKey( nIdDocument );
1158
1159 if ( document != null )
1160 {
1161 int stateId = document.getStateId( );
1162
1163 if ( ( strAction.equals( CONSTANT_VALIDATE ) ) &&
1164 ( ( stateId == DocumentState.STATE_WAITING_FOR_APPROVAL ) ||
1165 ( stateId == DocumentState.STATE_WAITING_FOR_CHANGE_APPROVAL ) ) )
1166 {
1167 try
1168 {
1169
1170 if ( stateId == DocumentState.STATE_WAITING_FOR_APPROVAL )
1171 {
1172 nActionId = DocumentAction.ACTION_VALIDATE;
1173 }
1174 else if ( stateId == DocumentState.STATE_WAITING_FOR_CHANGE_APPROVAL )
1175 {
1176 nActionId = DocumentAction.ACTION_VALIDATE_CHANGE;
1177 }
1178
1179 if ( isAuthorized( nActionId, document ) )
1180 {
1181 DocumentService.getInstance( )
1182 .validateDocument( document, getUser( ),
1183 DocumentState.STATE_VALIDATE );
1184 nbDocumentsAffected++;
1185 }
1186 }
1187 catch ( DocumentException e )
1188 {
1189 return getErrorMessageUrl( request, e.getI18nMessage( ) );
1190 }
1191 }
1192 else if ( ( strAction.equals( CONSTANT_REFUSE ) ) &&
1193 ( ( stateId == DocumentState.STATE_WAITING_FOR_APPROVAL ) ||
1194 ( stateId == DocumentState.STATE_WAITING_FOR_CHANGE_APPROVAL ) ) )
1195 {
1196 try
1197 {
1198 if ( stateId == DocumentState.STATE_WAITING_FOR_APPROVAL )
1199 {
1200 nActionId = DocumentAction.ACTION_REFUSE;
1201
1202 if ( isAuthorized( nActionId, document ) )
1203 {
1204 DocumentService.getInstance( )
1205 .changeDocumentState( document, getUser( ),
1206 DocumentState.STATE_REJECTED );
1207 }
1208 }
1209 else if ( stateId == DocumentState.STATE_WAITING_FOR_CHANGE_APPROVAL )
1210 {
1211 nActionId = DocumentAction.ACTION_REFUSE_CHANGE;
1212
1213 if ( isAuthorized( nActionId, document ) )
1214 {
1215 DocumentService.getInstance( )
1216 .changeDocumentState( document, getUser( ),
1217 DocumentState.STATE_IN_CHANGE );
1218 }
1219 }
1220
1221 nbDocumentsAffected++;
1222 }
1223 catch ( DocumentException e )
1224 {
1225 return getErrorMessageUrl( request, e.getI18nMessage( ) );
1226 }
1227 }
1228 else if ( ( strAction.equals( CONSTANT_UNARCHIVE ) ) &&
1229 ( stateId == DocumentState.STATE_ARCHIVED ) )
1230 {
1231 nActionId = DocumentAction.ACTION_UNARCHIVE;
1232
1233 try
1234 {
1235 if ( isAuthorized( nActionId, document ) )
1236 {
1237 DocumentService.getInstance( )
1238 .changeDocumentState( document, getUser( ),
1239 DocumentState.STATE_VALIDATE );
1240 nbDocumentsAffected++;
1241 }
1242 }
1243 catch ( DocumentException e )
1244 {
1245 return getErrorMessageUrl( request, e.getI18nMessage( ) );
1246 }
1247 }
1248 else if ( strAction.equals( CONSTANT_SUBMIT ) )
1249 {
1250 try
1251 {
1252 if ( ( stateId == DocumentState.STATE_WRITING ) ||
1253 ( stateId == DocumentState.STATE_REJECTED ) )
1254 {
1255 nActionId = DocumentAction.ACTION_SUBMIT;
1256 DocumentService.getInstance( )
1257 .changeDocumentState( document, getUser( ),
1258 DocumentState.STATE_WAITING_FOR_APPROVAL );
1259 nbDocumentsAffected++;
1260 }
1261 else if ( ( stateId == DocumentState.STATE_IN_CHANGE ) )
1262 {
1263 nActionId = DocumentAction.ACTION_SUBMIT_CHANGE;
1264
1265 if ( isAuthorized( nActionId, document ) )
1266 {
1267 DocumentService.getInstance( )
1268 .changeDocumentState( document, getUser( ),
1269 DocumentState.STATE_WAITING_FOR_CHANGE_APPROVAL );
1270 }
1271
1272 nbDocumentsAffected++;
1273 }
1274 }
1275 catch ( DocumentException e )
1276 {
1277 return getErrorMessageUrl( request, e.getI18nMessage( ) );
1278 }
1279 }
1280 }
1281 }
1282 }
1283 }
1284
1285 return getHomeUrl( request );
1286 }
1287
1288
1289
1290
1291
1292
1293 public String doArchiveDocument( HttpServletRequest request )
1294 {
1295 saveReferer( request );
1296
1297 String strDocumentId = request.getParameter( PARAMETER_DOCUMENT_ID );
1298 String strActionId = request.getParameter( PARAMETER_ACTION_ID );
1299
1300 int nDocumentId = -1;
1301 int nActionId = -1;
1302
1303 try
1304 {
1305 nDocumentId = Integer.parseInt( strDocumentId );
1306 nActionId = Integer.parseInt( strActionId );
1307 }
1308 catch ( NumberFormatException ne )
1309 {
1310 AppLogService.error( ne );
1311 }
1312
1313 Document document = DocumentHome.findByPrimaryKeyWithoutBinaries( nDocumentId );
1314 DocumentAction action = DocumentActionHome.findByPrimaryKey( nActionId );
1315
1316 if ( ( action == null ) || ( action.getFinishDocumentState( ) == null ) || ( document == null ) ||
1317 !DocumentService.getInstance( )
1318 .isAuthorizedAdminDocument( document.getSpaceId( ),
1319 document.getCodeDocumentType( ), action.getPermission( ), getUser( ) ) )
1320 {
1321 return getHomeUrl( request );
1322 }
1323
1324 try
1325 {
1326 DocumentService.getInstance( )
1327 .archiveDocument( document, getUser( ), action.getFinishDocumentState( ).getId( ) );
1328 }
1329 catch ( DocumentException e )
1330 {
1331 return getErrorMessageUrl( request, e.getI18nMessage( ) );
1332 }
1333
1334 return getHomeUrl( request );
1335 }
1336
1337
1338
1339
1340
1341
1342 public String doSearchDocumentById( HttpServletRequest request )
1343 {
1344 saveReferer( request );
1345
1346 String strDocumentId = request.getParameter( PARAMETER_DOCUMENT_ID );
1347 int nDocumentId;
1348
1349 try
1350 {
1351 nDocumentId = Integer.parseInt( strDocumentId );
1352 }
1353 catch ( NumberFormatException e )
1354 {
1355 return AdminMessageService.getMessageUrl( request, MESSAGE_INVALID_DOCUMENT_ID, AdminMessage.TYPE_STOP );
1356 }
1357
1358 Document document = DocumentHome.findByPrimaryKeyWithoutBinaries( nDocumentId );
1359
1360 if ( document == null )
1361 {
1362 return AdminMessageService.getMessageUrl( request, MESSAGE_DOCUMENT_NOT_FOUND, AdminMessage.TYPE_STOP );
1363 }
1364
1365 if ( !DocumentService.getInstance( )
1366 .isAuthorizedAdminDocument( document.getSpaceId( ), document.getCodeDocumentType( ),
1367 DocumentTypeResourceIdService.PERMISSION_VIEW, getUser( ) ) )
1368 {
1369 return AdminMessageService.getMessageUrl( request, MESSAGE_DOCUMENT_NOT_AUTHORIZED, AdminMessage.TYPE_STOP );
1370 }
1371
1372 UrlItem url = new UrlItem( JSP_PREVIEW_DOCUMENT );
1373 url.addParameter( PARAMETER_DOCUMENT_ID, nDocumentId );
1374
1375 return url.getUrl( );
1376 }
1377
1378
1379
1380
1381
1382
1383 public String getPreviewDocument( HttpServletRequest request )
1384 {
1385 saveReferer( request );
1386 setPageTitleProperty( PROPERTY_PREVIEW_DOCUMENT_PAGE_TITLE );
1387
1388 String strDocumentId = request.getParameter( PARAMETER_DOCUMENT_ID );
1389 int nDocumentId = IntegerUtils.convert( strDocumentId );
1390
1391 Document document = DocumentHome.findByPrimaryKeyWithoutBinaries( nDocumentId );
1392
1393 if ( ( document == null ) ||
1394 !DocumentService.getInstance( )
1395 .isAuthorizedAdminDocument( document.getSpaceId( ),
1396 document.getCodeDocumentType( ), DocumentTypeResourceIdService.PERMISSION_VIEW, getUser( ) ) )
1397 {
1398 return getManageDocuments( request );
1399 }
1400
1401 document.setLocale( getLocale( ) );
1402 DocumentService.getInstance( ).getActions( document, getLocale( ), getUser( ) );
1403
1404 DocumentType type = DocumentTypeHome.findByPrimaryKey( document.getCodeDocumentType( ) );
1405
1406 XmlTransformerService xmlTransformerService = new XmlTransformerService( );
1407 String strPreview = xmlTransformerService.transformBySourceWithXslCache( document.getXmlWorkingContent( ),
1408 type.getAdminXslSource( ), DOCUMENT_STYLE_PREFIX_ID + type.getAdminStyleSheetId( ), null, null );
1409
1410 Map<String, Object> model = new HashMap<String, Object>( );
1411 model.put( MARK_DOCUMENT, document );
1412 model.put( MARK_PREVIEW, strPreview );
1413
1414 ExtendableResourcePluginActionManager.fillModel( request, getUser( ), model, strDocumentId,
1415 Document.PROPERTY_RESOURCE_TYPE );
1416
1417 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_PREVIEW_DOCUMENT, getLocale( ), model );
1418
1419 return getAdminPage( template.getHtml( ) );
1420 }
1421
1422
1423
1424
1425
1426
1427 public String getMoveDocument( HttpServletRequest request )
1428 {
1429 saveReferer( request );
1430 setPageTitleProperty( PROPERTY_MOVE_DOCUMENT_PAGE_TITLE );
1431
1432 String strDocumentId = request.getParameter( PARAMETER_DOCUMENT_ID );
1433 Document document = DocumentHome.findByPrimaryKeyWithoutBinaries( IntegerUtils.convert( strDocumentId ) );
1434
1435 if ( ( document == null ) ||
1436 !DocumentService.getInstance( )
1437 .isAuthorizedAdminDocument( document.getSpaceId( ),
1438 document.getCodeDocumentType( ), DocumentTypeResourceIdService.PERMISSION_MOVE, getUser( ) ) )
1439 {
1440 return getManageDocuments( request );
1441 }
1442
1443 Map<String, Object> model = new HashMap<String, Object>( );
1444 String strSpaceId = request.getParameter( DocumentSpacesService.PARAMETER_BROWSER_SELECTED_SPACE_ID );
1445 boolean bSubmitButtonDisabled = Boolean.TRUE;
1446
1447 if ( ( strSpaceId != null ) && !strSpaceId.equals( StringUtils.EMPTY ) )
1448 {
1449 bSubmitButtonDisabled = Boolean.FALSE;
1450 }
1451
1452
1453 model.put( MARK_SPACES_BROWSER,
1454 DocumentSpacesService.getInstance( ).getSpacesBrowser( request, getUser( ), getLocale( ), true, true ) );
1455 model.put( MARK_DOCUMENT, document );
1456 model.put( MARK_SUBMIT_BUTTON_DISABLED, bSubmitButtonDisabled );
1457
1458 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MOVE_DOCUMENT, getLocale( ), model );
1459
1460 return getAdminPage( template.getHtml( ) );
1461 }
1462
1463
1464
1465
1466
1467
1468 public String doMoveDocument( HttpServletRequest request )
1469 {
1470 saveReferer( request );
1471
1472 boolean bTypeAllowed = Boolean.FALSE;
1473 String strSpaceId = request.getParameter( DocumentSpacesService.PARAMETER_BROWSER_SELECTED_SPACE_ID );
1474
1475 if ( strSpaceId == null )
1476 {
1477 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
1478 }
1479
1480 int nSpaceIdDestination = IntegerUtils.convert( strSpaceId );
1481 DocumentSpace space = DocumentSpaceHome.findByPrimaryKey( nSpaceIdDestination );
1482 String strDocumentId = request.getParameter( PARAMETER_DOCUMENT_ID );
1483 Document document = DocumentHome.findByPrimaryKeyWithoutBinaries( IntegerUtils.convert( strDocumentId ) );
1484
1485 if ( document == null )
1486 {
1487 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_ERROR );
1488 }
1489
1490
1491 if ( !DocumentService.getInstance( )
1492 .isAuthorizedAdminDocument( document.getSpaceId( ), document.getCodeDocumentType( ),
1493 DocumentTypeResourceIdService.PERMISSION_MOVE, getUser( ) ) ||
1494 !DocumentService.getInstance( )
1495 .isAuthorizedAdminDocument( nSpaceIdDestination, document.getCodeDocumentType( ),
1496 DocumentTypeResourceIdService.PERMISSION_MOVE, getUser( ) ) )
1497 {
1498 return getHomeUrl( request );
1499 }
1500
1501 for ( String documentType : space.getAllowedDocumentTypes( ) )
1502 {
1503 if ( document.getCodeDocumentType( ).equals( documentType ) )
1504 {
1505 bTypeAllowed = Boolean.TRUE;
1506 }
1507 }
1508
1509 if ( bTypeAllowed )
1510 {
1511 document.setSpaceId( nSpaceIdDestination );
1512 DocumentHome.update( document, false );
1513
1514 return getHomeUrl( request );
1515 }
1516
1517 return AdminMessageService.getMessageUrl( request, MESSAGE_MOVING_NOT_AUTHORIZED, AdminMessage.TYPE_STOP );
1518 }
1519
1520
1521
1522
1523
1524
1525 public IPluginActionResult getMassArchivalDocument( HttpServletRequest request )
1526 {
1527 IPluginActionResult result = new DefaultPluginActionResult( );
1528
1529 if ( !RBACService.isAuthorized( new DocumentMassAction( ),
1530 DocumentMassActionResourceService.PERMISSION_MASS_ARCHIVE, getUser( ) ) )
1531 {
1532 result.setHtmlContent( getManageDocuments( request ) );
1533
1534 return result;
1535 }
1536
1537
1538 request.getSession( ).removeAttribute( "to_archive" );
1539
1540 String strAction = request.getParameter( DocumentJspBean.PARAMETER_ACTION );
1541 String strCriteria = request.getParameter( PARAMETER_ARCHIVAL_CRITERIA );
1542 String strTypeCode = request.getParameter( PARAMETER_DOCUMENT_TYPE_CODE );
1543 String strDateMin = request.getParameter( PARAMETER_DATE_MIN );
1544 String strDateMax = request.getParameter( PARAMETER_DATE_MAX );
1545
1546 if ( StringUtils.isBlank( strCriteria ) )
1547 {
1548 strCriteria = (String) request.getSession( ).getAttribute( PARAMETER_ARCHIVAL_CRITERIA );
1549 request.getSession( ).removeAttribute( PARAMETER_ARCHIVAL_CRITERIA );
1550 }
1551
1552 if ( StringUtils.isBlank( strTypeCode ) )
1553 {
1554 strTypeCode = (String) request.getSession( ).getAttribute( PARAMETER_DOCUMENT_TYPE_CODE );
1555 request.getSession( ).removeAttribute( PARAMETER_DOCUMENT_TYPE_CODE );
1556 }
1557
1558 if ( StringUtils.isBlank( strDateMin ) )
1559 {
1560 strDateMin = (String) request.getSession( ).getAttribute( PARAMETER_DATE_MIN );
1561 request.getSession( ).removeAttribute( PARAMETER_DATE_MIN );
1562 }
1563
1564 if ( StringUtils.isBlank( strDateMax ) )
1565 {
1566 strDateMax = (String) request.getSession( ).getAttribute( PARAMETER_DATE_MAX );
1567 request.getSession( ).removeAttribute( PARAMETER_DATE_MAX );
1568 }
1569
1570 if ( "apply".equals( strAction ) )
1571 {
1572 DocumentFilternt/business/DocumentFilter.html#DocumentFilter">DocumentFilter filter = new DocumentFilter( );
1573 filter.setIsPublished( false );
1574
1575 request.getSession( ).setAttribute( PARAMETER_ARCHIVAL_CRITERIA, strCriteria );
1576
1577 if ( "date".equals( strCriteria ) )
1578 {
1579 if ( StringUtils.isBlank( strDateMin ) && StringUtils.isBlank( strDateMax ) )
1580 {
1581 result.setRedirect( AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS,
1582 "jsp/admin/plugins/document/MassArchivalDocument.jsp", AdminMessage.TYPE_ERROR ) );
1583 }
1584 else
1585 {
1586 try
1587 {
1588 SimpleDateFormat sdf = new SimpleDateFormat( "dd/MM/yyyy" );
1589 SimpleDateFormat sqlSdf = new SimpleDateFormat( "yyyy-MM-dd" );
1590
1591 if ( StringUtils.isNotBlank( strDateMin ) )
1592 {
1593 Date dateMin;
1594 dateMin = sdf.parse( strDateMin );
1595 filter.setDateMin( sqlSdf.format( dateMin ) );
1596 }
1597
1598 if ( StringUtils.isNotBlank( strDateMax ) )
1599 {
1600 Date dateMax = sdf.parse( strDateMax );
1601 filter.setDateMax( sqlSdf.format( dateMax ) );
1602 }
1603
1604 request.getSession( ).setAttribute( PARAMETER_DATE_MIN, strDateMin );
1605 request.getSession( ).setAttribute( PARAMETER_DATE_MAX, strDateMax );
1606 }
1607 catch ( ParseException e )
1608 {
1609 AppLogService.error( e );
1610 }
1611 }
1612 }
1613 else if ( "space".equals( strCriteria ) )
1614 {
1615 String strSpaceId = request.getParameter( DocumentSpacesService.PARAMETER_BROWSER_SELECTED_SPACE_ID );
1616
1617 if ( StringUtils.isBlank( strSpaceId ) || !StringUtils.isNumeric( strSpaceId ) )
1618 {
1619 result.setRedirect( AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS,
1620 "jsp/admin/plugins/document/MassArchivalDocument.jsp", AdminMessage.TYPE_ERROR ) );
1621 }
1622
1623 filter.setIdSpace( Integer.valueOf( strSpaceId ) );
1624 }
1625 else if ( "type".equals( strCriteria ) )
1626 {
1627 request.getSession( ).setAttribute( PARAMETER_DOCUMENT_TYPE_CODE, strTypeCode );
1628 filter.setCodeDocumentType( strTypeCode );
1629 }
1630 else
1631 {
1632 result.setRedirect( AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS,
1633 "jsp/admin/plugins/document/MassArchivalDocument.jsp", AdminMessage.TYPE_ERROR ) );
1634 }
1635
1636 if ( result.getRedirect( ) == null )
1637 {
1638 List<Document> documents = DocumentHome.findByFilter( filter, getLocale( ) );
1639 List<Document> toArchive = new ArrayList<Document>( );
1640
1641 for ( Document doc : documents )
1642 {
1643 if ( isAuthorized( DocumentAction.ACTION_ARCHIVE, doc ) )
1644 {
1645 toArchive.add( doc );
1646 }
1647 }
1648
1649 if ( CollectionUtils.isNotEmpty( toArchive ) )
1650 {
1651 request.getSession( ).setAttribute( "to_archive", toArchive );
1652 result.setRedirect( AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_MASS_ARCHIVE,
1653 new String[] { toArchive.size( ) + "" },
1654 "jsp/admin/plugins/document/DoMassArchivalDocument.jsp", AdminMessage.TYPE_CONFIRMATION ) );
1655 }
1656 else
1657 {
1658 result.setRedirect( AdminMessageService.getMessageUrl( request, MESSAGE_NO_MASS_ARCHIVE,
1659 "jsp/admin/plugins/document/MassArchivalDocument.jsp", AdminMessage.TYPE_ERROR ) );
1660 }
1661 }
1662 }
1663 else
1664 {
1665 Map<String, Object> model = new HashMap<String, Object>( );
1666 model.put( MARK_SELECTED_CRITERIA, StringUtils.defaultString( strCriteria, "date" ) );
1667 model.put( MARK_LOCALE, getLocale( ).getLanguage( ) );
1668 model.put( MARK_SPACES_BROWSER,
1669 DocumentSpacesService.getInstance( ).getSpacesBrowser( request, getUser( ), getLocale( ), false, true ) );
1670 model.put( MARK_DOCUMENT_TYPES_LIST, DocumentTypeHome.findAll( ) );
1671 model.put( MARK_DOCUMENT_TYPE, StringUtils.defaultString( strTypeCode ) );
1672 model.put( MARK_DATE_MIN, StringUtils.defaultString( strDateMin ) );
1673 model.put( MARK_DATE_MAX, StringUtils.defaultString( strDateMax ) );
1674
1675 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MASS_ARCHIVAL, getLocale( ), model );
1676 result.setHtmlContent( getAdminPage( template.getHtml( ) ) );
1677 }
1678
1679 return result;
1680 }
1681
1682
1683
1684
1685
1686
1687
1688 public String doMassArchivalDocument( HttpServletRequest request )
1689 throws DocumentException
1690 {
1691 List<Document> documents = (List<Document>) request.getSession( ).getAttribute( "to_archive" );
1692 request.getSession( ).removeAttribute( "to_archive" );
1693
1694 for ( Document doc : documents )
1695 {
1696 DocumentService.getInstance( ).archiveDocument( doc, getUser( ), DocumentState.STATE_ARCHIVED );
1697 }
1698
1699 return getManageDocuments( request );
1700 }
1701
1702
1703
1704 private String getViewType( HttpServletRequest request )
1705 {
1706 String strViewType = request.getParameter( PARAMETER_VIEW_TYPE );
1707
1708 if ( strViewType == null )
1709 {
1710 if ( _strViewType != null )
1711 {
1712 strViewType = _strViewType;
1713 }
1714 else
1715 {
1716 strViewType = AppPropertiesService.getProperty( PROPERTY_DEFAULT_VIEW_TYPE );
1717 }
1718 }
1719 else
1720 {
1721 updateSpaceView( strViewType );
1722 }
1723
1724 return strViewType;
1725 }
1726
1727
1728
1729
1730
1731 private void setView( int nSpaceId )
1732 {
1733 DocumentSpace space = DocumentSpaceHome.findByPrimaryKey( nSpaceId );
1734
1735 if ( space != null )
1736 {
1737 _strViewType = space.getViewType( );
1738 }
1739 }
1740
1741
1742
1743
1744
1745
1746
1747 private String getDocumentType( HttpServletRequest request, DocumentFilter filter )
1748 {
1749
1750 String strCodeDocumentTypeFilter = request.getParameter( PARAMETER_DOCUMENT_TYPE_CODE_FILTER );
1751
1752 if ( strCodeDocumentTypeFilter == null )
1753 {
1754 if ( _strCurrentDocumentTypeFilter != null )
1755 {
1756 strCodeDocumentTypeFilter = _strCurrentDocumentTypeFilter;
1757 }
1758 else
1759 {
1760 strCodeDocumentTypeFilter = FILTER_ALL;
1761 }
1762 }
1763
1764 if ( !strCodeDocumentTypeFilter.equals( FILTER_ALL ) )
1765 {
1766 filter.setCodeDocumentType( strCodeDocumentTypeFilter );
1767 }
1768
1769 if ( !strCodeDocumentTypeFilter.equals( _strCurrentDocumentTypeFilter ) )
1770 {
1771 resetPageIndex( );
1772 }
1773
1774 return strCodeDocumentTypeFilter;
1775 }
1776
1777
1778
1779
1780
1781
1782
1783 private String getState( HttpServletRequest request, DocumentFilter filter )
1784 {
1785 String strStateId = request.getParameter( PARAMETER_STATE_ID_FILTER );
1786
1787 if ( strStateId == null )
1788 {
1789 if ( _strCurrentStateFilter != null )
1790 {
1791 strStateId = _strCurrentStateFilter;
1792 }
1793 else
1794 {
1795 strStateId = FILTER_ALL;
1796 }
1797 }
1798
1799 if ( !strStateId.equals( FILTER_ALL ) )
1800 {
1801 int nStateId = IntegerUtils.convert( strStateId );
1802 filter.setIdState( nStateId );
1803 }
1804
1805 if ( !strStateId.equals( _strCurrentStateFilter ) )
1806 {
1807 resetPageIndex( );
1808 }
1809
1810 return strStateId;
1811 }
1812
1813
1814
1815
1816
1817
1818
1819 private String getSpaceId( HttpServletRequest request, DocumentFilter filter )
1820 {
1821 String strSpaceId = request.getParameter( PARAMETER_SPACE_ID_FILTER );
1822
1823 if ( strSpaceId == null )
1824 {
1825 if ( ( _strCurrentSpaceId != null ) && !_strCurrentSpaceId.equals( "-1" ) )
1826 {
1827 strSpaceId = _strCurrentSpaceId;
1828 }
1829 else
1830 {
1831 int nSpaceId = DocumentSpacesService.getInstance( ).getUserDefaultSpace( getUser( ) );
1832 strSpaceId = Integer.toString( nSpaceId );
1833 }
1834 }
1835
1836 int nSpaceId = IntegerUtils.convert( strSpaceId );
1837 filter.setIdSpace( nSpaceId );
1838
1839 if ( !strSpaceId.equals( _strCurrentSpaceId ) )
1840 {
1841
1842 resetPageIndex( );
1843
1844
1845 setView( nSpaceId );
1846 }
1847
1848 return strSpaceId;
1849 }
1850
1851
1852
1853
1854 private void resetPageIndex( )
1855 {
1856 _strCurrentPageIndex = PAGE_INDEX_FIRST;
1857 }
1858
1859
1860
1861
1862
1863 private void updateSpaceView( String strViewType )
1864 {
1865 int nSpaceId = IntegerUtils.convert( _strCurrentSpaceId );
1866 DocumentSpace space = DocumentSpaceHome.findByPrimaryKey( nSpaceId );
1867
1868 if ( space != null )
1869 {
1870 space.setViewType( strViewType );
1871 DocumentSpaceHome.update( space );
1872 }
1873 }
1874
1875
1876
1877
1878
1879
1880
1881 private String getErrorMessageUrl( HttpServletRequest request, String strI18nMessage )
1882 {
1883 return AdminMessageService.getMessageUrl( request, MESSAGE_DOCUMENT_ERROR,
1884 new String[] { I18nService.getLocalizedString( strI18nMessage, getLocale( ) ) }, AdminMessage.TYPE_ERROR );
1885 }
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896 private String getTemplatesPageList( int nTemplatePageId, int nPageTemplateDocumentId, String nIndexRow )
1897 {
1898 Map<String, Object> model = new HashMap<String, Object>( );
1899 DocumentPageTemplate documentPageTemplate = DocumentPageTemplateHome.findByPrimaryKey( nTemplatePageId );
1900 model.put( MARK_DOCUMENT_PAGE_TEMPLATE, documentPageTemplate );
1901
1902 model.put( MARK_INDEX_ROW, nIndexRow );
1903
1904 String strChecked = ( documentPageTemplate.getId( ) == nPageTemplateDocumentId ) ? "checked=\"checked\"" : "";
1905 model.put( MARK_DOCUMENT_PAGE_TEMPLATE_CHECKED, strChecked );
1906
1907 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_DOCUMENT_PAGE_TEMPLATE_ROW, getLocale( ),
1908 model );
1909
1910 return template.getHtml( );
1911 }
1912
1913 private boolean isAuthorized( int nActionId, Document document )
1914 {
1915 DocumentAction action = DocumentActionHome.findByPrimaryKey( nActionId );
1916
1917 if ( ( action == null ) || ( action.getFinishDocumentState( ) == null ) || ( document == null ) ||
1918 !DocumentService.getInstance( )
1919 .isAuthorizedAdminDocument( document.getSpaceId( ),
1920 document.getCodeDocumentType( ), action.getPermission( ), getUser( ) ) )
1921 {
1922 return false;
1923 }
1924
1925 return true;
1926 }
1927
1928
1929
1930
1931
1932
1933
1934 @Override
1935 public String getHomeUrl( HttpServletRequest request )
1936 {
1937 if ( StringUtils.isNotBlank( _strSavedReferer ) )
1938 {
1939 return AppPathService.getBaseUrl( request ) + _strSavedReferer;
1940 }
1941
1942 return super.getHomeUrl( request );
1943 }
1944
1945
1946
1947
1948 @Override
1949 public void init( HttpServletRequest request, String strRight )
1950 throws AccessDeniedException, PasswordResetException
1951 {
1952 Right right = RightHome.findByPrimaryKey( strRight );
1953 _strFeatureUrl = right.getUrl( );
1954 super.init( request, strRight );
1955 }
1956
1957
1958
1959
1960
1961 private void saveReferer( HttpServletRequest request )
1962 {
1963 String strFromUrl = request.getParameter( PARAMETER_FROM_URL );
1964 String documentId = request.getParameter("id_document");
1965 if ( StringUtils.isNotBlank( strFromUrl ) )
1966 {
1967 _strSavedReferer = strFromUrl.replace( CONSTANT_AND_HTML, CONSTANT_AND );
1968 }
1969 else
1970 {
1971 String strReferer = request.getHeader( PARAMETER_HEADER_REFERER );
1972 String strAdminMenuUrl = AppPathService.getAdminMenuUrl( );
1973
1974 if ( StringUtils.contains( strReferer, strAdminMenuUrl ) )
1975 {
1976 _strSavedReferer = strAdminMenuUrl;
1977 }
1978 else if ( StringUtils.contains( strReferer, _strFeatureUrl ) || StringUtils.contains( strReferer, JSP_DOCUMENTS_PUBLISHING ))
1979 {
1980 _strSavedReferer = _strFeatureUrl + "#document_" + documentId;
1981 }
1982 }
1983 }
1984 }