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.blog.web;
35
36 import java.io.ByteArrayInputStream;
37 import java.io.IOException;
38 import java.io.InputStream;
39 import java.io.StringWriter;
40 import java.net.URLConnection;
41 import java.nio.charset.StandardCharsets;
42 import java.sql.Timestamp;
43 import java.text.ParseException;
44 import java.text.SimpleDateFormat;
45 import java.util.ArrayList;
46 import java.util.Arrays;
47 import java.util.Base64;
48 import java.util.Collections;
49 import java.util.Comparator;
50 import java.util.HashMap;
51 import java.util.List;
52 import java.util.Locale;
53 import java.util.Map;
54 import java.util.stream.Collectors;
55
56 import javax.servlet.http.HttpServletRequest;
57 import javax.servlet.http.HttpSession;
58 import javax.xml.transform.OutputKeys;
59 import javax.xml.transform.TransformerFactory;
60 import javax.xml.transform.sax.SAXTransformerFactory;
61 import javax.xml.transform.sax.TransformerHandler;
62 import javax.xml.transform.stream.StreamResult;
63
64 import fr.paris.lutece.plugins.blog.service.BlogParameterService;
65 import fr.paris.lutece.plugins.blog.utils.BlogUtils;
66 import fr.paris.lutece.portal.service.i18n.I18nService;
67 import fr.paris.lutece.util.ReferenceItem;
68 import org.apache.commons.collections.CollectionUtils;
69 import org.apache.commons.fileupload.FileItem;
70 import org.apache.commons.lang3.ArrayUtils;
71 import org.apache.commons.lang3.StringUtils;
72 import org.outerj.daisy.diff.HtmlCleaner;
73 import org.outerj.daisy.diff.html.HTMLDiffer;
74 import org.outerj.daisy.diff.html.HtmlSaxDiffOutput;
75 import org.outerj.daisy.diff.html.TextNodeComparator;
76 import org.outerj.daisy.diff.html.dom.DomTreeBuilder;
77 import org.xml.sax.InputSource;
78
79 import fr.paris.lutece.api.user.User;
80 import fr.paris.lutece.plugins.blog.business.Blog;
81 import fr.paris.lutece.plugins.blog.business.BlogHome;
82 import fr.paris.lutece.plugins.blog.business.BlogSearchFilter;
83 import fr.paris.lutece.plugins.blog.business.ContentType;
84 import fr.paris.lutece.plugins.blog.business.DocContent;
85 import fr.paris.lutece.plugins.blog.business.DocContentHome;
86 import fr.paris.lutece.plugins.blog.business.Tag;
87 import fr.paris.lutece.plugins.blog.business.TagHome;
88 import fr.paris.lutece.plugins.blog.business.portlet.BlogPublication;
89 import fr.paris.lutece.plugins.blog.business.portlet.BlogPublicationHome;
90 import fr.paris.lutece.plugins.blog.service.BlogService;
91 import fr.paris.lutece.plugins.blog.service.BlogServiceSession;
92 import fr.paris.lutece.plugins.blog.service.BlogSessionListner;
93 import fr.paris.lutece.plugins.blog.service.docsearch.BlogSearchService;
94 import fr.paris.lutece.plugins.blog.utils.BlogLock;
95 import fr.paris.lutece.portal.business.rbac.RBAC;
96 import fr.paris.lutece.portal.business.user.AdminUser;
97 import fr.paris.lutece.portal.service.admin.AccessDeniedException;
98 import fr.paris.lutece.portal.service.admin.AdminUserService;
99 import fr.paris.lutece.portal.service.datastore.DatastoreService;
100 import fr.paris.lutece.portal.service.i18n.I18nService;
101 import fr.paris.lutece.portal.service.message.AdminMessage;
102 import fr.paris.lutece.portal.service.message.AdminMessageService;
103 import fr.paris.lutece.portal.service.rbac.RBACService;
104 import fr.paris.lutece.portal.service.resource.ExtendableResourceRemovalListenerService;
105 import fr.paris.lutece.portal.service.util.AppLogService;
106 import fr.paris.lutece.portal.service.util.AppPathService;
107 import fr.paris.lutece.portal.service.util.AppPropertiesService;
108 import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
109 import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
110 import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
111 import fr.paris.lutece.portal.web.resource.ExtendableResourcePluginActionManager;
112 import fr.paris.lutece.portal.web.upload.MultipartHttpServletRequest;
113 import fr.paris.lutece.portal.web.util.LocalizedPaginator;
114 import fr.paris.lutece.util.ReferenceList;
115 import fr.paris.lutece.util.html.AbstractPaginator;
116 import fr.paris.lutece.util.json.JsonResponse;
117 import fr.paris.lutece.util.json.JsonUtil;
118 import fr.paris.lutece.util.sort.AttributeComparator;
119 import fr.paris.lutece.util.url.UrlItem;
120
121
122
123 @Controller( controllerJsp = "ManageBlogs.jsp", controllerPath = "jsp/admin/plugins/blog/", right = "BLOG_MANAGEMENT" )
124 public class BlogJspBean extends ManageBlogJspBean
125 {
126 private static final long serialVersionUID = 9149742923528515045L;
127
128
129 private static final String TEMPLATE_MANAGE_BLOGS = "/admin/plugins/blog/manage_blogs.html";
130 private static final String TEMPLATE_CREATE_BLOG = "/admin/plugins/blog/create_blog.html";
131 private static final String TEMPLATE_MODIFY_BLOG = "/admin/plugins/blog/modify_blog.html";
132 private static final String TEMPLATE_HISTORY_BLOG = "admin/plugins/blog/history_blog.html";
133 private static final String TEMPLATE_PREVIEW_BLOG = "admin/plugins/blog/preview_blog.html";
134 private static final String TEMPLATE_DIFF_BLOG = "admin/plugins/blog/diff_blog.html";
135
136
137 protected static final String PARAMETER_ID_BLOG = "id";
138 protected static final String PARAMETER_VERSION_BLOG = "blog_version";
139 protected static final String PARAMETER_VERSION_BLOG2 = "blog_version2";
140 protected static final String PARAMETER_CONTENT_LABEL = "content_label";
141 protected static final String PARAMETER_HTML_CONTENT = "html_content";
142 protected static final String PARAMETER_EDIT_COMMENT = "edit_comment";
143 protected static final String PARAMETER_DESCRIPTION = "description";
144 protected static final String PARAMETER_FILE_NAME = "fileName";
145 protected static final String PARAMETER_FILE = "file";
146 protected static final String PARAMETER_VIEW = "view";
147 protected static final String PARAMETER_BUTTON_SEARCH = "button_search";
148 protected static final String PARAMETER_BUTTON_RESET = "button_reset";
149
150 protected static final String PARAMETER_SEARCH_TEXT = "search_text";
151 protected static final String PARAMETER_UPDATE_ATTACHMENT = "update_attachment";
152 protected static final String PARAMETER_TAG = "tag_doc";
153 protected static final String PARAMETER_TAG_NAME = "tag_name";
154 protected static final String PARAMETER_URL = "url";
155 protected static final String PARAMETER_UNPUBLISHED = "unpublished";
156 protected static final String PARAMETER_DATE_UPDATE_BLOG_AFTER = "dateUpdateBlogAfter";
157 protected static final String PARAMETER_DATE_UPDATE_BLOG_BEFOR = "dateUpdateBlogBefor";
158
159 protected static final String PARAMETER_TAG_TO_REMOVE = "tag_remove";
160 protected static final String PARAMETER_SHAREABLE = "shareable";
161 protected static final String PARAMETER_PRIORITY = "tag_priority";
162 protected static final String PARAMETER_TAG_ACTION = "tagAction";
163 protected static final String PARAMETER_ACTION_BUTTON = "button";
164 protected static final String PARAMETER_UPDATE = "update";
165 protected static final String PARAMETER_TYPE_ID = "idType";
166 protected static final String PARAMETER_CONTENT_ID = "idContent";
167 protected static final String PARAMETER_CONTENT_ACTION = "contentAction";
168 protected static final String PARAMETER_INFO_MESSAGE = "info_message";
169 protected static final String PARAMETER_TO_ARCHIVE = "to_archive";
170
171 protected static final String PARAMETER_SELECTED_BLOGS = "select_blog_id";
172 protected static final String PARAMETER_SELECTED_BLOG_ACTION = "select_blog_action";
173 protected static final String PARAMETER_SELECTED_BLOG_IDS_LIST = "selected_blogs_list";
174
175
176
177 private static final String PROPERTY_PAGE_TITLE_MANAGE_BLOG = "blog.manage_blogs.pageTitle";
178 private static final String PROPERTY_PAGE_TITLE_MODIFY_BLOG = "blog.modify_blog.pageTitle";
179 private static final String PROPERTY_PAGE_TITLE_CREATE_BLOG = "blog.create_blog.pageTitle";
180 private static final String PROPERTY_PAGE_TITLE_HISTORY_BLOG = "blog.history_blog.pageTitle";
181 private static final String PROPERTY_PAGE_TITLE_PREVIEW_BLOG = "blog.preview_blog.pageTitle";
182 private static final String PROPERTY_PAGE_TITLE_DIFF_BLOG = "blog.diff_blog.pageTitle";
183 protected static final String PROPERTY_USE_UPLOAD_IMAGE_PLUGIN = "use_upload_image_plugin";
184
185
186 protected static final String MARK_BLOG_LIST = "blog_list";
187 protected static final String MARK_BLOG_VERSION_LIST = "blog_version_list";
188 protected static final String MARK_BLOG = "blog";
189 protected static final String MARK_WEBAPP_URL = "webapp_url";
190 protected static final String MARK_IS_CHECKED = "is_checked";
191 protected static final String MARK_CURRENT_USER = "current_user";
192 protected static final String MARK_ID_BLOG = "id";
193 protected static final String MARK_SEARCH_TEXT = "search_text";
194 protected static final String MARK_DIFF = "blog_diff";
195 protected static final String MARK_BLOG2 = "blog2";
196 protected static final String MARK_LIST_ALLTAG = "list_alltag";
197 protected static final String MARK_LIST_TAG = "list_tag";
198 protected static final String MARK_LIST_IMAGE_TYPE = "image_type";
199 protected static final String MARK_SORTED_ATTRIBUTE = "sorted_attribute_name";
200 protected static final String MARK_TAG = "tags";
201 protected static final String MARK_USE_UPLOAD_IMAGE_PLUGIN = "is_crop_image";
202 protected static final String MARK_PERMISSION_CREATE_BLOG = "permission_manage_create_blog";
203 protected static final String MARK_PERMISSION_MODIFY_BLOG = "permission_manage_modify_blog";
204 protected static final String MARK_PERMISSION_PUBLISH_BLOG = "permission_manage_publish_blog";
205 protected static final String MARK_PERMISSION_DELETE_BLOG = "permission_manage_delete_blog";
206 protected static final String MARK_PERMISSION_ARCHIVE_BLOG = "permission_manage_archive_blog";
207 private static final String MARK_NUMBER_MANDATORY_TAGS = "number_mandatory_tags";
208 private static final String MARK_STATUS_FILTER = "status_filter";
209
210 private static final String JSP_MANAGE_BLOGS = "jsp/admin/plugins/blog/ManageBlogs.jsp";
211
212
213 private static final String PROPERTY_DEFAULT_LIST_ITEM_PER_PAGE = "blog.listItems.itemsPerPage";
214 private static final String MESSAGE_CONFIRM_REMOVE_BLOG = "blog.message.confirmRemoveBlog";
215 private static final String MESSAGE_ERROR_DOCUMENT_IS_ACTIVE = "blog.message.errorDocumentIsActive";
216 private static final String MESSAGE_CONFIRM_REMOVE_HISTORY_BLOG = "blog.message.confirmRemoveHistoryBlog";
217 private static final String ACCESS_DENIED_MESSAGE = "portal.message.user.accessDenied";
218 private static final String MESSAGE_CONFIRM_ARCHIVE_BLOG = "blog.message.confirmArchiveBlog";
219 private static final String MESSAGE_CONFIRM_ARCHIVE_PUBLISHED_BLOG = "blog.message.confirmArchivePublishedBlog";
220 private static final String MESSAGE_CONFIRM_ARCHIVE_MULTIPLE_BLOGS = "blog.message.confirmArchiveMultipleBlogs";
221 private static final String MESSAGE_CONFIRM_ARCHIVE_MULTIPLE_PUBLISHED_BLOGS = "blog.message.confirmArchiveMultiplePublishedBlogs";
222 private static final String MESSAGE_ERROR_DOCUMENT_IS_PUBLISHED = "blog.message.errorDocumentIsPublished";
223 private static final String MESSAGE_CONFIRM_UNARCHIVE_MULTIPLE_BLOGS = "blog.message.confirmUnarchiveMultipleBlogs";
224 private static final String MESSAGE_CONFIRM_UNARCHIVE_BLOG= "blog.message.confirmUnarchiveBlog";
225 private static final String MESSAGE_CONFIRM_REMOVE_MULTIPE_BLOGS = "blog.message.confirmRemoveMultipleBlogs";
226
227 private static final String INFO_BLOG_UNARCHIVED = "blog.info.blog.blogUnarchived";
228 private static final String INFO_MULTIPLE_BLOGS_UNARCHIVED = "blog.info.blog.multipleBlogsUnarchived";
229 private static final String INFO_BLOG_ARCHIVED = "blog.info.blog.blogArchived";
230 private static final String INFO_MULTIPLE_BLOGS_ARCHIVED = "blog.info.blog.multipleBlogsArchived";
231
232 private static final String VALIDATION_ATTRIBUTES_PREFIX = "blog.model.entity.blog.attribute.";
233
234
235 protected static final String VIEW_MANAGE_BLOGS = "manageBlogs";
236 private static final String VIEW_CREATE_BLOG = "createBlog";
237 private static final String VIEW_MODIFY_BLOG = "modifyBlog";
238 private static final String VIEW_HISTORY_BLOG = "historyBlog";
239 private static final String VIEW_PREVIEW_BLOG = "previewBlog";
240 private static final String VIEW_DIFF_BLOG = "diffBlog";
241
242
243 private static final String ACTION_CREATE_BLOG = "createBlog";
244 private static final String ACTION_MODIFY_BLOG = "modifyBlog";
245 private static final String ACTION_REMOVE_BLOG = "removeBlog";
246 private static final String ACTION_CONFIRM_REMOVE_BLOG = "confirmRemoveBlog";
247 private static final String ACTION_ADD_TAG = "addTag";
248 private static final String ACTION_REMOVE_TAG = "removeTag";
249 private static final String ACTION_UPDATE_PRIORITY_TAG = "updatePriorityTag";
250 private static final String ACTION_ADD_FILE_CONTENT = "addContent";
251 private static final String ACTION_REMOVE_FILE_CONTENT = "deleteContent";
252 private static final String ACTION_UPDATE_PRIORITY_FILE_CONTENT = "updatePriorityContent";
253 private static final String ACTION_UPDATE_CONTENT_TYPE = "updateContentType";
254 private static final String ACTION_DUPLICATE_BLOG = "duplicateBlog";
255 private static final String ACTION_REMOVE_HISTORY_BLOG = "removeHistoryBlog";
256 private static final String ACTION_CONFIRM_REMOVE_HISTORY_BLOG = "confirmRemoveHistoryBlog";
257 private static final String ACTION_UPDATE_ARCHIVE_MULTIPLE_BLOGS = "updateArchiveMultipleBlogs";
258 private static final String ACTION_REMOVE_MULTIPLE_BLOGS = "removeMultipleBlogs";
259 private static final String ACTION_EXECUTE_SELECTED_ACTION = "form_checkbox_action";
260 private static final String ACTION_CONFIRM_REMOVE_MULTIPLE_BLOGS = "confirmRemoveMultipleBlogs";
261 private static final String ACTION_CONFIRM_ARCHIVE_BLOGS = "confirmArchiveBlogs";
262 private static final String ACTION_CONFIRM_UNARCHIVE_BLOGS = "confirmUnarchiveBlogs";
263
264
265 private static final String INFO_BLOG_CREATED = "blog.info.blog.created";
266 private static final String INFO_BLOG_UPDATED = "blog.info.blog.updated";
267 private static final String INFO_BLOG_REMOVED = "blog.info.blog.removed";
268 private static final String BLOG_LOCKED = "blog.message.blogLocked";
269 private static final String INFO_HISTORY_BLOG_REMOVED = "blog.info.history.blog.removed";
270 private static final String INFO_MULTIPLE_BLOGS_REMOVED = "blog.info.blog.multipleBlogsRemoved";
271
272
273 private static final String ERROR_HISTORY_BLOG_CANT_REMOVE_ORIGINAL = "blog.error.history.blog.cantRemoveOriginal";
274 private static final String ERROR_HISTORY_BLOG_NOT_REMOVED = "blog.error.history.blog.notRemoved";
275 private static final String MESSAGE_ERROR_MANDATORY_TAGS = "blog.message.errorMandatoryTags";
276
277 private static final String ERROR_ACTION_EXECUTION_FAILED = "blog.message.error.action.executionFailed";
278 private static final String ERROR_ACTION_NOT_FOUND = "blog.message.error.action.notFound";
279
280 protected static final String MARK_BLOG_FILTER_LIST = "blog_filter_list";
281 protected static final String MARK_BLOG_FILTER_NAME = "Nom";
282 protected static final String MARK_BLOG_FILTER_DATE = "Date";
283 protected static final String MARK_BLOG_FILTER_USER = "Utilisateur";
284 protected static final String MARK_PAGINATOR = "paginator";
285 protected static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page";
286 protected static final String MARK_ASC_SORT = "asc_sort";
287 protected static final String MARK_DATE_UPDATE_BLOG_AFTER = "dateUpdateBlogAfter";
288 protected static final String MARK_DATE_UPDATE_BLOG_BEFOR = "dateUpdateBlogBefor";
289 protected static final String MARK_UNPUBLISHED = "unpublished";
290 protected static final String MARK_LIST_BLOG_CONTRIBUTORS = "list_blog_contributors";
291 protected static final String MARK_ACTUAL_BLOG_VERSION = "actual_blog_version";
292
293 public static final String CONSTANT_DUPLICATE_BLOG_NAME = "Copie de ";
294
295 private static final String RESPONSE_BLOG_LOCKED = "BLOG_LOCKED";
296 private static final String RESPONSE_SUCCESS = "SUCCESS";
297 private static final String RESPONSE_FAILURE = "FAILURE";
298
299
300 private static Map<Integer, BlogLock> _mapLockBlog = new HashMap<>( );
301 protected Blog _blog;
302 protected boolean _bIsChecked = false;
303 protected String _strSearchText;
304 protected int _nIsUnpublished;
305 protected String _dateUpdateBlogAfter;
306 protected String _dateUpdateBlogBefor;
307 protected String _strCurrentPageIndex;
308 protected int _nItemsPerPage;
309 protected int _nDefaultItemsPerPage;
310 protected boolean _bIsSorted = false;
311 protected String _strSortedAttributeName;
312 protected Boolean _bIsAscSort;
313 protected String [ ] _strTag;
314 private List<Integer> _listSelectedBlogIds = new ArrayList<>( );
315
316
317
318 private final BlogServiceSession _blogServiceSession = BlogServiceSession.getInstance( );
319
320
321
322
323
324
325
326
327 @View( value = VIEW_MANAGE_BLOGS, defaultView = true )
328 public String getManageBlogs( HttpServletRequest request )
329 {
330 _blog = null;
331 _strCurrentPageIndex = AbstractPaginator.getPageIndex( request, AbstractPaginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
332 _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_DEFAULT_LIST_ITEM_PER_PAGE, 50 );
333 _nItemsPerPage = AbstractPaginator.getItemsPerPage( request, AbstractPaginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage, _nDefaultItemsPerPage );
334
335 String strSortedAttributeName = request.getParameter( MARK_SORTED_ATTRIBUTE );
336 String strAscSort;
337 SimpleDateFormat isoDateFormat = new SimpleDateFormat("yyyy-MM-dd");
338 AdminUser user = AdminUserService.getAdminUser( request );
339 List<Integer> listBlogsId = new ArrayList<>( );
340 String strButtonSearch = request.getParameter( PARAMETER_BUTTON_SEARCH );
341 String strButtonReset = request.getParameter( PARAMETER_BUTTON_RESET );
342 String strUnpublished = request.getParameter(PARAMETER_UNPUBLISHED);
343
344
345
346 if ( strButtonSearch != null )
347 {
348
349 _bIsChecked = request.getParameter( MARK_CURRENT_USER ) != null;
350 _strSearchText = request.getParameter( PARAMETER_SEARCH_TEXT );
351 _strTag = request.getParameterValues( PARAMETER_TAG );
352 _dateUpdateBlogAfter = request.getParameter( PARAMETER_DATE_UPDATE_BLOG_AFTER );
353 _dateUpdateBlogBefor = request.getParameter( PARAMETER_DATE_UPDATE_BLOG_BEFOR );
354 if (StringUtils.isNotBlank(strUnpublished))
355 {
356 _nIsUnpublished = Integer.parseInt( strUnpublished );
357 }
358 else
359 {
360 _nIsUnpublished = 0;
361 }
362 }
363 else
364 {
365 if ( strButtonReset != null )
366 {
367 _bIsChecked = false;
368 _strSearchText = null;
369 _strTag = null;
370 _dateUpdateBlogAfter = null;
371 _dateUpdateBlogBefor = null;
372 _nIsUnpublished = 0;
373 }
374 }
375 if ( StringUtils.isNotBlank( _strSearchText ) || ( _strTag != null && _strTag.length > 0 ) || _bIsChecked || _nIsUnpublished > 0
376 || _dateUpdateBlogAfter != null || _dateUpdateBlogBefor != null )
377 {
378 BlogSearchFilteriness/BlogSearchFilter.html#BlogSearchFilter">BlogSearchFilter filter = new BlogSearchFilter( );
379 if ( StringUtils.isNotBlank( _strSearchText ) )
380 {
381 filter.setKeywords( BlogUtils.removeAccents( _strSearchText ) );
382 }
383 if ( !ArrayUtils.isEmpty( _strTag ) )
384 {
385 filter.setTag( _strTag );
386 }
387 if ( _bIsChecked )
388 {
389 filter.setUser( user.getAccessCode( ) );
390 }
391 if(_nIsUnpublished == 3)
392 {
393 filter.setIsArchived(true);
394 }
395 else
396 {
397 filter.setIsArchived( false );
398 }
399 filter.setIsUnpulished(_nIsUnpublished);
400
401 if ( _dateUpdateBlogAfter != null )
402 {
403 try {
404 filter.setUpdateDateAfter( isoDateFormat.parse(_dateUpdateBlogAfter)) ;
405 } catch (ParseException e) {
406 AppLogService.error( "Bad Date Format for indexed item: " + e.getMessage( ) );
407 }
408 }
409 if ( _dateUpdateBlogBefor != null )
410 {
411 try {
412 filter.setUpdateDateBefor( isoDateFormat.parse( _dateUpdateBlogBefor ) ) ;
413 } catch ( ParseException e ) {
414 AppLogService.error( "Bad Date Format for indexed item: " + e.getMessage( ) );
415 }
416 }
417
418 BlogSearchService.getInstance( ).getSearchResults( filter, listBlogsId );
419
420 }
421 else
422 {
423 listBlogsId = BlogHome.getIdBlogsList( );
424 }
425
426 LocalizedPaginator<Integer> paginator = new LocalizedPaginator<>( (List<Integer>) listBlogsId, _nItemsPerPage, getHomeUrl( request ),
427 AbstractPaginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex, getLocale( ) );
428
429 List<Blog> listDocuments = new ArrayList<>( );
430 HashMap<Integer, List<String>> mapContributors = new HashMap<>( );
431 for ( Integer documentId : paginator.getPageItems( ) )
432 {
433 Blog document = BlogService.getInstance( ).findByPrimaryKeyWithoutBinaries( documentId );
434
435 if ( document != null )
436 {
437 if ( _mapLockBlog.containsKey( document.getId( ) ) && !_mapLockBlog.get( document.getId( ) ).getSessionId( )
438 .equals( request.getSession( ).getId( ) ) )
439 {
440
441 document.setLocked( true );
442 }
443 listDocuments.add( document );
444 List<String> listContributors = BlogHome.getUsersEditedBlogVersions( document.getId( ) );
445 mapContributors.put( document.getId( ), listContributors );
446 }
447 }
448
449 if ( strSortedAttributeName != null || _bIsSorted )
450 {
451 if ( strSortedAttributeName == null )
452 {
453 strSortedAttributeName = _strSortedAttributeName;
454 }
455 strAscSort = request.getParameter( MARK_ASC_SORT );
456
457 boolean bIsAscSort = Boolean.parseBoolean( strAscSort );
458 if ( strAscSort == null )
459 {
460 bIsAscSort = _bIsAscSort;
461 }
462
463 Collections.sort( listDocuments, new AttributeComparator( strSortedAttributeName, bIsAscSort ) );
464
465 _bIsSorted = true;
466
467 _strSortedAttributeName = strSortedAttributeName;
468 _bIsAscSort = bIsAscSort;
469 }
470 boolean bPermissionCreate = RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_CREATE,
471 (User) getUser( ) );
472 boolean bPermissionModify = RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_MODIFY,
473 (User) getUser( ) );
474 boolean bPermissionDelete = RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_DELETE,
475 (User) getUser( ) );
476 boolean bPermissionPublish = RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_PUBLISH,
477 (User) getUser( ) );
478 boolean bPermissionArchive = RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_ARCHIVE,
479 (User) getUser( ) );
480
481 HttpSession session = request.getSession();
482
483 Map<String, Object> model = new HashMap<>( );
484 if( session.getAttribute(PARAMETER_INFO_MESSAGE ) != null )
485 {
486 Locale locale = request.getLocale( );
487 String messageKey = request.getSession().getAttribute(PARAMETER_INFO_MESSAGE).toString();
488 model.put( PARAMETER_INFO_MESSAGE, I18nService.getLocalizedString( messageKey, locale ) );
489 session.removeAttribute(PARAMETER_INFO_MESSAGE);
490 } else {
491 model.put( PARAMETER_INFO_MESSAGE, null );
492 }
493
494 model.put( MARK_STATUS_FILTER, _nIsUnpublished );
495 model.put( MARK_BLOG_LIST, listDocuments );
496 model.put( MARK_PAGINATOR, paginator );
497 model.put( MARK_BLOG_FILTER_LIST, getBlogFilterList( ) );
498 model.put( MARK_LIST_TAG, TagHome.getTagsReferenceList( ) );
499 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
500 model.put( MARK_IS_CHECKED, _bIsChecked );
501 model.put( MARK_SEARCH_TEXT, _strSearchText );
502 model.put( MARK_NB_ITEMS_PER_PAGE, "" + _nItemsPerPage );
503 model.put( MARK_TAG, _strTag );
504 model.put( MARK_DATE_UPDATE_BLOG_AFTER, _dateUpdateBlogAfter );
505 model.put( MARK_DATE_UPDATE_BLOG_BEFOR, _dateUpdateBlogBefor );
506 model.put( MARK_UNPUBLISHED, _nIsUnpublished );
507 model.put( MARK_LIST_BLOG_CONTRIBUTORS, mapContributors );
508 model.put( MARK_PERMISSION_CREATE_BLOG, bPermissionCreate );
509 model.put( MARK_PERMISSION_MODIFY_BLOG, bPermissionModify );
510 model.put( MARK_PERMISSION_DELETE_BLOG, bPermissionDelete );
511 model.put( MARK_PERMISSION_PUBLISH_BLOG, bPermissionPublish );
512 model.put(BlogParameterService.MARK_DEFAULT_NUMBER_MANDATORY_TAGS, BlogParameterService.getInstance().getNumberMandatoryTags() );
513 model.put( MARK_PERMISSION_ARCHIVE_BLOG, bPermissionArchive );
514
515
516 return getPage( PROPERTY_PAGE_TITLE_MANAGE_BLOG, TEMPLATE_MANAGE_BLOGS, model );
517 }
518
519
520
521
522
523
524
525
526 @View( value = VIEW_HISTORY_BLOG )
527 public String getHistoryBlog( HttpServletRequest request )
528 {
529 _blog = null;
530 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
531 List<Blog> listBlogsVersions = BlogHome.getBlogsVersionsList( nId );
532
533 UrlItem urlHistory = new UrlItem( JSP_MANAGE_BLOGS );
534 urlHistory.addParameter( PARAMETER_VIEW, VIEW_HISTORY_BLOG );
535 urlHistory.addParameter( PARAMETER_ID_BLOG, nId );
536
537 Map<String, Object> model = getPaginatedListModel( request, MARK_BLOG_LIST, listBlogsVersions, urlHistory.getUrl( ) );
538
539 model.put( MARK_ID_BLOG, nId );
540
541 return getPage( PROPERTY_PAGE_TITLE_HISTORY_BLOG, TEMPLATE_HISTORY_BLOG, model );
542 }
543
544
545
546
547
548
549
550
551
552 @Action( ACTION_CONFIRM_REMOVE_HISTORY_BLOG )
553 public String getconfirmRemoveHistoryBlog( HttpServletRequest request ) throws AccessDeniedException
554 {
555 String strId = request.getParameter( PARAMETER_ID_BLOG );
556 int nId = Integer.parseInt( strId );
557 String strVersion = request.getParameter( PARAMETER_VERSION_BLOG );
558
559 if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, strId, Blog.PERMISSION_DELETE, (User) getUser( ) ) )
560 {
561 throw new AccessDeniedException( UNAUTHORIZED );
562 }
563
564 UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_HISTORY_BLOG ) );
565 url.addParameter( PARAMETER_ID_BLOG, nId );
566 url.addParameter( PARAMETER_VERSION_BLOG, strVersion );
567
568 String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_HISTORY_BLOG, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
569
570 return redirect( request, strMessageUrl );
571 }
572
573
574
575
576
577
578
579
580 @Action( ACTION_REMOVE_HISTORY_BLOG )
581 public String doRemoveHistoryBlog( HttpServletRequest request )
582 {
583 String strBlogId = request.getParameter( PARAMETER_ID_BLOG );
584 int nBlogId = Integer.parseInt( strBlogId );
585 String strVersion = request.getParameter( PARAMETER_VERSION_BLOG );
586 int nVersion = -1;
587
588
589 if ( StringUtils.isNumeric( strVersion ) )
590 {
591 nVersion = Integer.parseInt( strVersion );
592 if ( nVersion == 1 )
593 {
594
595 addError( ERROR_HISTORY_BLOG_CANT_REMOVE_ORIGINAL, getLocale( ) );
596 return redirect( request, VIEW_HISTORY_BLOG, PARAMETER_ID_BLOG, nBlogId );
597 }
598 }
599 else
600 {
601
602 addError( ERROR_HISTORY_BLOG_NOT_REMOVED, getLocale( ) );
603 AppLogService.error( "Plugin Blog: Can't delete invalid version {} for blog ID {}", strVersion, strBlogId );
604 return redirect( request, VIEW_HISTORY_BLOG, PARAMETER_ID_BLOG, nBlogId );
605 }
606
607 if ( RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, strBlogId, Blog.PERMISSION_DELETE, (User) getUser( ) ) )
608 {
609 Blog blog = BlogService.getInstance( ).loadBlog( nBlogId );
610
611
612 if ( blog.getVersion( ) == nVersion )
613 {
614
615 if ( checkLockBlog( nBlogId, request.getSession( ).getId( ) ) )
616 {
617
618 UrlItem url = new UrlItem( getViewFullUrl( VIEW_HISTORY_BLOG ) );
619 url.addParameter( PARAMETER_ID_BLOG, nBlogId );
620 String strMessageUrl = AdminMessageService.getMessageUrl( request, BLOG_LOCKED, url.getUrl( ), AdminMessage.TYPE_STOP );
621 return redirect( request, strMessageUrl );
622 }
623
624 List<BlogPublication> docPublication = BlogPublicationHome.getDocPublicationByIdDoc( nBlogId );
625 if ( CollectionUtils.isNotEmpty( docPublication ) || BlogHome.findByPrimaryKey( nBlogId ).isArchived() )
626 {
627
628 UrlItem url = new UrlItem( getViewFullUrl( VIEW_HISTORY_BLOG ) );
629 url.addParameter( PARAMETER_ID_BLOG, nBlogId );
630 String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_DOCUMENT_IS_PUBLISHED, url.getUrl( ),
631 AdminMessage.TYPE_STOP );
632 return redirect( request, strMessageUrl );
633 }
634
635 BlogService.getInstance( ).revertBlogToPreviousVersion( blog );
636 }
637 else
638 {
639
640 BlogService.getInstance( ).deleteBlogVersion( nBlogId, nVersion );
641 }
642 addInfo( INFO_HISTORY_BLOG_REMOVED, getLocale( ) );
643 }
644 return redirect( request, VIEW_HISTORY_BLOG, PARAMETER_ID_BLOG, nBlogId );
645 }
646
647
648
649
650
651
652
653
654
655 @View( VIEW_CREATE_BLOG )
656 public String getCreateBlog( HttpServletRequest request ) throws AccessDeniedException
657 {
658
659 if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_CREATE, (User) getUser( ) ) )
660 {
661 throw new AccessDeniedException( UNAUTHORIZED );
662 }
663
664 _blog = ( _blog != null && _blog.getId( ) == 0 ) ? _blog : new Blog( );
665 _blogServiceSession.saveBlogInSession( request.getSession( ), _blog );
666 _blog.getTag( ).sort( ( tg1, tg2 ) -> tg1.getPriority( ) - tg2.getPriority( ) );
667
668 String useCropImage = DatastoreService.getDataValue( PROPERTY_USE_UPLOAD_IMAGE_PLUGIN, "false" );
669 Map<String, Object> model = getModel( );
670
671 boolean bPermissionCreate = RBACService.isAuthorized( Tag.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Tag.PERMISSION_CREATE,
672 (User) getUser( ) );
673
674 AdminUser user = AdminUserService.getAdminUser( request );
675 List<DocContent> listDocContent = _blogServiceSession.getDocContentFromSession(request.getSession(), user);
676
677 for ( int i = 0; i < listDocContent.size(); i++ )
678 {
679 listDocContent.remove( i );
680 }
681 _blogServiceSession.removeDocContentFromSession( request.getSession( ), user );
682
683 ReferenceList allTag = TagHome.getTagsReferenceList( );
684 allTag.sort( Comparator.comparing(ReferenceItem::getName , String.CASE_INSENSITIVE_ORDER ) );
685
686 ReferenceList tagList = getTageList( );
687 tagList.sort( Comparator.comparing(ReferenceItem::getName , String.CASE_INSENSITIVE_ORDER ) );
688
689 model.put(BlogParameterService.MARK_DEFAULT_NUMBER_MANDATORY_TAGS, BlogParameterService.getInstance().getNumberMandatoryTags() );
690 model.put( MARK_LIST_IMAGE_TYPE, DocContentHome.getListContentType( ) );
691 model.put( MARK_PERMISSION_CREATE_TAG, bPermissionCreate );
692 model.put( MARK_BLOG, _blog );
693 model.put( MARK_LIST_ALLTAG , allTag );
694 model.put( MARK_LIST_TAG, tagList );
695 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
696 model.put( MARK_USE_UPLOAD_IMAGE_PLUGIN, Boolean.parseBoolean( useCropImage ) );
697
698 return getPage( PROPERTY_PAGE_TITLE_CREATE_BLOG, TEMPLATE_CREATE_BLOG, model );
699 }
700
701
702
703
704
705
706
707
708 @Action( ACTION_CREATE_BLOG )
709 public String doCreateBlog( HttpServletRequest request )
710 {
711
712 if ( RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_CREATE, (User) getUser( ) ) )
713 {
714
715 AdminUser user = AdminUserService.getAdminUser( request );
716 List<DocContent> listDocContent = _blogServiceSession.getDocContentFromSession(request.getSession(), user);
717 String strAction = request.getParameter( PARAMETER_ACTION_BUTTON );
718 _blog.setCreationDate( getSqlDate( ) );
719 _blog.setUpdateDate( getSqlDate( ) );
720 _blog.setUser( AdminUserService.getAdminUser( request ).getAccessCode( ) );
721 _blog.setUserCreator( AdminUserService.getAdminUser( request ).getAccessCode( ) );
722 _blog.setVersion( 1 );
723 _blog.setAttachedPortletId( 0 );
724 _blog.setArchived( false );
725 _blog.setDocContent( listDocContent );
726 populate( _blog, request );
727
728
729 if ( !validateBean( _blog, VALIDATION_ATTRIBUTES_PREFIX ) )
730 {
731 return redirectView( request, VIEW_CREATE_BLOG );
732 }
733
734 int nNumberMandatoryTags = BlogParameterService.getInstance().getNumberMandatoryTags();
735 if (nNumberMandatoryTags > _blog.getTag( ).size( ) )
736 {
737 String strMessage = I18nService.getLocalizedString(MESSAGE_ERROR_MANDATORY_TAGS, getLocale( ));
738 addError( strMessage, getLocale( ) );
739 return redirectView( request, VIEW_CREATE_BLOG );
740 }
741
742 BlogService.getInstance( ).createBlog( _blog, _blog.getDocContent( ) );
743 _blogServiceSession.removeDocContentFromSession( request.getSession( ), user );
744
745 if ( strAction != null && strAction.equals( PARAMETER_UPDATE ) )
746 {
747
748 return redirect( request, VIEW_MODIFY_BLOG, PARAMETER_ID_BLOG, _blog.getId( ) );
749 }
750
751 addInfo( INFO_BLOG_CREATED, getLocale( ) );
752 }
753 return redirectView( request, VIEW_MANAGE_BLOGS );
754 }
755
756
757
758
759
760
761
762
763 @Action( ACTION_ADD_TAG )
764 public String doAddTag( HttpServletRequest request )
765 {
766 String strIdTag = request.getParameter( PARAMETER_TAG );
767 int nIdBlog = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
768 String nIdSession = request.getSession( ).getId( );
769 _blog = _blogServiceSession.getBlogFromSession( request.getSession( ), nIdBlog );
770 if ( _mapLockBlog.get( nIdBlog ) != null && _mapLockBlog.get( nIdBlog ).getSessionId( ).equals( nIdSession ) )
771 {
772
773 lockBlog( nIdBlog, request.getSession( ).getId( ) );
774 }
775 else
776 if ( _blog.getId( ) != 0 )
777 {
778
779 return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_BLOG_LOCKED ) );
780 }
781
782 if ( RBACService.isAuthorized( Tag.PROPERTY_RESOURCE_TYPE, strIdTag, Tag.PERMISSION_CREATE, (User) getUser( ) ) )
783 {
784
785 String strTagName = request.getParameter( PARAMETER_TAG_NAME );
786
787 Tagplugins/blog/business/Tag.html#Tag">Tag tag = new Tag( Integer.parseInt( strIdTag ), _blog.getTag( ).size( ) + 1 );
788 tag.setName( strTagName );
789
790 _blog.addTag( tag );
791
792 return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_SUCCESS ) );
793 }
794 return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_FAILURE ) );
795
796 }
797
798
799
800
801
802
803
804 @Action( ACTION_REMOVE_TAG )
805 public String doRemoveTag( HttpServletRequest request )
806 {
807 String strIdTag = request.getParameter( PARAMETER_TAG );
808 int nIdBlog = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
809 String nIdSession = request.getSession( ).getId( );
810 _blog = _blogServiceSession.getBlogFromSession( request.getSession( ), nIdBlog );
811 if ( _mapLockBlog.get( nIdBlog ) != null && _mapLockBlog.get( nIdBlog ).getSessionId( ).equals( nIdSession ) )
812 {
813
814 lockBlog( nIdBlog, request.getSession( ).getId( ) );
815 }
816 else
817 if ( _blog.getId( ) != 0 )
818 {
819
820 return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_BLOG_LOCKED ) );
821 }
822
823 if ( RBACService.isAuthorized( Tag.PROPERTY_RESOURCE_TYPE, strIdTag, Tag.PERMISSION_DELETE, (User) getUser( ) ) )
824 {
825 Tag tag = _blog.getTag( ).stream( ).filter( tg -> tg.getIdTag( ) == Integer.parseInt( strIdTag ) ).collect( Collectors.toList( ) ).get( 0 );
826 _blog.deleteTag( tag );
827
828 List<Tag> listTag = _blog.getTag( ).stream( ).map( ( Tag tg ) -> {
829 if ( ( tg.getPriority( ) > tag.getPriority( ) ) )
830 {
831 tg.setPriority( tg.getPriority( ) - 1 );
832 }
833 return tg;
834 } ).collect( Collectors.toList( ) );
835
836 _blog.setTag( listTag );
837 return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_SUCCESS ) );
838 }
839 return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_FAILURE ) );
840
841 }
842
843
844
845
846
847
848
849 @Action( ACTION_UPDATE_PRIORITY_TAG )
850 public String doUpdatePriorityTag( HttpServletRequest request )
851 {
852 Tag tg = null;
853 Tag tagMove = null;
854 int nPriorityToSet = 0;
855 int nPriority = 0;
856
857 String strIdTag = request.getParameter( PARAMETER_TAG );
858 String strAction = request.getParameter( PARAMETER_TAG_ACTION );
859 int nIdBlog = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
860 String nIdSession = request.getSession( ).getId( );
861 _blog = _blogServiceSession.getBlogFromSession( request.getSession( ), nIdBlog );
862 if ( _mapLockBlog.get( nIdBlog ) != null && _mapLockBlog.get( nIdBlog ).getSessionId( ).equals( nIdSession ) )
863 {
864
865 lockBlog( nIdBlog, request.getSession( ).getId( ) );
866 }
867 else
868 if ( _blog.getId( ) != 0 )
869 {
870
871 return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_BLOG_LOCKED ) );
872 }
873
874 for ( Tag tag : _blog.getTag( ) )
875 {
876 if ( tag.getIdTag( ) == Integer.parseInt( strIdTag ) )
877 {
878 tg = tag;
879 nPriorityToSet = tag.getPriority( );
880 nPriority = tag.getPriority( );
881 }
882 }
883 for ( Tag tag : _blog.getTag( ) )
884 {
885 if ( strAction.equals( "moveUp" ) && tag.getPriority( ) == nPriority - 1 )
886 {
887 tagMove = tag;
888 tagMove.setPriority( tagMove.getPriority( ) + 1 );
889 nPriorityToSet = nPriority - 1;
890
891 }
892 else
893 if ( strAction.equals( "moveDown" ) && tag.getPriority( ) == nPriority + 1 )
894 {
895 tagMove = tag;
896 tagMove.setPriority( tagMove.getPriority( ) - 1 );
897 nPriorityToSet = nPriority + 1;
898
899 }
900 }
901 tg.setPriority( nPriorityToSet );
902
903 if ( tagMove != null )
904 {
905
906 return JsonUtil.buildJsonResponse( new JsonResponse( String.valueOf( tagMove.getIdTag( ) ) ) );
907
908 }
909 return JsonUtil.buildJsonResponse( new JsonResponse( String.valueOf( tg.getIdTag( ) ) ) );
910
911 }
912
913
914
915
916
917
918
919
920
921 @Action( ACTION_CONFIRM_REMOVE_BLOG )
922 public String getConfirmRemoveBlog( HttpServletRequest request ) throws AccessDeniedException
923 {
924
925 String strId = request.getParameter( PARAMETER_ID_BLOG );
926 int nId = Integer.parseInt( strId );
927 if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, strId, Blog.PERMISSION_DELETE, (User) getUser( ) ) )
928 {
929 throw new AccessDeniedException( UNAUTHORIZED );
930 }
931 if ( checkLockBlog( nId, request.getSession( ).getId( ) ) )
932 {
933
934 UrlItem url = new UrlItem( getActionUrl( VIEW_MANAGE_BLOGS ) );
935 String strMessageUrl = AdminMessageService.getMessageUrl( request, BLOG_LOCKED, url.getUrl( ), AdminMessage.TYPE_STOP );
936 return redirect( request, strMessageUrl );
937
938 }
939
940 UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_BLOG ) );
941 url.addParameter( PARAMETER_ID_BLOG, nId );
942
943 String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_BLOG, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
944
945 return redirect( request, strMessageUrl );
946 }
947
948
949
950
951
952
953
954
955 @Action( ACTION_REMOVE_BLOG )
956 public String doRemoveBlog( HttpServletRequest request )
957 {
958 String strId = request.getParameter( PARAMETER_ID_BLOG );
959
960 int nId = Integer.parseInt( strId );
961
962 if ( RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, strId, Blog.PERMISSION_DELETE, (User) getUser( ) ) )
963 {
964
965 if ( checkLockBlog( nId, request.getSession( ).getId( ) ) )
966 {
967
968 UrlItem url = new UrlItem( getActionUrl( VIEW_MANAGE_BLOGS ) );
969 String strMessageUrl = AdminMessageService.getMessageUrl( request, BLOG_LOCKED, url.getUrl( ), AdminMessage.TYPE_STOP );
970 return redirect( request, strMessageUrl );
971
972 }
973
974 List<BlogPublication> docPublication = BlogPublicationHome.getDocPublicationByIdDoc( nId );
975
976 if ( CollectionUtils.isNotEmpty( docPublication ) || !BlogHome.findByPrimaryKey( nId ).isArchived( ) )
977 {
978 UrlItem url = new UrlItem( getActionUrl( VIEW_MANAGE_BLOGS ) );
979 String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_DOCUMENT_IS_ACTIVE, url.getUrl( ), AdminMessage.TYPE_STOP );
980
981 return redirect( request, strMessageUrl );
982 }
983 BlogService.getInstance( ).deleteBlog( nId );
984 _blogServiceSession.removeBlogFromSession( request.getSession( ), nId );
985 unLockBlog( nId );
986
987 ExtendableResourceRemovalListenerService.doRemoveResourceExtentions( Blog.PROPERTY_RESOURCE_TYPE, String.valueOf( nId ) );
988
989 HttpSession session = request.getSession();
990 session.setAttribute( PARAMETER_INFO_MESSAGE, INFO_BLOG_REMOVED);
991 }
992 return redirectView( request, VIEW_MANAGE_BLOGS );
993 }
994
995 @Action( ACTION_DUPLICATE_BLOG )
996 public String doDuplicateBlog( HttpServletRequest request ) throws AccessDeniedException
997 {
998
999 if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_CREATE, (User) getUser( ) ) )
1000 {
1001 throw new AccessDeniedException( UNAUTHORIZED );
1002 }
1003
1004 int nIdBlog = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
1005 _blog = BlogService.getInstance( ).loadBlog( nIdBlog );
1006
1007 Timestamp sqlDate = getSqlDate( );
1008
1009 _blog.setContentLabel( CONSTANT_DUPLICATE_BLOG_NAME + _blog.getContentLabel( ) );
1010 _blog.setCreationDate( sqlDate );
1011 _blog.setUpdateDate( sqlDate );
1012 _blog.setUser( AdminUserService.getAdminUser( request ).getAccessCode( ) );
1013 _blog.setUserCreator( AdminUserService.getAdminUser( request ).getAccessCode( ) );
1014 _blog.setVersion( 1 );
1015 _blog.setAttachedPortletId( 0 );
1016
1017 BlogService.getInstance( ).createBlog( _blog, _blog.getDocContent( ) );
1018
1019 return redirectView( request, VIEW_MANAGE_BLOGS );
1020 }
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030 @View( VIEW_MODIFY_BLOG )
1031 public String getModifyBlog( HttpServletRequest request ) throws AccessDeniedException
1032 {
1033 String strId = request.getParameter( PARAMETER_ID_BLOG );
1034
1035 if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, strId, Blog.PERMISSION_MODIFY, (User) getUser( ) ) )
1036 {
1037 throw new AccessDeniedException( UNAUTHORIZED );
1038 }
1039 int nId = Integer.parseInt( strId );
1040 String strResetVersion = request.getParameter( PARAMETER_VERSION_BLOG );
1041 String useCropImage = DatastoreService.getDataValue( PROPERTY_USE_UPLOAD_IMAGE_PLUGIN, "false" );
1042 String sessionId = request.getSession( ).getId( );
1043 Map<String, Object> model = getModel( );
1044
1045 int nVersion = -1;
1046 if ( strResetVersion != null )
1047 {
1048 nVersion = Integer.parseInt( strResetVersion );
1049 _blog = BlogHome.findVersion( nId, nVersion );
1050 _blogServiceSession.saveBlogInSession( request.getSession( ), _blog );
1051 }
1052 else
1053 {
1054 Blog actualBlog = BlogService.getInstance( ).loadBlog( nId );
1055 Blog lastVersion = BlogHome.getLastBlogVersionsList( nId, 1 ).get( 0 );
1056
1057
1058 if ( !actualBlog.getContentLabel( ).equals( lastVersion.getContentLabel( ) ) || !actualBlog.getDescription( ).equals( lastVersion.getDescription( ) ) )
1059 {
1060
1061 Timestamp actualVersionUpdateDate = actualBlog.getUpdateDate();
1062 int actualVersion = BlogHome.getActualVersionNumber( actualVersionUpdateDate,nId );
1063 model.put( MARK_ACTUAL_BLOG_VERSION, actualVersion );
1064 }
1065 lastVersion.setDocContent( actualBlog.getDocContent() );
1066 _blog = lastVersion;
1067 _blogServiceSession.saveBlogInSession( request.getSession( ), _blog );
1068
1069 }
1070
1071 if ( checkLockBlog( nId, sessionId ) )
1072 {
1073
1074 UrlItem url = new UrlItem( getActionUrl( VIEW_MANAGE_BLOGS ) );
1075 String strMessageUrl = AdminMessageService.getMessageUrl( request, BLOG_LOCKED, url.getUrl( ), AdminMessage.TYPE_STOP );
1076 return redirect( request, strMessageUrl );
1077 }
1078 for ( HttpSession httpSession : BlogSessionListner.getMapSession( ).values( ) )
1079 {
1080
1081 if ( !httpSession.getId( ).equals( sessionId ) )
1082 {
1083
1084 _blogServiceSession.removeBlogFromSession( httpSession, nId );
1085 }
1086 }
1087
1088 lockBlog( nId, sessionId );
1089
1090 _blog.getTag( ).sort( ( tg1, tg2 ) -> tg1.getPriority( ) - tg2.getPriority( ) );
1091 _blog.getDocContent( ).sort( ( dc1, dc2 ) -> dc1.getPriority( ) - dc2.getPriority( ) );
1092
1093 boolean bPermissionCreate = RBACService.isAuthorized( Tag.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Tag.PERMISSION_CREATE,
1094 (User) getUser( ) );
1095 boolean bPermissionToPublish = RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_PUBLISH,
1096 (User) getUser( ) );
1097
1098 ReferenceList allTag = TagHome.getTagsReferenceList( );
1099 allTag.sort( Comparator.comparing(ReferenceItem::getName , String.CASE_INSENSITIVE_ORDER ) );
1100
1101 ReferenceList tagList = getTageList( );
1102 tagList.sort( Comparator.comparing(ReferenceItem::getName , String.CASE_INSENSITIVE_ORDER ) );
1103
1104 model.put( MARK_LIST_IMAGE_TYPE, DocContentHome.getListContentType( ) );
1105 model.put( MARK_PERMISSION_CREATE_TAG, bPermissionCreate );
1106 model.put( MARK_PERMISSION_PUBLISH_BLOG, bPermissionToPublish );
1107 model.put( MARK_BLOG, _blog );
1108 model.put( MARK_LIST_ALLTAG , allTag );
1109 model.put( MARK_LIST_TAG, tagList );
1110 model.put( MARK_USE_UPLOAD_IMAGE_PLUGIN, Boolean.parseBoolean( useCropImage ) );
1111 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
1112 model.put(BlogParameterService.MARK_DEFAULT_NUMBER_MANDATORY_TAGS, BlogParameterService.getInstance().getNumberMandatoryTags() );
1113
1114 ExtendableResourcePluginActionManager.fillModel( request, getUser( ), model, String.valueOf( nId ), Blog.PROPERTY_RESOURCE_TYPE );
1115
1116 return getPage( PROPERTY_PAGE_TITLE_MODIFY_BLOG, TEMPLATE_MODIFY_BLOG, model );
1117 }
1118
1119
1120
1121
1122
1123
1124
1125
1126 @Action( ACTION_MODIFY_BLOG )
1127 public String doModifyBlog( HttpServletRequest request )
1128 {
1129
1130 String strId = request.getParameter( PARAMETER_ID_BLOG );
1131 String strAction = request.getParameter( PARAMETER_ACTION_BUTTON );
1132 int nId = Integer.parseInt( strId );
1133 String strHtmlContent = request.getParameter( PARAMETER_HTML_CONTENT );
1134 String strEditComment = request.getParameter( PARAMETER_EDIT_COMMENT );
1135 String strContentLabel = request.getParameter( PARAMETER_CONTENT_LABEL );
1136 String strDescription = request.getParameter( PARAMETER_DESCRIPTION );
1137 String strShareable = request.getParameter( PARAMETER_SHAREABLE );
1138 String strUrl = request.getParameter( PARAMETER_URL );
1139
1140 if ( RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, strId, Blog.PERMISSION_MODIFY, (User) getUser( ) ) )
1141 {
1142 _blog = _blogServiceSession.getBlogFromSession( request.getSession( ), nId );
1143 if ( checkLockBlog( Integer.parseInt( strId ), request.getSession( ).getId( ) ) || _blog == null )
1144 {
1145
1146 UrlItem url = new UrlItem( getActionUrl( VIEW_MANAGE_BLOGS ) );
1147 String strMessageUrl = AdminMessageService.getMessageUrl( request, BLOG_LOCKED, url.getUrl( ), AdminMessage.TYPE_STOP );
1148 return redirect( request, strMessageUrl );
1149 }
1150 Blog latestVersionBlog = BlogService.getInstance( ).loadBlog( nId );
1151
1152 _blog.setContentLabel( strContentLabel );
1153 _blog.setDescription( strDescription );
1154 _blog.setShareable( Boolean.parseBoolean( strShareable ) );
1155 _blog.setHtmlContent( strHtmlContent );
1156 _blog.setEditComment( strEditComment );
1157 _blog.setUpdateDate( getSqlDate( ) );
1158 _blog.setUser( AdminUserService.getAdminUser( request ).getAccessCode( ) );
1159 _blog.setUrl( strUrl );
1160
1161
1162 if ( !validateBean( _blog, VALIDATION_ATTRIBUTES_PREFIX ) )
1163 {
1164 return redirect( request, VIEW_MODIFY_BLOG, PARAMETER_ID_BLOG, _blog.getId( ) );
1165 }
1166
1167
1168 int nNumberMandatoryTags = BlogParameterService.getInstance().getNumberMandatoryTags();
1169 if (nNumberMandatoryTags > _blog.getTag( ).size( ) )
1170 {
1171 String strMessage = I18nService.getLocalizedString(MESSAGE_ERROR_MANDATORY_TAGS, getLocale( ));
1172 addError( strMessage, getLocale( ) );
1173 return redirectView( request, VIEW_CREATE_BLOG );
1174 }
1175
1176 if ( strAction != null && strAction.equals( PARAMETER_UPDATE ) && RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, strId, Blog.PERMISSION_PUBLISH, (User) getUser( ) ) )
1177 {
1178 _blog.setVersion( latestVersionBlog.getVersion( ) + 1 );
1179 BlogHome.update( _blog );
1180 BlogService.getInstance( ).updateBlog( _blog, _blog.getDocContent( ) );
1181 _blogServiceSession.removeBlogFromSession( request.getSession( ), nId );
1182 unLockBlog( nId );
1183 addInfo( INFO_BLOG_UPDATED, getLocale( ) );
1184 }
1185 else
1186 {
1187 _blog.setVersion( latestVersionBlog.getVersion( ) + 1 );
1188 BlogService.getInstance( ).updateBlog( _blog, _blog.getDocContent( ) );
1189 _blog = latestVersionBlog;
1190 _blog.setVersion( latestVersionBlog.getVersion( ) + 1 );
1191 BlogHome.update( _blog );
1192 _blogServiceSession.removeBlogFromSession( request.getSession( ), nId );
1193 unLockBlog( nId );
1194 return redirect( request, VIEW_MODIFY_BLOG, PARAMETER_ID_BLOG, _blog.getId( ) );
1195 }
1196 }
1197 return redirectView( request, VIEW_MANAGE_BLOGS );
1198 }
1199
1200
1201
1202
1203
1204
1205
1206
1207 @View( VIEW_PREVIEW_BLOG )
1208 public String getPreviewBlog( HttpServletRequest request )
1209 {
1210 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
1211 String strVersion = request.getParameter( PARAMETER_VERSION_BLOG );
1212 int nVersion = -1;
1213 if ( strVersion != null )
1214 {
1215 nVersion = Integer.parseInt( strVersion );
1216 }
1217
1218 Blog blog;
1219 if ( strVersion != null )
1220 {
1221 blog = BlogHome.findVersion( nId, nVersion );
1222 }
1223 else
1224 {
1225 blog = BlogService.getInstance( ).loadBlog( nId );
1226 }
1227 blog.setBlogPublication( BlogPublicationHome.getDocPublicationByIdDoc( nId ) );
1228
1229 Map<String, Object> model = getModel( );
1230 model.put( MARK_LIST_TAG, TagHome.getTagsReferenceList( ) );
1231
1232 model.put( MARK_BLOG, blog );
1233
1234 ExtendableResourcePluginActionManager.fillModel( request, getUser( ), model, String.valueOf( nId ), Blog.PROPERTY_RESOURCE_TYPE );
1235
1236 return getPage( PROPERTY_PAGE_TITLE_PREVIEW_BLOG, TEMPLATE_PREVIEW_BLOG, model );
1237 }
1238
1239
1240
1241
1242
1243
1244
1245
1246 @View( VIEW_DIFF_BLOG )
1247 public String getDiffBlog( HttpServletRequest request )
1248 {
1249 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
1250 String strVersion = request.getParameter( PARAMETER_VERSION_BLOG );
1251 int nVersion = -1;
1252 if ( strVersion != null )
1253 {
1254 nVersion = Integer.parseInt( strVersion );
1255 }
1256 String strVersion2 = request.getParameter( PARAMETER_VERSION_BLOG2 );
1257
1258 Blog blog;
1259 if ( strVersion != null )
1260 {
1261 blog = BlogHome.findVersion( nId, nVersion );
1262 }
1263 else
1264 {
1265 blog = BlogHome.findByPrimaryKey( nId );
1266 }
1267
1268 int nVersion2 = blog.getVersion( ) - 1;
1269 if ( strVersion2 != null )
1270 {
1271 nVersion2 = Integer.parseInt( strVersion2 );
1272 }
1273
1274 Blog blog2 = BlogHome.findVersion( nId, nVersion2 );
1275 if ( blog2 == null )
1276 {
1277 blog2 = BlogHome.findByPrimaryKey( nId );
1278 }
1279
1280 if ( blog2.getVersion( ) > blog.getVersion( ) )
1281 {
1282 Blog tmp = blog2;
1283 blog2 = blog;
1284 blog = tmp;
1285 }
1286
1287 String strDiff = null;
1288 HtmlCleaner cleaner = new HtmlCleaner( );
1289 try
1290 {
1291 SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance( );
1292 TransformerHandler result = tf.newTransformerHandler( );
1293 result.getTransformer( ).setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "yes" );
1294 StringWriter resultWriter = new StringWriter( );
1295 result.setResult( new StreamResult( resultWriter ) );
1296 Locale locale = getLocale( );
1297
1298 DomTreeBuilder oldHandler = new DomTreeBuilder( );
1299 cleaner.cleanAndParse( new InputSource( new ByteArrayInputStream( blog2.getHtmlContent( ).getBytes( StandardCharsets.UTF_8 ) ) ), oldHandler );
1300 TextNodeComparator leftComparator = new TextNodeComparator( oldHandler, locale );
1301
1302 DomTreeBuilder newHandler = new DomTreeBuilder( );
1303 cleaner.cleanAndParse( new InputSource( new ByteArrayInputStream( blog.getHtmlContent( ).getBytes( StandardCharsets.UTF_8 ) ) ), newHandler );
1304 TextNodeComparator rightComparator = new TextNodeComparator( newHandler, locale );
1305
1306 HtmlSaxDiffOutput output = new HtmlSaxDiffOutput( result, "" );
1307 HTMLDiffer differ = new HTMLDiffer( output );
1308 differ.diff( leftComparator, rightComparator );
1309
1310 strDiff = resultWriter.toString( );
1311 }
1312 catch( Exception e )
1313 {
1314 AppLogService.error( "Error generating daisy diff for blog " + nId + ":" + blog.getContentLabel( ) + "; versions (" + blog.getVersion( ) + ","
1315 + blog2.getVersion( ) + ")", e );
1316 }
1317
1318 List<Blog> listBlogsVersions = BlogHome.getBlogsVersionsList( nId );
1319
1320 Map<String, Object> model = getModel( );
1321 model.put( MARK_BLOG, blog );
1322 model.put( MARK_BLOG2, blog2 );
1323 model.put( MARK_DIFF, strDiff );
1324 model.put( MARK_BLOG_VERSION_LIST, listBlogsVersions );
1325
1326 return getPage( PROPERTY_PAGE_TITLE_DIFF_BLOG, TEMPLATE_DIFF_BLOG, model );
1327 }
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337 @Action( ACTION_ADD_FILE_CONTENT )
1338 public String addContent( HttpServletRequest request )
1339 {
1340 int nIdBlog = 0;
1341 if( request.getParameter( PARAMETER_ID_BLOG ) != null && !request.getParameter( PARAMETER_ID_BLOG ).equals( "0" ) )
1342 {
1343 nIdBlog = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
1344 }
1345 if( nIdBlog != 0 )
1346 {
1347 String nIdSession = request.getSession( ).getId( );
1348 _blog = _blogServiceSession.getBlogFromSession( request.getSession( ), nIdBlog );
1349
1350 if ( _mapLockBlog.get( nIdBlog ) != null && _mapLockBlog.get( nIdBlog ).getSessionId( ).equals( nIdSession ) )
1351 {
1352
1353 lockBlog( nIdBlog, request.getSession( ).getId( ) );
1354 }
1355 else
1356 if ( _blog.getId( ) != 0 )
1357 {
1358
1359 return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_BLOG_LOCKED ) );
1360 }
1361 }
1362
1363 FileItem file = ((MultipartHttpServletRequest) request).getFile(PARAMETER_FILE);
1364
1365
1366 String strFileName = request.getParameter( PARAMETER_FILE_NAME );
1367 String strFileType = request.getParameter( "fileType" );
1368
1369
1370 DocContentusiness/DocContent.html#DocContent">DocContent docContent = new DocContent( );
1371 docContent.setBinaryValue( file.get() );
1372 docContent.setValueContentType( file.getContentType() );
1373 docContent.setTextValue( strFileName );
1374
1375 if ( StringUtils.isNumeric( strFileType ) )
1376 {
1377
1378 ContentTypebusiness/ContentType.html#ContentType">ContentType contType = new ContentType( );
1379 contType.setIdContentType( Integer.parseInt( strFileType ) );
1380 docContent.setContentType( contType );
1381 }
1382 String[] results;
1383 if( nIdBlog != 0 )
1384 {
1385 int priority = _blog.getDocContent( ).size( ) + 1;
1386 docContent.setPriority( priority );
1387 _blog.addContent( docContent );
1388 DocContentHome.create( docContent );
1389 DocContentHome.insertInBlog( nIdBlog, docContent.getId(), priority);
1390 results = new String [ ] {
1391 strFileName, String.valueOf( docContent.getId( ) )
1392 };
1393 }
1394 else {
1395
1396 User user = AdminUserService.getAdminUser( request );
1397 int _nDocContentInSession = 1;
1398 if( _blogServiceSession.getDocContentFromSession( request.getSession( ), user ) != null && !_blogServiceSession.getDocContentFromSession( request.getSession( ), user ).isEmpty( ) )
1399 {
1400 _nDocContentInSession = _blogServiceSession.getDocContentFromSession( request.getSession( ), user ).size( ) + 1;
1401 }
1402 DocContentHome.create( docContent );
1403 _blog.addContent( docContent );
1404 docContent.setPriority( _nDocContentInSession );
1405 _blogServiceSession.saveBlogInSession( request.getSession( ), docContent, user );
1406 results = new String [ ] {
1407 strFileName, String.valueOf( docContent.getId() )
1408 };
1409
1410 }
1411
1412 return JsonUtil.buildJsonResponse( new JsonResponse( results ) );
1413
1414 }
1415
1416
1417
1418
1419
1420
1421
1422
1423 @Action( ACTION_REMOVE_FILE_CONTENT )
1424 public String removeContent( HttpServletRequest request )
1425 {
1426
1427 int nIdDoc = Integer.parseInt( request.getParameter( PARAMETER_CONTENT_ID ) );
1428 int nIdBlog = 0;
1429 String nIdSession = request.getSession( ).getId( );
1430 if( request.getParameter( PARAMETER_ID_BLOG ) != null && !request.getParameter( PARAMETER_ID_BLOG ).equals( "0" ) )
1431 {
1432 nIdBlog = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
1433 }
1434 if( nIdBlog != 0 )
1435 {
1436 _blog = _blogServiceSession.getBlogFromSession( request.getSession( ), nIdBlog );
1437
1438 if ( _mapLockBlog.get( nIdBlog ) != null && _mapLockBlog.get( nIdBlog ).getSessionId( ).equals( nIdSession ) )
1439 {
1440
1441 lockBlog( nIdBlog, request.getSession( ).getId( ) );
1442 }
1443 else
1444 if ( _blog.getId( ) != 0 )
1445 {
1446
1447 return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_BLOG_LOCKED ) );
1448 }
1449
1450 DocContent docCont = _blog.getDocContent( ).stream( ).filter( dc -> dc.getId( ) == nIdDoc ).collect( Collectors.toList( ) ).get( 0 );
1451 List<DocContent> listDocs = _blog.getDocContent( ).stream( ).map( ( DocContent dc ) -> {
1452 if ( ( dc.getPriority( ) > docCont.getPriority( ) ) && ( docCont.getId( ) != dc.getId( ) ) )
1453 {
1454
1455 dc.setPriority( dc.getPriority( ) - 1 );
1456 }
1457 return dc;
1458 } ).collect( Collectors.toList( ) );
1459
1460 _blog.setDocContent( listDocs );
1461 _blog.deleteDocContent( nIdDoc );
1462 DocContentHome.removeInBlogById( nIdDoc );
1463 DocContentHome.removeById( nIdDoc );
1464 }
1465 else
1466 {
1467
1468 User user = AdminUserService.getAdminUser( request );
1469 DocContent docContent = _blogServiceSession.getDocContentFromSession( request.getSession( ), user ).stream( ).filter( dc -> dc.getId( ) == nIdDoc ).collect( Collectors.toList( ) ).get( 0 );
1470 _blogServiceSession.removeDocContentFromSession( request.getSession( ), docContent, user );
1471 DocContentHome.removeById( nIdDoc );
1472 }
1473 return JsonUtil.buildJsonResponse( new JsonResponse( nIdDoc ) );
1474
1475 }
1476
1477
1478
1479
1480
1481
1482
1483 @Action( ACTION_UPDATE_PRIORITY_FILE_CONTENT )
1484 public String doUpdatePriorityContent( HttpServletRequest request )
1485 {
1486 DocContent docCont = null;
1487 DocContent docContMove = null;
1488 int nPriorityToSet = 0;
1489 int nPriority = 0;
1490
1491 String strIdDocContent = request.getParameter( PARAMETER_CONTENT_ID );
1492 String strAction = request.getParameter( PARAMETER_CONTENT_ACTION );
1493 int nIdBlog = 0;
1494 String nIdSession = request.getSession( ).getId( );
1495 if( request.getParameter( PARAMETER_ID_BLOG ) != null && !request.getParameter( PARAMETER_ID_BLOG ).equals( "0" ) )
1496 {
1497 nIdBlog = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
1498 }
1499 if( nIdBlog != 0 )
1500 {
1501 _blog = _blogServiceSession.getBlogFromSession( request.getSession( ), nIdBlog );
1502 if ( _mapLockBlog.get( nIdBlog ) != null && _mapLockBlog.get( nIdBlog ).getSessionId( ).equals( nIdSession ) )
1503 {
1504
1505 lockBlog( nIdBlog, request.getSession( ).getId( ) );
1506 }
1507 else
1508 if ( _blog.getId( ) != 0 )
1509 {
1510
1511 return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_BLOG_LOCKED ) );
1512 }
1513 }
1514 else
1515 {
1516 List<DocContent> listDocContent = _blogServiceSession.getDocContentFromSession( request.getSession( ), AdminUserService.getAdminUser( request ) );
1517 _blog.setDocContent( listDocContent );
1518 }
1519 for ( DocContent dc : _blog.getDocContent( ) )
1520 {
1521 if ( dc.getId( ) == Integer.parseInt( strIdDocContent ) )
1522 {
1523 docCont = dc;
1524 nPriorityToSet = dc.getPriority( );
1525 nPriority = dc.getPriority( );
1526 }
1527 }
1528 for ( DocContent dc : _blog.getDocContent( ) )
1529 {
1530 if ( strAction.equals( "moveUp" ) && dc.getPriority( ) == nPriority - 1 )
1531 {
1532 docContMove = dc;
1533 docContMove.setPriority( dc.getPriority( ) + 1 );
1534 nPriorityToSet = nPriority - 1;
1535
1536 }
1537 else
1538 if ( strAction.equals( "moveDown" ) && dc.getPriority( ) == nPriority + 1 )
1539 {
1540 docContMove = dc;
1541 docContMove.setPriority( docContMove.getPriority( ) - 1 );
1542 nPriorityToSet = nPriority + 1;
1543
1544 }
1545 }
1546 docCont.setPriority( nPriorityToSet );
1547 if( nIdBlog == 0 )
1548 {
1549 _blogServiceSession.saveBlogInSession( request.getSession( ), docCont, AdminUserService.getAdminUser( request ) );
1550 if( docContMove != null ) {
1551 _blogServiceSession.saveBlogInSession(request.getSession(), docContMove, AdminUserService.getAdminUser( request ) );
1552 }
1553 }
1554 if ( docContMove != null )
1555 {
1556
1557 return JsonUtil.buildJsonResponse( new JsonResponse( String.valueOf( docContMove.getId( ) ) ) );
1558
1559 }
1560 return JsonUtil.buildJsonResponse( new JsonResponse( String.valueOf( docCont.getId( ) ) ) );
1561
1562 }
1563
1564
1565
1566
1567
1568
1569 @Action( ACTION_UPDATE_CONTENT_TYPE )
1570 public String updateContentType( HttpServletRequest request )
1571 {
1572
1573 String strContentTypeId = request.getParameter( PARAMETER_TYPE_ID );
1574 String strContentId = request.getParameter( PARAMETER_CONTENT_ID );
1575
1576 int nIdBlog = 0;
1577 if( request.getParameter( PARAMETER_ID_BLOG ) != null && !request.getParameter( PARAMETER_ID_BLOG ).equals( "0" ) )
1578 {
1579 nIdBlog = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
1580 }
1581
1582 if( nIdBlog != 0 ) {
1583 String nIdSession = request.getSession().getId();
1584 _blog = _blogServiceSession.getBlogFromSession(request.getSession(), nIdBlog);
1585
1586 if (_mapLockBlog.get(nIdBlog) != null && _mapLockBlog.get(nIdBlog).getSessionId().equals(nIdSession)) {
1587
1588 lockBlog(nIdBlog, request.getSession().getId());
1589 } else if (_blog.getId() != 0) {
1590
1591 return JsonUtil.buildJsonResponse(new JsonResponse(RESPONSE_BLOG_LOCKED));
1592 }
1593 }
1594
1595 for (DocContent content : _blog.getDocContent()) {
1596 if (strContentId != null && content.getId() == Integer.parseInt(strContentId)) {
1597
1598 ContentTypebusiness/ContentType.html#ContentType">ContentType contType = new ContentType();
1599 contType.setIdContentType(Integer.parseInt(strContentTypeId));
1600
1601 content.setContentType(contType);
1602 DocContentHome.update(content);
1603 break;
1604 }
1605 }
1606
1607 return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_SUCCESS ) );
1608 }
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618 public DocContent setContent( MultipartHttpServletRequest mRequest, Locale locale )
1619 {
1620
1621 FileItem fileParameterBinaryValue = mRequest.getFile( "attachment" );
1622
1623 if ( fileParameterBinaryValue != null )
1624 {
1625
1626 String strContentType = fileParameterBinaryValue.getContentType( );
1627 byte [ ] bytes = fileParameterBinaryValue.get( );
1628 String strFileName = fileParameterBinaryValue.getName( );
1629
1630 if ( !ArrayUtils.isEmpty( bytes ) )
1631 {
1632
1633 DocContentusiness/DocContent.html#DocContent">DocContent docContent = new DocContent( );
1634 docContent.setBinaryValue( bytes );
1635 docContent.setValueContentType( strContentType );
1636 docContent.setTextValue( strFileName );
1637
1638 return docContent;
1639 }
1640
1641 }
1642
1643 return null;
1644 }
1645
1646
1647
1648
1649
1650 private ReferenceList getBlogFilterList( )
1651 {
1652 ReferenceList list = new ReferenceList( );
1653 list.addItem( MARK_BLOG_FILTER_NAME, "Nom" );
1654 list.addItem( MARK_BLOG_FILTER_DATE, "Date" );
1655 list.addItem( MARK_BLOG_FILTER_USER, "Utilisateur" );
1656
1657 return list;
1658 }
1659
1660
1661
1662
1663
1664 private ReferenceList getTageList( )
1665 {
1666
1667 ReferenceList blogList = TagHome.getTagsReferenceList( );
1668
1669 for ( Tag tg : _blog.getTag( ) )
1670 {
1671 blogList.removeIf( item -> item.getCode( ).equals( String.valueOf( tg.getIdTag( ) ) ) );
1672
1673 }
1674 return blogList;
1675 }
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686 private static boolean checkLockBlog( int nIdBlog, String strIdSession )
1687 {
1688 return _mapLockBlog.get( nIdBlog ) != null && !_mapLockBlog.get( nIdBlog ).getSessionId( ).equals( strIdSession );
1689 }
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700 @Action( ACTION_CONFIRM_REMOVE_MULTIPLE_BLOGS )
1701 public String getConfirmRemoveMultipleBlogs( HttpServletRequest request ) throws AccessDeniedException
1702 {
1703
1704 AdminUser adminUser = AdminUserService.getAdminUser( request );
1705 User user = AdminUserService.getAdminUser( request );
1706 if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_DELETE, user ) )
1707 {
1708 String strMessage = I18nService.getLocalizedString( ACCESS_DENIED_MESSAGE, request.getLocale( ) );
1709 throw new AccessDeniedException( strMessage );
1710 }
1711
1712
1713 if ( checkLockMultipleBlogs( request.getSession( ).getId( ) ) )
1714 {
1715 UrlItem url = new UrlItem( getActionUrl( VIEW_MANAGE_BLOGS ) );
1716 String strMessageUrl = AdminMessageService.getMessageUrl( request, BLOG_LOCKED, url.getUrl( ), AdminMessage.TYPE_STOP );
1717 return redirect( request, strMessageUrl );
1718 }
1719
1720 UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_MULTIPLE_BLOGS ) );
1721 url.addParameter( PARAMETER_SELECTED_BLOGS, _listSelectedBlogIds.stream( ).map( String::valueOf ).collect( Collectors.joining( "," ) ) );
1722
1723 String confirmationMessage = _listSelectedBlogIds.size( ) > 1 ? MESSAGE_CONFIRM_REMOVE_MULTIPE_BLOGS : MESSAGE_CONFIRM_REMOVE_BLOG;
1724 if( _listSelectedBlogIds.size( ) > 1 )
1725 {
1726 Object [ ] messageArgs = {
1727 _listSelectedBlogIds.size( )
1728 };
1729 return redirect( request, AdminMessageService.getMessageUrl( request, confirmationMessage, messageArgs, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION ));
1730 }
1731 else
1732 {
1733 return redirect( request, AdminMessageService.getMessageUrl( request, confirmationMessage, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION ));
1734 }
1735 }
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745 @Action( ACTION_REMOVE_MULTIPLE_BLOGS )
1746 public String doRemoveMultipleBlog( HttpServletRequest request ) throws AccessDeniedException
1747 {
1748 User user = AdminUserService.getAdminUser( request );
1749 AdminUser adminUser = AdminUserService.getAdminUser( request );
1750
1751 if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_DELETE, user ) && !adminUser.isAdmin( ) )
1752 {
1753 String strMessage = I18nService.getLocalizedString( ACCESS_DENIED_MESSAGE, getLocale( ) );
1754 throw new AccessDeniedException( strMessage );
1755 }
1756
1757 _listSelectedBlogIds = (List<Integer>) request.getSession( ).getAttribute( PARAMETER_SELECTED_BLOG_IDS_LIST );
1758
1759
1760 if ( checkLockMultipleBlogs( request.getSession( ).getId( ) ) )
1761 {
1762 UrlItem url = new UrlItem( getActionUrl( VIEW_MANAGE_BLOGS ) );
1763 String strMessageUrl = AdminMessageService.getMessageUrl( request, BLOG_LOCKED, url.getUrl( ), AdminMessage.TYPE_STOP );
1764 return redirect( request, strMessageUrl );
1765 }
1766 for ( int docPublicationId : _listSelectedBlogIds )
1767 {
1768 if ( CollectionUtils.isNotEmpty( BlogPublicationHome.getDocPublicationByIdDoc( docPublicationId ) ) || !BlogHome.findByPrimaryKey(
1769 docPublicationId ).isArchived( ) )
1770 {
1771 String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_DOCUMENT_IS_ACTIVE, AdminMessage.TYPE_STOP );
1772
1773 return redirect( request, strMessageUrl );
1774 }
1775 }
1776 removeMultipleBlogs( _listSelectedBlogIds );
1777 HttpSession session = request.getSession();
1778 session.setAttribute( PARAMETER_INFO_MESSAGE, getRemovedResultMessageKey( _listSelectedBlogIds ));
1779 return redirectView( request, VIEW_MANAGE_BLOGS );
1780 }
1781 private void removeMultipleBlogs( List<Integer> listBlogIds )
1782 {
1783 if( listBlogIds == null )
1784 {
1785 return;
1786 }
1787 for ( int blogId : listBlogIds )
1788 {
1789 if ( BlogPublicationHome.getDocPublicationByIdDoc( blogId ) != null && BlogPublicationHome.getDocPublicationByIdDoc( blogId ).size( ) > 0 )
1790 {
1791 BlogPublicationHome.removeByBlogId( blogId );
1792 }
1793 BlogHome.removeVersions( blogId );
1794 BlogHome.remove( blogId );
1795 }
1796 }
1797
1798
1799
1800
1801
1802
1803
1804
1805 @Action( ACTION_CONFIRM_ARCHIVE_BLOGS )
1806 public String getConfirmArchiveBlogs( HttpServletRequest request ) throws AccessDeniedException
1807 {
1808
1809 if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_ARCHIVE,
1810 (User) getUser( ) ) )
1811 {
1812 throw new AccessDeniedException( UNAUTHORIZED );
1813 }
1814
1815
1816 if ( checkLockMultipleBlogs( request.getSession( ).getId( ) ) )
1817 {
1818 UrlItem url = new UrlItem( getActionUrl( VIEW_MANAGE_BLOGS ) );
1819 String strMessageUrl = AdminMessageService.getMessageUrl( request, BLOG_LOCKED, url.getUrl( ), AdminMessage.TYPE_STOP );
1820 return redirect( request, strMessageUrl );
1821 }
1822
1823 UrlItem url = new UrlItem( getActionUrl( ACTION_UPDATE_ARCHIVE_MULTIPLE_BLOGS ) );
1824 url.addParameter( PARAMETER_SELECTED_BLOGS, _listSelectedBlogIds.stream( ).map( String::valueOf ).collect( Collectors.joining( "," ) ) );
1825 url.addParameter( PARAMETER_TO_ARCHIVE, String.valueOf( true ));
1826 String confirmationMessage;
1827 Boolean publishedBlog = false;
1828
1829
1830 for ( int blogId : _listSelectedBlogIds )
1831 {
1832 if ( BlogPublicationHome.getDocPublicationByIdDoc( blogId ) != null && !BlogPublicationHome.getDocPublicationByIdDoc( blogId ).isEmpty( ) )
1833 {
1834 publishedBlog = true;
1835 break;
1836 }
1837 }
1838
1839 if ( _listSelectedBlogIds.size( ) > 1 )
1840 {
1841 confirmationMessage = publishedBlog ? MESSAGE_CONFIRM_ARCHIVE_MULTIPLE_PUBLISHED_BLOGS : MESSAGE_CONFIRM_ARCHIVE_MULTIPLE_BLOGS;
1842
1843 Object [ ] messageArgs = {
1844 _listSelectedBlogIds.size( )
1845 };
1846 return redirect( request, AdminMessageService.getMessageUrl( request, confirmationMessage, messageArgs, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION ));
1847 }
1848 else
1849 {
1850 confirmationMessage = publishedBlog ? MESSAGE_CONFIRM_ARCHIVE_PUBLISHED_BLOG : MESSAGE_CONFIRM_ARCHIVE_BLOG;
1851 return redirect( request, AdminMessageService.getMessageUrl( request, confirmationMessage, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION ));
1852 }
1853 }
1854
1855
1856
1857
1858
1859
1860
1861
1862 @Action( ACTION_CONFIRM_UNARCHIVE_BLOGS )
1863 public String getConfirmUnarchiveBlogs( HttpServletRequest request ) throws AccessDeniedException
1864 {
1865
1866 if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_ARCHIVE,
1867 (User) getUser( ) ) )
1868 {
1869 String strMessage = I18nService.getLocalizedString( ACCESS_DENIED_MESSAGE, request.getLocale( ) );
1870 throw new AccessDeniedException( strMessage );
1871 }
1872
1873
1874 if ( checkLockMultipleBlogs( request.getSession( ).getId( ) ) )
1875 {
1876 UrlItem url = new UrlItem( getActionUrl( VIEW_MANAGE_BLOGS ) );
1877 String strMessageUrl = AdminMessageService.getMessageUrl( request, BLOG_LOCKED, url.getUrl( ), AdminMessage.TYPE_STOP );
1878 return redirect( request, strMessageUrl );
1879 }
1880
1881 UrlItem url = new UrlItem( getActionUrl( ACTION_UPDATE_ARCHIVE_MULTIPLE_BLOGS ) );
1882 url.addParameter( PARAMETER_SELECTED_BLOGS, _listSelectedBlogIds.stream( ).map( String::valueOf ).collect( Collectors.joining( "," ) ) );
1883 url.addParameter( PARAMETER_TO_ARCHIVE, String.valueOf( false ));
1884
1885 String confirmationMessage = _listSelectedBlogIds.size( ) > 1 ? MESSAGE_CONFIRM_UNARCHIVE_MULTIPLE_BLOGS : MESSAGE_CONFIRM_UNARCHIVE_BLOG;
1886 if( _listSelectedBlogIds.size( ) > 1 )
1887 {
1888 Object [ ] messageArgs = {
1889 _listSelectedBlogIds.size( )
1890 };
1891 return redirect( request, AdminMessageService.getMessageUrl( request, confirmationMessage, messageArgs, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION ));
1892 }
1893 else
1894 {
1895 return redirect( request, AdminMessageService.getMessageUrl( request, confirmationMessage, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION ) );
1896 }
1897 }
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907 @Action( ACTION_UPDATE_ARCHIVE_MULTIPLE_BLOGS )
1908 public String doArchiveMultipleBlog( HttpServletRequest request ) throws AccessDeniedException
1909 {
1910 User user = AdminUserService.getAdminUser( request );
1911 if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_ARCHIVE, user ) )
1912 {
1913 String strMessage = I18nService.getLocalizedString( ACCESS_DENIED_MESSAGE, getLocale( ) );
1914 throw new AccessDeniedException( strMessage );
1915 }
1916
1917
1918 _listSelectedBlogIds = (List<Integer>) request.getSession( ).getAttribute( PARAMETER_SELECTED_BLOG_IDS_LIST );
1919
1920
1921 if ( checkLockMultipleBlogs( request.getSession( ).getId( ) ) )
1922 {
1923 UrlItem url = new UrlItem( getActionUrl( VIEW_MANAGE_BLOGS ) );
1924 String strMessageUrl = AdminMessageService.getMessageUrl( request, BLOG_LOCKED, url.getUrl( ), AdminMessage.TYPE_STOP );
1925 return redirect( request, strMessageUrl );
1926 }
1927
1928 Boolean bArchive = Boolean.parseBoolean( request.getParameter( PARAMETER_TO_ARCHIVE ) );
1929 updateArchiveMultipleBlogs( _listSelectedBlogIds, bArchive );
1930 HttpSession session = request.getSession();
1931 session.setAttribute( PARAMETER_INFO_MESSAGE, getArchivedResultMessageKey( bArchive, _listSelectedBlogIds ) );
1932 return redirectView( request, VIEW_MANAGE_BLOGS );
1933 }
1934
1935
1936
1937
1938
1939
1940
1941 private String getArchivedResultMessageKey(Boolean toArchived, List<Integer> listBlogIds)
1942 {
1943 if(toArchived)
1944 {
1945 if(listBlogIds.size() == 1)
1946 {
1947 return INFO_BLOG_ARCHIVED;
1948 }
1949 else
1950 {
1951 return INFO_MULTIPLE_BLOGS_ARCHIVED;
1952 }
1953 }
1954 else
1955 {
1956 if(listBlogIds.size() == 1)
1957 {
1958 return INFO_BLOG_UNARCHIVED;
1959 }
1960 else
1961 {
1962 return INFO_MULTIPLE_BLOGS_UNARCHIVED;
1963 }
1964 }
1965 }
1966
1967
1968
1969
1970
1971 private String getRemovedResultMessageKey(List<Integer> listBlogIds)
1972 {
1973 if(listBlogIds.size() == 1)
1974 {
1975 return INFO_BLOG_REMOVED;
1976 }
1977 else
1978 {
1979 return INFO_MULTIPLE_BLOGS_REMOVED;
1980 }
1981 };
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991 @Action( ACTION_EXECUTE_SELECTED_ACTION )
1992 public String doExecuteSelectedAction( HttpServletRequest request ) throws AccessDeniedException
1993 {
1994 Locale locale = getLocale( );
1995
1996
1997 int selectedActionId = getSelectedAction( request );
1998
1999 _listSelectedBlogIds = getSelectedBlogPostsIds( request );
2000
2001
2002 if ( selectedActionId == -1 || CollectionUtils.isEmpty( _listSelectedBlogIds ) )
2003 {
2004 addError( ERROR_ACTION_EXECUTION_FAILED, locale );
2005 return redirectView( request, VIEW_MANAGE_BLOGS );
2006 }
2007
2008
2009 request.getSession( ).setAttribute( PARAMETER_SELECTED_BLOG_IDS_LIST, _listSelectedBlogIds );
2010
2011
2012 if ( selectedActionId == 0 )
2013 {
2014 return getConfirmArchiveBlogs( request );
2015 }
2016 else if ( selectedActionId == 1 )
2017 {
2018 return getConfirmUnarchiveBlogs( request );
2019 }
2020 else if ( selectedActionId == 2 )
2021 {
2022 return getConfirmRemoveMultipleBlogs( request );
2023 }
2024 else
2025 {
2026 addError( ERROR_ACTION_NOT_FOUND, locale );
2027 return redirectView( request, VIEW_MANAGE_BLOGS );
2028 }
2029 }
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039 private int getSelectedAction( HttpServletRequest request )
2040 {
2041
2042 String strSelectedActionId = request.getParameter( PARAMETER_SELECTED_BLOG_ACTION );
2043 if ( StringUtils.isNumeric( strSelectedActionId ) )
2044 {
2045 return Integer.parseInt( strSelectedActionId );
2046 }
2047 return -1;
2048 }
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058 private List<Integer> getSelectedBlogPostsIds( HttpServletRequest request )
2059 {
2060
2061 String [ ] listSelectedBlogPosts = request.getParameterValues( PARAMETER_SELECTED_BLOGS );
2062 if ( ArrayUtils.isNotEmpty( listSelectedBlogPosts ) )
2063 {
2064
2065 return Arrays.stream( listSelectedBlogPosts ).map( Integer::parseInt ).collect( Collectors.toList( ) );
2066 }
2067 return Collections.emptyList( );
2068 }
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078 private synchronized boolean checkLockMultipleBlogs( String strIdSession )
2079 {
2080 if( CollectionUtils.isEmpty( _listSelectedBlogIds ))
2081 {
2082 return false;
2083 }
2084 for ( int blogId : _listSelectedBlogIds )
2085 {
2086
2087 if ( checkLockBlog( blogId, strIdSession ) )
2088 {
2089 return true;
2090 }
2091 }
2092
2093 return false;
2094 }
2095
2096 private void updateArchiveMultipleBlogs( List<Integer> listBlogIds, boolean bArchive )
2097 {
2098 if( listBlogIds == null )
2099 {
2100 return;
2101 }
2102 for ( int i = 0; i < listBlogIds.size( ); i++ )
2103 {
2104 Integer blogId = listBlogIds.get( i );
2105 BlogHome.updateBlogArchiveId(bArchive, blogId);
2106 Blog blog = BlogHome.findByPrimaryKey( blogId );
2107 BlogSearchService.getInstance( ).updateDocument( blog );
2108 BlogSearchService.getInstance( ).updateDocument( blog );
2109 if( bArchive )
2110 {
2111 BlogPublicationHome.getDocPublicationByIdDoc( blogId );
2112
2113 BlogPublicationHome.getDocPublicationByIdDoc( blogId );
2114 if ( BlogPublicationHome.getDocPublicationByIdDoc( blogId ) != null && BlogPublicationHome.getDocPublicationByIdDoc( blogId ).size( ) > 0 )
2115 {
2116 BlogPublicationHome.removeByBlogId( blogId );
2117 }
2118 }
2119 }
2120 }
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130 private void lockBlog( int nIdBlog, String strIdSession )
2131 {
2132
2133 _mapLockBlog.remove( nIdBlog );
2134 _mapLockBlog.put( nIdBlog, new BlogLock( strIdSession, System.currentTimeMillis( ) ) );
2135
2136 }
2137
2138
2139
2140
2141
2142
2143
2144 private void unLockBlog( int nIdBlog )
2145 {
2146
2147 _mapLockBlog.remove( nIdBlog );
2148
2149 }
2150
2151
2152
2153
2154
2155
2156
2157 public static void unLockedBlogByIdSession( String strIdSession )
2158 {
2159
2160 _mapLockBlog.values( ).removeIf( id -> id.getSessionId( ).equals( strIdSession ) );
2161 }
2162
2163
2164
2165
2166
2167
2168
2169 public static void unLockedBlogByTime( long nTime )
2170 {
2171
2172 long currentTime = System.currentTimeMillis( );
2173 _mapLockBlog.values( ).removeIf( id -> id.getTime( ) + nTime < currentTime );
2174 }
2175
2176
2177
2178
2179
2180
2181 public java.sql.Timestamp getSqlDate( )
2182 {
2183 java.util.Date utilDate = new java.util.Date( );
2184 java.sql.Timestamp sqlDate = new java.sql.Timestamp( utilDate.getTime( ) );
2185
2186 return ( sqlDate );
2187 }
2188
2189 }