1 64 65 package com.jcorporate.expresso.services.dbobj; 66 67 import com.jcorporate.expresso.core.db.DBConnection; 68 import com.jcorporate.expresso.core.db.DBException; 69 import com.jcorporate.expresso.core.dbobj.RequestContext; 70 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 71 import com.jcorporate.expresso.core.misc.EventHandler; 72 import com.jcorporate.expresso.core.security.User; 73 import com.jcorporate.expresso.core.security.UserListener; 74 import org.apache.log4j.Logger; 75 76 import java.util.Iterator ; 77 78 79 86 abstract public class RegistrationDBObject extends SecuredDBObject 87 implements UserListener { 88 89 static private final String thisClass = RegistrationDBObject.class.getName(); 90 static private Logger log = Logger.getLogger(RegistrationDBObject.class); 91 92 97 public RegistrationDBObject() throws DBException { 98 super(); 99 addAsUserListener(this); 100 } 101 102 103 108 public RegistrationDBObject(DBConnection myConnection) throws DBException { 109 super(myConnection); 110 addAsUserListener(this); 111 } 112 113 114 132 public RegistrationDBObject(DBConnection dbConnection, String securityContext) 133 throws DBException { 134 super(dbConnection, securityContext); 135 addAsUserListener(this); 136 } 137 138 145 public RegistrationDBObject(int uid) throws DBException { 146 super(uid); 147 addAsUserListener(this); 148 } 149 150 156 public RegistrationDBObject(RequestContext request) throws DBException { 157 super(request); 158 addAsUserListener(this); 159 } 160 161 162 168 public void deletedUser(User user) throws DBException { 169 RegistrationDBObject regobj = null; 170 try { 171 regobj = (RegistrationDBObject) Class.forName(this.getClass().getName()).newInstance(); 172 } catch (Exception e) { 173 throw new DBException(thisClass + 174 ".deletedUser() Error instantiating class: " 175 + this.getClass().getName()); 176 } 177 regobj.setDataContext(user.getDataContext()); 178 179 String uidFieldName = getUidFieldName(user); 181 182 try { 183 regobj.setField(uidFieldName, user.getUid()); 184 } catch (Exception e) { 185 regobj.setField("ExpUid", user.getUid()); } 188 189 RegistrationDBObject oneMember = null; 190 191 for (Iterator e = regobj.searchAndRetrieveList().iterator(); e.hasNext();) { 192 oneMember = (RegistrationDBObject) e.next(); 193 194 try { 195 oneMember.delete(); 196 } catch (DBException dbe) { 197 String msg = "Error deleting registration info for class: " + 198 this.getClass().getName() + 199 " please delete these records manually as soon as possible"; 200 201 log.error(msg, dbe); 202 203 EventHandler.Event(user.getDataContext(), "SYSERROR", 204 msg, false); 205 } 206 } 207 208 } 209 210 private String getUidFieldName(User user) throws DBException { 211 String uidFieldName = "ExpUid"; 212 RegistrationDomain rd = new RegistrationDomain(); 213 rd.setDataContext(user.getDataContext()); 214 rd.setField("Name", user.getRegistrationDomain()); 215 216 if (!rd.find()) { 217 throw new DBException( 218 "User '+ " + user.getLoginName() + " specifies registration domain name = '" + user.getRegistrationDomain() + "' but cannot find this domain."); 219 } 220 221 RegistrationObjectMap rom = new RegistrationObjectMap(SecuredDBObject.SYSTEM_ACCOUNT); 222 rom.setDataContext(user.getDataContext()); 223 rom.setField("RegDomId", rd.getField("RegDomId")); 224 225 if (rom.find()) { 226 uidFieldName = rom.getField("UidField"); 227 } 228 return uidFieldName; 229 } 230 231 232 protected synchronized static void addAsUserListener(UserListener ul) { 233 if (!User.isListener(ul)) { 234 User.addListener(ul); 235 } 236 } 237 238 public void addedUser(User user) throws DBException { 239 return; 240 } 241 242 public void loggedOffUser(User user) throws DBException { 243 return; 244 } 245 246 public void loggedOnUser(User user) throws DBException { 247 return; 248 } 249 250 public void modifiedUser(User user) throws DBException { 251 return; 252 } 253 } 254 | Popular Tags |