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 fr.paris.lutece.plugins.digglike.utils.DiggUtils;
37  import fr.paris.lutece.portal.service.resource.IExtendableResource;
38  import fr.paris.lutece.util.date.DateUtil;
39  import fr.paris.lutece.util.xml.XmlUtil;
40  
41  import java.sql.Timestamp;
42  import java.util.HashMap;
43  import java.util.List;
44  import java.util.Locale;
45  
46  import javax.servlet.http.HttpServletRequest;
47  
48  
49  /**
50   * 
51   * class DiggSubmit
52   * 
53   */
54  public class DiggSubmit implements IExtendableResource
55  {
56      public static final String RESOURCE_TYPE = "DIGGLIKE_DIGG_SUBMIT_TYPE";
57      public static final int STATE_DISABLE = 1;
58      public static final int STATE_WAITING_FOR_PUBLISH = 2;
59      public static final int STATE_PUBLISH = 3;
60      private static final String TAG_DIGG_SUBMIT = "digg-submit";
61      private static final String TAG_DIGG_SUBMIT_TITLE = "digg-submit-title";
62      private static final String TAG_DIGG_SUBMIT_CATEGORY = "digg-submit-category";
63      private static final String TAG_DIGG_SUBMIT_TYPE = "digg-submit-type";
64      private static final String TAG_DIGG_SUBMIT_DATE_RESPONSE = "digg-submit-date-response";
65      private static final String TAG_DIGG_SUBMIT_NUMBER_VOTE = "digg-submit-number-vote";
66      private static final String TAG_DIGG_SUBMIT_NUMBER_COMMENT = "digg-submit-number-comment";
67      private static final String TAG_DIGG_SUBMIT_SCORE = "digg-submit-score";
68      private static final String TAG_DIGGS_SUBMIT_COMMENTS = "digg-submit-comments";
69      private static final String TAG_DIGGS_SUBMIT_RESPONSES = "digg-submit-responses";
70      private int _nIdDiggSubmit;
71      private Timestamp _tDateResponse;
72      private Digg _digg;
73      private DiggSubmitState _diggSubmitState;
74      private List<Response> _listResponse;
75      private Category _category;
76      private int _nNumberVote;
77      private int _nNumberScore;
78      private int _nNumberEnableComment;
79      private int _nNumberComment;
80      private int _nNumberView;
81      private String _strDiggSubmitValue;
82      private String _strDiggSubmitTitle;
83      private String _strDiggSubmitValueShowInTheList;
84      private boolean _bReported;
85      private String _strLuteceUserKey;
86      private List<CommentSubmit> _listComments;
87      private int _nDiggSubmitOrder;
88      private DiggSubmitType _diggSubmitType;
89      private boolean _bDisableVote;
90      private boolean _bDisableComment;
91      private boolean _bPinned;
92      private List<ReportedMessage> _listReportedMessages;
93      private Integer _nIdImageResource;
94  
95      /**
96       * true if the digg submit have been reported by people
97       * @return true if the digg submit have been reported by people
98       */
99      public boolean isReported( )
100     {
101         return _bReported;
102     }
103 
104     /**
105      * set true if the digg submit have been reported by people
106      * @param reported true if the digg submit have been reported by people
107      */
108     public void setReported( boolean reported )
109     {
110         _bReported = reported;
111     }
112 
113     /**
114      * 
115      * @return the title of the digg submit
116      */
117     public String getDiggSubmitTitle( )
118     {
119         return _strDiggSubmitTitle;
120     }
121 
122     /**
123      * set the title of the digg submit
124      * @param diggSubmitTitle the title of the digg submit
125      */
126     public void setDiggSubmitTitle( String diggSubmitTitle )
127     {
128         _strDiggSubmitTitle = diggSubmitTitle;
129     }
130 
131     /**
132      * 
133      * @return the digg associate to the submit
134      */
135     public Digg getDigg( )
136     {
137         return _digg;
138     }
139 
140     /**
141      * 
142      * set the digg associate to the submit
143      * @param digg the digg associate to the submit
144      */
145     public void setDigg( Digg digg )
146     {
147         this._digg = digg;
148     }
149 
150     /**
151      * return the id of the digg submit
152      * @return the id of the digg submit
153      */
154     public int getIdDiggSubmit( )
155     {
156         return _nIdDiggSubmit;
157     }
158 
159     /**
160      * set the id of the digg submit
161      * @param idDiggSubmit the id of the digg submit
162      */
163     public void setIdDiggSubmit( int idDiggSubmit )
164     {
165         _nIdDiggSubmit = idDiggSubmit;
166     }
167 
168     /**
169      * return the digg submit date
170      * @return the digg submit date
171      */
172     public Timestamp getDateResponse( )
173     {
174         return _tDateResponse;
175     }
176 
177     /**
178      * set the digg submit date
179      * @param dateResponse digg submit date
180      */
181     public void setDateResponse( Timestamp dateResponse )
182     {
183         _tDateResponse = dateResponse;
184     }
185 
186     /**
187      * 
188      * @return the list of response associate to the digg submit
189      */
190     public List<Response> getResponses( )
191     {
192         return _listResponse;
193     }
194 
195     /**
196      * set the list of response associate to the digg submit
197      * @param listResponse the list of response associate to the digg submit
198      */
199     public void setResponses( List<Response> listResponse )
200     {
201         _listResponse = listResponse;
202     }
203 
204     /**
205      * 
206      * @return the digg submit state (published,enabled,disabled)
207      */
208     public DiggSubmitState getDiggSubmitState( )
209     {
210         return _diggSubmitState;
211     }
212 
213     /**
214      * set the digg submit state (published,enabled,disabled)
215      * @param submitState the digg submit state (published,enabled,disabled)
216      */
217     public void setDiggSubmitState( DiggSubmitState submitState )
218     {
219         _diggSubmitState = submitState;
220     }
221 
222     /**
223      * 
224      * @return the category associated to the digg submit
225      */
226     public Category getCategory( )
227     {
228         return _category;
229     }
230 
231     /**
232      * set the category associated to the digg submit
233      * @param category the category associated to the digg submit
234      */
235     public void setCategory( Category category )
236     {
237         _category = category;
238     }
239 
240     /**
241      * 
242      * @return the number of vote
243      */
244     public int getNumberVote( )
245     {
246         return _nNumberVote;
247     }
248 
249     /**
250      * set the number of vote
251      * @param numberVote the number of vote
252      */
253     public void setNumberVote( int numberVote )
254     {
255         _nNumberVote = numberVote;
256     }
257 
258     /**
259      * return the score of the digg submit
260      * @return the score of the digg submit
261      */
262     public int getNumberScore( )
263     {
264         return _nNumberScore;
265     }
266 
267     /**
268      * set the score of the digg submit
269      * @param numberScore the score of the digg submit
270      */
271     public void setNumberScore( int numberScore )
272     {
273         _nNumberScore = numberScore;
274     }
275 
276     /**
277      * 
278      * @return the digg submit value
279      */
280     public String getDiggSubmitValue( )
281     {
282         return _strDiggSubmitValue;
283     }
284 
285     /**
286      * set the digg submit value
287      * @param diggSubmitValue the digg submit value
288      */
289     public void setDiggSubmitValue( String diggSubmitValue )
290     {
291         _strDiggSubmitValue = diggSubmitValue;
292     }
293 
294     /**
295      * 
296      * @return the digg submit value show in the list of digg submit
297      */
298     public String getDiggSubmitValueShowInTheList( )
299     {
300         return _strDiggSubmitValueShowInTheList;
301     }
302 
303     /**
304      * set the digg submit value show in the list of digg submit
305      * @param diggSubmitValue the digg submit value show in the list of digg
306      *            submit
307      */
308     public void setDiggSubmitValueShowInTheList( String diggSubmitValue )
309     {
310         _strDiggSubmitValueShowInTheList = diggSubmitValue;
311     }
312 
313     /**
314      * 
315      * @return the number of enable comment associated to the digg submit
316      */
317     public int getNumberCommentEnable( )
318     {
319         return _nNumberEnableComment;
320     }
321 
322     /**
323      * set the number of enable comment associated to the digg submit
324      * @param numberComment the number of enable comment associated to the digg
325      *            submit
326      */
327     public void setNumberCommentEnable( int numberComment )
328     {
329         _nNumberEnableComment = numberComment;
330     }
331 
332     /**
333      * 
334      * @return the number of comment associated to the digg submit
335      */
336     public int getNumberComment( )
337     {
338         return _nNumberComment;
339     }
340 
341     /**
342      * set the number of comment associated to the digg submit
343      * @param numberComment the number of comment associated to the digg submit
344      */
345     public void setNumberComment( int numberComment )
346     {
347         _nNumberComment = numberComment;
348     }
349 
350     /**
351      * 
352      * @return the number of view associated to the digg submit
353      */
354     public int getNumberView( )
355     {
356         return _nNumberView;
357     }
358 
359     /**
360      * set the number of view associated to the digg submit
361      * @param nNumberView the number of view associated to the digg submit
362      */
363     public void setNumberView( int nNumberView )
364     {
365         _nNumberView = nNumberView;
366     }
367 
368     /**
369      * 
370      * @return the lutece user key associate to the digg submit
371      */
372     public String getLuteceUserKey( )
373     {
374         return _strLuteceUserKey;
375     }
376 
377     /**
378      * 
379      * set the lutece user key associate to the digg submit
380      * @param strLuteceUserKey the lutece user key associate to the digg submit
381      */
382     public void setLuteceUserKey( String strLuteceUserKey )
383     {
384         _strLuteceUserKey = strLuteceUserKey;
385     }
386 
387     /**
388      * Returns the xml of this digg submit
389      * 
390      * @param request The HTTP Servlet request
391      * @param locale the Locale
392      * @return the xml of this digg submit
393      */
394     public String getXml( HttpServletRequest request, Locale locale )
395     {
396         StringBuffer strXml = new StringBuffer( );
397         XmlUtil.beginElement( strXml, TAG_DIGG_SUBMIT );
398         XmlUtil.addElementHtml( strXml, TAG_DIGG_SUBMIT_DATE_RESPONSE,
399                 DateUtil.getDateString( this.getDateResponse( ), locale ) );
400         XmlUtil.addElementHtml( strXml, TAG_DIGG_SUBMIT_SCORE, Integer.toString( this.getNumberScore( ) ) );
401         XmlUtil.addElementHtml( strXml, TAG_DIGG_SUBMIT_NUMBER_VOTE, Integer.toString( this.getNumberVote( ) ) );
402         XmlUtil.addElementHtml( strXml, TAG_DIGG_SUBMIT_NUMBER_COMMENT, Integer.toString( this.getNumberComment( ) ) );
403         XmlUtil.addElementHtml( strXml, TAG_DIGG_SUBMIT_CATEGORY, ( this.getCategory( ) != null ) ? this.getCategory( )
404                 .getTitle( ) : DiggUtils.EMPTY_STRING );
405         XmlUtil.addElementHtml( strXml, TAG_DIGG_SUBMIT_TYPE, ( this.getDiggSubmitType( ) != null ) ? this
406                 .getDiggSubmitType( ).getName( ) : DiggUtils.EMPTY_STRING );
407         XmlUtil.addElementHtml( strXml, TAG_DIGG_SUBMIT_TITLE, this.getDiggSubmitTitle( ) );
408 
409         XmlUtil.beginElement( strXml, TAG_DIGGS_SUBMIT_RESPONSES );
410 
411         if ( ( getResponses( ) != null ) && ( getResponses( ).size( ) != 0 ) )
412         {
413             HashMap<Integer, Response> hashResponsesEntry = new HashMap<Integer, Response>( );
414 
415             for ( Response response : getResponses( ) )
416             {
417                 hashResponsesEntry.put( response.getEntry( ).getIdEntry( ), response );
418             }
419 
420             for ( IEntry entry : this.getDigg( ).getEntries( ) )
421             {
422                 if ( hashResponsesEntry.containsKey( entry.getIdEntry( ) ) )
423                 {
424                     strXml.append( hashResponsesEntry.get( entry.getIdEntry( ) ).getXml( request, locale ) );
425                 }
426                 else
427                 {
428                     //add xml empty response for this digg submit
429                     Response responseEmpty = new Response( );
430                     responseEmpty.setEntry( entry );
431                     responseEmpty.setValueResponse( DiggUtils.EMPTY_STRING );
432                     strXml.append( responseEmpty.getXml( request, locale ) );
433                 }
434             }
435         }
436 
437         XmlUtil.endElement( strXml, TAG_DIGGS_SUBMIT_RESPONSES );
438 
439         XmlUtil.beginElement( strXml, TAG_DIGGS_SUBMIT_COMMENTS );
440 
441         if ( ( getComments( ) != null ) && ( getComments( ).size( ) != 0 ) )
442         {
443             for ( CommentSubmit commentSubmit : getComments( ) )
444             {
445                 strXml.append( commentSubmit.getXml( request, locale ) );
446             }
447         }
448 
449         XmlUtil.endElement( strXml, TAG_DIGGS_SUBMIT_COMMENTS );
450 
451         XmlUtil.endElement( strXml, TAG_DIGG_SUBMIT );
452 
453         return strXml.toString( );
454     }
455 
456     /**
457      * @param listComments the _listComments to set
458      */
459     public void setComments( List<CommentSubmit> listComments )
460     {
461         this._listComments = listComments;
462     }
463 
464     /**
465      * @return the _listComments
466      */
467     public List<CommentSubmit> getComments( )
468     {
469         return _listComments;
470     }
471 
472     /**
473      * @param nDiggSubmitOrder the _nDiggSubmitOrder to set
474      */
475     public void setDiggSubmitOrder( int nDiggSubmitOrder )
476     {
477         this._nDiggSubmitOrder = nDiggSubmitOrder;
478     }
479 
480     /**
481      * @return the _nDiggSubmitOrder
482      */
483     public int getDiggSubmitOrder( )
484     {
485         return _nDiggSubmitOrder;
486     }
487 
488     /**
489      * @param diggSubmitType the diggSubmitType to set
490      */
491     public void setDiggSubmitType( DiggSubmitType diggSubmitType )
492     {
493         this._diggSubmitType = diggSubmitType;
494     }
495 
496     /**
497      * @return the diggSubmitType
498      */
499     public DiggSubmitType getDiggSubmitType( )
500     {
501         return _diggSubmitType;
502     }
503 
504     /**
505      * 
506      * @return true if the vote is disable
507      */
508     public boolean isDisableVote( )
509     {
510         return _bDisableVote;
511     }
512 
513     /**
514      * set true if the vote is disable
515      * @param bDisable true if the vote is disable
516      */
517     public void setDisableVote( boolean bDisable )
518     {
519         _bDisableVote = bDisable;
520     }
521 
522     /**
523      * 
524      * @return true if the vote is disable
525      */
526     public boolean isDisableComment( )
527     {
528         return _bDisableComment;
529     }
530 
531     /**
532      * set true if the vote is disable
533      * @param bDisable true if the comment is disable
534      */
535     public void setDisableComment( boolean bDisable )
536     {
537         _bDisableComment = bDisable;
538     }
539 
540     /**
541      * 
542      * @return true if the diggsubmit is pinned
543      */
544     public boolean isPinned( )
545     {
546         return _bPinned;
547     }
548 
549     /**
550      * 
551      * @param bPinned true if the diggsubmit is pinned
552      */
553     public void setPinned( boolean bPinned )
554     {
555         this._bPinned = bPinned;
556     }
557 
558     /**
559      * 
560      * @return the list of reported Messages
561      */
562     public List<ReportedMessage> getReportedMessages( )
563     {
564         return _listReportedMessages;
565     }
566 
567     /**
568      * set the list of reported Messages
569      * @param listReportedMessages the list of reported Messages
570      */
571     public void setReportedMessages( List<ReportedMessage> listReportedMessages )
572     {
573         this._listReportedMessages = listReportedMessages;
574     }
575 
576     /**
577      * {@inheritDoc}
578      */
579     @Override
580     public String getIdExtendableResource( )
581     {
582         return Integer.toString( _nIdDiggSubmit );
583     }
584 
585     /**
586      * {@inheritDoc}
587      */
588     @Override
589     public String getExtendableResourceType( )
590     {
591         return RESOURCE_TYPE;
592     }
593 
594     /**
595      * {@inheritDoc}
596      */
597     @Override
598     public String getExtendableResourceName( )
599     {
600         return _strDiggSubmitTitle;
601     }
602 
603     /**
604      * {@inheritDoc}
605      */
606     @Override
607     public String getExtendableResourceDescription( )
608     {
609         return _strDiggSubmitTitle;
610     }
611 
612     /**
613      * {@inheritDoc}
614      */
615     @Override
616     public String getExtendableResourceImageUrl( )
617     {
618         if ( _nIdImageResource != null )
619         {
620             StringBuilder sbUrl = new StringBuilder( DiggUtils.SERVLET_IMAGE_PATH );
621             sbUrl.append( _nIdImageResource );
622 
623             return sbUrl.toString( );
624         }
625 
626         return null;
627     }
628 
629     /**
630      * the image id resource associate to the digg submit
631      * @return the image id resource associate to the digg submit
632      */
633     public Integer getIdImageResource( )
634     {
635         return _nIdImageResource;
636     }
637 
638     /**
639      * set the image id resource associate to the digg submit
640      * @param nIdImageRessource the image id resource associate to the digg
641      *            submit
642      */
643     public void setIdImageResource( Integer nIdImageRessource )
644     {
645         this._nIdImageResource = nIdImageRessource;
646     }
647 }