KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > business > addressbook > struts > PersonAction


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: PersonAction.java,v $
31  * Revision 1.5 2005/05/10 20:03:34 colinmacleod
32  * Added checking for demo version
33  * so the demo no longer removes users.
34  *
35  * Revision 1.4 2005/05/01 08:43:06 colinmacleod
36  * In clear, no longer removes the session
37  * attributes.
38  *
39  * Revision 1.3 2005/04/10 18:47:36 colinmacleod
40  * Changed i tag to em and b tag to strong.
41  *
42  * Revision 1.2 2005/04/09 17:19:08 colinmacleod
43  * Changed copyright text to GPL v2 explicitly.
44  *
45  * Revision 1.1.1.1 2005/03/10 17:50:25 colinmacleod
46  * Restructured ivata op around Hibernate/PicoContainer.
47  * Renamed ivata groupware.
48  *
49  * Revision 1.9 2004/12/31 18:27:43 colinmacleod
50  * Added MaskFactory to constructor of MaskAction.
51  *
52  * Revision 1.8 2004/12/23 21:01:25 colinmacleod
53  * Updated Struts to v1.2.4.
54  * Changed base classes to use ivata masks.
55  *
56  * Revision 1.7 2004/11/12 18:19:14 colinmacleod
57  * Change action and form classes to extend MaskAction, MaskForm respectively.
58  *
59  * Revision 1.6 2004/11/12 15:57:07 colinmacleod
60  * Removed dependencies on SSLEXT.
61  * Moved Persistence classes to ivata masks.
62  *
63  * Revision 1.5 2004/11/03 15:31:50 colinmacleod
64  * Change method interfaces to remove log.
65  *
66  * Revision 1.4 2004/07/13 19:41:14 colinmacleod
67  * Moved project to POJOs from EJBs.
68  * Applied PicoContainer to services layer (replacing session EJBs).
69  * Applied Hibernate to persistence layer (replacing entity EJBs).
70  *
71  * Revision 1.3 2004/03/21 21:16:08 colinmacleod
72  * Shortened name to ivata op.
73  *
74  * Revision 1.2 2004/02/01 22:00:33 colinmacleod
75  * Added full names to author tags
76  *
77  * Revision 1.1.1.1 2004/01/27 20:57:54 colinmacleod
78  * Moved ivata openportal to SourceForge..
79  *
80  * Revision 1.4 2003/12/12 11:08:58 jano
81  * fixing addressbook functionality
82  *
83  * Revision 1.3 2003/10/17 12:36:12 jano
84  * fixing problems with building
85  * converting intranet -> portal
86  * Eclipse building
87  *
88  * Revision 1.2 2003/10/15 13:18:02 colin
89  * fixing for XDoclet
90  *
91  * Revision 1.18 2003/09/11 13:10:30 jano
92  * fixing bugs with renaming userName and with removing user from system
93  *
94  * Revision 1.17 2003/08/25 08:36:38 jano
95  * fixing bug with new contact and TABS
96  *
97  * Revision 1.16 2003/08/22 15:23:51 jano
98  * fixing bug
99  *
100  * Revision 1.15 2003/08/21 09:49:32 jano
101  * fixing for new addressBook extension
102  *
103  * Revision 1.14 2003/08/20 16:24:15 jano
104  * fixing addressBook extension
105  *
106  * Revision 1.13 2003/07/25 11:41:04 jano
107  * adding functionality for addressBook extension
108  *
109  * Revision 1.12 2003/06/18 14:22:12 jano
110  * fixing problem with removing user
111  * and spaces in userName
112  * and capitals in userName
113  *
114  * Revision 1.11 2003/06/10 10:42:15 peter
115  * changed keys when flushing tree JSP caches
116  *
117  * Revision 1.10 2003/06/09 08:14:49 jano
118  * fixing user aliases and his emails
119  *
120  * Revision 1.9 2003/06/04 09:57:54 jano
121  * fixing addUser to Person
122  * and email if user has not it
123  *
124  * Revision 1.8 2003/06/04 07:17:23 peter
125  * jndiPrefix test fixed
126  *
127  * Revision 1.7 2003/04/09 13:29:17 jano
128  * fixing bug
129  *
130  * Revision 1.6 2003/04/09 12:10:22 jano
131  * *** empty log message ***
132  *
133  * Revision 1.5 2003/04/09 09:43:55 jano
134  * *** empty log message ***
135  *
136  * Revision 1.4 2003/04/09 08:53:20 jano
137  * handling data of removing user
138  *
139  * Revision 1.3 2003/02/25 17:45:57 colin
140  * no longer refreshes the opener on cancel
141  *
142  * Revision 1.2 2003/02/25 14:38:13 colin
143  * implemented setModified methods on entity beans thro IvataEntityBean
144  * superclass
145  *
146  * Revision 1.1 2003/02/24 19:09:21 colin
147  * moved to business
148  *
149  * Revision 1.14 2003/02/21 10:06:41 colin
150  * added missing import for EmployeeDO
151  *
152  * Revision 1.13 2003/02/21 09:50:56 colin
153  * fixed bug - null employee on apply
154  *
155  * Revision 1.12 2003/02/20 20:23:17 colin
156  * improved validation error handling
157  *
158  * Revision 1.11 2003/02/20 16:18:31 colin
159  * fixed algorithm for adding email address to people
160  *
161  * Revision 1.10 2003/02/20 13:57:07 colin
162  * moved amendPerson to end
163  *
164  * Revision 1.9 2003/02/20 13:46:37 colin
165  * changed jndiPrefix handling to application server
166  *
167  * Revision 1.8 2003/02/20 13:33:46 colin
168  * update person when extra email address is added
169  *
170  * Revision 1.7 2003/02/20 13:31:10 colin
171  * added checking for an email address with users
172  *
173  * Revision 1.6 2003/02/20 08:32:07 colin
174  * made apply also go thro execute to catch changes to main group id
175  *
176  * Revision 1.5 2003/02/20 07:45:24 colin
177  * fixed bug where name of main group doesn't show in personSummary.jsp
178  *
179  * Revision 1.4 2003/02/18 11:10:27 colin
180  * first release of address book with Struts
181  *
182  * Revision 1.3 2003/02/14 08:59:48 colin
183  * changed findParentGroups... to findGroups...
184  *
185  * Revision 1.2 2003/02/04 17:39:47 colin
186  * updated for new struts interface
187  *
188  * Revision 1.1 2003/01/30 15:27:28 colin
189  * first version
190  * -----------------------------------------------------------------------------
191  */

