Source code: com/clra/web/EditMemberInfoAction.java
1 /*
2 * Copyright (c) Carnegie Lake Rowing Association 2002. All rights reserved.
3 * Distributed under the GPL license. See doc/COPYING.
4 * $RCSfile: EditMemberInfoAction.java,v $
5 * $Date: 2003/02/26 03:38:46 $
6 * $Revision: 1.12 $
7 */
8
9 package com.clra.web;
10
11 import com.clra.member.MemberDBRead;
12 import com.clra.member.MemberSnapshot;
13 import com.clra.member.MemberName;
14 import com.clra.member.Address;
15 import com.clra.member.Telephone;
16 import com.clra.util.ErrorUtils;
17
18 import java.io.IOException;
19 import java.util.ArrayList;
20 import java.util.Calendar;
21 import java.util.Collection;
22 import java.util.Date;
23 import java.util.Map;
24 import javax.ejb.CreateException;
25 import javax.naming.NamingException;
26 import javax.servlet.ServletException;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpSession;
29 import javax.servlet.http.HttpServletResponse;
30 import org.apache.log4j.Category;
31 import org.apache.struts.action.Action;
32 import org.apache.struts.action.ActionForm;
33 import org.apache.struts.action.ActionForward;
34 import org.apache.struts.action.ActionMapping;
35 import org.apache.struts.action.ActionError;
36 import org.apache.struts.action.ActionErrors;
37
38 /**
39 * A workflow manager that sets up an input form that queries a user for
40 * information needed to maintain the user's personal information.
41 * See the related workflow manager, <tt>SaveMemberInfoAction</tt>,
42 * which pulls information from the input form and invokes the business
43 * logic that does the actual work of editing the personal information.
44 *
45 * The 'function' parameter is 'Edit' or 'Manage'.
46 * For 'Edit', retrieve a MemberSnapshot for the member specified by the
47 * parameter 'id'.
48 * For 'Manage', present a blank form.
49 *
50 * @author <a href="mailto:jmstone@nerc.com"> Jan Stone </a>
51 * @see MemberInfoForm
52 * @see SaveMemberInfoAction
53 */
54
55 public final class EditMemberInfoAction extends Action {
56
57 private final static String base = EditMemberInfoAction.class.getName();
58 private final static Category theLog = Category.getInstance( base );
59
60 /**
61 * Indicates the purpose of this workflow is to edit an
62 * existing member with restrictions (by a member of the club)
63 */
64 public final static String FUNCTION_MEMBEREDIT =
65 MemberInfoForm.FUNCTION_MEMBEREDIT;
66
67 /**
68 * Indicates the purpose of this workflow is to create
69 * a new member.
70 */
71 public final static String FUNCTION_ADMINCREATE =
72 MemberInfoForm.FUNCTION_ADMINCREATE;
73
74 /**
75 * Indicates the purpose of this workflow is to edit an
76 * existing member without restriction (by an admin of the club)
77 */
78 public final static String FUNCTION_ADMINEDIT =
79 MemberInfoForm.FUNCTION_ADMINEDIT;
80
81 /**
82 * Handle the workflow step in which a form is popluated with data from
83 * the database.
84 *
85 * @param mapping The ActionMapping used to select this instance
86 * @param actionForm The optional ActionForm bean for this request (if any)
87 * @param request The HTTP request we are processing
88 * @param response The HTTP response we are creating
89 *
90 * @exception IOException if an input/output error occurs
91 * @exception ServletException if a servlet exception occurs
92 **/
93
94 public ActionForward perform( ActionMapping mapping, ActionForm form,
95 HttpServletRequest request, HttpServletResponse response )
96 throws IOException, ServletException {
97
98 // A null return value indicates that processing should continue
99 ActionForward retVal = null;
100
101 String msg;
102
103 // Extract the workflow action
104 HttpSession session = request.getSession();
105 String function = request.getParameter("function");
106
107 if ( theLog.isInfoEnabled() ) {
108 msg = "function = " + function;
109 theLog.info( msg );
110 }
111
112 if ( function == null ) {
113 theLog.error( "form's http request has null function parameter" );
114 retVal = mapping.findForward("failure");
115 }
116
117 // 'AdminCreate': return a nearly blank form with some defaults
118 else if ( function.equalsIgnoreCase(FUNCTION_ADMINCREATE) ) {
119 MemberInfoForm theForm = (MemberInfoForm)(form);
120 theForm.setState( "NJ" );
121 int thisYear = Calendar.getInstance().get(Calendar.YEAR);
122 theForm.setAccountYear( thisYear );
123 theForm.setMember( true );
124 retVal = mapping.findForward("success");
125 }
126
127 // 'MemberEdit': restricted updates to existing database entry
128 // 'AdminEdit': unrestricted updates to existing database entry
129 else if ( function.equalsIgnoreCase(FUNCTION_MEMBEREDIT)
130 || function.equalsIgnoreCase(FUNCTION_ADMINEDIT) ) {
131
132 String idStr = request.getParameter("id");
133 if ( theLog.isInfoEnabled() ) {
134 msg = "member id = '" + idStr + "'";
135 theLog.info( msg );
136 }
137
138 // Populate the member info form
139 if ( form != null ) {
140
141 MemberSnapshot ms = null;
142 try {
143 Integer id = new Integer( idStr );
144 ms = MemberDBRead.findMemberByMemberId( id );
145 }
146 catch( NumberFormatException x ) {
147 theLog.error( "Invalid member id = '" + idStr + "'" );
148 retVal = mapping.findForward("failure");
149 }
150 catch( Exception x ) {
151 theLog.error( "GetMemberFromKey threw an exception", x);
152 retVal = mapping.findForward("failure");
153 }
154
155 // Return value is null if no errors have occurred so far
156 if ( retVal == null ) {
157
158 MemberInfoForm theForm = (MemberInfoForm)(form);
159
160 if ( theLog.isDebugEnabled() ) {
161 theLog.debug("Populating Member Info form");
162 }
163
164 try {
165
166 theForm.setFunction( function );
167
168 MemberName nm = ms.getMemberName();
169 theForm.setFirstName( nm.getFirstName() );
170 theForm.setMiddleName( nm.getMiddleName() );
171 theForm.setLastName( nm.getLastName() );
172 theForm.setSuffix( nm.getSuffix() );
173
174 Address address = ms.getAddress();
175 theForm.setAddress( address );
176 theForm.setStreet1( address.getStreet1() );
177 theForm.setStreet2( address.getStreet2() );
178 theForm.setCity ( address.getCity() );
179 theForm.setState ( address.getState() );
180 theForm.setZip ( address.getZip() );
181
182 Map phoneNumbers = ms.getTelephoneNumbers();
183 Telephone phone = (Telephone)(phoneNumbers.get(Telephone.EVENING));
184
185 if ( theLog.isDebugEnabled() ) {
186 msg = "Evening phone = " + phone.toString();
187 theLog.debug( msg );
188 }
189
190 theForm.setPhoneEveningAreaCode ( phone.getAreaCode() );
191 theForm.setPhoneEveningExchange ( phone.getExchange() );
192 theForm.setPhoneEveningLocal ( phone.getLocal() );
193 theForm.setPhoneEveningExt ( phone.getExtension() );
194
195 phone = (Telephone)(phoneNumbers.get(Telephone.DAY));
196 if ( theLog.isDebugEnabled() ) {
197 msg = "Day phone == '" +
198 ( phone == null ? "null" : phone.toString() ) + "'";
199 theLog.debug( msg );
200 }
201 if ( phone != null ) {
202
203 theForm.setPhoneDayAreaCode ( phone.getAreaCode() );
204 theForm.setPhoneDayExchange ( phone.getExchange() );
205 theForm.setPhoneDayLocal ( phone.getLocal() );
206 theForm.setPhoneDayExt ( phone.getExtension() );
207 }
208
209 phone = (Telephone)(phoneNumbers.get(Telephone.OTHER));
210 if ( theLog.isDebugEnabled() ) {
211 msg = "Other phone == '" +
212 ( phone == null ? "null" : phone.toString() ) + "'";
213 theLog.debug( msg );
214 }
215 if ( phone != null ) {
216
217 theForm.setPhoneOtherAreaCode ( phone.getAreaCode() );
218 theForm.setPhoneOtherExchange ( phone.getExchange() );
219 theForm.setPhoneOtherLocal ( phone.getLocal() );
220 theForm.setPhoneOtherExt ( phone.getExtension() );
221 }
222
223 if ( ms.hasEmail() ) {
224 theForm.setEmail( ms.getEmail().toString() );
225 }
226
227 theForm.setId( ms.getId() );
228 theForm.setAccountName( ms.getAccountName() );
229 theForm.setAccountNameOriginal( ms.getAccountName() );
230 theForm.setAccountPassword( ms.getAccountPassword() );
231 theForm.setConfirmPassword( ms.getAccountPassword() );
232
233 int y = 1900 + ms.getAccountDate().getYear();
234 theForm.setAccountYear( y );
235
236 theForm.setAccountTypeStr( ms.getAccountType().toString() );
237
238 theForm.setMemberRoles( ms.getMemberRoles() );
239
240 if ( ms.hasKnownBirthDate() ) {
241 theForm.setBirthDate( ms.getBirthDate() );
242 }
243
244 if ( theLog.isInfoEnabled() ) {
245
246 msg = "Member name = '" + theForm.getFullName() + "'";
247 theLog.info( msg );
248
249 StringBuffer sb = new StringBuffer();
250 sb.append( "Evening phone = '" );
251 sb.append( theForm.getPhoneEveningAreaCode().toString() );
252 sb.append( " " );
253 sb.append( theForm.getPhoneEveningExchange() );
254 sb.append( "-" );
255 sb.append( theForm.getPhoneEveningLocal() );
256 sb.append( " (ext. " );
257 sb.append( theForm.getPhoneEveningExt() );
258 sb.append( ")" );
259 msg = new String(sb);
260 theLog.info( msg );
261
262 msg = "Account year = " + theForm.getAccountYear();
263 theLog.info( msg );
264
265 msg = "street1 = " + address.getStreet1();
266 theLog.info( msg );
267
268 msg = "street2 = " + address.getStreet2();
269 theLog.info( msg );
270
271 msg = "city = " + address.getCity();
272 theLog.info( msg );
273
274 msg = "state = " + address.getState();
275 theLog.info( msg );
276
277 msg = "zip = " + address.getZip();
278 theLog.info( msg );
279 }
280
281 retVal = mapping.findForward("success");
282
283 } // end try
284
285 catch ( Exception m ) {
286 theLog.error( "Error populating form", m );
287 retVal = mapping.findForward("failure");
288 }
289
290 // Processing is complete.
291 } // end if ( retVal == null )
292
293 } // end if form != null
294
295 // Missing form
296 else {
297 theLog.error( "unexpected null form" );
298 retVal = mapping.findForward("failure");
299 }
300
301 } // end if AdminEdit || MemberEdit
302
303 // Invalid 'function' parameter
304 else {
305 theLog.error( "unrecognized function parameter: '" + function + "'" );
306 retVal = mapping.findForward("failure");
307 }
308
309 // Forward control to the appropriate page
310 if ( retVal == null ) {
311 throw new Error( "design error" );
312 }
313 if ( theLog.isDebugEnabled() ) {
314 theLog.debug( "Forwarding to " + retVal.toString() );
315 }
316
317 return retVal;
318 } // perform
319
320
321 } // EditMemberInfoAction
322
323 /*
324 * $Log: EditMemberInfoAction.java,v $
325 * Revision 1.12 2003/02/26 03:38:46 rphall
326 * Added copyright and GPL license
327 *
328 * Revision 1.11 2003/02/24 13:29:54 rphall
329 * Added handling for when accountName changes
330 *
331 * Revision 1.10 2003/02/20 16:27:41 rphall
332 * Minor: removed obsolete comment
333 *
334 * Revision 1.9 2003/02/20 04:49:36 rphall
335 * Reorganized perform method
336 *
337 */
338