View Javadoc
1   /*
2    * Copyright (c) 2002-2021, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.extend.modules.comment.web;
35  
36  import java.sql.Timestamp;
37  import java.util.Date;
38  import java.util.HashMap;
39  import java.util.List;
40  import java.util.Map;
41  
42  import javax.servlet.http.HttpServletRequest;
43  
44  import org.apache.commons.lang3.StringUtils;
45  
46  import fr.paris.lutece.plugins.extend.business.extender.ResourceExtenderDTO;
47  import fr.paris.lutece.plugins.extend.business.extender.ResourceExtenderDTOFilter;
48  import fr.paris.lutece.plugins.extend.modules.comment.business.Comment;
49  import fr.paris.lutece.plugins.extend.modules.comment.service.CommentPlugin;
50  import fr.paris.lutece.plugins.extend.modules.comment.service.CommentService;
51  import fr.paris.lutece.plugins.extend.modules.comment.service.ICommentService;
52  import fr.paris.lutece.plugins.extend.modules.comment.service.extender.CommentResourceExtender;
53  import fr.paris.lutece.plugins.extend.modules.comment.util.constants.CommentConstants;
54  import fr.paris.lutece.plugins.extend.service.extender.IResourceExtenderService;
55  import fr.paris.lutece.plugins.extend.service.extender.ResourceExtenderService;
56  import fr.paris.lutece.plugins.extend.service.extender.config.IResourceExtenderConfigService;
57  import fr.paris.lutece.plugins.extend.service.extender.history.IResourceExtenderHistoryService;
58  import fr.paris.lutece.plugins.extend.service.extender.history.ResourceExtenderHistoryService;
59  import fr.paris.lutece.portal.business.user.AdminUser;
60  import fr.paris.lutece.portal.service.admin.AdminUserService;
61  import fr.paris.lutece.portal.service.message.AdminMessage;
62  import fr.paris.lutece.portal.service.message.AdminMessageService;
63  import fr.paris.lutece.portal.service.spring.SpringContextService;
64  import fr.paris.lutece.portal.service.template.AppTemplateService;
65  import fr.paris.lutece.portal.service.util.AppException;
66  import fr.paris.lutece.portal.service.util.AppLogService;
67  import fr.paris.lutece.portal.service.util.AppPathService;
68  import fr.paris.lutece.portal.service.workflow.WorkflowService;
69  import fr.paris.lutece.portal.web.admin.PluginAdminPageJspBean;
70  import fr.paris.lutece.portal.web.constants.Messages;
71  import fr.paris.lutece.util.html.HtmlTemplate;
72  import fr.paris.lutece.util.http.SecurityUtil;
73  import fr.paris.lutece.util.url.UrlItem;
74  
75  /**
76   * 
77   * CommentJspBean
78   * 
79   */
80  public class CommentJspBean extends PluginAdminPageJspBean
81  {
82      /**
83       * Serial version UID
84       */
85      private static final long serialVersionUID = -1787559203779077088L;
86  
87      // JSP
88      private static final String JSP_VIEW_EXTENDER_INFO = "../../ViewExtenderInfo.jsp";
89      private static final String JSP_URL_DO_REMOVE_COMMENT = "jsp/admin/plugins/extend/modules/comment/DoRemoveComment.jsp";
90      private static final String JSP_VIEW_TASKS_FORM = "../comment/GetTasksFormWorkflow.jsp";
91      
92      // MESSAGES
93      private static final String MESSAGE_MANDATORY_FIELD = "portal.util.message.mandatoryField";
94      private static final String MESSAGE_TITLE_CREATE_COMMENT = "module.extend.comment.create_comment.pageTitle";
95  
96      // TEMPLATE
97      private static final String TEMPLATE_CREATE_COMMENT = "admin/plugins/extend/modules/comment/create_comment.html";
98      private static final String TEMPLATE_TASKS_FORM_WORKFLOW  = "admin/plugins/extend/modules/comment/tasks_form_workflow.html";
99      
100     // MARKS
101     private static final String MARK_TASK_FORM = "tasks_form";
102     
103     // CONSTANT
104     private static final String CONSTANT_SPACE = " ";
105 
106     private ICommentService _commentService = SpringContextService.getBean( CommentService.BEAN_SERVICE );
107     private IResourceExtenderHistoryService _resourceHistoryService = SpringContextService.getBean( ResourceExtenderHistoryService.BEAN_SERVICE );
108 
109     private IResourceExtenderService _resourceExtenderService = SpringContextService.getBean( ResourceExtenderService.BEAN_SERVICE );
110 
111     /**
112      * Do publish unpublish comment.
113      * 
114      * @param request
115      *            the request
116      * @return the string
117      */
118     public String doPublishUnpublishComment( HttpServletRequest request )
119     {
120         String strIdComment = request.getParameter( CommentConstants.PARAMETER_ID_COMMENT );
121 
122         if ( StringUtils.isNotBlank( strIdComment ) && StringUtils.isNumeric( strIdComment ) )
123         {
124             int nIdComment = Integer.parseInt( strIdComment );
125             Comment comment = _commentService.findByPrimaryKey( nIdComment );
126 
127             if ( comment != null )
128             {
129                 try
130                 {
131                     _commentService.updateCommentStatus( comment.getIdComment( ), !comment.isPublished( ) );
132                 }
133                 catch( Exception ex )
134                 {
135                     // Something wrong happened... a database check might be needed
136                     AppLogService.error( ex.getMessage( ) + " when updating a comment", ex );
137 
138                     return AdminMessageService.getMessageUrl( request, CommentConstants.MESSAGE_ERROR_GENERIC_MESSAGE, AdminMessage.TYPE_ERROR );
139                 }
140 
141                 return getPostBackUrl( request, comment );
142             }
143         }
144 
145         return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
146     }
147 
148     /**
149      * Do flag comment as important
150      * 
151      * @param request
152      *            the request
153      * @param cancelFlag
154      *            true if the flag important of the comment must be cancel
155      * @return the string
156      */
157     public String doFlagImportantComment( HttpServletRequest request, boolean cancelFlag )
158     {
159         String strIdComment = request.getParameter( CommentConstants.PARAMETER_ID_COMMENT );
160 
161         if ( StringUtils.isNotBlank( strIdComment ) && StringUtils.isNumeric( strIdComment ) )
162         {
163             int nIdComment = Integer.parseInt( strIdComment );
164             Comment comment = _commentService.findByPrimaryKey( nIdComment );
165 
166             if ( comment != null )
167             {
168                 try
169                 {
170 
171                     _commentService.updateFlagImportant( comment.getIdComment( ), !cancelFlag );
172                 }
173                 catch( Exception ex )
174                 {
175                     // Something wrong happened... a database check might be needed
176                     AppLogService.error( ex.getMessage( ) + " when updating a comment", ex );
177 
178                     return AdminMessageService.getMessageUrl( request, CommentConstants.MESSAGE_ERROR_GENERIC_MESSAGE, AdminMessage.TYPE_ERROR );
179                 }
180 
181                 return getPostBackUrl( request, comment );
182             }
183         }
184 
185         return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
186     }
187 
188     /**
189      * Do pinned a comment.
190      * 
191      * @param request
192      *            the request
193      * @param cancelPinned
194      *            true if the comment must be unpinned
195      * @return the string
196      */
197     public String doPinned( HttpServletRequest request, boolean cancelPinned )
198     {
199         String strIdComment = request.getParameter( CommentConstants.PARAMETER_ID_COMMENT );
200 
201         if ( StringUtils.isNotBlank( strIdComment ) && StringUtils.isNumeric( strIdComment ) )
202         {
203             int nIdComment = Integer.parseInt( strIdComment );
204             Comment comment = _commentService.findByPrimaryKey( nIdComment );
205 
206             if ( comment != null )
207             {
208                 try
209                 {
210                     _commentService.updateCommentPinned( nIdComment, !cancelPinned );
211                 }
212                 catch( Exception ex )
213                 {
214                     // Something wrong happened... a database check might be needed
215                     AppLogService.error( ex.getMessage( ) + " when updating a comment", ex );
216 
217                     return AdminMessageService.getMessageUrl( request, CommentConstants.MESSAGE_ERROR_GENERIC_MESSAGE, AdminMessage.TYPE_ERROR );
218                 }
219 
220                 return getPostBackUrl( request, comment );
221             }
222         }
223 
224         return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
225     }
226 
227     /**
228      * Gets the confirm remove comment.
229      * 
230      * @param request
231      *            the request
232      * @return the confirm remove comment
233      */
234     public String getConfirmRemoveComment( HttpServletRequest request )
235     {
236         UrlItem url = new UrlItem( JSP_URL_DO_REMOVE_COMMENT );
237         url.addParameter( CommentConstants.PARAMETER_ID_COMMENT, request.getParameter( CommentConstants.PARAMETER_ID_COMMENT ) );
238         url.addParameter( CommentConstants.PARAMETER_FROM_URL, StringUtils.replace( request.getParameter( CommentConstants.PARAMETER_FROM_URL ),
239                 CommentConstants.CONSTANT_AND, CommentConstants.CONSTANT_AND_HTML ) );
240         addViewResourceInUrl( request, url );
241 
242         return AdminMessageService.getMessageUrl( request, CommentConstants.MESSAGE_CONFIRM_REMOVE_COMMENT, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
243     }
244 
245     /**
246      * Do remove comment.
247      * 
248      * @param request
249      *            the request
250      * @return the string
251      */
252     public String doRemoveComment( HttpServletRequest request )
253     {
254         String strIdComment = request.getParameter( CommentConstants.PARAMETER_ID_COMMENT );
255 
256         if ( StringUtils.isNotBlank( strIdComment ) && StringUtils.isNumeric( strIdComment ) )
257         {
258             int nIdComment = Integer.parseInt( strIdComment );
259             Comment comment = _commentService.findByPrimaryKey( nIdComment );
260 
261             if ( comment != null )
262             {
263                 try
264                 {
265                     _commentService.remove( nIdComment );
266                 }
267                 catch( Exception ex )
268                 {
269                     // Something wrong happened... a database check might be needed
270                     AppLogService.error( ex.getMessage( ) + " when updating a comment", ex );
271 
272                     return AdminMessageService.getMessageUrl( request, CommentConstants.MESSAGE_ERROR_GENERIC_MESSAGE, AdminMessage.TYPE_ERROR );
273                 }
274 
275                 return getPostBackUrl( request, comment );
276             }
277         }
278 
279         return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
280     }
281 
282     /**
283      * Get the comment creation page
284      * 
285      * @param request
286      *            The request
287      * @return The HTML content to display
288      */
289     public String getCreateComment( HttpServletRequest request )
290     {
291         setPageTitleProperty( MESSAGE_TITLE_CREATE_COMMENT );
292 
293         String strExtendableResourceType = request.getParameter( CommentConstants.PARAMETER_EXTENDABLE_RESOURCE_TYPE );
294         String strIdExtendableResource = request.getParameter( CommentConstants.PARAMETER_ID_EXTENDABLE_RESOURCE );
295         String strIdParentComment = request.getParameter( CommentConstants.PARAMETER_ID_COMMENT );
296         String strViewAllResources = request.getParameter( CommentConstants.PARAMETER_VIEW_ALL_RESOURCES );
297 
298         AdminUser user = AdminUserService.getAdminUser( request );
299 
300         Map<String, Object> model = new HashMap<String, Object>( );
301         model.put( CommentConstants.MARK_ALL_RESOURCES, !StringUtils.isEmpty( strViewAllResources ) && new Boolean( strViewAllResources ) );
302         model.put( CommentConstants.MARK_EXTENDABLE_RESOURCE_TYPE, strExtendableResourceType );
303         model.put( CommentConstants.MARK_ID_EXTENDABLE_RESOURCE, strIdExtendableResource );
304         model.put( CommentConstants.PARAMETER_ID_COMMENT, strIdParentComment );
305         model.put( CommentConstants.PARAMETER_NAME, user.getFirstName( ) + CONSTANT_SPACE + user.getLastName( ).toUpperCase( ) );
306         model.put( CommentConstants.MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
307         model.put( CommentConstants.MARK_LOCALE, AdminUserService.getLocale( request ) );
308         model.put( CommentConstants.PARAMETER_FROM_URL, StringUtils.replace( request.getParameter( CommentConstants.PARAMETER_FROM_URL ),
309                 CommentConstants.CONSTANT_AND, CommentConstants.CONSTANT_AND_HTML ) );
310         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_COMMENT, AdminUserService.getLocale( request ), model );
311 
312         return getAdminPage( template.getHtml( ) );
313     }
314 
315     /**
316      * Do create a comment
317      * 
318      * @param request
319      *            The request
320      * @return The URL to redirect to
321      */
322     public String doCreateComment( HttpServletRequest request )
323     {
324         String strExtendableResourceType = request.getParameter( CommentConstants.PARAMETER_EXTENDABLE_RESOURCE_TYPE );
325         String strIdExtendableResource = request.getParameter( CommentConstants.PARAMETER_ID_EXTENDABLE_RESOURCE );
326         String strIdParentComment = request.getParameter( CommentConstants.PARAMETER_ID_COMMENT );
327         String strName = request.getParameter( CommentConstants.PARAMETER_NAME );
328 
329         String strComment = request.getParameter( CommentConstants.MARK_COMMENT );
330         if ( StringUtils.isEmpty( strComment ) || StringUtils.isEmpty( strName ) )
331         {
332             return AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_FIELD, AdminMessage.TYPE_STOP );
333         }
334 
335         int nIdParentComment = 0;
336         if ( StringUtils.isNotEmpty( strIdParentComment ) && StringUtils.isNumeric( strIdParentComment ) )
337         {
338             nIdParentComment = Integer.parseInt( strIdParentComment );
339             // We check that the parent has no parent. If it has one, then we use it instead
340             if ( nIdParentComment > 0 )
341             {
342                 Comment parrentComment = _commentService.findByPrimaryKey( nIdParentComment );
343                 // If the parent has a parent
344                 if ( parrentComment.getIdParentComment( ) > 0 )
345                 {
346                     nIdParentComment = parrentComment.getIdParentComment( );
347                 }
348             }
349         }
350         AdminUser user = AdminUserService.getAdminUser( request );
351 
352         Commentugins/extend/modules/comment/business/Comment.html#Comment">Comment comment = new Comment( );
353         comment.setIdExtendableResource( strIdExtendableResource );
354         comment.setExtendableResourceType( strExtendableResourceType );
355         comment.setIdParentComment( nIdParentComment );
356         comment.setComment( strComment );
357         Timestamp currentDate = new Timestamp( new Date( ).getTime( ) );
358         comment.setDateComment( currentDate );
359         comment.setDateLastModif( currentDate );
360         comment.setName( strName );
361         comment.setEmail( user.getEmail( ) );
362         comment.setPublished( true );
363         comment.setIpAddress( SecurityUtil.getRealIp( request ) );
364         comment.setIsAdminComment( true );
365 
366         _commentService.create( comment, request );
367         _resourceHistoryService.create( CommentResourceExtender.EXTENDER_TYPE_COMMENT, strIdExtendableResource, strExtendableResourceType, request );
368 
369         // we redirect the user to the manage comment page
370         String strPostBackUrl = (String) request.getSession( ).getAttribute( CommentPlugin.PLUGIN_NAME + CommentConstants.SESSION_COMMENT_ADMIN_POST_BACK_URL );
371         request.getSession( ).setAttribute( CommentPlugin.PLUGIN_NAME + CommentConstants.SESSION_COMMENT_ADMIN_POST_BACK_URL, null );
372         if ( StringUtils.isEmpty( strPostBackUrl ) )
373         {
374             strPostBackUrl = JSP_VIEW_EXTENDER_INFO;
375         }
376         UrlItem url = new UrlItem( strPostBackUrl );
377         url.addParameter( CommentConstants.PARAMETER_EXTENDER_TYPE, CommentResourceExtender.EXTENDER_TYPE_COMMENT );
378         addIdExtendableResourceInUrl( strIdExtendableResource, request, url );
379         url.addParameter( CommentConstants.PARAMETER_EXTENDABLE_RESOURCE_TYPE, strExtendableResourceType );
380 
381         if ( nIdParentComment > 0 )
382         {
383             url.addParameter( CommentConstants.PARAMETER_ID_COMMENT, nIdParentComment );
384         }
385         url.addParameter( CommentConstants.PARAMETER_FROM_URL, StringUtils.replace( request.getParameter( CommentConstants.PARAMETER_FROM_URL ),
386                 CommentConstants.CONSTANT_AND, CommentConstants.CONSTANT_AND_HTML ) );
387 
388         return url.getUrl( );
389     }
390 
391     private void addIdExtendableResourceInUrl( String strIdExtendableResource, HttpServletRequest request, UrlItem url )
392     {
393         String strViewAllResources = request.getParameter( CommentConstants.PARAMETER_VIEW_ALL_RESOURCES );
394         if ( !StringUtils.isEmpty( strViewAllResources ) && new Boolean( strViewAllResources ) )
395         {
396             url.addParameter( CommentConstants.PARAMETER_ID_EXTENDABLE_RESOURCE, CommentConstants.CONSTANT_ALL_RESSOURCE_ID );
397         }
398         else
399         {
400             url.addParameter( CommentConstants.PARAMETER_ID_EXTENDABLE_RESOURCE, strIdExtendableResource );
401         }
402 
403     }
404 
405     private void addViewResourceInUrl( HttpServletRequest request, UrlItem url )
406     {
407 
408         String strViewAllResources = request.getParameter( CommentConstants.PARAMETER_VIEW_ALL_RESOURCES );
409         if ( !StringUtils.isEmpty( strViewAllResources ) )
410         {
411             url.addParameter( CommentConstants.PARAMETER_VIEW_ALL_RESOURCES, strViewAllResources );
412         }
413 
414     }
415 
416     /**
417      * Do process a workflow action over an comment
418      * 
419      * @param request
420      *            The request
421      * @return The next URL to redirect to
422      */
423     public String doProcessWorkflowAction( HttpServletRequest request )
424     {
425         String strIdAction = request.getParameter( CommentConstants.PARAMETER_ID_ACTION );
426         String strIdComment = request.getParameter( CommentConstants.PARAMETER_ID_COMMENT );
427 
428         if ( StringUtils.isNumeric( strIdAction ) && StringUtils.isNumeric( strIdComment ) )
429         {
430             int nIdAction = Integer.parseInt( strIdAction );
431             int nIdComment = Integer.parseInt( strIdComment );
432             
433             Comment comment = _commentService.findByPrimaryKey( nIdComment );
434             String resourceType = _commentService.getResourceType( comment.getExtendableResourceType( ) );
435            
436             int nIdExtendable = getIdExtender( comment );
437                         
438             try
439             {
440                 if ( WorkflowService.getInstance( ).isDisplayTasksForm( nIdAction, getLocale( ) ) )
441                 {                   
442                     UrlItem url = new UrlItem( JSP_VIEW_TASKS_FORM );
443                    
444                     url.addParameter( CommentConstants.PARAMETER_ID_ACTION, strIdAction ); 
445                     url.addParameter( CommentConstants.PARAMETER_ID_COMMENT, strIdComment );
446 
447                     return url.getUrl( );
448                 }
449                 else
450                 {
451                     WorkflowService.getInstance( ).doProcessAction( nIdComment, resourceType, nIdAction, nIdExtendable, request, getLocale( ), false, getUser( ) );
452                 }
453             }
454             catch( Exception e )
455             {
456                 AppLogService.error( "Error processing action for record {} ", nIdComment, e.getMessage( ), e );
457             }
458             
459             return getPostBackUrl( request, comment );
460         }
461         return AdminMessageService.getMessageUrl( request, CommentConstants.MESSAGE_ERROR_GENERIC_MESSAGE, AdminMessage.TYPE_ERROR );
462     }
463     
464     /**
465      * Get tasks form workflow
466      * @param request
467      * @return
468      */
469     public String getTasksFormWorkflow( HttpServletRequest request )
470     {
471         String strIdAction = request.getParameter( CommentConstants.PARAMETER_ID_ACTION );
472         String strIdComment = request.getParameter( CommentConstants.PARAMETER_ID_COMMENT );
473         
474         Map<String, Object> model = new HashMap<>( );
475         
476         if ( StringUtils.isNumeric( strIdAction ) && StringUtils.isNumeric( strIdComment ) )
477         {
478             int nIdAction = Integer.parseInt( strIdAction );
479             int nIdComment = Integer.parseInt( strIdComment );
480             
481             Comment comment = _commentService.findByPrimaryKey( nIdComment );  
482             String resourceType = _commentService.getResourceType( comment.getExtendableResourceType( ) );   
483             String strHtmlTasksForm = WorkflowService.getInstance( ).getDisplayTasksForm( nIdComment, resourceType, nIdAction, request, getLocale( ),
484                     getUser( ) );
485             
486             model.put( CommentConstants.PARAMETER_ID_ACTION, strIdAction );
487             model.put( CommentConstants.PARAMETER_ID_COMMENT, strIdComment );
488             model.put( MARK_TASK_FORM, strHtmlTasksForm );
489         }
490         
491         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_TASKS_FORM_WORKFLOW, AdminUserService.getLocale( request ), model );
492         
493         return getAdminPage( template.getHtml( ) );
494     }
495     
496     /**
497      * Do save task form
498      * @param request
499      * @return The next URL to redirect to
500      */
501     public String doSaveTaskForm( HttpServletRequest request )
502     {
503         String strIdAction = request.getParameter( CommentConstants.PARAMETER_ID_ACTION );
504         String strIdComment = request.getParameter( CommentConstants.PARAMETER_ID_COMMENT );
505         
506         if ( StringUtils.isNumeric( strIdAction ) && StringUtils.isNumeric( strIdComment ) )
507         {
508             int nIdAction = Integer.parseInt( strIdAction );
509             int nIdComment = Integer.parseInt( strIdComment );
510         
511             Comment comment = _commentService.findByPrimaryKey( nIdComment );
512             String resourceType = _commentService.getResourceType( comment.getExtendableResourceType( ) );
513         
514             int nIdExtendable = getIdExtender( comment );
515             
516             try
517             {
518                 String strError = WorkflowService.getInstance( ).doSaveTasksForm( comment.getIdComment( ) , resourceType, nIdAction, nIdExtendable,
519                         request, getLocale( ), getUser( ) );
520                 
521                 if( strError != null )
522                 {
523                     return AdminMessageService.getMessageUrl( request, CommentConstants.MESSAGE_ERROR_GENERIC_MESSAGE, AdminMessage.TYPE_ERROR );
524                 }
525                 else 
526                 {
527                     WorkflowService.getInstance( ).doProcessAction( comment.getIdComment( ), resourceType, nIdAction, nIdExtendable, request, getLocale( ),
528                             false, getUser( ) );
529                 }
530             }
531             catch ( AppException e )
532             {
533                 AppLogService.error( "Error processing action for record {}", nIdComment, e );
534             }
535         
536             return getPostBackUrl( request, comment );
537         }
538         return getAdminPage( JSP_VIEW_EXTENDER_INFO );
539     }
540 
541     /**
542      * Get id extender
543      * @param comment
544      * @return id extender
545      */
546     private int getIdExtender( Comment comment )
547     {
548         ResourceExtenderDTOFilter filter = new ResourceExtenderDTOFilter( );
549         filter.setFilterExtendableResourceType( comment.getExtendableResourceType( ) );
550         filter.setFilterIdExtendableResource( comment.getIdExtendableResource( ) );
551         filter.setFilterExtenderType( CommentResourceExtender.EXTENDER_TYPE_COMMENT );
552         filter.setIncludeWildcardResource( true );
553         
554         List<ResourceExtenderDTO> listResourceExtender = _resourceExtenderService.findByFilter( filter );        
555         return listResourceExtender.get( 0 ).getIdExtender( );
556     }
557     
558     /**
559      * get post back url
560      * @param request
561      * @param comment
562      * @return back url
563      */
564     private String getPostBackUrl( HttpServletRequest request, Comment comment )
565     {
566         String strPostBackUrl = (String) request.getSession( )
567                 .getAttribute( CommentPlugin.PLUGIN_NAME + CommentConstants.SESSION_COMMENT_ADMIN_POST_BACK_URL );
568         
569         request.getSession( ).setAttribute( CommentPlugin.PLUGIN_NAME + CommentConstants.SESSION_COMMENT_ADMIN_POST_BACK_URL, null );
570         
571         if ( StringUtils.isEmpty( strPostBackUrl ) )
572         {
573             strPostBackUrl = JSP_VIEW_EXTENDER_INFO;
574         }
575         
576         UrlItem url = new UrlItem( strPostBackUrl );
577         url.addParameter( CommentConstants.PARAMETER_EXTENDER_TYPE, CommentResourceExtender.EXTENDER_TYPE_COMMENT );
578         addIdExtendableResourceInUrl( comment.getIdExtendableResource( ), request, url );
579 
580         url.addParameter( CommentConstants.PARAMETER_EXTENDABLE_RESOURCE_TYPE, comment.getExtendableResourceType( ) );
581         if ( comment.getIdParentComment( ) > 0 )
582         {
583             url.addParameter( CommentConstants.PARAMETER_ID_COMMENT, comment.getIdParentComment( ) );
584         }
585         
586         url.addParameter( CommentConstants.PARAMETER_FROM_URL, StringUtils.replace( request.getParameter( CommentConstants.PARAMETER_FROM_URL ),
587                 CommentConstants.CONSTANT_AND, CommentConstants.CONSTANT_AND_HTML ) );
588 
589         return url.getUrl( );
590     }
591 }