192 package com.ivata.groupware.business.addressbook.struts;
193
194 import java.util.HashMap JavaDoc;
195 import java.util.HashSet JavaDoc;
196 import java.util.Iterator JavaDoc;
197 import java.util.List JavaDoc;
198 import java.util.Map JavaDoc;
199 import java.util.Vector JavaDoc;
200
201 import javax.servlet.http.HttpServletRequest JavaDoc;
202 import javax.servlet.http.HttpServletResponse JavaDoc;
203 import javax.servlet.http.HttpSession JavaDoc;
204
205 import org.apache.log4j.Logger;
206 import org.apache.struts.action.ActionErrors;
207 import org.apache.struts.action.ActionForm;
208 import org.apache.struts.action.ActionMapping;
209
210 import com.ivata.groupware.admin.security.addressbook.AddressBookSecurity;
211 import com.ivata.groupware.admin.security.right.SecurityRights;
212 import com.ivata.groupware.admin.security.server.SecuritySession;
213 import com.ivata.groupware.admin.security.user.UserDO;
214 import com.ivata.groupware.admin.security.user.UserConstants;
215 import com.ivata.groupware.admin.setting.Settings;
216 import com.ivata.groupware.business.addressbook.AddressBook;
217 import com.ivata.groupware.business.addressbook.address.AddressDO;
218 import com.ivata.groupware.business.addressbook.person.PersonDO;
219 import com.ivata.groupware.business.addressbook.person.employee.EmployeeDO;
220 import com.ivata.groupware.business.addressbook.person.group.GroupConstants;
221 import com.ivata.groupware.business.addressbook.person.group.GroupDO;
222 import com.ivata.groupware.business.addressbook.right.AddressBookRights;
223 import com.ivata.mask.MaskFactory;
224 import com.ivata.mask.util.StringHandling;
225 import com.ivata.mask.util.SystemException;
226 import com.ivata.mask.web.struts.MaskAction;
227 import com.ivata.mask.web.struts.MaskAuthenticator;
228
229
230 /**
231  * <p>Invoked when the user edits, displays or enters a new person -
232  * it's all the same to ivata groupware.</p>
233  *
234  * @since 2003-01-26
235  * @author Colin MacLeod
236  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
237  * @version $Revision: 1.5 $
238  *
239  * @TODO dependency AddressbookAction on WebMail
240  */

