KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > projectmanagement > presentation > employees > Edit


1 package projectmanagement.presentation.employees;
2
3 import projectmanagement.*;
4 import projectmanagement.presentation.*;
5
6 import projectmanagement.spec.employee.*;
7 import projectmanagement.spec.*;
8 import com.lutris.appserver.server.httpPresentation.*;
9 import org.enhydra.xml.xmlc.XMLObject;
10
11 import org.w3c.dom.*;
12 import org.w3c.dom.html.*;
13
14 import java.sql.Date JavaDoc;
15 import java.util.*;
16
17 /**
18  * Manages all actions on employees.
19  *
20  * @author Sasa Bojanic
21  * @version 1.0
22  */

23 public class Edit extends BasePO {
24
25    /**
26     * Constants
27     */

28    private static String JavaDoc FIRST_NAME = "txtFirstName";
29    private static String JavaDoc LAST_NAME = "txtLastName";
30    private static String JavaDoc LOGIN = "txtLogin";
31    private static String JavaDoc PASSWORD = "txtPassword";
32    private static String JavaDoc TITLE = "txtTitle";
33    private static String JavaDoc TITLE_OF_COURTESY = "txtTitleOfCourtesy";
34    private static String JavaDoc BIRTH_DATE_YYYY = "txtBirthDateYYYY";
35    private static String JavaDoc BIRTH_DATE_MM = "txtBirthDateMM";
36    private static String JavaDoc BIRTH_DATE_DD = "txtBirthDateDD";
37    private static String JavaDoc HIRE_DATE_YYYY = "txtHireDateYYYY";
38    private static String JavaDoc HIRE_DATE_MM = "txtHireDateMM";
39    private static String JavaDoc HIRE_DATE_DD = "txtHireDateDD";
40    private static String JavaDoc ADDRESS = "txtAddress";
41    private static String JavaDoc CITY = "txtCity";
42    private static String JavaDoc REGION = "txtRegion";
43    private static String JavaDoc POSTAL_CODE = "txtPostalCode";
44    private static String JavaDoc COUNTRY = "txtCountry";
45    private static String JavaDoc HOME_PHONE = "txtHomePhone";
46    private static String JavaDoc MOBILE_PHONE = "txtMobilePhone";
47    private static String JavaDoc EMAIL = "txtEmail";
48    private static String JavaDoc NOTES = "txtNotes";
49    private static String JavaDoc IS_ADMIN = "cbxIsAdmin";
50
51    private static String JavaDoc EMPLOYEE_ID = "employeeID";
52    private static String JavaDoc CONTEXT_PAGE = "Context.po";
53    private static String JavaDoc ADD = "add";
54    private static String JavaDoc DELETE = "delete";
55    private static String JavaDoc MODIFY = "modify";
56    private static String JavaDoc DETAILS = "showDetailsPage";
57    private static String JavaDoc EVENT = "event";
58
59    /**
60     * Superclass method override. Returns 1.
61     */

62    protected int getRequiredAuthLevel() {
63       String JavaDoc event="";
64       try {
65          event=this.getComms().request.getParameter(EVENT);
66       } catch (Exception JavaDoc ex) {}
67
68       if (event!=null && event.equalsIgnoreCase(DETAILS)) {
69          return 1;
70       } else {
71          return 2;
72       }
73    }
74
75    /**
76     * Default event. Just show the page for editing.
77     */

78    public XMLObject handleDefault()
79          throws HttpPresentationException {
80       return showModifyPage(null,false);
81    }
82
83    /**
84     * handle show add employee page event.
85     *
86     * @return html document
87     * @exception HttpPresentationException
88     */

89    public XMLObject handleShowAddPage()
90       throws HttpPresentationException {
91       return showAddPage(null);
92    }
93
94    /**
95     * handle show details employee page event.
96     *
97     * @return html document
98     * @exception HttpPresentationException
99     */

100    public XMLObject handleShowDetailsPage ()
101          throws HttpPresentationException {
102       return showModifyPage(null,true);
103    }
104
105    /*
106     * Modifies an existing employee
107     *
108     * @return html document
109     * @exception HttpPresentationException
110     */

111    public XMLObject handleModify()
112          throws HttpPresentationException {
113       String JavaDoc employeeID = this.getComms().request.getParameter(EMPLOYEE_ID);
114       Employee employee=null;
115
116       // Try to get the employee by its ID
117
try {
118   
119     EmployeeManager employeeManager = EmployeeManagerFactory.getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
120     employee = employeeManager.findEmployeeByID(employeeID);
121    
122       } catch(Exception JavaDoc ex) {
123          this.getSessionData().setUserMessage("Please choose a valid employee to edit");
124          throw new ClientPageRedirectException(CONTEXT_PAGE);
125       }
126
127       try {
128          // check if the username already exists
129
if (!isExistingLogin(employee)) {
130             saveEmployee(employee);
131             throw new ClientPageRedirectException(CONTEXT_PAGE);
132          } else {
133             return showModifyPage("The login you've entered already exists !",false);
134          }
135       } catch(Exception JavaDoc ex) {
136          return showModifyPage("To modify this employee, you must fill out fields properly!",false);
137       }
138    }
139
140    /*
141     * Adds a employee to the employee database
142     *
143     * @return html document
144     * @exception HttpPresentationException
145     */

146    public XMLObject handleAdd()
147          throws HttpPresentationException {
148       try {
149    
150          EmployeeManager employeeManager = EmployeeManagerFactory.getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
151          Employee employee = employeeManager.getEmployee();
152       
153          // check if the username already exists
154
if (!isExistingLogin(employee)) {
155             saveEmployee(employee);
156             throw new ClientPageRedirectException(CONTEXT_PAGE);
157          } else {
158             return showAddPage("The login you've entered already exists !");
159          }
160 /*
161  * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run ProjectManagement_pres )
162  * We need to allow ProjectManagement_pres to be functional , response
163  * will be default HTML page
164  */

165      } catch(NullPointerException JavaDoc ex) {
166           return showAddPage("You cannot add employee while runing ProjectManagement_pres");
167      } catch(Exception JavaDoc ex) {
168          return showAddPage("To add this employee, you must fill out fields properly!");
169       }
170    }
171
172    /*
173     * Deletes a Employee from the Employee database
174     *
175     * @return html document
176     * @exception HttpPresentationException
177     */

178    public XMLObject handleDelete()
179          throws HttpPresentationException, ProjectManagementPresentationException {
180       String JavaDoc employeeID = this.getComms().request.getParameter(EMPLOYEE_ID);
181
182       try {
183     
184      EmployeeManager employeeManager = EmployeeManagerFactory.getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
185      Employee employee = employeeManager.findEmployeeByID(employeeID);
186      
187          String JavaDoc fullName = employee.getFirstName() + " " + employee.getLastName();
188          employee.delete();
189          this.getSessionData().setUserMessage("The employee, " + fullName + ", was deleted");
190          // Catch any possible database exception as well as the null pointer
191
// exception if the employee is not found and is null after findEmployeeByID
192
} catch(Exception JavaDoc ex) {
193          this.getSessionData().setUserMessage("Please choose a valid employee to delete");
194       }
195       // Redirect to the catalog page which will display the error message,
196
// if there was one set by the above exception
197
throw new ClientPageRedirectException(CONTEXT_PAGE);
198    }
199
200    /**
201     * Produce HTML for this PO, populated by the employee information
202     * that the user wants to edit
203     *
204     * @param errorMsg, the error messages
205     * @param disabled, if controls are disabled
206     * @return html document
207     * @exception HttpPresentationException
208     */

209    public XMLObject showModifyPage(String JavaDoc errorMsg,boolean disabled)
210          throws HttpPresentationException, ProjectManagementPresentationException {
211
212       String JavaDoc firstName = this.getComms().request.getParameter(FIRST_NAME);
213       String JavaDoc lastName = this.getComms().request.getParameter(LAST_NAME);
214       String JavaDoc login = this.getComms().request.getParameter(LOGIN);
215       String JavaDoc password = this.getComms().request.getParameter(PASSWORD);
216       String JavaDoc title = this.getComms().request.getParameter(TITLE);
217       String JavaDoc titleOfCourtesy = this.getComms().request.getParameter(TITLE_OF_COURTESY);
218       String JavaDoc birthDateYYYY = this.getComms().request.getParameter(BIRTH_DATE_YYYY);
219       String JavaDoc birthDateMM = this.getComms().request.getParameter(BIRTH_DATE_MM);
220       String JavaDoc birthDateDD = this.getComms().request.getParameter(BIRTH_DATE_DD);
221       String JavaDoc hireDateYYYY = this.getComms().request.getParameter(HIRE_DATE_YYYY);
222       String JavaDoc hireDateMM = this.getComms().request.getParameter(HIRE_DATE_MM);
223       String JavaDoc hireDateDD = this.getComms().request.getParameter(HIRE_DATE_DD);
224       String JavaDoc address = this.getComms().request.getParameter(ADDRESS);
225       String JavaDoc city = this.getComms().request.getParameter(CITY);
226       String JavaDoc region = this.getComms().request.getParameter(REGION);
227       String JavaDoc postalCode = this.getComms().request.getParameter(POSTAL_CODE);
228       String JavaDoc country = this.getComms().request.getParameter(COUNTRY);
229       String JavaDoc homePhone = this.getComms().request.getParameter(HOME_PHONE);
230       String JavaDoc mobilePhone = this.getComms().request.getParameter(MOBILE_PHONE);
231       String JavaDoc email = this.getComms().request.getParameter(EMAIL);
232       String JavaDoc notes = this.getComms().request.getParameter(NOTES);
233       String JavaDoc isAdmin = this.getComms().request.getParameter(IS_ADMIN);
234
235       String JavaDoc employeeID = this.getComms().request.getParameter(EMPLOYEE_ID);
236       // Instantiate the page object
237
EditHTML page = new EditHTML();
238
239       Employee employee = null;
240
241       try {
242   
243        EmployeeManager employeeManager = EmployeeManagerFactory.getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
244        employee = employeeManager.findEmployeeByID(employeeID);
245            
246       
247   /*
248  * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run ProjectManagement_pres )
249  * We need to allow ProjectManagement_pres to be functional , response
250  * will be default HTML page with message
251  */

252        } catch(NullPointerException JavaDoc ex) {
253            page.setTextErrorText("This is a default HTML page");
254            return page;
255         // Catch any possible database exception in findEmployeeByID()
256
} catch(ProjectManagementException ex) {
257          this.getSessionData().setUserMessage("Please choose a valid employee to edit");
258          throw new ClientPageRedirectException(CONTEXT_PAGE);
259       }
260
261       try {
262          // If we received a valid employeeID then try to show the employee's contents,
263
// otherwise try to use the HTML input parameters
264
page.getElementEmployeeID().setValue(employee.getHandle());
265
266          HTMLInputElement el=page.getElementTxtFirstName();
267          el.setDisabled(disabled);
268          if (null != firstName && firstName.length() != 0) {
269             el.setValue(firstName);
270          } else {
271             el.setValue(employee.getFirstName());
272          }
273
274          el=page.getElementTxtLastName();
275          el.setDisabled(disabled);
276          if (null != lastName && lastName.length() != 0) {
277             el.setValue(lastName);
278          } else {
279             el.setValue(employee.getLastName());
280          }
281
282          el=page.getElementTxtLogin();
283          el.setDisabled(disabled);
284          if (!disabled) {
285             if (null != login && login.length() != 0) {
286                el.setValue(login);
287             } else {
288                el.setValue(employee.getLogin());
289             }
290          } else {
291             el.getParentNode().getParentNode().getParentNode().removeChild(el.getParentNode().getParentNode());
292          }
293
294          el=page.getElementTxtPassword();
295          el.setDisabled(disabled);
296          if (!disabled) {
297             if (null != password && password.length() != 0) {
298                el.setValue(password);
299             } else {
300                el.setValue(employee.getPassword());
301             }
302          } else {
303             el.getParentNode().getParentNode().getParentNode().removeChild(el.getParentNode().getParentNode());
304          }
305
306
307          el=page.getElementTxtTitle();
308          el.setDisabled(disabled);
309          if (null != title && title.length() != 0) {
310             el.setValue(title);
311          } else {
312             el.setValue(employee.getTitle());
313          }
314
315          el=page.getElementTxtTitleOfCourtesy();
316          el.setDisabled(disabled);
317          if (null != titleOfCourtesy && titleOfCourtesy.length() != 0) {
318             el.setValue(titleOfCourtesy);
319          } else {
320             el.setValue(employee.getTitleOfCourtesy());
321          }
322
323          el=page.getElementTxtBirthDateYYYY();
324          el.setDisabled(disabled);
325          if (null != birthDateYYYY && birthDateYYYY.length() != 0) {
326             el.setValue(birthDateYYYY);
327          } else {
328             Calendar cal=new GregorianCalendar();
329             cal.setTime(employee.getBirthDate());
330             el.setValue(String.valueOf(cal.get(Calendar.YEAR)));
331          }
332
333          el=page.getElementTxtBirthDateMM();
334          el.setDisabled(disabled);
335          if (null != birthDateMM && birthDateMM.length() != 0) {
336             el.setValue(birthDateMM);
337          } else {
338             Calendar cal=new GregorianCalendar();
339             cal.setTime(employee.getBirthDate());
340             el.setValue(String.valueOf(cal.get(Calendar.MONTH)+1));
341          }
342
343          el=page.getElementTxtBirthDateDD();
344          el.setDisabled(disabled);
345          if (null != birthDateDD && birthDateDD.length() != 0) {
346             el.setValue(birthDateDD);
347          } else {
348             Calendar cal=new GregorianCalendar();
349             cal.setTime(employee.getBirthDate());
350             el.setValue(String.valueOf(cal.get(Calendar.DAY_OF_MONTH)));
351          }
352
353          el=page.getElementTxtHireDateYYYY();
354          el.setDisabled(disabled);
355          if (null != hireDateYYYY && hireDateYYYY.length() != 0) {
356             el.setValue(hireDateYYYY);
357          } else {
358             Calendar cal=new GregorianCalendar();
359             cal.setTime(employee.getHireDate());
360             el.setValue(String.valueOf(cal.get(Calendar.YEAR)));
361          }
362
363          el=page.getElementTxtHireDateMM();
364          el.setDisabled(disabled);
365          if (null != hireDateMM && hireDateMM.length() != 0) {
366             el.setValue(hireDateMM);
367          } else {
368             Calendar cal=new GregorianCalendar();
369             cal.setTime(employee.getHireDate());
370             el.setValue(String.valueOf(cal.get(Calendar.MONTH)+1));
371          }
372
373          el=page.getElementTxtHireDateDD();
374          el.setDisabled(disabled);
375          if (null != hireDateDD && hireDateDD.length() != 0) {
376             el.setValue(hireDateDD);
377          } else {
378             Calendar cal=new GregorianCalendar();
379             cal.setTime(employee.getHireDate());
380             el.setValue(String.valueOf(cal.get(Calendar.DAY_OF_MONTH)));
381          }
382
383          el=page.getElementTxtAddress();
384          el.setDisabled(disabled);
385          if (null != address && address.length() != 0) {
386             el.setValue(address);
387          } else {
388             el.setValue(employee.getAddress());
389          }
390
391          el=page.getElementTxtCity();
392          el.setDisabled(disabled);
393          if (null != city && city.length() != 0) {
394             el.setValue(city);
395          } else {
396             el.setValue(employee.getCity());
397          }
398
399          el=page.getElementTxtRegion();
400          el.setDisabled(disabled);
401          if (null != region && region.length() != 0) {
402             el.setValue(region);
403          } else {
404             el.setValue(employee.getRegion());
405          }
406
407          el=page.getElementTxtPostalCode();
408          el.setDisabled(disabled);
409          if (null != postalCode && postalCode.length() != 0) {
410             el.setValue(postalCode);
411          } else {
412             el.setValue(employee.getPostalCode());
413          }
414
415          el=page.getElementTxtCountry();
416          el.setDisabled(disabled);
417          if (null != country && country.length() != 0) {
418             el.setValue(country);
419          } else {
420             el.setValue(employee.getCountry());
421          }
422
423          el=page.getElementTxtHomePhone();
424          el.setDisabled(disabled);
425          if (null != homePhone && homePhone.length() != 0) {
426             el.setValue(homePhone);
427          } else {
428             el.setValue(employee.getHomePhone());
429          }
430
431          el=page.getElementTxtMobilePhone();
432          el.setDisabled(disabled);
433          if (null != mobilePhone && mobilePhone.length() != 0) {
434             el.setValue(mobilePhone);
435          } else {
436             el.setValue(employee.getMobilePhone());
437          }
438
439          el=page.getElementTxtEmail();
440          el.setDisabled(disabled);
441          if (null != email && email.length() != 0) {
442             el.setValue(email);
443          } else {
444             el.setValue(employee.getEmail());
445          }
446
447          //HTMLTextAreaElement tael=page.getElementTxtNotes();
448
el=page.getElementTxtNotes();
449          el.setDisabled(disabled);
450          if (null != notes && notes.length() != 0) {
451             el.setValue(notes);
452          } else {
453             el.setValue(employee.getNotes());
454          }
455
456          el=page.getElementCbxIsAdmin();
457          el.setDisabled(disabled);
458          if (null != isAdmin) {
459             el.setChecked(true);
460          } else {
461             el.setChecked(false);
462          }
463
464          el=page.getElementBtnSave();
465          el.setDisabled(disabled);
466
467          if (null == errorMsg) {
468             page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText());
469          } else {
470             page.setTextErrorText(errorMsg);
471          }
472       } catch(ProjectManagementException ex) {
473          throw new ProjectManagementPresentationException("Error populating page for employee editing", ex);
474       }
475
476       page.getElementEvent().setValue(MODIFY);
477       return page;
478    }
479
480    /**
481     * Produce HTML for this PO
482     *
483     * @param errorMsg, the error messages
484     * @return html document
485     * @exception HttpPresentationException
486     */

