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.plugins.directory.business.EntryHome;
38  import fr.paris.lutece.plugins.directory.business.IEntry;
39  import fr.paris.lutece.plugins.directory.business.RecordField;
40  import fr.paris.lutece.plugins.directory.business.RecordFieldFilter;
41  import fr.paris.lutece.plugins.directory.utils.DirectoryUtils;
42  import fr.paris.lutece.portal.service.plugin.Plugin;
43  import fr.paris.lutece.portal.service.util.AppPropertiesService;
44  import fr.paris.lutece.portal.web.constants.Parameters;
45  
46  import java.io.Serializable;
47  
48  import java.util.Date;
49  import java.util.HashMap;
50  import java.util.List;
51  
52  import javax.servlet.http.HttpServletRequest;
53  
54  /**
55   * DefaultDirectorySearchFields
56   */
57  public abstract class DefaultDirectorySearchFields implements IDirectorySearchFields, Serializable
58  {
59      public static final int ALL_INT = -1;
60  
61      /**
62       * Generated serial version UID
63       */
64      private static final long serialVersionUID = -2839610597359957115L;
65      private static final String PROPERTY_ITEM_PER_PAGE = "directory.itemsPerPage";
66      private int _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_ITEM_PER_PAGE, 50 );
67      private int _nItemsPerPage;
68      private int _nIdDirectory = ALL_INT;
69      private int _nIdEntry = ALL_INT;
70      private int _nIsDisabled = ALL_INT;
71      private HashMap<String, List<RecordField>> _mapQuery;
72      private Date _dateCreationBeginRecord;
73      private Date _dateCreationEndRecord;
74      private Date _dateCreationRecord;
75      private Date _dateModificationBeginRecord;
76      private Date _dateModificationEndRecord;
77      private Date _dateModificationRecord;
78      private boolean _bIsSortByDateModification;
79      private IEntry _sortEntry;
80      private int _nSortOrder = RecordFieldFilter.ORDER_NONE;
81      private String _strCurrentPageIndex;
82  
83      /*
84       * (non-Javadoc)
85       * 
86       * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# getCurrentPageIndex()
87       */
88      public String getCurrentPageIndex( )
89      {
90          return _strCurrentPageIndex;
91      }
92  
93      /*
94       * (non-Javadoc)
95       * 
96       * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# getDateCreationBeginRecord()
97       */
98      public Date getDateCreationBeginRecord( )
99      {
100         return _dateCreationBeginRecord;
101     }
102 
103     /*
104      * (non-Javadoc)
105      * 
106      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# getDateCreationEndRecord()
107      */
108     public Date getDateCreationEndRecord( )
109     {
110         return _dateCreationEndRecord;
111     }
112 
113     /*
114      * (non-Javadoc)
115      * 
116      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# getDateCreationRecord()
117      */
118     public Date getDateCreationRecord( )
119     {
120         return _dateCreationRecord;
121     }
122 
123     /*
124      * (non-Javadoc)
125      * 
126      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# getDefaultItemsPerPage()
127      */
128     public int getDefaultItemsPerPage( )
129     {
130         return _nDefaultItemsPerPage;
131     }
132 
133     /*
134      * (non-Javadoc)
135      * 
136      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# getIdDirectory()
137      */
138     public int getIdDirectory( )
139     {
140         return _nIdDirectory;
141     }
142 
143     /*
144      * (non-Javadoc)
145      * 
146      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# getIdEntry()
147      */
148     public int getIdEntry( )
149     {
150         return _nIdEntry;
151     }
152 
153     /*
154      * (non-Javadoc)
155      * 
156      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# getMapQuery()
157      */
158     public HashMap<String, List<RecordField>> getMapQuery( )
159     {
160         return _mapQuery;
161     }
162 
163     /*
164      * (non-Javadoc)
165      * 
166      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# getSortEntry()
167      */
168     public IEntry getSortEntry( )
169     {
170         return _sortEntry;
171     }
172 
173     /*
174      * (non-Javadoc)
175      * 
176      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# getSortOrder()
177      */
178     public int getSortOrder( )
179     {
180         return _nSortOrder;
181     }
182 
183     /*
184      * (non-Javadoc)
185      * 
186      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# setCurrentPageIndex(java.lang.String)
187      */
188     public void setCurrentPageIndex( String strCurrentPageIndex )
189     {
190         _strCurrentPageIndex = strCurrentPageIndex;
191     }
192 
193     /*
194      * (non-Javadoc)
195      * 
196      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# setDateCreationBeginRecord(java.util.Date)
197      */
198     public void setDateCreationBeginRecord( Date dateCreationBeginRecord )
199     {
200         _dateCreationBeginRecord = dateCreationBeginRecord;
201     }
202 
203     /*
204      * (non-Javadoc)
205      * 
206      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# setDateCreationEndRecord(java.util.Date)
207      */
208     public void setDateCreationEndRecord( Date dateCreationEndRecord )
209     {
210         _dateCreationEndRecord = dateCreationEndRecord;
211     }
212 
213     /*
214      * (non-Javadoc)
215      * 
216      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# setDateCreationRecord(java.util.Date)
217      */
218     public void setDateCreationRecord( Date dateCreationRecord )
219     {
220         _dateCreationRecord = dateCreationRecord;
221     }
222 
223     /*
224      * (non-Javadoc)
225      * 
226      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# setDefaultItemsPerPage(int)
227      */
228     public void setDefaultItemsPerPage( int nDefaultItemsPerPage )
229     {
230         _nDefaultItemsPerPage = nDefaultItemsPerPage;
231     }
232 
233     /*
234      * (non-Javadoc)
235      * 
236      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# setIdDirectory(int)
237      */
238     public void setIdDirectory( int nIdDirectory )
239     {
240         _nIdDirectory = nIdDirectory;
241     }
242 
243     /*
244      * (non-Javadoc)
245      * 
246      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# setIdEntry(int)
247      */
248     public void setIdEntry( int nIdEntry )
249     {
250         _nIdEntry = nIdEntry;
251     }
252 
253     /*
254      * (non-Javadoc)
255      * 
256      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# setMapQuery(java.util.HashMap)
257      */
258     public void setMapQuery( HashMap<String, List<RecordField>> mapQuery )
259     {
260         _mapQuery = mapQuery;
261     }
262 
263     /*
264      * (non-Javadoc)
265      * 
266      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# setSortEntry(fr.paris.lutece.plugins.directory.business.IEntry)
267      */
268     public void setSortEntry( IEntry sortEntry )
269     {
270         _sortEntry = sortEntry;
271     }
272 
273     /*
274      * (non-Javadoc)
275      * 
276      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# setSortOrder(int)
277      */
278     public void setSortOrder( int nSortOrder )
279     {
280         _nSortOrder = nSortOrder;
281     }
282 
283     /*
284      * (non-Javadoc)
285      * 
286      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# setSortParameters(javax.servlet.http.HttpServletRequest,
287      * fr.paris.lutece.plugins.directory.business.Directory, fr.paris.lutece.portal.service.plugin.Plugin)
288      */
289     public void setSortParameters( HttpServletRequest request, Directory directory, Plugin plugin )
290     {
291         String strSortedAttributeName = request.getParameter( Parameters.SORTED_ATTRIBUTE_NAME );
292         String strAscSort = null;
293 
294         if ( ( strSortedAttributeName != null ) || ( getDefaultIdSortEntry( directory ) != null ) )
295         {
296             if ( strSortedAttributeName == null )
297             {
298                 strSortedAttributeName = getDefaultIdSortEntry( directory );
299             }
300 
301             if ( DirectoryUtils.PARAMETER_DATECREATION.equals( strSortedAttributeName ) )
302             {
303                 // IMPORTANT : date creation is default filter
304             }
305             else
306                 if ( DirectoryUtils.PARAMETER_DATEMODIFICATION.equals( strSortedAttributeName ) )
307                 {
308                     _bIsSortByDateModification = true;
309                 }
310                 else
311                 {
312                     int nSortedEntryId = Integer.parseInt( strSortedAttributeName );
313                     _sortEntry = EntryHome.findByPrimaryKey( nSortedEntryId, plugin );
314                 }
315 
316             strAscSort = request.getParameter( Parameters.SORTED_ASC );
317 
318             boolean bIsAscSort;
319 
320             if ( strAscSort != null )
321             {
322                 bIsAscSort = Boolean.parseBoolean( strAscSort );
323             }
324             else
325             {
326                 bIsAscSort = isDefaultAscendingSort( directory );
327             }
328 
329             if ( bIsAscSort )
330             {
331                 _nSortOrder = RecordFieldFilter.ORDER_ASC;
332             }
333             else
334             {
335                 _nSortOrder = RecordFieldFilter.ORDER_DESC;
336             }
337         }
338     }
339 
340     /*
341      * (non-Javadoc)
342      * 
343      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# getItemsPerPage()
344      */
345     public int getItemsPerPage( )
346     {
347         return _nItemsPerPage;
348     }
349 
350     /*
351      * (non-Javadoc)
352      * 
353      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# setItemsPerPage(int)
354      */
355     public void setItemsPerPage( int nItemsPerPage )
356     {
357         _nItemsPerPage = nItemsPerPage;
358     }
359 
360     /*
361      * (non-Javadoc)
362      * 
363      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# setIsDisabled(int)
364      */
365     public void setIsDisabled( int nIdIsDisabled )
366     {
367         _nIsDisabled = nIdIsDisabled;
368     }
369 
370     /*
371      * (non-Javadoc)
372      * 
373      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# getIsDisabled()
374      */
375     public int getIsDisabled( )
376     {
377         return _nIsDisabled;
378     }
379 
380     /*
381      * (non-Javadoc)
382      * 
383      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# getDefaultIdSortEntry (fr.paris.lutece.plugins.directory.business.Directory)
384      */
385     public abstract String getDefaultIdSortEntry( Directory directory );
386 
387     /*
388      * (non-Javadoc)
389      * 
390      * @see fr.paris.lutece.plugins.directory.web.action.IDirectorySearchFields# isDefaultAscendingSort (fr.paris.lutece.plugins.directory.business.Directory)
391      */
392     public abstract boolean isDefaultAscendingSort( Directory directory );
393 
394     /**
395      * {@inheritDoc}
396      */
397     public void setDateModificationBeginRecord( Date dateModificationBeginRecord )
398     {
399         _dateModificationBeginRecord = dateModificationBeginRecord;
400     }
401 
402     /**
403      * {@inheritDoc}
404      */
405     public Date getDateModificationBeginRecord( )
406     {
407         return _dateModificationBeginRecord;
408     }
409 
410     /**
411      * {@inheritDoc}
412      */
413     public void setDateModificationEndRecord( Date dateModificationEndRecord )
414     {
415         _dateModificationEndRecord = dateModificationEndRecord;
416     }
417 
418     /**
419      * {@inheritDoc}
420      */
421     public Date getDateModificationEndRecord( )
422     {
423         return _dateModificationEndRecord;
424     }
425 
426     /**
427      * {@inheritDoc}
428      */
429     public void setDateModificationRecord( Date dateModificationRecord )
430     {
431         _dateModificationRecord = dateModificationRecord;
432     }
433 
434     /**
435      * {@inheritDoc}
436      */
437     public Date getDateModificationRecord( )
438     {
439         return _dateModificationRecord;
440     }
441 
442     /**
443      * {@inheritDoc}
444      */
445     public void setSortByDateModification( boolean bIsSortByDateModification )
446     {
447         _bIsSortByDateModification = bIsSortByDateModification;
448     }
449 
450     /**
451      * {@inheritDoc}
452      */
453     public boolean isSortByDateModification( )
454     {
455         return _bIsSortByDateModification;
456     }
457 }