1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.service;
18
19 import java.sql.Timestamp;
20 import java.util.ArrayList;
21 import java.util.Calendar;
22 import java.util.List;
23
24 import org.kuali.rice.core.exception.RiceRuntimeException;
25 import org.kuali.rice.core.resourceloader.GlobalResourceLoader;
26 import org.kuali.rice.kew.dto.ActionRequestDTO;
27 import org.kuali.rice.kew.dto.ActionTakenDTO;
28 import org.kuali.rice.kew.dto.AdHocRevokeDTO;
29 import org.kuali.rice.kew.dto.DocumentContentDTO;
30 import org.kuali.rice.kew.dto.DocumentDetailDTO;
31 import org.kuali.rice.kew.dto.DocumentLinkDTO;
32 import org.kuali.rice.kew.dto.EmplIdDTO;
33 import org.kuali.rice.kew.dto.ModifiableDocumentContentDTO;
34 import org.kuali.rice.kew.dto.MovePointDTO;
35 import org.kuali.rice.kew.dto.NetworkIdDTO;
36 import org.kuali.rice.kew.dto.NoteDTO;
37 import org.kuali.rice.kew.dto.ReturnPointDTO;
38 import org.kuali.rice.kew.dto.RouteHeaderDTO;
39 import org.kuali.rice.kew.dto.RouteNodeInstanceDTO;
40 import org.kuali.rice.kew.dto.UserIdDTO;
41 import org.kuali.rice.kew.dto.WorkflowAttributeDefinitionDTO;
42 import org.kuali.rice.kew.dto.WorkflowAttributeValidationErrorDTO;
43 import org.kuali.rice.kew.dto.WorkflowIdDTO;
44 import org.kuali.rice.kew.exception.WorkflowException;
45 import org.kuali.rice.kew.exception.WorkflowRuntimeException;
46 import org.kuali.rice.kew.util.KEWConstants;
47 import org.kuali.rice.kim.bo.Person;
48 import org.kuali.rice.kim.bo.entity.KimPrincipal;
49 import org.kuali.rice.kim.service.IdentityManagementService;
50 import org.kuali.rice.kim.service.PersonService;
51 import org.kuali.rice.kim.util.KimConstants;
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 public class WorkflowDocument implements java.io.Serializable {
72
73 private static final long serialVersionUID = -3672966990721719088L;
74
75
76
77
78 private String principalId;
79
80
81
82 private RouteHeaderDTO routeHeader;
83
84
85
86
87
88
89 private boolean documentContentDirty = false;
90
91
92
93 private ModifiableDocumentContentDTO documentContent;
94
95
96
97
98 public WorkflowDocument(UserIdDTO userId, String documentType) throws WorkflowException {
99 String principalId = convertUserIdToPrincipalId(userId);
100 init(principalId, documentType, null);
101 }
102
103
104
105
106 public WorkflowDocument(UserIdDTO userId, Long routeHeaderId) throws WorkflowException {
107 String principalId = convertUserIdToPrincipalId(userId);
108 init(principalId, null, routeHeaderId);
109 }
110
111 private String convertUserIdToPrincipalId(UserIdDTO userId) {
112
113 if (userId == null) {
114 return null;
115 } else if (userId instanceof WorkflowIdDTO) {
116 return ((WorkflowIdDTO)userId).getWorkflowId();
117 } else if (userId instanceof NetworkIdDTO) {
118 IdentityManagementService identityManagementService = (IdentityManagementService)GlobalResourceLoader.getService(KimConstants.KIM_IDENTITY_MANAGEMENT_SERVICE);
119 String principalName = ((NetworkIdDTO)userId).getNetworkId();
120 KimPrincipal principal = identityManagementService.getPrincipalByPrincipalName(principalName);
121 return principal.getPrincipalId();
122 } else if (userId instanceof EmplIdDTO) {
123 PersonService personService = (PersonService)GlobalResourceLoader.getService(KimConstants.KIM_PERSON_SERVICE);
124 String employeeId = ((EmplIdDTO)userId).getEmplId();
125 Person person = personService.getPersonByEmployeeId(employeeId);
126 if (person == null) {
127 throw new RiceRuntimeException("Could not locate a person with the given employee id of " + employeeId);
128 }
129 return person.getPrincipalId();
130 }
131 throw new IllegalArgumentException("Invalid UserIdDTO type was passed: " + userId);
132 }
133
134
135
136
137
138
139
140
141
142 public WorkflowDocument(String principalId, String documentType) throws WorkflowException {
143 init(principalId, documentType, null);
144 }
145
146
147
148
149
150
151
152
153 public WorkflowDocument(String principalId, Long routeHeaderId) throws WorkflowException {
154 init(principalId, null, routeHeaderId);
155 }
156
157
158
159
160
161
162
163
164
165 private void init(String principalId, String documentType, Long routeHeaderId) throws WorkflowException {
166 this.principalId = principalId;
167 routeHeader = new RouteHeaderDTO();
168 routeHeader.setDocTypeName(documentType);
169 if (routeHeaderId != null) {
170 routeHeader = getWorkflowUtility().getRouteHeaderWithPrincipal(principalId, routeHeaderId);
171 }
172 }
173
174
175
176
177 private WorkflowUtility getWorkflowUtility() throws WorkflowException {
178 WorkflowUtility workflowUtility =
179 (WorkflowUtility)GlobalResourceLoader.getService(KEWConstants.WORKFLOW_UTILITY_SERVICE);
180 if (workflowUtility == null) {
181 throw new WorkflowException("Could not locate the WorkflowUtility service. Please ensure that KEW client is configured properly!");
182 }
183 return workflowUtility;
184
185 }
186
187
188
189
190 private WorkflowDocumentActions getWorkflowDocumentActions() throws WorkflowException {
191 WorkflowDocumentActions workflowDocumentActions =
192 (WorkflowDocumentActions)GlobalResourceLoader.getService(KEWConstants.WORKFLOW_DOCUMENT_ACTIONS_SERVICE);
193 if (workflowDocumentActions == null) {
194 throw new WorkflowException("Could not locate the WorkflowDocumentActions service. Please ensure that KEW client is configured properly!");
195 }
196 return workflowDocumentActions;
197 }
198
199
200
201
202
203
204
205
206
207 public DocumentContentDTO getDocumentContent() {
208 try {
209
210 if (getRouteHeader().getRouteHeaderId() == null) {
211 routeHeader = getWorkflowDocumentActions().createDocument(principalId, getRouteHeader());
212 }
213 if (documentContent == null || documentContentDirty) {
214 documentContent = new ModifiableDocumentContentDTO(getWorkflowUtility().getDocumentContent(routeHeader.getRouteHeaderId()));
215 documentContentDirty = false;
216 }
217 } catch (Exception e) {
218 throw handleExceptionAsRuntime(e);
219 }
220 return documentContent;
221 }
222
223
224
225
226
227
228
229
230
231
232 public String getApplicationContent() {
233 return getDocumentContent().getApplicationContent();
234 }
235
236
237
238
239
240 public void setApplicationContent(String applicationContent) {
241 getDocumentContent().setApplicationContent(applicationContent);
242 }
243
244
245
246
247
248
249
250
251
252
253
254 public void clearAttributeContent() {
255 getDocumentContent().setAttributeContent("");
256 }
257
258
259
260
261
262
263 public String getAttributeContent() {
264 return getDocumentContent().getAttributeContent();
265 }
266
267
268
269
270
271
272
273
274
275
276
277 public void addAttributeDefinition(WorkflowAttributeDefinitionDTO attributeDefinition) {
278 getDocumentContent().addAttributeDefinition(attributeDefinition);
279 }
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294 public WorkflowAttributeValidationErrorDTO[] validateAttributeDefinition(WorkflowAttributeDefinitionDTO attributeDefinition) throws WorkflowException {
295 return getWorkflowUtility().validateWorkflowAttributeDefinitionVO(attributeDefinition);
296 }
297
298
299
300
301
302
303 public void removeAttributeDefinition(WorkflowAttributeDefinitionDTO attributeDefinition) {
304 getDocumentContent().removeAttributeDefinition(attributeDefinition);
305 }
306
307
308
309
310
311 public void clearAttributeDefinitions() {
312 getDocumentContent().setAttributeDefinitions(new WorkflowAttributeDefinitionDTO[0]);
313 }
314
315
316
317
318
319
320
321 public WorkflowAttributeDefinitionDTO[] getAttributeDefinitions() {
322 return getDocumentContent().getAttributeDefinitions();
323 }
324
325
326
327
328
329
330
331
332
333 public void addSearchableDefinition(WorkflowAttributeDefinitionDTO searchableDefinition) {
334 getDocumentContent().addSearchableDefinition(searchableDefinition);
335 }
336
337
338
339
340
341
342 public void removeSearchableDefinition(WorkflowAttributeDefinitionDTO searchableDefinition) {
343 getDocumentContent().removeSearchableDefinition(searchableDefinition);
344 }
345
346
347
348
349
350 public void clearSearchableDefinitions() {
351 getDocumentContent().setSearchableDefinitions(new WorkflowAttributeDefinitionDTO[0]);
352 }
353
354
355
356
357
358 public void clearSearchableContent() {
359 getDocumentContent().setSearchableContent("");
360 }
361
362
363
364
365
366
367
368 public WorkflowAttributeDefinitionDTO[] getSearchableDefinitions() {
369 return getDocumentContent().getSearchableDefinitions();
370 }
371
372
373
374
375
376
377
378
379 public RouteHeaderDTO getRouteHeader() {
380 return routeHeader;
381 }
382
383
384
385
386
387
388
389 public Long getRouteHeaderId() throws WorkflowException {
390 createDocumentIfNeccessary();
391 return getRouteHeader().getRouteHeaderId();
392 }
393
394
395
396
397
398
399
400
401
402
403
404
405 public ActionRequestDTO[] getActionRequests() throws WorkflowException {
406 if (getRouteHeaderId() == null) {
407 return new ActionRequestDTO[0];
408 }
409 return getWorkflowUtility().getAllActionRequests(getRouteHeaderId());
410 }
411
412
413
414
415
416
417
418
419
420
421
422
423 public ActionTakenDTO[] getActionsTaken() throws WorkflowException {
424 if (getRouteHeaderId() == null) {
425 return new ActionTakenDTO[0];
426 }
427 return getWorkflowUtility().getActionsTaken(getRouteHeaderId());
428 }
429
430
431
432
433
434 public void setAppDocId(String appDocId) {
435 routeHeader.setAppDocId(appDocId);
436 }
437
438
439
440
441
442 public String getAppDocId() {
443 return routeHeader.getAppDocId();
444 }
445
446
447
448
449
450 public Timestamp getDateCreated() {
451 if (routeHeader.getDateCreated() == null) {
452 return null;
453 }
454 return new Timestamp(routeHeader.getDateCreated().getTime().getTime());
455 }
456
457
458
459
460
461 public String getTitle() {
462 return getRouteHeader().getDocTitle();
463 }
464
465
466
467
468
469
470
471
472 public void saveDocument(String annotation) throws WorkflowException {
473 createDocumentIfNeccessary();
474 routeHeader = getWorkflowDocumentActions().saveDocument(principalId, getRouteHeader(), annotation);
475 documentContentDirty = true;
476 }
477
478
479
480
481
482
483
484
485 public void routeDocument(String annotation) throws WorkflowException {
486 createDocumentIfNeccessary();
487 routeHeader = getWorkflowDocumentActions().routeDocument(principalId, routeHeader, annotation);
488 documentContentDirty = true;
489 }
490
491
492
493
494
495
496
497
498 public void disapprove(String annotation) throws WorkflowException {
499 createDocumentIfNeccessary();
500 routeHeader = getWorkflowDocumentActions().disapproveDocument(principalId, getRouteHeader(), annotation);
501 documentContentDirty = true;
502 }
503
504
505
506
507
508
509
510
511 public void approve(String annotation) throws WorkflowException {
512 createDocumentIfNeccessary();
513 routeHeader = getWorkflowDocumentActions().approveDocument(principalId, getRouteHeader(), annotation);
514 documentContentDirty = true;
515 }
516
517
518
519
520
521
522
523
524 public void cancel(String annotation) throws WorkflowException {
525 createDocumentIfNeccessary();
526 routeHeader = getWorkflowDocumentActions().cancelDocument(principalId, getRouteHeader(), annotation);
527 documentContentDirty = true;
528 }
529
530
531
532
533
534
535
536
537 public void blanketApprove(String annotation) throws WorkflowException {
538 blanketApprove(annotation, (String)null);
539 }
540
541
542
543
544
545
546
547 public void saveRoutingData() throws WorkflowException {
548 createDocumentIfNeccessary();
549 routeHeader = getWorkflowDocumentActions().saveRoutingData(principalId, getRouteHeader());
550 documentContentDirty = true;
551 }
552
553
554
555
556
557
558
559
560
561 public void updateAppDocStatus(String appDocStatus) throws WorkflowException {
562 getRouteHeader().setAppDocStatus(appDocStatus);
563 saveRoutingData();
564 }
565
566
567
568
569
570
571
572
573 public void acknowledge(String annotation) throws WorkflowException {
574 createDocumentIfNeccessary();
575 routeHeader = getWorkflowDocumentActions().acknowledgeDocument(principalId, getRouteHeader(), annotation);
576 documentContentDirty = true;
577 }
578
579
580
581
582
583
584
585 public void fyi() throws WorkflowException {
586 createDocumentIfNeccessary();
587 routeHeader = getWorkflowDocumentActions().clearFYIDocument(principalId, getRouteHeader());
588 documentContentDirty = true;
589 }
590
591
592
593
594
595
596
597
598 public void delete() throws WorkflowException {
599 createDocumentIfNeccessary();
600 getWorkflowDocumentActions().deleteDocument(principalId, getRouteHeader());
601 documentContentDirty = true;
602 }
603
604
605
606
607
608
609 public void refreshContent() throws WorkflowException {
610 createDocumentIfNeccessary();
611 routeHeader = getWorkflowUtility().getRouteHeader(getRouteHeaderId());
612 documentContentDirty = true;
613 }
614
615
616
617
618
619 public void adHocRouteDocumentToPrincipal(String actionRequested, String annotation, String principalId, String responsibilityDesc, boolean forceAction) throws WorkflowException {
620 adHocRouteDocumentToPrincipal(actionRequested, null, annotation, principalId, responsibilityDesc, forceAction);
621 }
622
623
624
625
626
627 public void adHocRouteDocumentToPrincipal(String actionRequested, String nodeName, String annotation, String principalId, String responsibilityDesc, boolean forceAction) throws WorkflowException {
628 adHocRouteDocumentToPrincipal(actionRequested, nodeName, annotation, principalId, responsibilityDesc, forceAction, null);
629 }
630
631
632
633
634
635 public void adHocRouteDocumentToPrincipal(String actionRequested, String nodeName, String annotation, String principalId, String responsibilityDesc, boolean forceAction, String requestLabel) throws WorkflowException {
636 createDocumentIfNeccessary();
637 routeHeader = getWorkflowDocumentActions().adHocRouteDocumentToPrincipal(principalId, getRouteHeader(), actionRequested, nodeName, annotation, principalId, responsibilityDesc, forceAction, requestLabel);
638 documentContentDirty = true;
639 }
640
641
642
643
644
645 public void adHocRouteDocumentToGroup(String actionRequested, String annotation, String groupId, String responsibilityDesc, boolean forceAction) throws WorkflowException {
646 adHocRouteDocumentToGroup(actionRequested, null, annotation, groupId, responsibilityDesc, forceAction);
647 }
648
649
650
651
652
653 public void adHocRouteDocumentToGroup(String actionRequested, String nodeName, String annotation, String groupId, String responsibilityDesc, boolean forceAction) throws WorkflowException {
654 adHocRouteDocumentToGroup(actionRequested, nodeName, annotation, groupId, responsibilityDesc, forceAction, null);
655 }
656
657
658
659
660
661 public void adHocRouteDocumentToGroup(String actionRequested, String nodeName, String annotation, String groupId, String responsibilityDesc, boolean forceAction, String requestLabel) throws WorkflowException {
662 createDocumentIfNeccessary();
663 routeHeader = getWorkflowDocumentActions().adHocRouteDocumentToGroup(principalId, getRouteHeader(), actionRequested, nodeName, annotation, groupId, responsibilityDesc, forceAction, requestLabel);
664 documentContentDirty = true;
665 }
666
667
668
669
670
671
672
673
674
675
676
677 public void revokeAdHocRequests(AdHocRevokeDTO revoke, String annotation) throws WorkflowException {
678 if (getRouteHeader().getRouteHeaderId() == null) {
679 throw new WorkflowException("Can't revoke request, the workflow document has not yet been created!");
680 }
681 createDocumentIfNeccessary();
682 routeHeader = getWorkflowDocumentActions().revokeAdHocRequests(principalId, getRouteHeader(), revoke, annotation);
683 documentContentDirty = true;
684 }
685
686
687
688
689
690
691 public void setTitle(String title) throws WorkflowException {
692 if (title == null) {
693 title = "";
694 }
695 if (title.length() > KEWConstants.TITLE_MAX_LENGTH) {
696 title = title.substring(0, KEWConstants.TITLE_MAX_LENGTH);
697 }
698 getRouteHeader().setDocTitle(title);
699 }
700
701
702
703
704
705
706
707 public String getDocumentType() {
708 if (getRouteHeader() == null) {
709
710
711 throw new RuntimeException("No such document!");
712 }
713 return getRouteHeader().getDocTypeName();
714 }
715
716
717
718
719
720
721
722 public boolean isAcknowledgeRequested() {
723 return getRouteHeader().isAckRequested();
724 }
725
726
727
728
729
730
731
732 public boolean isApprovalRequested() {
733 return getRouteHeader().isApproveRequested();
734 }
735
736
737
738
739
740
741
742 public boolean isCompletionRequested() {
743 return getRouteHeader().isCompleteRequested();
744 }
745
746
747
748
749
750
751
752 public boolean isFYIRequested() {
753 return getRouteHeader().isFyiRequested();
754 }
755
756
757
758
759
760
761 public boolean isBlanketApproveCapable() {
762
763 return getRouteHeader().getValidActions().contains(KEWConstants.ACTION_TAKEN_BLANKET_APPROVE_CD) && (isCompletionRequested() || isApprovalRequested() || stateIsInitiated());
764 }
765
766
767
768
769
770
771 public boolean isActionCodeValidForDocument(String actionTakenCode) {
772 return getRouteHeader().getValidActions().contains(actionTakenCode);
773 }
774
775
776
777
778
779
780
781
782 public void superUserApprove(String annotation) throws WorkflowException {
783 createDocumentIfNeccessary();
784 routeHeader = getWorkflowDocumentActions().superUserApprove(principalId, getRouteHeader(), annotation);
785 documentContentDirty = true;
786 }
787
788
789
790
791
792
793
794
795
796 public void superUserActionRequestApprove(Long actionRequestId, String annotation) throws WorkflowException {
797 createDocumentIfNeccessary();
798 routeHeader = getWorkflowDocumentActions().superUserActionRequestApprove(principalId, getRouteHeader(), actionRequestId, annotation);
799 documentContentDirty = true;
800 }
801
802
803
804
805
806
807
808
809 public void superUserDisapprove(String annotation) throws WorkflowException {
810 createDocumentIfNeccessary();
811 routeHeader = getWorkflowDocumentActions().superUserDisapprove(principalId, getRouteHeader(), annotation);
812 documentContentDirty = true;
813 }
814
815
816
817
818
819
820
821
822 public void superUserCancel(String annotation) throws WorkflowException {
823 createDocumentIfNeccessary();
824 routeHeader = getWorkflowDocumentActions().superUserCancel(principalId, getRouteHeader(), annotation);
825 documentContentDirty = true;
826 }
827
828
829
830
831
832
833
834 public boolean isSuperUser() throws WorkflowException {
835 createDocumentIfNeccessary();
836 return getWorkflowUtility().isSuperUserForDocumentType(principalId, getRouteHeader().getDocTypeId());
837 }
838
839
840
841
842
843
844
845 public boolean isRouteCapable() {
846 return isActionCodeValidForDocument(KEWConstants.ACTION_TAKEN_ROUTED_CD);
847 }
848
849
850
851
852
853
854
855
856 public void clearFYI() throws WorkflowException {
857 createDocumentIfNeccessary();
858 getWorkflowDocumentActions().clearFYIDocument(principalId, getRouteHeader());
859 documentContentDirty = true;
860 }
861
862
863
864
865
866
867
868
869 public void complete(String annotation) throws WorkflowException {
870 createDocumentIfNeccessary();
871 routeHeader = getWorkflowDocumentActions().completeDocument(principalId, getRouteHeader(), annotation);
872 documentContentDirty = true;
873 }
874
875
876
877
878
879
880
881
882 public void logDocumentAction(String annotation) throws WorkflowException {
883 createDocumentIfNeccessary();
884 getWorkflowDocumentActions().logDocumentAction(principalId, getRouteHeader(), annotation);
885 documentContentDirty = true;
886 }
887
888
889
890
891
892
893 public boolean stateIsInitiated() {
894 return KEWConstants.ROUTE_HEADER_INITIATED_CD.equals(getRouteHeader().getDocRouteStatus());
895 }
896
897
898
899
900
901
902 public boolean stateIsSaved() {
903 return KEWConstants.ROUTE_HEADER_SAVED_CD.equals(getRouteHeader().getDocRouteStatus());
904 }
905
906
907
908
909
910
911 public boolean stateIsEnroute() {
912 return KEWConstants.ROUTE_HEADER_ENROUTE_CD.equals(getRouteHeader().getDocRouteStatus());
913 }
914
915
916
917
918
919
920 public boolean stateIsException() {
921 return KEWConstants.ROUTE_HEADER_EXCEPTION_CD.equals(getRouteHeader().getDocRouteStatus());
922 }
923
924
925
926
927
928
929 public boolean stateIsCanceled() {
930 return KEWConstants.ROUTE_HEADER_CANCEL_CD.equals(getRouteHeader().getDocRouteStatus());
931 }
932
933
934
935
936
937
938 public boolean stateIsDisapproved() {
939 return KEWConstants.ROUTE_HEADER_DISAPPROVED_CD.equals(getRouteHeader().getDocRouteStatus());
940 }
941
942
943
944
945
946
947 public boolean stateIsApproved() {
948 return KEWConstants.ROUTE_HEADER_APPROVED_CD.equals(getRouteHeader().getDocRouteStatus()) || stateIsProcessed() || stateIsFinal();
949 }
950
951
952
953
954
955
956 public boolean stateIsProcessed() {
957 return KEWConstants.ROUTE_HEADER_PROCESSED_CD.equals(getRouteHeader().getDocRouteStatus());
958 }
959
960
961
962
963
964
965 public boolean stateIsFinal() {
966 return KEWConstants.ROUTE_HEADER_FINAL_CD.equals(getRouteHeader().getDocRouteStatus());
967 }
968
969
970
971
972
973 public String getStatusDisplayValue() {
974 return (String) KEWConstants.DOCUMENT_STATUSES.get(getRouteHeader().getDocRouteStatus());
975 }
976
977
978
979
980
981 public String getPrincipalId() {
982 return principalId;
983 }
984
985
986
987
988
989 public void setPrincipalId(String principalId) {
990 this.principalId = principalId;
991 }
992
993
994
995
996
997
998
999 private void createDocumentIfNeccessary() throws WorkflowException {
1000 if (getRouteHeader().getRouteHeaderId() == null) {
1001 routeHeader = getWorkflowDocumentActions().createDocument(principalId, getRouteHeader());
1002 }
1003 if (documentContent != null && documentContent.isModified()) {
1004 saveDocumentContent(documentContent);
1005 }
1006 }
1007
1008
1009
1010
1011 private RuntimeException handleExceptionAsRuntime(Exception e) {
1012 if (e instanceof RuntimeException) {
1013 return (RuntimeException)e;
1014 }
1015 return new WorkflowRuntimeException(e);
1016 }
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028 public void blanketApprove(String annotation, String nodeName) throws WorkflowException {
1029 blanketApprove(annotation, (nodeName == null ? null : new String[] { nodeName }));
1030 }
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040 public void blanketApprove(String annotation, String[] nodeNames) throws WorkflowException {
1041 createDocumentIfNeccessary();
1042 routeHeader = getWorkflowDocumentActions().blanketApprovalToNodes(principalId, getRouteHeader(), annotation, nodeNames);
1043 documentContentDirty = true;
1044 }
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054 public void takeGroupAuthority(String annotation, String groupId) throws WorkflowException {
1055 createDocumentIfNeccessary();
1056 routeHeader = getWorkflowDocumentActions().takeGroupAuthority(principalId, getRouteHeader(), groupId, annotation);
1057 documentContentDirty = true;
1058 }
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068 public void releaseGroupAuthority(String annotation, String groupId) throws WorkflowException {
1069 createDocumentIfNeccessary();
1070 routeHeader = getWorkflowDocumentActions().releaseGroupAuthority(principalId, getRouteHeader(), groupId, annotation);
1071 documentContentDirty = true;
1072 }
1073
1074
1075
1076
1077
1078
1079
1080
1081 public String[] getNodeNames() throws WorkflowException {
1082 RouteNodeInstanceDTO[] activeNodeInstances = getWorkflowUtility().getActiveNodeInstances(getRouteHeaderId());
1083 String[] nodeNames = new String[(activeNodeInstances == null ? 0 : activeNodeInstances.length)];
1084 for (int index = 0; index < activeNodeInstances.length; index++) {
1085 nodeNames[index] = activeNodeInstances[index].getName();
1086 }
1087 return nodeNames;
1088 }
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098 public void returnToPreviousNode(String annotation, String nodeName) throws WorkflowException {
1099 ReturnPointDTO returnPoint = new ReturnPointDTO(nodeName);
1100 returnToPreviousNode(annotation, returnPoint);
1101 }
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111 public void returnToPreviousNode(String annotation, ReturnPointDTO returnPoint) throws WorkflowException {
1112 createDocumentIfNeccessary();
1113 routeHeader = getWorkflowDocumentActions().returnDocumentToPreviousNode(principalId, getRouteHeader(), returnPoint, annotation);
1114 documentContentDirty = true;
1115 }
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125 public void moveDocument(MovePointDTO movePoint, String annotation) throws WorkflowException {
1126 createDocumentIfNeccessary();
1127 routeHeader = getWorkflowDocumentActions().moveDocument(principalId, getRouteHeader(), movePoint, annotation);
1128 documentContentDirty = true;
1129 }
1130
1131
1132
1133
1134
1135
1136
1137
1138 public RouteNodeInstanceDTO[] getRouteNodeInstances() throws WorkflowException {
1139 return getWorkflowUtility().getDocumentRouteNodeInstances(getRouteHeaderId());
1140 }
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150 public String[] getPreviousNodeNames() throws WorkflowException {
1151 return getWorkflowUtility().getPreviousRouteNodeNames(getRouteHeaderId());
1152 }
1153
1154
1155
1156
1157
1158
1159
1160 public DocumentDetailDTO getDetail() throws WorkflowException {
1161 return getWorkflowUtility().getDocumentDetail(getRouteHeaderId());
1162 }
1163
1164
1165
1166
1167
1168
1169
1170 public DocumentContentDTO saveDocumentContent(DocumentContentDTO documentContent) throws WorkflowException {
1171 if (documentContent.getRouteHeaderId() == null) {
1172 throw new WorkflowException("Document Content does not have a valid document ID.");
1173 }
1174
1175
1176 if (!documentContent.getRouteHeaderId().equals(getRouteHeader().getRouteHeaderId())) {
1177 throw new WorkflowException("Attempted to save content on this document with an invalid document id of " + documentContent.getRouteHeaderId());
1178 }
1179 DocumentContentDTO newDocumentContent = getWorkflowDocumentActions().saveDocumentContent(documentContent);
1180 this.documentContent = new ModifiableDocumentContentDTO(newDocumentContent);
1181 documentContentDirty = false;
1182 return this.documentContent;
1183 }
1184
1185 public void placeInExceptionRouting(String annotation) throws WorkflowException {
1186 createDocumentIfNeccessary();
1187 routeHeader = getWorkflowDocumentActions().placeInExceptionRouting(principalId, getRouteHeader(), annotation);
1188 documentContentDirty = true;
1189 }
1190
1191
1192
1193
1194
1195
1196
1197
1198 public void blanketApprove(String annotation, Integer routeLevel) throws WorkflowException {
1199 createDocumentIfNeccessary();
1200 routeHeader = getWorkflowDocumentActions().blanketApproval(principalId, getRouteHeader(), annotation, routeLevel);
1201 documentContentDirty = true;
1202 }
1203
1204
1205
1206
1207 public Integer getDocRouteLevel() {
1208 return routeHeader.getDocRouteLevel();
1209 }
1210
1211
1212
1213
1214 public void returnToPreviousRouteLevel(String annotation, Integer destRouteLevel) throws WorkflowException {
1215 createDocumentIfNeccessary();
1216 getWorkflowDocumentActions().returnDocumentToPreviousRouteLevel(principalId, getRouteHeader(), destRouteLevel, annotation);
1217 documentContentDirty = true;
1218 }
1219
1220
1221
1222
1223
1224
1225 public List<NoteDTO> getNoteList(){
1226 List<NoteDTO> notesList = new ArrayList<NoteDTO>();
1227 NoteDTO[] notes = routeHeader.getNotes();
1228 if (notes != null){
1229 for (int i=0; i<notes.length; i++){
1230 if (! isDeletedNote(notes[i])){
1231 notesList.add(notes[i]);
1232 }
1233 }
1234 }
1235 return notesList;
1236 }
1237
1238
1239
1240
1241
1242 public void deleteNote(NoteDTO noteVO){
1243 if (noteVO != null && noteVO.getNoteId()!=null){
1244 NoteDTO noteToDelete = new NoteDTO();
1245 noteToDelete.setNoteId(new Long(noteVO.getNoteId().longValue()));
1246
1247
1248
1249
1250
1251 increaseNotesToDeleteArraySizeByOne();
1252 routeHeader.getNotesToDelete()[routeHeader.getNotesToDelete().length - 1]=noteToDelete;
1253 }
1254 }
1255
1256
1257
1258
1259
1260 public void updateNote (NoteDTO noteVO){
1261 boolean isUpdateNote = false;
1262 if (noteVO != null){
1263 NoteDTO[] notes = routeHeader.getNotes();
1264 NoteDTO copyNote = new NoteDTO();
1265 if (noteVO.getNoteId() != null){
1266 copyNote.setNoteId(new Long(noteVO.getNoteId().longValue()));
1267 }
1268
1269 if (noteVO.getRouteHeaderId() != null){
1270 copyNote.setRouteHeaderId(new Long(noteVO.getRouteHeaderId().longValue()));
1271 } else {
1272 copyNote.setRouteHeaderId(routeHeader.getRouteHeaderId());
1273 }
1274
1275 if (noteVO.getNoteAuthorWorkflowId() != null){
1276 copyNote.setNoteAuthorWorkflowId(new String(noteVO.getNoteAuthorWorkflowId()));
1277 } else {
1278 copyNote.setNoteAuthorWorkflowId(principalId.toString()) ;
1279 }
1280
1281 if (noteVO.getNoteCreateDate() != null){
1282 Calendar cal = Calendar.getInstance();
1283 cal.setTimeInMillis(noteVO.getNoteCreateDate().getTimeInMillis());
1284 copyNote.setNoteCreateDate(cal);
1285 } else {
1286 copyNote.setNoteCreateDate(Calendar.getInstance());
1287 }
1288
1289 if (noteVO.getNoteText() != null){
1290 copyNote.setNoteText(new String(noteVO.getNoteText()));
1291 }
1292 if (noteVO.getLockVerNbr() != null){
1293 copyNote.setLockVerNbr(new Integer(noteVO.getLockVerNbr().intValue()));
1294 }
1295 if (notes != null){
1296 for (int i=0; i<notes.length; i++){
1297 if (notes[i].getNoteId()!= null && notes[i].getNoteId().equals(copyNote.getNoteId())){
1298 notes[i] = copyNote;
1299 isUpdateNote = true;
1300 break;
1301 }
1302 }
1303 }
1304
1305 if (! isUpdateNote){
1306 copyNote.setNoteId(null);
1307 increaseNotesArraySizeByOne();
1308 routeHeader.getNotes()[routeHeader.getNotes().length-1]= copyNote;
1309 }
1310 }
1311 }
1312
1313
1314
1315
1316
1317
1318 public void setVariable(String name, String value) throws WorkflowException {
1319 createDocumentIfNeccessary();
1320 getRouteHeader().setVariable(name, value);
1321 }
1322
1323
1324
1325
1326
1327
1328 public String getVariable(String name) throws WorkflowException {
1329 createDocumentIfNeccessary();
1330 return getRouteHeader().getVariable(name);
1331 }
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341 public void setReceiveFutureRequests() throws WorkflowException {
1342 WorkflowUtility workflowUtility = getWorkflowUtility();
1343 this.setVariable(workflowUtility.getFutureRequestsKey(principalId), workflowUtility.getReceiveFutureRequestsValue());
1344 }
1345
1346
1347
1348
1349
1350
1351
1352
1353 public void setDoNotReceiveFutureRequests() throws WorkflowException {
1354 WorkflowUtility workflowUtility = getWorkflowUtility();
1355 this.setVariable(workflowUtility.getFutureRequestsKey(principalId), workflowUtility.getDoNotReceiveFutureRequestsValue());
1356 }
1357
1358
1359
1360
1361
1362
1363
1364 public void setClearFutureRequests() throws WorkflowException {
1365 WorkflowUtility workflowUtility = getWorkflowUtility();
1366 this.setVariable(workflowUtility.getFutureRequestsKey(principalId), workflowUtility.getClearFutureRequestsValue());
1367 }
1368
1369
1370
1371
1372
1373
1374 private boolean isDeletedNote(NoteDTO noteVO) {
1375 NoteDTO[] notesToDelete = routeHeader.getNotesToDelete();
1376 if (notesToDelete != null){
1377 for (int i=0; i<notesToDelete.length; i++){
1378 if (notesToDelete[i].getNoteId().equals(noteVO.getNoteId())){
1379 return true;
1380 }
1381 }
1382 }
1383 return false;
1384 }
1385
1386
1387
1388
1389 private void increaseNotesArraySizeByOne() {
1390 NoteDTO[] tempArray;
1391 NoteDTO[] notes = routeHeader.getNotes();
1392 if (notes == null){
1393 tempArray = new NoteDTO[1];
1394 } else {
1395 tempArray = new NoteDTO[notes.length + 1];
1396 for (int i=0; i<notes.length; i++){
1397 tempArray[i] = notes[i];
1398 }
1399 }
1400 routeHeader.setNotes(tempArray);
1401 }
1402
1403
1404
1405
1406 private void increaseNotesToDeleteArraySizeByOne() {
1407 NoteDTO[] tempArray;
1408 NoteDTO[] notesToDelete = routeHeader.getNotesToDelete();
1409 if (notesToDelete == null){
1410 tempArray = new NoteDTO[1];
1411 } else {
1412 tempArray = new NoteDTO[notesToDelete.length + 1];
1413 for (int i=0; i<notesToDelete.length; i++){
1414 tempArray[i] = notesToDelete[i];
1415 }
1416 }
1417 routeHeader.setNotesToDelete(tempArray);
1418 }
1419
1420
1421 public void addLinkedDocument(DocumentLinkDTO docLinkVO) throws WorkflowException{
1422 try{
1423 if(DocumentLinkDTO.checkDocLink(docLinkVO))
1424 getWorkflowUtility().addDocumentLink(docLinkVO);
1425 }
1426 catch(Exception e){
1427 throw handleExceptionAsRuntime(e);
1428 }
1429 }
1430
1431
1432 public DocumentLinkDTO getLinkedDocument(DocumentLinkDTO docLinkVO) throws WorkflowException{
1433 try{
1434 if(DocumentLinkDTO.checkDocLink(docLinkVO))
1435 return getWorkflowUtility().getLinkedDocument(docLinkVO);
1436 else
1437 return null;
1438 }
1439 catch(Exception e){
1440 throw handleExceptionAsRuntime(e);
1441 }
1442 }
1443
1444
1445 public List<DocumentLinkDTO> getLinkedDocumentsByDocId(Long id) throws WorkflowException{
1446 if(id == null)
1447 throw new WorkflowException("doc id is null");
1448 try{
1449 return getWorkflowUtility().getLinkedDocumentsByDocId(id);
1450 }
1451 catch (Exception e) {
1452 throw handleExceptionAsRuntime(e);
1453 }
1454 }
1455
1456
1457 public void removeLinkedDocuments(Long docId) throws WorkflowException{
1458
1459 if(docId == null)
1460 throw new WorkflowException("doc id is null");
1461
1462 try{
1463 getWorkflowUtility().deleteDocumentLinksByDocId(docId);
1464 }
1465 catch (Exception e) {
1466 throw handleExceptionAsRuntime(e);
1467 }
1468 }
1469
1470
1471 public void removeLinkedDocument(DocumentLinkDTO docLinkVO) throws WorkflowException{
1472
1473 try{
1474 if(DocumentLinkDTO.checkDocLink(docLinkVO))
1475 getWorkflowUtility().deleteDocumentLink(docLinkVO);
1476 }
1477 catch(Exception e){
1478 throw handleExceptionAsRuntime(e);
1479 }
1480 }
1481
1482 }