1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.quicklinks.dao.impl; |
18 | |
|
19 | |
import java.sql.Connection; |
20 | |
import java.sql.PreparedStatement; |
21 | |
import java.sql.ResultSet; |
22 | |
import java.sql.SQLException; |
23 | |
import java.util.ArrayList; |
24 | |
import java.util.Collections; |
25 | |
import java.util.List; |
26 | |
import java.util.StringTokenizer; |
27 | |
|
28 | |
import org.apache.ojb.broker.PersistenceBroker; |
29 | |
import org.kuali.rice.kew.docsearch.service.DocumentSearchService; |
30 | |
import org.kuali.rice.kew.doctype.DocumentTypePolicy; |
31 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
32 | |
import org.kuali.rice.kew.doctype.service.DocumentTypeService; |
33 | |
import org.kuali.rice.kew.exception.WorkflowRuntimeException; |
34 | |
import org.kuali.rice.kew.quicklinks.ActionListStats; |
35 | |
import org.kuali.rice.kew.quicklinks.InitiatedDocumentType; |
36 | |
import org.kuali.rice.kew.quicklinks.WatchedDocument; |
37 | |
import org.kuali.rice.kew.quicklinks.dao.QuickLinksDAO; |
38 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
39 | |
import org.kuali.rice.kew.util.KEWConstants; |
40 | |
import org.kuali.rice.kew.util.Utilities; |
41 | |
import org.kuali.rice.kew.web.KeyValue; |
42 | |
import org.kuali.rice.kns.util.KNSConstants; |
43 | |
import org.springmodules.orm.ojb.PersistenceBrokerCallback; |
44 | |
import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport; |
45 | |
|
46 | |
|
47 | 0 | public class QuickLinksDAOOjbImpl extends PersistenceBrokerDaoSupport implements QuickLinksDAO { |
48 | |
|
49 | |
public List<ActionListStats> getActionListStats(final String principalId) { |
50 | 0 | return (List<ActionListStats>) this.getPersistenceBrokerTemplate().execute(new PersistenceBrokerCallback() { |
51 | |
public Object doInPersistenceBroker(PersistenceBroker broker) { |
52 | 0 | PreparedStatement selectActionItems = null; |
53 | 0 | PreparedStatement selectDocTypeLabel = null; |
54 | 0 | ResultSet selectedActionItems = null; |
55 | 0 | ResultSet selectedDocTypeLabel = null; |
56 | 0 | List<ActionListStats> docTypes = new ArrayList<ActionListStats>(); |
57 | |
try { |
58 | 0 | Connection connection = broker.serviceConnectionManager().getConnection(); |
59 | 0 | selectActionItems = connection.prepareStatement("select DOC_TYP_NM, COUNT(*) from KREW_ACTN_ITM_T where PRNCPL_ID = ? " + |
60 | |
"and (dlgn_typ is null or dlgn_typ != '" + KEWConstants.DELEGATION_SECONDARY + "') group by DOC_TYP_NM"); |
61 | 0 | selectDocTypeLabel = connection.prepareStatement("select LBL from KREW_DOC_TYP_T WHERE DOC_TYP_NM = ? and CUR_IND = 1"); |
62 | 0 | selectActionItems.setString(1, principalId); |
63 | 0 | selectedActionItems = selectActionItems.executeQuery(); |
64 | 0 | while (selectedActionItems.next()) { |
65 | 0 | String docTypeName = selectedActionItems.getString(1); |
66 | 0 | int count = selectedActionItems.getInt(2); |
67 | 0 | selectDocTypeLabel.setString(1, docTypeName); |
68 | 0 | selectedDocTypeLabel = selectDocTypeLabel.executeQuery(); |
69 | 0 | if (selectedDocTypeLabel.next()) { |
70 | 0 | docTypes.add(new ActionListStats(docTypeName, selectedDocTypeLabel.getString(1), count)); |
71 | |
} |
72 | 0 | } |
73 | 0 | Collections.sort(docTypes); |
74 | 0 | return docTypes; |
75 | 0 | } catch (Exception e) { |
76 | 0 | throw new WorkflowRuntimeException("Error getting action list stats for user: " + principalId, e); |
77 | |
} finally { |
78 | 0 | if (selectActionItems != null) { |
79 | |
try { |
80 | 0 | selectActionItems.close(); |
81 | 0 | } catch (SQLException e) { |
82 | 0 | } |
83 | |
} |
84 | |
|
85 | 0 | if (selectDocTypeLabel != null) { |
86 | |
try { |
87 | 0 | selectDocTypeLabel.close(); |
88 | 0 | } catch (SQLException e) { |
89 | 0 | } |
90 | |
} |
91 | |
|
92 | 0 | if (selectedActionItems != null) { |
93 | |
try { |
94 | 0 | selectedActionItems.close(); |
95 | 0 | } catch (SQLException e) { |
96 | 0 | } |
97 | |
} |
98 | |
|
99 | 0 | if (selectedDocTypeLabel != null) { |
100 | |
try { |
101 | 0 | selectedDocTypeLabel.close(); |
102 | 0 | } catch (SQLException e) { |
103 | 0 | } |
104 | |
} |
105 | |
|
106 | |
} |
107 | |
} |
108 | |
}); |
109 | |
} |
110 | |
|
111 | |
public List<InitiatedDocumentType> getInitiatedDocumentTypesList(final String principalId) { |
112 | 0 | return (List<InitiatedDocumentType>) this.getPersistenceBrokerTemplate().execute(new PersistenceBrokerCallback() { |
113 | |
|
114 | |
public Object doInPersistenceBroker(PersistenceBroker broker) { |
115 | 0 | PreparedStatement selectDistinctDocumentTypes = null; |
116 | 0 | ResultSet selectedDistinctDocumentTypes = null; |
117 | 0 | List<InitiatedDocumentType> documentTypesByName = new ArrayList<InitiatedDocumentType>(); |
118 | |
try { |
119 | 0 | Connection connection = broker.serviceConnectionManager().getConnection(); |
120 | |
|
121 | 0 | String sql = "select distinct B.DOC_TYP_NM, B.LBL from KREW_DOC_HDR_T A, KREW_DOC_TYP_T B "+ |
122 | |
"where A.INITR_PRNCPL_ID = ? and A.DOC_TYP_ID = B.DOC_TYP_ID and " + |
123 | |
"B.ACTV_IND = 1 and B.CUR_IND = 1 " + |
124 | |
"order by upper(B.LBL)"; |
125 | |
|
126 | 0 | selectDistinctDocumentTypes = connection.prepareStatement(sql); |
127 | 0 | selectDistinctDocumentTypes.setString(1, principalId); |
128 | 0 | selectedDistinctDocumentTypes = selectDistinctDocumentTypes.executeQuery(); |
129 | |
|
130 | 0 | String documentNames = Utilities.getKNSParameterValue(KEWConstants.KEW_NAMESPACE, KNSConstants.DetailTypes.QUICK_LINK_DETAIL_TYPE, KEWConstants.QUICK_LINKS_RESTRICT_DOCUMENT_TYPES); |
131 | 0 | if (documentNames != null) { |
132 | |
|
133 | 0 | documentNames = documentNames.trim(); |
134 | |
} |
135 | 0 | if (documentNames == null || "none".equals(documentNames)) { |
136 | 0 | documentNames = ""; |
137 | |
} |
138 | |
|
139 | 0 | List docTypesToRestrict = new ArrayList(); |
140 | 0 | StringTokenizer st = new StringTokenizer(documentNames, ","); |
141 | 0 | while (st.hasMoreTokens()) { |
142 | 0 | docTypesToRestrict.add(st.nextToken()); |
143 | |
} |
144 | 0 | while (selectedDistinctDocumentTypes.next()) { |
145 | 0 | String docTypeName = selectedDistinctDocumentTypes.getString(1); |
146 | 0 | String docTypeTopParent = ""; |
147 | 0 | int firstPeriod = docTypeName.indexOf("."); |
148 | 0 | if (firstPeriod == -1) { |
149 | 0 | docTypeTopParent = docTypeName.substring(0); |
150 | |
} else { |
151 | 0 | docTypeTopParent = docTypeName.substring(0, firstPeriod); |
152 | |
} |
153 | 0 | if (!docTypesToRestrict.contains(docTypeTopParent)) { |
154 | |
|
155 | 0 | DocumentType docType = KEWServiceLocator.getDocumentTypeService().findByName(docTypeName); |
156 | 0 | DocumentTypePolicy quickInitiatePolicy = docType.getSupportsQuickInitiatePolicy(); |
157 | 0 | if (quickInitiatePolicy.getPolicyValue().booleanValue()) { |
158 | 0 | documentTypesByName.add(new InitiatedDocumentType(docTypeName, selectedDistinctDocumentTypes.getString(2))); |
159 | |
} |
160 | |
} |
161 | 0 | } |
162 | 0 | return documentTypesByName; |
163 | 0 | } catch (Exception e) { |
164 | 0 | throw new WorkflowRuntimeException("Error getting initiated document types for user: " + principalId, e); |
165 | |
} finally { |
166 | 0 | if (selectDistinctDocumentTypes != null) { |
167 | |
try { |
168 | 0 | selectDistinctDocumentTypes.close(); |
169 | 0 | } catch (SQLException e) { |
170 | 0 | } |
171 | |
} |
172 | 0 | if (selectedDistinctDocumentTypes != null) { |
173 | |
try { |
174 | 0 | selectedDistinctDocumentTypes.close(); |
175 | 0 | } catch (SQLException e) { |
176 | 0 | } |
177 | |
} |
178 | |
|
179 | |
} |
180 | |
|
181 | |
} |
182 | |
}); |
183 | |
} |
184 | |
|
185 | |
public List<KeyValue> getNamedSearches(String principalId) { |
186 | 0 | return getDocumentSearchService().getNamedSearches(principalId); |
187 | |
} |
188 | |
|
189 | |
public List<KeyValue> getRecentSearches(String principalId) { |
190 | 0 | return getDocumentSearchService().getMostRecentSearches(principalId); |
191 | |
} |
192 | |
|
193 | |
public List<WatchedDocument> getWatchedDocuments(final String principalId) { |
194 | 0 | return (List<WatchedDocument>) this.getPersistenceBrokerTemplate().execute(new PersistenceBrokerCallback() { |
195 | |
public Object doInPersistenceBroker(PersistenceBroker broker) { |
196 | 0 | List<WatchedDocument> watchedDocuments = new ArrayList<WatchedDocument>(); |
197 | 0 | PreparedStatement selectWatchedDocuments = null; |
198 | 0 | ResultSet selectedWatchedDocuments = null; |
199 | |
try { |
200 | 0 | Connection connection = broker.serviceConnectionManager().getConnection(); |
201 | 0 | selectWatchedDocuments = connection.prepareStatement("select DOC_HDR_ID, DOC_HDR_STAT_CD, TTL, CRTE_DT from KREW_DOC_HDR_T where INITR_PRNCPL_ID = ? and DOC_HDR_STAT_CD in ('"+ KEWConstants.ROUTE_HEADER_ENROUTE_CD +"','"+ KEWConstants.ROUTE_HEADER_EXCEPTION_CD +"') order by CRTE_DT desc"); |
202 | 0 | selectWatchedDocuments.setString(1, principalId); |
203 | 0 | selectedWatchedDocuments = selectWatchedDocuments.executeQuery(); |
204 | 0 | while (selectedWatchedDocuments.next()) { |
205 | 0 | watchedDocuments.add(new WatchedDocument(selectedWatchedDocuments.getString(1), (String)KEWConstants.DOCUMENT_STATUSES.get(selectedWatchedDocuments.getString(2)), selectedWatchedDocuments.getString(3))); |
206 | |
} |
207 | 0 | return watchedDocuments; |
208 | 0 | } catch (Exception e) { |
209 | 0 | throw new WorkflowRuntimeException("Error getting initiated document types for user: " + principalId, e); |
210 | |
} finally { |
211 | 0 | if (selectWatchedDocuments != null) { |
212 | |
try { |
213 | 0 | selectWatchedDocuments.close(); |
214 | 0 | } catch (SQLException e) { |
215 | 0 | } |
216 | |
} |
217 | 0 | if (selectedWatchedDocuments != null) { |
218 | |
try { |
219 | 0 | selectedWatchedDocuments.close(); |
220 | 0 | } catch (SQLException e) { |
221 | 0 | } |
222 | |
} |
223 | |
|
224 | |
} |
225 | |
} |
226 | |
}); |
227 | |
} |
228 | |
|
229 | |
public DocumentTypeService getDocumentTypeService() { |
230 | 0 | return ((DocumentTypeService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)); |
231 | |
} |
232 | |
|
233 | |
public DocumentSearchService getDocumentSearchService() { |
234 | 0 | return ((DocumentSearchService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE)); |
235 | |
} |
236 | |
|
237 | |
} |