1 5 6 package com.quikj.application.communicator.applications.webtalk.controller; 7 8 import com.quikj.application.communicator.applications.webtalk.model.*; 9 import com.quikj.application.communicator.admin.model.*; 10 import com.quikj.application.communicator.admin.controller.*; 11 import com.quikj.server.framework.*; 12 13 import javax.servlet.http.*; 14 import org.apache.struts.action.*; 15 import java.sql.*; 16 import java.util.*; 17 18 22 public class GroupWizardCustomerInfoAction extends Action 23 { 24 25 26 public GroupWizardCustomerInfoAction() 27 { 28 } 29 30 public ActionForward execute(ActionMapping mapping, 31 ActionForm form, 32 HttpServletRequest request, 33 HttpServletResponse response) 34 { 35 ActionErrors errors = new ActionErrors(); 36 37 Connection c = (Connection)request.getSession().getAttribute("connection"); 38 if (c == null) 39 { 40 errors.add(ActionErrors.GLOBAL_ERROR, 41 new ActionError("error.not.logged.in")); 42 saveErrors(request, errors); 43 return mapping.findForward("logon"); 44 } 45 46 AccountElement element = (AccountElement)request.getSession().getAttribute("userInfo"); 47 if (element.isAdminLevel() == false) 48 { 49 errors.add(ActionErrors.GLOBAL_ERROR, 50 new ActionError("error.insufficient.privilege")); 51 saveErrors(request, errors); 52 53 return mapping.findForward("main_menu"); 54 } 55 56 String submit = (String )((DynaActionForm)form).get("submit"); 57 58 if (submit.equals("Next") == true) 59 { 60 String nickname = ((String )((DynaActionForm)form).get("companyNickname")).trim(); 61 62 GroupTable groups = new GroupTable(); 63 groups.setConnection(c); 64 UserTable users = new UserTable(); 65 users.setConnection(c); 66 67 if (commonGroupNameAvailable(nickname, groups, users, c) == true) 68 { 69 GroupElement e = new GroupElement(); 70 71 e.setMemberBusyNotificationControl(GroupElement.NOTIFY_ALL); 72 e.setMemberLoginNotificationControl(GroupElement.NOTIFY_ALL); 73 e.setOwnerBusyNotificationControl(GroupElement.NOTIFY_NONE); 74 e.setOwnerLoginNotificationControl(GroupElement.NOTIFY_NONE); 75 76 e.setName(nickname); 77 e.setDomain(nickname); 78 79 boolean status_ok = groups.create(e); 80 81 if (status_ok == false) 82 { 83 errors.add(ActionErrors.GLOBAL_ERROR, 84 new ActionError("error.common.group.create.failure", nickname)); 85 86 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 87 "GroupWizardCustomerInfoAction.execute()/Create Common Group/by-" 88 + element.getName() 89 + ": " 90 + groups.getErrorMessage()); 91 } 92 else 93 { 94 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG, 95 "User " + element.getName() + " created new group " + 96 nickname); 97 98 String company_name = ((String )((DynaActionForm)form).get("companyName")).trim(); 99 String company_url = ((String )((DynaActionForm)form).get("companyUrl")).trim(); 100 101 ArrayList log = new ArrayList(); 103 104 StringBuffer buf = new StringBuffer ("Informational - Customer name: "); 105 buf.append(company_name); 106 buf.append("\n"); 107 log.add(buf.toString()); 108 109 buf = new StringBuffer ("Informational - Customer acronym: "); 110 buf.append(nickname); 111 buf.append("\n"); 112 log.add(buf.toString()); 113 114 buf = new StringBuffer ("Informational - Customer webpage: "); 115 buf.append(company_url); 116 buf.append("\n"); 117 log.add(buf.toString()); 118 119 log.add("\n"); 120 121 buf = new StringBuffer ("Created common customer group '"); 122 buf.append(nickname); 123 buf.append("'\n"); 124 log.add(buf.toString()); 125 126 request.getSession().setAttribute("groupWizardLog", log); 128 request.getSession().setAttribute("groupWizardDomain", nickname); 129 request.getSession().setAttribute("groupWizardCompanyName", company_name); 130 request.getSession().setAttribute("groupWizardCompanyUrl", company_url); 131 132 134 String groupowner_name = nickname + "-owner"; 135 136 UserElement u = new UserElement(); 137 138 u.setAdditionalInfo("Owner of group " + nickname + ", company: " 139 + company_name + ", url: " + company_url); 140 u.setFullName(nickname + " Group Owner"); 141 u.setName(groupowner_name); 142 u.setPassword("a1b2c3d4"); 143 u.addOwnsGroup(nickname); 144 u.setDomain(nickname); 145 146 status_ok = users.create(u); 147 148 if (status_ok == false) 149 { 150 errors.add(ActionErrors.GLOBAL_ERROR, 151 new ActionError("error.common.groupowner.create.failure", new String (groupowner_name), new String (nickname))); 152 153 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 154 "GroupWizardCustomerInfoAction.execute()/Create Group Owner/by-" 155 + element.getName() 156 + ": " 157 + users.getErrorMessage()); 158 159 buf = new StringBuffer ("\n*** ERROR *** creating group owner : The group owner named '"); 161 buf.append(groupowner_name); 162 buf.append("' for the new group '"); 163 buf.append(nickname); 164 buf.append("' could not be created because a user with that name already exists or there was a database error. If that user name already exists in the system, proceed with the wizard as you normally would. After finishing with the wizard, add the group owner for this new group yourself, using a unique name other than '"); 165 buf.append(groupowner_name); 166 buf.append("'. Assign its domain = "); 167 buf.append(nickname); 168 buf.append(", give it any password, and be sure to mark it as owning group '"); 169 buf.append(nickname); 170 buf.append("'."); 171 buf.append("\n"); 172 log.add(buf.toString()); 173 } 174 else 175 { 176 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG, 177 "User " + element.getName() + " created new webtalk user " + 178 groupowner_name); 179 180 buf = new StringBuffer ("\nCreated common group owner '"); 182 buf.append(groupowner_name); 183 buf.append("'\n"); 184 log.add(buf.toString()); 185 } 186 } 187 } 188 else 189 { 190 errors.add(ActionErrors.GLOBAL_ERROR, 191 new ActionError("error.company.acronym.unavailable")); 192 } 193 } 194 195 if (errors.isEmpty() == false) 196 { 197 saveErrors(request, errors); 198 return mapping.getInputForward(); 199 } 200 201 if (submit.startsWith("Cancel") == false) 202 { 203 WebTalkRelatedTasks menu = new WebTalkRelatedTasks(); 205 menu.addLink(new LinkAttribute("List all groups", "list_groups")); 206 menu.addLink(new LinkAttribute("List all features", "list_features")); 207 menu.addLink(new LinkAttribute("Search users", "display_user_search")); 208 209 request.setAttribute("menu", menu); 210 } 211 212 return mapping.findForward(submit); 213 } 214 215 private boolean commonGroupNameAvailable(String name, GroupTable groups, UserTable users, Connection c) 216 { 217 219 GroupElement ele = groups.query(name); 220 221 if (ele == null) 222 { 223 if (groups.getErrorMessage() != null) 224 { 225 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 226 "GroupWizardCustomerInfoAction.commonGroupNameAvailable(): " 227 + groups.getErrorMessage()); 228 229 return false; 230 } 231 } 232 else 233 { 234 return false; 235 } 236 237 239 ArrayList list = groups.list(name); 240 241 if (list == null) 242 { 243 if (groups.getErrorMessage() != null) 244 { 245 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 246 "GroupWizardCustomerInfoAction.commonGroupNameAvailable(): " 247 + groups.getErrorMessage()); 248 249 return false; 250 } 251 } 252 else 253 { 254 if (list.size() > 0) 255 { 256 return false; 257 } 258 } 259 260 262 AccountsTable accounts = new AccountsTable(AdminConfig.getInstance().getDBParams().getAdminDb()); 263 accounts.setConnection(c); 264 265 list = accounts.list(name); 266 267 if (list == null) 268 { 269 if (accounts.getErrorMessage() != null) 270 { 271 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 272 "GroupWizardCustomerInfoAction.commonGroupNameAvailable(): " 273 + accounts.getErrorMessage()); 274 275 return false; 276 } 277 } 278 else 279 { 280 if (list.size() > 0) 281 { 282 return false; 283 } 284 } 285 286 288 UserElement user = users.query(name + "-owner"); 289 290 if (user == null) 291 { 292 if (users.getErrorMessage() != null) 293 { 294 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 295 "GroupWizardCustomerInfoAction.commonGroupNameAvailable(): " 296 + users.getErrorMessage()); 297 298 return false; 299 } 300 } 301 else 302 { 303 return false; 304 } 305 306 return true; 307 } 308 309 } 310 | Popular Tags |