View Javadoc
1   /*
2    * Copyright (c) 2002-2017, Mairie de 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.directory.web.action;
35  
36  import fr.paris.lutece.plugins.directory.business.Directory;
37  import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupService;
38  import fr.paris.lutece.util.html.ItemNavigator;
39  import fr.paris.lutece.util.url.UrlItem;
40  
41  import java.util.ArrayList;
42  import java.util.Enumeration;
43  import java.util.List;
44  
45  import javax.servlet.http.HttpServletRequest;
46  
47  /**
48   * Visualization of all needed session values. Many features depends on search result or paginator. Those fields may be required for actions.
49   *
50   */
51  public final class DirectoryAdminSearchFields extends DefaultDirectorySearchFields
52  {
53      private static final long serialVersionUID = 7256733494058540733L;
54  
55      // session fields
56      private String _strCurrentPageIndexDirectory;
57      private int _nItemsPerPageDirectory;
58      private String _strCurrentPageIndexEntry;
59      private int _nItemsPerPageEntry;
60      private String _strCurrentPageIndexPrintMass;
61  
62      // private String _nItemsPerPagePrintMass;
63      private int _nItemsPerPagePrintMass;
64      private String _strCurrentPageIndex;
65      private String _strCurrentPageIndexDirectoryRecord;
66      private int _nItemsPerPageDirectoryRecord;
67      private int _nIdActive = ALL_INT;
68      private String _strWorkGroup = AdminWorkgroupService.ALL_GROUPS;
69      private int _nCountLine;
70      private int _nCountLineFailure;
71      private int _nIdWorkflowSate = ALL_INT;
72      private StringBuffer _strError;
73      private List<String> _listSelectedRecords;
74      private List<Integer> _listIdsResultRecord;
75      private ItemNavigator _itemNavigatorViewRecords;
76      private ItemNavigator _itemNavigatorHistory;
77      private String _strRedirectUrl;
78  
79      /**
80       * Gets the selected records
81       * 
82       * @return the selected records
83       */
84      public List<String> getSelectedRecords( )
85      {
86          return _listSelectedRecords;
87      }
88  
89      /**
90       * Sets the selected records
91       * 
92       * @param listSelectedRecords
93       *            the selected records
94       */
95      public void setSelectedRecords( List<String> listSelectedRecords )
96      {
97          _listSelectedRecords = listSelectedRecords;
98      }
99  
100     /**
101      * Current page index directory
102      * 
103      * @return current page index directory
104      */
105     public String getCurrentPageIndexDirectory( )
106     {
107         return _strCurrentPageIndexDirectory;
108     }
109 
110     /**
111      * Current page index directory
112      * 
113      * @param strCurrentPageIndexDirectory
114      *            current page index directory
115      */
116     public void setCurrentPageIndexDirectory( String strCurrentPageIndexDirectory )
117     {
118         _strCurrentPageIndexDirectory = strCurrentPageIndexDirectory;
119     }
120 
121     /**
122      * Items per page directory
123      * 
124      * @return item per page directory
125      */
126     public int getItemsPerPageDirectory( )
127     {
128         return _nItemsPerPageDirectory;
129     }
130 
131     /**
132      * Items per page directory
133      * 
134      * @param nItemsPerPageDirectory
135      *            items per page directory
136      */
137     public void setItemsPerPageDirectory( int nItemsPerPageDirectory )
138     {
139         _nItemsPerPageDirectory = nItemsPerPageDirectory;
140     }
141 
142     /**
143      * Current page index entry
144      * 
145      * @return current page index entry
146      */
147     public String getCurrentPageIndexEntry( )
148     {
149         return _strCurrentPageIndexEntry;
150     }
151 
152     /**
153      * Current page index entry
154      * 
155      * @param strCurrentPageIndexEntry
156      *            current page index entry
157      */
158     public void setCurrentPageIndexEntry( String strCurrentPageIndexEntry )
159     {
160         _strCurrentPageIndexEntry = strCurrentPageIndexEntry;
161     }
162 
163     /**
164      * Items per page entry
165      * 
166      * @return items per page entry
167      */
168     public int getItemsPerPageEntry( )
169     {
170         return _nItemsPerPageEntry;
171     }
172 
173     /**
174      * Items per page entry
175      * 
176      * @param nItemsPerPageEntry
177      *            items per page entry
178      */
179     public void setItemsPerPageEntry( int nItemsPerPageEntry )
180     {
181         _nItemsPerPageEntry = nItemsPerPageEntry;
182     }
183 
184     /**
185      * Current page index print mass
186      * 
187      * @return current page index print mass
188      */
189     public String getCurrentPageIndexPrintMass( )
190     {
191         return _strCurrentPageIndexPrintMass;
192     }
193 
194     /**
195      * Current page index print mass
196      * 
197      * @param strCurrentPageIndexPrintMass
198      *            current page index print mass
199      */
200     public void setCurrentPageIndexPrintMass( String strCurrentPageIndexPrintMass )
201     {
202         _strCurrentPageIndexPrintMass = strCurrentPageIndexPrintMass;
203     }
204 
205     /**
206      * Items per page print mass
207      * 
208      * @return items per page print mass
209      */
210     public int getItemsPerPagePrintMass( )
211     {
212         return _nItemsPerPagePrintMass;
213     }
214 
215     /**
216      * Items per page print mass
217      * 
218      * @param nItemsPerPagePrintMass
219      *            items per page print mass
220      */
221     public void setItemsPerPagePrintMass( int nItemsPerPagePrintMass )
222     {
223         _nItemsPerPagePrintMass = nItemsPerPagePrintMass;
224     }
225 
226     /**
227      * Current page index
228      * 
229      * @return current page index
230      */
231     public String getCurrentPageIndex( )
232     {
233         return _strCurrentPageIndex;
234     }
235 
236     /**
237      * Current page index
238      * 
239      * @param strCurrentPageIndex
240      *            current page index
241      */
242     public void setCurrentPageIndex( String strCurrentPageIndex )
243     {
244         _strCurrentPageIndex = strCurrentPageIndex;
245     }
246 
247     /**
248      * Current page index directory record
249      * 
250      * @return current page index directory record
251      */
252     public String getCurrentPageIndexDirectoryRecord( )
253     {
254         return _strCurrentPageIndexDirectoryRecord;
255     }
256 
257     /**
258      * Current page index directory record
259      * 
260      * @param strCurrentPageIndexDirectoryRecord
261      *            current page index directory record
262      */
263     public void setCurrentPageIndexDirectoryRecord( String strCurrentPageIndexDirectoryRecord )
264     {
265         _strCurrentPageIndexDirectoryRecord = strCurrentPageIndexDirectoryRecord;
266     }
267 
268     /**
269      * Items per page directory record
270      * 
271      * @return items per page directory record
272      */
273     public int getItemsPerPageDirectoryRecord( )
274     {
275         return _nItemsPerPageDirectoryRecord;
276     }
277 
278     /**
279      * Items per page directory record
280      * 
281      * @param nItemsPerPageDirectoryRecord
282      *            items per page directory record
283      */
284     public void setItemsPerPageDirectoryRecord( int nItemsPerPageDirectoryRecord )
285     {
286         _nItemsPerPageDirectoryRecord = nItemsPerPageDirectoryRecord;
287     }
288 
289     /**
290      * Id active
291      * 
292      * @return id active
293      */
294     public int getIdActive( )
295     {
296         return _nIdActive;
297     }
298 
299     /**
300      * Id active
301      * 
302      * @param nIdActive
303      *            id active
304      */
305     public void setIdActive( int nIdActive )
306     {
307         _nIdActive = nIdActive;
308     }
309 
310     /**
311      * Workgroup
312      * 
313      * @return workgroup
314      */
315     public String getWorkGroup( )
316     {
317         return _strWorkGroup;
318     }
319 
320     /**
321      * Workgroup
322      * 
323      * @param strWorkGroup
324      *            workgroup
325      */
326     public void setWorkGroup( String strWorkGroup )
327     {
328         _strWorkGroup = strWorkGroup;
329     }
330 
331     /**
332      * Count line
333      * 
334      * @return count line
335      */
336     public int getCountLine( )
337     {
338         return _nCountLine;
339     }
340 
341     /**
342      * Count line
343      * 
344      * @param nCountLine
345      *            count line
346      */
347     public void setCountLine( int nCountLine )
348     {
349         _nCountLine = nCountLine;
350     }
351 
352     /**
353      * Count line failure
354      * 
355      * @return count line failure
356      */
357     public int getCountLineFailure( )
358     {
359         return _nCountLineFailure;
360     }
361 
362     /**
363      * Count line failure
364      * 
365      * @param nCountLineFailure
366      *            count line failure
367      */
368     public void setCountLineFailure( int nCountLineFailure )
369     {
370         _nCountLineFailure = nCountLineFailure;
371     }
372 
373     /**
374      * Id workfow state
375      * 
376      * @return id workflow state
377      */
378     public int get_nIdWorkflowSate( )
379     {
380         return _nIdWorkflowSate;
381     }
382 
383     /**
384      * Id workflow state
385      * 
386      * @param nIdWorkflowSate
387      *            id workflow state
388      */
389     public void setIdWorkflowSate( int nIdWorkflowSate )
390     {
391         _nIdWorkflowSate = nIdWorkflowSate;
392     }
393 
394     /**
395      * Error
396      * 
397      * @return error
398      */
399     public StringBuffer getError( )
400     {
401         return _strError;
402     }
403 
404     /**
405      * Error
406      * 
407      * @param strError
408      *            error
409      */
410     public void setError( StringBuffer strError )
411     {
412         _strError = strError;
413     }
414 
415     /**
416      * Set the list of ids result record
417      * 
418      * @param listIdsResultRecord
419      *            the list of id result record
420      */
421     public void setListIdsResultRecord( List<Integer> listIdsResultRecord )
422     {
423         _listIdsResultRecord = listIdsResultRecord;
424     }
425 
426     /**
427      * Get the list of ids result record
428      * 
429      * @return the list of ids result record
430      */
431     public List<Integer> getListIdsResultRecord( )
432     {
433         return _listIdsResultRecord;
434     }
435 
436     /**
437      * Set the item navigator for records
438      * 
439      * @param nCurrentIdRecord
440      *            the current id record
441      * @param strUrl
442      *            the url
443      * @param strParameterName
444      *            the parameter name
445      */
446     public void setItemNavigatorViewRecords( int nCurrentIdRecord, String strUrl, String strParameterName )
447     {
448         if ( _itemNavigatorViewRecords == null )
449         {
450             if ( ( _listIdsResultRecord != null ) && !_listIdsResultRecord.isEmpty( ) )
451             {
452                 List<String> listIds = new ArrayList<String>( _listIdsResultRecord.size( ) );
453                 int nCurrentItemId = 0;
454                 int nIndex = 0;
455 
456                 for ( int nIdRecord : _listIdsResultRecord )
457                 {
458                     listIds.add( Integer.toString( nIdRecord ) );
459 
460                     if ( nIdRecord == nCurrentIdRecord )
461                     {
462                         nCurrentItemId = nIndex;
463                     }
464 
465                     nIndex++;
466                 }
467 
468                 _itemNavigatorViewRecords = new ItemNavigator( listIds, nCurrentItemId, strUrl, strParameterName );
469             }
470         }
471         else
472         {
473             _itemNavigatorViewRecords.setCurrentItemId( Integer.toString( nCurrentIdRecord ) );
474         }
475     }
476 
477     /**
478      * Set the item navigator
479      * 
480      * @param itemNavigator
481      *            the item navigator
482      */
483     public void setItemNavigatorViewRecords( ItemNavigator itemNavigator )
484     {
485         _itemNavigatorViewRecords = itemNavigator;
486     }
487 
488     /**
489      * Get the item navigator
490      * 
491      * @return the item navigator
492      */
493     public ItemNavigator getItemNavigatorViewRecords( )
494     {
495         return _itemNavigatorViewRecords;
496     }
497 
498     /**
499      * Set the item navigator for records
500      * 
501      * @param nCurrentIdRecord
502      *            the current id record
503      * @param strUrl
504      *            the url
505      * @param strParameterName
506      *            the parameter name
507      */
508     public void setItemNavigatorHistory( int nCurrentIdRecord, String strUrl, String strParameterName )
509     {
510         if ( _itemNavigatorHistory == null )
511         {
512             if ( ( _listIdsResultRecord != null ) && !_listIdsResultRecord.isEmpty( ) )
513             {
514                 List<String> listIds = new ArrayList<String>( _listIdsResultRecord.size( ) );
515                 int nCurrentItemId = 0;
516                 int nIndex = 0;
517 
518                 for ( int nIdRecord : _listIdsResultRecord )
519                 {
520                     listIds.add( Integer.toString( nIdRecord ) );
521 
522                     if ( nIdRecord == nCurrentIdRecord )
523                     {
524                         nCurrentItemId = nIndex;
525                     }
526 
527                     nIndex++;
528                 }
529 
530                 _itemNavigatorHistory = new ItemNavigator( listIds, nCurrentItemId, strUrl, strParameterName );
531             }
532         }
533         else
534         {
535             _itemNavigatorHistory.setCurrentItemId( Integer.toString( nCurrentIdRecord ) );
536         }
537     }
538 
539     /**
540      * Set the item navigator
541      * 
542      * @param itemNavigator
543      *            the item navigator
544      */
545     public void setItemNavigatorHistory( ItemNavigator itemNavigator )
546     {
547         _itemNavigatorHistory = itemNavigator;
548     }
549 
550     /**
551      * Get the history item navigator
552      * 
553      * @return The history item navigator
554      */
555     public ItemNavigator getItemNavigatorHistory( )
556     {
557         return _itemNavigatorHistory;
558     }
559 
560     /**
561      * Set the redirect url
562      * 
563      * @param request
564      *            The request
565      */
566     public void setRedirectUrl( HttpServletRequest request )
567     {
568         String strNextUrl = request.getRequestURI( );
569         UrlItem url = new UrlItem( strNextUrl );
570         Enumeration enumParams = request.getParameterNames( );
571 
572         while ( enumParams.hasMoreElements( ) )
573         {
574             String strParamName = (String) enumParams.nextElement( );
575             url.addParameter( strParamName, request.getParameter( strParamName ) );
576         }
577 
578         _strRedirectUrl = url.getUrl( );
579     }
580 
581     /**
582      * Get the redirect url
583      * 
584      * @return the redirect url
585      */
586     public String getRedirectUrl( )
587     {
588         return _strRedirectUrl;
589     }
590 
591     /**
592      * {@inheritDoc}
593      */
594     @Override
595     public String getDefaultIdSortEntry( Directory directory )
596     {
597         return directory.getIdSortEntry( );
598     }
599 
600     /**
601      * {@inheritDoc}
602      */
603     @Override
604     public boolean isDefaultAscendingSort( Directory directory )
605     {
606         return directory.isAscendingSort( );
607     }
608 }