View Javadoc
1   /*
2    * Copyright (c) 2002-2020, City of 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.announce.business;
35  
36  import java.io.Serializable;
37  import java.sql.Timestamp;
38  import java.util.Collection;
39  import java.util.List;
40  
41  import org.apache.commons.collections.CollectionUtils;
42  
43  import fr.paris.lutece.plugins.announce.service.AnnounceResponseImageResourceProvider;
44  import fr.paris.lutece.plugins.genericattributes.business.Response;
45  import fr.paris.lutece.plugins.workflowcore.business.action.Action;
46  import fr.paris.lutece.portal.service.rbac.RBACResource;
47  import fr.paris.lutece.portal.service.resource.IExtendableResource;
48  import fr.paris.lutece.portal.service.util.AppLogService;
49  
50  /**
51   * This is the business class for the object Announce
52   */
53  public class Announce implements Serializable, IExtendableResource, RBACResource, Cloneable
54  {
55      /**
56       * Announce resource type
57       */
58      public static final String RESOURCE_TYPE = "announce";
59      private static final long serialVersionUID = 4717207701123679302L;
60  
61      // Variables declarations
62      private String _strTitle;
63      private String _strDescription;
64      private String _strContactInformation;
65      private int _nIdAnnounce;
66      private Category _category;
67      private boolean _bPublished;
68      private boolean _bSuspended;
69      private boolean _bSuspendedByUser;
70      private String _strUserName;
71      private String _strUserLastName;
72      private String _strUserSecondName;
73      private boolean _bHasPictures;
74      private List<Integer> _listIdImageResponse;
75      private Timestamp _dateCreation;
76      private Timestamp _dateModification;
77      private Timestamp _datePublication;
78      private long _lTimePublication;
79      private Double _nPrice;
80      private String _strTags;
81      private List<Response> _listResponse;
82      private transient Collection<Action> _listActions;
83      private int _nHasNotify;
84  
85      /**
86       * Get the list of responses of this announce
87       * 
88       * @return The list of responses of this announce
89       */
90      public List<Response> getListResponse( )
91      {
92          return _listResponse;
93      }
94  
95      /**
96       * Set the list of responses of this announce
97       * 
98       * @param listResponse
99       *            The list of responses of this announce
100      */
101     public void setListResponse( List<Response> listResponse )
102     {
103         this._listResponse = listResponse;
104     }
105 
106     /**
107      * Returns the IdAnnounce
108      * 
109      * @return The IdAnnounce
110      */
111     public int getId( )
112     {
113         return _nIdAnnounce;
114     }
115 
116     /**
117      * Sets the IdAnnounce
118      * 
119      * @param nIdAnnounce
120      *            The IdAnnounce
121      */
122     public void setId( int nIdAnnounce )
123     {
124         _nIdAnnounce = nIdAnnounce;
125     }
126 
127     /**
128      * Returns the Published state
129      * 
130      * @return The Published state
131      */
132     public boolean getPublished( )
133     {
134         return _bPublished;
135     }
136 
137     /**
138      * Sets the Published state
139      * 
140      * @param bPublished
141      *            the published state
142      */
143     public void setPublished( boolean bPublished )
144     {
145         _bPublished = bPublished;
146     }
147 
148     /**
149      * gets the suspended state
150      * 
151      * @return the suspended state of announce
152      */
153     public boolean getSuspended( )
154     {
155         return _bSuspended;
156     }
157 
158     /**
159      * sets the suspended state
160      * 
161      * @param bSuspended
162      *            the suspended state
163      */
164     public void setSuspended( boolean bSuspended )
165     {
166         _bSuspended = bSuspended;
167     }
168 
169     /**
170      * gets the title
171      * 
172      * @return the title of announce
173      */
174     public String getTitle( )
175     {
176         return _strTitle;
177     }
178 
179     /**
180      * gets the description
181      * 
182      * @return the description of announce
183      */
184     public String getDescription( )
185     {
186         return _strDescription;
187     }
188 
189     /**
190      * gets the title
191      * 
192      * @param strTitle
193      *            gets the suspended state
194      */
195     public void setTitle( String strTitle )
196     {
197         _strTitle = strTitle;
198     }
199 
200     /**
201      * sets the description
202      * 
203      * @param strDescription
204      *            the description
205      */
206     public void setDescription( String strDescription )
207     {
208         _strDescription = strDescription;
209     }
210 
211     /**
212      * gets the category
213      * 
214      * @return the announce category
215      */
216     public Category getCategory( )
217     {
218         return _category;
219     }
220 
221     /**
222      * sets the announce category
223      * 
224      * @param category
225      *            the announce category
226      */
227     public void setCategory( Category category )
228     {
229         _category = category;
230     }
231 
232     /**
233      * gets the user name
234      * 
235      * @return the username
236      */
237     public String getUserName( )
238     {
239         return _strUserName;
240     }
241 
242     /**
243      * sets the announce user name
244      * 
245      * @param strUserName
246      *            the user name
247      */
248     public void setUserName( String strUserName )
249     {
250         _strUserName = strUserName;
251     }
252 
253     /**
254      * gets the user name
255      * 
256      * @return the username
257      */
258     public String getUserLastName( )
259     {
260         return _strUserLastName;
261     }
262 
263     /**
264      * sets the announce user name
265      * 
266      * @param strUserName
267      *            the user name
268      */
269     public void setUserLastName( String strUserLastName )
270     {
271         _strUserLastName = strUserLastName;
272     }
273 
274     /**
275      * gets the user name
276      * 
277      * @return the username
278      */
279     public String getUserSecondName( )
280     {
281         return _strUserSecondName;
282     }
283 
284     /**
285      * sets the announce user name
286      * 
287      * @param strUserName
288      *            the user name
289      */
290     public void setUserSecondName( String strUserSecondName )
291     {
292         _strUserSecondName = strUserSecondName;
293     }
294 
295     /**
296      * weather or not the announce has pictures in slideshow
297      * 
298      * @return weather or not the announce has pictures in slideshow
299      */
300     public boolean getHasPictures( )
301     {
302         return _bHasPictures;
303     }
304 
305     /**
306      * set weather or not the announce has pictures
307      * 
308      * @param bHasPictures
309      *            weather or not the announce has pictures
310      */
311     public void setHasPictures( boolean bHasPictures )
312     {
313         _bHasPictures = bHasPictures;
314     }
315 
316     /**
317      * Gets the list of ids of images responses of this announce
318      * 
319      * @return The list of ids of images responses of this announce
320      */
321     public List<Integer> getListIdImageResponse( )
322     {
323         return _listIdImageResponse;
324     }
325 
326     /**
327      * Sets the list of ids of images responses of this announce
328      * 
329      * @param listIdImageResponse
330      *            the list of ids of image responses of this announce
331      */
332     public void setListIdImageResponse( List<Integer> listIdImageResponse )
333     {
334         this._listIdImageResponse = listIdImageResponse;
335     }
336 
337     /**
338      * gets the creation date
339      * 
340      * @return the creation date
341      */
342     public Timestamp getDateCreation( )
343     {
344         return _dateCreation;
345     }
346 
347     /**
348      * sets the creation date
349      * 
350      * @param time
351      *            the creation date
352      */
353     public void setDateCreation( Timestamp time )
354     {
355         this._dateCreation = time;
356     }
357 
358     /**
359      * Get the modification date
360      * 
361      * @return The modification date
362      */
363     public Timestamp getDateModification( )
364     {
365         return _dateModification;
366     }
367 
368     /**
369      * Set the modification date
370      * 
371      * @param dateModification
372      *            The modification date
373      */
374     public void setDateModification( Timestamp dateModification )
375     {
376         this._dateModification = dateModification;
377     }
378 
379     /**
380      * gets the publication time
381      * 
382      * @return the publication time
383      */
384     public long getTimePublication( )
385     {
386         return _lTimePublication;
387     }
388 
389     /**
390      * sets the publication time
391      * 
392      * @param lTime
393      *            the publication time
394      */
395     public void setTimePublication( long lTime )
396     {
397         this._lTimePublication = lTime;
398     }
399 
400     /**
401      * gets the contact information
402      * 
403      * @return the contact information
404      */
405     public String getContactInformation( )
406     {
407         return _strContactInformation;
408     }
409 
410     /**
411      * sets the contact information
412      * 
413      * @param strContactInformation
414      *            the contact information
415      */
416     public void setContactInformation( String strContactInformation )
417     {
418         this._strContactInformation = strContactInformation;
419     }
420 
421     /**
422      * gets the price of the announce
423      * 
424      * @return the price of announce
425      */
426     public Double getPrice( )
427     {
428         return _nPrice;
429     }
430 
431     /**
432      * sets the price of the announce
433      * 
434      * @param price
435      *            the price of the announce
436      */
437     public void setPrice( Double price )
438     {
439         this._nPrice = price;
440     }
441 
442     /**
443      * Check if the announce was suspended by the user or not
444      * 
445      * @return True if the announce was suspended by the user or not, false otherwise
446      */
447     public boolean getSuspendedByUser( )
448     {
449         return _bSuspendedByUser;
450     }
451 
452     /**
453      * Set the announce was suspended by the user or not
454      * 
455      * @param bSuspendedByUser
456      *            True to set the announce was suspended by the user or not, false otherwise
457      */
458     public void setSuspendedByUser( boolean bSuspendedByUser )
459     {
460         this._bSuspendedByUser = bSuspendedByUser;
461     }
462 
463     /**
464      * gets the tags of announce
465      * 
466      * @return gets the tags of announce
467      */
468     public String getTags( )
469     {
470         return _strTags;
471     }
472 
473     /**
474      * sets the Tags of announce
475      * 
476      * @param strTags
477      *            the Tags of announce
478      */
479     public void setTags( String strTags )
480     {
481         _strTags = strTags;
482     }
483 
484     /**
485      * {@inheritDoc}
486      */
487     @Override
488     public String getIdExtendableResource( )
489     {
490         return Integer.toString( getId( ) );
491     }
492 
493     /**
494      * {@inheritDoc}
495      */
496     @Override
497     public String getExtendableResourceType( )
498     {
499         return RESOURCE_TYPE;
500     }
501 
502     /**
503      * {@inheritDoc}
504      */
505     @Override
506     public String getExtendableResourceName( )
507     {
508         return getTitle( );
509     }
510 
511     /**
512      * {@inheritDoc}
513      */
514     @Override
515     public String getExtendableResourceDescription( )
516     {
517         return getDescription( );
518     }
519 
520     /**
521      * {@inheritDoc}
522      */
523     @Override
524     public String getExtendableResourceImageUrl( )
525     {
526         if ( getHasPictures( ) && CollectionUtils.isNotEmpty( getListIdImageResponse( ) ) )
527         {
528             return AnnounceResponseImageResourceProvider.getUrlDownloadImageResponse( getListIdImageResponse( ).get( 0 ) );
529         }
530 
531         return null;
532     }
533 
534     /**
535      * Get the list of workflow actions of this announce
536      * 
537      * @return The list of workflow announce of this announce
538      */
539     public Collection<Action> getListWorkflowActions( )
540     {
541         return _listActions;
542     }
543 
544     /**
545      * Set the list of workflow actions of this announce
546      * 
547      * @param listActions
548      *            The list of workflow actions of this announce
549      */
550     public void setListWorkflowActions( Collection<Action> listActions )
551     {
552         this._listActions = listActions;
553     }
554 
555     /**
556      * {@inheritDoc}
557      */
558     @Override
559     public String getResourceTypeCode( )
560     {
561         return getExtendableResourceType( );
562     }
563 
564     /**
565      * {@inheritDoc}
566      */
567     @Override
568     public String getResourceId( )
569     {
570         return getIdExtendableResource( );
571     }
572 
573     /**
574      * {@inheritDoc}
575      */
576     @Override
577     public Object clone( )
578     {
579         try
580         {
581             return super.clone( );
582         }
583         catch( CloneNotSupportedException e )
584         {
585             AppLogService.error( e.getMessage( ), e );
586         }
587 
588         return this;
589     }
590 
591     /**
592      * @return the _datePublication
593      */
594     public Timestamp getDatePublication( )
595     {
596         return new Timestamp( this.getTimePublication( ) );
597     }
598 
599     /**
600      * @param _datePublication
601      *            the _datePublication to set
602      */
603     public void setDatePublication( )
604     {
605         this._datePublication = new Timestamp( this.getTimePublication( ) );
606     }
607 
608     /**
609      * @return the _nHasNotify
610      */
611     public int getHasNotify( )
612     {
613         return _nHasNotify;
614     }
615 
616     /**
617      * @param nHasNotify
618      *            the _nHasNotify to set
619      */
620     public void setHasNotify( int nHasNotify )
621     {
622         this._nHasNotify = nHasNotify;
623     }
624 
625 }