View Javadoc

1   /*
2    * Copyright (c) 2002-2014, 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.digglike.business;
35  
36  import java.sql.Timestamp;
37  import java.util.ArrayList;
38  import java.util.List;
39  
40  import org.apache.commons.lang.StringUtils;
41  
42  
43  /**
44   * 
45   * class SubmiFilter
46   * 
47   */
48  public class SubmitFilter
49  {
50      public static final int SORT_BY_DATE_RESPONSE_ASC = 0;
51      public static final int SORT_BY_DATE_RESPONSE_DESC = 1;
52      public static final int SORT_BY_SCORE_ASC = 2;
53      public static final int SORT_BY_SCORE_DESC = 3;
54      public static final int SORT_BY_NUMBER_COMMENT_ASC = 4;
55      public static final int SORT_BY_NUMBER_COMMENT_DESC = 5;
56      public static final int SORT_BY_NUMBER_VOTE_ASC = 6;
57      public static final int SORT_BY_NUMBER_VOTE_DESC = 7;
58      public static final int SORT_MANUALLY = 8;
59      public static final int SORT_BY_NUMBER_VIEW_ASC = 9;
60      public static final int SORT_BY_NUMBER_VIEW_DESC = 10;
61      public static final int SORT_BY_DATE_MODIFY_ASC = 11;
62      public static final int SORT_BY_DATE_MODIFY_DESC = 12;
63      public static final int SORT_BY_PINNED_FIRST = 13;
64      public static final int ALL_INT = -1;
65      public static final int ID_TRUE = 1;
66      public static final int ID_FALSE = 0;
67      public static final int ID_ASC = 1;
68      public static final int ID_DESC = 0;
69      public static final int ID_PARENT_NULL = 0;
70      private int _nNumberVote = ALL_INT;
71      private int _nIdDigg = ALL_INT;
72      private int _nIdDiggSubmit = ALL_INT;
73      private int _nIdEntry = ALL_INT;
74      private int _nIdCategory = ALL_INT;
75      private int _nIdType = ALL_INT;
76      private int _nIdParent = ALL_INT;
77      private int _nIdReported = ALL_INT;
78      private Timestamp _tDateFirst;
79      private Timestamp _tDateLast;
80      private int _nIdDiggSubmitState = ALL_INT;
81      private int _nIdCommentSubmitState = ALL_INT;
82      private int _nIdPinned = ALL_INT;
83      private int _nIdContainsCommentDisable = ALL_INT;
84      private String _strLuteceUserKey = null;
85      private List<Integer> _listSortBy = new ArrayList<Integer>( );
86  
87      /**
88       * 
89       * @return the id of the digg insert in the filter
90       */
91      public int getIdDigg( )
92      {
93          return _nIdDigg;
94      }
95  
96      /**
97       * set the id of the digg in the filter
98       * @param nIdDigg the id of digg to insert in the filter
99       */
100     public void setIdDigg( int nIdDigg )
101     {
102         _nIdDigg = nIdDigg;
103     }
104 
105     /**
106      * 
107      * @return true if the filter contain an id of digg
108      */
109     public boolean containsIdDigg( )
110     {
111         return ( _nIdDigg != ALL_INT );
112     }
113 
114     /**
115      * 
116      * @return the digg submit state
117      * 
118      * */
119     public int getIdDiggSubmitState( )
120     {
121         return _nIdDiggSubmitState;
122     }
123 
124     /**
125      * Set the digg submit state
126      * @param idState the digg submit state
127      */
128     public void setIdDiggSubmitState( int idState )
129     {
130         _nIdDiggSubmitState = idState;
131     }
132 
133     /**
134      * 
135      * @return true if the filter contain the digg submit state
136      */
137     public boolean containsIdDiggSubmitState( )
138     {
139         return ( _nIdDiggSubmitState != ALL_INT );
140     }
141 
142     /**
143      * 
144      * @return the comment submit state
145      * 
146      * */
147     public int getIdCommentSubmitState( )
148     {
149         return _nIdCommentSubmitState;
150     }
151 
152     /**
153      * Set the comment submit state
154      * @param nIdState the comment submit state
155      */
156     public void setIdCommentSubmitState( int nIdState )
157     {
158         _nIdCommentSubmitState = nIdState;
159     }
160 
161     /**
162      * 
163      * @return true if the filter contain the comment submit state
164      */
165     public boolean containsIdCommentSubmitState( )
166     {
167         return ( _nIdCommentSubmitState != ALL_INT );
168     }
169 
170     /**
171      * 
172      * @return the id of the digg submit insert in the filter
173      */
174     public int getIdDiggSubmit( )
175     {
176         return _nIdDiggSubmit;
177     }
178 
179     /**
180      * set the id of the digg submit in the filter
181      * @param nIdDiggSubmit the id of digg submit to insert in the filter
182      */
183     public void setIdDiggSubmit( int nIdDiggSubmit )
184     {
185         _nIdDiggSubmit = nIdDiggSubmit;
186     }
187 
188     /**
189      * 
190      * @return true if the filter contain an id of digg
191      */
192     public boolean containsIdDiggSubmit( )
193     {
194         return ( _nIdDiggSubmit != ALL_INT );
195     }
196 
197     /**
198      * 
199      * @return the id of entry insert in the filter
200      */
201     public int getIdEntry( )
202     {
203         return _nIdEntry;
204     }
205 
206     /**
207      * set the id of entry depend in the filter
208      * @param nIdEntry the id of entry depend to insert in the filter
209      */
210     public void setIdEntry( int nIdEntry )
211     {
212         _nIdEntry = nIdEntry;
213     }
214 
215     /**
216      * 
217      * @return true if the filter contain an id of entry depend
218      */
219     public boolean containsIdEntry( )
220     {
221         return ( _nIdEntry != ALL_INT );
222     }
223 
224     /**
225      * 
226      * @return date of the first submit
227      */
228     public Timestamp getDateFirst( )
229     {
230         return _tDateFirst;
231     }
232 
233     /**
234      * set the date of the first submit
235      * @param begin date of the first submit
236      */
237     public void setDateFirst( Timestamp begin )
238     {
239         _tDateFirst = begin;
240     }
241 
242     /**
243      * 
244      * @return true if the filter contain the date of the first submit
245      */
246     public boolean containsDateFirst( )
247     {
248         return ( _tDateFirst != null );
249     }
250 
251     /**
252      * 
253      * @return date of the last submit
254      */
255     public Timestamp getDateLast( )
256     {
257         return _tDateLast;
258     }
259 
260     /**
261      * set the date of the last submit
262      * @param end the date of the last submit
263      */
264     public void setDateLast( Timestamp end )
265     {
266         _tDateLast = end;
267     }
268 
269     /**
270      * 
271      * @return true if the filter contain the date of the last submit
272      */
273     public boolean containsDateLast( )
274     {
275         return ( _tDateLast != null );
276     }
277 
278     /**
279      * return the list of sort
280      * @return the list of sort
281      */
282     public List<Integer> getSortBy( )
283     {
284         return _listSortBy;
285     }
286 
287     /**
288      * set the list of sort
289      * @param listSortBy the list of sort
290      */
291     public void setSortBy( List<Integer> listSortBy )
292     {
293         _listSortBy = listSortBy;
294     }
295 
296     /**
297      * 
298      * @return true if the filter contain the list of sort
299      */
300     public boolean containsSortBy( )
301     {
302         return ( ( _listSortBy != null ) && ( _listSortBy.size( ) != 0 ) );
303     }
304 
305     /**
306      * @param nSort The sort
307      * @return true if the filter contain the sort
308      */
309     public boolean containsSortBy( Integer nSort )
310     {
311         if ( ( nSort != null ) && ( _listSortBy != null ) && ( _listSortBy.size( ) != 0 ) )
312         {
313             for ( Integer nSortBy : _listSortBy )
314             {
315                 if ( nSortBy.equals( nSort ) )
316                 {
317                     return true;
318                 }
319             }
320         }
321 
322         return false;
323     }
324 
325     /**
326      * convert a int to a boolean
327      * @param nIdBoolean the id to convert
328      * @return boolean
329      */
330     public boolean convertIdBoolean( int nIdBoolean )
331     {
332         if ( nIdBoolean == ID_TRUE )
333         {
334             return true;
335         }
336 
337         return false;
338     }
339 
340     /**
341      * 
342      * @return the id of the category insert in the filter
343      */
344     public int getIdCategory( )
345     {
346         return _nIdCategory;
347     }
348 
349     /**
350      * set the id of the category in the filter
351      * @param nIdCategory the id of the category to insert in the filter
352      */
353     public void setIdCategory( int nIdCategory )
354     {
355         _nIdCategory = nIdCategory;
356     }
357 
358     /**
359      * 
360      * @return true if the filter contain an id of category
361      */
362     public boolean containsIdCategory( )
363     {
364         return ( _nIdCategory != ALL_INT );
365     }
366 
367     /**
368      * 
369      * @return 1 if the diggs return must be reported
370      *         0 if the diggs return must not be reported
371      */
372     public int getIdReported( )
373     {
374         return _nIdReported;
375     }
376 
377     /**
378      * set 1 if the diggs return must be reported
379      * 0 if the diggs return must not be reported
380      * @param nIdReported idReported
381      */
382     public void setIdReported( int nIdReported )
383     {
384         _nIdReported = nIdReported;
385     }
386 
387     /**
388      * 
389      * @return true if the filter contain reported
390      */
391     public boolean containsIdReported( )
392     {
393         return ( _nIdReported != ALL_INT );
394     }
395 
396     /**
397      * 
398      * @return the number of vote in the filter
399      */
400     public int getNumberVote( )
401     {
402         return _nNumberVote;
403     }
404 
405     /**
406      * set the number of vote in the filter
407      * @param nNumberVote the number of vote
408      */
409     public void setNumberVote( int nNumberVote )
410     {
411         _nNumberVote = nNumberVote;
412     }
413 
414     /**
415      * 
416      * @return true if the filter contain a number of vote
417      */
418     public boolean containsNumberVote( )
419     {
420         return ( _nNumberVote != ALL_INT );
421     }
422 
423     /**
424      * @param strLuteceUserKey the _strLuteceUserKey to set
425      */
426     public void setLuteceUserKey( String strLuteceUserKey )
427     {
428         this._strLuteceUserKey = strLuteceUserKey;
429     }
430 
431     /**
432      * @return the _strLuteceUserKey
433      */
434     public String getLuteceUserKey( )
435     {
436         return _strLuteceUserKey;
437     }
438 
439     /**
440      * 
441      * @return true if the filter contain a number of vote
442      */
443     public boolean containsLuteceUserKey( )
444     {
445         return ( !StringUtils.isEmpty( _strLuteceUserKey) );
446     }
447 
448     /**
449      * 
450      * @return the id of the digg insert in the filter
451      */
452     public int getIdParent( )
453     {
454         return _nIdParent;
455     }
456 
457     /**
458      * set the id of the digg in the filter
459      * @param nIdParent the id of digg to insert in the filter
460      */
461     public void setIdParent( int nIdParent )
462     {
463         _nIdParent = nIdParent;
464     }
465 
466     /**
467      * 
468      * @return true if the filter contain an id of digg
469      */
470     public boolean containsIdParent( )
471     {
472         return ( _nIdParent != ALL_INT );
473     }
474 
475     /**
476      * 
477      * @return 1 if the diggs return must be reported
478      *         0 if the diggss return must not be reported
479      */
480     public int getIdPinned( )
481     {
482         return _nIdPinned;
483     }
484 
485     /**
486      * set 1 if the diggsubmit return must be pinned
487      * 0 if the diggsubmit return must not be pinned
488      * @param nIdPinned idPinned
489      */
490     public void setIdPinned( int nIdPinned )
491     {
492         _nIdPinned = nIdPinned;
493     }
494 
495     /**
496      * 
497      * @return true if the filter contain reported
498      */
499     public boolean containsIdPinned( )
500     {
501         return ( _nIdPinned != ALL_INT );
502     }
503 
504     /**
505      * 
506      * @return the id of the type insert in the filter
507      */
508     public int getIdType( )
509     {
510         return _nIdType;
511     }
512 
513     /**
514      * set the id of the type in the filter
515      * @param nIdType the id of the type to insert in the filter
516      */
517     public void setIdType( int nIdType )
518     {
519         _nIdType = nIdType;
520     }
521 
522     /**
523      * 
524      * @return true if the filter contain an id of type
525      */
526     public boolean containsIdType( )
527     {
528         return ( _nIdType != ALL_INT );
529     }
530 
531     /**
532      * 
533      * @return 1 if the diggsubmit return must contains comment disable
534      *         0 if the diggsubmit return must not contains comment disable
535      */
536     public int getIdContainsCommentDisable( )
537     {
538         return _nIdContainsCommentDisable;
539     }
540 
541     /**
542      * 
543      * @param nIdContainsCommentDisable 1 if the diggsubmit return must
544      *            contains comment disable 0 if the diggsubmit return must not
545      *            contains comment disable
546      */
547     public void setIdContainsCommentDisable( int nIdContainsCommentDisable )
548     {
549         this._nIdContainsCommentDisable = nIdContainsCommentDisable;
550     }
551 
552     /**
553      * 
554      * @return true if the filter contains Id comment Disable
555      */
556     public boolean containsIdContainsCommentDisable( )
557     {
558         return ( _nIdContainsCommentDisable != ALL_INT );
559     }
560 }