001: package de.webman.content.workflow;
002:
003: import com.teamkonzept.lib.*;
004: import com.teamkonzept.db.*;
005:
006: import com.teamkonzept.web.*;
007: import com.teamkonzept.field.*;
008: import com.teamkonzept.webman.mainint.DatabaseDefaults;
009: import de.webman.content.eventhandler.ContentContext;
010: import de.webman.content.workflow.db.queries.*;
011: import de.webman.content.db.queries.GetContentNodeFromContentInstance;
012: import java.util.*;
013: import java.sql.*;
014: import com.teamkonzept.webman.mainint.db.queries.*;
015: import de.webman.content.*;
016: import com.teamkonzept.webman.mainint.db.SearchListIterator;
017:
018: import org.apache.log4j.Category;
019:
020: /**
021: Cached die WorkflowDaten
022: Key ist die InstanceID eines Contents
023: * @author $Author: sebastian $
024: * @version $Revision: 1.27 $
025: */
026: public class VersionCache implements DatabaseDefaults, VersionConstants {
027: /** Logging Category */
028: private static Category cat = Category
029: .getInstance(VersionCache.class);
030:
031: /**
032: Invalidieren des Caches
033: */
034: public static void invalidInstance(Integer instanceID) {
035: // not implemented yet
036: instanceID = instanceID;
037: }
038:
039: public static TKVector getVersionInfo(Integer nodeId,
040: boolean subtree) throws SQLException {
041: return getVersionInfo(nodeId, subtree, false, null);
042: }
043:
044: public static TKVector getVersionInfo(Integer nodeId,
045: boolean subtree, boolean kennung, String searchString)
046: throws SQLException {
047: TKQuery q;
048:
049: if (subtree)
050: q = (TKUnprepQuery) TKDBManager
051: .newQuery(TKDBGetAllTreeContentVersions.class);
052: else
053: q = (TKUnprepQuery) TKDBManager
054: .newQuery(TKDBGetAllNodeContentVersions.class);
055:
056: if ((searchString != null) && (searchString.length() != 0)) {
057: if (kennung)
058: q.setQueryParams("KENNUNG", new Integer(1));
059: else
060: q.setQueryParams("KENNUNG", new Integer(0));
061: ((TKUnprepQuery) q).setListIterator(new SearchListIterator(
062: searchString, "SEARCH_STRING", (TKUnprepQuery) q));
063: }
064: q.setQueryParams("CONTENT_NODE_ID", nodeId);
065:
066: return doReadInstances(q);
067: }
068:
069: /**
070: Liefert zum angegebenen Context die Versionsdaten aller Instanzen
071:
072: @param WMContentContext
073: @param subtree ist der ganze Unterbaum mit ausgewählt
074: @param context
075:
076: */
077: public static TKVector getVersionInfo(ContentContext context,
078: boolean subtree) throws SQLException {
079: boolean isGroup = context.conNodeType.intValue() == GROUP_INTEGER
080: .intValue();
081: return getVersionInfo(isGroup ? context.groupConNodeId
082: : context.conNodeId, subtree);
083: }
084:
085: /**
086: Liefert zum angegebenen Context die Versionsdaten aller Instanzen
087:
088: @param WMContentContext
089: @param subtree
090: @kennung nach Kennung suchen (für Suche)
091: @searchString für Suche
092: */
093: public static TKVector getVersionInfo(ContentContext context,
094: boolean subtree, boolean kennung, String searchString)
095: throws SQLException {
096: boolean isGroup = context.conNodeType.intValue() == GROUP_INTEGER
097: .intValue();
098: return getVersionInfo(isGroup ? context.groupConNodeId
099: : context.conNodeId, subtree, kennung, searchString);
100: }
101:
102: /*
103: liefert Content mit durchgefuehrtem Workflow fuer eine Instanz ID zurueck
104: */
105: public static Content getInstanceInfo(Integer instanceId) {
106: try {
107: TKQuery q = TKDBManager
108: .newQuery(GetContentNodeFromContentInstance.class);
109: q.setQueryParams("INSTANCE_ID", instanceId);
110: q.execute();
111: ResultSet rs = q.fetchResultSet();
112: rs.next();
113: Integer contentNodeId = new Integer(rs
114: .getInt("CONTENT_NODE_ID"));
115: return getContentInfo(contentNodeId);
116: } catch (SQLException e) {
117: cat.error("Could not get content for instance : "
118: + instanceId, e);
119: }
120: return null;
121: }
122:
123: /*
124: liefert Content mit durchgefuehrtem Workflow fuer eine Content Node ID zurueck
125: */
126: public static Content getContentInfo(Integer contentNodeId) {
127: try {
128:
129: TKVector result = getVersionInfo(contentNodeId, false);
130: if (result.size() > 0)
131: return (Content) result.elementAt(0);
132: } catch (SQLException e) {
133: cat.error("Could not get content : " + contentNodeId, e);
134: }
135: return null;
136: }
137:
138: /**
139: * Returns all instances readable by the given query.
140: *
141: * @param query the query to be executed.
142: * @return all instances readable by the given query.
143: * @throws SQLException if an error occurred while executing
144: * the query.
145: */
146: public static TKVector doReadInstances (TKQuery query)
147: throws SQLException
148: {
149: query.execute();
150: ResultSet rs = query.fetchResultSet();
151: // ordnet einer instanceId die Instanzdaten zu
152: TKHashtable instances = new TKHashtable();
153:
154: // das ResultSet einlesen
155: instances = readResultSet(rs);
156: TKVector allInstances = new TKVector();
157: Enumeration enum = instances.elements();
158: while (enum.hasMoreElements())
159: {
160: Content c = (Content)enum.nextElement();
161: WorkflowEngine.getInterestingVersionsPerInstance(c);
162: allInstances.addElement(c);
163: }
164:
165: return allInstances;
166:
167: }
168:
169: /**
170: * Processes the given result set.
171: *
172: * @param rs the result set.
173: * @return a hashtable containing the processed result set.
174: * @throws SQLException if an error occurred while reading
175: * the result set.
176: */
177: public static TKHashtable readResultSet(ResultSet rs)
178: throws SQLException {
179: // statische Daten der Versionsverwaltung abrufen
180: VersionStatics statics = VersionStatics.setup();
181: TKHashtable allInstances = new TKHashtable();
182: boolean hasRefNode = false;
183: try {
184: int index = rs.findColumn("REF_NODE_ID");
185: hasRefNode = (index > 0);
186: } catch (SQLException e) {
187: cat.debug("No GeneratorQuery");
188: }
189: while (rs.next()) {
190: // Versionsinformation auslesen
191: int versionId = rs.getInt("VERSION_ID");
192: // System.out.println(versionId);
193: Integer instanceId = new Integer(rs.getInt("INSTANCE_ID"));
194: Integer contentNodeId = new Integer(rs
195: .getInt("CONTENT_NODE_ID"));
196: // int contentNodeType = rs.getInt ("CONTENT_NODE_TYPE");
197: int parentType = rs.getInt("PARENT_TYPE");
198:
199: // abhaengig vom parenttype den Type des Content bestimmen (inGroup/single)
200: Integer contentId = new Integer(rs.getInt("CONTENT_ID"));
201: int statusId = rs.getInt("STATUS_ID");
202: Integer formId = new Integer(rs.getInt("CONTENT_FORM"));
203: VersionStatus statusDesc = (VersionStatus) statics
204: .getStatusPool().get(new Integer(statusId));
205: if (statusDesc.comment)
206: continue;
207:
208: // fuer die Generator Query
209: Integer refId = null;
210: if (hasRefNode) {
211: refId = new Integer(rs.getInt("REF_NODE_ID"));
212: }
213: java.util.Date date = rs.getTimestamp("VERSION_DATE");
214: // System.out.println("Datum : " + date);
215: String author = rs.getString("AUTHOR");
216: Integer parentId = new Integer(rs
217: .getInt("CONTENT_NODE_PARENT"));
218: String contentNodename = rs.getString("CONTENT_NODE_NAME");
219: String contentNodeShortName = rs
220: .getString("CONTENT_NODE_SHORTNAME");
221:
222: // String status = rs.getString ("STATUS");
223: ContentVersion version = new ContentVersion(new Integer(
224: versionId), contentId, contentNodeId, author, date,
225: statusDesc, parentType == DIRECTORY_NODE_INTEGER
226: .intValue());
227: Content content = (Content) allInstances.get(contentNodeId);
228: if (content == null) {
229: content = new Content(
230: contentNodeId,
231: contentNodename,
232: contentNodeShortName,
233: instanceId,
234: formId,
235: parentType == DIRECTORY_NODE_INTEGER.intValue(),
236: parentId);
237: if (refId != null) {
238: content.setRefNodeId(refId);
239: }
240: allInstances.put(contentNodeId, content);
241: }
242: // hier noch auf die Sortierung achten !!!
243: content.addVersion(version);
244: }
245: return allInstances;
246: }
247:
248: }
|