Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ActionListDAOOjbImpl |
|
| 7.0588235294117645;7.059 | ||||
ActionListDAOOjbImpl$1 |
|
| 7.0588235294117645;7.059 |
1 | /* | |
2 | * Copyright 2005-2007 The Kuali Foundation | |
3 | * | |
4 | * | |
5 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
6 | * you may not use this file except in compliance with the License. | |
7 | * You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.opensource.org/licenses/ecl2.php | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | package org.kuali.rice.kew.actionlist.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.sql.Timestamp; | |
24 | import java.util.Calendar; | |
25 | import java.util.Collection; | |
26 | import java.util.Date; | |
27 | import java.util.HashMap; | |
28 | import java.util.Iterator; | |
29 | import java.util.List; | |
30 | import java.util.Map; | |
31 | ||
32 | import org.apache.commons.lang.StringUtils; | |
33 | import org.apache.ojb.broker.PersistenceBroker; | |
34 | import org.apache.ojb.broker.accesslayer.LookupException; | |
35 | import org.apache.ojb.broker.query.Criteria; | |
36 | import org.apache.ojb.broker.query.QueryByCriteria; | |
37 | import org.kuali.rice.kew.actionitem.ActionItem; | |
38 | import org.kuali.rice.kew.actionitem.ActionItemActionListExtension; | |
39 | import org.kuali.rice.kew.actionitem.OutboxItemActionListExtension; | |
40 | import org.kuali.rice.kew.actionlist.ActionListFilter; | |
41 | import org.kuali.rice.kew.actionlist.dao.ActionListDAO; | |
42 | import org.kuali.rice.kew.doctype.bo.DocumentType; | |
43 | import org.kuali.rice.kew.exception.WorkflowRuntimeException; | |
44 | import org.kuali.rice.kew.service.KEWServiceLocator; | |
45 | import org.kuali.rice.kew.util.KEWConstants; | |
46 | import org.kuali.rice.kim.api.services.KimApiServiceLocator; | |
47 | import org.springmodules.orm.ojb.PersistenceBrokerCallback; | |
48 | import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport; | |
49 | ||
50 | /** | |
51 | * OJB implementation of the {@link ActionListDAO}. | |
52 | * | |
53 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
54 | */ | |
55 | 0 | public class ActionListDAOOjbImpl extends PersistenceBrokerDaoSupport implements ActionListDAO { |
56 | ||
57 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ActionListDAOOjbImpl.class); |
58 | ||
59 | public Collection<ActionItem> getActionList(String principalId, ActionListFilter filter) { | |
60 | 0 | return getActionItemsInActionList(ActionItemActionListExtension.class, principalId, filter); |
61 | // LOG.debug("getting action list for user " + workflowUser.getWorkflowUserId().getWorkflowId()); | |
62 | // Criteria crit = null; | |
63 | // if (filter == null) { | |
64 | // crit = new Criteria(); | |
65 | // crit.addEqualTo("workflowId", workflowUser.getWorkflowUserId().getWorkflowId()); | |
66 | // } else { | |
67 | // crit = setUpActionListCriteria(workflowUser, filter); | |
68 | // } | |
69 | // LOG.debug("running query to get action list for criteria " + crit); | |
70 | // Collection<ActionItem> collection = this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionItemActionListExtension.class, crit)); | |
71 | // LOG.debug("found " + collection.size() + " action items for user " + workflowUser.getWorkflowUserId().getWorkflowId()); | |
72 | // return createActionListForUser(collection); | |
73 | } | |
74 | ||
75 | public Collection<ActionItem> getActionListForSingleDocument(String documentId) { | |
76 | 0 | LOG.debug("getting action list for document id " + documentId); |
77 | 0 | Criteria crit = new Criteria(); |
78 | 0 | crit.addEqualTo("documentId", documentId); |
79 | 0 | Collection<ActionItem> collection = this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionItemActionListExtension.class, crit)); |
80 | 0 | LOG.debug("found " + collection.size() + " action items for document id " + documentId); |
81 | 0 | return createActionListForRouteHeader(collection); |
82 | } | |
83 | ||
84 | private Criteria setUpActionListCriteria(String principalId, ActionListFilter filter) { | |
85 | 0 | LOG.debug("setting up Action List criteria"); |
86 | 0 | Criteria crit = new Criteria(); |
87 | 0 | boolean filterOn = false; |
88 | 0 | String filteredByItems = ""; |
89 | ||
90 | 0 | if (filter.getActionRequestCd() != null && !"".equals(filter.getActionRequestCd().trim()) && !filter.getActionRequestCd().equals(KEWConstants.ALL_CODE)) { |
91 | 0 | if (filter.isExcludeActionRequestCd()) { |
92 | 0 | crit.addNotEqualTo("actionRequestCd", filter.getActionRequestCd()); |
93 | } else { | |
94 | 0 | crit.addEqualTo("actionRequestCd", filter.getActionRequestCd()); |
95 | } | |
96 | 0 | filteredByItems += filteredByItems.length() > 0 ? ", " : ""; |
97 | 0 | filteredByItems += "Action Requested"; |
98 | } | |
99 | ||
100 | 0 | if (filter.getCreateDateFrom() != null || filter.getCreateDateTo() != null) { |
101 | 0 | if (filter.isExcludeCreateDate()) { |
102 | 0 | if (filter.getCreateDateFrom() != null && filter.getCreateDateTo() != null) { |
103 | 0 | crit.addNotBetween("routeHeader.createDate", new Timestamp(beginningOfDay(filter.getCreateDateFrom()).getTime()), new Timestamp(endOfDay(filter.getCreateDateTo()).getTime())); |
104 | 0 | } else if (filter.getCreateDateFrom() != null && filter.getCreateDateTo() == null) { |
105 | 0 | crit.addLessOrEqualThan("routeHeader.createDate", new Timestamp(beginningOfDay(filter.getCreateDateFrom()).getTime())); |
106 | 0 | } else if (filter.getCreateDateFrom() == null && filter.getCreateDateTo() != null) { |
107 | 0 | crit.addGreaterOrEqualThan("routeHeader.createDate", new Timestamp(endOfDay(filter.getCreateDateTo()).getTime())); |
108 | } | |
109 | } else { | |
110 | 0 | if (filter.getCreateDateFrom() != null && filter.getCreateDateTo() != null) { |
111 | 0 | crit.addBetween("routeHeader.createDate", new Timestamp(beginningOfDay(filter.getCreateDateFrom()).getTime()), new Timestamp(endOfDay(filter.getCreateDateTo()).getTime())); |
112 | 0 | } else if (filter.getCreateDateFrom() != null && filter.getCreateDateTo() == null) { |
113 | 0 | crit.addGreaterOrEqualThan("routeHeader.createDate", new Timestamp(beginningOfDay(filter.getCreateDateFrom()).getTime())); |
114 | 0 | } else if (filter.getCreateDateFrom() == null && filter.getCreateDateTo() != null) { |
115 | 0 | crit.addLessOrEqualThan("routeHeader.createDate", new Timestamp(endOfDay(filter.getCreateDateTo()).getTime())); |
116 | } | |
117 | } | |
118 | 0 | filteredByItems += filteredByItems.length() > 0 ? ", " : ""; |
119 | 0 | filteredByItems += "Date Created"; |
120 | } | |
121 | ||
122 | 0 | if (filter.getDocRouteStatus() != null && !"".equals(filter.getDocRouteStatus().trim()) && !filter.getDocRouteStatus().equals(KEWConstants.ALL_CODE)) { |
123 | 0 | if (filter.isExcludeRouteStatus()) { |
124 | 0 | crit.addNotEqualTo("routeHeader.docRouteStatus", filter.getDocRouteStatus()); |
125 | } else { | |
126 | 0 | crit.addEqualTo("routeHeader.docRouteStatus", filter.getDocRouteStatus()); |
127 | } | |
128 | 0 | filteredByItems += filteredByItems.length() > 0 ? ", " : ""; |
129 | 0 | filteredByItems += "Document Route Status"; |
130 | } | |
131 | ||
132 | 0 | if (filter.getDocumentTitle() != null && !"".equals(filter.getDocumentTitle().trim())) { |
133 | 0 | String docTitle = filter.getDocumentTitle(); |
134 | 0 | if (docTitle.trim().endsWith("*")) { |
135 | 0 | docTitle = docTitle.substring(0, docTitle.length() - 1); |
136 | } | |
137 | ||
138 | 0 | if (filter.isExcludeDocumentTitle()) { |
139 | 0 | crit.addNotLike("docTitle", "%" + docTitle + "%"); |
140 | } else { | |
141 | 0 | crit.addLike("docTitle", "%" + docTitle + "%"); |
142 | } | |
143 | 0 | filteredByItems += filteredByItems.length() > 0 ? ", " : ""; |
144 | 0 | filteredByItems += "Document Title"; |
145 | } | |
146 | ||
147 | 0 | if (filter.getDocumentType() != null && !"".equals(filter.getDocumentType().trim())) { |
148 | 0 | if (filter.isExcludeDocumentType()) { |
149 | 0 | crit.addNotLike("docName", "%" + filter.getDocumentType() + "%"); |
150 | } else { | |
151 | 0 | String documentTypeName = filter.getDocumentType(); |
152 | 0 | DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName); |
153 | 0 | if (documentType == null) { |
154 | 0 | crit.addLike("docName", "%" + filter.getDocumentType() + "%"); |
155 | } else { | |
156 | // search this document type plus it's children | |
157 | 0 | Criteria docTypeCrit = new Criteria(); |
158 | 0 | constructDocumentTypeCriteria(docTypeCrit, documentType); |
159 | 0 | crit.addAndCriteria(docTypeCrit); |
160 | } | |
161 | } | |
162 | 0 | filteredByItems += filteredByItems.length() > 0 ? ", " : ""; |
163 | 0 | filteredByItems += "Document Type"; |
164 | } | |
165 | ||
166 | 0 | if (filter.getLastAssignedDateFrom() != null || filter.getLastAssignedDateTo() != null) { |
167 | 0 | if (filter.isExcludeLastAssignedDate()) { |
168 | 0 | if (filter.getLastAssignedDateFrom() != null && filter.getLastAssignedDateTo() != null) { |
169 | 0 | crit.addNotBetween("dateAssigned", new Timestamp(beginningOfDay(filter.getLastAssignedDateFrom()).getTime()), new Timestamp(endOfDay(filter.getLastAssignedDateTo()).getTime())); |
170 | 0 | } else if (filter.getLastAssignedDateFrom() != null && filter.getLastAssignedDateTo() == null) { |
171 | 0 | crit.addLessOrEqualThan("dateAssigned", new Timestamp(beginningOfDay(filter.getLastAssignedDateFrom()).getTime())); |
172 | 0 | } else if (filter.getLastAssignedDateFrom() == null && filter.getLastAssignedDateTo() != null) { |
173 | 0 | crit.addGreaterOrEqualThan("dateAssigned", new Timestamp(endOfDay(filter.getLastAssignedDateTo()).getTime())); |
174 | } | |
175 | } else { | |
176 | 0 | if (filter.getLastAssignedDateFrom() != null && filter.getLastAssignedDateTo() != null) { |
177 | 0 | crit.addBetween("dateAssigned", new Timestamp(beginningOfDay(filter.getLastAssignedDateFrom()).getTime()), new Timestamp(endOfDay(filter.getLastAssignedDateTo()).getTime())); |
178 | 0 | } else if (filter.getLastAssignedDateFrom() != null && filter.getLastAssignedDateTo() == null) { |
179 | 0 | crit.addGreaterOrEqualThan("dateAssigned", new Timestamp(beginningOfDay(filter.getLastAssignedDateFrom()).getTime())); |
180 | 0 | } else if (filter.getLastAssignedDateFrom() == null && filter.getLastAssignedDateTo() != null) { |
181 | 0 | crit.addLessOrEqualThan("dateAssigned", new Timestamp(endOfDay(filter.getLastAssignedDateTo()).getTime())); |
182 | } | |
183 | } | |
184 | 0 | filteredByItems += filteredByItems.length() > 0 ? ", " : ""; |
185 | 0 | filteredByItems += "Date Last Assigned"; |
186 | } | |
187 | ||
188 | 0 | filter.setGroupId(null); |
189 | 0 | if (filter.getGroupIdString() != null && !"".equals(filter.getGroupIdString().trim()) && !filter.getGroupIdString().trim().equals(KEWConstants.NO_FILTERING)) { |
190 | ||
191 | 0 | filter.setGroupId(filter.getGroupIdString().trim()); |
192 | ||
193 | 0 | if (filter.isExcludeGroupId()) { |
194 | 0 | Criteria critNotEqual = new Criteria(); |
195 | 0 | critNotEqual.addNotEqualTo("groupId", filter.getGroupId()); |
196 | 0 | Criteria critNull = new Criteria(); |
197 | 0 | critNull.addIsNull("groupId"); |
198 | 0 | critNotEqual.addOrCriteria(critNull); |
199 | 0 | crit.addAndCriteria(critNotEqual); |
200 | 0 | } else { |
201 | 0 | crit.addEqualTo("groupId", filter.getGroupId()); |
202 | } | |
203 | 0 | filteredByItems += filteredByItems.length() > 0 ? ", " : ""; |
204 | 0 | filteredByItems += "Action Request Workgroup"; |
205 | } | |
206 | ||
207 | 0 | if (filteredByItems.length() > 0) { |
208 | 0 | filterOn = true; |
209 | } | |
210 | ||
211 | 0 | boolean addedDelegationCriteria = false; |
212 | 0 | if (StringUtils.isBlank(filter.getDelegationType()) && StringUtils.isBlank(filter.getPrimaryDelegateId()) && StringUtils.isBlank(filter.getDelegatorId())) { |
213 | 0 | crit.addEqualTo("principalId", principalId); |
214 | 0 | addedDelegationCriteria = true; |
215 | 0 | } else if ((StringUtils.isNotBlank(filter.getDelegationType()) && KEWConstants.DELEGATION_PRIMARY.equals(filter.getDelegationType())) |
216 | || StringUtils.isNotBlank(filter.getPrimaryDelegateId())) { | |
217 | // using a primary delegation | |
218 | 0 | if ((StringUtils.isBlank(filter.getPrimaryDelegateId())) || (filter.getPrimaryDelegateId().trim().equals(KEWConstants.ALL_CODE))) { |
219 | // user wishes to see all primary delegations | |
220 | 0 | Criteria userCrit = new Criteria(); |
221 | 0 | Criteria groupCrit = new Criteria(); |
222 | 0 | Criteria orCrit = new Criteria(); |
223 | 0 | userCrit.addEqualTo("delegatorWorkflowId", principalId); |
224 | 0 | List<String> delegatorGroupIds = KimApiServiceLocator.getIdentityManagementService().getGroupIdsForPrincipal(principalId); |
225 | 0 | if (delegatorGroupIds != null && !delegatorGroupIds.isEmpty()) { |
226 | 0 | groupCrit.addIn("delegatorGroupId", delegatorGroupIds); |
227 | } | |
228 | 0 | orCrit.addOrCriteria(userCrit); |
229 | 0 | orCrit.addOrCriteria(groupCrit); |
230 | 0 | crit.addAndCriteria(orCrit); |
231 | 0 | crit.addEqualTo("delegationType", KEWConstants.DELEGATION_PRIMARY); |
232 | 0 | filter.setDelegationType(KEWConstants.DELEGATION_PRIMARY); |
233 | 0 | filter.setExcludeDelegationType(false); |
234 | 0 | addToFilterDescription(filteredByItems, "Primary Delegator Id"); |
235 | 0 | addedDelegationCriteria = true; |
236 | 0 | filterOn = true; |
237 | 0 | } else if (!filter.getPrimaryDelegateId().trim().equals(KEWConstants.PRIMARY_DELEGATION_DEFAULT)) { |
238 | // user wishes to see primary delegation for a single user | |
239 | 0 | crit.addEqualTo("principalId", filter.getPrimaryDelegateId()); |
240 | 0 | Criteria userCrit = new Criteria(); |
241 | 0 | Criteria groupCrit = new Criteria(); |
242 | 0 | Criteria orCrit = new Criteria(); |
243 | 0 | userCrit.addEqualTo("delegatorWorkflowId", principalId); |
244 | 0 | List<String> delegatorGroupIds = KimApiServiceLocator.getIdentityManagementService().getGroupIdsForPrincipal(principalId); |
245 | 0 | if (delegatorGroupIds != null && !delegatorGroupIds.isEmpty()) { |
246 | 0 | groupCrit.addIn("delegatorGroupId", delegatorGroupIds); |
247 | } | |
248 | 0 | orCrit.addOrCriteria(userCrit); |
249 | 0 | orCrit.addOrCriteria(groupCrit); |
250 | 0 | crit.addAndCriteria(orCrit); |
251 | 0 | crit.addEqualTo("delegationType", KEWConstants.DELEGATION_PRIMARY); |
252 | 0 | filter.setDelegationType(KEWConstants.DELEGATION_PRIMARY); |
253 | 0 | filter.setExcludeDelegationType(false); |
254 | 0 | addToFilterDescription(filteredByItems, "Primary Delegator Id"); |
255 | 0 | addedDelegationCriteria = true; |
256 | 0 | filterOn = true; |
257 | } | |
258 | } | |
259 | 0 | if (!addedDelegationCriteria && ( (StringUtils.isNotBlank(filter.getDelegationType()) && KEWConstants.DELEGATION_SECONDARY.equals(filter.getDelegationType())) |
260 | || StringUtils.isNotBlank(filter.getDelegatorId()) )) { | |
261 | // using a secondary delegation | |
262 | 0 | crit.addEqualTo("principalId", principalId); |
263 | 0 | if (StringUtils.isBlank(filter.getDelegatorId())) { |
264 | 0 | filter.setDelegationType(KEWConstants.DELEGATION_SECONDARY); |
265 | // if isExcludeDelegationType() we want to show the default action list which is set up later in this method | |
266 | 0 | if (!filter.isExcludeDelegationType()) { |
267 | 0 | crit.addEqualTo("delegationType", KEWConstants.DELEGATION_SECONDARY); |
268 | 0 | addToFilterDescription(filteredByItems, "Secondary Delegator Id"); |
269 | 0 | addedDelegationCriteria = true; |
270 | 0 | filterOn = true; |
271 | } | |
272 | 0 | } else if (filter.getDelegatorId().trim().equals(KEWConstants.ALL_CODE)) { |
273 | // user wishes to see all secondary delegations | |
274 | 0 | crit.addEqualTo("delegationType", KEWConstants.DELEGATION_SECONDARY); |
275 | 0 | filter.setDelegationType(KEWConstants.DELEGATION_SECONDARY); |
276 | 0 | filter.setExcludeDelegationType(false); |
277 | 0 | addToFilterDescription(filteredByItems, "Secondary Delegator Id"); |
278 | 0 | addedDelegationCriteria = true; |
279 | 0 | filterOn = true; |
280 | 0 | } else if (!filter.getDelegatorId().trim().equals( |
281 | KEWConstants.DELEGATION_DEFAULT)) { | |
282 | // user has specified an id to see for secondary delegation | |
283 | 0 | filter.setDelegationType(KEWConstants.DELEGATION_SECONDARY); |
284 | 0 | filter.setExcludeDelegationType(false); |
285 | 0 | Criteria userCrit = new Criteria(); |
286 | 0 | Criteria groupCrit = new Criteria(); |
287 | 0 | if (filter.isExcludeDelegatorId()) { |
288 | 0 | Criteria userNull = new Criteria(); |
289 | 0 | userCrit.addNotEqualTo("delegatorWorkflowId", filter.getDelegatorId()); |
290 | 0 | userNull.addIsNull("delegatorWorkflowId"); |
291 | 0 | userCrit.addOrCriteria(userNull); |
292 | 0 | Criteria groupNull = new Criteria(); |
293 | 0 | groupCrit.addNotEqualTo("delegatorGroupId", filter.getDelegatorId()); |
294 | 0 | groupNull.addIsNull("delegatorGroupId"); |
295 | 0 | groupCrit.addOrCriteria(groupNull); |
296 | 0 | crit.addAndCriteria(userCrit); |
297 | 0 | crit.addAndCriteria(groupCrit); |
298 | 0 | } else { |
299 | 0 | Criteria orCrit = new Criteria(); |
300 | 0 | userCrit.addEqualTo("delegatorWorkflowId", filter.getDelegatorId()); |
301 | 0 | groupCrit.addEqualTo("delegatorGroupId", filter.getDelegatorId()); |
302 | 0 | orCrit.addOrCriteria(userCrit); |
303 | 0 | orCrit.addOrCriteria(groupCrit); |
304 | 0 | crit.addAndCriteria(orCrit); |
305 | } | |
306 | 0 | addToFilterDescription(filteredByItems, "Secondary Delegator Id"); |
307 | 0 | addedDelegationCriteria = true; |
308 | 0 | filterOn = true; |
309 | } | |
310 | // } else if ( (StringUtils.isNotBlank(filter.getDelegationType()) && KEWConstants.DELEGATION_DEFAULT.equals(filter.getDelegationType())) || | |
311 | // StringUtils.isNotBlank(filter.getDelegatorId()) ) { | |
312 | // // not using a primary delegation so we can assume the action item will be assigned to the given user | |
313 | // crit.addEqualTo("workflowId", user.getWorkflowUserId().getWorkflowId()); | |
314 | // if (filter.getDelegatorId() != null && !"".equals(filter.getDelegatorId().trim()) && !filter.getDelegatorId().trim().equals(KEWConstants.DELEGATION_DEFAULT) | |
315 | // && !filter.getDelegatorId().trim().equals(KEWConstants.ALL_CODE)) { | |
316 | // filter.setDelegationType(KEWConstants.DELEGATION_SECONDARY); | |
317 | // filter.setExcludeDelegationType(false); | |
318 | // Criteria userCrit = new Criteria(); | |
319 | // Criteria groupCrit = new Criteria(); | |
320 | // if (filter.isExcludeDelegatorId()) { | |
321 | // Criteria userNull = new Criteria(); | |
322 | // userCrit.addNotEqualTo("delegatorWorkflowId", filter.getDelegatorId()); | |
323 | // userNull.addIsNull("delegatorWorkflowId"); | |
324 | // userCrit.addOrCriteria(userNull); | |
325 | // Criteria groupNull = new Criteria(); | |
326 | // groupCrit.addNotEqualTo("delegatorWorkgroupId", filter.getDelegatorId()); | |
327 | // groupNull.addIsNull("delegatorWorkgroupId"); | |
328 | // groupCrit.addOrCriteria(groupNull); | |
329 | // crit.addAndCriteria(userCrit); | |
330 | // crit.addAndCriteria(groupCrit); | |
331 | // } else { | |
332 | // Criteria orCrit = new Criteria(); | |
333 | // userCrit.addEqualTo("delegatorWorkflowId", filter.getDelegatorId()); | |
334 | // groupCrit.addEqualTo("delegatorWorkgroupId", filter.getDelegatorId()); | |
335 | // orCrit.addOrCriteria(userCrit); | |
336 | // orCrit.addOrCriteria(groupCrit); | |
337 | // crit.addAndCriteria(orCrit); | |
338 | // } | |
339 | // addToFilterDescription(filteredByItems, "Secondary Delegator Id"); | |
340 | // addedDelegationCriteria = true; | |
341 | // } else if (filter.getDelegatorId().trim().equals(KEWConstants.ALL_CODE)) { | |
342 | // filter.setDelegationType(KEWConstants.DELEGATION_SECONDARY); | |
343 | // filter.setExcludeDelegationType(false); | |
344 | // addToFilterDescription(filteredByItems, "Secondary Delegator Id"); | |
345 | // addedDelegationCriteria = true; | |
346 | // } | |
347 | } | |
348 | ||
349 | // if we haven't added delegation criteria then use the default criteria below | |
350 | 0 | if (!addedDelegationCriteria) { |
351 | 0 | crit.addEqualTo("principalId", principalId); |
352 | 0 | filter.setDelegationType(KEWConstants.DELEGATION_SECONDARY); |
353 | 0 | filter.setExcludeDelegationType(true); |
354 | 0 | Criteria critNotEqual = new Criteria(); |
355 | 0 | Criteria critNull = new Criteria(); |
356 | 0 | critNotEqual.addNotEqualTo("delegationType", KEWConstants.DELEGATION_SECONDARY); |
357 | 0 | critNull.addIsNull("delegationType"); |
358 | 0 | critNotEqual.addOrCriteria(critNull); |
359 | 0 | crit.addAndCriteria(critNotEqual); |
360 | } | |
361 | ||
362 | ||
363 | // if (filter.getPrimaryDelegateId().equals(KEWConstants.PRIMARY_DELEGATION_DEFAULT) && filter.getDelegatorId().equals(KEWConstants.DELEGATION_DEFAULT)) { | |
364 | // // no secondary or primary delegation displayed | |
365 | // crit.addEqualTo("workflowId", user.getWorkflowUserId().getWorkflowId()); | |
366 | // filter.setDelegationType(KEWConstants.DELEGATION_SECONDARY); | |
367 | // Criteria critNotEqual = new Criteria(); | |
368 | // Criteria critNull = new Criteria(); | |
369 | // critNotEqual.addNotEqualTo("delegationType", KEWConstants.DELEGATION_SECONDARY); | |
370 | // critNull.addIsNull("delegationType"); | |
371 | // critNotEqual.addOrCriteria(critNull); | |
372 | // crit.addAndCriteria(critNotEqual); | |
373 | // filter.setExcludeDelegationType(true); | |
374 | // } else if (filter.getPrimaryDelegateId().trim().equals(KEWConstants.ALL_CODE)) { | |
375 | // // user wishes to see all primary delegations | |
376 | // Criteria userCrit = new Criteria(); | |
377 | // Criteria groupCrit = new Criteria(); | |
378 | // Criteria orCrit = new Criteria(); | |
379 | // userCrit.addEqualTo("delegatorWorkflowId", user.getWorkflowUserId().getWorkflowId()); | |
380 | // groupCrit.addEqualTo("delegatorWorkgroupId", filter.getPrimaryDelegateId()); // TODO delyea: add all workgroups here? | |
381 | // orCrit.addOrCriteria(userCrit); | |
382 | // orCrit.addOrCriteria(groupCrit); | |
383 | // crit.addAndCriteria(orCrit); | |
384 | // crit.addEqualTo("delegationType", KEWConstants.DELEGATION_PRIMARY); | |
385 | // filter.setDelegationType(KEWConstants.DELEGATION_PRIMARY); | |
386 | // filter.setExcludeDelegationType(false); | |
387 | // filteredByItems += filteredByItems.length() > 0 ? ", " : ""; | |
388 | // filteredByItems += "Primary Delegator Id"; | |
389 | // filterOn = true; | |
390 | // } else if (filter.getDelegatorId().trim().equals(KEWConstants.ALL_CODE)) { | |
391 | // // user wishes to see all secondary delegations | |
392 | // crit.addEqualTo("workflowId", user.getWorkflowUserId().getWorkflowId()); | |
393 | // crit.addEqualTo("delegationType", KEWConstants.DELEGATION_SECONDARY); | |
394 | // filter.setDelegationType(KEWConstants.DELEGATION_SECONDARY); | |
395 | // filter.setExcludeDelegationType(false); | |
396 | // filteredByItems += filteredByItems.length() > 0 ? ", " : ""; | |
397 | // filteredByItems += "Secondary Delegator Id"; | |
398 | // filterOn = true; | |
399 | // } else if (filter.getPrimaryDelegateId() != null && !"".equals(filter.getPrimaryDelegateId().trim())) { | |
400 | // // user wishes to see primary delegation for a single user | |
401 | // Criteria userCrit = new Criteria(); | |
402 | // Criteria groupCrit = new Criteria(); | |
403 | // Criteria orCrit = new Criteria(); | |
404 | // userCrit.addEqualTo("delegatorWorkflowId", user.getWorkflowUserId().getWorkflowId()); | |
405 | // groupCrit.addEqualTo("delegatorWorkgroupId", filter.getDelegatorId()); // TODO delyea: add all workgroups here? | |
406 | // orCrit.addOrCriteria(userCrit); | |
407 | // orCrit.addOrCriteria(groupCrit); | |
408 | // crit.addAndCriteria(orCrit); | |
409 | // crit.addEqualTo("delegationType", KEWConstants.DELEGATION_PRIMARY); | |
410 | // filter.setDelegationType(KEWConstants.DELEGATION_PRIMARY); | |
411 | // filter.setExcludeDelegationType(false); | |
412 | // filteredByItems += filteredByItems.length() > 0 ? ", " : ""; | |
413 | // filteredByItems += "Primary Delegator Id"; | |
414 | // filterOn = true; | |
415 | // } else if (filter.getDelegatorId() != null && !"".equals(filter.getDelegatorId().trim())) { | |
416 | // // user wishes to see secondary delegation for a single user | |
417 | // crit.addEqualTo("workflowId", user.getWorkflowUserId().getWorkflowId()); | |
418 | // crit.addEqualTo("delegationType", KEWConstants.DELEGATION_SECONDARY); | |
419 | // filter.setDelegationType(KEWConstants.DELEGATION_SECONDARY); | |
420 | // filter.setExcludeDelegationType(false); | |
421 | // Criteria userCrit = new Criteria(); | |
422 | // Criteria groupCrit = new Criteria(); | |
423 | // if (filter.isExcludeDelegatorId()) { | |
424 | // Criteria userNull = new Criteria(); | |
425 | // userCrit.addNotEqualTo("delegatorWorkflowId", filter.getDelegatorId()); | |
426 | // userNull.addIsNull("delegatorWorkflowId"); | |
427 | // userCrit.addOrCriteria(userNull); | |
428 | // Criteria groupNull = new Criteria(); | |
429 | // groupCrit.addNotEqualTo("delegatorWorkgroupId", filter.getDelegatorId()); | |
430 | // groupNull.addIsNull("delegatorWorkgroupId"); | |
431 | // groupCrit.addOrCriteria(groupNull); | |
432 | // crit.addAndCriteria(userCrit); | |
433 | // crit.addAndCriteria(groupCrit); | |
434 | // } else { | |
435 | // Criteria orCrit = new Criteria(); | |
436 | // userCrit.addEqualTo("delegatorWorkflowId", filter.getDelegatorId()); | |
437 | // groupCrit.addEqualTo("delegatorWorkgroupId", filter.getDelegatorId()); | |
438 | // orCrit.addOrCriteria(userCrit); | |
439 | // orCrit.addOrCriteria(groupCrit); | |
440 | // crit.addAndCriteria(orCrit); | |
441 | // } | |
442 | // filteredByItems += filteredByItems.length() > 0 ? ", " : ""; | |
443 | // filteredByItems += "SeDelegator Id"; | |
444 | // filterOn = true; | |
445 | // } else if (StringUtils.isBlank(filter.getPrimaryDelegateId()) && StringUtils.isBlank(filter.getDelegatorId())) { | |
446 | // crit.addEqualTo("workflowId", user.getWorkflowUserId().getWorkflowId()); | |
447 | // if (filter.getDelegationType() != null && !"".equals(filter.getDelegationType().trim())) { | |
448 | // if (filter.isExcludeDelegationType()) { | |
449 | // Criteria critNotEqual = new Criteria(); | |
450 | // Criteria critNull = new Criteria(); | |
451 | // critNotEqual.addNotEqualTo("delegationType", filter.getDelegationType()); | |
452 | // critNull.addIsNull("delegationType"); | |
453 | // critNotEqual.addOrCriteria(critNull); | |
454 | // crit.addAndCriteria(critNotEqual); | |
455 | // } else { | |
456 | // crit.addEqualTo("delegationType", filter.getDelegationType()); | |
457 | // } | |
458 | // } | |
459 | // } | |
460 | ||
461 | ||
462 | // if (primary delegation) { | |
463 | // filter.setDelegationType(KEWConstants.DELEGATION_PRIMARY); | |
464 | // crit.addEqualTo("delegatorWorkflowId", user.getWorkflowUserId().getWorkflowId()); | |
465 | // | |
466 | // } else { | |
467 | // crit.addEqualTo("workflowId", user.getWorkflowUserId().getWorkflowId()); | |
468 | // if (filter.getDelegatorId() != null && !"".equals(filter.getDelegatorId().trim()) && !filter.getDelegatorId().trim().equals(KEWConstants.DELEGATION_DEFAULT) | |
469 | // && !filter.getDelegatorId().trim().equals(KEWConstants.ALL_CODE)) { | |
470 | // filter.setDelegationType(KEWConstants.DELEGATION_SECONDARY); | |
471 | // filter.setExcludeDelegationType(false); | |
472 | // Criteria userCrit = new Criteria(); | |
473 | // Criteria groupCrit = new Criteria(); | |
474 | // if (filter.isExcludeDelegatorId()) { | |
475 | // Criteria userNull = new Criteria(); | |
476 | // userCrit.addNotEqualTo("delegatorWorkflowId", filter.getDelegatorId()); | |
477 | // userNull.addIsNull("delegatorWorkflowId"); | |
478 | // userCrit.addOrCriteria(userNull); | |
479 | // Criteria groupNull = new Criteria(); | |
480 | // groupCrit.addNotEqualTo("delegatorWorkgroupId", filter.getDelegatorId()); | |
481 | // groupNull.addIsNull("delegatorWorkgroupId"); | |
482 | // groupCrit.addOrCriteria(groupNull); | |
483 | // crit.addAndCriteria(userCrit); | |
484 | // crit.addAndCriteria(groupCrit); | |
485 | // } else { | |
486 | // Criteria orCrit = new Criteria(); | |
487 | // userCrit.addEqualTo("delegatorWorkflowId", filter.getDelegatorId()); | |
488 | // groupCrit.addEqualTo("delegatorWorkgroupId", filter.getDelegatorId()); | |
489 | // orCrit.addOrCriteria(userCrit); | |
490 | // orCrit.addOrCriteria(groupCrit); | |
491 | // crit.addAndCriteria(orCrit); | |
492 | // } | |
493 | // filteredByItems += filteredByItems.length() > 0 ? ", " : ""; | |
494 | // filteredByItems += "Delegator Id"; | |
495 | // filterOn = true; | |
496 | // } else if (filter.getDelegatorId().trim().equals(KEWConstants.DELEGATION_DEFAULT)) { | |
497 | // filter.setDelegationType(KEWConstants.DELEGATION_SECONDARY); | |
498 | // filter.setExcludeDelegationType(true); | |
499 | // } else if (filter.getDelegatorId().trim().equals(KEWConstants.ALL_CODE)) { | |
500 | // filter.setDelegationType(KEWConstants.DELEGATION_SECONDARY); | |
501 | // filter.setExcludeDelegationType(false); | |
502 | // filteredByItems += filteredByItems.length() > 0 ? ", " : ""; | |
503 | // filteredByItems += "Delegator Id"; | |
504 | // filterOn = true; | |
505 | // } | |
506 | // | |
507 | // } | |
508 | // | |
509 | // | |
510 | // //must come after delegation id since the delegation choices are all secondary delegations | |
511 | // if (filter.getDelegationType() != null && !"".equals(filter.getDelegationType().trim())) { | |
512 | // if (filter.isExcludeDelegationType()) { | |
513 | // Criteria critNotEqual = new Criteria(); | |
514 | // Criteria critNull = new Criteria(); | |
515 | // critNotEqual.addNotEqualTo("delegationType", filter.getDelegationType()); | |
516 | // critNull.addIsNull("delegationType"); | |
517 | // critNotEqual.addOrCriteria(critNull); | |
518 | // crit.addAndCriteria(critNotEqual); | |
519 | // } else { | |
520 | // crit.addEqualTo("delegationType", filter.getDelegationType()); | |
521 | // } | |
522 | // } | |
523 | ||
524 | 0 | if (! "".equals(filteredByItems)) { |
525 | 0 | filteredByItems = "Filtered by " + filteredByItems; |
526 | } | |
527 | 0 | filter.setFilterLegend(filteredByItems); |
528 | 0 | filter.setFilterOn(filterOn); |
529 | ||
530 | 0 | LOG.debug("returning from Action List criteria"); |
531 | 0 | return crit; |
532 | } | |
533 | ||
534 | private void constructDocumentTypeCriteria(Criteria criteria, DocumentType documentType) { | |
535 | // search this document type plus it's children | |
536 | 0 | Criteria docTypeBaseCrit = new Criteria(); |
537 | 0 | docTypeBaseCrit.addEqualTo("docName", documentType.getName()); |
538 | 0 | criteria.addOrCriteria(docTypeBaseCrit); |
539 | 0 | Collection children = documentType.getChildrenDocTypes(); |
540 | 0 | if (children != null) { |
541 | 0 | for (Iterator iterator = children.iterator(); iterator.hasNext();) { |
542 | 0 | DocumentType childDocumentType = (DocumentType) iterator.next(); |
543 | 0 | constructDocumentTypeCriteria(criteria, childDocumentType); |
544 | 0 | } |
545 | } | |
546 | 0 | } |
547 | ||
548 | private void addToFilterDescription(String filterDescription, String labelToAdd) { | |
549 | 0 | filterDescription += filterDescription.length() > 0 ? ", " : ""; |
550 | 0 | filterDescription += labelToAdd; |
551 | 0 | } |
552 | ||
553 | private static final String ACTION_LIST_COUNT_QUERY = "select count(distinct(ai.doc_hdr_id)) from krew_actn_itm_t ai where ai.PRNCPL_ID = ? and (ai.dlgn_typ is null or ai.dlgn_typ = 'P')"; | |
554 | ||
555 | public int getCount(final String workflowId) { | |
556 | 0 | return (Integer)getPersistenceBrokerTemplate().execute(new PersistenceBrokerCallback() { |
557 | public Object doInPersistenceBroker(PersistenceBroker broker) { | |
558 | 0 | PreparedStatement statement = null; |
559 | 0 | ResultSet resultSet = null; |
560 | try { | |
561 | 0 | Connection connection = broker.serviceConnectionManager().getConnection(); |
562 | 0 | statement = connection.prepareStatement(ACTION_LIST_COUNT_QUERY); |
563 | 0 | statement.setString(1, workflowId); |
564 | 0 | resultSet = statement.executeQuery(); |
565 | 0 | if (!resultSet.next()) { |
566 | 0 | throw new WorkflowRuntimeException("Error determining Action List Count."); |
567 | } | |
568 | 0 | return resultSet.getInt(1); |
569 | 0 | } catch (SQLException e) { |
570 | 0 | throw new WorkflowRuntimeException("Error determining Action List Count.", e); |
571 | 0 | } catch (LookupException e) { |
572 | 0 | throw new WorkflowRuntimeException("Error determining Action List Count.", e); |
573 | } finally { | |
574 | 0 | if (statement != null) { |
575 | try { | |
576 | 0 | statement.close(); |
577 | 0 | } catch (SQLException e) {} |
578 | } | |
579 | 0 | if (resultSet != null) { |
580 | try { | |
581 | 0 | resultSet.close(); |
582 | 0 | } catch (SQLException e) {} |
583 | } | |
584 | } | |
585 | } | |
586 | }); | |
587 | } | |
588 | ||
589 | /** | |
590 | * Creates an Action List from the given collection of Action Items. The Action List should | |
591 | * contain only one action item per document. The action item chosen should be the most "critical" | |
592 | * or "important" one on the document. | |
593 | * | |
594 | * @return the Action List as a Collection of ActionItems | |
595 | */ | |
596 | private Collection<ActionItem> createActionListForUser(Collection<ActionItem> actionItems) { | |
597 | 0 | Map<String, ActionItem> actionItemMap = new HashMap<String, ActionItem>(); |
598 | 0 | ActionListPriorityComparator comparator = new ActionListPriorityComparator(); |
599 | 0 | for (ActionItem potentialActionItem: actionItems) { |
600 | 0 | ActionItem existingActionItem = actionItemMap.get(potentialActionItem.getDocumentId()); |
601 | 0 | if (existingActionItem == null || comparator.compare(potentialActionItem, existingActionItem) > 0) { |
602 | 0 | actionItemMap.put(potentialActionItem.getDocumentId(), potentialActionItem); |
603 | } | |
604 | 0 | } |
605 | 0 | return actionItemMap.values(); |
606 | } | |
607 | ||
608 | /** | |
609 | * Creates an Action List from the given collection of Action Items. The Action List should | |
610 | * contain only one action item per user. The action item chosen should be the most "critical" | |
611 | * or "important" one on the document. | |
612 | * | |
613 | * @return the Action List as a Collection of ActionItems | |
614 | */ | |
615 | private Collection<ActionItem> createActionListForRouteHeader(Collection<ActionItem> actionItems) { | |
616 | 0 | Map<String, ActionItem> actionItemMap = new HashMap<String, ActionItem>(); |
617 | 0 | ActionListPriorityComparator comparator = new ActionListPriorityComparator(); |
618 | 0 | for (ActionItem potentialActionItem: actionItems) { |
619 | 0 | ActionItem existingActionItem = actionItemMap.get(potentialActionItem.getPrincipalId()); |
620 | 0 | if (existingActionItem == null || comparator.compare(potentialActionItem, existingActionItem) > 0) { |
621 | 0 | actionItemMap.put(potentialActionItem.getPrincipalId(), potentialActionItem); |
622 | } | |
623 | 0 | } |
624 | 0 | return actionItemMap.values(); |
625 | } | |
626 | ||
627 | private Collection<ActionItem> getActionItemsInActionList(Class objectsToRetrieve, String principalId, ActionListFilter filter) { | |
628 | 0 | LOG.debug("getting action list for user " + principalId); |
629 | 0 | Criteria crit = null; |
630 | 0 | if (filter == null) { |
631 | 0 | crit = new Criteria(); |
632 | 0 | crit.addEqualTo("principalId", principalId); |
633 | } else { | |
634 | 0 | crit = setUpActionListCriteria(principalId, filter); |
635 | } | |
636 | 0 | LOG.debug("running query to get action list for criteria " + crit); |
637 | 0 | Collection<ActionItem> collection = this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(objectsToRetrieve, crit)); |
638 | 0 | LOG.debug("found " + collection.size() + " action items for user " + principalId); |
639 | 0 | return createActionListForUser(collection); |
640 | } | |
641 | ||
642 | public Collection<ActionItem> getOutbox(String principalId, ActionListFilter filter) { | |
643 | 0 | return getActionItemsInActionList(OutboxItemActionListExtension.class, principalId, filter); |
644 | // LOG.debug("getting action list for user " + workflowUser.getWorkflowUserId().getWorkflowId()); | |
645 | // Criteria crit = new Criteria(); | |
646 | // crit.addEqualTo("workflowId", workflowUser.getWorkflowUserId().getWorkflowId()); | |
647 | // if (filter != null) { | |
648 | // setUpActionListCriteria(workflowUser, filter); | |
649 | // } | |
650 | // LOG.debug("running query to get action list for criteria " + crit); | |
651 | // Collection<ActionItem> collection = this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(OutboxItemActionListExtension.class, crit)); | |
652 | // LOG.debug("found " + collection.size() + " action items for user " + workflowUser.getWorkflowUserId().getWorkflowId()); | |
653 | // return createActionListForUser(collection); | |
654 | } | |
655 | ||
656 | /** | |
657 | * | |
658 | * Deletes all outbox items specified by the list of ids | |
659 | * | |
660 | * @see org.kuali.rice.kew.actionlist.dao.ActionListDAO#removeOutboxItems(java.lang.String, java.util.List) | |
661 | */ | |
662 | public void removeOutboxItems(String principalId, List<String> outboxItems) { | |
663 | 0 | Criteria crit = new Criteria(); |
664 | 0 | crit.addIn("actionItemId", outboxItems); |
665 | 0 | getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(OutboxItemActionListExtension.class, crit)); |
666 | 0 | } |
667 | ||
668 | /** | |
669 | * Saves an outbox item | |
670 | * | |
671 | * @see org.kuali.rice.kew.actionlist.dao.ActionListDAO#saveOutboxItem(org.kuali.rice.kew.actionitem.OutboxItemActionListExtension) | |
672 | */ | |
673 | public void saveOutboxItem(OutboxItemActionListExtension outboxItem) { | |
674 | 0 | this.getPersistenceBrokerTemplate().store(outboxItem); |
675 | 0 | } |
676 | ||
677 | /** | |
678 | * Gets the outbox item associated with the document id | |
679 | * | |
680 | * @see org.kuali.rice.kew.actionlist.dao.ActionListDAO#getOutboxByDocumentId(java.lang.String) | |
681 | */ | |
682 | public OutboxItemActionListExtension getOutboxByDocumentId(String documentId) { | |
683 | 0 | Criteria crit = new Criteria(); |
684 | 0 | crit.addEqualTo("documentId", documentId); |
685 | 0 | return (OutboxItemActionListExtension)getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(OutboxItemActionListExtension.class, crit)); |
686 | } | |
687 | ||
688 | /** | |
689 | * This overridden method ... | |
690 | * | |
691 | * @see org.kuali.rice.kew.actionlist.dao.ActionListDAO#getOutboxByDocumentIdUserId(java.lang.String) | |
692 | */ | |
693 | public OutboxItemActionListExtension getOutboxByDocumentIdUserId(String documentId, String userId) { | |
694 | 0 | Criteria crit = new Criteria(); |
695 | 0 | crit.addEqualTo("documentId", documentId); |
696 | 0 | crit.addEqualTo("principalId", userId); |
697 | 0 | return (OutboxItemActionListExtension)getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(OutboxItemActionListExtension.class, crit)); |
698 | } | |
699 | ||
700 | private Date beginningOfDay(Date date) { | |
701 | 0 | Calendar cal = Calendar.getInstance(); |
702 | 0 | cal.setTime(date); |
703 | 0 | cal.set(Calendar.HOUR_OF_DAY, 0); |
704 | 0 | cal.set(Calendar.MINUTE, 0); |
705 | 0 | cal.set(Calendar.SECOND, 0); |
706 | 0 | return cal.getTime(); |
707 | } | |
708 | ||
709 | private Date endOfDay(Date date) { | |
710 | 0 | Calendar cal = Calendar.getInstance(); |
711 | 0 | cal.setTime(date); |
712 | 0 | cal.set(Calendar.HOUR_OF_DAY, 23); |
713 | 0 | cal.set(Calendar.MINUTE, 59); |
714 | 0 | cal.set(Calendar.SECOND, 59); |
715 | 0 | return cal.getTime(); |
716 | } | |
717 | ||
718 | } |