1 package de.webman.content.workflow; 2 3 import com.teamkonzept.lib.*; 4 import com.teamkonzept.db.*; 5 import de.webman.content.workflow.db.queries.*; 6 import com.teamkonzept.international.LanguageManager; 7 8 import java.util.*; 9 import java.sql.*; 10 11 import org.apache.log4j.Category; 12 13 18 public class VersionStatus implements TKHashable 19 { 20 21 private static Category cat = Category.getInstance(VersionStatus.class); 22 23 24 public static int defaultNewStatus = 1; 25 26 27 public int status_id = -1; 28 29 30 private String name; 31 32 33 public String attributes; 34 35 36 private String id; 37 38 39 private String shortName; 40 41 42 private String originalShortName; 43 44 45 public String filter; 46 47 48 public String event; 49 50 51 public boolean single; 52 53 54 public boolean confirm; 55 56 57 public boolean delete; 58 59 public boolean rename; 60 61 62 public boolean newContent; 63 public boolean newVersion; 64 65 66 public boolean generate; 67 68 69 public boolean comment; 70 71 72 public TKHashtable hashed; 73 74 public VersionStatus () 75 { 76 init (-1,null,null); 77 } 78 79 public VersionStatus (int status_id, String status, String attributes) 80 { 81 init (status_id,status,attributes); 82 } 83 84 87 public VersionStatus (ResultSet rs) { 88 89 try 90 { 91 init(rs); 92 } 93 catch (Exception ex) 94 { 95 init (-1,null,null); 96 } 97 } 98 99 private void init(ResultSet rs) throws SQLException 100 { 101 status_id = rs.getInt("STATUS_ID"); 102 name = rs.getString("STATUS"); 103 attributes = rs.getString("STATUS_ATTRIBUTES"); 104 scanAttributes (); 105 } 106 107 110 public void init (int status_id, String status, String attributes) 111 { 112 this.status_id = status_id; 113 name = status; 114 this.attributes = attributes; 115 scanAttributes (); 116 makeHashed(); 117 } 118 119 public String getName() 120 { 121 return LanguageManager.getText("workflow", name, null); 122 } 124 125 public String getShortName() 126 { 127 return LanguageManager.getText("workflow", shortName, null); 128 } 129 130 133 public void getFromEvent(TKHashtable params) 134 { 135 name = (String )params.get("STATUS"); 136 single= params.get("STATUS_SINGLE") != null; 137 confirm = params.get("CONFIRM") != null; 138 rename = params.get ("RENAME") != null; 139 newContent = params.get ("NEW_CONTENT") != null; 140 newVersion = params.get ("NEW_VERSION") != null; 141 generate = params.get("GENERATE") != null; 142 comment = params.get ("COMMENT") != null; 143 delete = params.get("DELETE") != null; 144 assembleAttributes(); 146 hashed = null; 147 cat.debug("Aktuelle Attribute : " + attributes); 148 } 149 150 153 public void saveToDB() 154 { 155 try 156 { 157 TKQuery query = null; 158 if (status_id != -1) 160 { 161 query = TKDBManager.newQuery(UpdateStatus.class); 162 query.setQueryParams("STATUS_ID", new Integer (status_id)); 163 } 164 else 165 { 166 query = TKDBManager.newQuery(InsertStatus.class); 167 } 168 query.setQueryParams("STATUS", name); 169 query.setQueryParams("STATUS_ATTRIBUTES", attributes); 170 query.execute(); 171 if (status_id == -1) 172 { 173 ResultSet rs = query.fetchResultSet(); 174 if (rs.next()) 175 init(rs); 176 } 177 } 178 catch (SQLException e) 179 { 180 cat.error("Error during save ", e); 181 } 182 } 183 184 188 public void assembleAttributes () 189 { 190 attributes = 191 (id == null ? "" : "id:" + id + ";") + 192 (shortName == null ? "" : "shortName:" + shortName + ";") + 193 (filter == null ? "" : "filter:" + filter + ";") + 194 (event == null ? "" : "event:" + event + ";") + 195 (single ? "" : "single:off;") + 196 (confirm ? "confirm;" : "") + 197 (rename ? "rename;" : "") + 198 (newContent ? "new;" : "") + 199 (newVersion ? "newVersion;" : "") + 200 (generate ? "generate;" : "") + 201 (comment ? "comment;" : "") + 202 (delete ? "delete:true" : ""); 203 } 204 205 208 public void scanAttributes () 209 { 210 id = null; 211 shortName = null; 212 filter = null; 213 event = null; 214 single = true; 215 confirm = false; 216 rename = false; 217 newContent = false; 218 newVersion = false; 219 generate = false; 220 comment = false; 221 222 if (attributes == null) return; 223 224 StringTokenizer tokenizer = new StringTokenizer(attributes,";"); 225 while (tokenizer.hasMoreTokens()) { 226 227 String attr = tokenizer.nextToken(); 228 if (attr == null) continue; 229 230 StringTokenizer sub = new StringTokenizer(attr,":"); 231 String attrName = sub.hasMoreTokens() ? sub.nextToken() : null; 232 233 if (attrName == null) continue; 234 String attrValue = sub.hasMoreTokens() ? sub.nextToken() : null; 235 236 if (attrName.equalsIgnoreCase ("id") && attrValue != null) this.id = attrValue; 237 else if (attrName.equalsIgnoreCase ("short") && attrValue != null) 238 { 239 this.shortName = LanguageManager.getText("workflow", attrValue); 240 originalShortName = attrValue; 241 } 242 else if (attrName.equalsIgnoreCase ("filter") && attrValue != null) 243 this.filter = attrValue.toUpperCase(); 244 else if (attrName.equalsIgnoreCase ("event") && attrValue != null) 245 this.event = attrValue.toUpperCase(); 246 else if (attrName.equalsIgnoreCase ("single") && attrValue != null) 247 this.single = attrValue.equalsIgnoreCase("on"); 248 else if (attrName.equalsIgnoreCase ("confirm")) this.confirm = true; 249 else if (attrName.equalsIgnoreCase ("rename")) this.rename = true; 250 else if (attrName.equalsIgnoreCase ("new")) this.newContent = true; 251 else if (attrName.equalsIgnoreCase ("newversion")) this.newVersion = true; 252 else if (attrName.equalsIgnoreCase ("generate")) this.generate = true; 253 else if (attrName.equalsIgnoreCase ("comment")) this.comment = true; 254 else if (attrName.equalsIgnoreCase ("delete")) delete = true; 255 originalShortName = name + "_short"; 256 shortName = name + "shortbogus"; 257 } 258 } 259 260 264 public void makeHashed () 265 { 266 hashed = new TKHashtable(); 267 hashed.put ("STATUS_ID",new Integer (status_id)); 268 269 if (name != null) hashed.put ("STATUS", name); 270 if (attributes != null) hashed.put ("STATUS_ATTRIBUTES",attributes); 271 if (id != null) hashed.put ("STATUS_SHORT_ID",id); 272 if (shortName != null) 273 { 274 hashed.put ("STATUS_SHORT", shortName); 275 hashed.put ("STATUS_SHORT_ORIGINAL", originalShortName); 276 277 } 278 279 if (filter != null) hashed.put ("STATUS_FILTER",filter); 280 if (event != null) hashed.put ("STATUS_EVENT",event); 281 if (single) hashed.put ("STATUS_SINGLE", Boolean.TRUE); 282 if (confirm) hashed.put ("CONFIRM", Boolean.TRUE); 283 if (rename) hashed.put ("RENAME", Boolean.TRUE); 284 if (newContent) hashed.put ("NEW_CONTENT", Boolean.TRUE); 285 if (newVersion) hashed.put ("NEW_VERSION", Boolean.TRUE); 286 if (generate) hashed.put ("GENERATE", Boolean.TRUE); 287 if (comment) hashed.put ("COMMENT", Boolean.TRUE); 288 if (delete) hashed.put("DELETE", Boolean.TRUE); 289 } 290 291 294 public TKHashtable toHashtable () 295 { 296 if (hashed == null) makeHashed(); 297 return hashed; 298 } 299 300 301 304 public static TKHashtable load () throws Exception 305 { 306 TKHashtable statusPool = new TKHashtable(); 307 TKQuery query = TKDBManager.newQuery(VersionStatusGetAll.class); 308 query.execute(); 309 ResultSet rs = query.fetchResultSet(); 310 311 while (rs.next()) { 312 VersionStatus desc = new VersionStatus (rs); 313 statusPool.put (new Integer (desc.status_id),desc); 314 } 315 return statusPool; 316 } 317 318 323 public static TKHashtable selectSingles (VersionStatics statics, boolean single) 324 { 325 TKHashtable list = new TKHashtable(); 326 Enumeration e = statics.getStatusPool().elements(); 327 while (e.hasMoreElements()) 328 { 329 VersionStatus status = (VersionStatus) e.nextElement(); 330 if (!single || status.single) 331 list.put (new Integer (status.status_id),status); 332 } 333 return list; 334 } 335 336 339 public static TKVector selectNotNewVersion (VersionStatics statics) 340 { 341 TKVector list = new TKVector(); 342 Enumeration e = statics.getStatusPool().elements(); 343 while (e.hasMoreElements()) 344 { 345 VersionStatus status = (VersionStatus) e.nextElement(); 346 if (! (status.newVersion || status.comment)) 347 { 348 TKHashtable attributes = new TKHashtable(); 349 attributes.put("STATUS_ID", new Integer ( status.status_id )); 350 attributes.put("STATUS_SHORT_ORIGINAL", new String (status.originalShortName)); 351 attributes.put("STATUS", new String (status.getName())); 352 if (status.confirm) 353 attributes.put("CONFIRM", new String ("TRUE")); 354 list.add (attributes); 355 } 356 } 357 return list; 358 } 359 360 363 public static TKHashtable filterComments (VersionStatics statics) 364 { 365 TKHashtable list = new TKHashtable(); 366 Enumeration e = statics.getStatusPool().elements(); 367 while (e.hasMoreElements()) 368 { 369 VersionStatus status = (VersionStatus) e.nextElement(); 370 if (!status.comment) 371 list.put (new Integer (status.status_id),status); 372 } 373 return list; 374 } 375 376 public static VersionStatus lookupRename (VersionStatics statics) 377 { 378 Enumeration e = statics.getStatusPool().elements(); 379 while (e.hasMoreElements()) 380 { 381 VersionStatus status = (VersionStatus) e.nextElement(); 382 if (status.rename) return status; 383 } 384 return null; 385 } 386 387 public static VersionStatus lookupComment (VersionStatics statics) 388 { 389 Enumeration e = statics.getStatusPool().elements(); 390 while (e.hasMoreElements()) 391 { 392 VersionStatus status = (VersionStatus) e.nextElement(); 393 if (status.comment) return status; 394 } 395 return null; 396 } 397 398 401 public static VersionStatus lookupNewContent (VersionStatics statics) 402 { 403 Enumeration e = statics.getStatusPool().elements(); 404 while (e.hasMoreElements()) 405 { 406 VersionStatus status = (VersionStatus) e.nextElement(); 407 if (status.newContent) return status; 408 } 409 return null; 410 } 411 412 416 public static TKHashtable getGeneratables (VersionStatics statics) 417 { 418 TKHashtable table = new TKHashtable(); 419 Enumeration e = statics.getStatusPool().elements(); 420 while (e.hasMoreElements()) 421 { 422 VersionStatus status = (VersionStatus) e.nextElement(); 423 if (status.generate) table.put (new Integer (status.status_id),status); 424 } 425 return table; 426 } 427 428 431 public String toInsertSql () 432 { 433 assembleAttributes(); 434 return "INSERT INTO VERSION_STATUS (STATUS_ID, STATUS, STATUS_ATTRIBUTES) "+ 435 "VALUES ("+status_id+",\""+ name +"\""+",\""+attributes+"\") "; 436 } 437 438 } 439 440 | Popular Tags |