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.misc.DateTime; 72 73 import java.util.Hashtable ; 74 import java.util.Iterator ; 75 import java.util.Vector ; 76 77 78 83 public class ValidationQueue 84 extends SecuredDBObject { 85 private Hashtable valuesCoded = null; 86 private Vector myParams = null; 87 public static final String FLD_ID = "ValID"; 88 public static final String FLD_STATUS_CODE = "StatusCode"; 89 public static final String FLD_ADDED_ON = "AddedOn"; 90 public static final String FLD_EXPIRES_AT = "ExpiresAt"; 91 public static final String FLD_PROCESSED_ON = "ProcessedOn"; 92 public static final String FLD_PROCESSED_BY = "ExpUid"; 93 public static final String FLD_VAL_CODE = "ValCode"; 94 public static final String FLD_VAL_HANDLER = "ValHandler"; 95 public static final String JOB_STATUS_NEW = "N"; 96 public static final String JOB_STATUS_AVAILABLE = "A"; 97 public static final String JOB_STATUS_WAIT = "W"; 98 public static final String JOB_STATUS_VALIDATED = "V"; 99 public static final String JOB_STATUS_DENIED = "D"; 100 public static final String JOB_STATUS_EXPIRED = "E"; 101 102 105 public ValidationQueue() 106 throws DBException { 107 super(); 108 } 109 110 117 public ValidationQueue(RequestContext request) 118 throws DBException { 119 super(request); 120 } 121 122 129 public ValidationQueue(int uid) 130 throws DBException { 131 super(uid); 132 } 133 134 141 public void add() 142 throws DBException { 143 if (getField(FLD_STATUS_CODE).equals("")) { 144 setField(FLD_STATUS_CODE, JOB_STATUS_NEW); 145 } 146 147 setField(FLD_ADDED_ON, DateTime.getDateTimeForDB(this.getDataContext())); 148 super.add(); 149 } 150 151 156 protected void checkAllRefs() 157 throws DBException { 158 checkRef(FLD_PROCESSED_BY, new DefaultUserInfo(), "Invalid " + getString(getMetaData().getDescription(FLD_PROCESSED_BY))); 160 } 161 162 168 public boolean find() 169 throws DBException { 170 boolean res = super.find(); 171 readParams(); 172 173 return res; 174 } 175 176 182 public synchronized Vector getParams() 183 throws DBException { 184 if (myParams == null) { 185 throw new DBException("Parameters not available until job queue entry has " + 186 "been retrieved"); 187 } 188 189 return (Vector ) myParams.clone(); 190 } 191 192 199 public synchronized String getParamValue(String paramCode) 200 throws DBException { 201 if (valuesCoded == null) { 202 readParams(); 203 } 204 205 return (String ) valuesCoded.get(paramCode); 206 } 207 208 215 public boolean isExpired() throws DBException { 216 java.util.Date dt = this.getFieldDate(FLD_EXPIRES_AT); 217 if (dt == null) { 218 return false; 219 } 220 return (dt.getTime() < System.currentTimeMillis()); 221 } 222 223 231 public Vector getValidValues(String fieldName) 232 throws DBException { 233 if (fieldName.equals(FLD_STATUS_CODE)) { 234 Vector myValues = new Vector (4); 235 myValues.addElement(new ValidValue(JOB_STATUS_NEW, "New")); 236 myValues.addElement(new ValidValue(JOB_STATUS_AVAILABLE, 237 "Available")); 238 myValues.addElement(new ValidValue(JOB_STATUS_WAIT, 239 "Waiting For Validation")); 240 myValues.addElement(new ValidValue(JOB_STATUS_VALIDATED, 241 "Validated")); 242 myValues.addElement(new ValidValue(JOB_STATUS_DENIED, "Denied")); 243 myValues.addElement(new ValidValue(JOB_STATUS_EXPIRED, "Expired")); 244 245 return myValues; 246 } 247 248 return super.getValidValues(fieldName); 249 } 250 251 256 private void readParams() 257 throws DBException { 258 myParams = new Vector (3); 259 valuesCoded = new Hashtable (3); 260 261 ValidationQueueParam paramList = new ValidationQueueParam(SecuredDBObject.SYSTEM_ACCOUNT); 262 paramList.setDataContext(getDataContext()); 263 paramList.setField(ValidationQueueParam.FLD_QUEUE_ID, getField(FLD_ID)); 264 265 for (Iterator e = paramList.searchAndRetrieveList(ValidationQueueParam.FLD_PARAM_NUM).iterator(); 266 e.hasNext();) { 267 ValidationQueueParam oneParam = (ValidationQueueParam) e.next(); 268 myParams.addElement(oneParam); 269 valuesCoded.put(oneParam.getField(ValidationQueueParam.FLD_PARAM_CODE), 270 oneParam.getField(ValidationQueueParam.FLD_PARAM_VAL)); 271 } 272 } 273 274 280 public void retrieve() 281 throws DBException { 282 super.retrieve(); 283 readParams(); 284 } 285 286 289 protected synchronized void setupFields() 290 throws DBException { 291 setTargetTable("VALQUEUE"); 292 setDescription("DBvalidQueue"); 293 setCharset("ISO-8859-1"); 294 addField(FLD_ID, "auto-inc", 0, false, "entryNumber"); 295 addField(FLD_STATUS_CODE, "char", 1, false, "statusCode"); 296 addField(FLD_ADDED_ON, "datetime", 0, false, "addedOn"); 297 addField(FLD_EXPIRES_AT, "datetime", 0, false, "expiresAt"); 298 addField(FLD_PROCESSED_ON, "datetime", 0, true, "processedOn"); 299 addField(FLD_PROCESSED_BY, "int", 0, true, "processedBy"); 300 addField(FLD_VAL_CODE, "varchar", 255, false, "valSecurityCode"); 301 addField(FLD_VAL_HANDLER, "varchar", 255, false, "valHandlerClass"); 302 addKey(FLD_ID); 303 setMultiValued(FLD_STATUS_CODE); 304 setReadOnly(FLD_ID); 305 setReadOnly(FLD_ADDED_ON); 306 setStringFilter(FLD_VAL_CODE, "rawFilter"); 307 setStringFilter(FLD_VAL_HANDLER, "stripFilter"); 308 setLookupObject(FLD_PROCESSED_BY, 309 com.jcorporate.expresso.services.dbobj.DefaultUserInfo.class.getName()); 310 addDetail(com.jcorporate.expresso.services.dbobj.ValidationQueueParam.class.getName(), 311 FLD_ID, ValidationQueueParam.FLD_QUEUE_ID); 312 } 313 } | Popular Tags |