KickJava   Java API By Example, From Geeks To Geeks.

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


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: PersonListAction.java,v $
31  * Revision 1.4 2005/04/29 02:48:14 colinmacleod
32  * Data bugfixes.
33  * Changed primary key back to Integer.
34  *
35  * Revision 1.3 2005/04/10 20:09:38 colinmacleod
36  * Added new themes.
37  * Changed id type to String.
38  * Changed i tag to em and b tag to strong.
39  * Improved PicoContainerFactory with NanoContainer scripts.
40  *
41  * Revision 1.2 2005/04/09 17:19:08 colinmacleod
42  * Changed copyright text to GPL v2 explicitly.
43  *
44  * Revision 1.1.1.1 2005/03/10 17:50:24 colinmacleod
45  * Restructured ivata op around Hibernate/PicoContainer.
46  * Renamed ivata groupware.
47  *
48  * Revision 1.9 2004/12/31 18:27:43 colinmacleod
49  * Added MaskFactory to constructor of MaskAction.
50  *
51  * Revision 1.8 2004/12/23 21:01:25 colinmacleod
52  * Updated Struts to v1.2.4.
53  * Changed base classes to use ivata masks.
54  *
55  * Revision 1.7 2004/11/12 18:19:14 colinmacleod
56  * Change action and form classes to extend MaskAction, MaskForm respectively.
57  *
58  * Revision 1.6 2004/11/12 15:57:07 colinmacleod
59  * Removed dependencies on SSLEXT.
60  * Moved Persistence classes to ivata masks.
61  *
62  * Revision 1.5 2004/11/03 15:31:50 colinmacleod
63  * Change method interfaces to remove log.
64  *
65  * Revision 1.4 2004/07/13 19:41:14 colinmacleod
66  * Moved project to POJOs from EJBs.
67  * Applied PicoContainer to services layer (replacing session EJBs).
68  * Applied Hibernate to persistence layer (replacing entity EJBs).
69  *
70  * Revision 1.3 2004/03/21 21:16:08 colinmacleod
71  * Shortened name to ivata op.
72  *
73  * Revision 1.2 2004/02/01 22:00:33 colinmacleod
74  * Added full names to author tags
75  *
76  * Revision 1.1.1.1 2004/01/27 20:57:54 colinmacleod
77  * Moved ivata openportal to SourceForge..
78  *
79  * Revision 1.3 2003/10/17 12:36:12 jano
80  * fixing problems with building
81  * converting intranet -> portal
82  * Eclipse building
83  *
84  * Revision 1.2 2003/10/15 13:18:02 colin
85  * fixing for XDoclet
86  *
87  * Revision 1.3 2003/08/05 14:57:35 jano
88  * addressBook extension
89  *
90  * Revision 1.2 2003/07/31 08:56:21 jano
91  * we are using new method for finding all people
92  *
93  * Revision 1.1 2003/02/24 19:09:21 colin
94  * moved to business
95  *
96  * Revision 1.3 2003/02/14 08:59:48 colin
97  * changed findParentGroups... to findGroups...
98  *
99  * Revision 1.2 2003/02/04 17:39:47 colin
100  * updated for new struts interface
101  *
102  * Revision 1.1 2003/01/30 09:02:20 colin
103  * updates for struts conversion
104  * -----------------------------------------------------------------------------
105  */

106 package com.ivata.groupware.business.addressbook.struts;
107
108 import java.lang.reflect.InvocationTargetException JavaDoc;
109 import java.util.Iterator JavaDoc;
110 import java.util.List JavaDoc;
111 import java.util.Vector JavaDoc;
112
113 import javax.servlet.http.HttpServletRequest JavaDoc;
114 import javax.servlet.http.HttpServletResponse JavaDoc;
115 import javax.servlet.http.HttpSession JavaDoc;
116
117 import org.apache.commons.beanutils.PropertyUtils;
118 import org.apache.struts.action.ActionErrors;
119 import org.apache.struts.action.ActionForm;
120 import org.apache.struts.action.ActionMapping;
121
122 import com.ivata.groupware.admin.security.server.SecuritySession;
123 import com.ivata.groupware.business.addressbook.AddressBook;
124 import com.ivata.groupware.business.addressbook.person.group.GroupConstants;
125 import com.ivata.groupware.business.addressbook.person.group.GroupDO;
126 import com.ivata.mask.MaskFactory;
127 import com.ivata.mask.util.StringHandling;
128 import com.ivata.mask.util.SystemException;
129 import com.ivata.mask.web.struts.MaskAction;
130 import com.ivata.mask.web.struts.MaskAuthenticator;
131
132
133 /**
134  * <p>Retrieves a list of people for the main index page of the
135  * address book.</p>
136  *
137  * @since 2003-01-26
138  * @author Colin MacLeod
139  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
140  * @version $Revision: 1.4 $
141  */