487    public XMLObject showAddPage(String JavaDoc errorMsg)
488          throws HttpPresentationException, ProjectManagementPresentationException {
489     
490       String JavaDoc firstName = this.getComms().request.getParameter(FIRST_NAME);
491       String JavaDoc lastName = this.getComms().request.getParameter(LAST_NAME);
492       String JavaDoc login = this.getComms().request.getParameter(LOGIN);
493       String JavaDoc password = this.getComms().request.getParameter(PASSWORD);
494       String JavaDoc title = this.getComms().request.getParameter(TITLE);
495       String JavaDoc titleOfCourtesy = this.getComms().request.getParameter(TITLE_OF_COURTESY);
496       String JavaDoc birthDateYYYY = this.getComms().request.getParameter(BIRTH_DATE_YYYY);
497       String JavaDoc birthDateMM = this.getComms().request.getParameter(BIRTH_DATE_MM);
498       String JavaDoc birthDateDD = this.getComms().request.getParameter(BIRTH_DATE_DD);
499       String JavaDoc hireDateYYYY = this.getComms().request.getParameter(HIRE_DATE_YYYY);
500       String JavaDoc hireDateMM = this.getComms().request.getParameter(HIRE_DATE_MM);
501       String JavaDoc hireDateDD = this.getComms().request.getParameter(HIRE_DATE_DD);
502       String JavaDoc address = this.getComms().request.getParameter(ADDRESS);
503       String JavaDoc city = this.getComms().request.getParameter(CITY);
504       String JavaDoc region = this.getComms().request.getParameter(REGION);
505       String JavaDoc postalCode = this.getComms().request.getParameter(POSTAL_CODE);
506       String JavaDoc country = this.getComms().request.getParameter(COUNTRY);
507       String JavaDoc homePhone = this.getComms().request.getParameter(HOME_PHONE);
508       String JavaDoc mobilePhone = this.getComms().request.getParameter(MOBILE_PHONE);
509       String JavaDoc email = this.getComms().request.getParameter(EMAIL);
510       String JavaDoc notes = this.getComms().request.getParameter(NOTES);
511       String JavaDoc isAdmin = this.getComms().request.getParameter(IS_ADMIN);
512
513       // Instantiate the page object
514
EditHTML page = new EditHTML();
515
516       HTMLInputElement el=page.getElementTxtFirstName();
517       if (null != firstName) {
518          el.setValue(firstName);
519       } else {
520          el.setValue("");
521       }
522
523       el=page.getElementTxtLastName();
524       if (null != lastName) {
525          el.setValue(lastName);
526       } else {
527          el.setValue("");
528       }
529
530       el=page.getElementTxtLogin();
531       if (null != login) {
532          el.setValue(login);
533       } else {
534          el.setValue("");
535       }
536
537       el=page.getElementTxtPassword();
538       if (null != password) {
539          el.setValue(password);
540       } else {
541          el.setValue("");
542       }
543
544       el=page.getElementTxtTitle();
545       if (null != title) {
546          el.setValue(title);
547       } else {
548          el.setValue("");
549       }
550
551       el=page.getElementTxtTitleOfCourtesy();
552       if (null != titleOfCourtesy) {
553          el.setValue(titleOfCourtesy);
554       } else {
555          el.setValue("");
556       }
557
558
559       el=page.getElementTxtBirthDateYYYY();
560       if (null != birthDateYYYY) {
561          el.setValue(birthDateYYYY);
562       } else {
563          el.setValue("");
564       }
565
566       el=page.getElementTxtBirthDateMM();
567       if (null != birthDateMM) {
568          el.setValue(birthDateMM);
569       } else {
570          el.setValue("");
571       }
572
573       el=page.getElementTxtBirthDateDD();
574       if (null != birthDateDD) {
575          el.setValue(birthDateDD);
576       } else {
577          el.setValue("");
578       }
579
580       el=page.getElementTxtHireDateYYYY();
581       if (null != hireDateYYYY) {
582          el.setValue(hireDateYYYY);
583       } else {
584          el.setValue("");
585       }
586
587       el=page.getElementTxtHireDateMM();
588       if (null != hireDateMM) {
589          el.setValue(hireDateMM);
590       } else {
591          el.setValue("");
592       }
593
594       el=page.getElementTxtHireDateDD();
595       if (null != hireDateDD) {
596          el.setValue(hireDateDD);
597       } else {
598          el.setValue("");
599       }
600
601       el=page.getElementTxtAddress();
602       if (null != address) {
603          el.setValue(address);
604       } else {
605          el.setValue("");
606       }
607
608       el=page.getElementTxtCity();
609       if (null != city) {
610          el.setValue(city);
611       } else {
612          el.setValue("");
613       }
614
615       el=page.getElementTxtRegion();
616       if (null != region) {
617          el.setValue(region);
618       } else {
619          el.setValue("");
620       }
621
622       el=page.getElementTxtPostalCode();
623       if (null != postalCode) {
624          el.setValue(postalCode);
625       } else {
626          el.setValue("");
627       }
628
629       el=page.getElementTxtCountry();
630       if (null != country) {
631          el.setValue(country);
632       } else {
633          el.setValue("");
634       }
635
636       el=page.getElementTxtHomePhone();
637       if (null != homePhone) {
638          el.setValue(homePhone);
639       } else {
640          el.setValue("");
641       }
642
643       el=page.getElementTxtMobilePhone();
644       if (null != mobilePhone) {
645          el.setValue(mobilePhone);
646       } else {
647          el.setValue("");
648       }
649
650       el=page.getElementTxtEmail();
651       if (null != email) {
652          el.setValue(email);
653       } else {
654          el.setValue("");
655       }
656
657       //HTMLTextAreaElement tael=page.getElementTxtNotes();
658
el=page.getElementTxtNotes();
659       if (null != notes) {
660          el.setValue(notes);
661       } else {
662          el.setValue("");
663       }
664
665       el=page.getElementCbxIsAdmin();
666       if (null != isAdmin) {
667          el.setChecked(true);
668       } else {
669          el.setChecked(false);
670       }
671
672
673       if (null == errorMsg) {
674          page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText());
675       } else {
676          page.setTextErrorText(errorMsg);
677       }
678
679       return page;
680    }
681
682    /**
683     * Method to save a new or existing employee to the database
684     *
685     * @param employee, the employee to be saved
686     * @return html document
687     * @exception HttpPresentationException
688     */

