View Javadoc
1   /*
2    * Copyright (c) 2002-2021, 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.newsletter.business;
35  
36  import fr.paris.lutece.plugins.newsletter.service.NewsletterTemplateRemovalService;
37  import fr.paris.lutece.portal.service.rbac.RBACResource;
38  import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupResource;
39  import fr.paris.lutece.portal.service.workgroup.WorkgroupRemovalListenerService;
40  
41  import java.sql.Timestamp;
42  
43  /**
44   * This class represents business NewsLetter Object
45   */
46  public class NewsLetter implements AdminWorkgroupResource, RBACResource
47  {
48      /**
49       * Name of the resource type
50       */
51      public static final String RESOURCE_TYPE = "NEWSLETTER";
52      private static final String EMPTY_STRING = "";
53      private static NewsletterWorkgroupRemovalListener _listenerWorkgroup;
54  
55      /////////////////////////////////////////////////////////////////////////////////
56      // Constants
57      private int _nId;
58      private String _strName;
59      private String _strDescription;
60      private Timestamp _dateLastSending;
61      private String _strHtml;
62      private int _nNewsLetterTemplateId;
63      private boolean _bIsValidationActive;
64      private boolean _bIsCaptchaActive;
65      private String _strWorkgroup;
66      private String _strTestRecipients;
67      private String _strUnsubscribe;
68      private String _strNewsletterSenderMail;
69      private String _strNewsletterSenderName;
70      private String _strTermOfService;
71      private String _strSubject;
72      private int _nNbSections;
73  
74      /**
75       * Initialize the Newsletter
76       */
77      public static synchronized void init( )
78      {
79          // Create removal listeners and register them
80          if ( _listenerWorkgroup == null )
81          {
82              _listenerWorkgroup = new NewsletterWorkgroupRemovalListener( );
83              WorkgroupRemovalListenerService.getService( ).registerListener( _listenerWorkgroup );
84          }
85          NewsletterTemplateRemovalService.getService( ).registerListener( new NewsletterTemplateRemovalListener( ) );
86      }
87  
88      /**
89       * Returns the identifier of the newsletter
90       * 
91       * @return the newsletter identifier
92       */
93      public int getId( )
94      {
95          return _nId;
96      }
97  
98      /**
99       * Sets the identifier of the newsletter
100      * 
101      * @param nId
102      *            the newsletter identifier
103      */
104     public void setId( int nId )
105     {
106         _nId = nId;
107     }
108 
109     /**
110      * Returns the subject of the newsletter
111      * 
112      * @return the newsletter identifier
113      */
114     public String getTestSubject( )
115     {
116         return _strSubject;
117     }
118 
119     /**
120      * Sets the test subject of the newsletter
121      * 
122      * @param strTestSubject
123      *            the newsletter test subject
124      */
125     public void setTestSubject( String strTestSubject )
126     {
127         _strSubject = strTestSubject;
128     }
129 
130     /**
131      * 
132      * Set if the user must validate by mail
133      * 
134      * @param bIsValidationActive
135      *            the boolean
136      */
137     public void setValidationActive( boolean bIsValidationActive )
138     {
139         _bIsValidationActive = bIsValidationActive;
140     }
141 
142     /**
143      * return if the validation by mail is active
144      * 
145      * @return _bIsValidationActive the boolean
146      */
147     public boolean isValidationActive( )
148     {
149         return _bIsValidationActive;
150     }
151 
152     /**
153      * 
154      * Set if the user must enter a captcha to subscribe
155      * 
156      * @param bIsCaptchaActive
157      *            the boolean
158      */
159     public void setCaptchaActive( boolean bIsCaptchaActive )
160     {
161         _bIsCaptchaActive = bIsCaptchaActive;
162     }
163 
164     /**
165      * return if the user must enter a captcha to subscribe
166      * 
167      * @return bIsCaptchaActive the boolean
168      */
169     public boolean isCaptchaActive( )
170     {
171         return _bIsCaptchaActive;
172     }
173 
174     /**
175      * Returns the name of the newsletter
176      * 
177      * @return the newsletter name
178      */
179     public String getName( )
180     {
181         return _strName;
182     }
183 
184     /**
185      * Sets the name of the newsletter
186      * 
187      * @param strName
188      *            the newsletter name
189      */
190     public void setName( String strName )
191     {
192         _strName = ( strName == null ) ? EMPTY_STRING : strName;
193     }
194 
195     /**
196      * Returns the name of the newsletter
197      * 
198      * @return the newsletter name
199      */
200     public String getDescription( )
201     {
202         return _strDescription;
203     }
204 
205     /**
206      * Sets the description of the newsletter
207      * 
208      * @param strDescription
209      *            the description
210      */
211     public void setDescription( String strDescription )
212     {
213         _strDescription = ( strDescription == null ) ? EMPTY_STRING : strDescription;
214     }
215 
216     /**
217      * Returns the unsubscription of the newsletter
218      * 
219      * @return the newsletter unsubscrition value
220      */
221     public String getUnsubscribe( )
222     {
223         return _strUnsubscribe;
224     }
225 
226     /**
227      * Sets the value of the unsubscription to the newsletter
228      * 
229      * @param strUnsubscribe
230      *            the newsletter name
231      */
232     public void setUnsubscribe( String strUnsubscribe )
233     {
234         _strUnsubscribe = ( strUnsubscribe == null ) ? EMPTY_STRING : strUnsubscribe;
235     }
236 
237     /**
238      * Sets the date of the last newsletter sending
239      * 
240      * @param dateLastSending
241      *            the last date of sending
242      */
243     public void setDateLastSending( Timestamp dateLastSending )
244     {
245         _dateLastSending = dateLastSending;
246     }
247 
248     /**
249      * Returns the date of the last sending
250      * 
251      * @return the last sending date
252      */
253     public Timestamp getDateLastSending( )
254     {
255         return _dateLastSending;
256     }
257 
258     /**
259      * Returns the html content of the newsletter
260      * 
261      * @return the html content of the newsletter
262      */
263     public String getHtml( )
264     {
265         return _strHtml;
266     }
267 
268     /**
269      * Sets the html content of the newsletter
270      * 
271      * @param strHtml
272      *            the html content of the newsletter
273      */
274     public void setHtml( String strHtml )
275     {
276         _strHtml = ( strHtml == null ) ? EMPTY_STRING : strHtml;
277     }
278 
279     /**
280      * Returns the tos content of the newsletter
281      * 
282      * @return the tos content of the newsletter
283      */
284     public String getTOS( )
285     {
286         return _strTermOfService;
287     }
288 
289     /**
290      * Sets the tos content of the newsletter
291      * 
292      * @param strTermOfService
293      *            the tos content of the newsletter
294      */
295     public void setTOS( String strTermOfService )
296     {
297         _strTermOfService = strTermOfService;
298     }
299 
300     /**
301      * Returns the identifier of the newsletter template
302      * 
303      * @return the newsletter template identifier
304      */
305     public int getNewsLetterTemplateId( )
306     {
307         return _nNewsLetterTemplateId;
308     }
309 
310     /**
311      * Sets the identifier of the newsletter template
312      * 
313      * @param nNewsLetterTemplateId
314      *            the newsletter template identifier
315      */
316     public void setNewsLetterTemplateId( int nNewsLetterTemplateId )
317     {
318         _nNewsLetterTemplateId = nNewsLetterTemplateId;
319     }
320 
321     /**
322      * Returns the workgroup
323      * 
324      * @return The workgroup
325      */
326     public String getWorkgroup( )
327     {
328         return _strWorkgroup;
329     }
330 
331     /**
332      * Sets the workgroup
333      * 
334      * @param strWorkgroup
335      *            The workgroup
336      */
337     public void setWorkgroup( String strWorkgroup )
338     {
339         _strWorkgroup = strWorkgroup;
340     }
341 
342     /**
343      * Returns the test recipients
344      * 
345      * @return The test recipients
346      */
347     public String getTestRecipients( )
348     {
349         return _strTestRecipients;
350     }
351 
352     /**
353      * Sets the test recipients
354      * 
355      * @param strTestRecipients
356      *            The Test recipients
357      */
358     public void setTestRecipients( String strTestRecipients )
359     {
360         _strTestRecipients = strTestRecipients;
361     }
362 
363     /**
364      * Returns the Newsletter sender mail
365      * 
366      * @return The Newsletter sender mail
367      */
368     public String getNewsletterSenderMail( )
369     {
370         return _strNewsletterSenderMail;
371     }
372 
373     /**
374      * Sets the Newsletter sender mail
375      * 
376      * @param strNewsletterSenderMail
377      *            The NewsletterSenderMail
378      */
379     public void setNewsletterSenderMail( String strNewsletterSenderMail )
380     {
381         _strNewsletterSenderMail = strNewsletterSenderMail;
382     }
383 
384     /**
385      * Returns the Newsletter sender name
386      * 
387      * @return The Newsletter sender name
388      */
389     public String getNewsletterSenderName( )
390     {
391         return _strNewsletterSenderName;
392     }
393 
394     /**
395      * Sets the Newsletter sender name
396      * 
397      * @param strNewsletterSenderName
398      *            The NewsletterSenderName
399      */
400     public void setNewsletterSenderName( String strNewsletterSenderName )
401     {
402         _strNewsletterSenderName = strNewsletterSenderName;
403     }
404 
405     /**
406      * Returns the Resource Type Code that identify the resource type
407      * 
408      * @return The Resource Type Code
409      */
410     public String getResourceId( )
411     {
412         return "" + getId( );
413     }
414 
415     /**
416      * Returns the resource Id of the current object
417      * 
418      * @return The resource Id of the current object
419      */
420     public String getResourceTypeCode( )
421     {
422         return RESOURCE_TYPE;
423     }
424 
425     /**
426      * Get the number of sections of this newsletter
427      * 
428      * @return The number of sections of this newsletter
429      */
430     public int getNbSections( )
431     {
432         return _nNbSections;
433     }
434 
435     /**
436      * Set the number of sections of this newsletter
437      * 
438      * @param nNbSections
439      *            The number of sections of this newsletter
440      */
441     public void setNbSections( int nNbSections )
442     {
443         this._nNbSections = nNbSections;
444     }
445 }