KickJava   Java API By Example, From Geeks To Geeks.

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


1 // Source file: h:/cvslocal/ivata groupware/src/com/ivata/intranet/business/addressbook/struts/FindPersonAction.java
2

3 /*
4  * Copyright (c) 2001 - 2005 ivata limited.
5  * All rights reserved.
6  * -----------------------------------------------------------------------------
7  * ivata groupware may be redistributed under the GNU General Public
8  * License as published by the Free Software Foundation;
9  * version 2 of the License.
10  *
11  * These programs are free software; you can redistribute them and/or
12  * modify them under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; version 2 of the License.
14  *
15  * These programs are distributed in the hope that they will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * See the GNU General Public License in the file LICENSE.txt for more
20  * details.
21  *
22  * If you would like a copy of the GNU General Public License write to
23  *
24  * Free Software Foundation, Inc.
25  * 59 Temple Place - Suite 330
26  * Boston, MA 02111-1307, USA.
27  *
28  *
29  * To arrange commercial support and licensing, contact ivata at
30  * http://www.ivata.com/contact.jsp
31  * -----------------------------------------------------------------------------
32  * $Log: FindPersonAction.java,v $
33  * Revision 1.3 2005/04/10 20:32:02 colinmacleod
34  * Added new themes.
35  * Changed id type to String.
36  * Changed i tag to em and b tag to strong.
37  * Improved PicoContainerFactory with NanoContainer scripts.
38  *
39  * Revision 1.2 2005/04/09 17:19:08 colinmacleod
40  * Changed copyright text to GPL v2 explicitly.
41  *
42  * Revision 1.1.1.1 2005/03/10 17:50:25 colinmacleod
43  * Restructured ivata op around Hibernate/PicoContainer.
44  * Renamed ivata groupware.
45  *
46  * Revision 1.9 2004/12/31 18:27:42 colinmacleod
47  * Added MaskFactory to constructor of MaskAction.
48  *
49  * Revision 1.8 2004/12/23 21:01:25 colinmacleod
50  * Updated Struts to v1.2.4.
51  * Changed base classes to use ivata masks.
52  *
53  * Revision 1.7 2004/11/12 18:19:13 colinmacleod
54  * Change action and form classes to extend MaskAction, MaskForm respectively.
55  *
56  * Revision 1.6 2004/11/12 15:57:06 colinmacleod
57  * Removed dependencies on SSLEXT.
58  * Moved Persistence classes to ivata masks.
59  *
60  * Revision 1.5 2004/11/03 15:31:50 colinmacleod
61  * Change method interfaces to remove log.
62  *
63  * Revision 1.4 2004/07/13 19:41:14 colinmacleod
64  * Moved project to POJOs from EJBs.
65  * Applied PicoContainer to services layer (replacing session EJBs).
66  * Applied Hibernate to persistence layer (replacing entity EJBs).
67  *
68  * Revision 1.3 2004/03/21 21:16:08 colinmacleod
69  * Shortened name to ivata op.
70  *
71  * Revision 1.2 2004/02/01 22:00:33 colinmacleod
72  * Added full names to author tags
73  *
74  * Revision 1.1.1.1 2004/01/27 20:57:53 colinmacleod
75  * Moved ivata openportal to SourceForge..
76  *
77  * Revision 1.4 2003/11/13 16:03:16 jano
78  * commitng everything to CVS
79  * can deploy and application is ruuning, can login into
80  *
81  * Revision 1.3 2003/10/17 12:36:12 jano
82  * fixing problems with building
83  * converting intranet -> portal
84  * Eclipse building
85  *
86  * Revision 1.2 2003/10/15 13:18:02 colin
87  * fixing for XDoclet
88  *
89  * Revision 1.5 2003/08/21 09:49:32 jano
90  * fixing for new addressBook extension
91  *
92  * Revision 1.4 2003/08/20 16:24:15 jano
93  * fixing addressBook extension
94  *
95  * Revision 1.3 2003/04/14 12:21:12 peter
96  * helpKey initialisation added
97  *
98  * Revision 1.2 2003/02/28 09:36:38 jano
99  * RuntimeException(e) -> IntrnetRuntimeException
100  *
101  * Revision 1.1 2003/02/24 19:09:21 colin
102  * moved to business
103  *
104  * Revision 1.4 2003/02/21 16:17:03 peter
105  * added initialisation of the birthDate of personForm
106  *
107  * Revision 1.3 2003/02/18 11:10:27 colin
108  * first release of address book with Struts
109  *
110  * Revision 1.2 2003/02/14 08:59:48 colin
111  * changed findParentGroups... to findGroups...
112  *
113  * Revision 1.1 2003/02/04 17:40:18 colin
114  * first version in CVS
115  *
116  * Revision 1.6 2003/01/30 09:02:19 colin
117  * updates for struts conversion
118  *
119  * Revision 1.5 2003/01/18 20:12:36 colin
120  * fixes and changes to override new MaskAction method
121  *
122  * Revision 1.4 2003/01/10 10:29:46 jano
123  * we need information about user who created group
124  *
125  * Revision 1.3 2003/01/09 10:50:54 jano
126  * I need only one method for finding right for group
127  *
128  * Revision 1.2 2003/01/08 17:16:21 jano
129  * We will use new methods for finding and changing rights for
130  * GROUP of AddressBookRightsBean
131  * -----------------------------------------------------------------------------
132  */

