KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > content > workflow > VersionStatus


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 /**
14     repraesentiert einen Status
15  * @author $Author: sebastian $
16  * @version $Revision: 1.5 $
17 */

18 public class VersionStatus implements TKHashable
19 {
20     /** Logging Category */
21     private static Category cat = Category.getInstance(VersionStatus.class);
22
23     /** Default Vorbelegung fuer neue Contents - macht das Sinn ? */
24     public static int defaultNewStatus = 1;
25
26     /** Id des Status */
27     public int status_id = -1;
28     
29     /** name des Status -> ist jetzt nur Platzhalter fuer den intern. Namen*/
30     private String JavaDoc name;
31     
32     /** die in der DB gespeicherten Attribute */
33     public String JavaDoc attributes;
34     
35     /** ganz Kurzbeschreibung z.B. b fuer bearbeiten - kann raus !*/
36     private String JavaDoc id;
37     
38     /** etwas laengerer Name, wie z.B. bea fuer bearbeiten -> ist jetzt nur Platzhalter fuer den intern. Namen*/
39     private String JavaDoc shortName;
40     
41     /** fuer die Buttons */
42     private String JavaDoc originalShortName;
43     
44     /** ist der im Standardfilter drin ?*/
45     public String JavaDoc filter;
46     
47     /** Der Event, mit dem dieser Status verbunden ist kann auch bald raus*/
48     public String JavaDoc event;
49
50     /** Ist dieser Status fuer SingleContents ? */
51     public boolean single;
52     
53     /** soll eine Transition in diesen Zustand bestaetigt werden ? */
54     public boolean confirm;
55     
56     /** wird der Content beim Schalten in diesen Content physikalisch geloescht ?*/
57     public boolean delete;
58     
59     public boolean rename;
60     
61     /** Ist dieser Status fuer neuen Content ? oder erzeugt er neuen Content ?*/
62     public boolean newContent;
63     public boolean newVersion;
64     
65     /** Ist dieser Status fuer die Generierung ? */
66     public boolean generate;
67     
68     /** ist dieser Status nur ein Kommentar, dann wird er beinahe immer ausgefiltert */
69     public boolean comment;
70     
71     /** Hashable Darstellung der Attribute */
72     public TKHashtable hashed;
73
74     public VersionStatus ()
75     {
76         init (-1,null,null);
77     }
78
79     public VersionStatus (int status_id, String JavaDoc status, String JavaDoc attributes)
80     {
81         init (status_id,status,attributes);
82     }
83
84     /**
85         Konstruktor, mit Datenbankinfos
86     */

87     public VersionStatus (ResultSet rs) {
88
89         try
90         {
91             init(rs);
92         }
93         catch (Exception JavaDoc 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     /**
108         fuehrt alle zur Initialisierung noetigen Aktionen aus
109     */

110     public void init (int status_id, String JavaDoc status, String JavaDoc attributes)
111     {
112         this.status_id = status_id;
113         name = status;
114         this.attributes = attributes;
115         scanAttributes ();
116         makeHashed();
117     }
118     
119     public String JavaDoc getName()
120     {
121         return LanguageManager.getText("workflow", name, null);
122         // return name;
123
}
124     
125     public String JavaDoc getShortName()
126     {
127         return LanguageManager.getText("workflow", shortName, null);
128     }
129     
130     /**
131         stellt die Attribute neu zusammen, aus einer Hashtabelle in die Instanzdaten
132     */

133     public void getFromEvent(TKHashtable params)
134     {
135         name = (String JavaDoc)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         // die Attribute wieder uptodate machen
145
assembleAttributes();
146         hashed = null;
147         cat.debug("Aktuelle Attribute : " + attributes);
148     }
149     
150     /**
151         speichert den aktuellen Status in die Datenbank
152     */

153     public void saveToDB()
154     {
155         try
156         {
157             TKQuery query = null;
158             // Id da ?
159
if (status_id != -1)
160             {
161                 query = TKDBManager.newQuery(UpdateStatus.class);
162                 query.setQueryParams("STATUS_ID", new Integer JavaDoc(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     /**
185         Neuzusammenstellung der Attribute in die Instanzvariable
186         attributes (Datenbanknotation)
187     */

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     /**
206         scant die Attribute eines Status, sind in der DB im Feld Version_Status.Status_Attributes
207     */

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 JavaDoc attr = tokenizer.nextToken();
228             if (attr == null) continue;
229
230             StringTokenizer sub = new StringTokenizer(attr,":");
231             String JavaDoc attrName = sub.hasMoreTokens() ? sub.nextToken() : null;
232
233             if (attrName == null) continue;
234             String JavaDoc 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     /**
261         packed die Attribute in eine Hashtabelle
262         Implementierung von TKHashable
263     */

264     public void makeHashed ()
265     {
266         hashed = new TKHashtable();
267         hashed.put ("STATUS_ID",new Integer JavaDoc(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     /**
292         Imlementierung des Interfaces TKHashable
293     */

294     public TKHashtable toHashtable ()
295     {
296         if (hashed == null) makeHashed();
297         return hashed;
298     }
299
300
301     /**
302         laedt alle Informationen aus der Datenbank
303     */

304     public static TKHashtable load () throws Exception JavaDoc
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 JavaDoc (desc.status_id),desc);
314         }
315         return statusPool;
316     }
317
318     /**
319         gibt alle Stati zurueck, die fuer Single Nodes interessant sind
320         @param single wenn true, gibt es nur die Single Zustaende zurueck, wenn false
321         dann alle?
322     */

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 JavaDoc (status.status_id),status);
332         }
333         return list;
334     }
335     
336     /**
337         gibt alle Stati zurueck, die nicht zu einer neuen Version führen
338     */

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 JavaDoc( status.status_id ));
350                 attributes.put("STATUS_SHORT_ORIGINAL", new String JavaDoc(status.originalShortName));
351                 attributes.put("STATUS", new String JavaDoc(status.getName()));
352                 if (status.confirm)
353                     attributes.put("CONFIRM", new String JavaDoc("TRUE"));
354                 list.add (attributes);
355             }
356         }
357         return list;
358     }
359
360     /**
361         filtert alle Stati aus der Hashtable, die nur ein Kommentar sind
362     */

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 JavaDoc (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     /**
399         gibt den ersten Status zurueck, der fuer neuen Content gilt
400     */

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     /**
413         gibt alle Stati zurück,
414         die generierbar sind
415     */

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 JavaDoc (status.status_id),status);
424         }
425         return table;
426     }
427
428     /**
429         gibt einen SQL String zum Einfügen dieses Versionstatus zurück
430     */

431     public String JavaDoc 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