Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/clra/web/RowingSessionForm.java


1   /*
2    * Copyright (c) Carnegie Lake Rowing Association 2002. All rights reserved.
3    * Distributed under the GPL license. See doc/COPYING.
4    * $RCSfile: RowingSessionForm.java,v $
5    * $Date: 2003/02/26 03:38:46 $
6    * $Revision: 1.5 $
7    */
8   
9   package com.clra.web;
10  
11  import com.clra.rowing.RowingSessionLevel;
12  import com.clra.rowing.RowingSessionState;
13  import com.clra.rowing.RowingSessionType;
14  import java.text.SimpleDateFormat;
15  import java.util.ArrayList;
16  import java.util.Calendar;
17  import java.util.Collection;
18  import java.util.Iterator;
19  import java.util.Date;
20  import java.util.GregorianCalendar;
21  import javax.servlet.http.HttpServletRequest;
22  import org.apache.log4j.Category;
23  import org.apache.struts.action.ActionError;
24  import org.apache.struts.action.ActionErrors;
25  import org.apache.struts.action.ActionForm;
26  import org.apache.struts.action.ActionMapping;
27  
28  /**
29   * Form bean for the rowing session page.  This form has the following fields,
30   * with default values in square brackets:
31   * <ul>
32   * <li><b>action</b> - The maintenance action that is being performed:
33   * Create, Edit, Publish, Lock, View, Cancel or Delete. [REQUIRED]</li>
34   * <li><b>id</b> - The rowing_id of the rowing session.
35   * [REQUIRED except on Create, IMMUTABLE otherwise]</li>
36   * <li><b>datetime</b> - The date (and time) for this rowing session.
37   * [REQUIRED on Create and Edit, IMMUTABLE otherwise]</li>
38   * <li><b>level</b> - The level (LTR, REGULAR) of this rowing session.
39   * [REQUIRED on Create and Edit, IMMUTABLE otherwise]</li>
40   * <li><b>type</b> - The type (COMPETITION,PRACTICE) of this rowing session.
41   * [REQUIRED on Create and Edit, IMMUTABLE otherwise]</li>
42   * <li><b>state</b> - The state (TENATIVE, OPEN, LOCKED, BOATING1, BOATING2,
43   * COMPLETE, INVOICING, CLOSED) of this rowing session.
44   * [REQUIRED on Create and Edit, IMMUTABLE otherwise]</li>
45   * </ul>
46   *
47   * @author <a href="mailto:rphall@pluto.njcc.com">Rick Hall</a>
48   * @version $Revision: 1.5 $ $Date: 2003/02/26 03:38:46 $
49   */
50  public class RowingSessionForm extends ActionForm  {
51  
52    private final static String base = RowingSessionForm.class.getName();
53    private final static Category theLog = Category.getInstance( base );
54  
55    /** Name of the action that creates a rowing session */
56    public final static String CREATE  = "Create";
57  
58    /** Name of the action that publishes a rowing session */
59    public final static String PUBLISH = "Publish";
60  
61    /** Name of the action that edits a rowing session */
62    public final static String EDIT    = "Edit";
63  
64    /** Name of the action that locks a rowing session */
65    public final static String LOCK = "Lock";
66  
67    /** Name of the action that displays a rowing session */
68    public final static String VIEW    = "View";
69  
70    /** Name of the action that cancels a rowing session */
71    public final static String SESSIONCANCEL  = "SessionCancel";
72  
73    /** Name of the action that deletes a rowing session */
74    public final static String DELETE  = "Delete";
75  
76    /** Name of the action that cancels action by the form */
77    public final static String CANCEL  = "Cancel";
78  
79    private final static String spec1 = Text.getMessage( "dateformat.date1" );
80    private final static SimpleDateFormat sdf1 = new SimpleDateFormat(spec1);
81  
82    private final static String spec2 = Text.getMessage( "dateformat.time1" );
83    private final static SimpleDateFormat sdf2 = new SimpleDateFormat(spec2);
84  
85    private final static String spec3 = Text.getMessage( "dateformat.long1" );
86    private final static SimpleDateFormat sdf3 = new SimpleDateFormat(spec3);
87  
88    /** The maintenance action that is being performed. */
89    private String action = CREATE;
90  
91    /** The id of the rowing session */
92    private Integer rowingId = null;
93  
94    /** Date (and time) of the rowing session */
95    private Calendar calendar = tomorrowMorning();
96  
97    /** A collection of participants enrolled in the rowing session */
98    private Collection participants = new ArrayList();
99  
100   /**
101    * The level of the rowing session.
102    * @see com.clra.rowing.RowingSessionLevel
103   */
104   private String level = RowingSessionLevel.NAME_REGULAR;
105 
106   /**
107    * The rowing session type.
108    * @see com.clra.rowing.RowingSessionType
109    */
110   private String type = RowingSessionType.NAME_PRACTICE;
111 
112   /**
113    * The rowing session type.
114    * @see com.clra.rowing.RowingSessionState
115    */
116   private String state = RowingSessionState.NAME_NEW;
117 
118   /** Return the maintenance action */
119   public String getAction() {
120     return this.action;
121   }
122 
123   /** Set the maintenance action.  */
124   public void setAction(String action) {
125     this.action = action;
126   }
127 
128   /** Return the persistent id of the rowing session */
129   public Integer getRowingId() {
130     return this.rowingId;
131   }
132 
133   /** Set the persistent id of the rowing session */
134   void setRowingId( Integer rowingId ) {
135     this.rowingId = rowingId;
136   }
137 
138   /** Return the state of the rowing session */
139   public String getState() {
140     return this.state;
141   }
142 
143   /** Set the state of the rowing session */
144   public void setState( String state ) {
145     this.state = state;
146   }
147 
148   /** Returns the formatted date of the rowing session */
149   public String getDate() {
150     return sdf1.format( this.calendar.getTime() );
151   }
152 
153   /** Returns the formatted time of the rowing session */
154   public String getTime() {
155     return sdf2.format( this.calendar.getTime() );
156   }
157 
158   /** Returns the formatted date and time of the rowing session */
159   public String getDateTime() {
160     return sdf3.format( this.calendar.getTime() );
161   }
162 
163   /** Returns the date and time in a Date object */
164   public Date getDateTimeAsDateObject() {
165     return this.calendar.getTime();
166   }
167 
168   /** Sets the date and time from a Date object */
169   public void setDateTimeFromDate( Date date ) {
170     if ( date == null ) {
171       throw new IllegalArgumentException( "null date" );
172     }
173     // Bug workaround
174     date = new Date( date.getTime() );
175     // End workaround
176     this.calendar.set( Calendar.YEAR, date.getYear() + 1900 );
177     this.calendar.set( Calendar.MONTH, date.getMonth() );
178     this.calendar.set( Calendar.DATE, date.getDate() );
179     this.calendar.set( Calendar.HOUR_OF_DAY, date.getHours() );
180     this.calendar.set( Calendar.MINUTE, date.getMinutes() );
181   }
182 
183   /** Returns the date and time in a Calendar object */
184   public Calendar getCalendar() {
185     return (Calendar) this.calendar.clone();
186   }
187 
188   /** Sets the date and time from a Calendar object */
189   public void setCalendar( Calendar calendar ) {
190     if ( calendar == null ) {
191       throw new IllegalArgumentException( "null calendar" );
192     }
193     this.calendar = (Calendar) calendar.clone();
194   }
195 
196   /** Return the year. Range: 2001 - ... */
197   public int getYear() {
198     return this.calendar.get( Calendar.YEAR );
199   }
200 
201   /** Sets the year. Range: 2001 - ... */
202   public void setYear( int year ) {
203     this.calendar.set( Calendar.YEAR, year );
204   }
205 
206   /** Return the month. Range: 0 - 11 */
207   public int getMonth() {
208     return this.calendar.get( Calendar.MONTH );
209   }
210 
211   /** Sets the month. Range: 0 - 11 */
212   public void setMonth( int month ) {
213     this.calendar.set( Calendar.MONTH, month );
214   }
215 
216   /** Return the day. Range: 1 - 31 */
217   public int getDay() {
218     return this.calendar.get( Calendar.DATE );
219   }
220 
221   /** Sets the day. Range: 1 - 31 */
222   public void setDay( int day ) {
223     this.calendar.set( Calendar.DATE, day );
224   }
225 
226   /** Return the hour. Range: 1 - 12 */
227   public int getHour() {
228     return this.calendar.get( Calendar.HOUR );
229   }
230 
231   /** Sets the hour. Range: 1 - 12 */
232   public void setHour( int hour ) {
233     this.calendar.set( Calendar.HOUR, hour );
234   }
235 
236   /** Return the minute */
237   public int getMinute() {
238     return this.calendar.get( Calendar.MINUTE );
239   }
240 
241   /** Sets the minute */
242   public void setMinute( int minute ) {
243     this.calendar.set( Calendar.MINUTE, minute );
244   }
245 
246   /** Return am/pm. Range: Calendar.AM or Calendar.PM */
247   public int getAmPm() {
248     return this.calendar.get( Calendar.AM_PM );
249   }
250 
251   /** Sets am/pm Range: Calendar.AM or Calendar.PM */
252   public void setAmPm( int ampm ) {
253     this.calendar.set( Calendar.AM_PM, ampm );
254   }
255 
256   /** Return the level of the rowing session */
257   public String getLevel() {
258     return this.level;
259   }
260 
261   /** Set the level of the rowing session */
262   public void setLevel( String level ) {
263     this.level = level;
264   }
265 
266   /** Return the type of the rowing session */
267   public String getType() {
268     return this.type;
269   }
270 
271   /** Set the type of the rowing session */
272   public void setType( String type ) {
273     this.type = type;
274   }
275 
276   /**
277    * Reset all properties to their default values.
278    *
279    * @param mapping The mapping used to select this instance
280    * @param request The servlet request we are processing
281    */
282   public void reset(ActionMapping mapping, HttpServletRequest request) {
283 
284     // FIXME reset to request values
285     this.action = CREATE;
286     this.rowingId = null;
287     this.calendar = tomorrowMorning();
288     this.level = RowingSessionLevel.NAME_REGULAR;
289     this.type = RowingSessionType.NAME_PRACTICE;
290     this.state = RowingSessionState.NAME_NEW;
291 
292   }
293 
294 
295   /**
296    * Validate the properties that have been set from this HTTP request,
297    * and return an <code>ActionErrors</code> object that encapsulates any
298    * validation errors that have been found.  If no errors are found, return
299    * <code>null</code> or an <code>ActionErrors</code> object with no
300    * recorded error messages.
301    *
302    * <p>Restrictions:<ul>
303    *
304    * <li>A NEW session may be created. No other action is permitted.</li>
305    * <li>After creation, a session is considered TENATIVE. A TENATIVE
306    * sessions. The Create action is not permitted on any other session
307    * state.</li>
308    * <li>The Edit and Delete actions are permitted only for TENATIVE rowing
309    * sessions.</li>
310    * <li>The Promote and Cancel actions are not permitted for CLOSED rowing
311    * sessions.</li>
312    * <li>Only the Edit action is permitted on CANCELLED rowing sessions.</li>
313    * <ul>
314    *
315    * @param mapping The mapping used to select this instance
316    * @param request The servlet request we are processing
317    */
318   public ActionErrors validate(ActionMapping mapping,
319                            HttpServletRequest request) {
320 
321     ActionErrors errors = new ActionErrors();
322 
323     return (errors);
324   }
325 
326   /** Package utility to calculate 5:45 AM tomorrow morning */
327   static Calendar tomorrowMorning() {
328     GregorianCalendar calendar = new GregorianCalendar();
329     calendar.add(Calendar.DATE,1);
330     calendar.set(Calendar.HOUR,5);
331     calendar.set(Calendar.MINUTE,45);
332     calendar.set(Calendar.AM_PM,Calendar.AM);
333     return calendar;
334   }
335 
336   /** Package utility to calculate 7:00 PM tomorrow evening */
337   static Calendar tomorrowEvening() {
338     GregorianCalendar calendar = new GregorianCalendar();
339     calendar.add(Calendar.DATE,1);
340     calendar.set(Calendar.HOUR,19);
341     calendar.set(Calendar.MINUTE,0);
342     calendar.set(Calendar.AM_PM,Calendar.PM);
343     return calendar;
344   }
345 
346   /**
347    * Sets the (name-sorted) collection of other participants in this
348    * rowing session. Items in the collection should be instances of
349    * Participant2View.
350    */
351   void setParticipants( Collection participants ) {
352     if ( participants == null ) {
353       throw new IllegalArgumentException( "null participant collection" );
354     }
355     this.participants = participants;
356   }
357 
358   /**
359    * Returns a read-only iterator of "starboard" participants.
360    * Items in the iteration are Strings, formatted for display on a screen.
361    */
362   public Iterator getStarboards() {
363     Iterator retVal = ParticipationForm.selectStarboards( this.participants );
364     return retVal;
365   }
366 
367   /**
368    * Returns a read-only iterator of "port" participants.
369    * Items in the iteration are Strings, formatted for display on a screen.
370    */
371   public Iterator getPorts() {
372     Iterator retVal = ParticipationForm.selectPorts( this.participants );
373     return retVal;
374   }
375 
376   /**
377    * Returns a read-only iterator of "coxswain" participants.
378    * Items in the iteration are Strings, formatted for display on a screen.
379    */
380   public Iterator getCoxswains() {
381     Iterator retVal = ParticipationForm.selectCoxswains( this.participants );
382     return retVal;
383   }
384 
385 } // RowingSessionForm
386 
387 /*
388  * $Log: RowingSessionForm.java,v $
389  * Revision 1.5  2003/02/26 03:38:46  rphall
390  * Added copyright and GPL license
391  *
392  * Revision 1.4  2002/03/24 01:51:28  rphall
393  * Locking and participant changes
394  *
395  * Revision 1.3  2002/02/24 18:17:10  rphall
396  * Fixed bug #514881
397  *
398  * Revision 1.2  2002/02/18 18:07:02  rphall
399  * Ran dos2unix to remove ^M (carriage return) from end of lines
400  *
401  * Revision 1.1.1.1  2002/01/03 21:57:28  rphall
402  * Initial load, 5th try, Jan-03-2002 4:57 PM
403  *
404  * Revision 1.6  2001/12/15 02:27:38  rphall
405  * Removed final, made extensible
406  *
407  * Revision 1.5  2001/12/09 22:12:56  rphall
408  * Fixed day/hour bug
409  *
410  * Revision 1.4  2001/12/04 02:43:36  rphall
411  * Added a logging.
412  * Distinguished CANCEL from SESSIONCANCEL.
413  * Added getDateTimeAsDateObject(), getCalendar() and setters.
414  *
415  * Revision 1.3  2001/12/02 22:07:17  rphall
416  * Replaced stubs with valid methods
417  *
418  * Revision 1.2  2001/12/01 14:07:18  rphall
419  * Major changes
420  *
421  * Revision 1.1  2001/11/28 12:18:39  rphall
422  * Started struts framework for managing rowing sessions
423  *
424  */
425