001: package de.webman.content.workflow;
002:
003: import com.teamkonzept.lib.*;
004: import com.teamkonzept.db.*;
005: import de.webman.content.workflow.db.queries.*;
006: import com.teamkonzept.international.LanguageManager;
007:
008: import java.util.*;
009: import java.sql.*;
010:
011: import org.apache.log4j.Category;
012:
013: /**
014: repraesentiert einen Status
015: * @author $Author: sebastian $
016: * @version $Revision: 1.5 $
017: */
018: public class VersionStatus implements TKHashable {
019: /** Logging Category */
020: private static Category cat = Category
021: .getInstance(VersionStatus.class);
022:
023: /** Default Vorbelegung fuer neue Contents - macht das Sinn ? */
024: public static int defaultNewStatus = 1;
025:
026: /** Id des Status */
027: public int status_id = -1;
028:
029: /** name des Status -> ist jetzt nur Platzhalter fuer den intern. Namen*/
030: private String name;
031:
032: /** die in der DB gespeicherten Attribute */
033: public String attributes;
034:
035: /** ganz Kurzbeschreibung z.B. b fuer bearbeiten - kann raus !*/
036: private String id;
037:
038: /** etwas laengerer Name, wie z.B. bea fuer bearbeiten -> ist jetzt nur Platzhalter fuer den intern. Namen*/
039: private String shortName;
040:
041: /** fuer die Buttons */
042: private String originalShortName;
043:
044: /** ist der im Standardfilter drin ?*/
045: public String filter;
046:
047: /** Der Event, mit dem dieser Status verbunden ist kann auch bald raus*/
048: public String event;
049:
050: /** Ist dieser Status fuer SingleContents ? */
051: public boolean single;
052:
053: /** soll eine Transition in diesen Zustand bestaetigt werden ? */
054: public boolean confirm;
055:
056: /** wird der Content beim Schalten in diesen Content physikalisch geloescht ?*/
057: public boolean delete;
058:
059: public boolean rename;
060:
061: /** Ist dieser Status fuer neuen Content ? oder erzeugt er neuen Content ?*/
062: public boolean newContent;
063: public boolean newVersion;
064:
065: /** Ist dieser Status fuer die Generierung ? */
066: public boolean generate;
067:
068: /** ist dieser Status nur ein Kommentar, dann wird er beinahe immer ausgefiltert */
069: public boolean comment;
070:
071: /** Hashable Darstellung der Attribute */
072: public TKHashtable hashed;
073:
074: public VersionStatus() {
075: init(-1, null, null);
076: }
077:
078: public VersionStatus(int status_id, String status, String attributes) {
079: init(status_id, status, attributes);
080: }
081:
082: /**
083: Konstruktor, mit Datenbankinfos
084: */
085: public VersionStatus(ResultSet rs) {
086:
087: try {
088: init(rs);
089: } catch (Exception ex) {
090: init(-1, null, null);
091: }
092: }
093:
094: private void init(ResultSet rs) throws SQLException {
095: status_id = rs.getInt("STATUS_ID");
096: name = rs.getString("STATUS");
097: attributes = rs.getString("STATUS_ATTRIBUTES");
098: scanAttributes();
099: }
100:
101: /**
102: fuehrt alle zur Initialisierung noetigen Aktionen aus
103: */
104: public void init(int status_id, String status, String attributes) {
105: this .status_id = status_id;
106: name = status;
107: this .attributes = attributes;
108: scanAttributes();
109: makeHashed();
110: }
111:
112: public String getName() {
113: return LanguageManager.getText("workflow", name, null);
114: // return name;
115: }
116:
117: public String getShortName() {
118: return LanguageManager.getText("workflow", shortName, null);
119: }
120:
121: /**
122: stellt die Attribute neu zusammen, aus einer Hashtabelle in die Instanzdaten
123: */
124: public void getFromEvent(TKHashtable params) {
125: name = (String) params.get("STATUS");
126: single = params.get("STATUS_SINGLE") != null;
127: confirm = params.get("CONFIRM") != null;
128: rename = params.get("RENAME") != null;
129: newContent = params.get("NEW_CONTENT") != null;
130: newVersion = params.get("NEW_VERSION") != null;
131: generate = params.get("GENERATE") != null;
132: comment = params.get("COMMENT") != null;
133: delete = params.get("DELETE") != null;
134: // die Attribute wieder uptodate machen
135: assembleAttributes();
136: hashed = null;
137: cat.debug("Aktuelle Attribute : " + attributes);
138: }
139:
140: /**
141: speichert den aktuellen Status in die Datenbank
142: */
143: public void saveToDB() {
144: try {
145: TKQuery query = null;
146: // Id da ?
147: if (status_id != -1) {
148: query = TKDBManager.newQuery(UpdateStatus.class);
149: query.setQueryParams("STATUS_ID",
150: new Integer(status_id));
151: } else {
152: query = TKDBManager.newQuery(InsertStatus.class);
153: }
154: query.setQueryParams("STATUS", name);
155: query.setQueryParams("STATUS_ATTRIBUTES", attributes);
156: query.execute();
157: if (status_id == -1) {
158: ResultSet rs = query.fetchResultSet();
159: if (rs.next())
160: init(rs);
161: }
162: } catch (SQLException e) {
163: cat.error("Error during save ", e);
164: }
165: }
166:
167: /**
168: Neuzusammenstellung der Attribute in die Instanzvariable
169: attributes (Datenbanknotation)
170: */
171: public void assembleAttributes() {
172: attributes = (id == null ? "" : "id:" + id + ";")
173: + (shortName == null ? "" : "shortName:" + shortName
174: + ";")
175: + (filter == null ? "" : "filter:" + filter + ";")
176: + (event == null ? "" : "event:" + event + ";")
177: + (single ? "" : "single:off;")
178: + (confirm ? "confirm;" : "")
179: + (rename ? "rename;" : "")
180: + (newContent ? "new;" : "")
181: + (newVersion ? "newVersion;" : "")
182: + (generate ? "generate;" : "")
183: + (comment ? "comment;" : "")
184: + (delete ? "delete:true" : "");
185: }
186:
187: /**
188: scant die Attribute eines Status, sind in der DB im Feld Version_Status.Status_Attributes
189: */
190: public void scanAttributes() {
191: id = null;
192: shortName = null;
193: filter = null;
194: event = null;
195: single = true;
196: confirm = false;
197: rename = false;
198: newContent = false;
199: newVersion = false;
200: generate = false;
201: comment = false;
202:
203: if (attributes == null)
204: return;
205:
206: StringTokenizer tokenizer = new StringTokenizer(attributes, ";");
207: while (tokenizer.hasMoreTokens()) {
208:
209: String attr = tokenizer.nextToken();
210: if (attr == null)
211: continue;
212:
213: StringTokenizer sub = new StringTokenizer(attr, ":");
214: String attrName = sub.hasMoreTokens() ? sub.nextToken()
215: : null;
216:
217: if (attrName == null)
218: continue;
219: String attrValue = sub.hasMoreTokens() ? sub.nextToken()
220: : null;
221:
222: if (attrName.equalsIgnoreCase("id") && attrValue != null)
223: this .id = attrValue;
224: else if (attrName.equalsIgnoreCase("short")
225: && attrValue != null) {
226: this .shortName = LanguageManager.getText("workflow",
227: attrValue);
228: originalShortName = attrValue;
229: } else if (attrName.equalsIgnoreCase("filter")
230: && attrValue != null)
231: this .filter = attrValue.toUpperCase();
232: else if (attrName.equalsIgnoreCase("event")
233: && attrValue != null)
234: this .event = attrValue.toUpperCase();
235: else if (attrName.equalsIgnoreCase("single")
236: && attrValue != null)
237: this .single = attrValue.equalsIgnoreCase("on");
238: else if (attrName.equalsIgnoreCase("confirm"))
239: this .confirm = true;
240: else if (attrName.equalsIgnoreCase("rename"))
241: this .rename = true;
242: else if (attrName.equalsIgnoreCase("new"))
243: this .newContent = true;
244: else if (attrName.equalsIgnoreCase("newversion"))
245: this .newVersion = true;
246: else if (attrName.equalsIgnoreCase("generate"))
247: this .generate = true;
248: else if (attrName.equalsIgnoreCase("comment"))
249: this .comment = true;
250: else if (attrName.equalsIgnoreCase("delete"))
251: delete = true;
252: originalShortName = name + "_short";
253: shortName = name + "shortbogus";
254: }
255: }
256:
257: /**
258: packed die Attribute in eine Hashtabelle
259: Implementierung von TKHashable
260: */
261: public void makeHashed() {
262: hashed = new TKHashtable();
263: hashed.put("STATUS_ID", new Integer(status_id));
264:
265: if (name != null)
266: hashed.put("STATUS", name);
267: if (attributes != null)
268: hashed.put("STATUS_ATTRIBUTES", attributes);
269: if (id != null)
270: hashed.put("STATUS_SHORT_ID", id);
271: if (shortName != null) {
272: hashed.put("STATUS_SHORT", shortName);
273: hashed.put("STATUS_SHORT_ORIGINAL", originalShortName);
274:
275: }
276:
277: if (filter != null)
278: hashed.put("STATUS_FILTER", filter);
279: if (event != null)
280: hashed.put("STATUS_EVENT", event);
281: if (single)
282: hashed.put("STATUS_SINGLE", Boolean.TRUE);
283: if (confirm)
284: hashed.put("CONFIRM", Boolean.TRUE);
285: if (rename)
286: hashed.put("RENAME", Boolean.TRUE);
287: if (newContent)
288: hashed.put("NEW_CONTENT", Boolean.TRUE);
289: if (newVersion)
290: hashed.put("NEW_VERSION", Boolean.TRUE);
291: if (generate)
292: hashed.put("GENERATE", Boolean.TRUE);
293: if (comment)
294: hashed.put("COMMENT", Boolean.TRUE);
295: if (delete)
296: hashed.put("DELETE", Boolean.TRUE);
297: }
298:
299: /**
300: Imlementierung des Interfaces TKHashable
301: */
302: public TKHashtable toHashtable() {
303: if (hashed == null)
304: makeHashed();
305: return hashed;
306: }
307:
308: /**
309: laedt alle Informationen aus der Datenbank
310: */
311: public static TKHashtable load() throws Exception {
312: TKHashtable statusPool = new TKHashtable();
313: TKQuery query = TKDBManager.newQuery(VersionStatusGetAll.class);
314: query.execute();
315: ResultSet rs = query.fetchResultSet();
316:
317: while (rs.next()) {
318: VersionStatus desc = new VersionStatus(rs);
319: statusPool.put(new Integer(desc.status_id), desc);
320: }
321: return statusPool;
322: }
323:
324: /**
325: gibt alle Stati zurueck, die fuer Single Nodes interessant sind
326: @param single wenn true, gibt es nur die Single Zustaende zurueck, wenn false
327: dann alle?
328: */
329: public static TKHashtable selectSingles(VersionStatics statics,
330: boolean single) {
331: TKHashtable list = new TKHashtable();
332: Enumeration e = statics.getStatusPool().elements();
333: while (e.hasMoreElements()) {
334: VersionStatus status = (VersionStatus) e.nextElement();
335: if (!single || status.single)
336: list.put(new Integer(status.status_id), status);
337: }
338: return list;
339: }
340:
341: /**
342: gibt alle Stati zurueck, die nicht zu einer neuen Version führen
343: */
344: public static TKVector selectNotNewVersion(VersionStatics statics) {
345: TKVector list = new TKVector();
346: Enumeration e = statics.getStatusPool().elements();
347: while (e.hasMoreElements()) {
348: VersionStatus status = (VersionStatus) e.nextElement();
349: if (!(status.newVersion || status.comment)) {
350: TKHashtable attributes = new TKHashtable();
351: attributes.put("STATUS_ID", new Integer(
352: status.status_id));
353: attributes.put("STATUS_SHORT_ORIGINAL", new String(
354: status.originalShortName));
355: attributes.put("STATUS", new String(status.getName()));
356: if (status.confirm)
357: attributes.put("CONFIRM", new String("TRUE"));
358: list.add(attributes);
359: }
360: }
361: return list;
362: }
363:
364: /**
365: filtert alle Stati aus der Hashtable, die nur ein Kommentar sind
366: */
367: public static TKHashtable filterComments(VersionStatics statics) {
368: TKHashtable list = new TKHashtable();
369: Enumeration e = statics.getStatusPool().elements();
370: while (e.hasMoreElements()) {
371: VersionStatus status = (VersionStatus) e.nextElement();
372: if (!status.comment)
373: list.put(new Integer(status.status_id), status);
374: }
375: return list;
376: }
377:
378: public static VersionStatus lookupRename(VersionStatics statics) {
379: Enumeration e = statics.getStatusPool().elements();
380: while (e.hasMoreElements()) {
381: VersionStatus status = (VersionStatus) e.nextElement();
382: if (status.rename)
383: return status;
384: }
385: return null;
386: }
387:
388: public static VersionStatus lookupComment(VersionStatics statics) {
389: Enumeration e = statics.getStatusPool().elements();
390: while (e.hasMoreElements()) {
391: VersionStatus status = (VersionStatus) e.nextElement();
392: if (status.comment)
393: 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: Enumeration e = statics.getStatusPool().elements();
403: while (e.hasMoreElements()) {
404: VersionStatus status = (VersionStatus) e.nextElement();
405: if (status.newContent)
406: return status;
407: }
408: return null;
409: }
410:
411: /**
412: gibt alle Stati zurück,
413: die generierbar sind
414: */
415: public static TKHashtable getGeneratables(VersionStatics statics) {
416: TKHashtable table = new TKHashtable();
417: Enumeration e = statics.getStatusPool().elements();
418: while (e.hasMoreElements()) {
419: VersionStatus status = (VersionStatus) e.nextElement();
420: if (status.generate)
421: table.put(new Integer(status.status_id), status);
422: }
423: return table;
424: }
425:
426: /**
427: gibt einen SQL String zum Einfügen dieses Versionstatus zurück
428: */
429: public String toInsertSql() {
430: assembleAttributes();
431: return "INSERT INTO VERSION_STATUS (STATUS_ID, STATUS, STATUS_ATTRIBUTES) "
432: + "VALUES ("
433: + status_id
434: + ",\""
435: + name
436: + "\""
437: + ",\""
438: + attributes + "\") ";
439: }
440:
441: }
|