1 64 65 package com.jcorporate.expresso.services.dbobj; 66 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.security.User; 72 73 import java.util.Vector ; 74 75 76 82 public class EventMail 83 extends SecuredDBObject { 84 87 public EventMail() 88 throws DBException { 89 super(); 90 } 91 92 98 103 107 public EventMail(int uid) 108 throws DBException { 109 super(uid); 110 } 111 112 119 public EventMail(RequestContext request) 120 throws DBException { 121 super(request); 122 } 123 124 129 protected void checkAllRefs() 130 throws DBException { 131 checkRef("Event", new Event(), "Invalid " + getString(getMetaData().getDescription("Event"))); 132 } 133 134 135 144 public synchronized Vector getValidValues(String fieldName) 145 throws DBException { 146 if (fieldName.equals("Success")) { 147 Vector myValues = new Vector (2); 148 myValues.addElement(new ValidValue("Y", "Yes")); 149 myValues.addElement(new ValidValue("N", "No")); 150 151 return myValues; 152 } 153 154 return super.getValidValues(fieldName); 155 } 156 157 158 161 protected synchronized void setupFields() 162 throws DBException { 163 setTargetTable("EVENTMAIL"); 164 setDescription("DBeventMail"); 165 setCharset("ISO-8859-1"); 166 addField("Event", "char", 30, false, "eventCode"); 167 addField("ExpUid", "int", 0, false, "userId"); 168 addVirtualField("LoginName", "char", 30, "loginName"); 169 addField("Success", "char", 1, false, "userNotifiedOnSuccess"); 170 addKey("Event"); 171 addKey("ExpUid"); 172 addKey("Success"); 173 setStringFilter("Event", "stripFilter"); 174 setMultiValued("Event"); 175 setMultiValued("Success"); 176 setLookupObject("Event", 177 "com.jcorporate.expresso.services.dbobj.Event"); 178 setLookupObject("ExpUid", "com.jcorporate.expresso.core.security.User"); 179 } 180 181 182 189 public String getField(String fieldName) 190 throws DBException { 191 if (fieldName.equals("LoginName")) { 192 User u = new User(); 193 u.setUid(getFieldInt("ExpUid")); 194 u.setDataContext(this.getDataContext()); 195 196 if (u.find()) { 197 return u.getLoginName(); 198 } 199 200 return "No such user"; 201 } 202 203 return super.getField(fieldName); 204 } 205 206 209 public synchronized void populateDefaultValues() 210 throws DBException { 211 int adminId = User.getAdminId(getDataContext()); 212 213 EventMail oneMail = new EventMail(); 215 oneMail.setDataContext(getDataContext()); 216 oneMail.setField("Event", "SYSERROR"); 217 oneMail.setField("ExpUid", adminId); 218 oneMail.setField("Success", "Y"); 219 220 if (!oneMail.find()) { 221 oneMail.add(); 222 } 223 224 oneMail.clear(); 225 oneMail.setField("Event", "SYSERROR"); 226 oneMail.setField("ExpUid", adminId); 227 oneMail.setField("Success", "N"); 228 229 if (!oneMail.find()) { 230 oneMail.add(); 231 } 232 233 oneMail.clear(); 235 oneMail.setField("Event", "HEALTH"); 236 oneMail.setField("ExpUid", adminId); 237 oneMail.setField("Success", "Y"); 238 239 if (!oneMail.find()) { 240 oneMail.add(); 241 } 242 243 oneMail.clear(); 244 oneMail.setField("Event", "HEALTH"); 245 oneMail.setField("ExpUid", adminId); 246 oneMail.setField("Success", "N"); 247 248 if (!oneMail.find()) { 249 oneMail.add(); 250 } 251 252 oneMail.clear(); 254 oneMail.setDataContext(getDataContext()); 255 oneMail.setField("Event", "DOWNLOAD"); 256 oneMail.setField("ExpUid", adminId); 257 oneMail.setField("Success", "Y"); 258 259 if (!oneMail.find()) { 260 oneMail.add(); 261 } 262 263 oneMail.clear(); 264 oneMail.setDataContext(getDataContext()); 265 oneMail.setField("Event", "DOWNLOAD"); 266 oneMail.setField("ExpUid", adminId); 267 oneMail.setField("Success", "N"); 268 269 if (!oneMail.find()) { 270 oneMail.add(); 271 } 272 273 oneMail.clear(); 275 oneMail.setDataContext(getDataContext()); 276 oneMail.setField("Event", "REGISTER"); 277 oneMail.setField("ExpUid", adminId); 278 oneMail.setField("Success", "Y"); 279 280 if (!oneMail.find()) { 281 oneMail.add(); 282 } 283 284 oneMail.clear(); 285 oneMail.setDataContext(getDataContext()); 286 oneMail.setField("Event", "REGISTER"); 287 oneMail.setField("ExpUid", adminId); 288 oneMail.setField("Success", "N"); 289 290 if (!oneMail.find()) { 291 oneMail.add(); 292 } 293 } 294 295 296 } 297 298 | Popular Tags |