241 public class PersonAction extends MaskAction {
242     /**
243      * <p>This log provides tracing and debugging information.</p>
244      */

245     private static Logger log = Logger.getLogger(PersonAction.class);
246     private AddressBook addressBook;
247     private AddressBookRights addressBookRights;
248     private AddressBookSecurity security;
249     private SecurityRights securityRights;
250     private Settings settings;
251
252     /**
253      * <p>
254      * TODO
255      * </p>
256      *
257      * @param addressBook
258      * @param addressBookRights
259      * @param security
260      * @param securityRights
261      * @param settings
262      * @param maskFactory This factory is needed to access the masks and groups
263      * of masks.
264      * @param authenticator used to confirm whether or not the
265      * user should be allowed to continue, in the <code>execute</code> method.
266      */

267     public PersonAction(AddressBook addressBook,
268             AddressBookRights addressBookRights,
269             AddressBookSecurity security, SecurityRights securityRights,
270             Settings settings,
271             MaskFactory maskFactory, MaskAuthenticator authenticator) {
272         super(maskFactory, authenticator);
273         this.addressBook = addressBook;
274         this.addressBookRights = addressBookRights;
275         this.security = security;
276         this.securityRights = securityRights;
277         this.settings = settings;
278     }
279
280     /**
281      * <p>Called when the clear button is pressed, or after an ok or
282      * delete button, where the session should be restored to its default
283      * state.</p>
284      *
285      * @param mapping current action mapping from <em>Struts</em> config.
286      * @param log valid logging object to write messages to.
287      * @param errors valid errors object to append errors to. If there are
288      * any errors, the action will return to the input.
289      * @param form optional ActionForm bean for this request (if any)
290      * @param request non-HTTP request we are processing
291      * @param response The non-HTTP response we are creating
292      * @param session returned from the <code>request</code> parameter.
293      * @param userName valid, non-null user name from session.
294      * @param settings valid, non-null settings from session.
295      * @exception SystemException if there is any problem which
296      * prevents processing. It will result in the webapp being forwarded
297      * to
298      * the standard error page.
299      */

300     public void clear(final ActionMapping mapping,
301             final ActionErrors errors,
302             final ActionForm form,
303             final HttpServletRequest JavaDoc request,
304             final HttpServletResponse JavaDoc response,
305             final HttpSession JavaDoc session) throws SystemException {
306         if (log.isDebugEnabled()) {
307             log.debug("In PersonAction.clear");
308         }
309
310         PersonForm personForm = (PersonForm) form;
311         personForm.clear();
312         if (personForm.getRefreshOnExit()
313                 && StringHandling.isNullOrEmpty(personForm.getClear())) {
314             // set the opener page to the address book
315
request.setAttribute("openerPage", "/addressBook/index.action");
316         }
317
318         if (log.isDebugEnabled()) {
319             log.debug("Out PersonAction.clear");
320         }
321     }
322
323     /**
324      * <p>Overridden from the default intranet implementation to
325      * process tab changes.</p>
326      *
327      * @param mapping current action mapping from <em>Struts</em> config.
328      * @param log valid logging object to write messages to.
329      * @param errors valid errors object to append errors to. If there
330      * are any errors, the action will return to the input.
331      * @param form optional ActionForm bean for this request (if any)
332      * @param request non-HTTP request we are processing
333      * @param response The non-HTTP response we are creating
334      * @param session returned from the <code>request</code> parameter.
335      * @param userName current user name from session. .
336      * @param settings valid, non-null settings from session.
337      * @exception SystemException if there is any problem which
338      * prevents processing. It will result in the webapp being forwarded
339      * to
340      * the standard error page.
341      * @return this method returns the string used to identify the correct
342      * <em>Struts</em> <code>ActionForward</code> which should follow this
343      * page, or <code>null</code> if it should return to the input.
344      */

345     public String JavaDoc execute(final ActionMapping mapping,
346             final ActionErrors errors,
347             final ActionForm form,
348             final HttpServletRequest JavaDoc request,
349             final HttpServletResponse JavaDoc response,
350             final HttpSession JavaDoc session) throws SystemException {
351         if (log.isDebugEnabled()) {
352             log.debug("In PersonAction.execute");
353         }
354
355         SecuritySession securitySession = (SecuritySession)
356             session.getAttribute("securitySession");
357         PersonForm personForm = (PersonForm) form;
358
359         // Shouldn't struts do this? *confused*
360
session.setAttribute("addressBookPersonForm", personForm);
361
362         // see if the address book groups are there - if not, initialize them
363
// from the address book service layer
364
Map JavaDoc addressBookGroupNames = personForm.getAddressBookGroupNames();
365         if (addressBookGroupNames == null) {
366             personForm.setAddressBookGroupNames(addressBookGroupNames =
367                 new HashMap JavaDoc());
368             List JavaDoc allAddressBookGroups = addressBook.findAddressBooks(
369                     securitySession, true);
370             Iterator JavaDoc groupIterator = allAddressBookGroups.iterator();
371             while(groupIterator.hasNext()) {
372                 GroupDO addressBookGroup = (GroupDO) groupIterator.next();
373                 addressBookGroupNames.put(addressBookGroup.getId(),
374                         addressBookGroup.getName());
375             }
376         }
377         // users are always in the default public address book
378
PersonDO person = personForm.getPerson();
379         if (!StringHandling.isNullOrEmpty(personForm.getUserName())
380                 || (personForm.getAddressBookGroupId() == null)) {
381             GroupDO defaultAddressBook =
382                 addressBook.findGroupByPrimaryKey(securitySession,
383                         GroupConstants.ADDRESS_BOOK_DEFAULT);
384             personForm.setAddressBookGroupId(defaultAddressBook.getId());
385             personForm.setAddressBookGroupName(defaultAddressBook.getName());
386             person.setGroup(defaultAddressBook);
387         } else {
388             // update the address book name to match the id
389
personForm.setAddressBookGroupName((String JavaDoc)
390                     addressBookGroupNames.get(
391                             personForm.getAddressBookGroupId()));
392         }
393
394         // get/set a list of all possible user groups
395
if (personForm.getUserGroups() == null) {
396             personForm.setUserGroups(addressBook.findUserGroups(securitySession,
397                     true));
398         }
399
400         // ensure there is an address object we can use
401
if (person.getAddress() == null) {
402             person.setAddress(new AddressDO());
403         }
404         // and ensure there is an employee
405
if (person.getEmployee() == null) {
406             person.setEmployee(new EmployeeDO());
407         }
408
409         // likewise, we need a country
410
personForm.findAndSetCountry(securitySession);
411
412         GroupDO group = person.getGroup();
413         if (group == null) {
414             person.setGroup(group = new GroupDO());
415         }
416         UserDO user = person.getUser();
417         if (user == null) {
418             person.setUser(user = new UserDO());
419         }
420         if (user.getGroups() == null) {
421             user.setGroups(new HashSet JavaDoc());
422         }
423
424         // update the telecom addresses in the person
425
personForm.setPersonFromTelecomAddresses();
426
427
428         String JavaDoc activeTabKey =
429             (personForm.getPersonTab_activeTabKey() == null)
430             ? ""
431             : personForm.getPersonTab_activeTabKey();
432
433         // if we want to restore user
434
// but really restore her only on Apply/OK button
435
if (!StringHandling.isNullOrEmpty(personForm.getRestoreUser())) {
436             user.setDeleted(false);
437             personForm.setUserName(person.getUser().getName());
438             // TODO personForm.getUserAliases().add(personForm.getUserName());
439

440             // add the first one as an email address
441
int size = personForm.getTelecomAddresses().size();
442             String JavaDoc emailSubHost =
443                 settings.getStringSetting(
444                     securitySession,
445                     "emailSubHost",
446                     user);
447
448
449 /*TODO TelecomAddressDO newAddress = new TelecomAddressDO();
450             newAddress.setAddress(personForm.getUserName()
451              + "@" + emailSubHost);
452             newAddress.setNumber(telecomAddresses.size());
453             newAddress.setType(TelecomAddressConstants.TYPE_EMAIL);
454             telecomAddresses.add(newAddress);
455             personForm.setRestoreUser("");*/

456         }
457
458         // create the keys of all the tabs we want to show
459
List JavaDoc tabKeys = personForm.getTabKeys();
460         if (tabKeys == null) {
461             personForm.setTabKeys(tabKeys = new Vector JavaDoc());
462         } else {
463             tabKeys.clear();
464         }
465
466         // first the standard ones - these are always shown
467
tabKeys.add("person.tab.contact");
468         tabKeys.add("person.tab.address");
469         tabKeys.add("person.tab.telecomAddress");
470
471         // only show the extra tabs if this is not a new contact - you must
472
// add a contact first before you can make him/her a user or employee
473
if (person.getId() != null) {
474             // if this is a user, show a different delete warning message
475
if (user.getId() != null) {
476                 personForm.setDeleteKey("person.alert.delete.user");
477             } else {
478                 personForm.setDeleteKey("person.alert.delete");
479             }
480
481             // user tab is only shown if the person already has a user, or the
482
// current user has the rights to add one
483
if ((user.getId() != null)
484                     || securityRights.canAddUser(securitySession)) {
485                 tabKeys.add("person.tab.user");
486             }
487             // groups tab is only shown if the person has a user - you need to
488
// add one first, then apply to change the groups.
489
// TODO: for now this is never shown: remove the 'false &&' when
490
// user rights are enabled again
491
if (false
492                     && (user.getId() != null)) {
493                 tabKeys.add("person.tab.groups");
494             }
495             // employee tab is only shown if the user has the rights
496
if (addressBookRights.canAddEmployeeToPerson(securitySession,
497                     person)) {
498                 tabKeys.add("person.tab.employee");
499             }
500         }
501         // set Up READ ONLY flag
502
personForm.setReadOnly(!addressBookRights.canAmendInGroup(
503                 securitySession, person.getGroup().getAddressBook()));
504         if (personForm.getReadOnly()
505                 && person.getCreatedBy().equals(securitySession.getUser())) {
506             personForm.setReadOnly(false);
507         }
508         // set Up CAN REMOVE flag - the only person you definitely can't
509
// remove is the root administrator user
510
boolean canRemove = addressBookRights.canRemoveFromGroup(
511                 securitySession, person.getGroup().getAddressBook())
512                 && !UserConstants.ADMINISTRATOR.equals(
513                                 personForm.getPerson().getId());
514         // users cannot be removed if this is a demo
515
Boolean JavaDoc demoVersion = settings.getBooleanSetting(securitySession,
516             "demoVersion", null);
517         if (demoVersion.booleanValue()
518                 && (person.getUser() != null)
519                 && (person.getUser().getId() != null)) {
520             canRemove = false;
521         }
522         personForm.setCanRemove(canRemove);
523
524         if ("person.tab.address".equals(activeTabKey)) {
525             personForm.setTabPage("/addressBook/address.jsp");
526             personForm.setHelpKey("addressbook.address");
527         } else if ("person.tab.telecomAddress".equals(activeTabKey)) {
528             personForm.setTabPage("/addressBook/telecomAddress.jsp");
529             personForm.setHelpKey("addressbook.telecomAddress");
530             // and update the telecom addresses back to the form again, to make
531
// sure we have the extra blank ones.
532
personForm.setTelecomAddressesFromPerson();
533
534         // TODO: who added this one? check it out!
535
} else if ("person.tab.restoreUser".equals(activeTabKey)) {
536             personForm.setTabPage("/addressBook/restoreUser.jsp");
537             personForm.setHelpKey("addressbook.restoreUser");
538
539         } else if ("person.tab.user".equals(activeTabKey)) {
540             personForm.setTabPage("/addressBook/user.jsp");
541             personForm.setHelpKey("addressbook.user");
542         } else if ("person.tab.employee".equals(activeTabKey)) {
543             // this could be 4 if the user tab is not showing
544
personForm.setTabPage("/addressBook/employee.jsp");
545             personForm.setHelpKey("addressbook.employee");
546         } else {
547             personForm.setTabPage("/addressBook/personDetails.jsp");
548             personForm.setHelpKey("addressbook.person");
549         }
550
551         if (log.isDebugEnabled()) {
552             log.debug("Out PersonAction.execute");
553         }
554         return null;
555     }
556
557     /**
558      * <p>This method is called if the ok or apply buttons are pressed.</p>
559      *
560      * @param mapping current action mapping from <em>Struts</em> config.
561      * @param log valid logging object to write messages to.
562      * @param errors valid errors object to append errors to. If there are
563      * any errors, the action will return to the input.
564      * @param form optional ActionForm bean for this request (if any)
565      * @param request non-HTTP request we are processing
566      * @param response The non-HTTP response we are creating
567      * @param session returned from the <code>request</code> parameter.
568      * @param userName valid, non-null user name from session.
569      * @param settings valid, non-null settings from session.
570      * @param defaultForward &quot;ok&quot; if the <code>Ok</code> button
571      * was pressed, otherwise &quot;apply&quot; if the <code>Apply</code> button
572      * was pressed.
573      * @exception SystemException if there is any problem which
574      * prevents processing. It will result in the webapp being forwarded
575      * to
576      * the standard error page.
577      * @return this method returns the string used to identify the correct
578      * <em>Struts</em> <code>ActionForward</code> which should follow this
579      * page, or <code>null</code> if it should return to the input.
580      */

581     public String JavaDoc onConfirm(final ActionMapping mapping,
582             final ActionErrors errors,
583             final ActionForm form,
584             final HttpServletRequest JavaDoc request,
585             final HttpServletResponse JavaDoc response,
586             final HttpSession JavaDoc session,
587             final String JavaDoc defaultForward) throws SystemException {
588         if (log.isDebugEnabled()) {
589             log.debug("In PersonAction.onConfirm");
590         }
591
592         SecuritySession securitySession = (SecuritySession)
593             session.getAttribute("securitySession");
594         PersonForm personForm = (PersonForm) form;
595         PersonDO person = personForm.getPerson();
596         UserDO user = person.getUser();
597         if (user == null) {
598             person.setUser(user = new UserDO());
599         }
600
601         // set the user group from the id
602
GroupDO group = addressBook.findGroupByPrimaryKey(securitySession,
603                 person.getGroup().getId());
604         person.setGroup(group);
605
606         // update the telecom addresses in the person
607
personForm.setPersonFromTelecomAddresses();
608
609         AddressDO address = person.getAddress();
610         if (StringHandling.isNullOrEmpty(address.getPostCode())
611                 && StringHandling.isNullOrEmpty(address.getRegion())
612                 && StringHandling.isNullOrEmpty(address.getStreetAddress())
613                 && StringHandling.isNullOrEmpty(address.getTown())) {
614             // if there is no address, ignore the address elements for
615
// validation purposes (we'll set it back again at the end of this
616
// method
617
person.setAddress(null);
618         }
619
620         // add a new person
621
if (person.getId() == null) {
622             // if it's a new person, add them to the address book
623
// initially the person is only a member of the group
624
person.setEmployee(null);
625             // you need to apply person changes before you can create a new
626
// user
627
person.setUser(null);
628             person = addressBook.addPerson(securitySession, person);
629
630             // amend an existing person
631
} else {
632             // if this is not an employee, remove the employee from the
633
// person
634
if (!personForm.isEmployee()) {
635                 person.setEmployee(null);
636             }
637
638             // if there is to be no user name, clear the user
639
if (StringHandling.isNullOrEmpty(personForm.getUserName())) {
640                 if (user.getId() == null) {
641                     person.setUser(null);
642                 } else {
643                     user.setDeleted(true);
644                     security.amendUser(securitySession, user);
645                 }
646             } else {
647                 user.setName(personForm.getUserName());
648                 user.setDeleted(false);
649                 user.setEnabled(personForm.getEnableUser());
650                 if (user.getId() == null) {
651                     user.setId(person.getId());
652                     security.addUserToPerson(securitySession, person);
653                 } else {
654                     security.amendUser(securitySession, user);
655                 }
656             }
657
658             person = addressBook.amendPerson(securitySession, person);
659         }
660
661         //flush the cached group and person trees
662
//flushCache("ContactTree",
663
// javax.servlet.jsp.PageContext.APPLICATION_SCOPE, request);
664

665         // if this is the okay button, just get out now
666
if ("ok".equals(defaultForward)) {
667             if (log.isDebugEnabled()) {
668                 log.debug("Out PersonAction.onConfirm (ok)");
669             }
670             return "utilClosePopUp";
671         }
672         // if we are applying changes, save the (possibly) new person back
673
// in the form again
674
// make an empty employee, in case this changes in form
675
if (person.getEmployee() == null) {
676             person.setEmployee(new EmployeeDO());
677         }
678         personForm.setPerson(person);
679
680         if (log.isDebugEnabled()) {
681             log.debug("Out PersonAction.onConfirm");
682         }
683
684         // in case we deleted the address, set it back again
685
person.setAddress(address);
686         // go back thro' execute - we might have changed the group
687
execute(mapping, errors, form, request, response, session);
688         return defaultForward;
689     }
690
691     /**
692      * <p>This method is called if the delete (confirm, not warn) button
693      * is pressed.</p>
694      * @param mapping current action mapping from <em>Struts</em> config.
695      * @param errors valid errors object to append errors to. If there are
696      * any errors, the action will return to the input.
697      * @param form optional ActionForm bean for this request (if any)
698      * @param request non-HTTP request we are processing
699      * @param response The non-HTTP response we are creating
700      * @param session returned from the <code>request</code> parameter.
701      * @param log valid logging object to write messages to.
702      * @param userName valid, non-null user name from session.
703      * @param settings valid, non-null settings from session.
704      *
705      * @exception SystemException if there is any problem which
706      * prevents processing. It will result in the webapp being forwarded
707      * to
708      * the standard error page.
709      * @return this method returns the string used to identify the correct
710      * <em>Struts</em> <code>ActionForward</code> which should follow this
711      * page, or <code>null</code> if it should return to the input.
712      */

713     public String JavaDoc onDelete(final ActionMapping mapping,
714             final ActionErrors errors,
715             final ActionForm form,
716             final HttpServletRequest JavaDoc request,
717             final HttpServletResponse JavaDoc response,
718             final HttpSession JavaDoc session, final String JavaDoc defaultForward) throws SystemException {
719         if (log.isDebugEnabled()) {
720             log.debug("Out PersonAction.onDelete");
721         }
722
723         PersonForm personForm = (PersonForm) form;
724         PersonDO person = personForm.getPerson();
725         SecuritySession securitySession = (SecuritySession)
726             session.getAttribute("securitySession");
727
728         UserDO user = person.getUser();
729         if (user.getId() != null) {
730             user.setDeleted(true);
731             security.amendUser(securitySession, user);
732         }
733
734         // do you want to delete this poor person?
735
addressBook.removePerson(securitySession, person.getId());
736         if (log.isDebugEnabled()) {
737             log.debug("Out PersonAction.onDelete");
738         }
739         return "utilClosePopUp";
740     }
741 }
742
Popular Tags