1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.workflow.service.impl; |
17 | |
|
18 | |
import java.io.Serializable; |
19 | |
import java.sql.Timestamp; |
20 | |
import java.util.ArrayList; |
21 | |
import java.util.HashSet; |
22 | |
import java.util.Iterator; |
23 | |
import java.util.Set; |
24 | |
|
25 | |
import org.apache.commons.lang.StringUtils; |
26 | |
import org.kuali.rice.kew.dto.ActionRequestDTO; |
27 | |
import org.kuali.rice.kew.dto.ActionTakenDTO; |
28 | |
import org.kuali.rice.kew.dto.ReturnPointDTO; |
29 | |
import org.kuali.rice.kew.dto.RouteHeaderDTO; |
30 | |
import org.kuali.rice.kew.dto.WorkflowAttributeDefinitionDTO; |
31 | |
import org.kuali.rice.kew.exception.InvalidActionTakenException; |
32 | |
import org.kuali.rice.kew.exception.ResourceUnavailableException; |
33 | |
import org.kuali.rice.kew.exception.WorkflowException; |
34 | |
import org.kuali.rice.kew.service.WorkflowDocument; |
35 | |
import org.kuali.rice.kew.service.WorkflowDocumentActions; |
36 | |
import org.kuali.rice.kew.util.KEWConstants; |
37 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
38 | |
import org.kuali.rice.kim.bo.Person; |
39 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
40 | |
import org.kuali.rice.kns.workflow.service.KualiWorkflowDocument; |
41 | |
import org.kuali.rice.kns.workflow.service.KualiWorkflowInfo; |
42 | |
|
43 | |
public class KualiWorkflowDocumentImpl implements KualiWorkflowDocument, Serializable { |
44 | |
|
45 | |
private WorkflowDocument workflowDocument; |
46 | |
|
47 | |
public static KualiWorkflowDocumentImpl createKualiDocumentImpl(String principalId, String documentType) throws WorkflowException { |
48 | 0 | return new KualiWorkflowDocumentImpl(principalId, documentType, null); |
49 | |
} |
50 | |
|
51 | |
public static KualiWorkflowDocumentImpl LoadKualiDocumentImpl(String principalId, String documentId) throws WorkflowException { |
52 | 0 | return new KualiWorkflowDocumentImpl(principalId, null, documentId); |
53 | |
} |
54 | |
|
55 | 0 | private KualiWorkflowDocumentImpl(String principalId, String documentType, String documentId) throws WorkflowException { |
56 | 0 | if (StringUtils.isNotBlank(documentType)) { |
57 | 0 | workflowDocument = WorkflowDocument.createDocument(principalId, documentType); |
58 | 0 | } else if (StringUtils.isNotBlank(documentId)) { |
59 | 0 | workflowDocument = WorkflowDocument.loadDocument(principalId, documentId); |
60 | |
} |
61 | 0 | } |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
public String getApplicationContent() { |
74 | 0 | return workflowDocument.getApplicationContent(); |
75 | |
} |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
public void setApplicationContent(String applicationContent) { |
81 | 0 | workflowDocument.setApplicationContent(applicationContent); |
82 | 0 | } |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
public void clearAttributeContent() { |
92 | 0 | workflowDocument.clearAttributeContent(); |
93 | 0 | } |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
public String getAttributeContent() { |
99 | 0 | return workflowDocument.getAttributeContent(); |
100 | |
} |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
public void addAttributeDefinition(WorkflowAttributeDefinitionDTO attributeDefinition) { |
109 | 0 | workflowDocument.addAttributeDefinition(attributeDefinition); |
110 | 0 | } |
111 | |
|
112 | |
public void removeAttributeDefinition(WorkflowAttributeDefinitionDTO attributeDefinition) { |
113 | 0 | workflowDocument.removeAttributeDefinition(attributeDefinition); |
114 | 0 | } |
115 | |
|
116 | |
public void clearAttributeDefinitions() { |
117 | 0 | workflowDocument.clearAttributeDefinitions(); |
118 | 0 | } |
119 | |
|
120 | |
public WorkflowAttributeDefinitionDTO[] getAttributeDefinitions() { |
121 | 0 | return workflowDocument.getAttributeDefinitions(); |
122 | |
} |
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
public void addSearchableDefinition(WorkflowAttributeDefinitionDTO searchableDefinition) { |
131 | 0 | workflowDocument.addSearchableDefinition(searchableDefinition); |
132 | 0 | } |
133 | |
|
134 | |
public void removeSearchableDefinition(WorkflowAttributeDefinitionDTO searchableDefinition) { |
135 | 0 | workflowDocument.removeSearchableDefinition(searchableDefinition); |
136 | 0 | } |
137 | |
|
138 | |
public void clearSearchableDefinitions() { |
139 | 0 | workflowDocument.clearSearchableDefinitions(); |
140 | 0 | } |
141 | |
|
142 | |
public WorkflowAttributeDefinitionDTO[] getSearchableDefinitions() { |
143 | 0 | return workflowDocument.getSearchableDefinitions(); |
144 | |
} |
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
public RouteHeaderDTO getRouteHeader() { |
151 | 0 | return workflowDocument.getRouteHeader(); |
152 | |
} |
153 | |
|
154 | |
public String getDocumentId() throws WorkflowException { |
155 | 0 | return workflowDocument.getDocumentId(); |
156 | |
} |
157 | |
|
158 | |
public void setAppDocId(String appDocId) { |
159 | 0 | workflowDocument.setAppDocId(appDocId); |
160 | 0 | } |
161 | |
|
162 | |
public String getAppDocId() { |
163 | 0 | return workflowDocument.getAppDocId(); |
164 | |
} |
165 | |
|
166 | |
public String getTitle() { |
167 | 0 | return workflowDocument.getTitle(); |
168 | |
} |
169 | |
|
170 | |
public String getInitiatorPrincipalId() { |
171 | 0 | return workflowDocument.getRouteHeader().getInitiatorPrincipalId(); |
172 | |
} |
173 | |
|
174 | |
public String getRoutedByPrincipalId() { |
175 | 0 | return workflowDocument.getRouteHeader().getRoutedByPrincipalId(); |
176 | |
} |
177 | |
|
178 | |
public void saveDocument(String annotation) throws WorkflowException { |
179 | 0 | workflowDocument.saveDocument(annotation); |
180 | 0 | } |
181 | |
|
182 | |
public void routeDocument(String annotation) throws WorkflowException { |
183 | 0 | workflowDocument.routeDocument(annotation); |
184 | 0 | } |
185 | |
|
186 | |
public void disapprove(String annotation) throws WorkflowException { |
187 | 0 | workflowDocument.disapprove(annotation); |
188 | 0 | } |
189 | |
|
190 | |
public void approve(String annotation) throws WorkflowException { |
191 | 0 | workflowDocument.approve(annotation); |
192 | 0 | } |
193 | |
|
194 | |
public void superUserApprove(String annotation) throws WorkflowException { |
195 | 0 | workflowDocument.superUserApprove(annotation); |
196 | 0 | } |
197 | |
|
198 | |
public void superUserActionRequestApprove(Long actionRequestId, String annotation) throws WorkflowException { |
199 | 0 | workflowDocument.superUserActionRequestApprove(actionRequestId, annotation); |
200 | 0 | } |
201 | |
|
202 | |
public void superUserCancel(String annotation) throws WorkflowException { |
203 | 0 | workflowDocument.superUserCancel(annotation); |
204 | 0 | } |
205 | |
|
206 | |
public void superUserDisapprove(String annotation) throws WorkflowException { |
207 | 0 | workflowDocument.superUserDisapprove(annotation); |
208 | 0 | } |
209 | |
|
210 | |
public void cancel(String annotation) throws WorkflowException { |
211 | 0 | workflowDocument.cancel(annotation); |
212 | 0 | } |
213 | |
|
214 | |
public void blanketApprove(String annotation) throws WorkflowException { |
215 | 0 | workflowDocument.blanketApprove(annotation); |
216 | 0 | } |
217 | |
|
218 | |
public void saveRoutingData() throws WorkflowException { |
219 | 0 | workflowDocument.saveRoutingData(); |
220 | 0 | } |
221 | |
|
222 | |
public void acknowledge(String annotation) throws WorkflowException { |
223 | 0 | workflowDocument.acknowledge(annotation); |
224 | 0 | } |
225 | |
|
226 | |
public void fyi() throws WorkflowException { |
227 | 0 | workflowDocument.fyi(); |
228 | 0 | } |
229 | |
|
230 | |
public void delete() throws WorkflowException { |
231 | 0 | workflowDocument.delete(); |
232 | 0 | } |
233 | |
|
234 | |
public void refreshContent() throws WorkflowException { |
235 | 0 | workflowDocument.refreshContent(); |
236 | 0 | } |
237 | |
|
238 | |
public void adHocRouteDocumentToPrincipal(String actionRequested, String routeTypeName, String annotation, String principalId, String responsibilityDesc, boolean forceAction) throws WorkflowException { |
239 | 0 | workflowDocument.adHocRouteDocumentToPrincipal(actionRequested, routeTypeName, annotation, principalId, responsibilityDesc, forceAction); |
240 | 0 | } |
241 | |
|
242 | |
public void adHocRouteDocumentToGroup(String actionRequested, String routeTypeName, String annotation, String groupId, String responsibilityDesc, boolean forceAction) throws WorkflowException { |
243 | 0 | workflowDocument.adHocRouteDocumentToGroup(actionRequested, routeTypeName, annotation, groupId, responsibilityDesc, forceAction); |
244 | 0 | } |
245 | |
|
246 | |
public void adHocRouteDocumentToPrincipal(String actionRequested, String routeTypeName, String annotation, String principalId, String responsibilityDesc, boolean forceAction, String actionRequestLabel) throws WorkflowException { |
247 | 0 | workflowDocument.adHocRouteDocumentToPrincipal(actionRequested, routeTypeName, annotation, principalId, responsibilityDesc, forceAction, actionRequestLabel); |
248 | 0 | } |
249 | |
|
250 | |
public void adHocRouteDocumentToGroup(String actionRequested, String routeTypeName, String annotation, String groupId, String responsibilityDesc, boolean forceAction, String actionRequestLabel) throws WorkflowException { |
251 | 0 | workflowDocument.adHocRouteDocumentToGroup(actionRequested, routeTypeName, annotation, groupId, responsibilityDesc, forceAction, actionRequestLabel); |
252 | 0 | } |
253 | |
|
254 | |
public void setTitle(String title) throws WorkflowException { |
255 | 0 | workflowDocument.setTitle(title); |
256 | 0 | } |
257 | |
|
258 | |
public String getDocumentType() { |
259 | 0 | return workflowDocument.getDocumentType(); |
260 | |
} |
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
public boolean isAdHocRequested() { |
266 | 0 | boolean isAdHocRequested = false; |
267 | 0 | String documentId = null; |
268 | 0 | KualiWorkflowInfo workflowInfo = null; |
269 | |
try { |
270 | 0 | documentId = getDocumentId(); |
271 | 0 | workflowInfo = KNSServiceLocatorWeb.getWorkflowInfoService(); |
272 | 0 | String principalId = workflowDocument.getPrincipalId(); |
273 | 0 | ActionRequestDTO[] actionRequests = workflowInfo.getActionRequests(documentId); |
274 | 0 | for (int actionRequestIndex = 0; actionRequestIndex < actionRequests.length; actionRequestIndex++) { |
275 | 0 | if (actionRequests[actionRequestIndex].isActivated() && actionRequests[actionRequestIndex].isAdHocRequest()) { |
276 | 0 | if (actionRequests[actionRequestIndex].isUserRequest() && principalId.equals(actionRequests[actionRequestIndex].getPrincipalId())) { |
277 | 0 | isAdHocRequested = true; |
278 | |
} |
279 | 0 | else if (actionRequests[actionRequestIndex].isGroupRequest()) { |
280 | 0 | if (KimApiServiceLocator.getIdentityManagementService().isMemberOfGroup(principalId, actionRequests[actionRequestIndex].getGroupId())) { |
281 | 0 | isAdHocRequested = true; |
282 | |
} |
283 | |
} |
284 | |
} |
285 | |
} |
286 | |
} |
287 | 0 | catch (WorkflowException e) { |
288 | 0 | throw new RuntimeException(new StringBuffer(getClass().getName()).append(" encountered an exception while attempting to get the actoins requests for documentId: ").append(documentId).toString(), e); |
289 | 0 | } |
290 | 0 | return isAdHocRequested; |
291 | |
} |
292 | |
|
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
public boolean isAcknowledgeRequested() { |
298 | 0 | return workflowDocument.isAcknowledgeRequested(); |
299 | |
} |
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | |
public boolean isApprovalRequested() { |
306 | 0 | return workflowDocument.isApprovalRequested(); |
307 | |
} |
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
public boolean isCompletionRequested() { |
314 | 0 | return workflowDocument.isCompletionRequested(); |
315 | |
} |
316 | |
|
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | |
public boolean isFYIRequested() { |
322 | 0 | return workflowDocument.isFYIRequested(); |
323 | |
} |
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
|
329 | |
public boolean isBlanketApproveCapable() { |
330 | 0 | return workflowDocument.isBlanketApproveCapable(); |
331 | |
} |
332 | |
|
333 | |
@SuppressWarnings("deprecation") |
334 | |
public Integer getDocRouteLevel() { |
335 | 0 | return workflowDocument.getDocRouteLevel(); |
336 | |
} |
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | |
|
342 | |
|
343 | |
|
344 | |
public void complete(String annotation) throws WorkflowException { |
345 | 0 | workflowDocument.complete(annotation); |
346 | 0 | } |
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
public void returnToPreviousNode(String annotation, String nodeName) throws WorkflowException { |
357 | 0 | workflowDocument.returnToPreviousNode(annotation, nodeName); |
358 | 0 | } |
359 | |
|
360 | |
|
361 | |
|
362 | |
|
363 | |
|
364 | |
|
365 | |
|
366 | |
|
367 | |
|
368 | |
public void returnToPreviousNode(String annotation, ReturnPointDTO returnPoint) throws WorkflowException { |
369 | 0 | workflowDocument.returnToPreviousNode(annotation, returnPoint); |
370 | 0 | } |
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | |
|
380 | |
@SuppressWarnings("deprecation") |
381 | |
public void returnToPreviousRouteLevel(String annotation, Integer destRouteLevel) throws WorkflowException { |
382 | 0 | workflowDocument.returnToPreviousRouteLevel(annotation, destRouteLevel); |
383 | 0 | } |
384 | |
|
385 | |
public void logDocumentAction(String annotation) throws WorkflowException { |
386 | 0 | workflowDocument.logDocumentAction(annotation); |
387 | 0 | } |
388 | |
|
389 | |
|
390 | |
|
391 | |
|
392 | |
|
393 | |
|
394 | |
public boolean stateIsInitiated() { |
395 | 0 | return workflowDocument.stateIsInitiated(); |
396 | |
} |
397 | |
|
398 | |
|
399 | |
|
400 | |
|
401 | |
|
402 | |
|
403 | |
public boolean stateIsSaved() { |
404 | 0 | return workflowDocument.stateIsSaved(); |
405 | |
} |
406 | |
|
407 | |
|
408 | |
|
409 | |
|
410 | |
|
411 | |
|
412 | |
public boolean stateIsEnroute() { |
413 | 0 | return workflowDocument.stateIsEnroute(); |
414 | |
} |
415 | |
|
416 | |
|
417 | |
|
418 | |
|
419 | |
|
420 | |
|
421 | |
public boolean stateIsFinal() { |
422 | 0 | return workflowDocument.stateIsFinal(); |
423 | |
} |
424 | |
|
425 | |
|
426 | |
|
427 | |
|
428 | |
|
429 | |
|
430 | |
public boolean stateIsException() { |
431 | 0 | return workflowDocument.stateIsException(); |
432 | |
} |
433 | |
|
434 | |
|
435 | |
|
436 | |
|
437 | |
|
438 | |
|
439 | |
public boolean stateIsCanceled() { |
440 | 0 | return workflowDocument.stateIsCanceled(); |
441 | |
} |
442 | |
|
443 | |
|
444 | |
|
445 | |
|
446 | |
|
447 | |
|
448 | |
public boolean stateIsDisapproved() { |
449 | 0 | return workflowDocument.stateIsDisapproved(); |
450 | |
} |
451 | |
|
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | |
public boolean stateIsApproved() { |
458 | 0 | return workflowDocument.stateIsApproved(); |
459 | |
} |
460 | |
|
461 | |
|
462 | |
|
463 | |
|
464 | |
|
465 | |
|
466 | |
public boolean stateIsProcessed() { |
467 | 0 | return workflowDocument.stateIsProcessed(); |
468 | |
} |
469 | |
|
470 | |
public String getStatusDisplayValue() { |
471 | 0 | return workflowDocument.getStatusDisplayValue(); |
472 | |
} |
473 | |
|
474 | |
public Timestamp getCreateDate() { |
475 | 0 | return workflowDocument.getDateCreated(); |
476 | |
} |
477 | |
|
478 | |
|
479 | |
|
480 | |
|
481 | |
|
482 | |
|
483 | |
public boolean userIsInitiator(Person user) { |
484 | 0 | if (user == null) { |
485 | 0 | throw new IllegalArgumentException("invalid (null) user"); |
486 | |
} |
487 | |
|
488 | 0 | return StringUtils.equalsIgnoreCase(getInitiatorPrincipalId(), user.getPrincipalId()); |
489 | |
} |
490 | |
|
491 | |
|
492 | |
|
493 | |
|
494 | |
|
495 | |
public boolean userIsRoutedByUser(Person user) { |
496 | 0 | if (user == null) { |
497 | 0 | throw new IllegalArgumentException("invalid (null) user"); |
498 | |
} |
499 | |
|
500 | 0 | return StringUtils.equalsIgnoreCase(getRoutedByPrincipalId(), user.getPrincipalId()); |
501 | |
} |
502 | |
|
503 | |
public String[] getNodeNames() throws WorkflowException { |
504 | 0 | return workflowDocument.getNodeNames(); |
505 | |
} |
506 | |
|
507 | |
public String getCurrentRouteNodeNames() { |
508 | 0 | return workflowDocument.getRouteHeader().getCurrentRouteNodeNames(); |
509 | |
} |
510 | |
|
511 | |
public boolean isStandardSaveAllowed() { |
512 | 0 | return workflowDocument.isActionCodeValidForDocument(KEWConstants.ACTION_TAKEN_SAVED_CD); |
513 | |
} |
514 | |
|
515 | |
public void setReceiveFutureRequests() throws WorkflowException { |
516 | 0 | workflowDocument.setReceiveFutureRequests(); |
517 | 0 | } |
518 | |
|
519 | |
public void setDoNotReceiveFutureRequests() throws WorkflowException { |
520 | 0 | workflowDocument.setDoNotReceiveFutureRequests(); |
521 | 0 | } |
522 | |
|
523 | |
public void setClearFutureRequests() throws WorkflowException { |
524 | 0 | workflowDocument.setClearFutureRequests(); |
525 | 0 | } |
526 | |
|
527 | |
|
528 | |
|
529 | |
|
530 | |
public String toString() { |
531 | 0 | ArrayList trueFlags = new ArrayList(); |
532 | 0 | if (isAcknowledgeRequested()) { |
533 | 0 | trueFlags.add("acknowledgeRequested"); |
534 | |
} |
535 | 0 | if (isApprovalRequested()) { |
536 | 0 | trueFlags.add("approvalRequested"); |
537 | |
} |
538 | 0 | if (isBlanketApproveCapable()) { |
539 | 0 | trueFlags.add("blanketApproveCapable"); |
540 | |
} |
541 | 0 | if (isCompletionRequested()) { |
542 | 0 | trueFlags.add("completionRequested"); |
543 | |
} |
544 | 0 | if (isFYIRequested()) { |
545 | 0 | trueFlags.add("FYIRequested"); |
546 | |
} |
547 | |
|
548 | 0 | if (stateIsApproved()) { |
549 | 0 | trueFlags.add("stateIsApproved"); |
550 | |
} |
551 | 0 | if (stateIsCanceled()) { |
552 | 0 | trueFlags.add("stateIsCanceled"); |
553 | |
} |
554 | 0 | if (stateIsDisapproved()) { |
555 | 0 | trueFlags.add("stateIsDisapproved"); |
556 | |
} |
557 | 0 | if (stateIsEnroute()) { |
558 | 0 | trueFlags.add("stateIsEnroute"); |
559 | |
} |
560 | 0 | if (stateIsException()) { |
561 | 0 | trueFlags.add("stateIsException"); |
562 | |
} |
563 | 0 | if (stateIsFinal()) { |
564 | 0 | trueFlags.add("stateIsFinal"); |
565 | |
} |
566 | 0 | if (stateIsInitiated()) { |
567 | 0 | trueFlags.add("stateIsInitiated"); |
568 | |
} |
569 | 0 | if (stateIsProcessed()) { |
570 | 0 | trueFlags.add("stateIsProcessed"); |
571 | |
} |
572 | 0 | if (stateIsSaved()) { |
573 | 0 | trueFlags.add("stateIsSaved"); |
574 | |
} |
575 | |
|
576 | 0 | StringBuffer b = new StringBuffer("true flags=("); |
577 | 0 | for (Iterator i = trueFlags.iterator(); i.hasNext();) { |
578 | 0 | b.append(i.next()); |
579 | 0 | if (i.hasNext()) { |
580 | 0 | b.append(","); |
581 | |
} |
582 | |
} |
583 | 0 | b.append(")"); |
584 | |
|
585 | 0 | return b.toString(); |
586 | |
} |
587 | |
|
588 | |
|
589 | |
|
590 | |
|
591 | |
public Set<Person> getAllPriorApprovers() throws WorkflowException { |
592 | 0 | org.kuali.rice.kim.service.PersonService personService = KimApiServiceLocator.getPersonService(); |
593 | 0 | ActionTakenDTO[] actionsTaken = workflowDocument.getActionsTaken(); |
594 | 0 | Set<String> principalIds = new HashSet<String>(); |
595 | 0 | Set<Person> persons = new HashSet<Person>(); |
596 | |
|
597 | 0 | for (ActionTakenDTO actionTaken : actionsTaken) { |
598 | 0 | if (KEWConstants.ACTION_TAKEN_APPROVED_CD.equals(actionTaken.getActionTaken())) { |
599 | 0 | String principalId = actionTaken.getPrincipalId(); |
600 | 0 | if (!principalIds.contains(principalId)) { |
601 | 0 | principalIds.add(principalId); |
602 | 0 | persons.add(personService.getPerson(principalId)); |
603 | |
} |
604 | |
} |
605 | |
} |
606 | 0 | return persons; |
607 | |
} |
608 | |
} |