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.blog.web.portlet;
35  
36  import java.sql.Date;
37  import java.text.ParseException;
38  import java.text.SimpleDateFormat;
39  import java.util.ArrayList;
40  import java.util.HashMap;
41  import java.util.List;
42  
43  import javax.servlet.http.HttpServletRequest;
44  
45  import fr.paris.lutece.plugins.blog.business.Blog;
46  import fr.paris.lutece.plugins.blog.business.BlogHome;
47  import fr.paris.lutece.plugins.blog.business.BlogSearchFilter;
48  import fr.paris.lutece.plugins.blog.business.BlogSerializable;
49  import fr.paris.lutece.plugins.blog.business.TagHome;
50  
51  import org.apache.commons.lang3.StringUtils;
52  import org.apache.commons.lang3.ArrayUtils;
53  
54  import fr.paris.lutece.plugins.blog.business.portlet.BlogListPortlet;
55  import fr.paris.lutece.plugins.blog.business.portlet.BlogListPortletHome;
56  import fr.paris.lutece.plugins.blog.business.portlet.BlogPublication;
57  import fr.paris.lutece.plugins.blog.business.portlet.BlogPublicationHome;
58  import fr.paris.lutece.plugins.blog.service.BlogService;
59  import fr.paris.lutece.plugins.blog.service.PublishingService;
60  import fr.paris.lutece.plugins.blog.service.docsearch.BlogSearchService;
61  import fr.paris.lutece.plugins.blog.web.BlogPublicationJspBean;
62  import fr.paris.lutece.portal.business.portlet.PortletHome;
63  import fr.paris.lutece.portal.business.user.AdminUser;
64  import fr.paris.lutece.portal.service.admin.AdminUserService;
65  import fr.paris.lutece.portal.service.util.AppPathService;
66  import fr.paris.lutece.portal.service.util.AppPropertiesService;
67  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
68  import fr.paris.lutece.portal.web.portlet.PortletJspBean;
69  import fr.paris.lutece.portal.web.util.LocalizedPaginator;
70  import fr.paris.lutece.util.date.DateUtil;
71  import fr.paris.lutece.util.html.AbstractPaginator;
72  import fr.paris.lutece.util.html.HtmlTemplate;
73  import fr.paris.lutece.util.json.JsonResponse;
74  import fr.paris.lutece.util.json.JsonUtil;
75  import java.util.Map;
76  
77  /**
78   * This class provides the user interface to manage BlogList Portlet
79   */
80  public class BlogListPortletJspBean extends PortletJspBean
81  {
82      // Right
83      public static final String RIGHT_MANAGE_ADMIN_SITE = "CORE_ADMIN_SITE";
84  
85      public static final String MARK_WEBAPP_URL = "webapp_url";
86      public static final String MARK_LIST_HTMLDOC = "blog_list";
87      public static final String MARK_LIST_PAGES = "pages_list";
88      public static final String MARK_LIST_HTMLDOC_PUBLISHED = "blog_list_published";
89  
90      public static final String PARAMETER_ACTION_PORTLET_ADD = "add";
91      public static final String PARAMETER_ACTION_PORTLET_REMOVE = "remove";
92      public static final String PARAMETER_ACTION_PORTLET = "action";
93      private static final String PARAMETER_PAGE_TEMPLATE_CODE = "page_template_code";
94  
95      private static final String PARAMETER_DOCUMENT_ID = "idDocument";
96      private static final String PARAMETER_DOCUMENT_ORDER = "orderDocument";
97      private static final String PARAMETER_REFRESH_BUTTON = "refresh";
98      protected static final String PARAMETER_TAG = "tag_doc";
99  
100     protected static final String PARAMETER_SEARCH_TEXT = "search_text";
101     protected static final String PARAMETER_UNPUBLISHED = "unpublished";
102     protected static final String PARAMETER_DATE_UPDATE_BLOG_AFTER = "dateUpdateBlogAfter";
103     protected static final String PARAMETER_DATE_UPDATE_BLOG_BEFOR = "dateUpdateBlogBefor";
104 
105     protected static final String PARAMETER_BUTTON_SEARCH = "button_search";
106     protected static final String PARAMETER_BUTTON_RESET = "button_reset";
107 
108     protected static final String MARK_IS_CHECKED = "is_checked";
109     protected static final String MARK_CURRENT_USER = "current_user";
110     protected static final String MARK_ID_BLOG = "id";
111     protected static final String MARK_SEARCH_TEXT = "search_text";
112 
113     protected static final String MARK_PAGINATOR = "paginator";
114     protected static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page";
115     protected static final String MARK_DATE_UPDATE_BLOG_AFTER = "dateUpdateBlogAfter";
116     protected static final String MARK_DATE_UPDATE_BLOG_BEFOR = "dateUpdateBlogBefor";
117     protected static final String MARK_UNPUBLISHED = "unpublished";
118     protected static final String MARK_LIST_TAG = "list_tag";
119 
120     // Properties
121     private static final String PROPERTY_DEFAULT_LIST_ITEM_PER_PAGE = "blog.listItems.itemsPerPage";
122 
123     private static final String VIEW_MODIFY_PORTLET = "getModify";
124 
125     private static final String RESPONSE_SUCCESS = "SUCCESS";
126 
127     // //////////////////////////////////////////////////////////////////////////
128     // Constants
129     private static final long serialVersionUID = 1L;
130 
131     // //////////////////////////////////////////////////////////////////////////
132     // Class attributes
133 
134     private BlogListPortlet _portlet;
135 
136     protected String _strCurrentPageIndex;
137     protected int _nItemsPerPage;
138 
139     protected int _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_DEFAULT_LIST_ITEM_PER_PAGE, 20 );
140 
141     // Session variable to store working values
142     protected boolean _bIsChecked = false;
143     protected String _strSearchText;
144     protected boolean _bIsUnpulished = false;
145     protected String _dateUpdateBlogAfter;
146     protected String _dateUpdateBlogBefor;
147     protected boolean _bIsSorted = false;
148     protected String _strSortedAttributeName;
149     protected Boolean _bIsAscSort;
150     protected String [ ] _strTag;
151 
152     /**
153      * Returns portlet's properties prefix
154      *
155      * @return prefix
156      */
157     public String getPropertiesPrefix( )
158     {
159         return "portlet.blogdocument";
160     }
161 
162     /**
163      * Return a model that contains the list and paginator infos
164      * 
165      * @param request
166      *            The HTTP request
167      * @return The map
168      */
169     protected Map<String, Object> getPaginatedListModel( HttpServletRequest request )
170     {
171         List<Integer> listBlogsId = filterBlogIds( request );
172 
173         _strCurrentPageIndex = AbstractPaginator.getPageIndex( request, AbstractPaginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
174         _nItemsPerPage = AbstractPaginator.getItemsPerPage( request, AbstractPaginator.PARAMETER_ITEMS_PER_PAGE, _nDefaultItemsPerPage, _nItemsPerPage );
175         List<Blog> listBlogPublished = new ArrayList<>( );
176         List<Blog> listBlogNotPublished = new ArrayList<>( );
177 
178         for ( BlogPublication i : _portlet.getArrayBlogs( ) )
179         {
180             Blog blog = BlogService.getInstance( ).findByPrimaryKeyWithoutBinaries( i.getIdBlog( ) );
181             listBlogPublished.add( blog );
182             listBlogsId.removeIf( blg -> blg.equals( blog.getId( ) ) );
183         }
184 
185         LocalizedPaginator<Integer> paginator = new LocalizedPaginator<>( listBlogsId, _nItemsPerPage, getCurrentUrlFromRequest( request ),
186                 AbstractPaginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex, getLocale( ) );
187         List<Blog> listBlog = new ArrayList<>( );
188 
189         for ( Integer documentId : paginator.getPageItems( ) )
190         {
191             Blog blog = BlogService.getInstance( ).findByPrimaryKeyWithoutBinaries( documentId );
192 
193             if ( blog != null )
194             {
195                 listBlog.add( blog );
196             }
197         }
198 
199         listBlogNotPublished.addAll( listBlog );
200 
201         HashMap<String, Object> model = new HashMap<>( );
202         model.put( MARK_PAGINATOR, paginator );
203         model.put( MARK_NB_ITEMS_PER_PAGE, "" + _nItemsPerPage );
204         model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
205         model.put( MARK_LIST_HTMLDOC, listBlogNotPublished );
206         model.put( MARK_LIST_HTMLDOC_PUBLISHED, listBlogPublished );
207 
208         model.put( MARK_LIST_TAG, TagHome.getTagsReferenceList( ) );
209         model.put( MARK_IS_CHECKED, _bIsChecked );
210         model.put( MARK_SEARCH_TEXT, _strSearchText );
211         model.put( MARK_DATE_UPDATE_BLOG_AFTER, _dateUpdateBlogAfter );
212         model.put( MARK_DATE_UPDATE_BLOG_BEFOR, _dateUpdateBlogBefor );
213         model.put( MARK_UNPUBLISHED, _bIsUnpulished );
214 
215         model.put( MARK_LIST_PAGES, BlogListPortletHome.loadPages( BlogListPortlet.RESOURCE_ID ) );
216 
217         return model;
218     }
219 
220     /**
221      * Get the list of filtered blog ids.
222      *
223      * @param request
224      * @return list of blog id.
225      */
226     private List<Integer> filterBlogIds( HttpServletRequest request )
227     {
228         List<Integer> listBlogsId = new ArrayList<>( );
229         AdminUser user = AdminUserService.getAdminUser( request );
230 
231         if ( StringUtils.isNotBlank( _strSearchText ) || ArrayUtils.isNotEmpty(
232                 _strTag ) || _bIsChecked || _bIsUnpulished || _dateUpdateBlogAfter != null || _dateUpdateBlogBefor != null )
233         {
234             BlogSearchFilterbusiness/BlogSearchFilter.html#BlogSearchFilter">BlogSearchFilter filter = new BlogSearchFilter( );
235             if ( StringUtils.isNotBlank( _strSearchText ) )
236             {
237                 filter.setKeywords( _strSearchText );
238             }
239             if ( ArrayUtils.isNotEmpty( _strTag ) )
240             {
241                 filter.setTag( _strTag );
242             }
243             if ( _bIsChecked )
244             {
245                 filter.setUser( user.getAccessCode( ) );
246             }
247             if ( _bIsUnpulished )
248             {
249                 filter.setIsUnpulished( _bIsUnpulished );
250             }
251             if ( _dateUpdateBlogAfter != null )
252             {
253                 filter.setUpdateDateAfter( DateUtil.formatDate( _dateUpdateBlogAfter, request.getLocale( ) ) );
254             }
255             if ( _dateUpdateBlogBefor != null )
256             {
257                 filter.setUpdateDateBefor( DateUtil.formatDate( _dateUpdateBlogBefor, request.getLocale( ) ) );
258             }
259 
260             BlogSearchService.getInstance( ).getSearchResults( filter, listBlogsId );
261 
262         }
263         else
264         {
265 
266             listBlogsId = BlogHome.getIdBlogsList( );
267         }
268 
269         return listBlogsId;
270     }
271 
272 
273     /**
274      *
275      * @param request
276      */
277     private void setSearchBlog( HttpServletRequest request, String strButtonSearch, String strButtonReset )
278     {
279 
280         if ( strButtonSearch != null )
281         {
282             // CURRENT USER
283             _bIsChecked = request.getParameter( MARK_CURRENT_USER ) != null;
284             _strSearchText = request.getParameter( PARAMETER_SEARCH_TEXT );
285             _strTag = request.getParameterValues( PARAMETER_TAG );
286             _bIsUnpulished = request.getParameter( PARAMETER_UNPUBLISHED ) != null;
287             _dateUpdateBlogAfter = request.getParameter( PARAMETER_DATE_UPDATE_BLOG_AFTER );
288             _dateUpdateBlogBefor = request.getParameter( PARAMETER_DATE_UPDATE_BLOG_BEFOR );
289 
290         }
291         else
292             if ( strButtonReset != null )
293             {
294 
295                 _bIsChecked = false;
296                 _strSearchText = null;
297                 _strTag = null;
298                 _bIsUnpulished = false;
299                 _dateUpdateBlogAfter = null;
300                 _dateUpdateBlogBefor = null;
301 
302             }
303     }
304 
305     public String getSearch( HttpServletRequest request )
306     {
307         Map<String, Object> data = new HashMap<>( );
308         String strButtonSearch = request.getParameter( PARAMETER_BUTTON_SEARCH );
309         String strButtonReset = request.getParameter( PARAMETER_BUTTON_RESET );
310         setSearchBlog( request, strButtonSearch, strButtonReset );
311 
312         List<Integer> listBlogsId = filterBlogIds( request );
313 
314         List<BlogSerializable> listBlogNotPublished = new ArrayList<>( );
315 
316         for ( BlogPublication i : _portlet.getArrayBlogs( ) )
317         {
318             Blog blog = BlogService.getInstance( ).findByPrimaryKeyWithoutBinaries( i.getIdBlog( ) );
319             listBlogsId.removeIf( blg -> blg.equals( blog.getId( ) ) );
320         }
321         LocalizedPaginator<Integer> paginator = new LocalizedPaginator<>( listBlogsId, _nItemsPerPage, getCurrentUrlFromRequest( request ),
322                 AbstractPaginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex, getLocale( ) );
323 
324         for ( Integer documentId : paginator.getPageItems( ) )
325         {
326             Blog blog = BlogService.getInstance( ).findByPrimaryKeyWithoutBinaries( documentId );
327             if ( blog != null )
328             {
329                 listBlogNotPublished.add( new BlogSerializable( blog.getId( ), blog.getContentLabel( ) ) );
330             }
331         }
332         data.put( MARK_LIST_HTMLDOC, listBlogNotPublished );
333         JsonResponse json = new JsonResponse( data );
334         return JsonUtil.buildJsonResponse( json );
335     }
336 
337     /**
338      * Returns the Download portlet creation form
339      *
340      * @param request
341      *            The http request
342      * @return The HTML form
343      */
344     @Override
345     public String getCreate( HttpServletRequest request )
346     {
347         String strIdPage = request.getParameter( PARAMETER_PAGE_ID );
348         String strIdPortletType = request.getParameter( PARAMETER_PORTLET_TYPE_ID );
349         _portlet = ( _portlet != null && request.getParameter( AbstractPaginator.PARAMETER_PAGE_INDEX ) != null ) ? _portlet : new BlogListPortlet( );
350         Map<String, Object> model = getPaginatedListModel( request );
351         HtmlTemplate template = getCreateTemplate( strIdPage, strIdPortletType, model );
352 
353         return template.getHtml( );
354     }
355 
356     /**
357      * Returns the Download portlet modification form
358      *
359      * @param request
360      *            The Http request
361      * @return The HTML form
362      */
363     @View( VIEW_MODIFY_PORTLET )
364     @Override
365     public String getModify( HttpServletRequest request )
366     {
367         String strPortletId = request.getParameter( PARAMETER_PORTLET_ID );
368         int nPortletId = Integer.parseInt( strPortletId );
369         _portlet = ( _portlet != null && request.getParameter( AbstractPaginator.PARAMETER_PAGE_INDEX ) != null ) ? _portlet
370                 : (BlogListPortlet) PortletHome.findByPrimaryKey( nPortletId );
371         Map<String, Object> model = getPaginatedListModel( request );
372 
373         HtmlTemplate template = getModifyTemplate( _portlet, model );
374 
375         return template.getHtml( );
376     }
377 
378     /**
379      * Process portlet's creation
380      *
381      * @param request
382      *            The Http request
383      * @return The Jsp management URL of the process result
384      */
385     @Override
386     public String doCreate( HttpServletRequest request )
387     {
388 
389         String button = request.getParameter( PARAMETER_REFRESH_BUTTON );
390         _nDefaultItemsPerPage = AbstractPaginator.getItemsPerPage( request, AbstractPaginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage, _nDefaultItemsPerPage );
391         String strIdPage = request.getParameter( PARAMETER_PAGE_ID );
392         String strButtonSearch = request.getParameter( PARAMETER_BUTTON_SEARCH );
393         String strButtonReset = request.getParameter( PARAMETER_BUTTON_RESET );
394         int nIdPage = Integer.parseInt( strIdPage );
395 
396         if ( ( button != null && button.equals( PARAMETER_REFRESH_BUTTON ) ) || strButtonSearch != null || strButtonReset != null )
397         {
398 
399             setSearchBlog( request, strButtonSearch, strButtonReset );
400             return "../../DoCreatePortlet.jsp?portlet_type_id=" + BlogListPortlet.RESOURCE_ID + "&page_id=" + strIdPage + "&"
401                     + AbstractPaginator.PARAMETER_PAGE_INDEX + "=1";
402         }
403 
404         int order = 1;
405 
406         // gets the identifier of the parent page
407         String strTemplateCode = request.getParameter( PARAMETER_PAGE_TEMPLATE_CODE );
408 
409         // get portlet common attributes
410         String strErrorUrl = setPortletCommonData( request, _portlet );
411 
412         if ( strErrorUrl != null )
413         {
414             return strErrorUrl;
415         }
416 
417         _portlet.setPageId( nIdPage );
418 
419         // gets the specific parameters
420         _portlet.setPageTemplateDocument( Integer.parseInt( strTemplateCode ) );
421 
422         for ( BlogPublication doc : _portlet.getArrayBlogs( ) )
423         {
424 
425             doc.setBlogOrder( order );
426             order++;
427 
428         }
429         // Portlet creation
430         BlogListPortletHome.getInstance( ).create( _portlet );
431 
432         for ( BlogPublication doc : _portlet.getArrayBlogs( ) )
433         {
434             int nbPublication = BlogPublicationHome.countPublicationByIdBlogAndDate( doc.getIdBlog( ), new java.util.Date( ) );
435             // First publication of this blog -> indexing needed
436             if ( nbPublication == 1 )
437             {
438                 BlogService.getInstance( ).fireCreateBlogEvent( doc.getIdBlog( ) );
439             }
440         }
441 
442         // Displays the page with the new Portlet
443         return getPageUrl( nIdPage );
444     }
445 
446     /**
447      * Process portlet's modification
448      *
449      * @param request
450      *            The http request
451      * @return Management's Url
452      */
453     @Override
454     public String doModify( HttpServletRequest request )
455     {
456 
457         _nDefaultItemsPerPage = AbstractPaginator.getItemsPerPage( request, AbstractPaginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage, _nDefaultItemsPerPage );
458         String button = request.getParameter( PARAMETER_REFRESH_BUTTON );
459         String strButtonSearch = request.getParameter( PARAMETER_BUTTON_SEARCH );
460         String strButtonReset = request.getParameter( PARAMETER_BUTTON_RESET );
461 
462         if ( ( button != null && button.equals( PARAMETER_REFRESH_BUTTON ) ) || strButtonSearch != null || strButtonReset != null )
463         {
464 
465             setSearchBlog( request, strButtonSearch, strButtonReset );
466             return "../../DoModifyPortlet.jsp?portlet_id=" + _portlet.getId( ) + "&" + AbstractPaginator.PARAMETER_PAGE_INDEX + "=1";
467         }
468 
469         int order = 1;
470 
471         // recovers portlet attributes
472         String strDocumentTypeCode = request.getParameter( PARAMETER_PAGE_TEMPLATE_CODE );
473         // retrieve portlet common attributes
474         String strErrorUrl = setPortletCommonData( request, _portlet );
475 
476         if ( strErrorUrl != null )
477         {
478             return strErrorUrl;
479         }
480 
481         _portlet.setPageTemplateDocument( Integer.parseInt( strDocumentTypeCode ) );
482 
483         for ( BlogPublication doc : _portlet.getArrayBlogs( ) )
484         {
485 
486             doc.setBlogOrder( order );
487             order++;
488 
489         }
490         // updates the portlet
491         _portlet.update( );
492 
493         for ( Integer removedBlog : _portlet.getRemovedBlogsId( ) )
494         {
495             int nbPublication = BlogPublicationHome.countPublicationByIdBlogAndDate( removedBlog, new java.util.Date( ) );
496             // Last publication of this blog removed -> removing from index
497             if ( nbPublication == 0 )
498             {
499                 BlogService.getInstance( ).fireDeleteBlogEvent( removedBlog );
500             }
501         }
502 
503         for ( BlogPublication doc : _portlet.getArrayBlogs( ) )
504         {
505             int nbPublication = BlogPublicationHome.countPublicationByIdBlogAndDate( doc.getIdBlog( ), new java.util.Date( ) );
506             // First publication of this blog -> indexing needed
507             if ( nbPublication == 1 )
508             {
509                 BlogService.getInstance( ).fireCreateBlogEvent( doc.getIdBlog( ) );
510             }
511         }
512 
513         // displays the page withe the potlet updated
514         return getPageUrl( _portlet.getPageId( ) );
515     }
516 
517     /**
518      * Update blog portlet
519      *
520      * @param request
521      * @return Json The Json succes or echec
522      * @throws ParseException
523      */
524     public String updatePortletDocument( HttpServletRequest request ) throws ParseException
525     {
526         // recovers portlet attributes
527 
528         String strAction = request.getParameter( PARAMETER_ACTION_PORTLET );
529         String strIdDocument = request.getParameter( PARAMETER_DOCUMENT_ID );
530         String strOrderDocument = request.getParameter( PARAMETER_DOCUMENT_ORDER );
531 
532         int nIdDocument = Integer.parseInt( strIdDocument );
533         BlogPublication doc = PublishingService.getInstance( ).getBlogPublication( _portlet.getId( ), nIdDocument );
534         if ( doc == null )
535         {
536             doc = new BlogPublication( );
537             SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
538             doc.setDateEndPublishing( new Date( sdf.parse( BlogPublicationJspBean.DATE_END_PUBLICATION ).getTime( ) ) );
539             doc.setIdBlog( nIdDocument );
540         }
541         if ( strAction != null && !strAction.isEmpty( ) && strAction.equals( PARAMETER_ACTION_PORTLET_ADD ) )
542         {
543 
544             int nDocumentOrder = Integer.parseInt( strOrderDocument );
545             _portlet.addIdBlogs( nDocumentOrder, doc );
546 
547         }
548         else
549             if ( strAction != null && !strAction.isEmpty( ) && strAction.equals( PARAMETER_ACTION_PORTLET_REMOVE ) )
550             {
551 
552                 _portlet.removeBlogs( doc );
553 
554             }
555 
556         return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_SUCCESS ) );
557     }
558 
559     /**
560      *
561      * @param request
562      * @return
563      */
564     public static String getCurrentUrlFromRequest( HttpServletRequest request )
565     {
566         StringBuffer sbRequestURL = request.getRequestURL( );
567         String queryString = request.getQueryString( );
568 
569         if ( queryString == null )
570         {
571 
572             return sbRequestURL.toString( );
573 
574         }
575         else
576             if ( request.getParameter( AbstractPaginator.PARAMETER_PAGE_INDEX ) != null )
577             {
578 
579                 String [ ] query = queryString.split( "&" + AbstractPaginator.PARAMETER_PAGE_INDEX );
580                 queryString = query [0];
581             }
582 
583         return sbRequestURL.append( '?' ).append( queryString ).toString( );
584     }
585 
586 }