133 package com.ivata.groupware.business.addressbook.struts;
134
135 import javax.servlet.http.HttpServletRequest JavaDoc;
136 import javax.servlet.http.HttpServletResponse JavaDoc;
137 import javax.servlet.http.HttpSession JavaDoc;
138
139 import org.apache.struts.action.ActionErrors;
140 import org.apache.struts.action.ActionForm;
141 import org.apache.struts.action.ActionMapping;
142 import org.picocontainer.PicoContainer;
143
144 import com.ivata.groupware.admin.security.Security;
145 import com.ivata.groupware.admin.security.server.SecuritySession;
146 import com.ivata.groupware.admin.security.user.UserDO;
147 import com.ivata.groupware.admin.setting.Settings;
148 import com.ivata.groupware.admin.setting.SettingsInitializationException;
149 import com.ivata.groupware.business.addressbook.AddressBook;
150 import com.ivata.groupware.business.addressbook.person.PersonDO;
151 import com.ivata.groupware.business.addressbook.person.employee.EmployeeDO;
152 import com.ivata.groupware.business.addressbook.right.AddressBookRights;
153 import com.ivata.groupware.container.PicoContainerFactory;
154 import com.ivata.groupware.util.SettingDateFormatter;
155 import com.ivata.mask.MaskFactory;
156 import com.ivata.mask.util.SystemException;
157 import com.ivata.mask.web.format.DateFormatterConstants;
158 import com.ivata.mask.web.struts.MaskAction;
159 import com.ivata.mask.web.struts.MaskAuthenticator;
160
161
162 /**
163  * <p><code>FindPersonAction</code> invoked from the index page. This
164  * action locates the person and prepares the form for
165  * <code>person.jsp</code>.</p>
166  *
167  * @since 2003-02-01
168  * @author Colin MacLeod
169  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
170  * @version $Revision: 1.3 $
171  *
172  * @TODO dependency AddressbookAction on WebMail
173  */

