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