1 106 package com.ivata.groupware.business.addressbook.struts; 107 108 import java.lang.reflect.InvocationTargetException ; 109 import java.util.Iterator ; 110 import java.util.List ; 111 import java.util.Vector ; 112 113 import javax.servlet.http.HttpServletRequest ; 114 import javax.servlet.http.HttpServletResponse ; 115 import javax.servlet.http.HttpSession ; 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 142 public class PersonListAction extends MaskAction { 143 private AddressBook addressBook; 144 153 public PersonListAction(AddressBook addressBook, 154 MaskFactory maskFactory, MaskAuthenticator authenticator) { 155 super(maskFactory, authenticator); 156 this.addressBook = addressBook; 157 } 158 159 160 183 public String execute(final ActionMapping mapping, 184 final ActionErrors errors, 185 final ActionForm form, 186 final HttpServletRequest request, 187 final HttpServletResponse response, 188 final HttpSession session) throws SystemException { 189 SecuritySession securitySession = (SecuritySession) session.getAttribute("securitySession"); 190 Integer comboAddressBook = null; 192 Integer comboGroup = null; 193 String index = null; 194 try { 195 comboAddressBook = (Integer ) PropertyUtils.getSimpleProperty(form, "comboAddressBook"); 196 comboGroup = (Integer ) PropertyUtils.getSimpleProperty(form, "comboGroup"); 197 index = (String ) PropertyUtils.getSimpleProperty(form, "index"); 198 String requestIndex = request.getParameter("index"); 200 if (!StringHandling.isNullOrEmpty(requestIndex)) { 201 PropertyUtils.setSimpleProperty(form, "index", index = requestIndex); 202 } 203 } catch (NoSuchMethodException e) { 204 throw new SystemException(e); 205 } catch (InvocationTargetException e) { 206 throw new SystemException(e); 207 } catch (IllegalAccessException e) { 208 throw new SystemException(e); 209 } 210 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 List results; 225 226 if ((comboAddressBook == null) 230 || comboAddressBook.equals("4")) { 231 comboAddressBook = new Integer (0); 232 comboGroup = new Integer (0); 233 } 234 235 if (StringHandling.isNullOrEmpty(index)) { 237 index = "all"; 238 } 239 String initialLetter = "all".equals(index) ? null : index; 240 try { 241 Integer groupId; 242 243 if (!"".equals(comboGroup)) { 245 groupId = comboGroup; 246 247 } 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 addressBooks = addressBook.findAddressBooks(securitySession, true); 262 List addressBookNames = new Vector (); 263 Iterator addressBookIterator = addressBooks.iterator(); 264 while(addressBookIterator.hasNext()) { 265 GroupDO addressBook = (GroupDO) addressBookIterator.next(); 266 addressBookNames.add(addressBook.getName()); 267 } 268 269 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 e) { 277 throw new SystemException(e); 278 } catch (InvocationTargetException e) { 279 throw new SystemException(e); 280 } catch (IllegalAccessException e) { 281 throw new SystemException(e); 282 } 283 284 return null; 286 } 287 } 288 | Popular Tags |