1 64 package com.jcorporate.expresso.services.dbobj; 65 66 import com.jcorporate.expresso.core.controller.Controller; 67 import com.jcorporate.expresso.core.db.DBException; 68 import com.jcorporate.expresso.core.dbobj.RequestContext; 69 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 70 import com.jcorporate.expresso.core.dbobj.ValidValue; 71 import com.jcorporate.expresso.core.misc.ConfigManager; 72 import com.jcorporate.expresso.core.misc.StringUtil; 73 import com.jcorporate.expresso.core.security.User; 74 75 import java.util.Iterator ; 76 import java.util.Vector ; 77 78 79 90 public class RegistrationDomain extends SecuredDBObject { 91 96 public RegistrationDomain() throws DBException { 97 super(); 98 } 99 100 101 108 public RegistrationDomain(int uid) throws DBException { 109 super(uid); 110 } 111 112 120 public RegistrationDomain(RequestContext request) throws DBException { 121 super(request); 122 } 123 124 132 public Vector getValidValues(String fieldName) throws DBException { 133 if (fieldName.equals("RegRequired") || fieldName.equals("Approve") || 134 fieldName.equals("UserPasswd") || 135 fieldName.equals("EmailValidate") || 136 fieldName.equals("EmailAsLogin")) { 137 Vector myValues = new Vector (2); 138 myValues.addElement(new ValidValue("Y", "Yes")); 139 myValues.addElement(new ValidValue("N", "No")); 140 141 return myValues; 142 } 143 144 if (fieldName.equals("NotApprovedGrp")) { 145 Vector myValues = super.getValidValues(fieldName); 146 myValues.add(0, new ValidValue("", getString("notSelected"))); 147 return myValues; 148 } 149 150 return super.getValidValues(fieldName); 151 } 152 153 154 157 public Vector getValues() throws DBException { 158 return getValuesDefault("RegDomId", "Name"); 159 } 160 161 162 170 public void add() throws com.jcorporate.expresso.core.db.DBException { 171 RegistrationDomain rd = new RegistrationDomain(); 172 rd.setDataContext(getDataContext()); 173 rd.setField("Name", this.getField("Name")); 174 175 if (rd.find()) { 176 throw new DBException("Registration domain \"" + 177 rd.getField("Name") + "\" already exists."); 178 } 179 180 if (getField("RegRequired").equals("")) { 181 setField("RegRequired", "Y"); 182 } 183 184 if (getField("Approve").equals("")) { 185 setField("Approve", "N"); 186 } 187 188 if (getField("UserPasswd").equals("")) { 189 setField("UserPasswd", "N"); 190 } 191 192 if (getField("EmailValidate").equals("")) { 193 setField("EmailValidate", "Y"); 194 } 195 196 if (getField("EmailAsLogin").equals("")) { 197 setField("EmailAsLogin", "Y"); 198 } 199 200 if (getField("NotApprovedGrp").equals("")) { 201 setField("NotRegGrp", "NotReg"); 202 } 203 204 if (getField("Approve").equals("Y")) { 205 if (getField("Approvers").equals("")) { 206 setField("Approvers", User.ADMIN_USER); 207 } 208 209 if (getField("NotApprovedGrp").equals("")) { 210 setField("NotApprovedGrp", "NotReg"); 211 } 212 } 213 214 super.add(); 215 } 216 217 218 226 public static RegistrationDomain buildDefaultRegistrationDomain(String dbContext) throws DBException { 227 String regDomain = Setup.getValueRequired(dbContext, "defaultRegDomain"); 228 RegistrationDomain rd = new RegistrationDomain(SecuredDBObject.SYSTEM_ACCOUNT); 229 rd.setDataContext(dbContext); 230 rd.setField("Name", regDomain); 231 232 if (rd.find()) { 233 return rd; 234 } else { 235 throw new DBException("Unable to locate default registration domain: '" + regDomain + 236 "'"); 237 } 238 } 239 240 246 public Controller getRegistrationObject() throws DBException { 247 StringUtil.assertNotBlank(this.getField("ControllerClass"), 248 "Invalid Registration ControllerClassname for this object"); 249 250 try { 251 return ConfigManager.getControllerFactory().getController(this.getField("ControllerClass")); 252 } catch (com.jcorporate.expresso.core.controller.ControllerException ce) { 253 throw new DBException("Error creating Registration controller", ce); 254 } 255 } 256 257 266 public void delete() throws com.jcorporate.expresso.core.db.DBException { 267 RegistrationObjectMap rom = new RegistrationObjectMap(); 268 rom.setDataContext(getDataContext()); 269 rom.setField("RegDomId", this.getField("RegDomId")); 270 271 RegistrationObjectMap oneRom = null; 272 273 for (Iterator e = rom.searchAndRetrieveList().iterator(); e.hasNext();) { 274 oneRom = (RegistrationObjectMap) e.next(); 275 oneRom.delete(); 276 } 277 278 super.delete(); 279 } 280 281 287 public void update() throws com.jcorporate.expresso.core.db.DBException { 288 RegistrationDomain rd = new RegistrationDomain(); 289 rd.setDataContext(getDataContext()); 290 rd.setField("Name", this.getField("Name")); 291 292 if (rd.find() && 293 (!rd.getField("RegDomId").equals(this.getField("RegDomId")))) { 294 throw new DBException("Registration domain \"" + 295 rd.getField("Name") + "\" already exists."); 296 } 297 298 if (getField("RegRequired").equals("")) { 299 setField("RegRequired", "Y"); 300 } 301 302 if (getField("RegRequired").equals("")) { 303 setField("RegRequired", "Y"); 304 } 305 306 if (getField("Approve").equals("")) { 307 setField("Approve", "N"); 308 } 309 310 if (getField("UserPasswd").equals("")) { 311 setField("UserPasswd", "N"); 312 } 313 314 if (getField("EmailValidate").equals("")) { 315 setField("EmailValidate", "Y"); 316 } 317 318 if (getField("EmailAsLogin").equals("")) { 319 setField("EmailAsLogin", "Y"); 320 } 321 322 if (getField("NotApprovedGrp").equals("")) { 323 setField("NotRegGrp", "NotReg"); 324 } 325 326 if (getField("Approve").equals("Y")) { 327 if (getField("Approvers").equals("")) { 328 setField("Approvers", User.ADMIN_USER); 329 } 330 331 if (getField("NotApprovedGrp").equals("")) { 332 setField("NotApprovedGrp", "NotReg"); 333 } 334 } 335 336 super.update(); 337 } 338 339 340 346 protected void checkAllRefs() throws DBException { 347 checkRef("GroupName", new UserGroup(SecuredDBObject.SYSTEM_ACCOUNT), 348 "Invalid " + getString(getMetaData().getDescription("GroupName"))); 349 } 350 351 352 362 protected void setupFields() throws DBException { 363 setTargetTable("REGDOMAIN"); 364 setDescription("DBregDomain"); 365 setCharset("ISO-8859-1"); 366 addField("RegDomId", "auto-inc", 0, false, "regDomId"); 367 addField("Name", "varchar", 30, false, "name"); 368 addField("Description", "varchar", 128, false, "description"); 369 addField("GroupName", "char", 10, false, "defaultGroup"); 370 addField("ControllerClass", "varchar", 128, true, "regControllerClass"); 371 addField("RegRequired", "char", 1, true, "regRequired"); 372 addField("Approve", "char", 1, true, "approvalRequired"); 373 addField("UserPasswd", "char", 1, true, "userPassword"); 374 addField("EmailValidate", "char", 1, true, "emailValidate"); 375 addField("EmailAsLogin", "char", 1, true, "emailAsLogin"); 376 addField("Approvers", "text", 0, true, "loginNamesForApprovers"); 377 addField("NotRegGrp", "char", 10, true, "groupBeforeRegistration"); 378 addField("NotApprovedGrp", "char", 10, true, "groupBeforeApproval"); 379 addKey("RegDomId"); 380 setReadOnly("RegDomId"); 381 382 addIndex("RegDomainName", "Name", true); 386 setStringFilter("Name", "stripFilter"); 387 setStringFilter("Description", "stripFilter"); 388 setStringFilter("ControllerClass", "stripFilter"); 389 setStringFilter("GroupName", "stripFilter"); 390 setStringFilter("Approvers", "stripFilter"); 391 setMultiValued("RegRequired"); 392 setMultiValued("Approve"); 393 setMultiValued("UserPasswd"); 394 setMultiValued("EmailValidate"); 395 setMultiValued("EmailAsLogin"); 396 setMultiValued("GroupName"); 397 setMultiValued("NotRegGrp"); 398 setMultiValued("NotApprovedGrp"); 399 setLookupObject("GroupName", 400 "com.jcorporate.expresso.services.dbobj.UserGroup"); 401 setLookupObject("NotRegGrp", 402 "com.jcorporate.expresso.services.dbobj.UserGroup"); 403 setLookupObject("NotApprovedGrp", 404 "com.jcorporate.expresso.services.dbobj.UserGroup"); 405 addDetail("com.jcorporate.expresso.services.dbobj.RegistrationObjectMap", 406 "RegDomId", "RegDomId"); 407 } 408 409 } 410 | Popular Tags |