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.business;
35  
36  import fr.paris.lutece.util.ReferenceList;
37  
38  import java.sql.Timestamp;
39  
40  import java.util.List;
41  
42  /**
43   *
44   * class RecordFieldFilter
45   *
46   */
47  public class RecordFieldFilter
48  {
49      public static final int ALL_INT = -1;
50      public static final int FILTER_FALSE = 0;
51      public static final int FILTER_TRUE = 1;
52      public static final int ORDER_NONE = -1;
53      public static final int ORDER_ASC = 0;
54      public static final int ORDER_DESC = 1;
55      private int _nIdDirectory = ALL_INT;
56      private int _nIdRecord = ALL_INT;
57      private int _nIdField = ALL_INT;
58      private int _nIdEntry = ALL_INT;
59      private Timestamp _tDateFirst;
60      private Timestamp _tDateLast;
61      private int _nIsEntryShownInResultList = ALL_INT;
62      private int _nIsEntryShownInResultRecord = ALL_INT;
63      private int _nIsDisabled = ALL_INT;
64      private ReferenceList _workgroupKeyList;
65      private List<String> _roleKeyList;
66      private boolean _bIncludeRoleNull;
67      private IEntry _sortEntry;
68      private int _nSortOrder = ORDER_NONE;
69      private boolean _bOrderByDateModification = false;
70      private boolean _bContainsFile = false;
71  
72      /**
73       * Gets the entry that should be used to sort the results
74       * 
75       * @return the entry that should be used to sort the results
76       */
77      public IEntry getSortEntry( )
78      {
79          return _sortEntry;
80      }
81  
82      /**
83       * Set the entry that should be used to sort the results
84       * 
85       * @param sortEntry
86       *            the entry to use to sort the results, <code>null</code> to use default sort (creation date).
87       */
88      public void setSortEntry( IEntry sortEntry )
89      {
90          this._sortEntry = sortEntry;
91      }
92  
93      /**
94       * <code>true</code> if an entry should be used to sort the results, <code>false</code> otherwise
95       * 
96       * @return <code>true</code> if an entry should be used to sort the results, <code>false</code> otherwise.
97       */
98      public boolean containsSortEntry( )
99      {
100         return _sortEntry != null;
101     }
102 
103     /**
104      * Gets the sort order. Default is {@link #ORDER_NONE}
105      * 
106      * @return the sort order
107      * @see #ORDER_ASC
108      * @see #ORDER_DESC
109      * @see #ORDER_NONE
110      */
111     public int getSortOrder( )
112     {
113         return _nSortOrder;
114     }
115 
116     /**
117      * Sets the sort order. Use it with {@link #setSortEntry(IEntry)}
118      * 
119      * @param nSortOrder
120      *            the sort order.
121      * @see #ORDER_ASC
122      * @see #ORDER_DESC
123      * @see #ORDER_NONE
124      */
125     public void setSortOrder( int nSortOrder )
126     {
127         this._nSortOrder = nSortOrder;
128     }
129 
130     /**
131      * Return <code>true</code> if sort order is not {@link #ORDER_NONE}
132      * 
133      * @return <code>true</code> if sort order is not {@link #ORDER_NONE}, <code>false</code> otherwise.
134      */
135     public boolean containsSortOrder( )
136     {
137         return this._nSortOrder != ORDER_NONE;
138     }
139 
140     /**
141      *
142      * @return the id of directory insert in the filter
143      */
144     public int getIdDirectory( )
145     {
146         return _nIdDirectory;
147     }
148 
149     /**
150      * set the id of directory in the filter
151      * 
152      * @param idDirectory
153      *            the id of directory to insert in the filter
154      */
155     public void setIdDirectory( int idDirectory )
156     {
157         _nIdDirectory = idDirectory;
158     }
159 
160     /**
161      *
162      * @return true if the filter contain an id of directory
163      *
164      */
165     public boolean containsIdDirectory( )
166     {
167         return ( _nIdDirectory != ALL_INT );
168     }
169 
170     /**
171      *
172      * @return the id of record insert in the filter
173      */
174     public int getIdRecord( )
175     {
176         return _nIdRecord;
177     }
178 
179     /**
180      * set the id of record in the filter
181      * 
182      * @param idRecord
183      *            the id of the record to insert in the filter
184      */
185     public void setIdRecord( int idRecord )
186     {
187         _nIdRecord = idRecord;
188     }
189 
190     /**
191      *
192      * @return true if the filter contain an id of record
193      *
194      */
195     public boolean containsIdRecord( )
196     {
197         return ( _nIdRecord != ALL_INT );
198     }
199 
200     /**
201      *
202      * @return the id of field insert in the filter
203      */
204     public int getIdField( )
205     {
206         return _nIdField;
207     }
208 
209     /**
210      * set the id of field depend in the filter
211      * 
212      * @param idField
213      *            the id of field depend to insert in the filter
214      */
215     public void setIdField( int idField )
216     {
217         _nIdField = idField;
218     }
219 
220     /**
221      *
222      * @return true if the filter contain an id of field depend
223      */
224     public boolean containsIdField( )
225     {
226         return ( _nIdField != ALL_INT );
227     }
228 
229     /**
230      *
231      * @return the id of entry insert in the filter
232      */
233     public int getIdEntry( )
234     {
235         return _nIdEntry;
236     }
237 
238     /**
239      * set the id of entry depend in the filter
240      * 
241      * @param idEntry
242      *            the id of entry depend to insert in the filter
243      */
244     public void setIdEntry( int idEntry )
245     {
246         _nIdEntry = idEntry;
247     }
248 
249     /**
250      *
251      * @return true if the filter contain an id of entry depend
252      */
253     public boolean containsIdEntry( )
254     {
255         return ( _nIdEntry != ALL_INT );
256     }
257 
258     /**
259      *
260      * @return date of the first submit
261      */
262     public Timestamp getDateFirst( )
263     {
264         return _tDateFirst;
265     }
266 
267     /**
268      * set the date of the first submit
269      * 
270      * @param begin
271      *            date of the first submit
272      */
273     public void setDateFirst( Timestamp begin )
274     {
275         _tDateFirst = begin;
276     }
277 
278     /**
279      *
280      * @return true if the filter contain the date of the first submit
281      */
282     public boolean containsDateFirst( )
283     {
284         return ( _tDateFirst != null );
285     }
286 
287     /**
288      *
289      * @return date of the last submit
290      */
291     public Timestamp getDateLast( )
292     {
293         return _tDateLast;
294     }
295 
296     /**
297      * set the date of the last submit
298      * 
299      * @param end
300      *            the date of the last submit
301      */
302     public void setDateLast( Timestamp end )
303     {
304         _tDateLast = end;
305     }
306 
307     /**
308      *
309      * @return true if the filter contain the date of the last submit
310      */
311     public boolean containsDateLast( )
312     {
313         return ( _tDateLast != null );
314     }
315 
316     /**
317      *
318      * @return 1 if the entry associate to the record field must be in the result list, O if the entry associate to the record field must not be in the result
319      *         list
320      */
321     public int getIsEntryShownInResultList( )
322     {
323         return _nIsEntryShownInResultList;
324     }
325 
326     /**
327      * set 1 if the entry associate to the record field must be in the result list, O if the entry associate to the record field must not be in the result list
328      * 
329      * @param nIsShown
330      *            1 if the entry associate to the record field must be in the result list
331      */
332     public void setIsEntryShownInResultList( int nIsShown )
333     {
334         _nIsEntryShownInResultList = nIsShown;
335     }
336 
337     /**
338      *
339      * @return true if the filter is initialized
340      */
341     public boolean containsIsEntryShownInResultList( )
342     {
343         return ( _nIsEntryShownInResultList != ALL_INT );
344     }
345 
346     /**
347      *
348      * @return 1 if the entry associate to the record field must be in the result record, O if the entry associate to the record field must not be in the result
349      *         record
350      */
351     public int getIsEntryShownInResultRecord( )
352     {
353         return _nIsEntryShownInResultRecord;
354     }
355 
356     /**
357      * set 1 if the entry associate to the record field must be in the result record, O if the entry associate to the record field must not be in the result
358      * record
359      * 
360      * @param nIsShown
361      *            1 if the entry associate to the record field must be in the result record
362      */
363     public void setIsEntryShownInResultRecord( int nIsShown )
364     {
365         _nIsEntryShownInResultRecord = nIsShown;
366     }
367 
368     /**
369      *
370      * @return true if the filter is initialized
371      */
372     public boolean containsIsEntryShownInResultRecord( )
373     {
374         return ( _nIsEntryShownInResultRecord != ALL_INT );
375     }
376 
377     /**
378      *
379      * @return 1 if the record return must be enabled 0 if the record return must be disabled
380      */
381     public int getIsDisabled( )
382     {
383         return _nIsDisabled;
384     }
385 
386     /**
387      * Set 1 if the recors return must be enabled 0 if the record return must be disabled
388      * 
389      * @param idState
390      *            1 if the record return must be enabled 0 if the record return must be disabled
391      */
392     public void setIsDisabled( int idState )
393     {
394         _nIsDisabled = idState;
395     }
396 
397     /**
398      *
399      * @return true if the filter contain form state
400      */
401     public boolean containsIsDisabled( )
402     {
403         return ( _nIsDisabled != ALL_INT );
404     }
405 
406     /**
407      * The workgroup key list to set
408      * 
409      * @param workgroupKeyList
410      *            The workgroup key list
411      */
412     public void setWorkgroupKeyList( ReferenceList workgroupKeyList )
413     {
414         this._workgroupKeyList = workgroupKeyList;
415     }
416 
417     /**
418      * Set the role key list
419      * 
420      * @param roleKeyList
421      *            The role key list
422      * @param bIncludeRoleNone
423      *            include role set to "none"
424      * @param bIncludeRoleNull
425      *            include role set to "null"
426      */
427     public void setRoleKeyList( List<String> roleKeyList, boolean bIncludeRoleNone, boolean bIncludeRoleNull )
428     {
429         this._roleKeyList = roleKeyList;
430 
431         if ( bIncludeRoleNone )
432         {
433             roleKeyList.add( Directory.ROLE_NONE );
434         }
435 
436         this._bIncludeRoleNull = bIncludeRoleNull;
437     }
438 
439     /**
440      * Test if the filter contains at least one role key
441      * 
442      * @return true if the filter contain role key list
443      */
444     public boolean containsRoleKeyList( )
445     {
446         return ( ( _roleKeyList != null ) && ( _roleKeyList.size( ) > 0 ) );
447     }
448 
449     /**
450      * Get the role key list
451      * 
452      * @return the role key list
453      */
454     public List<String> getRoleKeyList( )
455     {
456         return _roleKeyList;
457     }
458 
459     /**
460      * @return the _bIncludeRoleNull
461      */
462     public boolean includeRoleNull( )
463     {
464         return _bIncludeRoleNull;
465     }
466 
467     /**
468      * Get workgroup key list
469      * 
470      * @return The workgroup key list
471      */
472     public ReferenceList getWorkgroupKeyList( )
473     {
474         return _workgroupKeyList;
475     }
476 
477     /**
478      *
479      * @return true if the filter contain workgroup key list
480      */
481     public boolean containsWorkgroupKeyList( )
482     {
483         return ( ( _workgroupKeyList != null ) && ( _workgroupKeyList.size( ) != 0 ) );
484     }
485 
486     /**
487      * Set order by date modification
488      * 
489      * @param bOrderByDateModification
490      *            true if filter by date modification
491      */
492     public void setOrderByDateModification( boolean bOrderByDateModification )
493     {
494         _bOrderByDateModification = bOrderByDateModification;
495     }
496 
497     /**
498      * Order by date modification
499      * 
500      * @return order by date modification
501      */
502     public boolean isOrderByDateModification( )
503     {
504         return _bOrderByDateModification;
505     }
506 
507     /**
508      * Get the contains file boolean
509      * 
510      * @return true if filter by containing of file
511      */
512     public boolean containsFile( )
513     {
514         return _bContainsFile;
515     }
516 
517     /**
518      * Set the contains file boolean
519      * 
520      * @param bContainsFile
521      *            the contains file boolean
522      */
523     public void setContainsFile( boolean bContainsFile )
524     {
525         _bContainsFile = bContainsFile;
526     }
527 
528 }