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.formengine.business;
35  
36  import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupResource;
37  import fr.paris.lutece.util.date.DateUtil;
38  
39  import java.sql.Timestamp;
40  
41  import java.util.Calendar;
42  import java.util.Date;
43  
44  
45  /**
46   * Notice class
47   */
48  public class Notice implements AdminWorkgroupResource
49  {
50      private int _nIdNotice;
51      private String _strTitle;
52      private String _strMessage;
53      private String _strWorkgroupKey;
54      private Timestamp _tDateDebut;
55      private Timestamp _tDateFin;
56      private int _nIdDiffusion;
57      private int _nIdNoticeGroup;
58      private int _nOrder;
59      private boolean _bIsEnabled;
60  
61      //private int _nIdRss;
62      private int _nIdNotification;
63  
64      /**
65       * Get the id of Notice
66       * @return id notice
67       */
68      public int getIdNotice(  )
69      {
70          return _nIdNotice;
71      }
72  
73      /**
74       * Set the id of notice
75       * @param idNotice notice id
76       */
77      public void setIdNotice( int idNotice )
78      {
79          _nIdNotice = idNotice;
80      }
81  
82      /**
83       * Get the title of Notice
84       * @return title notice
85       */
86      public String getTitle(  )
87      {
88          return _strTitle;
89      }
90  
91      /**
92       * Set the title of notice
93       * @param title the title
94       */
95      public void setTitle( String title )
96      {
97          _strTitle = title;
98      }
99  
100     /**
101      * Get the message of Notice
102      * @return message notice
103      */
104     public String getMessage(  )
105     {
106         return _strMessage;
107     }
108 
109     /**
110      * Set the message of notice
111      * @param message the message of notice
112      */
113     public void setMessage( String message )
114     {
115         _strMessage = message;
116     }
117 
118     /**
119      * Get the workgroup key of Notice
120      * @return workgroup key of notice
121      */
122     public String getWorkgroupKey(  )
123     {
124         return _strWorkgroupKey;
125     }
126 
127     /**
128      * Set the workgroup key
129      * @param workgroupKey workgroup key
130      */
131     public void setWorkgroupKey( String workgroupKey )
132     {
133         _strWorkgroupKey = workgroupKey;
134     }
135 
136     /**
137      * Get the date begin of Notice
138      * @return date debut
139      */
140     public Timestamp getDateDebut(  )
141     {
142         return _tDateDebut;
143     }
144 
145     /**
146      * Set the begin date
147      * @param dateDebut the begin date
148      */
149     public void setDateDebut( Timestamp dateDebut )
150     {
151         _tDateDebut = dateDebut;
152     }
153 
154     /**
155      * Get the end date of Notice
156      * @return date fin
157      */
158     public Timestamp getDateFin(  )
159     {
160         return _tDateFin;
161     }
162 
163     /**
164      * Set the end date
165      * @param dateFin date fin
166      */
167     public void setDateFin( Timestamp dateFin )
168     {
169         _tDateFin = dateFin;
170     }
171 
172     /**
173      * Get the id diffusion of Notice
174      * @return id notice
175      */
176     public int getIdDiffusion(  )
177     {
178         return _nIdDiffusion;
179     }
180 
181     /**
182      * Set the Id Diffusion
183      * @param idDiffusion id diffusion
184      */
185     public void setIdDiffusion( int idDiffusion )
186     {
187         _nIdDiffusion = idDiffusion;
188     }
189 
190     /**
191     *
192     * @return true if the notice is enabled
193     */
194     public boolean isEnabled(  )
195     {
196         return _bIsEnabled;
197     }
198 
199     /**
200      * Set true if the notice is enabled
201      * @param enable true if the notice is enabled
202      */
203     public void setEnabled( boolean enable )
204     {
205         _bIsEnabled = enable;
206     }
207 
208     /**
209      * Get the rss id of Notice
210      * @return id notice
211      */
212 
213     /*public int getIdRss(  )
214     {
215         return _nIdRss;
216     }*/
217 
218     /**
219      * Set the id of RSS
220      * @param nIdRss id of RSS
221      */
222 
223     /*public void setIdRss( int nIdRss )
224     {
225         _nIdRss = nIdRss;
226     }*/
227 
228     /**
229      * Get Workgroup
230      * @return the workgroup of notice
231      */
232     public String getWorkgroup(  )
233     {
234         return _strWorkgroupKey;
235     }
236 
237     /**
238      * Get the id of notification
239      * @return the id of notification
240      */
241     public int getIdNotification(  )
242     {
243         return _nIdNotification;
244     }
245 
246     /**
247      * Set the id of notification
248      * @param idNotification the id notification
249      */
250     public void setIdNotification( int idNotification )
251     {
252         _nIdNotification = idNotification;
253     }
254 
255     /**
256      * Test if the date are valid
257      * @return true if the date are valid, false otherwise
258      */
259     public boolean hasValidDate(  )
260     {
261         Date dateDebut = getDateDebut(  );
262         Date dateFin = getDateFin(  );
263         Date dateDuJour = new Date(  );
264 
265         Calendar cal = Calendar.getInstance(  );
266         cal.setTime( dateDuJour );
267         cal.set( Calendar.MINUTE, 0 );
268         cal.set( Calendar.HOUR, 0 );
269         cal.set( Calendar.SECOND, 0 );
270 
271         dateDuJour = cal.getTime(  );
272 
273         if ( dateDebut == null )
274         {
275             dateDebut = dateDuJour;
276         }
277         else
278         {
279             cal.setTime( dateDebut );
280             cal.set( Calendar.MINUTE, 0 );
281             cal.set( Calendar.HOUR, 0 );
282             cal.set( Calendar.SECOND, 0 );
283 
284             dateDebut = cal.getTime(  );
285         }
286 
287         if ( dateFin != null )
288         {
289             cal.setTime( dateFin );
290             cal.set( Calendar.MINUTE, 0 );
291             cal.set( Calendar.HOUR, 0 );
292             cal.set( Calendar.SECOND, 0 );
293 
294             dateFin = cal.getTime(  );
295 
296             //AppLogService.error( DateUtil.getDateString( dateDebut ) + " " + DateUtil.getDateString( dateFin ) + " " + DateUtil.getDateString( dateDuJour ) );
297             if ( DateUtil.getDateString( dateDebut ).equals( DateUtil.getDateString( dateFin ) ) &&
298                     DateUtil.getDateString( dateDebut ).equals( DateUtil.getDateString( dateDuJour ) ) )
299             {
300                 return true;
301             }
302 
303             if ( dateDebut.after( dateDuJour ) || dateFin.before( dateDuJour ) )
304             {
305                 return false;
306             }
307         }
308         else
309         {
310             if ( dateDebut.after( dateDuJour ) )
311             {
312                 return false;
313             }
314         }
315 
316         return true;
317     }
318 
319     /**
320      * "Getter method" for {@link #_nIdNoticeGroup}
321      * @return value of {@link #_nIdNoticeGroup}
322      */
323     public int getIdNoticeGroup(  )
324     {
325         return _nIdNoticeGroup;
326     }
327 
328     /**
329      * "Setter method" for {@link #_nIdNoticeGroup}
330      * @param nIdNoticeGroup new value of {@link #_nIdNoticeGroup}
331      */
332     public void setIdNoticeGroup( int nIdNoticeGroup )
333     {
334         _nIdNoticeGroup = nIdNoticeGroup;
335     }
336 
337     /**
338      * "Getter method" for {@link #_nOrder}
339      * @return value of {@link #_nOrder}
340      */
341     public int getOrder(  )
342     {
343         return _nOrder;
344     }
345 
346     /**
347      * "Setter method" for {@link #_nOrder}
348      * @param nOrder new value of {@link #_nOrder}
349      */
350     public void setOrder( int nOrder )
351     {
352         _nOrder = nOrder;
353     }
354 }