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.rmi.RemoteException;
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.apache.log4j.Logger;
23 import org.kuali.rice.kew.dto.ActionItemDTO;
24 import org.kuali.rice.kew.dto.ActionRequestDTO;
25 import org.kuali.rice.kew.dto.ActionTakenDTO;
26 import org.kuali.rice.kew.dto.DocumentSearchCriteriaDTO;
27 import org.kuali.rice.kew.dto.DocumentSearchResultDTO;
28 import org.kuali.rice.kew.dto.DocumentTypeDTO;
29 import org.kuali.rice.kew.dto.ReportCriteriaDTO;
30 import org.kuali.rice.kew.dto.RouteHeaderDTO;
31 import org.kuali.rice.kew.exception.WorkflowException;
32 import org.kuali.rice.kew.exception.WorkflowRuntimeException;
33 import org.kuali.rice.kew.service.WorkflowInfo;
34 import org.kuali.rice.kew.util.KEWConstants;
35 import org.kuali.rice.kim.api.entity.principal.Principal;
36 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
37
38 import org.kuali.rice.kns.util.KNSConstants;
39 import org.kuali.rice.kns.workflow.service.KualiWorkflowInfo;
40 import org.springframework.transaction.annotation.Transactional;
41
42
43 @SuppressWarnings("deprecation")
44 @Transactional
45 public class KualiWorkflowInfoImpl implements KualiWorkflowInfo {
46
47 private static final Logger LOG = Logger.getLogger(KualiWorkflowInfoImpl.class);
48
49 private WorkflowInfo workflowInfo;
50
51 public KualiWorkflowInfoImpl() {
52 workflowInfo = new WorkflowInfo();
53 }
54
55 private WorkflowInfo getWorkflowUtility() {
56 return workflowInfo;
57 }
58
59 public RouteHeaderDTO getRouteHeader(String principalId, String documentId) throws WorkflowException {
60 return getWorkflowUtility().getRouteHeader(principalId, documentId);
61 }
62
63 public RouteHeaderDTO getRouteHeader(String documentId) throws WorkflowException {
64 Principal principal = KimApiServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName(KNSConstants.SYSTEM_USER);
65 if (principal == null) {
66 throw new WorkflowException("Failed to locate System User with principal name 'kr'");
67 }
68 return getWorkflowUtility().getRouteHeader(principal.getPrincipalId(), documentId);
69 }
70
71 public DocumentTypeDTO getDocType(Long documentTypeId) throws WorkflowException {
72 return getWorkflowUtility().getDocType(documentTypeId);
73 }
74
75 public DocumentTypeDTO getDocType(String documentTypeName) throws WorkflowException {
76 return getWorkflowUtility().getDocType(documentTypeName);
77 }
78
79 public Long getNewResponsibilityId() throws WorkflowException {
80 return getWorkflowUtility().getNewResponsibilityId();
81 }
82
83 public ActionRequestDTO[] getActionRequests(String documentId) throws WorkflowException {
84 return getWorkflowUtility().getActionRequests(documentId);
85 }
86
87 public ActionRequestDTO[] getActionRequests(String documentId, String nodeName, String principalId) throws WorkflowException {
88 return getWorkflowUtility().getActionRequests(documentId, nodeName, principalId);
89 }
90
91 public ActionTakenDTO[] getActionsTaken(String documentId) throws WorkflowException {
92 return getWorkflowUtility().getActionsTaken(documentId);
93 }
94
95 public void reResolveRoleByDocTypeName(String documentTypeName, String roleName, String qualifiedRoleNameLabel) throws WorkflowException {
96 getWorkflowUtility().reResolveRoleByDocTypeName(documentTypeName, roleName, qualifiedRoleNameLabel);
97 }
98
99 public void reResolveRoleByDocumentId(String documentId, String roleName, String qualifiedRoleNameLabel) throws WorkflowException {
100 getWorkflowUtility().reResolveRoleByDocumentId(documentId, roleName, qualifiedRoleNameLabel);
101 }
102
103
104
105
106
107 public boolean routeHeaderExists(String documentId) {
108 if (documentId == null) {
109 throw new IllegalArgumentException("Null argument passed in for documentId.");
110 }
111
112 RouteHeaderDTO routeHeader = null;
113 try {
114 routeHeader = getRouteHeader(documentId);
115 }
116 catch (WorkflowException e) {
117 LOG.error("Caught Exception from workflow", e);
118 throw new WorkflowRuntimeException(e);
119 }
120
121 if (routeHeader == null) {
122 return false;
123 }
124 else {
125 return true;
126 }
127 }
128
129
130
131
132
133 public boolean documentWillHaveAtLeastOneActionRequest(ReportCriteriaDTO reportCriteriaDTO, String[] actionRequestedCodes) throws WorkflowException {
134 return documentWillHaveAtLeastOneActionRequest(reportCriteriaDTO, actionRequestedCodes, false);
135 }
136
137
138
139
140 public boolean documentWillHaveAtLeastOneActionRequest(ReportCriteriaDTO reportCriteriaDTO, String[] actionRequestedCodes, boolean ignoreCurrentlyActiveRequests) throws WorkflowException {
141 return getWorkflowUtility().documentWillHaveAtLeastOneActionRequest(reportCriteriaDTO, actionRequestedCodes, ignoreCurrentlyActiveRequests);
142 }
143
144
145
146
147 public List<String> getApprovalRequestedUsers(String documentId) throws WorkflowException {
148 ActionItemDTO[] actionItemVOs = getWorkflowUtility().getActionItems(documentId, new String[]{KEWConstants.ACTION_REQUEST_COMPLETE_REQ, KEWConstants.ACTION_REQUEST_APPROVE_REQ});
149 List<String> users = new ArrayList<String>();
150 for (int i = 0; i < actionItemVOs.length; i++) {
151 ActionItemDTO actionItemVO = actionItemVOs[i];
152 users.add(actionItemVO.getPrincipalId());
153 }
154 return users;
155 }
156
157 public DocumentSearchResultDTO performDocumentSearch(DocumentSearchCriteriaDTO criteriaVO) throws WorkflowException {
158 return getWorkflowUtility().performDocumentSearch(criteriaVO);
159 }
160
161 public DocumentSearchResultDTO performDocumentSearch(String principalId, DocumentSearchCriteriaDTO criteriaVO) throws RemoteException, WorkflowException {
162 return getWorkflowUtility().performDocumentSearch(principalId, criteriaVO);
163 }
164
165
166
167
168
169
170 public boolean isCurrentActiveDocumentType(String documentTypeName) throws WorkflowException {
171 return getWorkflowUtility().isCurrentActiveDocumentType( documentTypeName );
172 }
173 }