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