174 public class FindPersonAction extends MaskAction {
175     /**
176      * Address book implementation.
177      */

178     private AddressBook addressBook;
179     /**
180      * Address book rights implementation.
181      */

182     private AddressBookRights addressBookRights;
183     /**
184      * Used to, well, format dates!
185      */

186     private SettingDateFormatter dateFormatter;
187     /**
188      * Settings implemntation.
189      */

190     private Settings settings;
191     private Security security;
192
193     /**
194      * Construct the action.
195      *
196      * @param addressBook address book implementation.
197      * @param addressBookRights address book rights implementation.
198      * @param settings settings implemntation.
199      * @param maskFactory This factory is needed to access the masks and groups
200      * of masks.
201      * @param authenticator used to confirm whether or not the
202      * user should be allowed to continue, in the <code>execute</code> method.
203      */

204     public FindPersonAction(AddressBook addressBook, AddressBookRights
205             addressBookRights, SettingDateFormatter dateFormatter,
206             Security security, Settings settings,
207             MaskFactory maskFactory, MaskAuthenticator authenticator) {
208         super(maskFactory, authenticator);
209         this.addressBook = addressBook;
210         this.addressBookRights = addressBookRights;
211         this.dateFormatter = dateFormatter;
212         this.security = security;
213         this.settings = settings;
214     }
215
216     /**
217      * <p>Invoked when the user clicks on a person in the address
218      * list.</p>
219      *
220      * @param mapping current action mapping from <em>Struts</em> config.
221      * @param log valid logging object to write messages to.
222      * @param errors valid errors object to append errors to. If there are
223      * any errors, the action will return to the input.
224      * @param form optional ActionForm bean for this request (if any)
225      * @param request non-HTTP request we are processing
226      * @param response The non-HTTP response we are creating
227      * @param session returned from the <code>request</code> parameter.
228      * @param userName current user name from session. .
229      * @param settings valid, non-null settings from session.
230      * @exception SystemException if there is any problem which
231      * prevents processing. It will result in the webapp being forwarded
232      * to
233      * the standard error page.
234      * @return this method returns the string used to identify the correct
235      * <em>Struts</em> <code>ActionForward</code> which should follow this
236      * page, or <code>null</code> if it should return to the input.
237      *
238      */

239     public String JavaDoc execute(final ActionMapping mapping,
240             final ActionErrors errors,
241             final ActionForm form,
242             final HttpServletRequest JavaDoc request,
243             final HttpServletResponse JavaDoc response,
244             final HttpSession JavaDoc session) throws SystemException {
245         // find the person and set him/her in the form
246
session.removeAttribute("personTab_activeTab");
247         String JavaDoc id = request.getParameter("id");
248
249         if (id == null) {
250             throw new SystemException("ERROR in FindPersonAction: id is null");
251         }
252         SecuritySession securitySession = (SecuritySession) session.getAttribute("securitySession");
253         PersonDO person = addressBook.findPersonByPrimaryKey(securitySession, id);
254         PicoContainer container = securitySession.getContainer();
255         PersonForm personForm = (PersonForm)
256             PicoContainerFactory.getInstance().instantiateOrOverride(container,
257                     PersonForm.class);
258         personForm.clear();
259         personForm.setPerson(person);
260
261         // set Up READ ONLY flag
262
personForm.setReadOnly(!addressBookRights.canAmendInGroup(securitySession,
263             person.getGroup().getAddressBook()));
264         String JavaDoc userName = securitySession.getUser().getName();
265         if (personForm.getReadOnly() && person.getCreatedBy().equals(securitySession.getUser())) {
266             personForm.setReadOnly(false);
267         }
268         // set Up CAN REMOVE flag
269
personForm.setCanRemove(addressBookRights.canRemoveFromGroup(securitySession,
270             person.getGroup().getAddressBook()));
271
272         // date of birth
273
java.util.Date JavaDoc birthDate = person.getDateOfBirth();
274         if (birthDate != null) {
275             try {
276                 dateFormatter.setUserName(userName);
277                 dateFormatter.setDateFormat(DateFormatterConstants.DATE_INPUT_DISPLAY);
278                 dateFormatter.setDateTimeText("{0}");
279
280                 personForm.setDateOfBirthString(dateFormatter.format(birthDate));
281             } catch (SettingsInitializationException e) {
282                 throw new RuntimeException JavaDoc(e);
283             }
284         }
285
286         session.setAttribute("addressBookPersonForm", personForm);
287
288         // set up the employee
289
personForm.setEmployee(person.getEmployee() != null);
290         // if the person is not yet an employee, make a new employee record
291
// (we'll remove this at the end unless the 'isEmployee' is set)
292
if (!personForm.isEmployee()) {
293             person.setEmployee(new EmployeeDO());
294         }
295         // set up the user
296
UserDO userSet = person.getUser();
297
298         personForm.setUserName(userSet == null ? null : userSet.getName());
299         personForm.setEnableUser((userSet != null)
300                 && security.isUserEnabled(securitySession, userSet.getName()));
301         // only get the email aliases and vacation message if the user name is
302
// set to something
303
// if (!StringHandling.isNullOrEmpty(userNameSet)) {
304
// MailRemote mail = getMail();
305

306 // personForm.setUserAliases(new Vector(mail.getUserAliases(userNameSet)));
307
// personForm.setVacationMessage(mail.getVacationMessage(userNameSet));
308
// }
309
// TODO: check for user rights here
310
personForm.setTitleKey("person.title.amend");
311         // TODO: personForm.setHelpKey("addressbook.person");
312
return "addressBookPersonAction";
313     }
314 }
315
Popular Tags