| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kew.actionlist.dao.impl; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.apache.ojb.broker.PersistenceBroker; |
| 20 | |
import org.apache.ojb.broker.accesslayer.LookupException; |
| 21 | |
import org.apache.ojb.broker.query.Criteria; |
| 22 | |
import org.apache.ojb.broker.query.QueryByCriteria; |
| 23 | |
import org.kuali.rice.core.api.delegation.DelegationType; |
| 24 | |
import org.kuali.rice.kew.actionitem.ActionItem; |
| 25 | |
import org.kuali.rice.kew.actionitem.ActionItemActionListExtension; |
| 26 | |
import org.kuali.rice.kew.actionitem.OutboxItemActionListExtension; |
| 27 | |
import org.kuali.rice.kew.actionlist.ActionListFilter; |
| 28 | |
import org.kuali.rice.kew.actionlist.dao.ActionListDAO; |
| 29 | |
import org.kuali.rice.kew.api.WorkflowRuntimeException; |
| 30 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
| 31 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
| 32 | |
import org.kuali.rice.kew.api.KewApiConstants; |
| 33 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
| 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.sql.Timestamp; |
| 42 | |
import java.util.Calendar; |
| 43 | |
import java.util.Collection; |
| 44 | |
import java.util.Date; |
| 45 | |
import java.util.HashMap; |
| 46 | |
import java.util.Iterator; |
| 47 | |
import java.util.List; |
| 48 | |
import java.util.Map; |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 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 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 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(KewApiConstants.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(KewApiConstants.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 | |
|
| 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(KewApiConstants.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()) && DelegationType.PRIMARY.getCode().equals(filter.getDelegationType())) |
| 216 | |
|| StringUtils.isNotBlank(filter.getPrimaryDelegateId())) { |
| 217 | |
|
| 218 | 0 | if ((StringUtils.isBlank(filter.getPrimaryDelegateId())) || (filter.getPrimaryDelegateId().trim().equals(KewApiConstants.ALL_CODE))) { |
| 219 | |
|
| 220 | 0 | Criteria userCrit = new Criteria(); |
| 221 | 0 | Criteria groupCrit = new Criteria(); |
| 222 | 0 | Criteria orCrit = new Criteria(); |
| 223 | 0 | userCrit.addEqualTo("delegatorPrincipalId", principalId); |
| 224 | 0 | List<String> delegatorGroupIds = KimApiServiceLocator.getGroupService().getGroupIdsByPrincipalId( |
| 225 | |
principalId); |
| 226 | 0 | if (delegatorGroupIds != null && !delegatorGroupIds.isEmpty()) { |
| 227 | 0 | groupCrit.addIn("delegatorGroupId", delegatorGroupIds); |
| 228 | |
} |
| 229 | 0 | orCrit.addOrCriteria(userCrit); |
| 230 | 0 | orCrit.addOrCriteria(groupCrit); |
| 231 | 0 | crit.addAndCriteria(orCrit); |
| 232 | 0 | crit.addEqualTo("delegationType", DelegationType.PRIMARY.getCode()); |
| 233 | 0 | filter.setDelegationType(DelegationType.PRIMARY.getCode()); |
| 234 | 0 | filter.setExcludeDelegationType(false); |
| 235 | 0 | addToFilterDescription(filteredByItems, "Primary Delegator Id"); |
| 236 | 0 | addedDelegationCriteria = true; |
| 237 | 0 | filterOn = true; |
| 238 | 0 | } else if (!filter.getPrimaryDelegateId().trim().equals(KewApiConstants.PRIMARY_DELEGATION_DEFAULT)) { |
| 239 | |
|
| 240 | 0 | crit.addEqualTo("principalId", filter.getPrimaryDelegateId()); |
| 241 | 0 | Criteria userCrit = new Criteria(); |
| 242 | 0 | Criteria groupCrit = new Criteria(); |
| 243 | 0 | Criteria orCrit = new Criteria(); |
| 244 | 0 | userCrit.addEqualTo("delegatorPrincipalId", principalId); |
| 245 | 0 | List<String> delegatorGroupIds = KimApiServiceLocator.getGroupService().getGroupIdsByPrincipalId( |
| 246 | |
principalId); |
| 247 | 0 | if (delegatorGroupIds != null && !delegatorGroupIds.isEmpty()) { |
| 248 | 0 | groupCrit.addIn("delegatorGroupId", delegatorGroupIds); |
| 249 | |
} |
| 250 | 0 | orCrit.addOrCriteria(userCrit); |
| 251 | 0 | orCrit.addOrCriteria(groupCrit); |
| 252 | 0 | crit.addAndCriteria(orCrit); |
| 253 | 0 | crit.addEqualTo("delegationType", DelegationType.PRIMARY.getCode()); |
| 254 | 0 | filter.setDelegationType(DelegationType.PRIMARY.getCode()); |
| 255 | 0 | filter.setExcludeDelegationType(false); |
| 256 | 0 | addToFilterDescription(filteredByItems, "Primary Delegator Id"); |
| 257 | 0 | addedDelegationCriteria = true; |
| 258 | 0 | filterOn = true; |
| 259 | |
} |
| 260 | |
} |
| 261 | 0 | if (!addedDelegationCriteria && ( (StringUtils.isNotBlank(filter.getDelegationType()) && DelegationType.SECONDARY.getCode().equals(filter.getDelegationType())) |
| 262 | |
|| StringUtils.isNotBlank(filter.getDelegatorId()) )) { |
| 263 | |
|
| 264 | 0 | crit.addEqualTo("principalId", principalId); |
| 265 | 0 | if (StringUtils.isBlank(filter.getDelegatorId())) { |
| 266 | 0 | filter.setDelegationType(DelegationType.SECONDARY.getCode()); |
| 267 | |
|
| 268 | 0 | if (!filter.isExcludeDelegationType()) { |
| 269 | 0 | crit.addEqualTo("delegationType", DelegationType.SECONDARY.getCode()); |
| 270 | 0 | addToFilterDescription(filteredByItems, "Secondary Delegator Id"); |
| 271 | 0 | addedDelegationCriteria = true; |
| 272 | 0 | filterOn = true; |
| 273 | |
} |
| 274 | 0 | } else if (filter.getDelegatorId().trim().equals(KewApiConstants.ALL_CODE)) { |
| 275 | |
|
| 276 | 0 | crit.addEqualTo("delegationType", DelegationType.SECONDARY.getCode()); |
| 277 | 0 | filter.setDelegationType(DelegationType.SECONDARY.getCode()); |
| 278 | 0 | filter.setExcludeDelegationType(false); |
| 279 | 0 | addToFilterDescription(filteredByItems, "Secondary Delegator Id"); |
| 280 | 0 | addedDelegationCriteria = true; |
| 281 | 0 | filterOn = true; |
| 282 | 0 | } else if (!filter.getDelegatorId().trim().equals( |
| 283 | |
KewApiConstants.DELEGATION_DEFAULT)) { |
| 284 | |
|
| 285 | 0 | filter.setDelegationType(DelegationType.SECONDARY.getCode()); |
| 286 | 0 | filter.setExcludeDelegationType(false); |
| 287 | 0 | Criteria userCrit = new Criteria(); |
| 288 | 0 | Criteria groupCrit = new Criteria(); |
| 289 | 0 | if (filter.isExcludeDelegatorId()) { |
| 290 | 0 | Criteria userNull = new Criteria(); |
| 291 | 0 | userCrit.addNotEqualTo("delegatorPrincipalId", filter.getDelegatorId()); |
| 292 | 0 | userNull.addIsNull("delegatorPrincipalId"); |
| 293 | 0 | userCrit.addOrCriteria(userNull); |
| 294 | 0 | Criteria groupNull = new Criteria(); |
| 295 | 0 | groupCrit.addNotEqualTo("delegatorGroupId", filter.getDelegatorId()); |
| 296 | 0 | groupNull.addIsNull("delegatorGroupId"); |
| 297 | 0 | groupCrit.addOrCriteria(groupNull); |
| 298 | 0 | crit.addAndCriteria(userCrit); |
| 299 | 0 | crit.addAndCriteria(groupCrit); |
| 300 | 0 | } else { |
| 301 | 0 | Criteria orCrit = new Criteria(); |
| 302 | 0 | userCrit.addEqualTo("delegatorPrincipalId", filter.getDelegatorId()); |
| 303 | 0 | groupCrit.addEqualTo("delegatorGroupId", filter.getDelegatorId()); |
| 304 | 0 | orCrit.addOrCriteria(userCrit); |
| 305 | 0 | orCrit.addOrCriteria(groupCrit); |
| 306 | 0 | crit.addAndCriteria(orCrit); |
| 307 | |
} |
| 308 | 0 | addToFilterDescription(filteredByItems, "Secondary Delegator Id"); |
| 309 | 0 | addedDelegationCriteria = true; |
| 310 | 0 | filterOn = true; |
| 311 | |
} |
| 312 | |
|
| 313 | |
|
| 314 | |
|
| 315 | |
|
| 316 | |
|
| 317 | |
|
| 318 | |
|
| 319 | |
|
| 320 | |
|
| 321 | |
|
| 322 | |
|
| 323 | |
|
| 324 | |
|
| 325 | |
|
| 326 | |
|
| 327 | |
|
| 328 | |
|
| 329 | |
|
| 330 | |
|
| 331 | |
|
| 332 | |
|
| 333 | |
|
| 334 | |
|
| 335 | |
|
| 336 | |
|
| 337 | |
|
| 338 | |
|
| 339 | |
|
| 340 | |
|
| 341 | |
|
| 342 | |
|
| 343 | |
|
| 344 | |
|
| 345 | |
|
| 346 | |
|
| 347 | |
|
| 348 | |
|
| 349 | |
} |
| 350 | |
|
| 351 | |
|
| 352 | 0 | if (!addedDelegationCriteria) { |
| 353 | 0 | crit.addEqualTo("principalId", principalId); |
| 354 | 0 | filter.setDelegationType(DelegationType.SECONDARY.getCode()); |
| 355 | 0 | filter.setExcludeDelegationType(true); |
| 356 | 0 | Criteria critNotEqual = new Criteria(); |
| 357 | 0 | Criteria critNull = new Criteria(); |
| 358 | 0 | critNotEqual.addNotEqualTo("delegationType", DelegationType.SECONDARY.getCode()); |
| 359 | 0 | critNull.addIsNull("delegationType"); |
| 360 | 0 | critNotEqual.addOrCriteria(critNull); |
| 361 | 0 | crit.addAndCriteria(critNotEqual); |
| 362 | |
} |
| 363 | |
|
| 364 | |
|
| 365 | |
|
| 366 | |
|
| 367 | |
|
| 368 | |
|
| 369 | |
|
| 370 | |
|
| 371 | |
|
| 372 | |
|
| 373 | |
|
| 374 | |
|
| 375 | |
|
| 376 | |
|
| 377 | |
|
| 378 | |
|
| 379 | |
|
| 380 | |
|
| 381 | |
|
| 382 | |
|
| 383 | |
|
| 384 | |
|
| 385 | |
|
| 386 | |
|
| 387 | |
|
| 388 | |
|
| 389 | |
|
| 390 | |
|
| 391 | |
|
| 392 | |
|
| 393 | |
|
| 394 | |
|
| 395 | |
|
| 396 | |
|
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
|
| 401 | |
|
| 402 | |
|
| 403 | |
|
| 404 | |
|
| 405 | |
|
| 406 | |
|
| 407 | |
|
| 408 | |
|
| 409 | |
|
| 410 | |
|
| 411 | |
|
| 412 | |
|
| 413 | |
|
| 414 | |
|
| 415 | |
|
| 416 | |
|
| 417 | |
|
| 418 | |
|
| 419 | |
|
| 420 | |
|
| 421 | |
|
| 422 | |
|
| 423 | |
|
| 424 | |
|
| 425 | |
|
| 426 | |
|
| 427 | |
|
| 428 | |
|
| 429 | |
|
| 430 | |
|
| 431 | |
|
| 432 | |
|
| 433 | |
|
| 434 | |
|
| 435 | |
|
| 436 | |
|
| 437 | |
|
| 438 | |
|
| 439 | |
|
| 440 | |
|
| 441 | |
|
| 442 | |
|
| 443 | |
|
| 444 | |
|
| 445 | |
|
| 446 | |
|
| 447 | |
|
| 448 | |
|
| 449 | |
|
| 450 | |
|
| 451 | |
|
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
|
| 456 | |
|
| 457 | |
|
| 458 | |
|
| 459 | |
|
| 460 | |
|
| 461 | |
|
| 462 | |
|
| 463 | |
|
| 464 | |
|
| 465 | |
|
| 466 | |
|
| 467 | |
|
| 468 | |
|
| 469 | |
|
| 470 | |
|
| 471 | |
|
| 472 | |
|
| 473 | |
|
| 474 | |
|
| 475 | |
|
| 476 | |
|
| 477 | |
|
| 478 | |
|
| 479 | |
|
| 480 | |
|
| 481 | |
|
| 482 | |
|
| 483 | |
|
| 484 | |
|
| 485 | |
|
| 486 | |
|
| 487 | |
|
| 488 | |
|
| 489 | |
|
| 490 | |
|
| 491 | |
|
| 492 | |
|
| 493 | |
|
| 494 | |
|
| 495 | |
|
| 496 | |
|
| 497 | |
|
| 498 | |
|
| 499 | |
|
| 500 | |
|
| 501 | |
|
| 502 | |
|
| 503 | |
|
| 504 | |
|
| 505 | |
|
| 506 | |
|
| 507 | |
|
| 508 | |
|
| 509 | |
|
| 510 | |
|
| 511 | |
|
| 512 | |
|
| 513 | |
|
| 514 | |
|
| 515 | |
|
| 516 | |
|
| 517 | |
|
| 518 | |
|
| 519 | |
|
| 520 | |
|
| 521 | |
|
| 522 | |
|
| 523 | |
|
| 524 | |
|
| 525 | |
|
| 526 | 0 | if (! "".equals(filteredByItems)) { |
| 527 | 0 | filteredByItems = "Filtered by " + filteredByItems; |
| 528 | |
} |
| 529 | 0 | filter.setFilterLegend(filteredByItems); |
| 530 | 0 | filter.setFilterOn(filterOn); |
| 531 | |
|
| 532 | 0 | LOG.debug("returning from Action List criteria"); |
| 533 | 0 | return crit; |
| 534 | |
} |
| 535 | |
|
| 536 | |
private void constructDocumentTypeCriteria(Criteria criteria, DocumentType documentType) { |
| 537 | |
|
| 538 | 0 | Criteria docTypeBaseCrit = new Criteria(); |
| 539 | 0 | docTypeBaseCrit.addEqualTo("docName", documentType.getName()); |
| 540 | 0 | criteria.addOrCriteria(docTypeBaseCrit); |
| 541 | 0 | Collection children = documentType.getChildrenDocTypes(); |
| 542 | 0 | if (children != null) { |
| 543 | 0 | for (Iterator iterator = children.iterator(); iterator.hasNext();) { |
| 544 | 0 | DocumentType childDocumentType = (DocumentType) iterator.next(); |
| 545 | 0 | constructDocumentTypeCriteria(criteria, childDocumentType); |
| 546 | 0 | } |
| 547 | |
} |
| 548 | 0 | } |
| 549 | |
|
| 550 | |
private void addToFilterDescription(String filterDescription, String labelToAdd) { |
| 551 | 0 | filterDescription += filterDescription.length() > 0 ? ", " : ""; |
| 552 | 0 | filterDescription += labelToAdd; |
| 553 | 0 | } |
| 554 | |
|
| 555 | |
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')"; |
| 556 | |
|
| 557 | |
public int getCount(final String workflowId) { |
| 558 | 0 | return (Integer)getPersistenceBrokerTemplate().execute(new PersistenceBrokerCallback() { |
| 559 | |
public Object doInPersistenceBroker(PersistenceBroker broker) { |
| 560 | 0 | PreparedStatement statement = null; |
| 561 | 0 | ResultSet resultSet = null; |
| 562 | |
try { |
| 563 | 0 | Connection connection = broker.serviceConnectionManager().getConnection(); |
| 564 | 0 | statement = connection.prepareStatement(ACTION_LIST_COUNT_QUERY); |
| 565 | 0 | statement.setString(1, workflowId); |
| 566 | 0 | resultSet = statement.executeQuery(); |
| 567 | 0 | if (!resultSet.next()) { |
| 568 | 0 | throw new WorkflowRuntimeException("Error determining Action List Count."); |
| 569 | |
} |
| 570 | 0 | return resultSet.getInt(1); |
| 571 | 0 | } catch (SQLException e) { |
| 572 | 0 | throw new WorkflowRuntimeException("Error determining Action List Count.", e); |
| 573 | 0 | } catch (LookupException e) { |
| 574 | 0 | throw new WorkflowRuntimeException("Error determining Action List Count.", e); |
| 575 | |
} finally { |
| 576 | 0 | if (statement != null) { |
| 577 | |
try { |
| 578 | 0 | statement.close(); |
| 579 | 0 | } catch (SQLException e) {} |
| 580 | |
} |
| 581 | 0 | if (resultSet != null) { |
| 582 | |
try { |
| 583 | 0 | resultSet.close(); |
| 584 | 0 | } catch (SQLException e) {} |
| 585 | |
} |
| 586 | |
} |
| 587 | |
} |
| 588 | |
}); |
| 589 | |
} |
| 590 | |
|
| 591 | |
|
| 592 | |
|
| 593 | |
|
| 594 | |
|
| 595 | |
|
| 596 | |
|
| 597 | |
|
| 598 | |
private Collection<ActionItem> createActionListForUser(Collection<ActionItem> actionItems) { |
| 599 | 0 | Map<String, ActionItem> actionItemMap = new HashMap<String, ActionItem>(); |
| 600 | 0 | ActionListPriorityComparator comparator = new ActionListPriorityComparator(); |
| 601 | 0 | for (ActionItem potentialActionItem: actionItems) { |
| 602 | 0 | ActionItem existingActionItem = actionItemMap.get(potentialActionItem.getDocumentId()); |
| 603 | 0 | if (existingActionItem == null || comparator.compare(potentialActionItem, existingActionItem) > 0) { |
| 604 | 0 | actionItemMap.put(potentialActionItem.getDocumentId(), potentialActionItem); |
| 605 | |
} |
| 606 | 0 | } |
| 607 | 0 | return actionItemMap.values(); |
| 608 | |
} |
| 609 | |
|
| 610 | |
|
| 611 | |
|
| 612 | |
|
| 613 | |
|
| 614 | |
|
| 615 | |
|
| 616 | |
|
| 617 | |
private Collection<ActionItem> createActionListForRouteHeader(Collection<ActionItem> actionItems) { |
| 618 | 0 | Map<String, ActionItem> actionItemMap = new HashMap<String, ActionItem>(); |
| 619 | 0 | ActionListPriorityComparator comparator = new ActionListPriorityComparator(); |
| 620 | 0 | for (ActionItem potentialActionItem: actionItems) { |
| 621 | 0 | ActionItem existingActionItem = actionItemMap.get(potentialActionItem.getPrincipalId()); |
| 622 | 0 | if (existingActionItem == null || comparator.compare(potentialActionItem, existingActionItem) > 0) { |
| 623 | 0 | actionItemMap.put(potentialActionItem.getPrincipalId(), potentialActionItem); |
| 624 | |
} |
| 625 | 0 | } |
| 626 | 0 | return actionItemMap.values(); |
| 627 | |
} |
| 628 | |
|
| 629 | |
private Collection<ActionItem> getActionItemsInActionList(Class objectsToRetrieve, String principalId, ActionListFilter filter) { |
| 630 | 0 | LOG.debug("getting action list for user " + principalId); |
| 631 | 0 | Criteria crit = null; |
| 632 | 0 | if (filter == null) { |
| 633 | 0 | crit = new Criteria(); |
| 634 | 0 | crit.addEqualTo("principalId", principalId); |
| 635 | |
} else { |
| 636 | 0 | crit = setUpActionListCriteria(principalId, filter); |
| 637 | |
} |
| 638 | 0 | LOG.debug("running query to get action list for criteria " + crit); |
| 639 | 0 | Collection<ActionItem> collection = this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(objectsToRetrieve, crit)); |
| 640 | 0 | LOG.debug("found " + collection.size() + " action items for user " + principalId); |
| 641 | 0 | return createActionListForUser(collection); |
| 642 | |
} |
| 643 | |
|
| 644 | |
public Collection<ActionItem> getOutbox(String principalId, ActionListFilter filter) { |
| 645 | 0 | return getActionItemsInActionList(OutboxItemActionListExtension.class, principalId, filter); |
| 646 | |
|
| 647 | |
|
| 648 | |
|
| 649 | |
|
| 650 | |
|
| 651 | |
|
| 652 | |
|
| 653 | |
|
| 654 | |
|
| 655 | |
|
| 656 | |
} |
| 657 | |
|
| 658 | |
|
| 659 | |
|
| 660 | |
|
| 661 | |
|
| 662 | |
|
| 663 | |
|
| 664 | |
public void removeOutboxItems(String principalId, List<String> outboxItems) { |
| 665 | 0 | Criteria crit = new Criteria(); |
| 666 | 0 | crit.addIn("id", outboxItems); |
| 667 | 0 | getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(OutboxItemActionListExtension.class, crit)); |
| 668 | 0 | } |
| 669 | |
|
| 670 | |
|
| 671 | |
|
| 672 | |
|
| 673 | |
|
| 674 | |
|
| 675 | |
public void saveOutboxItem(OutboxItemActionListExtension outboxItem) { |
| 676 | 0 | this.getPersistenceBrokerTemplate().store(outboxItem); |
| 677 | 0 | } |
| 678 | |
|
| 679 | |
|
| 680 | |
|
| 681 | |
|
| 682 | |
|
| 683 | |
|
| 684 | |
public OutboxItemActionListExtension getOutboxByDocumentId(String documentId) { |
| 685 | 0 | Criteria crit = new Criteria(); |
| 686 | 0 | crit.addEqualTo("documentId", documentId); |
| 687 | 0 | return (OutboxItemActionListExtension)getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(OutboxItemActionListExtension.class, crit)); |
| 688 | |
} |
| 689 | |
|
| 690 | |
|
| 691 | |
|
| 692 | |
|
| 693 | |
|
| 694 | |
|
| 695 | |
public OutboxItemActionListExtension getOutboxByDocumentIdUserId(String documentId, String userId) { |
| 696 | 0 | Criteria crit = new Criteria(); |
| 697 | 0 | crit.addEqualTo("documentId", documentId); |
| 698 | 0 | crit.addEqualTo("principalId", userId); |
| 699 | 0 | return (OutboxItemActionListExtension)getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(OutboxItemActionListExtension.class, crit)); |
| 700 | |
} |
| 701 | |
|
| 702 | |
private Date beginningOfDay(Date date) { |
| 703 | 0 | Calendar cal = Calendar.getInstance(); |
| 704 | 0 | cal.setTime(date); |
| 705 | 0 | cal.set(Calendar.HOUR_OF_DAY, 0); |
| 706 | 0 | cal.set(Calendar.MINUTE, 0); |
| 707 | 0 | cal.set(Calendar.SECOND, 0); |
| 708 | 0 | return cal.getTime(); |
| 709 | |
} |
| 710 | |
|
| 711 | |
private Date endOfDay(Date date) { |
| 712 | 0 | Calendar cal = Calendar.getInstance(); |
| 713 | 0 | cal.setTime(date); |
| 714 | 0 | cal.set(Calendar.HOUR_OF_DAY, 23); |
| 715 | 0 | cal.set(Calendar.MINUTE, 59); |
| 716 | 0 | cal.set(Calendar.SECOND, 59); |
| 717 | 0 | return cal.getTime(); |
| 718 | |
} |
| 719 | |
|
| 720 | |
} |