689    protected void saveEmployee(Employee theEmployee)
690          throws HttpPresentationException {
691
692       String JavaDoc firstName = this.getComms().request.getParameter(FIRST_NAME);
693       String JavaDoc lastName = this.getComms().request.getParameter(LAST_NAME);
694       String JavaDoc login = this.getComms().request.getParameter(LOGIN);
695       String JavaDoc password = this.getComms().request.getParameter(PASSWORD);
696       String JavaDoc title = this.getComms().request.getParameter(TITLE);
697       String JavaDoc titleOfCourtesy = this.getComms().request.getParameter(TITLE_OF_COURTESY);
698       String JavaDoc birthDateYYYY = this.getComms().request.getParameter(BIRTH_DATE_YYYY);
699       String JavaDoc birthDateMM = this.getComms().request.getParameter(BIRTH_DATE_MM);
700       String JavaDoc birthDateDD = this.getComms().request.getParameter(BIRTH_DATE_DD);
701       String JavaDoc hireDateYYYY = this.getComms().request.getParameter(HIRE_DATE_YYYY);
702       String JavaDoc hireDateMM = this.getComms().request.getParameter(HIRE_DATE_MM);
703       String JavaDoc hireDateDD = this.getComms().request.getParameter(HIRE_DATE_DD);
704       String JavaDoc address = this.getComms().request.getParameter(ADDRESS);
705       String JavaDoc city = this.getComms().request.getParameter(CITY);
706       String JavaDoc region = this.getComms().request.getParameter(REGION);
707       String JavaDoc postalCode = this.getComms().request.getParameter(POSTAL_CODE);
708       String JavaDoc country = this.getComms().request.getParameter(COUNTRY);
709       String JavaDoc homePhone = this.getComms().request.getParameter(HOME_PHONE);
710       String JavaDoc mobilePhone = this.getComms().request.getParameter(MOBILE_PHONE);
711       String JavaDoc email = this.getComms().request.getParameter(EMAIL);
712       String JavaDoc notes = this.getComms().request.getParameter(NOTES);
713       String JavaDoc isAdmin = this.getComms().request.getParameter(IS_ADMIN);
714
715       if (isNullField(firstName) || isNullField(lastName) || isNullField(login)
716           || isNullField(password) || !areDateFieldsValid(birthDateYYYY,birthDateMM,birthDateDD) ||
717           !areDateFieldsValid(hireDateYYYY,hireDateMM,hireDateDD)) {
718          throw new ProjectManagementPresentationException("Error adding employee",new Exception JavaDoc());
719       }
720
721       try {
722          String JavaDoc birthDate=birthDateYYYY+"-"+birthDateMM+"-"+birthDateDD;
723          String JavaDoc hireDate=hireDateYYYY+"-"+hireDateMM+"-"+hireDateDD;
724          theEmployee.setFirstName(firstName);
725          theEmployee.setLastName(lastName);
726          theEmployee.setLogin(login);
727          theEmployee.setPassword(password);
728          theEmployee.setTitle(title);
729          theEmployee.setTitleOfCourtesy(titleOfCourtesy);
730          theEmployee.setBirthDate(Date.valueOf(birthDate));
731          theEmployee.setHireDate(Date.valueOf(hireDate));
732          theEmployee.setAddress(address);
733          theEmployee.setCity(city);
734          theEmployee.setRegion(region);
735          theEmployee.setPostalCode(postalCode);
736          theEmployee.setCountry(country);
737          theEmployee.setHomePhone(homePhone);
738          theEmployee.setMobilePhone(mobilePhone);
739          theEmployee.setEmail(email);
740          theEmployee.setNotes(notes);
741          theEmployee.setIsAdmin(isAdmin!=null);
742          theEmployee.save();
743       } catch(Exception JavaDoc ex) {
744          throw new ProjectManagementPresentationException("Error adding employee", ex);
745       }
746    }
747
748    private boolean isExistingLogin (Employee employee) {
749       boolean isExistingLogin=false;
750       String JavaDoc login = null;
751       try {
752          login=this.getComms().request.getParameter(LOGIN).trim();
753       } catch (Exception JavaDoc exc) {}
754       if (!isNullField(login)) {
755          ProjectManagement pm=getApplication();
756          if (pm.getAdminUsername().equals(login)) {
757             isExistingLogin=true;
758          } else {
759             try {
760       
761   EmployeeManager employeeManager = EmployeeManagerFactory.getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
762   Employee user = employeeManager.findEmployee(login);
763                if (user!=null && (employee==null || !user.getHandle().equals(employee.getHandle()))) {
764                   isExistingLogin=true;
765                }
766             } catch(ProjectManagementException ex) {
767             }
768          }
769       }
770       return isExistingLogin;
771    }
772
773 }
774
775
Popular Tags