1 64 65 package com.jcorporate.expresso.ext.dbobj; 66 67 import com.jcorporate.expresso.core.db.DBConnection; 68 import com.jcorporate.expresso.core.db.DBException; 69 import com.jcorporate.expresso.core.db.exception.DBRecordNotFoundException; 70 import com.jcorporate.expresso.core.dbobj.RequestContext; 71 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 72 import com.jcorporate.expresso.core.dbobj.ValidValue; 73 import com.jcorporate.expresso.core.misc.DateTime; 74 import com.jcorporate.expresso.core.misc.EventHandler; 75 import com.jcorporate.expresso.core.misc.StringUtil; 76 import com.jcorporate.expresso.core.security.User; 77 import com.jcorporate.expresso.kernel.util.FastStringBuffer; 78 79 import java.util.Iterator ; 80 import java.util.Vector ; 81 82 87 public class RegisteredUser 88 extends com.jcorporate.expresso.services.dbobj.RegistrationDBObject { 89 90 93 public RegisteredUser() 94 throws DBException { 95 } 96 97 102 public RegisteredUser(DBConnection myConnection) 103 throws DBException { 104 super(myConnection); 105 } 106 107 114 public RegisteredUser(int uid) 115 throws DBException { 116 super(uid); 117 } 118 119 126 public RegisteredUser(RequestContext request) 127 throws DBException { 128 super(request); 129 } 130 131 134 public void add() 135 throws DBException { 136 setField("AddedOn", DateTime.getDateTimeForDB(this.getDataContext())); 137 setField("UpdatedOn", DateTime.getDateTimeForDB(this.getDataContext())); 138 super.add(); 139 sendNotice("New Registration:"); 140 } 141 142 147 private void sendNotice(String topic) 148 throws DBException { 149 FastStringBuffer theMessage = new FastStringBuffer(512); 150 151 theMessage.append(topic); 152 theMessage.append("\n\n"); 153 User theUser = new User(); 154 theUser.setDataContext(this.getDataContext()); 155 theUser.setUid(getFieldInt("ExpUid")); 156 theUser.retrieve(); 157 theMessage.append("Login Name:" + theUser.getLoginName() + "\n\n"); 158 159 String oneField = null; 160 161 for (Iterator ef = this.getMetaData().getFieldListArray().iterator(); ef.hasNext();) { 162 oneField = (String ) ef.next(); 163 theMessage.append(getString(getMetaData().getDescription(oneField)) + ":" + 164 getField(oneField) + "\n"); 165 } 166 167 EventHandler.Event(getDataContext(), "REGISTER", theMessage.toString(), 168 true); 169 } 170 171 172 177 public String getField(String fieldName) 178 throws DBException { 179 if (fieldName.equalsIgnoreCase("UserEMail")) { 180 User myUser = new User(); 181 myUser.setDataContext(this.getDataContext()); 182 183 if (StringUtil.notNull(getField("ExpUid")).equals("")) { 184 return null; 185 } 186 187 myUser.setUid(getField("ExpUid")); 188 189 try { 190 myUser.retrieve(); 191 192 return myUser.getEmail(); 193 } catch (DBRecordNotFoundException de) { 194 return "No Such User"; 195 } 196 } else if (fieldName.equals("LoginName")) { 197 User u = new User(); 198 u.setUid(getFieldInt("ExpUid")); 199 u.setDataContext(this.getDataContext()); 200 201 if (u.find()) { 202 return u.getLoginName(); 203 } 204 205 return "No such user"; 206 } 207 208 return super.getField(fieldName); 209 } 210 211 212 217 public Vector getValidValues(String fieldName) 218 throws DBException { 219 if (fieldName.equals("Employees")) { 220 Vector h = new Vector (5); 221 h.addElement(new ValidValue("0", "1 - 10")); 222 h.addElement(new ValidValue("A", "11 - 49")); 223 h.addElement(new ValidValue("1", "50 - 100")); 224 h.addElement(new ValidValue("2", "101-500")); 225 h.addElement(new ValidValue("3", "501-1000")); 226 h.addElement(new ValidValue("4", "1001-10,000")); 227 h.addElement(new ValidValue("5", "More than 10,000")); 228 229 return h; 230 } else if (fieldName.equals("Industry")) { 231 Vector h = new Vector (24); 232 h.addElement(new ValidValue("01", "Aerospace")); 233 h.addElement(new ValidValue("03", "Education")); 234 h.addElement(new ValidValue("04", "Engineering/Architecture")); 235 h.addElement(new ValidValue("FINANCIAL", 236 "Financial Services/Banking")); 237 h.addElement(new ValidValue("05", "Finance/Accounting/Banking")); 238 h.addElement(new ValidValue("06", "Government")); 239 h.addElement(new ValidValue("HEALTH", "Healthcare/Medical")); 240 h.addElement(new ValidValue("MANUF", "Manufacturing")); 241 h.addElement(new ValidValue("09", "Marketing/PR")); 242 h.addElement(new ValidValue("10", 243 "Process Industries (mine/farm/const.)")); 244 h.addElement(new ValidValue("11", 245 "Publishing/Electronic Publishing")); 246 h.addElement(new ValidValue("12", "Research & Development")); 247 h.addElement(new ValidValue("RETAIL", 248 "Retailer/Distributor/Wholesaler")); 249 h.addElement(new ValidValue("TELECOM", "Telecommunications")); 250 h.addElement(new ValidValue("15", "Transportation")); 251 h.addElement(new ValidValue("16", "Utilities")); 252 h.addElement(new ValidValue("17", "Custom Development/Consulting")); 253 h.addElement(new ValidValue("SOFTWARE", "Software")); 254 h.addElement(new ValidValue("23", "Systems Integrator/VAR/OEM")); 255 h.addElement(new ValidValue("CONSULT", "Consulting")); 256 h.addElement(new ValidValue("OTHER", "Other (Specify in Comment)")); 257 258 return h; 259 } else if (fieldName.equals("JobTitle")) { 260 Vector h = new Vector (); 261 h.addElement(new ValidValue("01", "Corporate Management")); 262 h.addElement(new ValidValue("02", "Other Management")); 263 h.addElement(new ValidValue("03", "IS/MIS/Technical Management")); 264 h.addElement(new ValidValue("04", "IS/MIS/Technical Staff")); 265 h.addElement(new ValidValue("05", "Internet/Web Management, Staff")); 266 h.addElement(new ValidValue("06", "Consultant")); 267 h.addElement(new ValidValue("07", "Educator/Trainer")); 268 h.addElement(new ValidValue("08", "Student")); 269 h.addElement(new ValidValue("09", "Developer")); 270 h.addElement(new ValidValue("10", "Independent Contractor")); 271 272 return h; 273 } else if (fieldName.equals("Country")) { 274 ISOCountryCodes countries = new ISOCountryCodes(SecuredDBObject.SYSTEM_ACCOUNT); 275 countries.setDataContext(this.getDataContext()); 276 Vector v = countries.getValues(); 277 return v; 278 } 279 280 return super.getValidValues(fieldName); 281 } 282 283 284 289 public void notify(String subject, String message) 290 throws DBException { 291 User myUser = new User(); 292 myUser.setDataContext(this.getDataContext()); 293 myUser.setUid(this.getField("ExpUid")); 294 if (!myUser.find()) { 295 throw new DBException("Unable to locate user: " + this.getField("ExpUid")); 296 } 297 298 myUser.notify(subject, message); 299 } 300 301 302 306 public void setupFields() 307 throws DBException { 308 setTargetTable("USERREGISTER"); 309 setDescription("DBuserRegister"); 310 setCharset("ISO-8859-1"); 311 addField("ExpUid", "int", 0, false, "userId"); 312 addVirtualField("LoginName", "char", 30, "loginName"); 313 addField("FirstName", "varchar", 30, false, "firstName"); 314 addField("LastName", "varchar", 80, false, "lastName"); 315 addField("FullName", "varchar", 80, true, "yourName"); 316 addField("CompanyName", "varchar", 30, true, "orgName"); 317 addField("URL", "varchar", 255, true, "url"); 318 addField("Address", "text", 0, false, "address"); 319 addField("City", "varchar", 40, false, "city"); 320 addField("StateProvince", "varchar", 40, false, "stateProvince"); 321 addField("PostalCode", "varchar", 15, true, "postalZip"); 322 addField("Country", "varchar", 40, false, "country"); 323 setDefaultValue("Country", "US"); 324 addField("UserComment", "text", 0, true, "userComment"); 325 addField("Industry", "char", 10, false, "industry"); 326 setDefaultValue("Industry", "17"); 327 addField("Employees", "char", 1, false, "employees"); 328 setDefaultValue("Employees", "0"); 329 addField("JobTitle", "char", 2, true, "jobTitle"); 330 addField("Subscribe", "char", 1, true, "subscribeToListServ"); 331 setDefaultValue("Subscribe", "Y"); 332 this.getMetaData().setAttribute("Subscribe", "checkbox", "Y"); 333 addField("Contributing", "char", 1, true, "contributing"); 334 setDefaultValue("Contributing", "N"); 335 this.getMetaData().setAttribute("Contributing", "checkbox", "Y"); 336 addField("Projects", "char", 1, true, "projectNotifications"); 337 this.getMetaData().setAttribute("Projects", "checkbox", "Y"); 338 setDefaultValue("Projects", "Y"); 339 addField("IsActive", "char", 1, true, "active"); 340 this.getMetaData().setAttribute("IsActive", "checkbox", "Y"); 341 addField("InternalComment", "text", 0, true, "internalComment"); 342 addField("AddedOn", "datetime", 0, true, "addedOn"); 343 addField("UpdatedOn", "datetime", 0, true, "updatedOn"); 344 addField("EmailPrivate", "char", 1, true, "keepEmailPrivate"); 345 addField("Occupation", "text", 0, true, "occupation"); 346 addField("Location", "text", 0, true, "location"); 347 addField("Expertise", "text", 0, true, "expertise"); 348 addField("Contributions", "text", 0, true, "contributions"); 349 addField("OtherProjects", "text", 0, true, "otherProjects"); 350 addField("Phone", "varchar", 80, true, "phone"); 351 addField("Testimonial", "text", 0, true, "testimonial"); 352 addField("IPAddress", "varchar", 30, true, "ipAddress"); 353 setReadOnly("IPAddress"); 354 setReadOnly("UpdatedOn"); 355 setReadOnly("AddedOn"); 356 357 addVirtualField("UserEMail", "varchar", 80, "EMail Address"); 360 setLookupObject("ExpUid", "com.jcorporate.expresso.core.security.User"); 361 addKey("ExpUid"); 362 setMultiValued("JobTitle"); 363 setMultiValued("Industry"); 364 setMultiValued("Employees"); 365 setMultiValued("Country"); 366 } 367 368 369 374 public void update() 375 throws DBException { 376 setField("UpdatedOn", DateTime.getDateTimeForDB(this.getDataContext())); 377 super.update(); 378 sendNotice("Updated Registration:"); 379 } 380 381 382 } 383 | Popular Tags |