142 public class PersonListAction extends MaskAction {
143     private AddressBook addressBook;
144     /**
145      * <p>TODO</p>
146      *
147      * @param addressBook
148      * @param maskFactory This factory is needed to access the masks and groups
149      * of masks.
150      * @param authenticator used to confirm whether or not the
151      * user should be allowed to continue, in the <code>execute</code> method.
152      */

153     public PersonListAction(AddressBook addressBook,
154             MaskFactory maskFactory, MaskAuthenticator authenticator) {
155         super(maskFactory, authenticator);
156         this.addressBook = addressBook;
157     }
158
159
160     /**
161      * <p>Retrieve a list of people to show in the main index view of the
162      * address book.</p>
163      *
164      * @param mapping current action mapping from <em>Struts</em> config.
165      * @param log valid logging object to write messages to.
166      * @param errors valid errors object to append errors to. If there are
167      * any errors, the action will return to the input.
168      * @param form optional ActionForm bean for this request (if any)
169      * @param request non-HTTP request we are processing
170      * @param response The non-HTTP response we are creating
171      * @param session returned from the <code>request</code> parameter.
172      * @param userName current user name from session. .
173      * @param settings valid, non-null settings from session.
174      * @exception SystemException if there is any problem which
175      * prevents processing. It will result in the webapp being forwarded
176      * to
177      * the standard error page.
178      * @return this method returns the string used to identify the correct
179      * <em>Struts</em> <code>ActionForward</code> which should follow this
180      * page, or <code>null</code> if it should return to the input.
181      *
182      */

183     public String JavaDoc execute(final ActionMapping mapping,
184             final ActionErrors errors,
185             final ActionForm form,
186             final HttpServletRequest JavaDoc request,
187             final HttpServletResponse JavaDoc response,
188             final HttpSession JavaDoc session) throws SystemException {
189         SecuritySession securitySession = (SecuritySession) session.getAttribute("securitySession");
190         // group is from the tree combo selector (frmPersonList), index from tabs
191
Integer JavaDoc comboAddressBook = null;
192         Integer JavaDoc comboGroup = null;
193         String JavaDoc index = null;
194         try {
195             comboAddressBook = (Integer JavaDoc) PropertyUtils.getSimpleProperty(form, "comboAddressBook");
196             comboGroup = (Integer JavaDoc) PropertyUtils.getSimpleProperty(form, "comboGroup");
197             index = (String JavaDoc) PropertyUtils.getSimpleProperty(form, "index");
198             // request parameter overrides the form
199
String JavaDoc requestIndex = request.getParameter("index");
200             if (!StringHandling.isNullOrEmpty(requestIndex)) {
201                 PropertyUtils.setSimpleProperty(form, "index", index = requestIndex);
202             }
203         } catch (NoSuchMethodException JavaDoc e) {
204             throw new SystemException(e);
205         } catch (InvocationTargetException JavaDoc e) {
206             throw new SystemException(e);
207         } catch (IllegalAccessException JavaDoc e) {
208             throw new SystemException(e);
209         }
210         // request overrides form state
211
if (request.getParameter("index") != null) {
212             index = request.getParameter("index");
213         }
214         if (request.getParameter("comboAddressBook") != null) {
215             comboAddressBook = StringHandling.integerValue(
216                     request.getParameter("comboAddressBook"));
217         }
218         if (request.getParameter("comboGroup") != null) {
219             comboGroup = StringHandling.integerValue(
220                     request.getParameter("comboGroup"));
221         }
222
223         // have to assign the results to something
224
List JavaDoc results;
225
226         // need to do this conversion, because 4 - the address_book group doesn't contain
227
// people, and the search by group isn't recursive... all the people
228
// will be found this way - with no group membership lookup
229
if ((comboAddressBook == null)
230                 || comboAddressBook.equals("4")) {
231             comboAddressBook = new Integer JavaDoc(0);
232             comboGroup = new Integer JavaDoc(0);
233         }
234
235         // default the index to everyone
236
if (StringHandling.isNullOrEmpty(index)) {
237             index = "all";
238         }
239         String JavaDoc initialLetter = "all".equals(index) ? null : index;
240         try {
241             Integer JavaDoc groupId;
242
243             // if there is a specific group, go for that
244
if (!"".equals(comboGroup)) {
245                 groupId = comboGroup;
246
247             // otherwise see if a general address book was specified
248
} else if (!"".equals(comboAddressBook)) {
249                 groupId = comboAddressBook;
250             } else {
251                 groupId = GroupConstants.ADDRESS_BOOK;
252             }
253             GroupDO parentGroup = addressBook.findGroupByPrimaryKey(securitySession,
254                 groupId);
255             results = addressBook.findAllPeopleInGroup(securitySession,
256                 parentGroup, initialLetter);
257         } catch(SystemException e) {
258             throw new SystemException(e);
259         }
260
261         List JavaDoc addressBooks = addressBook.findAddressBooks(securitySession, true);
262         List JavaDoc addressBookNames = new Vector JavaDoc();
263         Iterator JavaDoc addressBookIterator = addressBooks.iterator();
264         while(addressBookIterator.hasNext()) {
265             GroupDO addressBook = (GroupDO) addressBookIterator.next();
266             addressBookNames.add(addressBook.getName());
267         }
268
269         // now store the results we want to show
270
try {
271             PropertyUtils.setSimpleProperty(form, "comboAddressBook", comboAddressBook);
272             PropertyUtils.setSimpleProperty(form, "comboGroup", comboGroup);
273             PropertyUtils.setSimpleProperty(form, "index", index);
274             PropertyUtils.setSimpleProperty(form, "addressBooks", addressBookNames);
275             PropertyUtils.setSimpleProperty(form, "results", results);
276         } catch (NoSuchMethodException JavaDoc e) {
277             throw new SystemException(e);
278         } catch (InvocationTargetException JavaDoc e) {
279             throw new SystemException(e);
280         } catch (IllegalAccessException JavaDoc e) {
281             throw new SystemException(e);
282         }
283
284         // this list always goes to the same page
285
return null;
286     }
287 }
288
Popular Tags